vendor: 30,304 bytes, lines 1-1140
1/*! 2 Colorbox 1.6.4 3 license: MIT 4 http://www.jacklmoore.com/colorbox 5 6 Included patches: 7 * https://github.com/jackmoore/colorbox/pull/832 8*/ 9(function ($, document, window) { 10 var 11 // Default settings object. 12 // See http://jacklmoore.com/colorbox for details. 13 defaults = { 14 // data sources 15 html: false, 16 photo: false, 17 iframe: false, 18 inline: false, 19 20 // behavior and appearance 21 transition: "elastic", 22 speed: 300, 23 fadeOut: 300, 24 width: false, 25 initialWidth: "600", 26 innerWidth: false, 27 maxWidth: false, 28 height: false, 29 initialHeight: "450", 30 innerHeight: false, 31 maxHeight: false, 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: "image {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 // accessibility 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 preferred, 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 // Helper to enumerate focusable elements 207 function focusableEls ($e) { 208 return $e.find('a[href], area[href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), button:not([disabled]), [tabindex="0"]'); 209 } 210 211 function firstFocusableEl($e) { 212 return focusableEls($e).first(); 213 } 214 215 function lastFocusableEl($e) { 216 return focusableEls($e).last(); 217 } 218 219 function Settings(element, options) { 220 if (options !== Object(options)) { 221 options = {}; 222 } 223 224 this.cache = {}; 225 this.el = element; 226 227 this.value = function(key) { 228 var dataAttr; 229 230 if (this.cache[key] === undefined) { 231 dataAttr = $(this.el).attr('data-cbox-'+key); 232 233 if (dataAttr !== undefined) { 234 this.cache[key] = dataAttr; 235 } else if (options[key] !== undefined) { 236 this.cache[key] = options[key]; 237 } else if (defaults[key] !== undefined) { 238 this.cache[key] = defaults[key]; 239 } 240 } 241 242 return this.cache[key]; 243 }; 244 245 this.get = function(key) { 246 var value = this.value(key); 247 return $.isFunction(value) ? value.call(this.el, this) : value; 248 }; 249 } 250 251 // Determine the next and previous members in a group. 252 function getIndex(increment) { 253 var 254 max = $related.length, 255 newIndex = (index + increment) % max; 256 257 return (newIndex < 0) ? max + newIndex : newIndex; 258 } 259 260 // Convert '%' and 'px' values to integers 261 function setSize(size, dimension) { 262 return Math.round((/%/.test(size) ? ((dimension === 'x' ? $window.width() : winheight()) / 100) : 1) * parseInt(size, 10)); 263 } 264 265 // Checks an href to see if it is a photo. 266 // There is a force photo option (photo: true) for hrefs that cannot be matched by the regex. 267 function isImage(settings, url) { 268 return settings.get('photo') || settings.get('photoRegex').test(url); 269 } 270 271 function retinaUrl(settings, url) { 272 return settings.get('retinaUrl') && window.devicePixelRatio > 1 ? url.replace(settings.get('photoRegex'), settings.get('retinaSuffix')) : url; 273 } 274 275 function setClass(str) { 276 if (setClass.str !== str) { 277 $box.add($overlay).removeClass(setClass.str).addClass(str); 278 setClass.str = str; 279 } 280 } 281 282 function getRelated(rel) { 283 index = 0; 284 285 if (rel && rel !== false && rel !== 'nofollow') { 286 $related = $('.' + boxElement).filter(function () { 287 var options = $.data(this, colorbox); 288 var settings = new Settings(this, options); 289 return (settings.get('rel') === rel); 290 }); 291 index = $related.index(settings.el); 292 293 // Check direct calls to Colorbox. 294 if (index === -1) { 295 $related = $related.add(settings.el); 296 index = $related.length - 1; 297 } 298 } else { 299 $related = $(settings.el); 300 } 301 } 302 303 function trigger(event) { 304 // for external use 305 $(document).trigger(event); 306 // for internal use 307 $events.triggerHandler(event); 308 } 309 310 var slideshow = (function(){ 311 var active, 312 className = prefix + "Slideshow_", 313 click = "click." + prefix, 314 timeOut; 315 316 function clear () { 317 clearTimeout(timeOut); 318 } 319 320 function set() { 321 if (settings.get('loop') || $related[index + 1]) { 322 clear(); 323 timeOut = setTimeout(publicMethod.next, settings.get('slideshowSpeed')); 324 } 325 } 326 327 function start() { 328 $slideshow 329 .html(settings.get('slideshowStop')) 330 .attr('aria-label', settings.get('slideshowStop')) 331 .unbind(click) 332 .one(click, stop); 333 334 $events 335 .bind(event_complete, set) 336 .bind(event_load, clear); 337 338 $box.removeClass(className + "off").addClass(className + "on"); 339 } 340 341 function stop() { 342 clear(); 343 344 $events 345 .unbind(event_complete, set) 346 .unbind(event_load, clear); 347 348 $slideshow 349 .html(settings.get('slideshowStart')) 350 .attr('aria-label', settings.get('slideshowStart')) 351 .unbind(click) 352 .one(click, function () { 353 publicMethod.next(); 354 start(); 355 }); 356 357 $box.removeClass(className + "on").addClass(className + "off"); 358 } 359 360 function reset() { 361 active = false; 362 $slideshow.attr('aria-hidden', 'true').hide(); 363 clear(); 364 $events 365 .unbind(event_complete, set) 366 .unbind(event_load, clear); 367 $box.removeClass(className + "off " + className + "on"); 368 } 369 370 return function(){ 371 if (active) { 372 if (!settings.get('slideshow')) { 373 $events.unbind(event_cleanup, reset); 374 reset(); 375 } 376 } else { 377 if (settings.get('slideshow') && $related[1]) { 378 active = true; 379 $events.one(event_cleanup, reset); 380 if (settings.get('slideshowAuto')) { 381 start(); 382 } else { 383 stop(); 384 } 385 $slideshow.attr('aria-hidden', 'false').show(); 386 } 387 } 388 }; 389 390 }()); 391 392 393 function launch(element) { 394 var options; 395 396 if (!closing) { 397 398 options = $(element).data(colorbox); 399 400 settings = new Settings(element, options); 401 402 getRelated(settings.get('rel')); 403 404 if (!open) { 405 open = active = true; // Prevents the page-change action from queuing up if the visitor holds down the left or right keys. 406 407 setClass(settings.get('className')); 408 409 // Show colorbox so the sizes can be calculated in older versions of jQuery 410 $box.css({visibility:'hidden', display:'block', opacity:''}).attr('aria-hidden', 'true'); 411 412 $loaded = $tag(div, 'LoadedContent', 'width:0; height:0; overflow:hidden; visibility:hidden'); 413 $content.css({width:'', height:''}).append($loaded); 414 415 // Cache values needed for size calculations 416 interfaceHeight = $topBorder.height() + $bottomBorder.height() + $content.outerHeight(true) - $content.height(); 417 interfaceWidth = $leftBorder.width() + $rightBorder.width() + $content.outerWidth(true) - $content.width(); 418 loadedHeight = $loaded.outerHeight(true); 419 loadedWidth = $loaded.outerWidth(true); 420 421 // Opens inital empty Colorbox prior to content being loaded. 422 var initialWidth = setSize(settings.get('initialWidth'), 'x'); 423 var initialHeight = setSize(settings.get('initialHeight'), 'y'); 424 var maxWidth = settings.get('maxWidth'); 425 var maxHeight = settings.get('maxHeight'); 426 427 settings.w = Math.max((maxWidth !== false ? Math.min(initialWidth, setSize(maxWidth, 'x')) : initialWidth) - loadedWidth - interfaceWidth, 0); 428 settings.h = Math.max((maxHeight !== false ? Math.min(initialHeight, setSize(maxHeight, 'y')) : initialHeight) - loadedHeight - interfaceHeight, 0); 429 430 $loaded.css({width:'', height:settings.h}); 431 publicMethod.position(); 432 433 trigger(event_open); 434 settings.get('onOpen'); 435 436 $groupControls.add($title).hide(); 437 438 $box.attr('aria-hidden', 'false'); 439 440 // Return focus on closing 441 if (settings.get('returnFocus')) { 442 $events.one(event_closed, function () { 443 $(settings.el).focus(); 444 }); 445 } 446 } 447 448 var opacity = parseFloat(settings.get('opacity')); 449 $overlay.css({ 450 opacity: opacity === opacity ? opacity : '', 451 cursor: settings.get('overlayClose') ? 'pointer' : '', 452 visibility: 'visible' 453 }).show(); 454 455 if (settings.get('closeButton')) { 456 $close 457 .html(settings.get('close')) 458 .attr('aria-hidden', 'false') 459 .appendTo($content); 460 } else { 461 $close.appendTo('<div/>'); // replace with .detach() when dropping jQuery < 1.4 462 } 463 464 load(); 465 } 466 } 467 468 // Colorbox's markup needs to be added to the DOM prior to being called 469 // so that the browser will go ahead and load the CSS background images. 470 function appendHTML() { 471 if (!$box) { 472 init = false; 473 $window = $(window); 474 $box = $tag(div).attr({ 475 id: colorbox, 476 'class': $.support.opacity === false ? prefix + 'IE' : '', // class for optional IE8 & lower targeted CSS. 477 role: 'dialog', 478 'aria-hidden': 'true', 479 'aria-labelledby': "cboxTitle", 480 'aria-describedby': "cboxCurrent", 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 .attr('aria-live', 'polite'), 488 $current = $tag(div, "Current"), 489 $prev = $('<button type="button">previous</button>').attr({ 490 id: prefix+'Previous', 491 'aria-hidden': 'true' 492 }), 493 $next = $('<button type="button">next</button>').attr({ 494 id: prefix+'Next', 495 'aria-hidden': 'true' 496 }), 497 $slideshow = $('<button type="button">start slideshow</button>').attr({ 498 id: prefix+'Slideshow', 499 'aria-hidden': 'true' 500 }), 501 $loadingOverlay 502 ); 503 504 $close = $('<button type="button">close</button>').attr({ 505 id: prefix+'Close', 506 'aria-hidden': 'true' 507 }); 508 509 $wrap.append( // The 3x3 Grid that makes up Colorbox 510 $tag(div).append( 511 $tag(div, "TopLeft"), 512 $topBorder = $tag(div, "TopCenter"), 513 $tag(div, "TopRight") 514 ), 515 $tag(div, false, 'clear:left').append( 516 $leftBorder = $tag(div, "MiddleLeft"), 517 $content, 518 $rightBorder = $tag(div, "MiddleRight") 519 ), 520 $tag(div, false, 'clear:left').append( 521 $tag(div, "BottomLeft"), 522 $bottomBorder = $tag(div, "BottomCenter"), 523 $tag(div, "BottomRight") 524 ) 525 ).find('div div').css({'float': 'left'}); 526 527 $loadingBay = $tag(div, false, 'position:absolute; width:9999px; visibility:hidden; display:none; max-width:none;'); 528 529 $groupControls = $next.add($prev).add($current).add($slideshow); 530 } 531 if (document.body && !$box.parent().length) { 532 $(document.body).append($overlay, $box.append($wrap, $loadingBay)); 533 } 534 } 535 536 // Add Colorbox's event bindings 537 function addBindings() { 538 function clickHandler(e) { 539 // ignore non-left-mouse-clicks and clicks modified with ctrl / command, shift, or alt. 540 // See: http://jacklmoore.com/notes/click-events/ 541 if (!(e.which > 1 || e.shiftKey || e.altKey || e.metaKey || e.ctrlKey)) { 542 e.preventDefault(); 543 launch(this); 544 } 545 } 546 547 if ($box) { 548 if (!init) { 549 init = true; 550 551 // Anonymous functions here keep the public method from being cached, thereby allowing them to be redefined on the fly. 552 $next.click(function () { 553 publicMethod.next(); 554 }); 555 $prev.click(function () { 556 publicMethod.prev(); 557 }); 558 $close.click(function () { 559 publicMethod.close(); 560 }); 561 $overlay.click(function () { 562 if (settings.get('overlayClose')) { 563 publicMethod.close(); 564 } 565 }); 566 567 // Key Bindings 568 $(document).bind('keydown.' + prefix, function (e) { 569 var key = e.keyCode; 570 if (open && settings.get('escKey') && key === 27) { 571 e.preventDefault(); 572 publicMethod.close(); 573 } 574 if (open && settings.get('arrowKey') && $related[1] && !e.altKey) { 575 if (key === 37) { 576 e.preventDefault(); 577 $prev.click(); 578 } else if (key === 39) { 579 e.preventDefault(); 580 $next.click(); 581 } 582 } 583 if (open && settings.get('trapFocus') && key === 9) { 584 if ( focusableEls($box).length === 1 ) { 585 e.preventDefault(); 586 } else { 587 if ( e.shiftKey ) { 588 if ( document.activeElement === firstFocusableEl($box)[0] ) { 589 e.preventDefault(); 590 lastFocusableEl($box).focus(); 591 } 592 } else { 593 if ( document.activeElement === lastFocusableEl($box)[0] ) { 594 e.preventDefault(); 595 firstFocusableEl($box).focus(); 596 } 597 } 598 } 599 } 600 }); 601 602 if ($.isFunction($.fn.on)) { 603 // For jQuery 1.7+ 604 $(document).on('click.'+prefix, '.'+boxElement, clickHandler); 605 } else { 606 // For jQuery 1.3.x -> 1.6.x 607 // This code is never reached in jQuery 1.9, so do not contact me about 'live' being removed. 608 // This is not here for jQuery 1.9, it's here for legacy users. 609 $('.'+boxElement).live('click.'+prefix, clickHandler); 610 } 611 } 612 return true; 613 } 614 return false; 615 } 616 617 // Don't do anything if Colorbox already exists. 618 if ($[colorbox]) { 619 return; 620 } 621 622 // Append the HTML when the DOM loads 623 $(appendHTML); 624 625 626 // **************** 627 // PUBLIC FUNCTIONS 628 // Usage format: $.colorbox.close(); 629 // Usage from within an iframe: parent.jQuery.colorbox.close(); 630 // **************** 631 632 publicMethod = $.fn[colorbox] = $[colorbox] = function (options, callback) { 633 var settings; 634 var $obj = this; 635 636 options = options || {}; 637 638 if ($.isFunction($obj)) { // assume a call to $.colorbox 639 $obj = $('<a/>'); 640 options.open = true; 641 } 642 643 if (!$obj[0]) { // colorbox being applied to empty collection 644 return $obj; 645 } 646 647 appendHTML(); 648 649 if (addBindings()) { 650 651 if (callback) { 652 options.onComplete = callback; 653 } 654 655 $obj.each(function () { 656 var old = $.data(this, colorbox) || {}; 657 $.data(this, colorbox, $.extend(old, options)); 658 }).addClass(boxElement); 659 660 settings = new Settings($obj[0], options); 661 662 if (settings.get('open')) { 663 launch($obj[0]); 664 } 665 } 666 667 return $obj; 668 }; 669 670 publicMethod.position = function (speed, loadedCallback) { 671 var 672 css, 673 top = 0, 674 left = 0, 675 offset = $box.offset(), 676 scrollTop, 677 scrollLeft; 678 679 $window.unbind('resize.' + prefix); 680 681 // remove the modal so that it doesn't influence the document width/height 682 $box.css({top: -9e4, left: -9e4}); 683 684 scrollTop = $window.scrollTop(); 685 scrollLeft = $window.scrollLeft(); 686 687 if (settings.get('fixed')) { 688 offset.top -= scrollTop; 689 offset.left -= scrollLeft; 690 $box.css({position: 'fixed'}); 691 } else { 692 top = scrollTop; 693 left = scrollLeft; 694 $box.css({position: 'absolute'}); 695 } 696 697 // keeps the top and left positions within the browser's viewport. 698 if (settings.get('right') !== false) { 699 left += Math.max($window.width() - settings.w - loadedWidth - interfaceWidth - setSize(settings.get('right'), 'x'), 0); 700 } else if (settings.get('left') !== false) { 701 left += setSize(settings.get('left'), 'x'); 702 } else { 703 left += Math.round(Math.max($window.width() - settings.w - loadedWidth - interfaceWidth, 0) / 2); 704 } 705 706 if (settings.get('bottom') !== false) { 707 top += Math.max(winheight() - settings.h - loadedHeight - interfaceHeight - setSize(settings.get('bottom'), 'y'), 0); 708 } else if (settings.get('top') !== false) { 709 top += setSize(settings.get('top'), 'y'); 710 } else { 711 top += Math.round(Math.max(winheight() - settings.h - loadedHeight - interfaceHeight, 0) / 2); 712 } 713 714 $box.css({top: offset.top, left: offset.left, visibility:'visible'}).attr('aria-hidden', 'false'); 715 716 // this gives the wrapper plenty of breathing room so it's floated contents can move around smoothly, 717 // but it has to be shrank down around the size of div#colorbox when it's done. If not, 718 // it can invoke an obscure IE bug when using iframes. 719 $wrap[0].style.width = $wrap[0].style.height = "9999px"; 720 721 function modalDimensions() { 722 $topBorder[0].style.width = $bottomBorder[0].style.width = $content[0].style.width = (parseInt($box[0].style.width,10) - interfaceWidth)+'px'; 723 $content[0].style.height = $leftBorder[0].style.height = $rightBorder[0].style.height = (parseInt($box[0].style.height,10) - interfaceHeight)+'px'; 724 } 725 726 css = {width: settings.w + loadedWidth + interfaceWidth, height: settings.h + loadedHeight + interfaceHeight, top: top, left: left}; 727 728 // setting the speed to 0 if the content hasn't changed size or position 729 if (speed) { 730 var tempSpeed = 0; 731 $.each(css, function(i){ 732 if (css[i] !== previousCSS[i]) { 733 tempSpeed = speed; 734 return; 735 } 736 }); 737 speed = tempSpeed; 738 } 739 740 previousCSS = css; 741 742 if (!speed) { 743 $box.css(css); 744 } 745 746 $box.dequeue().animate(css, { 747 duration: speed || 0, 748 complete: function () { 749 modalDimensions(); 750 751 active = false; 752 753 // shrink the wrapper down to exactly the size of colorbox to avoid a bug in IE's iframe implementation. 754 $wrap[0].style.width = (settings.w + loadedWidth + interfaceWidth) + "px"; 755 $wrap[0].style.height = (settings.h + loadedHeight + interfaceHeight) + "px"; 756 757 if (settings.get('reposition')) { 758 setTimeout(function () { // small delay before binding onresize due to an IE8 bug. 759 $window.bind('resize.' + prefix, publicMethod.position); 760 }, 1); 761 } 762 763 if ($.isFunction(loadedCallback)) { 764 loadedCallback(); 765 } 766 }, 767 step: modalDimensions 768 }); 769 }; 770 771 publicMethod.resize = function (options) { 772 var scrolltop; 773 774 if (open) { 775 options = options || {}; 776 777 if (options.width) { 778 settings.w = setSize(options.width, 'x') - loadedWidth - interfaceWidth; 779 } 780 781 if (options.innerWidth) { 782 settings.w = setSize(options.innerWidth, 'x'); 783 } 784 785 $loaded.css({width: settings.w}); 786 787 if (options.height) { 788 settings.h = setSize(options.height, 'y') - loadedHeight - interfaceHeight; 789 } 790 791 if (options.innerHeight) { 792 settings.h = setSize(options.innerHeight, 'y'); 793 } 794 795 if (!options.innerHeight && !options.height) { 796 scrolltop = $loaded.scrollTop(); 797 $loaded.css({height: "auto"}); 798 settings.h = $loaded.height(); 799 } 800 801 $loaded.css({height: settings.h}); 802 803 if(scrolltop) { 804 $loaded.scrollTop(scrolltop); 805 } 806 807 publicMethod.position(settings.get('transition') === "none" ? 0 : settings.get('speed')); 808 } 809 }; 810 811 publicMethod.prep = function (object) { 812 if (!open) { 813 return; 814 } 815 816 var callback, speed = settings.get('transition') === "none" ? 0 : settings.get('speed'); 817 818 $loaded.remove(); 819 820 $loaded = $tag(div, 'LoadedContent').append(object); 821 822 function getWidth() { 823 settings.w = settings.w || $loaded.width(); 824 settings.w = settings.mw && settings.mw < settings.w ? settings.mw : settings.w; 825 return settings.w; 826 } 827 function getHeight() { 828 settings.h = settings.h || $loaded.height(); 829 settings.h = settings.mh && settings.mh < settings.h ? settings.mh : settings.h; 830 return settings.h; 831 } 832 833 $loaded.hide() 834 .appendTo($loadingBay.show())// content has to be appended to the DOM for accurate size calculations. 835 .css({width: getWidth(), overflow: settings.get('scrolling') ? 'auto' : 'hidden'}) 836 .css({height: getHeight()})// sets the height independently from the width in case the new width influences the value of height. 837 .prependTo($content); 838 839 $loadingBay.hide(); 840 841 // 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. 842 843 $(photo).css({'float': 'none'}); 844 845 setClass(settings.get('className')); 846 847 callback = function () { 848 var total = $related.length, 849 iframe, 850 complete; 851 852 if (!open) { 853 return; 854 } 855 856 function removeFilter() { // Needed for IE8 in versions of jQuery prior to 1.7.2 857 if ($.support.opacity === false) { 858 $box[0].style.removeAttribute('filter'); 859 } 860 } 861 862 complete = function () { 863 clearTimeout(loadingTimer); 864 $loadingOverlay.hide(); 865 trigger(event_complete); 866 settings.get('onComplete'); 867 }; 868 869 870 $title.html(settings.get('title')).show(); 871 $loaded.show(); 872 873 if (total > 1) { // handle grouping 874 if (typeof settings.get('current') === "string") { 875 $current.html(settings.get('current').replace('{current}', index + 1).replace('{total}', total)) 876 .attr('aria-live', 'polite') 877 .show(); 878 } 879 880 $showNext = (settings.get('loop') || index < total - 1); 881 $next[$showNext ? 'show' : 'hide']() 882 .html(settings.get('next')) 883 .attr('aria-hidden', $showNext ? 'false' : 'true'); 884 885 $showPrev = (settings.get('loop') || index); 886 $prev[$showPrev ? 'show' : 'hide']() 887 .html(settings.get('previous')) 888 .attr('aria-hidden', $showPrev ? 'false' : 'true'); 889 890 if (!($prev.is(':focus') || $next.is(':focus') || $close.is(':focus'))) { 891 if ($showPrev) { 892 $prev.focus(); 893 } else if ($showNext) { 894 $next.focus(); 895 } else { 896 $close.focus(); 897 } 898 } 899 900 slideshow(); 901 902 // Preloads images within a rel group 903 if (settings.get('preloading')) { 904 $.each([getIndex(-1), getIndex(1)], function(){ 905 var img, 906 i = $related[this], 907 settings = new Settings(i, $.data(i, colorbox)), 908 src = settings.get('href'); 909 910 if (src && isImage(settings, src)) { 911 src = retinaUrl(settings, src); 912 img = document.createElement('img'); 913 img.src = src; 914 } 915 }); 916 } 917 } else { 918 $groupControls.hide(); 919 } 920 921 if (settings.get('iframe')) { 922 923 iframe = settings.get('createIframe'); 924 925 if (!settings.get('scrolling')) { 926 iframe.scrolling = "no"; 927 } 928 929 $(iframe) 930 .attr({ 931 src: settings.get('href'), 932 'class': prefix + 'Iframe' 933 }) 934 .one('load', complete) 935 .appendTo($loaded); 936 937 $events.one(event_purge, function () { 938 iframe.src = "//about:blank"; 939 }); 940 941 if (settings.get('fastIframe')) { 942 $(iframe).trigger('load'); 943 } 944 } else { 945 complete(); 946 } 947 948 if (settings.get('transition') === 'fade') { 949 $box.fadeTo(speed, 1, removeFilter); 950 } else { 951 removeFilter(); 952 } 953 }; 954 955 if (settings.get('transition') === 'fade') { 956 $box.fadeTo(speed, 0, function () { 957 publicMethod.position(0, callback); 958 }); 959 } else { 960 publicMethod.position(speed, callback); 961 } 962 }; 963 964 function load () { 965 var href, setResize, prep = publicMethod.prep, $inline, request = ++requests; 966 967 active = true; 968 969 photo = false; 970 971 trigger(event_purge); 972 trigger(event_load); 973 settings.get('onLoad'); 974 975 settings.h = settings.get('height') ? 976 setSize(settings.get('height'), 'y') - loadedHeight - interfaceHeight : 977 settings.get('innerHeight') && setSize(settings.get('innerHeight'), 'y'); 978 979 settings.w = settings.get('width') ? 980 setSize(settings.get('width'), 'x') - loadedWidth - interfaceWidth : 981 settings.get('innerWidth') && setSize(settings.get('innerWidth'), 'x'); 982 983 // Sets the minimum dimensions for use in image scaling 984 settings.mw = settings.w; 985 settings.mh = settings.h; 986 987 // Re-evaluate the minimum width and height based on maxWidth and maxHeight values. 988 // If the width or height exceed the maxWidth or maxHeight, use the maximum values instead. 989 if (settings.get('maxWidth')) { 990 settings.mw = setSize(settings.get('maxWidth'), 'x') - loadedWidth - interfaceWidth; 991 settings.mw = settings.w && settings.w < settings.mw ? settings.w : settings.mw; 992 } 993 if (settings.get('maxHeight')) { 994 settings.mh = setSize(settings.get('maxHeight'), 'y') - loadedHeight - interfaceHeight; 995 settings.mh = settings.h && settings.h < settings.mh ? settings.h : settings.mh; 996 } 997 998 href = settings.get('href'); 999 1000 loadingTimer = setTimeout(function () { 1001 $loadingOverlay.show(); 1002 }, 100); 1003 1004 if (settings.get('inline')) { 1005 var $target = $(href).eq(0); 1006 // Inserts an empty placeholder where inline content is being pulled from. 1007 // An event is bound to put inline content back when Colorbox closes or loads new content. 1008 $inline = $('<div>').hide().insertBefore($target); 1009 1010 $events.one(event_purge, function () { 1011 $inline.replaceWith($target); 1012 }); 1013 1014 prep($target); 1015 } else if (settings.get('iframe')) { 1016 // IFrame element won't be added to the DOM until it is ready to be displayed, 1017 // to avoid problems with DOM-ready JS that might be trying to run in that iframe. 1018 prep(" "); 1019 } else if (settings.get('html')) { 1020 prep(settings.get('html')); 1021 } else if (isImage(settings, href)) { 1022 1023 href = retinaUrl(settings, href); 1024 1025 photo = settings.get('createImg'); 1026 1027 $(photo) 1028 .addClass(prefix + 'Photo') 1029 .bind('error.'+prefix,function () { 1030 prep($tag(div, 'Error').html(settings.get('imgError'))); 1031 }) 1032 .one('load', function () { 1033 if (request !== requests) { 1034 return; 1035 } 1036 1037 // A small pause because some browsers will occasionally report a 1038 // img.width and img.height of zero immediately after the img.onload fires 1039 setTimeout(function(){ 1040 var percent; 1041 1042 if (settings.get('retinaImage') && window.devicePixelRatio > 1) { 1043 photo.height = photo.height / window.devicePixelRatio; 1044 photo.width = photo.width / window.devicePixelRatio; 1045 } 1046 1047 if (settings.get('scalePhotos')) { 1048 setResize = function () { 1049 photo.height -= photo.height * percent; 1050 photo.width -= photo.width * percent; 1051 }; 1052 if (settings.mw && photo.width > settings.mw) { 1053 percent = (photo.width - settings.mw) / photo.width; 1054 setResize(); 1055 } 1056 if (settings.mh && photo.height > settings.mh) { 1057 percent = (photo.height - settings.mh) / photo.height; 1058 setResize(); 1059 } 1060 } 1061 1062 if (settings.h) { 1063 photo.style.marginTop = Math.max(settings.mh - photo.height, 0) / 2 + 'px'; 1064 } 1065 1066 if ($related[1] && (settings.get('loop') || $related[index + 1])) { 1067 photo.style.cursor = 'pointer'; 1068 1069 $(photo).bind('click.'+prefix, function () { 1070 publicMethod.next(); 1071 }); 1072 } 1073 1074 photo.style.width = photo.width + 'px'; 1075 photo.style.height = photo.height + 'px'; 1076 prep(photo); 1077 }, 1); 1078 }); 1079 1080 photo.src = href; 1081 1082 } else if (href) { 1083 $loadingBay.load(href, settings.get('data'), function (data, status) { 1084 if (request === requests) { 1085 prep(status === 'error' ? $tag(div, 'Error').html(settings.get('xhrError')) : $(this).contents()); 1086 } 1087 }); 1088 } 1089 } 1090 1091 // Navigates to the next page/image in a set. 1092 publicMethod.next = function () { 1093 if (!active && $related[1] && (settings.get('loop') || $related[index + 1])) { 1094 index = getIndex(1); 1095 launch($related[index]); 1096 } 1097 }; 1098 1099 publicMethod.prev = function () { 1100 if (!active && $related[1] && (settings.get('loop') || index)) { 1101 index = getIndex(-1); 1102 launch($related[index]); 1103 } 1104 }; 1105 1106 // Note: to use this within an iframe use the following format: parent.jQuery.colorbox.close(); 1107 publicMethod.close = function () { 1108 if (open && !closing) { 1109 1110 closing = true; 1111 open = false; 1112 trigger(event_cleanup); 1113 settings.get('onCleanup'); 1114 $window.unbind('.' + prefix); 1115 $overlay.fadeTo(settings.get('fadeOut') || 0, 0); 1116 1117 $box.stop().fadeTo(settings.get('fadeOut') || 0, 0, function () { 1118 $box.hide().attr('aria-hidden', 'true'); 1119 $overlay.hide(); 1120 trigger(event_purge); 1121 $loaded.remove(); 1122 1123 setTimeout(function () { 1124 closing = false; 1125 trigger(event_closed); 1126 settings.get('onClosed'); 1127 }, 1); 1128 }); 1129 } 1130 }; 1131 1132 // Removes changes Colorbox made to the document, but does not remove the plugin. 1133 publicMethod.remove = function () { 1134 if (!$box) { return; } 1135 1136 $box.stop(); 1137 $[colorbox].close(); 1138 $box.stop(false, true).remove(); 1139 $overlay.remove(); 1140 closing = false;
1141 $box = null; 1142 $('.' + boxElement) 1143 .removeData(colorbox) 1144 .removeClass(boxElement); 1145 1146 $(document).unbind('click.'+prefix).unbind('keydown.'+prefix); 1147 }; 1148 1149 // A method for fetching the current element Colorbox is referencing. 1150 // returns a jQuery object. 1151 publicMethod.element = function () { 1152 return $(settings.el); 1153 }; 1154 1155 publicMethod.settings = defaults; 1156 1157}(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.