|
1 | 1 | <template>
|
2 |
| - <div class="agile" :class="{'agile--fade': fade}"> |
| 2 | + <div class="agile" :class="{'agile--fade': fade_}"> |
3 | 3 | <div class="agile__list">
|
4 | 4 | <div class="agile__track"
|
5 |
| - :style="{width: width.track + 'px', transform: 'translate(-' + transform + 'px)', transition: 'transform ' + timing + ' ' + transitionDelay + 'ms'}"> |
| 5 | + :style="{width: width.track + 'px', transform: 'translate(-' + transform + 'px)', transition: 'transform ' + timing_ + ' ' + transitionDelay + 'ms'}"> |
6 | 6 | <slot></slot>
|
7 | 7 | </div>
|
8 | 8 |
|
9 |
| - <ul v-if="dots" class="agile__dots"> |
| 9 | + <ul v-if="dots_" class="agile__dots"> |
10 | 10 | <li v-for="n in slidesCount" class="agile__dot"
|
11 | 11 | :class="{'agile__dot--current': n - 1 === currentSlide}">
|
12 | 12 | <button @click="setSlide(n - 1)">{{n}}</button>
|
13 | 13 | </li>
|
14 | 14 | </ul>
|
15 | 15 |
|
16 |
| - <button v-if="arrows" class="agile__arrow agile__arrow--prev" |
17 |
| - :disabled="currentSlide === 0 && !infinite" @click="prevSlide" v-html="arrow"> |
| 16 | + <button v-if="arrows_" class="agile__arrow agile__arrow--prev" |
| 17 | + :disabled="currentSlide === 0 && !infinite_" @click="prevSlide" v-html="arrow_"> |
18 | 18 | </button>
|
19 |
| - <button v-if="arrows" class="agile__arrow agile__arrow--next" |
20 |
| - :disabled="currentSlide === slidesCount - 1 && !infinite" @click="nextSlide" v-html="arrow"> |
| 19 | + <button v-if="arrows_" class="agile__arrow agile__arrow--next" |
| 20 | + :disabled="currentSlide === slidesCount - 1 && !infinite_" @click="nextSlide" v-html="arrow_"> |
21 | 21 | </button>
|
22 | 22 | </div>
|
23 | 23 | </div>
|
|
28 | 28 | name: 'agile',
|
29 | 29 |
|
30 | 30 | props: {
|
| 31 | + arrow: { |
| 32 | + type: String, |
| 33 | + default: '<svg version="1.1" id="arrow-svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 240.823 240.823" style="enable-background:new 0 0 240.823 240.823;" xml:space="preserve"><g><path id="arrow" d="M183.189,111.816L74.892,3.555c-4.752-4.74-12.451-4.74-17.215,0c-4.752,4.74-4.752,12.439,0,17.179 l99.707,99.671l-99.695,99.671c-4.752,4.74-4.752,12.439,0,17.191c4.752,4.74,12.463,4.74,17.215,0l108.297-108.261 C187.881,124.315,187.881,116.495,183.189,111.816z"/></g></svg>' |
| 34 | + }, |
| 35 | +
|
31 | 36 | arrows: {
|
32 | 37 | type: Boolean,
|
33 | 38 | default: true
|
|
87 | 92 | track: null,
|
88 | 93 | slides: null
|
89 | 94 | },
|
90 |
| - arrow: '<svg version="1.1" id="arrow-svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 240.823 240.823" style="enable-background:new 0 0 240.823 240.823;" xml:space="preserve"><g><path id="arrow" d="M183.189,111.816L74.892,3.555c-4.752-4.74-12.451-4.74-17.215,0c-4.752,4.74-4.752,12.439,0,17.179 l99.707,99.671l-99.695,99.671c-4.752,4.74-4.752,12.439,0,17.191c4.752,4.74,12.463,4.74,17.215,0l108.297-108.261 C187.881,124.315,187.881,116.495,183.189,111.816z"/></g></svg>', |
91 | 95 | slidesCount: 0,
|
92 | 96 | autoplayTimeout: null,
|
93 | 97 | allSlidesCount: 0,
|
|
105 | 109 | slide: 0,
|
106 | 110 | track: 0
|
107 | 111 | },
|
108 |
| - slidesToShow: 1 |
| 112 | + slidesToShow: 1, |
| 113 | + arrow_: this.arrow, |
| 114 | + arrows_: this.arrows, |
| 115 | + autoplay_: this.autoplay, |
| 116 | + autoplaySpeed_: this.autoplaySpeed, |
| 117 | + dots_: this.dots, |
| 118 | + fade_: this.fade, |
| 119 | + infinite_: this.infinite, |
| 120 | + pauseOnDotsHover_: this.pauseOnDotsHover, |
| 121 | + pauseOnHover_: this.pauseOnHover, |
| 122 | + speed_: this.speed, |
| 123 | + timing_: this.timing |
109 | 124 | }
|
110 | 125 | },
|
111 | 126 |
|
112 | 127 | mounted () {
|
113 | 128 | // Protection against contradictory settings
|
114 |
| - if (this.autoplay) { |
115 |
| - this.infinite = true |
| 129 | + if (this.autoplay_) { |
| 130 | + this.infinite_ = true |
116 | 131 | }
|
117 | 132 |
|
118 |
| - if (this.pauseOnDotsHover) { |
119 |
| - this.dots = true |
| 133 | + if (this.pauseOnDotsHover_) { |
| 134 | + this.dots_ = true |
120 | 135 | }
|
121 | 136 |
|
122 | 137 | // Prepare list
|
123 | 138 | this.el.list = this.$el.getElementsByClassName('agile__list')[0]
|
124 | 139 |
|
125 | 140 | // Prepare dots
|
126 |
| - if (this.dots) { |
| 141 | + if (this.dots_) { |
127 | 142 | this.el.dots = this.$el.getElementsByClassName('agile__dots')[0].children
|
128 | 143 | }
|
129 | 144 |
|
130 | 145 | // Prepare slides
|
131 | 146 | this.el.slides = this.$el.getElementsByClassName('agile__track')[0].children
|
132 | 147 | this.slidesCount = this.el.slides.length
|
133 | 148 |
|
134 |
| - if (this.infinite && !this.fade) { |
| 149 | + if (this.infinite_ && !this.fade_) { |
135 | 150 | this.allSlidesCount = this.slidesCount + 2
|
136 | 151 | } else {
|
137 | 152 | this.allSlidesCount = this.slidesCount
|
|
141 | 156 | this.el.slides[i].classList.add('agile__slide')
|
142 | 157 |
|
143 | 158 | // Prepare slides for fade mode
|
144 |
| - if (this.fade) { |
| 159 | + if (this.fade_) { |
145 | 160 | this.el.slides[i].style.transition = 'opacity ' + this.timing + ' ' + this.speed + 'ms'
|
146 | 161 | }
|
147 | 162 | }
|
|
150 | 165 | this.el.track = this.$el.getElementsByClassName('agile__track')[0]
|
151 | 166 |
|
152 | 167 | // Prepare infinity mode
|
153 |
| - if (this.infinite && !this.fade) { |
| 168 | + if (this.infinite_ && !this.fade_) { |
154 | 169 | let firstSlide = this.el.track.firstChild.cloneNode(true)
|
155 | 170 | let lastSlide = this.el.track.lastChild.cloneNode(true)
|
156 | 171 |
|
|
162 | 177 | }
|
163 | 178 |
|
164 | 179 | // Prepare autoplay
|
165 |
| - if (this.autoplay) { |
| 180 | + if (this.autoplay_) { |
166 | 181 | this.startAutoplay()
|
167 | 182 | }
|
168 | 183 |
|
|
186 | 201 | }
|
187 | 202 |
|
188 | 203 | // Autoplay
|
189 |
| - if (this.autoplay) { |
190 |
| - if (this.pauseOnHover) { |
| 204 | + if (this.autoplay_) { |
| 205 | + if (this.pauseOnHover_) { |
191 | 206 | this.el.track.addEventListener('mouseover', this.stopAutoplay)
|
192 | 207 | this.el.track.addEventListener('mouseout', this.startAutoplay)
|
193 | 208 | }
|
194 | 209 |
|
195 |
| - if (this.pauseOnDotsHover) { |
| 210 | + if (this.pauseOnDotsHover_) { |
196 | 211 | for (let i = 0; i < this.slidesCount; ++i) {
|
197 | 212 | this.el.dots[i].addEventListener('mouseover', this.stopAutoplay)
|
198 | 213 | this.el.dots[i].addEventListener('mouseout', this.startAutoplay)
|
|
215 | 230 | this.el.track.removeEventListener('mousemove')
|
216 | 231 | }
|
217 | 232 |
|
218 |
| - if (this.autoplay) { |
219 |
| - if (this.pauseOnHover) { |
| 233 | + if (this.autoplay_) { |
| 234 | + if (this.pauseOnHover_) { |
220 | 235 | this.el.track.removeEventListener('mouseover')
|
221 | 236 | this.el.track.removeEventListener('mouseout')
|
222 | 237 | }
|
223 | 238 |
|
224 |
| - if (this.pauseOnDotsHover) { |
| 239 | + if (this.pauseOnDotsHover_) { |
225 | 240 | for (let i = 0; i < this.slidesCount; ++i) {
|
226 | 241 | this.el.dots[i].removeEventListener('mouseover')
|
227 | 242 | this.el.dots[i].removeEventListener('mouseout')
|
|
295 | 310 |
|
296 | 311 | setSlide (n, transition = true, autoplayTimeout = true) {
|
297 | 312 | // Reset autoplay timeout and set new
|
298 |
| - if (this.autoplay && autoplayTimeout) { |
| 313 | + if (this.autoplay_ && autoplayTimeout) { |
299 | 314 | this.stopAutoplay()
|
300 | 315 | this.startAutoplay()
|
301 | 316 | }
|
302 | 317 |
|
303 |
| - if (this.fade) { |
| 318 | + if (this.fade_) { |
304 | 319 | // Disable transition for initial slide
|
305 | 320 | if (transition === false) {
|
306 | 321 | this.el.slides[n].style.transition = '0ms'
|
|
314 | 329 | this.el.slides[i].classList.remove('agile__slide--expiring')
|
315 | 330 | }
|
316 | 331 |
|
317 |
| - if (this.infinite && n < 0) { |
| 332 | + if (this.infinite_ && n < 0) { |
318 | 333 | n = this.slidesCount - 1
|
319 | 334 | } else if (n >= this.slidesCount) {
|
320 | 335 | n = 0
|
|
326 | 341 |
|
327 | 342 | setTimeout(() => {
|
328 | 343 | this.el.slides[e].classList.remove('agile__slide--expiring')
|
329 |
| - }, this.speed) |
| 344 | + }, this.speed_) |
330 | 345 |
|
331 | 346 | this.transform = 0
|
332 | 347 | } else {
|
|
337 | 352 | this.el.slides[i].classList.remove('agile__slide--active')
|
338 | 353 | }
|
339 | 354 |
|
340 |
| - if (this.infinite && !this.fade) { |
| 355 | + if (this.infinite_ && !this.fade_) { |
341 | 356 | this.transform += this.width.slide
|
342 | 357 | this.addActiveClass(n + 1)
|
343 | 358 | } else {
|
|
350 | 365 | this.transitionDelay = this.speed
|
351 | 366 | }
|
352 | 367 |
|
353 |
| - if (this.infinite && n < 0) { |
| 368 | + if (this.infinite_ && n < 0) { |
354 | 369 | this.currentSlide = this.slidesCount - 1
|
355 | 370 |
|
356 | 371 | setTimeout(() => {
|
357 | 372 | this.setSlide(this.slidesCount - 1, false)
|
358 | 373 | }, this.speed)
|
359 |
| - } else if (this.infinite && n >= this.slidesCount) { |
| 374 | + } else if (this.infinite_ && n >= this.slidesCount) { |
360 | 375 | this.currentSlide = 0
|
361 | 376 |
|
362 | 377 | setTimeout(() => {
|
363 | 378 | this.setSlide(0, false)
|
364 |
| - }, this.speed) |
| 379 | + }, this.speed_) |
365 | 380 | } else {
|
366 | 381 | this.currentSlide = n
|
367 | 382 | }
|
|
383 | 398 | this.el.slides[i].style.width = this.width.container + 'px'
|
384 | 399 |
|
385 | 400 | // Prepare slides for fade mode
|
386 |
| - if (this.fade) { |
| 401 | + if (this.fade_) { |
387 | 402 | this.el.slides[i].style.transform = 'translate(-' + i * this.width.slide + 'px)'
|
388 | 403 | }
|
389 | 404 | }
|
|
399 | 414 | }
|
400 | 415 |
|
401 | 416 | if (this.dragDistance > this.swipeDistance) {
|
402 |
| - if (!this.infinite && this.currentSlide === 0) { |
| 417 | + if (!this.infinite_ && this.currentSlide === 0) { |
403 | 418 | return
|
404 | 419 | }
|
405 | 420 |
|
|
408 | 423 | }
|
409 | 424 |
|
410 | 425 | if (this.dragDistance < -1 * this.swipeDistance) {
|
411 |
| - if (!this.infinite && this.currentSlide === this.slidesCount - 1) { |
| 426 | + if (!this.infinite_ && this.currentSlide === this.slidesCount - 1) { |
412 | 427 | return
|
413 | 428 | }
|
414 | 429 |
|
|
0 commit comments