1 | /*! |
---|
2 | Slimbox v1.8 - The ultimate lightweight Lightbox clone |
---|
3 | (c) 2007-2011 Christophe Beyls <http://www.digitalia.be> |
---|
4 | MIT-style license. |
---|
5 | */ |
---|
6 | var Slimbox = (function() |
---|
7 | { |
---|
8 | var F = window,n = Browser.ie6,u,g,G = -1,o,w,E,v,y,M,s,m = {},t = new Image(),K = new Image(),I,a,h,q,J,e,H,c,A,L,x,i,d,C; |
---|
9 | F.addEvent( "domready", function() |
---|
10 | { |
---|
11 | $( document.body ).adopt( $$( I = new Element( "div#lbOverlay", {events:{click:D}} ), a = new Element( "div#lbCenter" ), H = new Element( "div#lbBottomContainer" ) ).setStyle( "display", "none" ) ); |
---|
12 | h = new Element( "div#lbImage" ).inject( a ).adopt( q = new Element( "div", {styles:{position:"relative"}} ).adopt( J = new Element( "a#lbPrevLink[href=#]", {events:{click:B}} ), e = new Element( "a#lbNextLink[href=#]", {events:{click:f}} ) ) ); |
---|
13 | c = new Element( "div#lbBottom" ).inject( H ).adopt( new Element( "a#lbCloseLink[href=#]", {events:{click:D}} ), A = new Element( "div#lbCaption" ), L = new Element( "div#lbNumber" ), new Element( "div", {styles:{clear:"both"}} ) ) |
---|
14 | } ); |
---|
15 | function z() |
---|
16 | { |
---|
17 | var N = F.getScroll(),O = F.getSize(); |
---|
18 | $$( a, H ).setStyle( "left", N.x + (O.x / 2) ); |
---|
19 | if( v ) |
---|
20 | { |
---|
21 | I.setStyles( {left:N.x,top:N.y,width:O.x,height:O.y} ) |
---|
22 | } |
---|
23 | } |
---|
24 | |
---|
25 | function l( N ) |
---|
26 | { |
---|
27 | ["object",n ? "select" : "embed"].forEach( function( P ) |
---|
28 | { |
---|
29 | Array.forEach( document.getElementsByTagName( P ), function( Q ) |
---|
30 | { |
---|
31 | if( N ) |
---|
32 | { |
---|
33 | Q._slimbox = Q.style.visibility |
---|
34 | } |
---|
35 | Q.style.visibility = N ? "hidden" : Q._slimbox |
---|
36 | } ) |
---|
37 | } ); |
---|
38 | I.style.display = N ? "" : "none"; |
---|
39 | var O = N ? "addEvent" : "removeEvent"; |
---|
40 | F[O]( "scroll", z )[O]( "resize", z ); |
---|
41 | document[O]( "keydown", p ) |
---|
42 | } |
---|
43 | |
---|
44 | function p( O ) |
---|
45 | { |
---|
46 | var N = O.code; |
---|
47 | return u.closeKeys.contains( N ) ? D() : u.nextKeys.contains( N ) ? f() : u.previousKeys.contains( N ) ? B() : false |
---|
48 | } |
---|
49 | |
---|
50 | function B() |
---|
51 | { |
---|
52 | return b( w ) |
---|
53 | } |
---|
54 | |
---|
55 | function f() |
---|
56 | { |
---|
57 | return b( E ) |
---|
58 | } |
---|
59 | |
---|
60 | function b( N ) |
---|
61 | { |
---|
62 | if( N >= 0 ) |
---|
63 | { |
---|
64 | G = N; |
---|
65 | o = g[N][0]; |
---|
66 | w = (G || (u.loop ? g.length : 0)) - 1; |
---|
67 | E = ((G + 1) % g.length) || (u.loop ? 0 : -1); |
---|
68 | r(); |
---|
69 | a.className = "lbLoading"; |
---|
70 | m = new Image(); |
---|
71 | m.onload = k; |
---|
72 | m.src = o |
---|
73 | } |
---|
74 | return false |
---|
75 | } |
---|
76 | |
---|
77 | function k() |
---|
78 | { |
---|
79 | a.className = ""; |
---|
80 | d.set( 0 ); |
---|
81 | h.setStyles( {backgroundImage:"url(" + o + ")",display:""} ); |
---|
82 | q.setStyle( "width", m.width ); |
---|
83 | $$( q, J, e ).setStyle( "height", m.height ); |
---|
84 | A.set( "html", g[G][1] || "" ); |
---|
85 | L.set( "html", (((g.length > 1) && u.counterText) || "").replace( /{x}/, G + 1 ).replace( /{y}/, g.length ) ); |
---|
86 | if( w >= 0 ) |
---|
87 | { |
---|
88 | t.src = g[w][0] |
---|
89 | } |
---|
90 | if( E >= 0 ) |
---|
91 | { |
---|
92 | K.src = g[E][0] |
---|
93 | } |
---|
94 | M = h.offsetWidth; |
---|
95 | s = h.offsetHeight; |
---|
96 | var P = Math.max( 0, y - (s / 2) ),N = 0,O; |
---|
97 | if( a.offsetHeight != s ) |
---|
98 | { |
---|
99 | N = i.start( {height:s,top:P} ) |
---|
100 | } |
---|
101 | if( a.offsetWidth != M ) |
---|
102 | { |
---|
103 | N = i.start( {width:M,marginLeft:-M / 2} ) |
---|
104 | } |
---|
105 | O = function() |
---|
106 | { |
---|
107 | H.setStyles( {width:M,top:P + s,marginLeft:-M / 2,visibility:"hidden",display:""} ); |
---|
108 | d.start( 1 ) |
---|
109 | }; |
---|
110 | if( N ) |
---|
111 | { |
---|
112 | i.chain( O ) |
---|
113 | } |
---|
114 | else |
---|
115 | { |
---|
116 | O() |
---|
117 | } |
---|
118 | } |
---|
119 | |
---|
120 | function j() |
---|
121 | { |
---|
122 | if( w >= 0 ) |
---|
123 | { |
---|
124 | J.style.display = "" |
---|
125 | } |
---|
126 | if( E >= 0 ) |
---|
127 | { |
---|
128 | e.style.display = "" |
---|
129 | } |
---|
130 | C.set( -c.offsetHeight ).start( 0 ); |
---|
131 | H.style.visibility = "" |
---|
132 | } |
---|
133 | |
---|
134 | function r() |
---|
135 | { |
---|
136 | m.onload = null; |
---|
137 | m.src = t.src = K.src = o; |
---|
138 | i.cancel(); |
---|
139 | d.cancel(); |
---|
140 | C.cancel(); |
---|
141 | $$( J, e, h, H ).setStyle( "display", "none" ) |
---|
142 | } |
---|
143 | |
---|
144 | function D() |
---|
145 | { |
---|
146 | if( G >= 0 ) |
---|
147 | { |
---|
148 | r(); |
---|
149 | G = w = E = -1; |
---|
150 | a.style.display = "none"; |
---|
151 | x.cancel().chain( l ).start( 0 ) |
---|
152 | } |
---|
153 | return false |
---|
154 | } |
---|
155 | |
---|
156 | Element.implement( {slimbox:function( N, O ) |
---|
157 | { |
---|
158 | $$( this ).slimbox( N, O ); |
---|
159 | return this |
---|
160 | }} ); |
---|
161 | Elements.implement( {slimbox:function( N, Q, P ) |
---|
162 | { |
---|
163 | Q = Q || function( R ) |
---|
164 | { |
---|
165 | return[R.href,R.title] |
---|
166 | }; |
---|
167 | P = P || function() |
---|
168 | { |
---|
169 | return true |
---|
170 | }; |
---|
171 | var O = this; |
---|
172 | O.removeEvents( "click" ).addEvent( "click", function() |
---|
173 | { |
---|
174 | var R = O.filter( P, this ); |
---|
175 | return Slimbox.open( R.map( Q ), R.indexOf( this ), N ) |
---|
176 | } ); |
---|
177 | return O |
---|
178 | }} ); |
---|
179 | return{open:function( P, O, N ) |
---|
180 | { |
---|
181 | u = Object.append( {loop:false,overlayOpacity:0.8,overlayFadeDuration:400,resizeDuration:400,resizeTransition:false,initialWidth:250,initialHeight:250,imageFadeDuration:400,captionAnimationDuration:400,counterText:"Image {x} of {y}",closeKeys:[27,88,67],previousKeys:[37,80],nextKeys:[39,78]}, N || {} ); |
---|
182 | x = new Fx.Tween( I, {property:"opacity",duration:u.overlayFadeDuration} ); |
---|
183 | i = new Fx.Morph( a, Object.append( {duration:u.resizeDuration,link:"chain"}, u.resizeTransition ? {transition:u.resizeTransition} : {} ) ); |
---|
184 | d = new Fx.Tween( h, {property:"opacity",duration:u.imageFadeDuration,onComplete:j} ); |
---|
185 | C = new Fx.Tween( c, {property:"margin-top",duration:u.captionAnimationDuration} ); |
---|
186 | if( typeof P == "string" ) |
---|
187 | { |
---|
188 | P = [ |
---|
189 | [P,O] |
---|
190 | ]; |
---|
191 | O = 0 |
---|
192 | } |
---|
193 | y = F.getScrollTop() + (F.getHeight() / 2); |
---|
194 | M = u.initialWidth; |
---|
195 | s = u.initialHeight; |
---|
196 | a.setStyles( {top:Math.max( 0, y - (s / 2) ),width:M,height:s,marginLeft:-M / 2,display:""} ); |
---|
197 | v = n || (I.currentStyle && (I.currentStyle.position != "fixed")); |
---|
198 | if( v ) |
---|
199 | { |
---|
200 | I.style.position = "absolute" |
---|
201 | } |
---|
202 | x.set( 0 ).start( u.overlayOpacity ); |
---|
203 | z(); |
---|
204 | l( 1 ); |
---|
205 | g = P; |
---|
206 | u.loop = u.loop && (g.length > 1); |
---|
207 | return b( O ) |
---|
208 | }} |
---|
209 | })(); |
---|
210 | |
---|
211 | // AUTOLOAD CODE BLOCK (MAY BE CHANGED OR REMOVED) |
---|
212 | Slimbox.scanPage = function() |
---|
213 | { |
---|
214 | $$( "a[rel^=lightbox]" ).slimbox( {/* Put custom options here */}, null, function( el ) |
---|
215 | { |
---|
216 | return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel)); |
---|
217 | } ); |
---|
218 | }; |
---|
219 | if( !/android|iphone|ipod|series60|symbian|windows ce|blackberry/i.test( navigator.userAgent ) ) |
---|
220 | { |
---|
221 | window.addEvent( "domready", Slimbox.scanPage ); |
---|
222 | } |
---|