|
35 | 35 | </template>
|
36 | 36 |
|
37 | 37 | <script>
|
| 38 | + import handlers from '@/mixins/handlers' |
| 39 | + import helpers from '@/mixins/helpers' |
| 40 | + import props from '@/mixins/props' |
| 41 | + import watchers from '@/mixins/watchers' |
| 42 | +
|
38 | 43 | export default {
|
39 | 44 | name: 'agile',
|
40 | 45 |
|
41 |
| - props: { |
42 |
| - // Depreciated |
43 |
| - arrows: { |
44 |
| - type: Boolean, |
45 |
| - default: true |
46 |
| - }, |
47 |
| -
|
48 |
| - asNavFor: { |
49 |
| - type: Array, |
50 |
| - default: function () { |
51 |
| - return [] |
52 |
| - } |
53 |
| - }, |
54 |
| -
|
55 |
| - autoplay: { |
56 |
| - type: Boolean, |
57 |
| - default: false |
58 |
| - }, |
59 |
| -
|
60 |
| - autoplaySpeed: { |
61 |
| - type: Number, |
62 |
| - default: 3000 |
63 |
| - }, |
64 |
| -
|
65 |
| - centerMode: { |
66 |
| - type: Boolean, |
67 |
| - default: false |
68 |
| - }, |
69 |
| -
|
70 |
| - centerPadding: { |
71 |
| - type: String, |
72 |
| - default: '15%' |
73 |
| - }, |
74 |
| -
|
75 |
| - dots: { |
76 |
| - type: Boolean, |
77 |
| - default: true |
78 |
| - }, |
79 |
| -
|
80 |
| - fade: { |
81 |
| - type: Boolean, |
82 |
| - default: false |
83 |
| - }, |
84 |
| -
|
85 |
| - infinite: { |
86 |
| - type: Boolean, |
87 |
| - default: true |
88 |
| - }, |
89 |
| -
|
90 |
| - initialSlide: { |
91 |
| - type: Number, |
92 |
| - default: 0 |
93 |
| - }, |
94 |
| -
|
95 |
| - mobileFirst: { |
96 |
| - type: Boolean, |
97 |
| - default: true |
98 |
| - }, |
99 |
| -
|
100 |
| - navButtons: { |
101 |
| - type: Boolean, |
102 |
| - default: true |
103 |
| - }, |
104 |
| -
|
105 |
| - // Depreciated |
106 |
| - nextArrow: { |
107 |
| - type: String, |
108 |
| - default: null |
109 |
| - }, |
110 |
| -
|
111 |
| - options: { |
112 |
| - type: Object, |
113 |
| - default: () => null |
114 |
| - }, |
115 |
| -
|
116 |
| - pauseOnDotsHover: { |
117 |
| - type: Boolean, |
118 |
| - default: false |
119 |
| - }, |
120 |
| -
|
121 |
| - pauseOnHover: { |
122 |
| - type: Boolean, |
123 |
| - default: true |
124 |
| - }, |
125 |
| -
|
126 |
| - // Depreciated |
127 |
| - prevArrow: { |
128 |
| - type: String, |
129 |
| - default: null |
130 |
| - }, |
131 |
| -
|
132 |
| - responsive: { |
133 |
| - type: Array, |
134 |
| - default: () => null |
135 |
| - }, |
136 |
| -
|
137 |
| - rtl: { |
138 |
| - type: Boolean, |
139 |
| - default: false |
140 |
| - }, |
141 |
| -
|
142 |
| - slidesToScroll: { |
143 |
| - type: Number, |
144 |
| - default: 1 |
145 |
| - }, |
146 |
| -
|
147 |
| - slidesToShow: { |
148 |
| - type: Number, |
149 |
| - default: 1 |
150 |
| - }, |
151 |
| -
|
152 |
| - speed: { |
153 |
| - type: Number, |
154 |
| - default: 300 |
155 |
| - }, |
156 |
| -
|
157 |
| - timing: { |
158 |
| - type: String, |
159 |
| - default: 'ease' // linear, ease-in, ease-out, ease-in-out |
160 |
| - }, |
161 |
| -
|
162 |
| - unagile: { |
163 |
| - type: Boolean, |
164 |
| - default: false |
165 |
| - } |
166 |
| - }, |
| 46 | + mixins: [handlers, helpers, props, watchers], |
167 | 47 |
|
168 | 48 | data () {
|
169 | 49 | return {
|
|
188 | 68 | widthWindow: 0,
|
189 | 69 | widthContainer: 0,
|
190 | 70 | widthSlide: 0,
|
191 |
| - initialSettings: { |
192 |
| - asNavFor: this.asNavFor, |
193 |
| - autoplay: this.autoplay, |
194 |
| - autoplaySpeed: this.autoplaySpeed, |
195 |
| - centerMode: this.centerMode, |
196 |
| - centerPadding: this.centerPadding, |
197 |
| - dots: this.dots, |
198 |
| - fade: this.fade, |
199 |
| - infinite: this.infinite, |
200 |
| - initialSlide: this.initialSlide, |
201 |
| - mobileFirst: this.mobileFirst, |
202 |
| - navButtons: this.navButtons, |
203 |
| - pauseOnDotsHover: this.pauseOnDotsHover, |
204 |
| - pauseOnHover: this.pauseOnHover, |
205 |
| - responsive: this.responsive, |
206 |
| - rtl: this.rtl, |
207 |
| - slidesToScroll: this.slidesToScroll, |
208 |
| - slidesToShow: this.slidesToShow, |
209 |
| - speed: this.speed, |
210 |
| - timing: this.timing, |
211 |
| - unagile: this.unagile |
212 |
| - }, |
213 | 71 | settings: {}
|
214 | 72 | }
|
215 | 73 | },
|
|
260 | 118 | }
|
261 | 119 | },
|
262 | 120 |
|
263 |
| - watch: { |
264 |
| - // Watch window width change |
265 |
| - widthWindow (newValue, oldValue) { |
266 |
| - if (oldValue) { |
267 |
| - this.prepareCarousel() |
268 |
| - this.toggleFade() |
269 |
| - } |
270 |
| - }, |
271 |
| -
|
272 |
| - // Watch current slide change |
273 |
| - currentSlide () { |
274 |
| - this.prepareSlidesClasses() |
275 |
| -
|
276 |
| - // Set start time of slide |
277 |
| - this.autoplayStart = (this.settings.autoplay) ? +new Date() : null |
278 |
| -
|
279 |
| - this.$emit('afterChange', { currentSlide: this.currentSlide }) |
280 |
| - }, |
281 |
| -
|
282 |
| - // Recalculate settings |
283 |
| - currentBreakpoint () { |
284 |
| - this.prepareSettings() |
285 |
| - this.$emit('breakpoint', { breakpoint: this.currentBreakpoint }) |
286 |
| - }, |
287 |
| -
|
288 |
| - // Watch drag distance change |
289 |
| - dragDistance () { |
290 |
| - if (this.mouseDown) { |
291 |
| - if (this.dragDistance > this.swipeDistance && this.canGoToPrev) { |
292 |
| - this.goToPrev() |
293 |
| - this.handleMouseUp() |
294 |
| - } |
295 |
| -
|
296 |
| - if (this.dragDistance < -1 * this.swipeDistance && this.canGoToNext) { |
297 |
| - this.goToNext() |
298 |
| - this.handleMouseUp() |
299 |
| - } |
300 |
| - } |
301 |
| - }, |
302 |
| -
|
303 |
| - 'settings.fade' () { |
304 |
| - this.toggleFade() |
305 |
| - }, |
306 |
| -
|
307 |
| - 'settings.autoplay' () { |
308 |
| - this.toggleAutoPlay() |
309 |
| - }, |
310 |
| -
|
311 |
| - pauseAutoPlay (nevValue) { |
312 |
| - if (nevValue) { |
313 |
| - // Store current slide remaining time and disable auto play mode |
314 |
| - this.remaining = this.settings.autoplaySpeed - (+new Date() - this.autoplayStart) |
315 |
| - this.disableAutoPlay() |
316 |
| - this.clearAutoPlayPause() |
317 |
| - } else { |
318 |
| - // Go to next after remaining time and rerun auto play mode |
319 |
| - this.autoplayTimeout = setTimeout(() => { |
320 |
| - this.clearAutoPlayPause() |
321 |
| - this.goToNext() |
322 |
| - this.toggleAutoPlay() |
323 |
| - }, this.remaining) |
324 |
| - } |
325 |
| - } |
326 |
| - }, |
327 |
| -
|
328 | 121 | created () {
|
329 | 122 | // Read settings from options object
|
330 | 123 | if (this.options) {
|
|
378 | 171 | },
|
379 | 172 |
|
380 | 173 | methods: {
|
381 |
| - // Convert HTML Collection to JS Array |
382 |
| - htmlCollectionToArray (collection) { |
383 |
| - return Array.prototype.slice.call(collection, 0) |
384 |
| - }, |
385 |
| -
|
386 |
| - // Compare elements for breakpoints sorting |
387 |
| - compare (a, b) { |
388 |
| - if (a.breakpoint < b.breakpoint) { |
389 |
| - return (this.initialSettings.mobileFirst) ? -1 : 1 |
390 |
| - } else if (a.breakpoint > b.breakpoint) { |
391 |
| - return (this.initialSettings.mobileFirst) ? 1 : -1 |
392 |
| - } else { |
393 |
| - return 0 |
394 |
| - } |
395 |
| - }, |
396 |
| -
|
397 |
| - getWidth () { |
398 |
| - this.widthWindow = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth |
399 |
| - this.widthContainer = this.$refs.list.clientWidth |
400 |
| - }, |
401 |
| -
|
402 |
| - handleMouseDown (e) { |
403 |
| - if (!e.touches) { |
404 |
| - e.preventDefault() |
405 |
| - } |
406 |
| - this.mouseDown = true |
407 |
| - this.dragStartX = ('ontouchstart' in window) ? e.touches[0].clientX : e.clientX |
408 |
| - this.dragStartY = ('ontouchstart' in window) ? e.touches[0].clientY : e.clientY |
409 |
| - }, |
410 |
| -
|
411 |
| - handleMouseMove (e) { |
412 |
| - let positionX = ('ontouchstart' in window) ? e.touches[0].clientX : e.clientX |
413 |
| - let positionY = ('ontouchstart' in window) ? e.touches[0].clientY : e.clientY |
414 |
| - let dragDistanceX = Math.abs(positionX - this.dragStartX) |
415 |
| - let dragDistanceY = Math.abs(positionY - this.dragStartY) |
416 |
| - if (dragDistanceX > 3 * dragDistanceY) { |
417 |
| - this.disableScroll() |
418 |
| - this.dragDistance = positionX - this.dragStartX |
419 |
| - } |
420 |
| - }, |
421 |
| -
|
422 |
| - handleMouseUp () { |
423 |
| - this.mouseDown = false |
424 |
| - this.enableScroll() |
425 |
| - }, |
426 |
| -
|
427 |
| - handleMouseOver (element) { |
428 |
| - if (this.settings.autoplay) { |
429 |
| - if ((element === 'dot' && this.settings.pauseOnDotsHover) || (element === 'track' && this.settings.pauseOnHover)) { |
430 |
| - this.pauseAutoPlay = true |
431 |
| - } |
432 |
| - } |
433 |
| - }, |
434 |
| -
|
435 |
| - handleMouseOut (element) { |
436 |
| - if (this.settings.autoplay) { |
437 |
| - if ((element === 'dot' && this.settings.pauseOnDotsHover) || (element === 'track' && this.settings.pauseOnHover)) { |
438 |
| - this.pauseAutoPlay = false |
439 |
| - } |
440 |
| - } |
441 |
| - }, |
442 |
| -
|
443 | 174 | // Reload carousel
|
444 | 175 | reload () {
|
445 | 176 | this.getWidth()
|
|
0 commit comments