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