PageSourceSearch

https://book-hall.ru/sites/all/libraries/colorbox/colorbox/jquery.colorbox.js?i

js book-hall.ru collected 2026-10-02 11:21:57 UTC 28,229 bytes, 865 lines download raw bytes

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