PageSourceSearch

https://www.ocist.org/ocist/modules/mod_s5_box/js/jquery.colorbox.js

js ocist.org collected 2026-10-02 08:10:08 UTC 26,274 bytes, 952 lines download raw bytes

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

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