source: ether_2012/trunk/web/resources/js/craftedpixelz-Craftyslide-4cd0adb/js/craftyslide.min.js @ 351

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

diaporama

File size: 3.4 KB
Line 
1/*
2 * Craftyslide
3 * Created by: Abid Din - http://craftedpixelz.co.uk
4 * Version: 1.0
5 * Copyright: Crafted Pixelz
6 * License: MIT license
7 * Updated: 7th June 2011
8 */
9
10(function( $ )
11{
12    $.fn.craftyslide = function( zoptions )
13    {
14        var defaults = {"width":600,"height":300,"pagination":true,"fadetime":350,"delay":500};
15        var options = $.extend( defaults, zoptions );
16        return this.each( function()
17        {
18            var $this = $( this );
19            var $slides = $this.find( "ul li" );
20            $slides.not( ':first' ).hide();
21            function paginate()
22            {
23                $this.append( "<ol id='pagination' />" );
24                var i = 1;
25                $slides.each( function()
26                {
27                    $( this ).attr( "id", "slide" + i );
28                    $( "#pagination" ).append( "<li><a href='#slide" + i + "'>" + i + "</a></li>" );
29                    i++;
30                } );
31                $( "#pagination li a:first" ).addClass( "active" );
32            }
33
34            function captions()
35            {
36                $slides.each( function()
37                {
38                    $caption = $( this ).find( "img" ).attr( "title" );
39                    if( $caption !== undefined )
40                    {
41                        $( this ).prepend( "<p class='caption'>" + $caption + "</p>" );
42                    }
43                    $slides.filter( ":first" ).find( ".caption" ).css( "bottom", 0 );
44                } );
45            }
46
47            function manual()
48            {
49                var $pagination = $( "#pagination li a" );
50                $pagination.click( function( e )
51                {
52                    e.preventDefault();
53                    var $current = $( this.hash );
54                    if( $current.is( ":hidden" ) )
55                    {
56                        $slides.fadeOut( options.fadetime );
57                        $current.fadeIn( options.fadetime );
58                        $pagination.removeClass( "active" );
59                        $( this ).addClass( "active" );
60                        $( ".caption" ).css( "bottom", "-37px" );
61                        $current.find( ".caption" ).delay( 300 ).animate( {bottom:0}, 300 );
62                    }
63                } );
64            }
65
66            function auto()
67            {
68                setInterval( function()
69                {
70                    $slides.filter( ":first-child" ).fadeOut( options.fadetime ).next( "li" ).fadeIn( options.fadetime ).end().appendTo( "#slideshow ul" );
71                    $slides.each( function()
72                    {
73                        if( $slides.is( ":visible" ) )
74                        {
75                            $( ".caption" ).css( "bottom", "-37px" );
76                            $( this ).find( ".caption" ).delay( 300 ).animate( {bottom:0}, 300 );
77                        }
78                    } );
79                }, options.delay );
80            }
81
82            $this.width( options.width );
83            $this.find( "ul, li img" ).width( options.width );
84            $this.height( options.height );
85            $this.find( "ul, li" ).height( options.height );
86            if( options.pagination === true )
87            {
88                paginate();
89            }
90            else
91            {
92                auto();
93            }
94            captions();
95            manual();
96        } );
97    };
98})( jQuery );
Note: See TracBrowser for help on using the repository browser.