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