Removed dep on API
[ninja.git] / application / media / js / jquery.fancybox.js
blobd8ccfd6aec2f7610ba51a12f379ea05a47cf5d31
1 /*
2 * FancyBox - jQuery Plugin
3 * Simple and fancy lightbox alternative
5 * Examples and documentation at: http://fancybox.net
7 * Copyright (c) 2008 - 2010 Janis Skarnelis
8 * That said, it is hardly a one-person project. Many people have submitted bugs, code, and offered their advice freely. Their support is greatly appreciated.
10 * Version: 1.3.4 (11/11/2010)
11 * Requires: jQuery v1.3+
13 * Dual licensed under the MIT and GPL licenses:
14 * http://www.opensource.org/licenses/mit-license.php
15 * http://www.gnu.org/licenses/gpl.html
18 (function (b) {
19 var m, t, u, f, D, j, E, n, z, A, q = 0,
20 e = {}, o = [],
21 p = 0,
22 d = {}, l = [],
23 G = null,
24 v = new Image,
25 J = /\.(jpg|gif|png|bmp|jpeg)(.*)?$/i,
26 W = /[^\.]\.(swf)\s*$/i,
27 K, L = 1,
28 y = 0,
29 s = "",
30 r, i, h = false,
31 B = b.extend(b("<div/>")[0], {
32 prop: 0
33 }),
34 M = b.browser.msie && b.browser.version < 7 && !window.XMLHttpRequest,
35 N = function () {
36 t.hide();
37 v.onerror = v.onload = null;
38 G && G.abort();
39 m.empty()
40 }, O = function () {
41 if (false === e.onError(o, q, e)) {
42 t.hide();
43 h = false
44 } else {
45 e.titleShow = false;
46 e.width = "auto";
47 e.height = "auto";
48 m.html('<p id="fancybox-error">The requested content cannot be loaded.<br />Please try again later.</p>');
49 F()
51 }, I = function () {
52 var a = o[q],
53 c, g, k, C, P, w;
54 N();
55 e = b.extend({}, b.fn.fancybox.defaults, typeof b(a).data("fancybox") == "undefined" ? e : b(a).data("fancybox"));
56 w = e.onStart(o, q, e);
57 if (w === false) h = false;
58 else {
59 if (typeof w == "object") e = b.extend(e, w);
60 k = e.title || (a.nodeName ? b(a).attr("title") : a.title) || "";
61 if (a.nodeName && !e.orig) e.orig = b(a).children("img:first").length ? b(a).children("img:first") : b(a);
62 if (k === "" && e.orig && e.titleFromAlt) k = e.orig.attr("alt");
63 c = e.href || (a.nodeName ? b(a).attr("href") : a.href) || null;
64 if (/^(?:javascript)/i.test(c) ||
65 c == "#") c = null;
66 if (e.type) {
67 g = e.type;
68 if (!c) c = e.content
69 } else if (e.content) g = "html";
70 else if (c) g = c.match(J) ? "image" : c.match(W) ? "swf" : b(a).hasClass("iframe") ? "iframe" : c.indexOf("#") === 0 ? "inline" : "ajax";
71 if (g) {
72 if (g == "inline") {
73 a = c.substr(c.indexOf("#"));
74 g = b(a).length > 0 ? "inline" : "ajax"
76 e.type = g;
77 e.href = c;
78 e.title = k;
79 if (e.autoDimensions)
80 if (e.type == "html" || e.type == "inline" || e.type == "ajax") {
81 e.width = "auto";
82 e.height = "auto"
83 } else e.autoDimensions = false;
84 if (e.modal) {
85 e.overlayShow = true;
86 e.hideOnOverlayClick = false;
87 e.hideOnContentClick =
88 false;
89 e.enableEscapeButton = false;
90 e.showCloseButton = false
92 e.padding = parseInt(e.padding, 10);
93 e.margin = parseInt(e.margin, 10);
94 m.css("padding", e.padding + e.margin);
95 b(".fancybox-inline-tmp").unbind("fancybox-cancel").bind("fancybox-change", function () {
96 b(this).replaceWith(j.children())
97 });
98 switch (g) {
99 case "html":
100 m.html(e.content);
101 F();
102 break;
103 case "inline":
104 if (b(a).parent().is("#fancybox-content") === true) {
105 h = false;
106 break
108 b('<div class="fancybox-inline-tmp" />').hide().insertBefore(b(a)).bind("fancybox-cleanup", function () {
109 b(this).replaceWith(j.children())
110 }).bind("fancybox-cancel",
111 function () {
112 b(this).replaceWith(m.children())
114 b(a).appendTo(m);
115 F();
116 break;
117 case "image":
118 h = false;
119 b.fancybox.showActivity();
120 v = new Image;
121 v.onerror = function () {
124 v.onload = function () {
125 h = true;
126 v.onerror = v.onload = null;
127 e.width = v.width;
128 e.height = v.height;
129 b("<img />").attr({
130 id: "fancybox-img",
131 src: v.src,
132 alt: e.title
133 }).appendTo(m);
136 v.src = c;
137 break;
138 case "swf":
139 e.scrolling = "no";
140 C = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="' + e.width + '" height="' + e.height + '"><param name="movie" value="' + c +
141 '"></param>';
142 P = "";
143 b.each(e.swf, function (x, H) {
144 C += '<param name="' + x + '" value="' + H + '"></param>';
145 P += " " + x + '="' + H + '"'
147 C += '<embed src="' + c + '" type="application/x-shockwave-flash" width="' + e.width + '" height="' + e.height + '"' + P + "></embed></object>";
148 m.html(C);
149 F();
150 break;
151 case "ajax":
152 h = false;
153 b.fancybox.showActivity();
154 e.ajax.win = e.ajax.success;
155 G = b.ajax(b.extend({}, e.ajax, {
156 url: c,
157 data: e.ajax.data || {},
158 error: function (x) {
159 x.status > 0 && O()
161 success: function (x, H, R) {
162 if ((typeof R == "object" ? R : G).status == 200) {
163 if (typeof e.ajax.win ==
164 "function") {
165 w = e.ajax.win(c, x, H, R);
166 if (w === false) {
167 t.hide();
168 return
169 } else if (typeof w == "string" || typeof w == "object") x = w
171 m.html(x);
175 }));
176 break;
177 case "iframe":
180 } else O()
182 }, F = function () {
183 var a = e.width,
184 c = e.height;
185 a = a.toString().indexOf("%") > -1 ? parseInt((b(window).width() - e.margin * 2) * parseFloat(a) / 100, 10) + "px" : a == "auto" ? "auto" : a + "px";
186 c = c.toString().indexOf("%") > -1 ? parseInt((b(window).height() - e.margin * 2) * parseFloat(c) / 100, 10) + "px" : c == "auto" ? "auto" : c + "px";
187 m.wrapInner('<div style="width:' + a + ";height:" + c +
188 ";overflow: " + (e.scrolling == "auto" ? "auto" : e.scrolling == "yes" ? "scroll" : "hidden") + ';position:relative;"></div>');
189 e.width = m.width();
190 e.height = m.height();
192 }, Q = function () {
193 var a, c;
194 t.hide();
195 if (f.is(":visible") && false === d.onCleanup(l, p, d)) {
196 b.event.trigger("fancybox-cancel");
197 h = false
198 } else {
199 h = true;
200 b(j.add(u)).unbind();
201 b(window).unbind("resize.fb scroll.fb");
202 b(document).unbind("keydown.fb");
203 f.is(":visible") && d.titlePosition !== "outside" && f.css("height", f.height());
204 l = o;
205 p = q;
206 d = e;
207 if (d.overlayShow) {
208 u.css({
209 "background-color": d.overlayColor,
210 opacity: d.overlayOpacity,
211 cursor: d.hideOnOverlayClick ? "pointer" : "auto",
212 height: b(document).height()
214 if (!u.is(":visible")) {
215 M && b("select:not(#fancybox-tmp select)").filter(function () {
216 return this.style.visibility !== "hidden"
217 }).css({
218 visibility: "hidden"
219 }).one("fancybox-cleanup", function () {
220 this.style.visibility = "inherit"
222 u.show()
224 } else u.hide();
225 i = X();
226 s = d.title || "";
227 y = 0;
228 n.empty().removeAttr("style").removeClass();
229 if (d.titleShow !== false) {
230 if (b.isFunction(d.titleFormat)) a = d.titleFormat(s, l, p, d);
231 else a = s && s.length ?
232 d.titlePosition == "float" ? '<table id="fancybox-title-float-wrap" cellpadding="0" cellspacing="0"><tr><td id="fancybox-title-float-left"></td><td id="fancybox-title-float-main">' + s + '</td><td id="fancybox-title-float-right"></td></tr></table>' : '<div id="fancybox-title-' + d.titlePosition + '">' + s + "</div>" : false;
233 s = a;
234 if (!(!s || s === "")) {
235 n.addClass("fancybox-title-" + d.titlePosition).html(s).appendTo("body").show();
236 switch (d.titlePosition) {
237 case "inside":
238 n.css({
239 width: i.width - d.padding * 2,
240 marginLeft: d.padding,
241 marginRight: d.padding
243 y = n.outerHeight(true);
244 n.appendTo(D);
245 i.height += y;
246 break;
247 case "over":
248 n.css({
249 marginLeft: d.padding,
250 width: i.width - d.padding * 2,
251 bottom: d.padding
252 }).appendTo(D);
253 break;
254 case "float":
255 n.css("left", parseInt((n.width() - i.width - 40) / 2, 10) * -1).appendTo(f);
256 break;
257 default:
258 n.css({
259 width: i.width - d.padding * 2,
260 paddingLeft: d.padding,
261 paddingRight: d.padding
262 }).appendTo(f)
266 n.hide();
267 if (f.is(":visible")) {
268 b(E.add(z).add(A)).hide();
269 a = f.position();
270 r = {
271 top: a.top,
272 left: a.left,
273 width: f.width(),
274 height: f.height()
276 c = r.width == i.width && r.height ==
277 i.height;
278 j.fadeTo(d.changeFade, 0.3, function () {
279 var g = function () {
280 j.html(m.contents()).fadeTo(d.changeFade, 1, S)
282 b.event.trigger("fancybox-change");
283 j.empty().removeAttr("filter").css({
284 "border-width": d.padding,
285 width: i.width - d.padding * 2,
286 height: e.autoDimensions ? "auto" : i.height - y - d.padding * 2
288 if (c) g();
289 else {
290 B.prop = 0;
291 b(B).animate({
292 prop: 1
293 }, {
294 duration: d.changeSpeed,
295 easing: d.easingChange,
296 step: T,
297 complete: g
301 } else {
302 f.removeAttr("style");
303 j.css("border-width", d.padding);
304 if (d.transitionIn == "elastic") {
305 r = V();
306 j.html(m.contents());
307 f.show();
308 if (d.opacity) i.opacity = 0;
309 B.prop = 0;
310 b(B).animate({
311 prop: 1
312 }, {
313 duration: d.speedIn,
314 easing: d.easingIn,
315 step: T,
316 complete: S
318 } else {
319 d.titlePosition == "inside" && y > 0 && n.show();
320 j.css({
321 width: i.width - d.padding * 2,
322 height: e.autoDimensions ? "auto" : i.height - y - d.padding * 2
323 }).html(m.contents());
324 f.css(i).fadeIn(d.transitionIn == "none" ? 0 : d.speedIn, S)
328 }, Y = function () {
329 if (d.enableEscapeButton || d.enableKeyboardNav) b(document).bind("keydown.fb", function (a) {
330 if (a.keyCode == 27 && d.enableEscapeButton) {
331 a.preventDefault();
332 b.fancybox.close()
333 } else if ((a.keyCode ==
334 37 || a.keyCode == 39) && d.enableKeyboardNav && a.target.tagName !== "INPUT" && a.target.tagName !== "TEXTAREA" && a.target.tagName !== "SELECT") {
335 a.preventDefault();
336 b.fancybox[a.keyCode == 37 ? "prev" : "next"]()
339 if (d.showNavArrows) {
340 if (d.cyclic && l.length > 1 || p !== 0) z.show();
341 if (d.cyclic && l.length > 1 || p != l.length - 1) A.show()
342 } else {
343 z.hide();
344 A.hide()
346 }, S = function () {
347 if (!b.support.opacity) {
348 j.get(0).style.removeAttribute("filter");
349 f.get(0).style.removeAttribute("filter")
351 e.autoDimensions && j.css("height", "auto");
352 f.css("height", "auto");
353 s && s.length && n.show();
354 d.showCloseButton && E.show();
355 Y();
356 d.hideOnContentClick && j.bind("click", b.fancybox.close);
357 d.hideOnOverlayClick && u.bind("click", b.fancybox.close);
358 b(window).bind("resize.fb", b.fancybox.resize);
359 d.centerOnScroll && b(window).bind("scroll.fb", b.fancybox.center);
360 if (d.type == "iframe") b('<iframe id="fancybox-frame" name="fancybox-frame' + (new Date).getTime() + '" frameborder="0" hspace="0" ' + (b.browser.msie ? 'allowtransparency="true""' : "") + ' scrolling="' + e.scrolling + '" src="' + d.href + '"></iframe>').appendTo(j);
361 f.show();
362 h = false;
363 b.fancybox.center();
364 d.onComplete(l, p, d);
365 var a, c;
366 if (l.length - 1 > p) {
367 a = l[p + 1].href;
368 if (typeof a !== "undefined" && a.match(J)) {
369 c = new Image;
370 c.src = a
373 if (p > 0) {
374 a = l[p - 1].href;
375 if (typeof a !== "undefined" && a.match(J)) {
376 c = new Image;
377 c.src = a
380 }, T = function (a) {
381 var c = {
382 width: parseInt(r.width + (i.width - r.width) * a, 10),
383 height: parseInt(r.height + (i.height - r.height) * a, 10),
384 top: parseInt(r.top + (i.top - r.top) * a, 10),
385 left: parseInt(r.left + (i.left - r.left) * a, 10)
387 if (typeof i.opacity !== "undefined") c.opacity = a < 0.5 ? 0.5 : a;
388 f.css(c);
389 j.css({
390 width: c.width - d.padding * 2,
391 height: c.height - y * a - d.padding * 2
393 }, U = function () {
394 return [b(window).width() - d.margin * 2, b(window).height() - d.margin * 2, b(document).scrollLeft() + d.margin, b(document).scrollTop() + d.margin]
395 }, X = function () {
396 var a = U(),
397 c = {}, g = d.autoScale,
398 k = d.padding * 2;
399 c.width = d.width.toString().indexOf("%") > -1 ? parseInt(a[0] * parseFloat(d.width) / 100, 10) : d.width + k;
400 c.height = d.height.toString().indexOf("%") > -1 ? parseInt(a[1] * parseFloat(d.height) / 100, 10) : d.height + k;
401 if (g && (c.width > a[0] || c.height > a[1]))
402 if (e.type ==
403 "image" || e.type == "swf") {
404 g = d.width / d.height;
405 if (c.width > a[0]) {
406 c.width = a[0];
407 c.height = parseInt((c.width - k) / g + k, 10)
409 if (c.height > a[1]) {
410 c.height = a[1];
411 c.width = parseInt((c.height - k) * g + k, 10)
413 } else {
414 c.width = Math.min(c.width, a[0]);
415 c.height = Math.min(c.height, a[1])
417 c.top = parseInt(Math.max(a[3] - 20, a[3] + (a[1] - c.height - 40) * 0.5), 10);
418 c.left = parseInt(Math.max(a[2] - 20, a[2] + (a[0] - c.width - 40) * 0.5), 10);
419 return c
420 }, V = function () {
421 var a = e.orig ? b(e.orig) : false,
422 c = {};
423 if (a && a.length) {
424 c = a.offset();
425 c.top += parseInt(a.css("paddingTop"),
426 10) || 0;
427 c.left += parseInt(a.css("paddingLeft"), 10) || 0;
428 c.top += parseInt(a.css("border-top-width"), 10) || 0;
429 c.left += parseInt(a.css("border-left-width"), 10) || 0;
430 c.width = a.width();
431 c.height = a.height();
432 c = {
433 width: c.width + d.padding * 2,
434 height: c.height + d.padding * 2,
435 top: c.top - d.padding - 20,
436 left: c.left - d.padding - 20
438 } else {
439 a = U();
440 c = {
441 width: d.padding * 2,
442 height: d.padding * 2,
443 top: parseInt(a[3] + a[1] * 0.5, 10),
444 left: parseInt(a[2] + a[0] * 0.5, 10)
447 return c
448 }, Z = function () {
449 if (t.is(":visible")) {
450 b("div", t).css("top", L * -40 + "px");
451 L = (L + 1) % 12
452 } else clearInterval(K)
454 b.fn.fancybox = function (a) {
455 if (!b(this).length) return this;
456 b(this).data("fancybox", b.extend({}, a, b.metadata ? b(this).metadata() : {})).unbind("click.fb").bind("click.fb", function (c) {
457 c.preventDefault();
458 if (!h) {
459 h = true;
460 b(this).blur();
461 o = [];
462 q = 0;
463 c = b(this).attr("rel") || "";
464 if (!c || c == "" || c === "nofollow") o.push(this);
465 else {
466 o = b("a[rel=" + c + "], area[rel=" + c + "]");
467 q = o.index(this)
472 return this
474 b.fancybox = function (a, c) {
475 var g;
476 if (!h) {
477 h = true;
478 g = typeof c !== "undefined" ? c : {};
479 o = [];
480 q = parseInt(g.index, 10) || 0;
481 if (b.isArray(a)) {
482 for (var k =
483 0, C = a.length; k < C; k++)
484 if (typeof a[k] == "object") b(a[k]).data("fancybox", b.extend({}, g, a[k]));
485 else a[k] = b({}).data("fancybox", b.extend({
486 content: a[k]
487 }, g));
488 o = jQuery.merge(o, a)
489 } else {
490 if (typeof a == "object") b(a).data("fancybox", b.extend({}, g, a));
491 else a = b({}).data("fancybox", b.extend({
492 content: a
493 }, g));
494 o.push(a)
495 } if (q > o.length || q < 0) q = 0;
499 b.fancybox.showActivity = function () {
500 clearInterval(K);
501 t.show();
502 K = setInterval(Z, 66)
504 b.fancybox.hideActivity = function () {
505 t.hide()
507 b.fancybox.next = function () {
508 return b.fancybox.pos(p +
511 b.fancybox.prev = function () {
512 return b.fancybox.pos(p - 1)
514 b.fancybox.pos = function (a) {
515 if (!h) {
516 a = parseInt(a);
517 o = l;
518 if (a > -1 && a < l.length) {
519 q = a;
521 } else if (d.cyclic && l.length > 1) {
522 q = a >= l.length ? 0 : l.length - 1;
527 b.fancybox.cancel = function () {
528 if (!h) {
529 h = true;
530 b.event.trigger("fancybox-cancel");
531 N();
532 e.onCancel(o, q, e);
533 h = false
536 b.fancybox.close = function () {
537 function a() {
538 u.fadeOut("fast");
539 n.empty().hide();
540 f.hide();
541 b.event.trigger("fancybox-cleanup");
542 j.empty();
543 d.onClosed(l, p, d);
544 l = e = [];
545 p = q = 0;
546 d = e = {};
547 h = false
549 if (!(h || f.is(":hidden"))) {
551 true;
552 if (d && false === d.onCleanup(l, p, d)) h = false;
553 else {
554 N();
555 b(E.add(z).add(A)).hide();
556 b(j.add(u)).unbind();
557 b(window).unbind("resize.fb scroll.fb");
558 b(document).unbind("keydown.fb");
559 j.find("iframe").attr("src", M && /^https/i.test(window.location.href || "") ? "javascript:void(false)" : "about:blank");
560 d.titlePosition !== "inside" && n.empty();
561 f.stop();
562 if (d.transitionOut == "elastic") {
563 r = V();
564 var c = f.position();
565 i = {
566 top: c.top,
567 left: c.left,
568 width: f.width(),
569 height: f.height()
571 if (d.opacity) i.opacity = 1;
572 n.empty().hide();
573 B.prop = 1;
574 b(B).animate({
575 prop: 0
576 }, {
577 duration: d.speedOut,
578 easing: d.easingOut,
579 step: T,
580 complete: a
582 } else f.fadeOut(d.transitionOut == "none" ? 0 : d.speedOut, a)
586 b.fancybox.resize = function () {
587 u.is(":visible") && u.css("height", b(document).height());
588 b.fancybox.center(true)
590 b.fancybox.center = function (a) {
591 var c, g;
592 if (!h) {
593 g = a === true ? 1 : 0;
594 c = U();
595 !g && (f.width() > c[0] || f.height() > c[1]) || f.stop().animate({
596 top: parseInt(Math.max(c[3] - 20, c[3] + (c[1] - j.height() - 100) * 0.5 - d.padding)),
597 left: parseInt(Math.max(c[2] - 20, c[2] + (c[0] - j.width() - 40) * 0.5 -
598 d.padding))
599 }, typeof a == "number" ? a : 200)
602 b.fancybox.init = function () {
603 if (!b("#fancybox-wrap").length) {
604 b("body").append(m = b('<div id="fancybox-tmp"></div>'), t = b('<div id="fancybox-loading"><div></div></div>'), u = b('<div id="fancybox-overlay"></div>'), f = b('<div id="fancybox-wrap"></div>'));
605 D = b('<div id="fancybox-outer"></div>').append('<div class="fancybox-bg" id="fancybox-bg-n"></div><div class="fancybox-bg" id="fancybox-bg-ne"></div><div class="fancybox-bg" id="fancybox-bg-e"></div><div class="fancybox-bg" id="fancybox-bg-se"></div><div class="fancybox-bg" id="fancybox-bg-s"></div><div class="fancybox-bg" id="fancybox-bg-sw"></div><div class="fancybox-bg" id="fancybox-bg-w"></div><div class="fancybox-bg" id="fancybox-bg-nw"></div>').appendTo(f);
606 D.append(j = b('<div id="fancybox-content"></div>'), E = b('<a id="fancybox-close"></a>'), n = b('<div id="fancybox-title"></div>'), z = b('<a href="javascript:;" id="fancybox-left"><span class="fancy-ico" id="fancybox-left-ico"></span></a>'), A = b('<a href="javascript:;" id="fancybox-right"><span class="fancy-ico" id="fancybox-right-ico"></span></a>'));
607 E.click(b.fancybox.close);
608 t.click(b.fancybox.cancel);
609 z.click(function (a) {
610 a.preventDefault();
611 b.fancybox.prev()
613 A.click(function (a) {
614 a.preventDefault();
615 b.fancybox.next()
617 b.fn.mousewheel && f.bind("mousewheel.fb", function (a, c) {
618 if (h) a.preventDefault();
619 else if (b(a.target).get(0).clientHeight == 0 || b(a.target).get(0).scrollHeight === b(a.target).get(0).clientHeight) {
620 a.preventDefault();
621 b.fancybox[c > 0 ? "prev" : "next"]()
624 b.support.opacity || f.addClass("fancybox-ie");
625 if (M) {
626 t.addClass("fancybox-ie6");
627 f.addClass("fancybox-ie6");
628 b('<iframe id="fancybox-hide-sel-frame" src="' + (/^https/i.test(window.location.href || "") ? "javascript:void(false)" : "about:blank") + '" scrolling="no" border="0" frameborder="0" tabindex="-1"></iframe>').prependTo(D)
632 b.fn.fancybox.defaults = {
633 padding: 10,
634 margin: 40,
635 opacity: false,
636 modal: false,
637 cyclic: false,
638 scrolling: "auto",
639 width: 560,
640 height: 340,
641 autoScale: true,
642 autoDimensions: true,
643 centerOnScroll: false,
644 ajax: {},
645 swf: {
646 wmode: "transparent"
648 hideOnOverlayClick: true,
649 hideOnContentClick: false,
650 overlayShow: true,
651 overlayOpacity: 0.7,
652 overlayColor: "#777",
653 titleShow: true,
654 titlePosition: "float",
655 titleFormat: null,
656 titleFromAlt: false,
657 transitionIn: "fade",
658 transitionOut: "fade",
659 speedIn: 300,
660 speedOut: 300,
661 changeSpeed: 300,
662 changeFade: "fast",
663 easingIn: "swing",
664 easingOut: "swing",
665 showCloseButton: true,
666 showNavArrows: true,
667 enableEscapeButton: true,
668 enableKeyboardNav: true,
669 onStart: function () {},
670 onCancel: function () {},
671 onComplete: function () {},
672 onCleanup: function () {},
673 onClosed: function () {},
674 onError: function () {}
676 b(document).ready(function () {
677 b.fancybox.init()
679 })(jQuery);