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