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