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