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