|
200 | 200 | // Prepare track
|
201 | 201 | this.el.track = this.$el.getElementsByClassName('agile__track')[0]
|
202 | 202 |
|
203 |
| - // Prepare autoplay |
204 |
| - if (this.settings.autoplay) { |
205 |
| - this.startAutoplay() |
206 |
| - } |
207 |
| -
|
208 | 203 | // Windows resize listener
|
209 | 204 | window.addEventListener('resize', this.getWidth)
|
210 | 205 |
|
|
221 | 216 | this.el.track.addEventListener('mouseup', this.handleMouseUp)
|
222 | 217 | this.el.track.addEventListener('mousemove', this.handleMouseMove)
|
223 | 218 | }
|
224 |
| -
|
225 |
| - // Autoplay |
226 |
| - if (this.settings.autoplay) { |
227 |
| - if (this.settings.pauseOnHover) { |
228 |
| - this.el.track.addEventListener('mouseover', this.stopAutoplay) |
229 |
| - this.el.track.addEventListener('mouseout', this.startAutoplay) |
230 |
| - } |
231 |
| -
|
232 |
| - if (this.settings.pauseOnDotsHover) { |
233 |
| - for (let i = 0; i < this.slidesCount; ++i) { |
234 |
| - this.el.dots[i].addEventListener('mouseover', this.stopAutoplay) |
235 |
| - this.el.dots[i].addEventListener('mouseout', this.startAutoplay) |
236 |
| - } |
237 |
| - } |
238 |
| - } |
239 | 219 | },
|
240 | 220 |
|
241 | 221 | beforeDestroy () {
|
|
251 | 231 | this.el.track.removeEventListener('mousemove', this.handleMouseMove)
|
252 | 232 | }
|
253 | 233 |
|
254 |
| - if (this.settings.autoplay) { |
255 |
| - if (this.settings.pauseOnHover) { |
256 |
| - this.el.track.removeEventListener('mouseover', this.stopAutoplay) |
257 |
| - this.el.track.removeEventListener('mouseout', this.startAutoplay) |
258 |
| - } |
259 |
| -
|
260 |
| - if (this.settings.pauseOnDotsHover) { |
261 |
| - for (let i = 0; i < this.slidesCount; ++i) { |
262 |
| - this.el.dots[i].removeEventListener('mouseover', this.stopAutoplay) |
263 |
| - this.el.dots[i].removeEventListener('mouseout', this.startAutoplay) |
264 |
| - } |
265 |
| - } |
266 |
| - } |
| 234 | + this.disableAutoplayMode() |
267 | 235 | },
|
268 | 236 |
|
269 | 237 | methods: {
|
|
338 | 306 | this.countSlides()
|
339 | 307 | },
|
340 | 308 |
|
| 309 | + enableAutoplayMode () { |
| 310 | + // Autoplay |
| 311 | + if (this.settings.autoplay) { |
| 312 | + if (this.settings.pauseOnHover) { |
| 313 | + this.el.track.addEventListener('mouseover', this.stopAutoplay) |
| 314 | + this.el.track.addEventListener('mouseout', this.startAutoplay) |
| 315 | + } |
| 316 | +
|
| 317 | + if (this.settings.pauseOnDotsHover) { |
| 318 | + for (let i = 0; i < this.slidesCount; ++i) { |
| 319 | + this.el.dots[i].addEventListener('mouseover', this.stopAutoplay) |
| 320 | + this.el.dots[i].addEventListener('mouseout', this.startAutoplay) |
| 321 | + } |
| 322 | + } |
| 323 | + } |
| 324 | + }, |
| 325 | +
|
| 326 | + disableAutoplayMode () { |
| 327 | + if (this.settings.autoplay) { |
| 328 | + if (this.settings.pauseOnHover) { |
| 329 | + this.el.track.removeEventListener('mouseover', this.stopAutoplay) |
| 330 | + this.el.track.removeEventListener('mouseout', this.startAutoplay) |
| 331 | + } |
| 332 | +
|
| 333 | + if (this.settings.pauseOnDotsHover) { |
| 334 | + for (let i = 0; i < this.slidesCount; ++i) { |
| 335 | + this.el.dots[i].removeEventListener('mouseover', this.stopAutoplay) |
| 336 | + this.el.dots[i].removeEventListener('mouseout', this.startAutoplay) |
| 337 | + } |
| 338 | + } |
| 339 | + } |
| 340 | + }, |
| 341 | +
|
341 | 342 | countSlides () {
|
342 | 343 | if (this.settings.infinite && !this.settings.fade) {
|
343 | 344 | this.allSlidesCount = this.slidesCount + 2
|
|
488 | 489 | this.disableInfiniteMode()
|
489 | 490 | }
|
490 | 491 |
|
| 492 | + // Check autoplay mode status and enable/disable |
| 493 | + if (this.settings.autoplay) { |
| 494 | + this.enableAutoplayMode() |
| 495 | + this.startAutoplay() |
| 496 | + } else { |
| 497 | + this.stopAutoplay() |
| 498 | + this.disableAutoplayMode() |
| 499 | + } |
| 500 | +
|
491 | 501 | // Actions on document resize
|
492 | 502 | for (let i = 0; i < this.allSlidesCount; ++i) {
|
493 | 503 | this.el.slides[i].style.width = this.width.container + 'px'
|
|
0 commit comments