PageSourceSearch

https://swende.se/colorbox-master/jquery.colorbox.js

js swende.se collected 2026-10-03 22:53:51 UTC 27,763 bytes, 1,025 lines download raw bytes

1/*!
2	jQuery ColorBox v1.4.3 - 2013-02-18
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.9,
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: "previous",
43		next: "next",
44		close: "close",
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(settings, url) {
170		return settings.photo || settings.photoRegex.test(url);
171	}
172
173	function retinaUrl(settings, url) {
174		return settings.retinaUrl && window.devicePixelRatio > 1 ? url.replace(settings.photoRegex, settings.retinaSuffix) : url;
175	}
176
177	function trapFocus(e) {
178		if ('contains' in $box[0] && !$box[0].contains(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            $overlay.css({
322                opacity: parseFloat(settings.opacity),
323                cursor: settings.overlayClose ? "pointer" : "auto",
324                visibility: 'visible'
325            }).show();
326            
327			if (!open) {
328				open = active = true; // Prevents the page-change action from queuing up if the visitor holds down the left or right keys.
329				
330				// Show colorbox so the sizes can be calculated in older versions of jQuery
331				$box.css({visibility:'hidden', display:'block'});
332				
333				$loaded = $tag(div, 'LoadedContent', 'width:0; height:0; overflow:hidden').appendTo($content);
334
335				// Cache values needed for size calculations
336				interfaceHeight = $topBorder.height() + $bottomBorder.height() + $content.outerHeight(true) - $content.height();//Subtraction needed for IE6
337				interfaceWidth = $leftBorder.width() + $rightBorder.width() + $content.outerWidth(true) - $content.width();
338				loadedHeight = $loaded.outerHeight(true);
339				loadedWidth = $loaded.outerWidth(true);
340				
341				
342				// Opens inital empty ColorBox prior to content being loaded.
343				settings.w = setSize(settings.initialWidth, 'x');
344				settings.h = setSize(settings.initialHeight, 'y');
345				publicMethod.position();
346
347				if (isIE6) {
348					$window.bind('resize.' + event_ie6 + ' scroll.' + event_ie6, function () {
349						$overlay.css({width: $window.width(), height: $window.height(), top: $window.scrollTop(), left: $window.scrollLeft()});
350					}).trigger('resize.' + event_ie6);
351				}
352				
353				slideshow();
354
355				trigger(event_open, settings.onOpen);
356				
357				$groupControls.add($title).hide();
358				
359				$close.html(settings.close).show();
360
361                $box.focus();
362                
363                // Confine focus to the modal
364                // Uses event capturing that is not supported in IE8-
365                if (document.addEventListener) {
366
367                    document.addEventListener('focus', trapFocus, true);
368                    
369                    $events.one(event_closed, function () {
370                        document.removeEventListener('focus', trapFocus, true);
371                    });
372                }
373
374                // Return focus on closing
375                if (settings.returnFocus) {
376                    $events.one(event_closed, function () {
377                        $(element).focus();
378                    });
379                }
380			}
381			
382			publicMethod.load(true);
383		}
384	}
385
386	// ColorBox's markup needs to be added to the DOM prior to being called
387	// so that the browser will go ahead and load the CSS background images.
388	function appendHTML() {
389		if (!$box && document.body) {
390			init = false;
391
392			$window = $(window);
393			$box = $tag(div).attr({
394                id: colorbox,
395                'class': isIE ? prefix + (isIE6 ? 'IE6' : 'IE') : '',
396                role: 'dialog',
397                tabindex: '-1'
398            }).hide();
399			$overlay = $tag(div, "Overlay", isIE6 ? 'position:absolute' : '').hide();
400			$loadingOverlay = $tag(div, "LoadingOverlay").add($tag(div, "LoadingGraphic"));
401			$wrap = $tag(div, "Wrapper");
402			$content = $tag(div, "Content").append(
403				$title = $tag(div, "Title"),
404				$current = $tag(div, "Current"),
405                $prev = $tag('button', "Previous"),
406				$next = $tag('button', "Next"),
407				$slideshow = $tag('button', "Slideshow"),
408                $loadingOverlay,
409				$close = $tag('button', "Close")
410			);
411			
412			$wrap.append( // The 3x3 Grid that makes up ColorBox
413				$tag(div).append(
414					$tag(div, "TopLeft"),
415					$topBorder = $tag(div, "TopCenter"),
416					$tag(div, "TopRight")
417				),
418				$tag(div, false, 'clear:left').append(
419					$leftBorder = $tag(div, "MiddleLeft"),
420					$content,
421					$rightBorder = $tag(div, "MiddleRight")
422				),
423				$tag(div, false, 'clear:left').append(
424					$tag(div, "BottomLeft"),
425					$bottomBorder = $tag(div, "BottomCenter"),
426					$tag(div, "BottomRight")
427				)
428			).find('div div').css({'float': 'left'});
429			
430			$loadingBay = $tag(div, false, 'position:absolute; width:9999px; visibility:hidden; display:none');
431			
432			$groupControls = $next.add($prev).add($current).add($slideshow);
433
434			$(document.body).append($overlay, $box.append($wrap, $loadingBay));
435		}
436	}
437
438	// Add ColorBox's event bindings
439	function addBindings() {
440		function clickHandler(e) {
441			// ignore non-left-mouse-clicks and clicks modified with ctrl / command, shift, or alt.
442			// See: http://jacklmoore.com/notes/click-events/
443			if (!(e.which > 1 || e.shiftKey || e.altKey || e.metaKey)) {
444				e.preventDefault();
445				launch(this);
446			}
447		}
448
449		if ($box) {
450			if (!init) {
451				init = true;
452
453				// Anonymous functions here keep the public method from being cached, thereby allowing them to be redefined on the fly.
454				$next.click(function () {
455					publicMethod.next();
456				});
457				$prev.click(function () {
458					publicMethod.prev();
459				});
460				$close.click(function () {
461					publicMethod.close();
462				});
463				$overlay.click(function () {
464					if (settings.overlayClose) {
465						publicMethod.close();
466					}
467				});
468				
469				// Key Bindings
470				$(document).bind('keydown.' + prefix, function (e) {
471					var key = e.keyCode;
472					if (open && settings.escKey && key === 27) {
473						e.preventDefault();
474						publicMethod.close();
475					}
476                    if (open && settings.arrowKey && $related[1] && !e.altKey) {
477						if (key === 37) {
478							e.preventDefault();
479							$prev.click();
480						} else if (key === 39) {
481							e.preventDefault();
482							$next.click();
483						}
484					}
485				});
486
487				if ($.isFunction($.fn.on)) {
488					// For jQuery 1.7+
489					$(document).on('click.'+prefix, '.'+boxElement, clickHandler);
490				} else {
491					// For jQuery 1.3.x -> 1.6.x
492					// This code is never reached in jQuery 1.9, so do not contact me about 'live' being removed.
493					// This is not here for jQuery 1.9, it's here for legacy users.
494					$('.'+boxElement).live('click.'+prefix, clickHandler);
495				}
496			}
497			return true;
498		}
499		return false;
500	}
501
502	// Don't do anything if ColorBox already exists.
503	if ($.colorbox) {
504		return;
505	}
506
507	// Append the HTML when the DOM loads
508	$(appendHTML);
509
510
511	// ****************
512	// PUBLIC FUNCTIONS
513	// Usage format: $.fn.colorbox.close();
514	// Usage from within an iframe: parent.$.fn.colorbox.close();
515	// ****************
516	
517	publicMethod = $.fn[colorbox] = $[colorbox] = function (options, callback) {
518		var $this = this;
519		
520		options = options || {};
521		
522		appendHTML();
523
524		if (addBindings()) {
525			if ($.isFunction($this)) { // assume a call to $.colorbox
526				$this = $('<a/>');
527				options.open = true;
528			} else if (!$this[0]) { // colorbox being applied to empty collection
529				return $this;
530			}
531			
532			if (callback) {
533				options.onComplete = callback;
534			}
535			
536			$this.each(function () {
537				$.data(this, colorbox, $.extend({}, $.data(this, colorbox) || defaults, options));
538			}).addClass(boxElement);
539			
540			if (($.isFunction(options.open) && options.open.call($this)) || options.open) {
541				launch($this[0]);
542			}
543		}
544		
545		return $this;
546	};
547
548	publicMethod.position = function (speed, loadedCallback) {
549		var
550		css,
551		top = 0,
552		left = 0,
553		offset = $box.offset(),
554		scrollTop,
555		scrollLeft;
556		
557		$window.unbind('resize.' + prefix);
558
559		// remove the modal so that it doesn't influence the document width/height
560		$box.css({top: -9e4, left: -9e4});
561
562		scrollTop = $window.scrollTop();
563		scrollLeft = $window.scrollLeft();
564
565		if (settings.fixed && !isIE6) {
566			offset.top -= scrollTop;
567			offset.left -= scrollLeft;
568			$box.css({position: 'fixed'});
569		} else {
570			top = scrollTop;
571			left = scrollLeft;
572			$box.css({position: 'absolute'});
573		}
574
575		// keeps the top and left positions within the browser's viewport.
576		if (settings.right !== false) {
577			left += Math.max($window.width() - settings.w - loadedWidth - interfaceWidth - setSize(sett
577ings.right, 'x'), 0);
578		} else if (settings.left !== false) {
579			left += setSize(settings.left, 'x');
580		} else {
581			left += Math.round(Math.max($window.width() - settings.w - loadedWidth - interfaceWidth, 0) / 2);
582		}
583		
584		if (settings.bottom !== false) {
585			top += Math.max($window.height() - settings.h - loadedHeight - interfaceHeight - setSize(settings.bottom, 'y'), 0);
586		} else if (settings.top !== false) {
587			top += setSize(settings.top, 'y');
588		} else {
589			top += Math.round(Math.max($window.height() - settings.h - loadedHeight - interfaceHeight, 0) / 2);
590		}
591
592		$box.css({top: offset.top, left: offset.left, visibility:'visible'});
593
594		// setting the speed to 0 to reduce the delay between same-sized content.
595		speed = ($box.width() === settings.w + loadedWidth && $box.height() === settings.h + loadedHeight) ? 0 : speed || 0;
596		
597		// this gives the wrapper plenty of breathing room so it's floated contents can move around smoothly,
598		// but it has to be shrank down around the size of div#colorbox when it's done.  If not,
599		// it can invoke an obscure IE bug when using iframes.
600		$wrap[0].style.width = $wrap[0].style.height = "9999px";
601		
602		function modalDimensions(that) {
603			$topBorder[0].style.width = $bottomBorder[0].style.width = $content[0].style.width = (parseInt(that.style.width,10) - interfaceWidth)+'px';
604			$content[0].style.height = $leftBorder[0].style.height = $rightBorder[0].style.height = (parseInt(that.style.height,10) - interfaceHeight)+'px';
605		}
606
607		css = {width: settings.w + loadedWidth + interfaceWidth, height: settings.h + loadedHeight + interfaceHeight, top: top, left: left};
608
609		if(speed===0){ // temporary workaround to side-step jQuery-UI 1.8 bug (http://bugs.jquery.com/ticket/12273)
610			$box.css(css);
611		}
612		$box.dequeue().animate(css, {
613			duration: speed,
614			complete: function () {
615				modalDimensions(this);
616				
617				active = false;
618				
619				// shrink the wrapper down to exactly the size of colorbox to avoid a bug in IE's iframe implementation.
620				$wrap[0].style.width = (settings.w + loadedWidth + interfaceWidth) + "px";
621				$wrap[0].style.height = (settings.h + loadedHeight + interfaceHeight) + "px";
622				
623				if (settings.reposition) {
624					setTimeout(function () {  // small delay before binding onresize due to an IE8 bug.
625						$window.bind('resize.' + prefix, publicMethod.position);
626					}, 1);
627				}
628
629				if (loadedCallback) {
630					loadedCallback();
631				}
632			},
633			step: function () {
634				modalDimensions(this);
635			}
636		});
637	};
638
639	publicMethod.resize = function (options) {
640		if (open) {
641			options = options || {};
642			
643			if (options.width) {
644				settings.w = setSize(options.width, 'x') - loadedWidth - interfaceWidth;
645			}
646			if (options.innerWidth) {
647				settings.w = setSize(options.innerWidth, 'x');
648			}
649			$loaded.css({width: settings.w});
650			
651			if (options.height) {
652				settings.h = setSize(options.height, 'y') - loadedHeight - interfaceHeight;
653			}
654			if (options.innerHeight) {
655				settings.h = setSize(options.innerHeight, 'y');
656			}
657			if (!options.innerHeight && !options.height) {
658				$loaded.css({height: "auto"});
659				settings.h = $loaded.height();
660			}
661			$loaded.css({height: settings.h});
662			
663			publicMethod.position(settings.transition === "none" ? 0 : settings.speed);
664		}
665	};
666
667	publicMethod.prep = function (object) {
668		if (!open) {
669			return;
670		}
671		
672		var callback, speed = settings.transition === "none" ? 0 : settings.speed;
673
674		$loaded.empty().remove(); // Using empty first may prevent some IE7 issues.
675
676		$loaded = $tag(div, 'LoadedContent').append(object);
677		
678		function getWidth() {
679			settings.w = settings.w || $loaded.width();
680			settings.w = settings.mw && settings.mw < settings.w ? settings.mw : settings.w;
681			return settings.w;
682		}
683		function getHeight() {
684			settings.h = settings.h || $loaded.height();
685			settings.h = settings.mh && settings.mh < settings.h ? settings.mh : settings.h;
686			return settings.h;
687		}
688		
689		$loaded.hide()
690		.appendTo($loadingBay.show())// content has to be appended to the DOM for accurate size calculations.
691		.css({width: getWidth(), overflow: settings.scrolling ? 'auto' : 'hidden'})
692		.css({height: getHeight()})// sets the height independently from the width in case the new width influences the value of height.
693		.prependTo($content);
694		
695		$loadingBay.hide();
696		
697		// 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.
698		
699		$(photo).css({'float': 'none'});
700
701		callback = function () {
702			var total = $related.length,
703				iframe,
704				frameBorder = 'frameBorder',
705				allowTransparency = 'allowTransparency',
706				complete;
707			
708			if (!open) {
709				return;
710			}
711			
712			function removeFilter() {
713				if (isIE) {
714					$box[0].style.removeAttribute('filter');
715				}
716			}
717			
718			complete = function () {
719				clearTimeout(loadingTimer);
720				$loadingOverlay.hide();
721				trigger(event_complete, settings.onComplete);
722			};
723			
724			if (isIE) {
725				//This fadeIn helps the bicubic resampling to kick-in.
726				if (photo) {
727					$loaded.fadeIn(100);
728				}
729			}
730			
731			$title.html(settings.title).add($loaded).show();
732			
733			if (total > 1) { // handle grouping
734				if (typeof settings.current === "string") {
735					$current.html(settings.current.replace('{current}', index + 1).replace('{total}', total)).show();
736				}
737				
738				$next[(settings.loop || index < total - 1) ? "show" : "hide"]().html(sett
738ings.next);
739				$prev[(settings.loop || index) ? "show" : "hide"]().html(settings.previous);
740				
741				if (settings.slideshow) {
742					$slideshow.show();
743				}
744				
745				// Preloads images within a rel group
746				if (settings.preloading) {
747					$.each([getIndex(-1), getIndex(1)], function(){
748						var src,
749							img,
750							i = $related[this],
751							data = $.data(i, colorbox);
752
753						if (data && data.href) {
754							src = data.href;
755							if ($.isFunction(src)) {
756								src = src.call(i);
757							}
758						} else {
759							src = $(i).attr('href');
760						}
761
762						if (src && isImage(data, src)) {
763							src = retinaUrl(data, src);
764							img = new Image();
765							img.src = src;
766						}
767					});
768				}
769			} else {
770				$groupControls.hide();
771			}
772			
773			if (settings.iframe) {
774				iframe = $tag('iframe')[0];
775				
776				if (frameBorder in iframe) {
777					iframe[frameBorder] = 0;
778				}
779				
780				if (allowTransparency in iframe) {
781					iframe[allowTransparency] = "true";
782				}
783
784				if (!settings.scrolling) {
785					iframe.scrolling = "no";
786				}
787				
788				$(iframe)
789					.attr({
790						src: settings.href,
791						name: (new Date()).getTime(), // give the iframe a unique name to prevent caching
792						'class': prefix + 'Iframe',
793						allowFullScreen : true, // allow HTML5 video to go fullscreen
794						webkitAllowFullScreen : true,
795						mozallowfullscreen : true
796					})
797					.one('load', complete)
798					.appendTo($loaded);
799				
800				$events.one(event_purge, function () {
801					iframe.src = "//about:blank";
802				});
803
804				if (settings.fastIframe) {
805					$(iframe).trigger('load');
806				}
807			} else {
808				complete();
809			}
810			
811			if (settings.transition === 'fade') {
812				$box.fadeTo(speed, 1, removeFilter);
813			} else {
814				removeFilter();
815			}
816		};
817		
818		if (settings.transition === 'fade') {
819			$box.fadeTo(speed, 0, function () {
820				publicMethod.position(0, callback);
821			});
822		} else {
823			publicMethod.position(speed, callback);
824		}
825	};
826
827	publicMethod.load = function (launched) {
828		var href, setResize, prep = publicMethod.prep, $inline;
829		
830		active = true;
831		
832		photo = false;
833		
834		element = $related[index];
835		
836		if (!launched) {
837			makeSettings();
838		}
839
840		if (className) {
841			$box.add($overlay).removeClass(className);
842		}
843		if (settings.className) {
844			$box.add($overlay).addClass(settings.className);
845		}
846		className = settings.className;
847		
848		trigger(event_purge);
849		
850		trigger(event_load, settings.onLoad);
851		
852		settings.h = settings.height ?
853				setSize(settings.height, 'y') - loadedHeight - interfaceHeight :
854				settings.innerHeight && setSize(settings.innerHeight, 'y');
855		
856		settings.w = settings.width ?
857				setSize(settings.width, 'x') - loadedWidth - interfaceWidth :
858				settings.innerWidth && setSize(settings.innerWidth, 'x');
859		
860		// Sets the minimum dimensions for use in image scaling
861		settings.mw = settings.w;
862		settings.mh = settings.h;
863		
864		// Re-evaluate the minimum width and height based on maxWidth and maxHeight values.
865		// If the width or height exceed the maxWidth or maxHeight, use the maximum values instead.
866		if (settings.maxWidth) {
867			settings.mw = setSize(settings.maxWidth, 'x') - loadedWidth - interfaceWidth;
868			settings.mw = settings.w && settings.w < settings.mw ? settings.w : settings.mw;
869		}
870		if (settings.maxHeight) {
871			settings.mh = setSize(settings.maxHeight, 'y') - loadedHeight - interfaceHeight;
872			settings.mh = settings.h && settings.h < settings.mh ? settings.h : settings.mh;
873		}
874		
875		href = settings.href;
876		
877		loadingTimer = setTimeout(function () {
878			$loadingOverlay.show();
879		}, 100);
880		
881		if (settings.inline) {
882			// Inserts an empty placeholder where inline content is being pulled from.
883			// An event is bound to put inline content back when ColorBox closes or loads new content.
884			$inline = $tag(div).hide().insertBefore($(href)[0]);
885
886			$events.one(event_purge, function () {
887				$inline.replaceWith($loaded.children());
888			});
889
890			prep($(href));
891		} else if (settings.iframe) {
892			// IFrame element won't be added to the DOM until it is ready to be displayed,
893			// to avoid problems with DOM-ready JS that might be trying to run in that iframe.
894			prep(" ");
895		} else if (settings.html) {
896			prep(settings.html);
897		} else if (isImage(settings, href)) {
898
899			href = retinaUrl(settings, href);
900
901			$(photo = new Image())
902			.addClass(prefix + 'Photo')
903			.bind('error',function () {
904				settings.title = false;
905				prep($tag(div, 'Error').html(settings.imgError));
906			})
907			.one('load', function () {
908				var percent;
909
910				if (settings.retinaImage && window.devicePixelRatio > 1) {
911					photo.height = photo.height / window.devicePixelRatio;
912					photo.width = photo.width / window.devicePixelRatio;
913				}
914
915				if (settings.scalePhotos) {
916					setResize = function () {
917						photo.height -= photo.height * percent;
918						photo.width -= photo.width * percent;
919					};
920					if (settings.mw && photo.width > settings.mw) {
921						percent = (photo.width - settings.mw) / photo.width;
922						setResize();
923					}
924					if (settings.mh && photo.height > settings.mh) {
925						percent = (photo.height - settings.mh) / photo.height;
926						setResize();
927					}
928				}
929				
930				if (settings.h) {
931					photo.style.marginTop = Math.max(settings.mh - photo.height, 0) / 2 + 'px';
932				}
933				
934				if ($related[1] && (settings.loop || $related[index + 1])) {
935					photo.style.cursor = 'pointer';
936					photo.onclick = function () {
937						publicMethod.next();
938					};
939				}
940				
941				if (isIE) {
942					photo.style.msInterpolationMode = 'bicubic';
943				}
944				
945				setTimeout(function () { // A pause because Chrome will sometimes report a 0 by 0 size otherwise.
946					prep(photo);
947				}, 1);
948			});
949			
950			setTimeout(function () { // A pause because Opera 10.6+ will sometimes not run the onload function otherwise.
951				photo.src = href;
952			}, 1);
953		} else if (href) {
954			$loadingBay.load(href, settings.data, function (data, status) {
955				prep(status === 'error' ? $tag(div, 'Error').html(settings.xhrError) : $(this).contents());
956			});
957		}
958	};
959		
960	// Navigates to the next page/image in a set.
961	publicMethod.next = function () {
962		if (!active && $related[1] && (settings.loop || $related[index + 1])) {
963			index = getIndex(1);
964			publicMethod.load();
965		}
966	};
967	
968	publicMethod.prev = function () {
969		if (!active && $related[1] && (settings.loop || index)) {
970			index = getIndex(-1);
971			publicMethod.load();
972		}
973	};
974
975	// Note: to use this within an iframe use the following format: parent.$.fn.colorbox.close();
976	publicMethod.close = function () {
977		if (open && !closing) {
978			
979			closing = true;
980			
981			open = false;
982			
983			trigger(event_cleanup, settings.onCleanup);
984			
985			$window.unbind('.' + prefix + ' .' + event_ie6);
986			
987			$overlay.fadeTo(200, 0);
988			
989			$box.stop().fadeTo(300, 0, function () {
990			
991				$box.add($overlay).css({'opacity': 1, cursor: 'auto'}).hide();
992				
993				trigger(event_purge);
994				
995				$loaded.empty().remove(); // Using empty first may prevent some IE7 issues.
996				
997				setTimeout(function () {
998					closing = false;
999					trigger(event_closed, settings.onClosed);
1000				}, 1);
1001			});
1002		}
1003	};
1004
1005	// Removes changes ColorBox made to the document, but does not remove the plugin
1006	// from jQuery.
1007	publicMethod.remove = function () {
1008		$([]).add($box).add($overlay).remove();
1009		$box = null;
1010		$('.' + boxElement)
1011			.removeData(colorbox)
1012			.removeClass(boxElement);
1013
1014		$(document).unbind('click.'+prefix);
1015	};
1016
1017	// A method for fetching the current element ColorBox is referencing.
1018	// returns a jQuery object.
1019	publicMethod.element = function () {
1020		return $(element);
1021	};
1022
1023	publicMethod.settings = defaults;
1024
1025}(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.