1jQuery(function( $ ) { 2 3 var Slider = (function () { 4 5 function _Slider(element, settings) { 6 this.defaults = { 7 8 slideDuration: '5000', 9 speed: 500, 10 arrowRight: '.right-arrow', 11 arrowLeft: '.left-arrow' 12 13 }; 14 15 this.settings = $.extend({}, this.defaults, settings); 16 17 this.initials = { 18 currentSlide: 0, 19 $currentSlide: null, 20 totalSlides: false, 21 cssTransitions: false 22 }; 23 24 $.extend(this, this.initials); 25 26 this.$el = $(element); 27 28 this.changeSlide = $.proxy(this.changeSlide, this); 29 30 this.init(); 31 32 } 33 34 return _Slider; 35 36 })(); 37 38 Slider.prototype.init = function () { 39 this.cssTransitionTest(); 40 this.$el.addClass('slider'); 41 this.build(); 42 this.events(); 43 this.activate(); 44 this.initTimer(); 45 }; 46 47 Slider.prototype.cssTransitionTest = function () { 48 var elem = document.createElement('modernizr'); 49 50 var props = ['transition', 'WebkitTransition', 'MozTransition', 'OTransition', 'msTransition']; 51 52 for (var i in props) { 53 var prop = props[i]; 54 var result = elem.style[prop] !== undefined ? prop : false; 55 if (result) { 56 this.cssTransitions = result; 57 break; 58 } 59 } 60 }; 61 62 Slider.prototype.addCSSDuration = function () { 63 var sliderModule = this; 64 65 sliderModule.$el.find('.testimonial-slide').each(function () { 66 67 this.style[sliderModule.cssTransitions + 'Duration'] = sliderModule.settings.speed + 'ms'; 68 }); 69 }; 70 71 Slider.prototype.removeCSSDuration = function () { 72 var sliderModule = this; 73 74 //here we are using 'this' but we can also write sliderModule 75 //since we are refering to the same element...shorter and cleaner 76 this.$el.find('.testimonial-slide').each(function () { 77 this.style[sliderModule.cssTransitions + 'Duration'] = ''; 78 }); 79 }; 80 81 82 //create indicator dots below which also have the functionality 83 //as the arrows 84 Slider.prototype.build = function () { 85 var $indicators = this.$el.append("<ul class='dots-wrapper'>").find('.dots-wrapper'); 86 this.totalSlides = this.$el.find('.testimonial-slide').length; 87 for (var i = 0; i < this.totalSlides; i++) { 88 $indicators.append("<li data-index=" + i + ">"); 89 } 90 }; 91 92 Slider.prototype.activate = function () { 93 this.$currentSlide = this.$el.find('.testimonial-slide').eq(0); 94 this.$el.find('.dots-wrapper li').eq(0).addClass('active'); 95 }; 96 97 Slider.prototype.events = function () { 98 $('body') 99 .on('click', this.settings.arrowRight, { 100 direction: 'right' 101 }, this.changeSlide) 102 .on('click', this.settings.arrowLeft, { 103 direction: 'left' 104 }, this.changeSlide) 105 .on('click', '.dots-wrapper li', this.changeSlide); 106 }; 107 108 Slider.prototype.clearTimer = function () { 109 if (this.timer) { 110 clearInterval(this.timer); 111 } 112 }; 113 114 Slider.prototype.initTimer = function () { 115 this.timer = setInterval( 116 this.changeSlide, this.settings.slideDuration); 117 }; 118 119 Slider.prototype.startTimer = function () { 120 this.initTimer(); 121 this.throttle = false; 122 }; 123 124 Slider.prototype.changeSlide = function (e) { 125 if (this.throttle) { 126 return; 127 } 128 this.throttle = true; 129 130 this.clearTimer(); 131 132 var direction = this._direction(e); 133 134 var animate = this._next(e, direction); 135 if (!animate) { 136 return; 137 } 138 139 var $nextSlide = this.$el.find('.testimonial-slide').eq(this.currentSlide).addClass(direction + ' active'); 140 141 if (!this.csstransitions) { 142 this._jsAnimation($nextSlide, direction); 143 } else { 144 this._cssAnimation($nextSlide, direction); 145 } 146 }; 147 148 Slider.prototype._direction = function (e) { 149 var direction; 150 if (typeof e !== 'undefined') { 151 direction = (typeof e.data === 'undefined' ? 'right' : e.data.direction); 152 } else { 153 direction = 'right'; 154 } 155 return direction; 156 }; 157 158 Slider.prototype._next = function (e, direction) { 159 var index = (typeof e !== 'undefined' ? $(e.currentTarget).data('index') : undefined); 160 switch (true) { 161 case (typeof index !== 'undefined'): 162 if (this.currentSlide == index) { 163 this.startTimer(); 164 return false;
165 } 166 this.currentSlide = index; 167 break; 168 case (direction == 'right' && this.currentSlide < (this.totalSlides - 1)): 169 this.currentSlide++; 170 break; 171 case (direction == 'right'): 172 this.currentSlide = 0; 173 break; 174 case (direction == 'left' && this.currentSlide === 0): 175 this.currentSlide = (this.totalSlides - 1); 176 break; 177 case (direction == 'left'): 178 this.currentSlide--; 179 break; 180 } 181 return true; 182 }; 183 184 Slider.prototype._cssAnimation = function ($nextSlide, direction) { 185 setTimeout(function () { 186 this.$el.addClass('transition'); 187 this.addDuration(); 188 this.$currentSlide.addClass('shift' + direction); 189 }.bind(this), 100); 190 191 setTimeout(function () { 192 this.$el.removeClass('transition'); 193 this.removeCSSDuration(); 194 this.$currentSlide.removeClass('active shift-left shift-right'); 195 this.$currentSlide = $nextSlide.removeClass(direction); 196 this._updateIndicators(); 197 this.startTimer(); 198 }.bind(this), 100 + this.settings.speed); 199 }; 200 201 Slider.prototype._jsAnimation = function ($nextSlide, direction) { 202 var sliderModule = this; 203 204 if (direction == 'right') { 205 sliderModule.$currentSlide.addClass('js-reset-left'); 206 } 207 var animation = {}; 208 animation[direction] = '0%'; 209 210 var animationPrev = {}; 211 animationPrev[direction] = '100%'; 212 213 this.$currentSlide.animate(animationPrev, this.settings.speed); 214 215 $nextSlide.animate(animation, this.settings.speed, 'swing', function () { 216 sliderModule.$currentSlide.removeClass('active js-reset-left').attr('style', ''); 217 sliderModule.$currentSlide = $nextSlide.removeClass(direction).attr('style', ''); 218 sliderModule._updateIndicators(); 219 sliderModule.startTimer(); 220 }); 221 }; 222 223 Slider.prototype._updateIndicators = function () { 224 this.$el.find('.dots-wrapper li').removeClass('active').eq(this.currentSlide).addClass('active'); 225 }; 226 227 $.fn.Slider = function (options) { 228 return this.each(function (index, el) { 229 el.Slider = new Slider(el, options); 230 }); 231 }; 232 233 var args = { 234 arrowRight: '.right-arrow', 235 arrowLeft: '.left-arrow', 236 speed: 500, 237 slideDuration: 5000 238 }; 239 240 $('.testimonial').Slider(args); 241 242 $(".testimonial .testimonial-ul").removeAttr("style"); 243 244 /*var biggestHeight = "0"; 245 $(".testimonial .testimonial-ul > .testimonial-slide.active").each(function(){ 246 if ($(this).height() > biggestHeight ) { 247 biggestHeight = $(this).height() 248 } 249 }); 250 251 $(".testimonial .testimonial-ul").height(biggestHeight);*/ 252 253});
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.