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