PageSourceSearch

https://gingerbaker.com/jquery.colorbox.js

js gingerbaker.com collected 2026-10-02 12:37:28 UTC 27,832 bytes, 1,062 lines download raw bytes

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