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 : 8000 // 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() { 144 _self.isAnimating = false; 145 }); 146 147 $current.stop().animate( { 148 left : ( d === 'next' ) ? '-100%' : '100%' 149 }, 1000, function() { 150 $current.removeClass( 'da-slide-current' ); 151 }); 152 153 } 154 155 this._updatePage(); 156 157 }, 158 _updatePage : function() { 159 160 this.$pages.removeClass( 'da-dots-current' ); 161 this.$pages.eq( this.current ).addClass( 'da-dots-current' ); 162 163 }, 164 _startSlideshow : function() { 165 166 var _self = this; 167 168 this.slideshow = setTimeout( function() { 169 170 var page = ( _self.current < _self.slidesCount - 1 ) ? page = _self.current + 1 : page = 0; 171 _self._navigate( page, 'next' ); 172 173 if( _self.options.autoplay ) { 174 175 _self._startSlideshow(); 176 177 } 178 179 }, this.options.interval ); 180 181 }, 182 page : function( idx ) { 183 184 if( idx >= this.slidesCount || idx < 0 ) { 185 186 return false; 187 188 } 189 190 if( this.options.autoplay ) { 191 192 clearTimeout( this.slideshow ); 193 this.options.autoplay = false; 194 195 } 196 197 this._navigate( idx ); 198 199 }, 200 _loadEvents : function() { 201 202 var _self = this; 203 204 this.$pages.on( 'click.cslider', function( event ) { 205 206 _self.page( $(this).index() ); 207 return false; 208 209 }); 210 211 this.$navNext.on( 'click.cslider', function( event ) { 212 213 if( _self.options.autoplay ) { 214 215 clearTimeout( _self.slideshow ); 216 _self.options.autoplay = false; 217 218 } 219 220 var page = ( _self.current < _self.slidesCount - 1 ) ? page = _self.current + 1 : page = 0; 221 _self._navigate( page, 'next' ); 222 return false; 223 224 }); 225 226 this.$navPrev.on( 'click.cslider', function( event ) { 227 228 if( _self.options.autoplay ) { 229 230 clearTimeout( _self.slideshow ); 231 _self.options.autoplay = false; 232 233 } 234 235 var page = ( _self.current > 0 ) ? page = _self.current - 1 : page = _self.slidesCount - 1; 236 _self._navigate( page, 'prev' ); 237 return false; 238 239 }); 240 241 if( this.cssTransitions ) { 242 243 if( !this.options.bgincrement ) { 244 245 this.$el.on( 'webkitAnimationEnd.cslider animationend.cslider OAnimationEnd.cslider', function( event ) { 246 247 if( event.originalEvent.animationName === 'toRightAnim4' || event.originalEvent.animationName === 'toLeftAnim4' ) { 248 249 _self.isAnimating = false; 250 251 } 252 253 });
254 255 } 256 else { 257 258 this.$el.on( 'webkitTransitionEnd.cslider transitionend.cslider OTransitionEnd.cslider', function( event ) { 259 260 if( event.target.id === _self.$el.attr( 'id' ) ) 261 _self.isAnimating = false; 262 263 }); 264 265 } 266 267 } 268 269 } 270 }; 271 272 var logError = function( message ) { 273 if ( this.console ) { 274 console.error( message ); 275 } 276 }; 277 278 $.fn.cslider = function( options ) { 279 280 if ( typeof options === 'string' ) { 281 282 var args = Array.prototype.slice.call( arguments, 1 ); 283 284 this.each(function() { 285 286 var instance = $.data( this, 'cslider' ); 287 288 if ( !instance ) { 289 logError( "cannot call methods on cslider prior to initialization; " + 290 "attempted to call method '" + options + "'" ); 291 return; 292 } 293 294 if ( !$.isFunction( instance[options] ) || options.charAt(0) === "_" ) { 295 logError( "no such method '" + options + "' for cslider instance" ); 296 return; 297 } 298 299 instance[ options ].apply( instance, args ); 300 301 }); 302 303 } 304 else { 305 306 this.each(function() { 307 308 var instance = $.data( this, 'cslider' ); 309 if ( !instance ) { 310 $.data( this, 'cslider', new $.Slider( options, this ) ); 311 } 312 }); 313 314 } 315 316 return this; 317 318 }; 319 320})( 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.