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