1; 2(function($, window, document, undefined) { 3 "use strict"; 4 5 var pluginName = "ezScroller", 6 defaults = { 7 speed: 5000, 8 timeout: 5000, 9 numberToShow: 3, 10 auto: false, 11 direction: "horizontal" 12 }; 13 14 var horizontalItemStyles = { 15 display: "block", 16 float: "left" 17 }; 18 19 var verticalItemStyles = { 20 display: "block", 21 width: "100%" 22 }; 23 24 function Plugin(element, options) { 25 this.$element = $(element); 26 this.$parent = this.$element.parent(); 27 this.settings = $.extend({}, defaults, options); 28 this._defaults = defaults; 29 this._name = pluginName; 30 this.items = this.$element.children(); 31 this.length = this.items.length; 32 this.width = this.$element.outerWidth(true); 33 this.height = this.$element.outerHeight(true); 34 this.overflow = 0; 35 this.distanceTraveled = 0; 36 this.end = 0; 37 this.atEnd = false; 38 this.leftover = 0; 39 this.interval = null; 40 this.index = 0; 41 this.animating = false; 42 this.init(); 43 } 44 45 $.extend(Plugin.prototype, { 46 init: function() { 47 this.setup(); 48 this.start(); 49 }, 50 setup: function() { 51 if (this.settings.direction == "horizontal") { 52 this.items.addClass("ezc-horizontal-item").css(horizontalItemStyles); 53 } else { 54 this.items.addClass("ezc-vertical-item").css(verticalItemStyles); 55 } 56 this.settings.prevButton.addClass("ezc-button-disabled"); 57 }, 58 start: function() { 59 var _ = this; 60 if (this.settings.direction == "horizontal") { 61 _.items.each(function() { 62 var width = this.getBoundingClientRect().width; 63 var style = window.getComputedStyle(this); 64 var marginRight = parseFloat(style.marginRight); 65 var marginLeft = parseFloat(style.marginLeft); 66 var paddingRight = parseFloat(style.paddingRight); 67 var paddingLeft = parseFloat(style.paddingLeft); 68 _.overflow += (width + marginLeft + marginRight + paddingLeft + paddingRight); 69 $(this).css({ 70 width: width + "px" 71 }); 72 }); 73 74 _.overflow = Math.ceil(_.overflow); 75 _.end = -(_.overflow - _.width); 76 77 _.$element.css({ 78 width: _.overflow + "px", 79 transition: "all " + (_.settings.speed / 1000) + "s ease" 80 }).addClass("ezc-element"); 81 _.$parent.css({ 82 overflow: "hidden" 83 }); 84 } else { 85 var parentHeight = 0; 86 _.items.each(function(i) { 87 var height = this.getBoundingClientRect().height; 88 var style = window.getComputedStyle(this); 89 var marginTop = parseFloat(style.marginTop); 90 var marginBottom = parseFloat(style.marginBottom); 91 var paddingTop = parseFloat(style.paddingTop); 92 var paddingBottom = parseFloat(style.paddingBottom);
93 if ((i + 1) <= _.settings.numberToShow) parentHeight += height; 94 _.overflow += (height + marginTop + marginBottom + paddingTop + paddingBottom); 95 $(this).css({ 96 height: height + "px" 97 }); 98 }); 99 100 _.height = parentHeight; 101 _.overflow = Math.ceil(_.overflow); 102 _.end = -(_.overflow - _.height); 103 104 _.$element.css({ 105 height: _.overflow + "px", 106 transition: "all " + (_.settings.speed / 1000) + "s ease" 107 }).addClass("ezc-element"); 108 _.$parent.css({ 109 overflow: "hidden", 110 height: parentHeight + "px" 111 }); 112 } 113 if (Math.abs(_.end) > 0) { 114 _.settings.nextButton.on("click", _.nextClick.bind(_)); 115 _.settings.prevButton.on("click", _.prevClick.bind(_)); 116 } else { 117 _.settings.nextButton.hide() 118 _.settings.prevButton.hide(); 119 } 120 _.startTimer(); 121 }, 122 goToNext: function() { 123 var _ = this; 124 if (_.animating) return; 125 if (_.index <= _.length && _.index >= 0 && !_.atEnd && _.distanceTraveled != _.end) { 126 127 //Suspend while animating 128 _.animating = true; 129 setTimeout(function() { 130 _.animating = false; 131 }, _.settings.speed + 100); 132 _.index++; 133 134 //Calculate the distance for the next transition based on the dimensions of the next item in the queue 135 var distanceToTranslate = 0; 136 var $item = _.items.eq((_.index - 1)); 137 if (this.settings.direction == "horizontal") { 138 distanceToTranslate = $item.outerWidth(true); 139 } else { 140 distanceToTranslate = $item.outerHeight(true); 141 } 142 _.distanceTraveled -= distanceToTranslate; 143 _.settings.prevButton.removeClass("ezc-button-disabled"); 144 145 //Adjust the distace traveled if we are at the end of the scroller 146 if (_.distanceTraveled < _.end) { 147 var distanceTraveled = Math.abs(_.distanceTraveled); 148 var end = Math.abs(_.end); 149 _.leftover = distanceTraveled - end; 150 _.distanceTraveled = _.end; 151 clearInterval(_.interval); 152 _.atEnd = true; 153 _.settings.nextButton.addClass("ezc-button-disabled"); 154 } else { 155 _.atEnd = false; 156 _.leftover = 0; 157 _.settings.nextButton.removeClass("ezc-button-disabled"); 158 } 159 160 // Perform transition 161 if (this.settings.direction == "horizontal") { 162 _.$element.css({ 163 transform: "translateX(" + _.distanceTraveled + "px)" 164 }); 165 } else { 166 _.$element.css({ 167 transform: "translateY(" + _.distanceTraveled + "px)" 168 }); 169 } 170 } 171 }, 172 goToPrev: function() { 173 var _ = this; 174 if (_.animating) return; 175 if (_.index <= _.length && _.index > 0) { 176 //Suspend while animating 177 _.animating = true; 178 setTimeout(function() { 179 _.animating = false; 180 }, _.settings.speed + 100); 181 _.index--; 182 183 //Calculate the distance for the next transition based on the dimensions of the next item in the queue 184 var distanceToTranslate = 0; 185 var $item = _.items.eq((_.index)); 186 if (this.settings.direction == "horizontal") { 187 distanceToTranslate = $item.outerWidth(true); 188 } else { 189 distanceToTranslate = $item.outerHeight(true); 190 } 191 _.distanceTraveled += distanceToTranslate; 192 193 if (_.leftover) { 194 _.distanceTraveled -= _.leftover; 195 _.atEnd = false; 196 _.leftover = 0; 197 _.settings.nextButton.removeClass("ezc-button-disabled"); 198 } else { 199 _.leftover = 0; 200 _.atEnd = false; 201 } 202 203 //Do not let transition go past 0 because that is the first slide 204 if (_.distanceTraveled > 0) { 205 _.distanceTraveled = 0; 206 clearInterval(_.interval); 207 } 208 if (_.distanceTraveled == 0) _.settings.prevButton.addClass("ezc-button-disabled"); 209 210 // Perform transition 211 if (this.settings.direction == "horizontal") { 212 _.$element.css({
213 transform: "translateX(" + _.distanceTraveled + "px)" 214 }); 215 } else { 216 _.$element.css({ 217 transform: "translateY(" + _.distanceTraveled + "px)" 218 }); 219 } 220 } 221 }, 222 nextClick: function() { 223 if (this.animating) return; 224 this.goToNext(); 225 this.restartTimer(); 226 }, 227 prevClick: function() { 228 if (this.animating) return; 229 this.goToPrev(); 230 this.restartTimer(); 231 }, 232 startTimer: function() { 233 var _ = this; 234 if (_.settings.auto) { 235 _.interval = setInterval(function() { 236 _.goToNext(); 237 }, _.settings.timeout); 238 } 239 }, 240 restartTimer: function() { 241 var _ = this; 242 clearInterval(_.interval); 243 _.startTimer(); 244 } 245 }); 246 $.fn[pluginName] = function(options) { 247 return this.each(function() { 248 if (!$.data(this, "plugin_" + pluginName)) { 249 $.data(this, "plugin_" + 250 pluginName, new Plugin(this, options)); 251 } 252 }); 253 }; 254})(jQuery, window, document);
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.