1/*! 2 Colorbox 1.6.3 3 license: MIT 4 http://www.jacklmoore.com/colorbox 5*/ 6(function ($, document, window) { 7 var 8 // Default settings object. 9 // See http://jacklmoore.com/colorbox for details. 10 defaults = { 11 // data sources 12 html: false, 13 photo: false, 14 iframe: false, 15 inline: false, 16 17 // behavior and appearance 18 transition: "elastic", 19 speed: 300, 20 fadeOut: 300, 21 width: false, 22 //initialWidth: "600", 23 initialWidth: false, 24 innerWidth: false, 25 maxWidth: "100%", 26 //maxWidth: false, 27 height: false, 28 //initialHeight: "450", 29 initialHeight: false, 30 innerHeight: false, 31 maxHeight: "100%", 32 scalePhotos: true, 33 scrolling: true, 34 opacity: 0.9, 35 preloading: true, 36 className: false, 37 overlayClose: true, 38 escKey: true, 39 arrowKey: true, 40 top: false, 41 bottom: false, 42 left: false, 43 right: false, 44 fixed: false, 45 data: undefined, 46 closeButton: true, 47 fastIframe: true, 48 open: false, 49 reposition: true, 50 loop: true, 51 slideshow: false, 52 slideshowAuto: true, 53 slideshowSpeed: 2500, 54 slideshowStart: "start slideshow", 55 slideshowStop: "stop slideshow", 56 photoRegex: /\.(gif|png|jp(e|g|eg)|bmp|ico|webp|jxr|svg)((#|\?).*)?$/i, 57 58 // alternate image paths for high-res displays 59 retinaImage: false, 60 retinaUrl: false, 61 retinaSuffix: '@2x.$1', 62 63 // internationalization 64 current: "I
vendor: 27,915 bytes, lines 64-1108
64mage {current} of {total}", 65 previous: "previous", 66 next: "next", 67 close: "close", 68 xhrError: "This content failed to load.", 69 imgError: "This image failed to load.", 70 71 // accessbility 72 returnFocus: true, 73 trapFocus: true, 74 75 // callbacks 76 onOpen: false, 77 onLoad: false, 78 onComplete: false, 79 onCleanup: false, 80 onClosed: false, 81 82 rel: function() { 83 return this.rel; 84 }, 85 href: function() { 86 // using this.href would give the absolute url, when the href may have been inteded as a selector (e.g. '#container') 87 return $(this).attr('href'); 88 }, 89 title: function() { 90 return this.title; 91 }, 92 createImg: function() { 93 var img = new Image(); 94 var attrs = $(this).data('cbox-img-attrs'); 95 96 if (typeof attrs === 'object') { 97 $.each(attrs, function(key, val){ 98 img[key] = val; 99 }); 100 } 101 102 return img; 103 }, 104 createIframe: function() { 105 var iframe = document.createElement('iframe'); 106 var attrs = $(this).data('cbox-iframe-attrs'); 107 108 if (typeof attrs === 'object') { 109 $.each(attrs, function(key, val){ 110 iframe[key] = val; 111 }); 112 } 113 114 if ('frameBorder' in iframe) { 115 iframe.frameBorder = 0; 116 } 117 if ('allowTransparency' in iframe) { 118 iframe.allowTransparency = "true"; 119 } 120 iframe.name = (new Date()).getTime(); // give the iframe a unique name to prevent caching 121 iframe.allowFullscreen = true; 122 123 return iframe; 124 } 125 }, 126 127 // Abstracting the HTML and event identifiers for easy rebranding 128 colorbox = 'colorbox', 129 prefix = 'cbox', 130 boxElement = prefix + 'Element', 131 132 // Events 133 event_open = prefix + '_open', 134 event_load = prefix + '_load', 135 event_complete = prefix + '_complete', 136 event_cleanup = prefix + '_cleanup', 137 event_closed = prefix + '_closed', 138 event_purge = prefix + '_purge', 139 140 // Cached jQuery Object Variables 141 $overlay, 142 $box, 143 $wrap, 144 $content, 145 $topBorder, 146 $leftBorder, 147 $rightBorder, 148 $bottomBorder, 149 $related, 150 $window, 151 $loaded, 152 $loadingBay, 153 $loadingOverlay, 154 $title, 155 $current, 156 $slideshow, 157 $next, 158 $prev, 159 $close, 160 $groupControls, 161 $events = $('<a/>'), // $({}) would be prefered, but there is an issue with jQuery 1.4.2 162 163 // Variables for cached values or use across multiple functions 164 settings, 165 interfaceHeight, 166 interfaceWidth, 167 loadedHeight, 168 loadedWidth, 169 index, 170 photo, 171 open, 172 active, 173 closing, 174 loadingTimer, 175 publicMethod, 176 div = "div", 177 requests = 0, 178 previousCSS = {}, 179 init; 180 181 // **************** 182 // HELPER FUNCTIONS 183 // **************** 184 185 // Convenience function for creating new jQuery objects 186 function $tag(tag, id, css) { 187 var element = document.createElement(tag); 188 189 if (id) { 190 element.id = prefix + id; 191 } 192 193 if (css) { 194 element.style.cssText = css; 195 } 196 197 return $(element); 198 } 199 200 // Get the window height using innerHeight when available to avoid an issue with iOS 201 // http://bugs.jquery.com/ticket/6724 202 function winheight() { 203 return window.innerHeight ? window.innerHeight : $(window).height(); 204 } 205 206 function Settings(element, options) { 207 if (options !== Object(options)) { 208 options = {}; 209 } 210 211 this.cache = {}; 212 this.el = element; 213 214 this.value = function(key) { 215 var dataAttr; 216 217 if (this.cache[key] === undefined) { 218 dataAttr = $(this.el).attr('data-cbox-'+key); 219 220 if (dataAttr !== undefined) { 221 this.cache[key] = dataAttr; 222 } else if (options[key] !== undefined) { 223 this.cache[key] = options[key]; 224 } else if (defaults[key] !== undefined) { 225 this.cache[key] = defaults[key]; 226 } 227 } 228 229 return this.cache[key]; 230 }; 231 232 this.get = function(key) { 233 var value = this.value(key); 234 return $.isFunction(value) ? value.call(this.el, this) : value; 235 }; 236 } 237 238 // Determine the next and previous members in a group. 239 function getIndex(increment) { 240 var 241 max = $related.length, 242 newIndex = (index + increment) % max; 243 244 return (newIndex < 0) ? max + newIndex : newIndex; 245 } 246 247 // Convert '%' and 'px' values to integers 248 function setSize(size, dimension) { 249 return Math.round((/%/.test(size) ? ((dimension === 'x' ? $window.width() : winheight()) / 100) : 1) * parseInt(size, 10)); 250 } 251 252 // Checks an href to see if it is a photo. 253 // There is a force photo option (photo: true) for hrefs that cannot be matched by the regex. 254 function isImage(settings, url) { 255 return settings.get('photo') || settings.get('photoRegex').test(url); 256 } 257 258 function retinaUrl(settings, url) { 259 return settings.get('retinaUrl') && window.devicePixelRatio > 1 ? url.replace(settings.get('photoRegex'), settings.get('retinaSuffix')) : url; 260 } 261 262 function trapFocus(e) { 263 if ('contains' in $box[0] && !$box[0].contains(e.target) && e.target !== $overlay[0]) { 264 e.stopPropagation(); 265 $box.focus(); 266 } 267 } 268 269 function setClass(str) { 270 if (setClass.str !== str) { 271 $box.add($overlay).removeClass(setClass.str).addClass(str); 272 setClass.str = str; 273 } 274 } 275 276 function getRelated(rel) { 277 index = 0; 278 279 if (rel && rel !== false && rel !== 'nofollow') { 280 $related = $('.' + boxElement).filter(function () { 281 var options = $.data(this, colorbox); 282 var settings = new Settings(this, options); 283 return (settings.get('rel') === rel); 284 }); 285 index = $related.index(settings.el); 286 287 // Check direct calls to Colorbox. 288 if (index === -1) { 289 $related = $related.add(settings.el); 290 index = $related.length - 1; 291 } 292 } else { 293 $related = $(settings.el); 294 } 295 } 296 297 function trigger(event) { 298 // for external use 299 $(document).trigger(event); 300 // for internal use 301 $events.triggerHandler(event); 302 } 303 304 var slideshow = (function(){ 305 var active, 306 className = prefix + "Slideshow_", 307 click = "click." + prefix, 308 timeOut; 309 310 function clear () { 311 clearTimeout(timeOut); 312 } 313 314 function set() { 315 if (settings.get('loop') || $related[index + 1]) { 316 clear(); 317 timeOut = setTimeout(publicMethod.next, settings.get('slideshowSpeed')); 318 } 319 } 320 321 function start() { 322 $slideshow 323 .html(settings.get('slideshowStop')) 324 .unbind(click) 325 .one(click, stop); 326 327 $events 328 .bind(event_complete, set) 329 .bind(event_load, clear); 330 331 $box.removeClass(className + "off").addClass(className + "on"); 332 } 333 334 function stop() { 335 clear(); 336 337 $events 338 .unbind(event_complete, set) 339 .unbind(event_load, clear); 340 341 $slideshow 342 .html(settings.get('slideshowStart')) 343 .unbind(click) 344 .one(click, function () { 345 publicMethod.next(); 346 start(); 347 }); 348 349 $box.removeClass(className + "on").addClass(className + "off"); 350 } 351 352 function reset() { 353 active = false; 354 $slideshow.hide(); 355 clear(); 356 $events 357 .unbind(event_complete, set) 358 .unbind(event_load, clear); 359 $box.removeClass(className + "off " + className + "on"); 360 } 361 362 return function(){ 363 if (active) { 364 if (!settings.get('slideshow')) { 365 $events.unbind(event_cleanup, reset); 366 reset(); 367 } 368 } else { 369 if (settings.get('slideshow') && $related[1]) { 370 active = true; 371 $events.one(event_cleanup, reset); 372 if (settings.get('slideshowAuto')) { 373 start(); 374 } else { 375 stop(); 376 } 377 $slideshow.show(); 378 } 379 } 380 }; 381 382 }()); 383 384 385 function launch(element) { 386 var options; 387 388 if (!closing) { 389 390 options = $(element).data(colorbox); 391 392 settings = new Settings(element, options); 393 394 getRelated(settings.get('rel')); 395 396 if (!open) { 397 open = active = true; // Prevents the page-change action from queuing up if the visitor holds down the left or right keys. 398 399 setClass(settings.get('className')); 400 401 // Show colorbox so the sizes can be calculated in older versions of jQuery 402 $box.css({visibility:'hidden', display:'block', opacity:''}); 403 404 $loaded = $tag(div, 'LoadedContent', 'width:0; height:0; overflow:hidden; visibility:hidden'); 405 $content.css({width:'', height:''}).append($loaded); 406 407 // Cache values needed for size calculations 408 interfaceHeight = $topBorder.height() + $bottomBorder.height() + $content.outerHeight(true) - $content.height(); 409 interfaceWidth = $leftBorder.width() + $rightBorder.width() + $content.outerWidth(true) - $content.width(); 410 loadedHeight = $loaded.outerHeight(true); 411 loadedWidth = $loaded.outerWidth(true); 412 413 // Opens inital empty Colorbox prior to content being loaded. 414 var initialWidth = setSize(settings.get('initialWidth'), 'x'); 415 var initialHeight = setSize(settings.get('initialHeight'), 'y'); 416 var maxWidth = settings.get('maxWidth'); 417 var maxHeight = settings.get('maxHeight'); 418 419 settings.w = Math.max((maxWidth !== false ? Math.min(initialWidth, setSize(maxWidth, 'x')) : initialWidth) - loadedWidth - interfaceWidth, 0); 420 settings.h = Math.max((maxHeight !== false ? Math.min(initialHeight, setSize(maxHeight, 'y')) : initialHeight) - loadedHeight - interfaceHeight, 0); 421 422 $loaded.css({width:'', height:settings.h}); 423 publicMethod.position(); 424 425 trigger(event_open); 426 settings.get('onOpen'); 427 428 $groupControls.add($title).hide(); 429 430 $box.focus(); 431 432 if (settings.get('trapFocus')) { 433 // Confine focus to the modal 434 // Uses event capturing that is not supported in IE8- 435 if (document.addEventListener) { 436 437 document.addEventListener('focus', trapFocus, true); 438 439 $events.one(event_closed, function () { 440 document.removeEventListener('focus', trapFocus, true); 441 }); 442 } 443 } 444 445 // Return focus on closing 446 if (settings.get('returnFocus')) { 447 $events.one(event_closed, function () { 448 $(settings.el).focus(); 449 }); 450 } 451 } 452 453 var opacity = parseFloat(settings.get('opacity')); 454 $overlay.css({ 455 opacity: opacity === opacity ? opacity : '', 456 cursor: settings.get('overlayClose') ? 'pointer' : '', 457 visibility: 'visible' 458 }).show(); 459 460 if (settings.get('closeButton')) { 461 $close.html(settings.get('close')).appendTo($content); 462 } else { 463 $close.appendTo('<div/>'); // replace with .detach() when dropping jQuery < 1.4 464 } 465 466 load(); 467 } 468 } 469 470 // Colorbox's markup needs to be added to the DOM prior to being called 471 // so that the browser will go ahead and load the CSS background images. 472 function appendHTML() { 473 if (!$box) { 474 init = false; 475 $window = $(window); 476 $box = $tag(div).attr({ 477 id: colorbox, 478 'class': $.support.opacity === false ? prefix + 'IE' : '', // class for optional IE8 & lower targeted CSS. 479 role: 'dialog', 480 tabindex: '-1' 481 }).hide(); 482 $overlay = $tag(div, "Overlay").hide(); 483 $loadingOverlay = $([$tag(div, "LoadingOverlay")[0],$tag(div, "LoadingGraphic")[0]]); 484 $wrap = $tag(div, "Wrapper"); 485 $content = $tag(div, "Content").append( 486 $title = $tag(div, "Title"), 487 $current = $tag(div, "Current"), 488 $prev = $('<button type="button"/>').attr({id:prefix+'Previous'}), 489 $next = $('<button type="button"/>').attr({id:prefix+'Next'}), 490 $slideshow = $('<button type="button"/>').attr({id:prefix+'Slideshow'}), 491 $loadingOverlay 492 ); 493 494 $close = $('<button type="button"/>').attr({id:prefix+'Close'}); 495 496 $wrap.append( // The 3x3 Grid that makes up Colorbox 497 $tag(div).append( 498 $tag(div, "TopLeft"), 499 $topBorder = $tag(div, "TopCenter"), 500 $tag(div, "TopRight") 501 ), 502 $tag(div, false, 'clear:left').append( 503 $leftBorder = $tag(div, "MiddleLeft"), 504 $content, 505 $rightBorder = $tag(div, "MiddleRight") 506 ), 507 $tag(div, false, 'clear:left').append( 508 $tag(div, "BottomLeft"), 509 $bottomBorder = $tag(div, "BottomCenter"), 510 $tag(div, "BottomRight") 511 ) 512 ).find('div div').css({'float': 'left'}); 513 514 $loadingBay = $tag(div, false, 'position:absolute; width:9999px; visibility:hidden; display:none; max-width:none;'); 515 516 $groupControls = $next.add($prev).add($current).add($slideshow); 517 } 518 if (document.body && !$box.parent().length) { 519 $(document.body).append($overlay, $box.append($wrap, $loadingBay)); 520 } 521 } 522 523 // Add Colorbox's event bindings 524 function addBindings() { 525 function clickHandler(e) { 526 // ignore non-left-mouse-clicks and clicks modified with ctrl / command, shift, or alt. 527 // See: http://jacklmoore.com/notes/click-events/ 528 if (!(e.which > 1 || e.shiftKey || e.altKey || e.metaKey || e.ctrlKey)) { 529 e.preventDefault(); 530 launch(this); 531 } 532 } 533 534 if ($box) { 535 if (!init) { 536 init = true; 537 538 // Anonymous functions here keep the public method from being cached, thereby allowing them to be redefined on the fly. 539 $next.click(function () { 540 publicMethod.next(); 541 }); 542 $prev.click(function () { 543 publicMethod.prev(); 544 }); 545 $close.click(function () { 546 publicMethod.close(); 547 }); 548 $overlay.click(function () { 549 if (settings.get('overlayClose')) { 550 publicMethod.close(); 551 } 552 }); 553 554 // Key Bindings 555 $(document).bind('keydown.' + prefix, function (e) { 556 var key = e.keyCode; 557 if (open && settings.get('escKey') && key === 27) { 558 e.preventDefault(); 559 publicMethod.close(); 560 } 561 if (open && settings.get('arrowKey') && $related[1] && !e.altKey) { 562 if (key === 37) { 563 e.preventDefault(); 564 $prev.click(); 565 } else if (key === 39) { 566 e.preventDefault(); 567 $next.click(); 568 } 569 } 570 }); 571 572 if ($.isFunction($.fn.on)) { 573 // For jQuery 1.7+ 574 $(document).on('click.'+prefix, '.'+boxElement, clickHandler); 575 } else { 576 // For jQuery 1.3.x -> 1.6.x 577 // This code is never reached in jQuery 1.9, so do not contact me about 'live' being removed. 578 // This is not here for jQuery 1.9, it's here for legacy users. 579 $('.'+boxElement).live('click.'+prefix, clickHandler); 580 } 581 } 582 return true; 583 } 584 return false; 585 } 586 587 // Don't do anything if Colorbox already exists. 588 if ($[colorbox]) { 589 return; 590 } 591 592 // Append the HTML when the DOM loads 593 $(appendHTML); 594 595 596 // **************** 597 // PUBLIC FUNCTIONS 598 // Usage format: $.colorbox.close(); 599 // Usage from within an iframe: parent.jQuery.colorbox.close(); 600 // **************** 601 602 publicMethod = $.fn[colorbox] = $[colorbox] = function (options, callback) { 603 var settings; 604 var $obj = this; 605 606 options = options || {}; 607 608 if ($.isFunction($obj)) { // assume a call to $.colorbox 609 $obj = $('<a/>'); 610 options.open = true; 611 } 612 613 if (!$obj[0]) { // colorbox being applied to empty collection 614 return $obj; 615 } 616 617 appendHTML(); 618 619 if (addBindings()) { 620 621 if (callback) { 622 options.onComplete = callback; 623 } 624 625 $obj.each(function () { 626 var old = $.data(this, colorbox) || {}; 627 $.data(this, colorbox, $.extend(old, options)); 628 }).addClass(boxElement); 629 630 settings = new Settings($obj[0], options); 631 632 if (settings.get('open')) { 633 launch($obj[0]); 634 } 635 } 636 637 return $obj; 638 }; 639 640 publicMethod.position = function (speed, loadedCallback) { 641 var 642 css, 643 top = 0, 644 left = 0, 645 offset = $box.offset(), 646 scrollTop, 647 scrollLeft; 648 649 $window.unbind('resize.' + prefix); 650 651 // remove the modal so that it doesn't influence the document width/height 652 $box.css({top: -9e4, left: -9e4}); 653 654 scrollTop = $window.scrollTop(); 655 scrollLeft = $window.scrollLeft(); 656 657 if (settings.get('fixed')) { 658 offset.top -= scrollTop; 659 offset.left -= scrollLeft; 660 $box.css({position: 'fixed'}); 661 } else { 662 top = scrollTop; 663 left = scrollLeft; 664 $box.css({position: 'absolute'}); 665 } 666 667 // keeps the top and left positions within the browser's viewport. 668 if (settings.get('right') !== false) { 669 left += Math.max($window.width() - settings.w - loadedWidth - interfaceWidth - setSize(settings.get('right'), 'x'), 0); 670 } else if (settings.get('left') !== false) { 671 left += setSize(settings.get('left'), 'x'); 672 } else { 673 left += Math.round(Math.max($window.width() - settings.w - loadedWidth - interfaceWidth, 0) / 2); 674 } 675 676 if (settings.get('bottom') !== false) { 677 top += Math.max(winheight() - settings.h - loadedHeight - interfaceHeight - setSize(settings.get('bottom'), 'y'), 0); 678 } else if (settings.get('top') !== false) { 679 top += setSize(settings.get('top'), 'y'); 680 } else { 681 top += Math.round(Math.max(winheight() - settings.h - loadedHeight - interfaceHeight, 0) / 2); 682 } 683 684 $box.css({top: offset.top, left: offset.left, visibility:'visible'}); 685 686 // this gives the wrapper plenty of breathing room so it's floated contents can move around smoothly, 687 // but it has to be shrank down around the size of div#colorbox when it's done. If not, 688 // it can invoke an obscure IE bug when using iframes. 689 $wrap[0].style.width = $wrap[0].style.height = "9999px"; 690 691 function modalDimensions() { 692 $topBorder[0].style.width = $bottomBorder[0].style.width = $content[0].style.width = (parseInt($box[0].style.width,10) - interfaceWidth)+'px'; 693 $content[0].style.height = $leftBorder[0].style.height = $rightBorder[0].style.height = (parseInt($box[0].style.height,10) - interfaceHeight)+'px'; 694 } 695 696 css = {width: settings.w + loadedWidth + interfaceWidth, height: settings.h + loadedHeight + interfaceHeight, top: top, left: left}; 697 698 // setting the speed to 0 if the content hasn't changed size or position 699 if (speed) { 700 var tempSpeed = 0; 701 $.each(css, function(i){ 702 if (css[i] !== previousCSS[i]) { 703 tempSpeed = speed; 704 return; 705 } 706 }); 707 speed = tempSpeed; 708 } 709 710 previousCSS = css; 711 712 if (!speed) { 713 $box.css(css); 714 } 715 716 $box.dequeue().animate(css, { 717 duration: speed || 0, 718 complete: function () { 719 modalDimensions(); 720 721 active = false; 722 723 // shrink the wrapper down to exactly the size of colorbox to avoid a bug in IE's iframe implementation. 724 $wrap[0].style.width = (settings.w + loadedWidth + interfaceWidth) + "px"; 725 $wrap[0].style.height = (settings.h + loadedHeight + interfaceHeight) + "px"; 726 727 if (settings.get('reposition')) { 728 setTimeout(function () { // small delay before binding onresize due to an IE8 bug. 729 $window.bind('resize.' + prefix, publicMethod.position); 730 }, 1); 731 } 732 733 if ($.isFunction(loadedCallback)) { 734 loadedCallback(); 735 } 736 }, 737 step: modalDimensions 738 }); 739 }; 740 741 publicMethod.resize = function (options) { 742 var scrolltop; 743 744 if (open) { 745 options = options || {}; 746 747 if (options.width) { 748 settings.w = setSize(options.width, 'x') - loadedWidth - interfaceWidth; 749 } 750 751 if (options.innerWidth) { 752 settings.w = setSize(options.innerWidth, 'x'); 753 } 754 755 $loaded.css({width: settings.w}); 756 757 if (options.height) { 758 settings.h = setSize(options.height, 'y') - loadedHeight - interfaceHeight; 759 } 760 761 if (options.innerHeight) { 762 settings.h = setSize(options.innerHeight, 'y'); 763 } 764 765 if (!options.innerHeight && !options.height) { 766 scrolltop = $loaded.scrollTop(); 767 $loaded.css({height: "auto"}); 768 settings.h = $loaded.height(); 769 } 770 771 $loaded.css({height: settings.h}); 772 773 if(scrolltop) { 774 $loaded.scrollTop(scrolltop); 775 } 776 777 publicMethod.position(settings.get('transition') === "none" ? 0 : settings.get('speed')); 778 } 779 }; 780 781 publicMethod.prep = function (object) { 782 if (!open) { 783 return; 784 } 785 786 var callback, speed = settings.get('transition') === "none" ? 0 : settings.get('speed'); 787 788 $loaded.remove(); 789 790 $loaded = $tag(div, 'LoadedContent').append(object); 791 792 function getWidth() { 793 settings.w = settings.w || $loaded.width(); 794 settings.w = settings.mw && settings.mw < settings.w ? settings.mw : settings.w; 795 return settings.w; 796 } 797 function getHeight() { 798 settings.h = settings.h || $loaded.height(); 799 settings.h = settings.mh && settings.mh < settings.h ? settings.mh : settings.h; 800 return settings.h; 801 } 802 803 $loaded.hide() 804 .appendTo($loadingBay.show())// content has to be appended to the DOM for accurate size calculations. 805 .css({width: getWidth(), overflow: settings.get('scrolling') ? 'auto' : 'hidden'}) 806 .css({height: getHeight()})// sets the height independently from the width in case the new width influences the value of height. 807 .prependTo($content); 808 809 $loadingBay.hide(); 810 811 // floating the IMG removes the bottom line-height and fixed a problem where IE miscalculates the width of the parent element as 100% of the document width. 812 813 $(photo).css({'float': 'none'}); 814 815 setClass(settings.get('className')); 816 817 callback = function () { 818 var total = $related.length, 819 iframe, 820 complete; 821 822 if (!open) { 823 return; 824 } 825 826 function removeFilter() { // Needed for IE8 in versions of jQuery prior to 1.7.2 827 if ($.support.opacity === false) { 828 $box[0].style.removeAttribute('filter'); 829 } 830 } 831 832 complete = function () { 833 clearTimeout(loadingTimer); 834 $loadingOverlay.hide(); 835 trigger(event_complete); 836 settings.get('onComplete'); 837 }; 838 839 840 $title.html(settings.get('title')).show(); 841 $loaded.show(); 842 843 if (total > 1) { // handle grouping 844 if (typeof settings.get('current') === "string") { 845 $current.html(settings.get('current').replace('{current}', index + 1).replace('{total}', total)).show(); 846 } 847 848 $next[(settings.get('loop') || index < total - 1) ? "show" : "hide"]().html(settings.get('next')); 849 $prev[(settings.get('loop') || index) ? "show" : "hide"]().html(settings.get('previous')); 850 851 slideshow(); 852 853 // Preloads images within a rel group 854 if (settings.get('preloading')) { 855 $.each([getIndex(-1), getIndex(1)], function(){ 856 var img, 857 i = $related[this], 858 settings = new Settings(i, $.data(i, colorbox)), 859 src = settings.get('href'); 860 861 if (src && isImage(settings, src)) { 862 src = retinaUrl(settings, src); 863 img = document.createElement('img'); 864 img.src = src; 865 } 866 }); 867 } 868 } else { 869 $groupControls.hide(); 870 } 871 872 if (settings.get('iframe')) { 873 874 iframe = settings.get('createIframe'); 875 876 if (!settings.get('scrolling')) { 877 iframe.scrolling = "no"; 878 } 879 880 $(iframe) 881 .attr({ 882 src: settings.get('href'), 883 'class': prefix + 'Iframe' 884 }) 885 .one('load', complete) 886 .appendTo($loaded); 887 888 $events.one(event_purge, function () { 889 iframe.src = "//about:blank"; 890 }); 891 892 if (settings.get('fastIframe')) { 893 $(iframe).trigger('load'); 894 } 895 } else { 896 complete(); 897 } 898 899 if (settings.get('transition') === 'fade') { 900 $box.fadeTo(speed, 1, removeFilter); 901 } else { 902 removeFilter(); 903 } 904 }; 905 906 if (settings.get('transition') === 'fade') { 907 $box.fadeTo(speed, 0, function () { 908 publicMethod.position(0, callback); 909 }); 910 } else { 911 publicMethod.position(speed, callback); 912 } 913 }; 914 915 function load () { 916 var href, setResize, prep = publicMethod.prep, $inline, request = ++requests; 917 918 active = true; 919 920 photo = false; 921 922 trigger(event_purge); 923 trigger(event_load); 924 settings.get('onLoad'); 925 926 settings.h = settings.get('height') ? 927 setSize(settings.get('height'), 'y') - loadedHeight - interfaceHeight : 928 settings.get('innerHeight') && setSize(settings.get('innerHeight'), 'y'); 929 930 settings.w = settings.get('width') ? 931 setSize(settings.get('width'), 'x') - loadedWidth - interfaceWidth : 932 settings.get('innerWidth') && setSize(settings.get('innerWidth'), 'x'); 933 934 // Sets the minimum dimensions for use in image scaling 935 settings.mw = settings.w; 936 settings.mh = settings.h; 937 938 // Re-evaluate the minimum width and height based on maxWidth and maxHeight values. 939 // If the width or height exceed the maxWidth or maxHeight, use the maximum values instead. 940 if (settings.get('maxWidth')) { 941 settings.mw = setSize(settings.get('maxWidth'), 'x') - loadedWidth - interfaceWidth; 942 settings.mw = settings.w && settings.w < settings.mw ? settings.w : settings.mw; 943 } 944 if (settings.get('maxHeight')) { 945 settings.mh = setSize(settings.get('maxHeight'), 'y') - loadedHeight - interfaceHeight; 946 settings.mh = settings.h && settings.h < settings.mh ? settings.h : settings.mh; 947 } 948 949 href = settings.get('href'); 950 951 loadingTimer = setTimeout(function () { 952 $loadingOverlay.show(); 953 }, 100); 954 955 if (settings.get('inline')) { 956 var $target = $(href); 957 // Inserts an empty placeholder where inline content is being pulled from. 958 // An event is bound to put inline content back when Colorbox closes or loads new content. 959 $inline = $('<div>').hide().insertBefore($target); 960 961 $events.one(event_purge, function () { 962 $inline.replaceWith($target); 963 }); 964 965 prep($target); 966 } else if (settings.get('iframe')) { 967 // IFrame element won't be added to the DOM until it is ready to be displayed, 968 // to avoid problems with DOM-ready JS that might be trying to run in that iframe. 969 prep(" "); 970 } else if (settings.get('html')) { 971 prep(settings.get('html')); 972 } else if (isImage(settings, href)) { 973 974 href = retinaUrl(settings, href); 975 976 photo = settings.get('createImg'); 977 978 $(photo) 979 .addClass(prefix + 'Photo') 980 .bind('error.'+prefix,function () { 981 prep($tag(div, 'Error').html(settings.get('imgError'))); 982 }) 983 .one('load', function () { 984 if (request !== requests) { 985 return; 986 } 987 988 // A small pause because some browsers will occassionaly report a 989 // img.width and img.height of zero immediately after the img.onload fires 990 setTimeout(function(){ 991 var percent; 992 993 if (settings.get('retinaImage') && window.devicePixelRatio > 1) { 994 photo.height = photo.height / window.devicePixelRatio; 995 photo.width = photo.width / window.devicePixelRatio; 996 } 997 998 if (settings.get('scalePhotos')) { 999 setResize = function () { 1000 photo.height -= photo.height * percent; 1001 photo.width -= photo.width * percent; 1002 }; 1003 if (settings.mw && photo.width > settings.mw) { 1004 percent = (photo.width - settings.mw) / photo.width; 1005 setResize(); 1006 } 1007 if (settings.mh && photo.height > settings.mh) { 1008 percent = (photo.height - settings.mh) / photo.height; 1009 setResize(); 1010 } 1011 } 1012 1013 if (settings.h) { 1014 photo.style.marginTop = Math.max(settings.mh - photo.height, 0) / 2 + 'px'; 1015 } 1016 1017 if ($related[1] && (settings.get('loop') || $related[index + 1])) { 1018 photo.style.cursor = 'pointer'; 1019 1020 $(photo).bind('click.'+prefix, function () { 1021 publicMethod.next(); 1022 }); 1023 } 1024 1025 photo.style.width = photo.width + 'px'; 1026 photo.style.height = photo.height + 'px'; 1027 prep(photo); 1028 }, 1); 1029 }); 1030 1031 photo.src = href; 1032 1033 } else if (href) { 1034 $loadingBay.load(href, settings.get('data'), function (data, status) { 1035 if (request === requests) { 1036 prep(status === 'error' ? $tag(div, 'Error').html(settings.get('xhrError')) : $(this).contents()); 1037 } 1038 }); 1039 } 1040 } 1041 1042 // Navigates to the next page/image in a set. 1043 publicMethod.next = function () { 1044 if (!active && $related[1] && (settings.get('loop') || $related[index + 1])) { 1045 index = getIndex(1); 1046 launch($related[index]); 1047 } 1048 }; 1049 1050 publicMethod.prev = function () { 1051 if (!active && $related[1] && (settings.get('loop') || index)) { 1052 index = getIndex(-1); 1053 launch($related[index]); 1054 } 1055 }; 1056 1057 // Note: to use this within an iframe use the following format: parent.jQuery.colorbox.close(); 1058 publicMethod.close = function () { 1059 if (open && !closing) { 1060 1061 closing = true; 1062 open = false; 1063 trigger(event_cleanup); 1064 settings.get('onCleanup'); 1065 $window.unbind('.' + prefix); 1066 $overlay.fadeTo(settings.get('fadeOut') || 0, 0); 1067 1068 $box.stop().fadeTo(settings.get('fadeOut') || 0, 0, function () { 1069 $box.hide(); 1070 $overlay.hide(); 1071 trigger(event_purge); 1072 $loaded.remove(); 1073 1074 setTimeout(function () { 1075 closing = false; 1076 trigger(event_closed); 1077 settings.get('onClosed'); 1078 }, 1); 1079 }); 1080 } 1081 }; 1082 1083 // Removes changes Colorbox made to the document, but does not remove the plugin. 1084 publicMethod.remove = function () { 1085 if (!$box) { return; } 1086 1087 $box.stop(); 1088 $[colorbox].close(); 1089 $box.stop(false, true).remove(); 1090 $overlay.remove(); 1091 closing = false; 1092 $box = null; 1093 $('.' + boxElement) 1094 .removeData(colorbox) 1095 .removeClass(boxElement); 1096 1097 $(document).unbind('click.'+prefix).unbind('keydown.'+prefix); 1098 }; 1099 1100 // A method for fetching the current element Colorbox is referencing. 1101 // returns a jQuery object. 1102 publicMethod.element = function () { 1103 return $(settings.el); 1104 }; 1105 1106 publicMethod.settings = defaults; 1107 1108}(jQuery, document, window));
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.