vendor: 5,686 bytes, lines 1-233
1/** 2 * Autoplay Plugin 3 * @version 2.1.0 4 * @author Bartosz Wojciechowski 5 * @author Artus Kolanowski 6 * @author David Deutsch 7 * @author Tom De Caluwé 8 * @license The MIT License (MIT) 9 */ 10;(function($, window, document, undefined) { 11 12 /** 13 * Creates the autoplay plugin. 14 * @class The Autoplay Plugin 15 * @param {Owl} scope - The Owl Carousel 16 */ 17 var Autoplay = function(carousel) { 18 /** 19 * Reference to the core. 20 * @protected 21 * @type {Owl} 22 */ 23 this._core = carousel; 24 25 /** 26 * The autoplay timeout id. 27 * @type {Number} 28 */ 29 this._call = null; 30 31 /** 32 * Depending on the state of the plugin, this variable contains either 33 * the start time of the timer or the current timer value if it's 34 * paused. Since we start in a paused state we initialize the timer 35 * value. 36 * @type {Number} 37 */ 38 this._time = 0; 39 40 /** 41 * Stores the timeout currently used. 42 * @type {Number} 43 */ 44 this._timeout = 0; 45 46 /** 47 * Indicates whenever the autoplay is paused. 48 * @type {Boolean} 49 */ 50 this._paused = true; 51 52 /** 53 * All event handlers. 54 * @protected 55 * @type {Object} 56 */ 57 this._handlers = { 58 'changed.owl.carousel': $.proxy(function(e) { 59 if (e.namespace && e.property.name === 'settings') { 60 if (this._core.settings.autoplay) { 61 this.play(); 62 } else { 63 this.stop(); 64 } 65 } else if (e.namespace && e.property.name === 'position' && this._paused) { 66 // Reset the timer. This code is triggered when the position 67 // of the carousel was changed through user interaction. 68 this._time = 0; 69 } 70 }, this), 71 'initialized.owl.carousel': $.proxy(function(e) { 72 if (e.namespace && this._core.settings.autoplay) { 73 this.play(); 74 } 75 }, this), 76 'play.owl.autoplay': $.proxy(function(e, t, s) { 77 if (e.namespace) { 78 this.play(t, s); 79 } 80 }, this), 81 'stop.owl.autoplay': $.proxy(function(e) { 82 if (e.namespace) { 83 this.stop(); 84 } 85 }, this), 86 'mouseover.owl.autoplay': $.proxy(function() { 87 if (this._core.settings.autoplayHoverPause && this._core.is('rotating')) { 88 this.pause(); 89 } 90 }, this), 91 'mouseleave.owl.autoplay': $.proxy(function() { 92 if (this._core.settings.autoplayHoverPause && this._core.is('rotating')) { 93 this.play(); 94 } 95 }, this), 96 'touchstart.owl.core': $.proxy(function() { 97 if (this._core.settings.autoplayHoverPause && this._core.is('rotating')) { 98 this.pause(); 99 } 100 }, this), 101 'touchend.owl.core': $.proxy(function() { 102 if (this._core.settings.autoplayHoverPause) { 103 this.play(); 104 } 105 }, this) 106 }; 107 108 // register event handlers 109 this._core.$element.on(this._handlers); 110 111 // set default options 112 this._core.options = $.extend({}, Autoplay.Defaults, this._core.options); 113 }; 114 115 /** 116 * Default options. 117 * @public 118 */ 119 Autoplay.Defaults = { 120 autoplay: false, 121 autoplayTimeout: 5000, 122 autoplayHoverPause: false, 123 autoplaySpeed: false 124 }; 125 126 /** 127 * Transition to the next slide and set a timeout for the next transition. 128 * @private 129 * @param {Number} [speed] - The animation speed for the animations. 130 */ 131 Autoplay.prototype._next = function(speed) { 132 this._call = window.setTimeout( 133 $.proxy(this._next, this, speed), 134 this._timeout * (Math.round(this.read() / this._timeout) + 1) - this.read() 135 ); 136 137 if (this._core.is('busy') || this._core.is('interacting') || document.hidden) { 138 return; 139 } 140 this._core.next(speed || this._core.settings.autoplaySpeed); 141 } 142 143 /** 144 * Reads the current timer value when the timer is playing. 145 * @public 146 */ 147 Autoplay.prototype.read = function() { 148 return new Date().getTime() - this._time; 149 }; 150 151 /** 152 * Starts the autoplay. 153 * @public 154 * @param {Number} [timeout] - The interval before the next animation starts. 155 * @param {Number} [speed] - The animation speed for the animations. 156 */ 157 Autoplay.prototype.play = function(timeout, speed) { 158 var elapsed; 159 160 if (!this._core.is('rotating')) { 161 this._core.enter('rotating'); 162 } 163 164 timeout = timeout || this._core.settings.autoplayTimeout; 165 166 // Calculate the elapsed time since the last transition. If the carousel 167 // wasn't playing this calculation will yield zero. 168 elapsed = Math.min(this._time % (this._timeout || timeout), timeout); 169 170 if (this._paused) { 171 // Start the clock. 172 this._time = this.read(); 173 this._paused = false; 174 } else { 175 // Clear the active timeout to allow replacement. 176 window.clearTimeout(this._call); 177 } 178 179 // Adjust the origin of the timer to match the new timeout value. 180 this._time += this.read() % timeout - elapsed; 181 182 this._timeout = timeout; 183 this._call = window.setTimeout($.proxy(this._next, this, speed), timeout - elapsed); 184 }; 185 186 /** 187 * Stops the autoplay. 188 * @public 189 */ 190 Autoplay.prototype.stop = function() { 191 if (this._core.is('rotating')) { 192 // Reset the clock. 193 this._time = 0; 194 this._paused = true; 195 196 window.clearTimeout(this._call); 197 this._core.leave('rotating'); 198 } 199 }; 200 201 /** 202 * Pauses the autoplay. 203 * @public 204 */ 205 Autoplay.prototype.pause = function() { 206 if (this._core.is('rotating') && !this._paused) { 207 // Pause the clock. 208 this._time = this.read(); 209 this._paused = true; 210 211 window.clearTimeout(this._call); 212 } 213 }; 214 215 /** 216 * Destroys the plugin. 217 */ 218 Autoplay.prototype.destroy = function() { 219 var handler, property; 220 221 this.stop(); 222 223 for (handler in this._handlers) { 224 this._core.$element.off(handler, this._handlers[handler]); 225 } 226 for (property in Object.getOwnPropertyNames(this)) { 227 typeof this[property] != 'function' && (this[property] = null); 228 } 229 }; 230 231 $.fn.owlCarousel.Constructor.Plugins.autoplay = Autoplay; 232 233})(window.Zepto || window.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.