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