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