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