1/** 2 * @name Audiomania Slider Plugin 3 * @version 1.0 4 * @author Aleksandr Semenov 5 * @since 2013.10.14 16:52 6 */ 7;( function ( $, window ) { 8 9 if ( ! $.audiomania ) { 10 $.audiomania = {}; 11 } 12 13 $.audiomania.blockSlider = function ( el, config ) { 14 if ( ! el ) { 15 return; 16 } 17 var self = this; 18 19 $.extend ( self, { 20 init : function () { 21 self.el = el; 22 self.$el = $( el ); 23 var cache = self.$el.data( 'amSlider' ); 24 25 if ( ! cache ) { 26 self.$el.data( 'amSlider', self ); 27 self.options = $.extend( {}, $.audiomania.blockSlider.defaults, config, $.audiomania.blockSlider.options ); 28 self.id = self.options.cssClass + '-' + new Date().getTime(); 29 30 var $slides = self.$el.find( 'ul' ).eq( 0 ), 31 $slide = $slides.find( '> li' ); 32 33 self.$el.addClass ( self.options.cssClass ); 34 $slide.addClass ( self.options.cssClass + '-slide' ); 35 36 self.slideWidth = $slide.outerWidth(); 37 self.slideCount = $slide.length; 38 self.slideCurrent = 0; 39 40 $slides.addClass ( self.options.cssClass + '-slides' ).css( { 41 width : ( self.slideWidth * self.slideCount + ( self.slideCount ) * self.options.marginLeft ) 42 } ); 43 44 self.$slides = $slides; 45 self.$slide = $slide; 46 47 $slide.mouseenter( function() { $slides.clearQueue().stop(); clearTimeout( self.timerId ); } ); 48 $slide.mouseleave( function() { self.timerId = setTimeout( self.automove, self.options.pause ); } ); 49 50 self.navigation(); 51 $( window ).bind( 'resize.' + self.id, self.navigation ); 52 } else { 53 self = cache; 54 } 55 }, 56 destroy : function () { 57 self.$navigation.remove(); 58 $( window ).unbind ( 'resize.' + self.id ); 59 self.$slides.css( { width : 'auto' } ); 60 self.$el.removeData ( 'amSlider' ); 61 self.$el.removeClass ( self.options.cssClass ); 62 var classPrefix = new RegExp ( self.options.cssClass + '[\\S]*', 'ig' ); 63 self.$el.find( '*' ).each( function ( index, el ) { 64 el.className = el.className.replace( classPrefix, '' ).trim(); 65 if ( ! el.className ) { 66 el.removeAttribute( 'class' ); 67 } 68 } ); 69 }, 70 navigation : function () { 71 if ( self.$navigation ) { 72 self.$navigation.remove(); 73 clearTimeout( self.timerId ); 74 self.slideCurrent = 0; 75 self.$slides.stop(); 76 self.$slides.css( { left : 0 } ); 77 } 78 var settings = self.options, 79 slideWidth = self.slideWidth, 80 pages = Math.ceil( self.slideCount / parseInt( self.$el.width() / slideWidth ) ); 81 82 if ( pages < 2 ) { 83 return; 84 } 85 86 var $navigation = $( '<div />', { 87 'class' : settings.cssClass + '-navigation' 88 } ); 89 90 for ( var i = 0; i < pages; i++ ) { 91 var $point = $( '<a />', { 92 'class' : settings.cssClass + '-navigation-page', 93 href : '#', 94 html : $( '<span />' ) 95 } ); 96 $point.bind ( 'click', self.active ); 97 $point.appendTo( $navigation ); 98 } 99 100 self.$navigation = $navigation; 101 self.pages = pages; 102 103 if ( self.options.autoStart && $.isNumeric( self.options.pause ) && self.options.pause > 0 ) { 104 self.automove(); 105 } else { 106 $navigation.find( 'a' ).eq ( self.slideCurrent ).trigger( 'click' ); 107 } 108 109 $navigation.appendTo( self.$el ); 110 }, 111 active : function ( event ) { 112 if ( self.$slides.is( ':animated' ) ) { 113 return false; 114 } 115 if ( event ) { 116 clearTimeout( self.timerId ); 117 } 118 var $this = $( this ), 119 activeClass = self.options.cssClass + '-navigation-page-active'; 120 121 $this.parent().find( '.' + activeClass ).removeClass( activeClass ); 122 $this.addClass( activeClass ); 123 self.animate(); 124 return false; 125 }, 126 animate : function () { 127 var slideWidth = self.slideWidth, 128 currentIndex = self.$el.find( '.' + self.options.cssClass + '-navigation-page-active' ).index(); 129 130 if ( currentIndex < 0 ) { 131 return; 132 } 133 134 self.$slides.animate( { 135 left : -1 * currentIndex * ( slideWidth + self.options.marginLeft ) * parseInt( self.$el.width() / slideWidth ) 136 }, { easing : self.options.easing, duration : self.options.speed } ); 137 }, 138 automove : function () { 139 if ( ! self.$navigation ) { 140 return; 141 } 142 self.active.apply ( self.$navigation.find( 'a' ).eq ( self.slideCurrent ).get( 0 ) ); 143 self.slideCurrent ++; 144 if ( self.slideCurrent >= self.pages ) { 145 self.slideCurrent = 0; 146 } 147 self.timerId = setTimeout( self.automove, self.options.pause ); 148 } 149 } ); 150 151 self.init(); 152 }; 153 154 $.audiomania.blockSlider.options = { 155 marginLeft : 20 156 }; 157 158 $.audiomania.blockSlider.defaults = { 159 cssClass : 'am-slider', // Base CSS class 160 autoStart : true, // Auto animate 161 pause : 14000, // Pause in auto animation 162 speed : 2000, // Duration of animation 163 easing : 'swing' // Method of animation 164 }; 165 166 $.fn.amSlider = function ( config ) { 167 return this.each( function () {
168 new $.audiomania.blockSlider ( this, config ); 169 } ); 170 }; 171 172} ) ( jQuery, window );
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.