source: ether_statistics/web/resources/js/slimbox-1.8/js/slimbox.js @ 569

Last change on this file since 569 was 569, checked in by vmipsl, 12 years ago

Nouveau projet

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