1/*! 2 Slimbox v2.05 - The ultimate lightweight Lightbox clone for jQuery 3 (c) 2007-2013 Christophe Beyls <http://www.digitalia.be> 4 MIT-style license. 5 */ 6(function (w) { 7 var E = w(window), u, f, F = -1, n, x, D, v, y, L, r, m = !window.XMLHttpRequest, s = [], l = document.documentElement, k = {}, t = new Image(), J = new Image(), H, a, g, p, I, d, G, c, A, K; 8 w(function () { 9 w("body").append(w([H = w('<div id="lbOverlay" />').click(C)[0], a = w('<div id="lbCenter" />')[0], G = w('<div id="lbBottomContainer" />')[0]]).css("display", "none")); 10 g = w('<div id="lbImage" />').appendTo(a).append(p = w('<div style="position: relative;" />').append([I = w('<a id="lbPrevLink" href="#" />').click(B)[0], d = w('<a id="lbNextLink" href="#" />').click(e)[0]])[0])[0]; 11 c = w('<div id="lbBottom" />').appendTo(G).append([w('<a id="lbCloseLink" href="#" />').click(C)[0], A = w('<div id="lbCaption" />')[0], K = w('<div id="lbNumber" />')[0], w('<div style="clear: both;" />')[0]])[0] 12 }); 13 w.slimbox = function (O, N, M) { 14 u = w.extend({loop: false, overlayOpacity: 0.8, overlayFadeDuration: 400, resizeDuration: 400, resizeEasing: "swing", initialWidth: 250, initialHeight: 250, imageFadeDuration: 400, captionAnimationDuration: 400, counterText: "Image {x} of {y}", closeKeys: [27, 88, 67], previousKeys: [37, 80], nextKeys: [39, 78]}, M); 15 if (typeof O == "string") { 16 O = [ 17 [O, N] 18 ]; 19 N = 0 20 } 21 y = E.scrollTop() + (E.height() / 2); 22 L = u.initialWidth; 23 r = u.initialHeight; 24 w(a).css({top: Math.max(0, y - (r / 2)), width: L, height: r, marginLeft: -L / 2}).show(); 25 v = m || (H.currentStyle && (H.currentStyle.position != "fixed")); 26 if (v) { 27 H.style.position = "absolute" 28 } 29 w(H).css("opacity", u.overlayOpacity).fadeIn(u.overlayFadeDuration); 30 z(); 31 j(1); 32 f = O; 33 u.loop = u.loop && (f.length > 1); 34 return b(N) 35 }; 36 w.fn.slimbox = function (M, P, O) { 37 P = P || function (Q) { 38 return[Q.href, Q.title] 39 }; 40 O = O || function () { 41 return true 42 }; 43 var N = this; 44 return N.unbind("click").click(function () { 45 var S = this, U = 0, T, Q = 0, R; 46 T = w.grep(N, function (W, V) { 47 return O.call(S, W, V) 48 }); 49 for (R = T.length; Q < R; ++Q) { 50 if (T[Q] == S) { 51 U = Q 52 } 53 T[Q] = P(T[Q], Q) 54 } 55 return w.slimbox(T, U, M) 56 }) 57 }; 58 function z() { 59 var N = E.scrollLeft(), M = E.width(); 60 w([a, G]).css("left", N + (M / 2)); 61 if (v) { 62 w(H).css({left: N, top: E.scrollTop(), width: M, height: E.height()}) 63 } 64 } 65 66 function j(M) { 67 if (M) { 68 w("object").add(m ? "select" : "embed").each(function (O, P) { 69 s[O] = [P, P.style.visibility]; 70 P.style.visibility = "hidden" 71 }) 72 } else { 73 w.each(s, function (O, P) { 74 P[0].style.visibility = P[1] 75 }); 76 s = [] 77 } 78 var N = M ? "bind" : "unbind"; 79 E[N]("scroll resize", z); 80 w(document)[N]("keydown", o) 81 } 82 83 function o(O) { 84 var N = O.which, M = w.inArray; 85 return(M(N, u.closeKeys) >= 0) ? C() : (M(N, u.nextKeys) >= 0) ? e() : (M(N, u.previousKeys) >= 0) ? B() : null 86 } 87 88 function B() { 89 return b(x) 90 } 91 92 function e() { 93 return b(D) 94 } 95 96 function b(M) { 97 if (M >= 0) { 98 F = M; 99 n = f[F][0]; 100 x = (F || (u.loop ? f.length : 0)) - 1; 101 D = ((F + 1) % f.length) || (u.loop ? 0 : -1); 102 q(); 103 a.className = "lbLoading"; 104 k = new Image(); 105 k.onload = i; 106 k.src = n 107 } 108 return false 109 } 110 111 function i() { 112 a.className = ""; 113 w(g).css({backgroundImage: "url(" + n + ")", visibility: "hidden", display: ""}); 114 w(p).width(k.width); 115 w([p, I, d]).height(k.height); 116 w(A).html(f[F][1] || ""); 117 w(K).html((((f.length > 1) && u.counterText) || "").replace(/{x}/, F + 1).replace(/{y}/, f.length)); 118 if (x >= 0) { 119 t.src = f[x][0] 120 } 121 if (D >= 0) { 122 J.src = f[D][0] 123 } 124 L = g.offsetWidth; 125 r = g.offsetHeight; 126 var M = Math.max(0, y - (r / 2)); 127 if (a.offsetHeight != r) { 128 w(a).animate({height: r, top: M}, u.resizeDuration, u.resizeEasing) 129 } 130 if (a.offsetWidth != L) { 131 w(a).animate({width: L, marginLeft: -L / 2}, u.resizeDuration, u.resizeEasing) 132 } 133 w(a).queue(function () { 134 w(G).css({width: L, top: M + r, marginLeft: -L / 2, visibility: "hidden", display: ""}); 135 w(g).css({display: "none", visibility: "", opacity: ""}).fadeIn(u.imageFadeDuration, h) 136 }) 137 } 138 139 function h() { 140 if (x >= 0) { 141 w(I).show() 142 } 143 if (D >= 0) { 144 w(d).show() 145 } 146 w(c).css("marginTop", -c.offsetHeight).animate({marginTop: 0}, u.captionAnimationDuration); 147 G.style.visibility = "" 148 } 149 150 function q() { 151 k.onload = null; 152 k.src = t.src = J.src = n; 153 w([a, g, c]).stop(true); 154 w([I, d, g, G]).hide() 155 } 156 157 function C() { 158 if (F >= 0) { 159 q(); 160 F = x = D = -1; 161 w(a).hide(); 162 w(H).stop().fadeOut(u.overlayFadeDuration, j) 163 } 164 return false 165 } 166})(jQuery); 167 168// AUTOLOAD CODE BLOCK (MAY BE CHANGED OR REMOVED) 169if (!/android|iphone|ipod|series60|symbian|windows ce|blackberry/i.test(navigator.userAgent)) { 170 jQuery(function ($) { 171 $("a[rel^='cyberchimps-lightbox']").slimbox({/* Put custom options here */}, null, function (el) { 172 return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel)); 173 }); 174 }); 175} 176else { 177 jQuery(function ($) { 178 $("a[rel^='cyberchimps-lightbox']").click(function (e) { 179 e.preventDefault(); 180 }); 181 // Prevents the image to load in lightbox 182 $("a[rel^='cyberchimps-lightbox']").click(function (e) { 183 184 var source = $(this).attr('href') 185 var endIndex = source.lastIndexOf('.'); 186 var endValue = source.substring(endIndex + 1); 187 var arr = ['jpg', 'png', 'gif', 'jpeg'] 188 189 if ($.inArray(endValue, arr) >= 0) { 190 e.preventDefault(); 191 } 192 193 }); 194 }); 195}