PageSourceSearch

https://www.modulebazaar.com/skin/frontend/modulebazaar/default/js/colorbox.js

js modulebazaar.com collected 2026-10-01 11:53:47 UTC 27,412 bytes, 1,023 lines download raw bytes

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

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.