1// ColorBox v1.3.14 - a full featured, light-weight, customizable lightbox based on jQuery 1.3+ 2// Copyright (c) 2010 Jack Moore - [email protected] 3// Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php 4// Amelioree pour SPIP 5 6(function ($, window) { 7 8 var 9 // ColorBox Default Settings. 10 // See http://colorpowered.com/colorbox for details. 11 defaults = { 12 transition: "elastic", 13 speed: 300, 14 width: false, 15 initialWidth: "600", 16 innerWidth: false, 17 maxWidth: false, 18 minWidth:false, 19 height: false, 20 initialHeight: "450", 21 innerHeight: false, 22 maxHeight: false, 23 minHeight:false, 24 scalePhotos: true, 25 scrolling: true, 26 inline: false, 27 html: false, 28 iframe: false, 29 photo: false, 30 href: false, 31 title: false, 32 rel: false, 33 opacity: 0.9, 34 preloading: true, 35 current: "image {current} of {total}", 36 previous: "previous", 37 next: "next", 38 close: "close", 39 open: false, 40 returnFocus: true, 41 loop: true, 42 slideshow: false, 43 slideshowAuto: true, 44 slideshowSpeed: 2500, 45 slideshowStart: "start slideshow", 46 slideshowStop: "stop slideshow", 47 onOpen: false, 48 onLoad: false, 49 onComplete: false, 50 onCleanup: false, 51 onClosed: false, 52 overlayClose: true, 53 escKey: true, 54 arrowKey: true 55 }, 56 57 // Abstracting the HTML and event identifiers for easy rebranding 58 colorbox = 'colorbox', 59 prefix = 'cbox', 60 61 // Events 62 event_open = prefix + '_open', 63 event_load = prefix + '_load', 64 event_complete = prefix + '_complete', 65 event_cleanup = prefix + '_cleanup', 66 event_closed = prefix + '_closed', 67 event_purge = prefix + '_purge', 68 event_loaded = prefix + '_loaded', 69 70 // Special Handling for IE
71 isIE = $.browser.msie && !$.support.opacity, // feature detection alone gave a false positive on at least one phone browser and on some development versions of Chrome. 72 isIE6 = isIE && $.browser.version < 7, 73 event_ie6 = prefix + '_IE6', 74 75 // Cached jQuery Object Variables 76 $overlay, 77 $box, 78 $wrap, 79 $content, 80 $topBorder, 81 $leftBorder, 82 $rightBorder, 83 $bottomBorder, 84 $related, 85 $window, 86 $loaded, 87 $loadingBay, 88 $loadingOverlay, 89 $title, 90 $current, 91 $slideshow, 92 $next, 93 $prev, 94 $close, 95 96 // Variables for cached values or use across multiple functions 97 interfaceHeight, 98 interfaceWidth, 99 loadedHeight, 100 loadedWidth, 101 element, 102 index, 103 settings, 104 open, 105 active, 106 closing = false, 107 108 publicMethod, 109 boxElement = prefix + 'Element'; 110 111 // **************** 112 // HELPER FUNCTIONS 113 // **************** 114 115 // jQuery object generator to reduce code size 116 function $div(id, css) { 117 id = id ? ' id="' + prefix + id + '"' : ''; 118 css = css ? ' style="' + css + '"' : ''; 119 return $('<div' + id + css + '/>'); 120 } 121 122 // Convert % values to pixels 123 function setSize(size, dimension) { 124 dimension = dimension === 'x' ? $window.width() : $window.height(); 125 return (typeof size === 'string') ? Math.round((/%/.test(size) ? (dimension / 100) * parseInt(size, 10) : parseInt(size, 10))) : size; 126 } 127 128 // Checks an href to see if it is a photo. 129 // There is a force photo option (photo: true) for hrefs that cannot be matched by this regex. 130 function isImage(url) { 131 return settings.photo || /\.(gif|png|jpg|jpeg|bmp)(?:\?([^#]*))?(?:#(\.*))?$/i.test(url); 132 } 133 134 // Assigns function results to their respective settings. This allows functions to be used as values. 135 function process(settings) { 136 for (var i in settings) { 137 if ($.isFunction(settings[i]) && i.substring(0, 2) !== 'on') { // checks to make sure the function isn't one of the callbacks, they will be handled at the appropriate time. 138 settings[i] = settings[i].call(element); 139 } 140 } 141 settings.rel = settings.rel || element.rel || 'nofollow'; 142 settings.href = settings.href || $(element).attr('href'); 143 settings.title = settings.title || element.title; 144 return settings; 145 } 146 147 function trigger(event, callback) { 148 if (callback) { 149 callback.call(element); 150 } 151 $.event.trigger(event); 152 } 153 154 // Slideshow functionality 155 function slideshow() { 156 var 157 timeOut, 158 className = prefix + "Slideshow_", 159 click = "click." + prefix, 160 start, 161 stop, 162 clear; 163 164 if (settings.slideshow && $related[1]) { 165 start = function () { 166 $slideshow 167 .text(settings.slideshowStop) 168 .unbind(click) 169 .bind(event_complete, function () { 170 if (index < $related.length - 1 || settings.loop) { 171 timeOut = setTimeout(publicMethod.next, settings.slideshowSpeed); 172 } 173 }) 174 .bind(event_load, function () { 175 clearTimeout(timeOut); 176 }) 177 .one(click + ' ' + event_cleanup, stop); 178 $box.removeClass(className + "off").addClass(className + "on"); 179 timeOut = setTimeout(publicMethod.next, settings.slideshowSpeed); 180 }; 181 182 stop = function () { 183 clearTimeout(timeOut); 184 $slideshow 185 .text(settings.slideshowStart) 186 .unbind([event_complete, event_load, event_cleanup, click].join(' ')) 187 .one(click, start); 188 $box.removeClass(className + "on").addClass(className + "off"); 189 }; 190 191 if (settings.slideshowAuto) { 192 start(); 193 } else { 194 stop(); 195 } 196 } 197 } 198 199 function launch(elem) { 200 if (!closing) { 201 202 element = elem; 203 204 settings = process($.extend({}, $.data(element, colorbox))); 205 206 $related = $(element); 207 208 index = 0; 209 210 if (settings.rel !== 'nofollow') { 211 $related = $('.' + boxElement).filter(function () { 212 var relRelated = $.data(this, colorbox).rel || this.rel; 213 return (relRelated === settings.rel); 214 }); 215 index = $related.index(element); 216 217 // Check direct calls to ColorBox. 218 if (index === -1) { 219 $related = $related.add(element); 220 index = $related.length - 1; 221 } 222 } 223 224 if (!open) { 225 open = active = true; // Prevents the page-change action from queuing up if the visitor holds down the left or right
225keys. 226 227 $box.show(); 228 229 if (settings.returnFocus) { 230 try { 231 element.blur(); 232 $(element).one(event_closed, function () { 233 try { 234 this.focus(); 235 } catch (e) { 236 // do nothing 237 } 238 }); 239 } catch (e) { 240 // do nothing 241 } 242 } 243 244 // +settings.opacity avoids a problem in IE when using non-zero-prefixed-string-values, like '.5' 245 $overlay.css({"opacity": +settings.opacity, "cursor": settings.overlayClose ? "pointer" : "auto"}).show(); 246 247 // Opens inital empty ColorBox prior to content being loaded. 248 settings.w = setSize(settings.initialWidth, 'x'); 249 settings.h = setSize(settings.initialHeight, 'y'); 250 publicMethod.position(0); 251 252 if (isIE6) { 253 $window.bind('resize.' + event_ie6 + ' scroll.' + event_ie6, function () { 254 $overlay.css({width: $window.width(), height: $window.height(), top: $window.scrollTop(), left: $window.scrollLeft()}); 255 }).trigger('scroll.' + event_ie6); 256 } 257 258 trigger(event_open, settings.onOpen); 259 260 $current.add($prev).add($next).add($slideshow).add($title).hide(); 261 262 $close.html(settings.close).show(); 263 } 264 265 publicMethod.load(true); 266 } 267 } 268 269 // **************** 270 // PUBLIC FUNCTIONS 271 // Usage format: $.fn.colorbox.close(); 272 // Usage from within an iframe: parent.$.fn.colorbox.close(); 273 // **************** 274 275 publicMethod = $.fn[colorbox] = $[colorbox] = function (options, callback) { 276 var $this = this, autoOpen; 277 278 if (!$this[0] && $this.selector) { // if a selector was given and it didn't match any elements, go ahead and exit. 279 return $this; 280 } 281 282 options = options || {}; 283 284 if (callback) { 285 options.onComplete = callback; 286 } 287 288 if (!$this[0] || $this.selector === undefined) { // detects $.colorbox() and $.fn.colorbox() 289 $this = $('<a/>'); 290 options.open = true; // assume an immediate open 291 } 292 293 $this.each(function () { 294 $.data(this, colorbox, $.extend({}, $.data(this, colorbox) || defaults, options)); 295 var eltclass = $(this).attr('class') ? $(this).attr('class') : ' '; 296 297 if (eltclass.indexOf("boxWidth-")!==-1) { 298 var w = eltclass.match(/boxWidth-([^\s'">]*)/); 299 w = w[1].replace(/pc/,'%'); // % not allowed in html attribute ; use 100pc instead of 100% 300 $.data(this, colorbox, $.extend($.data(this, colorbox),{width:w})); 301 } 302 if (eltclass.indexOf("boxHeight-")!==-1) { 303 var h = eltclass.match(/boxHeight-([^\s'">]*)/); 304 h = h[1].replace(/pc/,'%'); // % not allowed in html attribute ; use 100pc instead of 100% 305 $.data(this, colorbox, $.extend($.data(this, colorbox),{height:h})); 306 } 307 if (eltclass.indexOf("boxIframe")!==-1) { 308 $.data(this, colorbox, $.extend($.data(this, colorbox),{iframe:true})); 309 } 310 if (eltclass.indexOf("boxSlideshow_off")!==-1) { 311 $.data(this, colorbox, $.extend($.data(this, colorbox),{slideshow:false})); 312 } 313 $(this).addClass(boxElement); 314 }); 315 316 autoOpen = options.open; 317 318 if ($.isFunction(autoOpen)) { 319 autoOpen = autoOpen.call($this); 320 } 321 322 if (autoOpen) { 323 launch($this[0]); 324 } 325 326 return $this; 327 }; 328 329 // Initialize ColorBox: store common calculations, preload the interface graphics, append the html. 330 // This preps colorbox for a speedy open when clicked, and lightens the burdon on the browser by only 331 // having to run once, instead of each time colorbox is opened. 332 publicMethod.init = function () { 333 // Create & Append jQuery Objects 334 $window = $(window); 335 $box = $div().attr({id: colorbox, 'class': isIE ? prefix + 'IE' : ''}); 336 $overlay = $div("Overlay", isIE6 ? 'position:absolute' : '').hide(); 337 338 $wrap = $div("Wrapper"); 339 $content = $div("Content").append( 340 $loaded = $div("LoadedContent", 'width:0; height:0; overflow:hidden'), 341 $loadingOverlay = $div("LoadingOverlay").add($div("LoadingGraphic")), 342 $title = $div("Title"), 343 $current = $div("Current"), 344 $next = $div("Next"), 345 $prev = $div("Previous"), 346 $slideshow = $div("Slideshow").bind(event_open, slideshow), 347 $close = $div("Close") 348 ); 349 $wrap.append( // The 3x3 Grid that makes up ColorBox 350 $div().append( 351 $div("TopLeft"), 352 $topBorder = $div("TopCenter"), 353 $div("TopRight") 354 ), 355 $div(false, 'clear:left').append( 356 $leftBorder = $div("MiddleLeft"), 357 $content, 358 $rightBorder = $div("MiddleRight") 359 ), 360 $div(false, 'clear:left').append( 361 $div("BottomLeft"), 362 $bottomBorder = $div("BottomCenter"), 363 $div("BottomRight") 364 ) 365 ).children().children().css({'float': 'left'}); 366 367 $loadingBay = $div(false, 'position:absolute; width:9999px; visibility:hidden; display:none'); 368 369 $('body').prepend($overlay, $box.append($wrap, $loadingBay)); 370 371 $content.children() 372 .hover(function () { 373 $(this).addClass('hover'); 374 }, function () { 375 $(this).removeClass('hover'); 376 }).addClass('hover'); 377 378 // Cache values needed for size calculations 379 interfaceHeight = $topBorder.height() + $bottomBorder.height() + $content.outerHeight(true) - $content.height();//Subtraction needed for IE6 380 interfaceWidth = $leftBorder.width() + $rightBorder.width() + $content.outerWidth(true) - $content.width(); 381 loadedHeight = $loaded.outerHeight(true); 382 loadedWidth = $loaded.outerWidth(true); 383 384 // Setting padding to remove the need to do size conversions during the animation step. 385 $box.css({"padding-bottom": interfaceHeight, "padding-right": interfaceWidth}).hide(); 386 387 // Setup button events. 388 $next.click(publicMethod.next); 389 $prev.click(publicMethod.prev); 390 $close.click(publicMethod.close); 391 392 // Adding the 'hover' class allowed the browser to load the hover-state 393 // background graphics. The class can now can be removed. 394 $content.children().removeClass('hover'); 395 396 $('.' + boxElement).live('click', function (e) { 397 // checks to see if it was a non-left mouse-click and for clicks modified with ctrl, shift, or alt. 398 if (!((e.button !== 0 && typeof e.button !== 'undefined') || e.ctrlKey || e.shiftKey || e.altKey)) { 399 e.preventDefault(); 400 launch(this); 401 } 402 }); 403 404 $overlay.click(function () { 405 if (settings.overlayClose) { 406 publicMethod.close(); 407 } 408 }); 409 410 // Set Navigation Key Bindings 411 $(document).bind("keydown", function (e) { 412 if (open && settings.escKey && e.keyCode === 27) { 413 e.preventDefault(); 414 publicMethod.close(); 415 } 416 if (open && settings.arrowKey && !active && $related[1]) { 417 if (e.keyCode === 37 && (index || settings.loop)) { 418 e.preventDefault(); 419 $prev.click(); 420 } else if (e.keyCode === 39 && (index < $related.length - 1 || settings.loop)) { 421 e.preventDefault(); 422 $next.click(); 423 } 424 } 425 }); 426 }; 427 428 publicMethod.remove = function () { 429 $box.add($overlay).remove(); 430 $('.' + boxElement).die('click').removeData(colorbox).removeClass(boxElement); 431 }; 432 433 publicMethod.position = function (speed, loadedCallback) { 434 var 435 animate_speed, 436 // keeps the top and left positions within the browser's viewport. 437 posTop = Math.max(document.documentElement.clientHeight - settings.h - loadedHeight - interfaceHeight, 0) / 2 + $window.scrollTop(), 438 posLeft = Math.max($window.width() - settings.w - loadedWidth - interfaceWidth, 0) / 2 + $window.scrollLeft(); 439 440 // setting the speed to 0 to reduce the delay between same-sized content. 441 animate_speed = ($box.width() === settings.w + loadedWidth && $box.height() === settings.h + loadedHeight) ? 0 : speed; 442 443 // this gives the wrapper plenty of breathing room so it's floated contents can move around smoothly, 444 // but it has to be shrank down around the size of div#colorbox when it's done. If not, 445 // it can invoke an obscure IE bug when using iframes. 446 $wrap[0].style.width = $wrap[0].style.height = "9999px"; 447 448 function modalDimensions(that) { 449 // loading overlay height has to be explicitly set for IE6. 450 $topBorder[0].style.width = $bottomBorder[0].style.width = $content[0].style.width = that.style.width; 451 $loadingOverlay[0].style.height = $loadingOverlay[1].style.height = $content[0].style.height = $leftBorder[0].style.height = $rightBorder[0].style.height = that.style.height; 452 } 453 454 $box.dequeue().animate({width: settings.w + loadedWidth, height: settings.h + loadedHeight, top: posTop, left: posLeft}, { 455 duration: animate_speed, 456 complete: function () { 457 modalDimensions(this); 458 459 active = false; 460 461 // shrink the wrapper down to exactly the size of colorbox to avoid a bug in IE's iframe implementation. 462 $wrap[0].style.width = (settings.w + loadedWidth + interfaceWidth) + "px"; 463 $wrap[0].style.height = (settings.h + loadedHeight + interfaceHeight) + "px"; 464 465 if (loadedCallback) { 466 loadedCallback(); 467 } 468 }, 469 step: function () { 470 modalDimensions(this); 471 } 472 }); 473 }; 474 475 publicMethod.resize = function (options) { 476 if (open) { 477 options = options || {}; 478 479 if (options.width) { 480 settings.w = setSize(options.width, 'x') - loadedWidth - interfaceWidth; 481 } 482 if (options.innerWidth) { 483 settings.w = setSize(options.innerWidth, 'x'); 484 } 485 $loaded.css({width: settings.w}); 486 487 if (options.height) { 488 settings.h = setSize(options.height, 'y') - loadedHeight - interfaceHeight; 489 } 490 if (options.innerHeight) { 491 settings.h = setSize(options.innerHeight, 'y'); 492 } 493 if (!options.innerHeight && !options.height) { 494 var $child = $loaded.wrapInner("<div style='overflow:auto'></div>").children(); // temporary wrapper to get an accurate estimate of just how high the total content should be. 495 settings.h = $child.height(); 496 $child.replaceWith($child.children()); // ditch the temporary wrapper div used in height calculation 497 } 498 $loaded.css({height: settings.h}); 499 500 publicMethod.position(settings.transition === "none" ? 0 : settings.speed); 501 } 502 }; 503 504 publicMethod.prep = function (object) { 505 if (!open) { 506 return; 507 } 508 509 var photo, 510 speed = settings.transition === "none" ? 0 : settings.speed; 511 512 $window.unbind('resize.' + prefix); 513 $loaded.remove(); 514 $loaded = $div('LoadedContent').html(object); 515 516 function getWidth() { 517 settings.w = settings.w || $loaded.width(); 518 settings.w = settings.minw && settings.minw > settings.w ? settings.minw : settings.w; 519 settings.w = settings.mw && settings.mw < settings.w ? settings.mw : settings.w; 520 return settings.w; 521 } 522 function getHeight() { 523 settings.h = settings.h || $loaded.height(); 524 settings.h = settings.minh && settings.minh > settings.h ? settings.minh : settings.h; 525 settings.h = settings.mh && settings.mh < settings.h ? settings.mh : settings.h; 526 return settings.h; 527 } 528 529 $loaded.hide() 530 .appendTo($loadingBay.show())// content has to be appended to the DOM for accurate size calculations. 531 .css({width: getWidth(), overflow: settings.scrolling ? 'auto' : 'hidden'}) 532 .css({height: getHeight()})// sets the height independently from the width in case the new width influences the value of height.
533 .prependTo($content); 534 535 $loadingBay.hide(); 536 537 // 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. 538 $('#' + prefix + 'Photo').css({cssFloat: 'none', marginLeft: 'auto', marginRight: 'auto'}); 539 540 // Hides SELECT elements in IE6 because they would otherwise sit on top of the overlay. 541 if (isIE6) { 542 $('select').not($box.find('select')).filter(function () { 543 return this.style.visibility !== 'hidden'; 544 }).css({'visibility': 'hidden'}).one(event_cleanup, function () { 545 this.style.visibility = 'inherit'; 546 }); 547 } 548 549 function setPosition(s) { 550 var prev, prevSrc, next, nextSrc, total = $related.length, loop = settings.loop; 551 publicMethod.position(s, function () { 552 function defilter() { 553 if (isIE) { 554 //IE adds a filter when ColorBox fades in and out that can cause problems if the loaded content contains transparent pngs. 555 $box[0].style.filter = false; 556 } 557 } 558 559 if (!open) { 560 return; 561 } 562 563 if (isIE) { 564 //This fadeIn helps the bicubic resampling to kick-in. 565 if (photo) { 566 $loaded.fadeIn(100); 567 } 568 } 569 570 $loaded.show(); 571 572 trigger(event_loaded); 573
574 $title.show().html(settings.title); 575 576 if (total > 1) { // handle grouping 577 if (typeof settings.current === "string") { 578 $current.html(settings.current.replace(/\{current\}/, index + 1).replace(/\{total\}/, total)).show(); 579 } 580 581 $next[(loop || index < total - 1) ? "show" : "hide"]().html(settings.next); 582 $prev[(loop || index) ? "show" : "hide"]().html(settings.previous); 583 584 prev = index ? $related[index - 1] : $related[total - 1]; 585 next = index < total - 1 ? $related[index + 1] : $related[0]; 586 587 if (settings.slideshow) { 588 $slideshow.show(); 589 } 590 591 // Preloads images within a rel group 592 if (settings.preloading) { 593 nextSrc = $.data(next, colorbox).href || next.href; 594 prevSrc = $.data(prev, colorbox).href || prev.href; 595 596 nextSrc = $.isFunction(nextSrc) ? nextSrc.call(next) : nextSrc; 597 prevSrc = $.isFunction(prevSrc) ? prevSrc.call(prev) : prevSrc; 598 599 if (isImage(nextSrc)) { 600 $('<img/>')[0].src = nextSrc; 601 } 602 603 if (isImage(prevSrc)) { 604 $('<img/>')[0].src = prevSrc; 605 } 606 } 607 } 608 609 $loadingOverlay.hide(); 610 611 if (settings.transition === 'fade') { 612 $box.fadeTo(speed, 1, function () { 613 defilter(); 614 }); 615 } else { 616 defilter(); 617 } 618 619 $window.bind('resize.' + prefix, function () { 620 publicMethod.position(0); 621 }); 622 623 trigger(event_complete, settings.onComplete); 624 }); 625 } 626 627 if (settings.transition === 'fade') { 628 $box.fadeTo(speed, 0, function () { 629 setPosition(0); 630 }); 631 } else { 632 setPosition(speed); 633 } 634 }; 635 636 publicMethod.load = function (launched) { 637 var href, img, setResize, prep = publicMethod.prep; 638 639 active = true; 640 element = $related[index]; 641 642 if (!launched) { 643 settings = process($.extend({}, $.data(element, colorbox))); 644 } 645 646 trigger(event_purge); 647 648 trigger(event_load, settings.onLoad); 649 650 settings.h = settings.height ? 651 setSize(settings.height, 'y') - loadedHeight - interfaceHeight : 652 settings.innerHeight && setSize(settings.innerHeight, 'y'); 653 654 settings.w = settings.width ? 655 setSize(settings.width, 'x') - loadedWidth - interfaceWidth : 656 settings.innerWidth && setSize(settings.innerWidth, 'x'); 657 658 // Sets the minimum dimensions for use in image scaling 659 settings.mw = settings.w; 660 settings.mh = settings.h; 661 settings.minw = settings.w; 662 settings.minh = settings.h; 663 664 // Re-evaluate the minimum width and height based on maxWidth and maxHeight values. 665 // If the width or height exceed the maxWidth or maxHeight, use the maximum values instead. 666 if (settings.maxWidth) { 667 settings.mw = setSize(settings.maxWidth, 'x') - loadedWidth - interfaceWidth; 668 settings.mw = settings.w && settings.w < settings.mw ? settings.w : settings.mw; 669 } 670 if(settings.minWidth){ 671 settings.minw = setSize(settings.minWidth, 'x') - loadedWidth - interfaceWidth; 672 settings.minw = settings.w && settings.w > settings.minw ? settings.w : settings.minw; 673 } 674 if (settings.maxHeight) { 675 settings.mh = setSize(settings.maxHeight, 'y') - loadedHeight - interfaceHeight; 676 settings.mh = settings.h && settings.h < settings.mh ? settings.h : settings.mh; 677 } 678 if(settings.minHeight){ 679 settings.minh = setSize(settings.minHeight, 'y') - loadedHeight - interfaceHeight; 680 settings.minh = settings.h && settings.h > settings.minh ? settings.h : settings.minh; 681 } 682 683 href = settings.href; 684 685 $loadingOverlay.show(); 686 687 if (settings.inline) { 688 // Inserts an empty placeholder where inline content is being pulled from. 689 // An event is bound to put inline content back when ColorBox closes or loads new content. 690 $div().hide().insertBefore($(href)[0]).one(event_purge, function () { 691 $(this).replaceWith($loaded.children()); 692 }); 693 prep($(href)); 694 } else if (settings.iframe) { 695 // IFrame element won't be added to the DOM until it is ready to be displayed, 696 // to avoid problems with DOM-ready JS that might be trying to run in that iframe. 697 $box.one(event_loaded, function () { 698 var $iframe = $("<iframe name='" + new Date().getTime() + "' frameborder=0" + (settings.scrolling ? "" : " scrolling='no'") + (isIE ? " allowtransparency='true'" : '') + " style='width:100%; height:100%; border:0; display:block;'/>"); 699 $iframe[0].src = settings.href; 700 $iframe.appendTo($loaded).one(event_purge, function () { 701 $iframe[0].src = '//about:blank'; 702 }); 703 }); 704 705 prep(" "); 706 } else if (settings.html) { 707 prep(settings.html); 708 } else if (isImage(href)) { 709 img = new Image(); 710 img.onload = function () { 711 var percent; 712 img.onload = null; 713 img.id = prefix + 'Photo'; 714 $(img).css({border: 'none', display: 'block', cssFloat: 'left'}); 715 if (settings.scalePhotos) { 716 setResize = function () { 717 img.height -= img.height * percent; 718 img.width -= img.width * percent; 719 }; 720 if (settings.mw && img.width > settings.mw) { 721 percent = (img.width - settings.mw) / img.width; 722 setResize(); 723 } 724 if (settings.mh && img.height > settings.mh) { 725 percent = (img.height - settings.mh) / img.height; 726 setResize(); 727 } 728 } 729 730 if (settings.h) {
731 img.style.marginTop = Math.max(settings.h - img.height, 0) / 2 + 'px'; 732 } 733 734 if ($related[1] && (index < $related.length - 1 || settings.loop)) { 735 $(img).css({cursor: 'pointer'}).click(publicMethod.next); 736 } 737 738 if (isIE) { 739 img.style.msInterpolationMode = 'bicubic'; 740 } 741 742 setTimeout(function () { // Chrome will sometimes report a 0 by 0 size if there isn't pause in execution 743 prep(img); 744 }, 1); 745 }; 746 747 setTimeout(function () { // Opera 10.6+ will sometimes load the src before the onload function is set 748 img.src = href; 749 }, 1); 750 } else if (href) { 751 $loadingBay.load(href, function (data, status, xhr) { 752 prep(status === 'error' ? 'Request unsuccessful: ' + xhr.statusText : $(this).children()); 753 }); 754 } 755 }; 756 757 // Navigates to the next page/image in a set. 758 publicMethod.next = function () { 759 if (!active) { 760 index = index < $related.length - 1 ? index + 1 : 0; 761 publicMethod.load(); 762 } 763 }; 764 765 publicMethod.prev = function () { 766 if (!active) { 767 index = index ? index - 1 : $related.length - 1; 768 publicMethod.load(); 769 } 770 }; 771 772 // Note: to use this within an iframe use the following format: parent.$.fn.colorbox.close(); 773 publicMethod.close = function () { 774 if (open && !closing) { 775 closing = true; 776 777 open = false; 778 779 trigger(event_cleanup, settings.onCleanup); 780 781 $window.unbind('.' + prefix + ' .' + event_ie6); 782 783 $overlay.fadeTo('fast', 0); 784 785 $box.stop().fadeTo('fast', 0, function () { 786 787 trigger(event_purge); 788 789 $loaded.remove(); 790 791 $box.add($overlay).css({'opacity': 1, cursor: 'auto'}).hide(); 792 793 setTimeout(function () { 794 closing = false; 795 trigger(event_closed, settings.onClosed); 796 }, 1); 797 }); 798 } 799 }; 800 801 // A method for fetching the current element ColorBox is referencing. 802 // returns a jQuery object. 803 publicMethod.element = function () { 804 return $(element); 805 }; 806 807 publicMethod.settings = defaults; 808 809 // Initializes ColorBox when the DOM has loaded 810 $(publicMethod.init); 811 812}(jQuery, 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.