1(function( $, undefined ) { 2 3 /* 4 * Slider object. 5 */ 6 $.Slider = function( options, element ) { 7 8 this.$el = $( element ); 9 10 this._init( options ); 11 12 }; 13 14 $.Slider.defaults = { 15 current : 0, // index of current slide 16 bgincrement : 50, // increment the bg position (parallax effect) when sliding 17 autoplay : false,// slideshow on / off 18 interval : 4000 // time between transitions 19 }; 20 21 $.Slider.prototype = { 22 _init : function( options ) { 23 24 this.options = $.extend( true, {}, $.Slider.defaults, options ); 25 26 this.$slides = this.$el.children('div.da-slide'); 27 this.slidesCount = this.$slides.length; 28 29 this.current = this.options.current; 30 31 if( this.current < 0 || this.current >= this.slidesCount ) { 32 33 this.current = 0; 34 35 } 36 37 this.$slides.eq( this.current ).addClass( 'da-slide-current' ); 38 39 var $navigation = $( '<nav class="da-dots"/>' ); 40 for( var i = 0; i < this.slidesCount; ++i ) { 41 42 $navigation.append( '<span/>' ); 43 44 } 45 $navigation.appendTo( this.$el ); 46 47 this.$pages = this.$el.find('nav.da-dots > span'); 48 this.$navNext = this.$el.find('span.da-arrows-next'); 49 this.$navPrev = this.$el.find('span.da-arrows-prev'); 50 51 this.isAnimating = false; 52 53 this.bgpositer = 0; 54 55 this.cssAnimations = Modernizr.cssanimations; 56 this.cssTransitions = Modernizr.csstransitions; 57 58 if( !this.cssAnimations || !this.cssAnimations ) { 59 60 this.$el.addClass( 'da-slider-fb' ); 61 62 } 63 64 this._updatePage(); 65 66 // load the events 67 this._loadEvents(); 68 69 // slideshow 70 if( this.options.autoplay ) { 71 72 this._startSlideshow(); 73 74 } 75 76 }, 77 _navigate : function( page, dir ) { 78 79 var $current = this.$slides.eq( this.current ), $next, _self = this; 80 81 if( this.current === page || this.isAnimating ) return false; 82 83 this.isAnimating = true; 84 85 // check dir 86 var classTo, classFrom, d; 87 88 if( !dir ) { 89 90 ( page > this.current ) ? d = 'next' : d = 'prev'; 91 92 } 93 else { 94 95 d = dir; 96 97 } 98 99 if( this.cssAnimations && this.cssAnimations ) { 100 101 if( d === 'next' ) { 102 103 classTo = 'da-slide-toleft'; 104 classFrom = 'da-slide-fromright'; 105 ++this.bgpositer; 106 107 } 108 else { 109 110 classTo = 'da-slide-toright'; 111 classFrom = 'da-slide-fromleft'; 112 --this.bgpositer; 113 114 } 115 116 this.$el.css( 'background-position' , this.bgpositer * this.options.bgincrement + '% 0%' ); 117 118 } 119 120 this.current = page; 121 122 $next = this.$slides.eq( this.current ); 123 124 if( this.cssAnimations && this.cssAnimations ) { 125 126 var rmClasses = 'da-slide-toleft da-slide-toright da-slide-fromleft da-slide-fromright'; 127 $current.removeClass( rmClasses ); 128 $next.removeClass( rmClasses ); 129 130 $current.addClass( classTo ); 131 $next.addClass( classFrom ); 132 133 $current.removeClass( 'da-slide-current' ); 134 $next.addClass( 'da-slide-current' ); 135 136 } 137 138 // fallback 139 if( !this.cssAnimations || !this.cssAnimations ) { 140 141 $next.css( 'left', ( d === 'next' ) ? '100%' : '-100%' ).stop().animate( { 142 left : '0%' 143 }, 1000, function() { _self.isAnimating = false; } ); 144 $current.stop().animate( { 145 left : ( d === 'next' ) ? '-100%' : '100%' 146 }, 1000, function() { $current.removeClass( 'da-slide-current' ); } ); 147 148 } 149 150 this._updatePage(); 151 152 }, 153 _updatePage : function() { 154 155 this.$pages.removeClass( 'da-dots-current' ); 156 this.$pages.eq( this.current ).addClass( 'da-dots-current' ); 157 158 }, 159 _startSlideshow : function() { 160 161 var _self = this; 162 163 this.slideshow = setTimeout( function() { 164 165 var page = ( _self.current < _self.slidesCount - 1 ) ? page = _self.current + 1 : page = 0; 166 _self._navigate( page, 'next' ); 167 168 if( _self.options.autoplay ) { 169 170 _self._startSlideshow(); 171 172 } 173 174 }, this.options.interval ); 175 176 }, 177 _loadEvents : function() { 178 179 var _self = this; 180 181 this.$pages.on( 'click.cslider', function( event ) { 182 183 if( _self.options.autoplay ) { 184 185 clearTimeout( _self.slideshow ); 186 _self.options.autoplay = false;
187 188 } 189 190 _self._navigate( $(this).index() ); 191 return false; 192 193 }); 194 195 this.$navNext.on( 'click.cslider', function( event ) { 196 197 if( _self.options.autoplay ) { 198 199 clearTimeout( _self.slideshow ); 200 _self.options.autoplay = false; 201 202 } 203 204 var page = ( _self.current < _self.slidesCount - 1 ) ? page = _self.current + 1 : page = 0; 205 _self._navigate( page, 'next' ); 206 return false; 207 208 }); 209 210 this.$navPrev.on( 'click.cslider', function( event ) { 211 212 if( _self.options.autoplay ) { 213 214 clearTimeout( _self.slideshow ); 215 _self.options.autoplay = false; 216 217 } 218 219 var page = ( _self.current > 0 ) ? page = _self.current - 1 : page = _self.slidesCount - 1; 220 _self._navigate( page, 'prev' ); 221 return false; 222 223 }); 224 225 if( this.cssTransitions ) { 226 227 this.$el.on( 'webkitTransitionEnd.cslider transitionend.cslider OTransitionEnd.cslider', function( event ) { 228 229 if( event.target.id === _self.$el.attr( 'id' ) ) 230 _self.isAnimating = false; 231 232 }); 233 234 } 235 236 } 237 }; 238 239 var logError = function( message ) { 240 if ( this.console ) { 241 console.error( message ); 242 } 243 }; 244 245 $.fn.cslider = function( options ) { 246 247 if ( typeof options === 'string' ) { 248 249 var args = Array.prototype.slice.call( arguments, 1 ); 250 251 this.each(function() { 252 253 var instance = $.data( this, 'cslider' ); 254 255 if ( !instance ) { 256 logError( "cannot call methods on cslider prior to initialization; " + 257 "attempted to call method '" + options + "'" ); 258 return; 259 } 260 261 if ( !$.isFunction( instance[options] ) || options.charAt(0) === "_" ) { 262 logError( "no such method '" + options + "' for cslider instance" ); 263 return; 264 } 265 266 instance[ options ].apply( instance, args ); 267 268 }); 269 270 } 271 else { 272 273 this.each(function() { 274 275 var instance = $.data( this, 'cslider' ); 276 if ( !instance ) { 277 $.data( this, 'cslider', new $.Slider( options, this ) ); 278 } 279 }); 280 281 } 282 283 return this; 284 285 }; 286 287})( jQuery );
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.