Skip to content
This repository was archived by the owner on Feb 24, 2023. It is now read-only.

Commit 8542f78

Browse files
author
Łukasz Florczak
committed
Merge commit 'c5d3e604028e4661fa3adf7042895e90d8dc96b8' into develop
* commit 'c5d3e604028e4661fa3adf7042895e90d8dc96b8': Update README.md Update README.md 0.2.4 Small change in listeners SSR example (#19) Added missing argument for removeEventListener (fixed #20)
2 parents 2acae33 + c5d3e60 commit 8542f78

File tree

3 files changed

+73
-42
lines changed

3 files changed

+73
-42
lines changed

README.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# vue-agile
22

33
> Carousel component for Vue.js inspired by [Slick](https://github.com/kenwheeler/slick/).<br>
4-
> ~~Simple~~ More powerfull with each version, touch-friendly, written in Vue and Vanilla JS (without jQuery dependency).
4+
> More powerfull with each version, touch-friendly, written in Vue and Vanilla JS (without jQuery dependency).
55
66
**[Demo & examples](https://lukaszflorczak.github.io/vue-agile/)**
77

@@ -68,6 +68,40 @@ Every first-level child of `<agile>` is a new slide.
6868
</agile>
6969
```
7070

71+
## SSR Support
72+
73+
The component uses browser specific attributes (like `window` and `document`). It is necessary, so probably the only option is to run vue-agile only on the client-side. It was tested on [nuxt v1.0.0-rc7](https://github.com/nuxt/nuxt.js/releases/tag/v1.0.0-rc7) and works fine.
74+
75+
### Example
76+
```js
77+
// plugins/vue-agile.js
78+
79+
import Vue from 'vue'
80+
import VueAgile from 'vue-agile'
81+
82+
Vue.component('agile', VueAgile)
83+
```
84+
85+
```js
86+
// nuxt.config.js
87+
88+
module.exports = {
89+
plugins: [
90+
{ src: '~/plugins/vue-agile', ssr: false }
91+
]
92+
}
93+
```
94+
95+
```vue
96+
<no-ssr placeholder="Loading...">
97+
<agile>
98+
...
99+
</agile>
100+
</no-ssr>
101+
```
102+
103+
PS. If you know a better way to work the component with SSR please, [let me know about it](https://github.com/lukaszflorczak/vue-agile/issues).
104+
71105
## Contributing
72106
```
73107
# install dependencies

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-agile",
3-
"version": "0.2.3",
3+
"version": "0.2.4",
44
"description": "Carousel component for Vue.js",
55
"author": "Łukasz Florczak <[email protected]>",
66
"license": "MIT",

src/Agile.vue

Lines changed: 37 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -195,65 +195,62 @@
195195
this.startAutoplay()
196196
}
197197
198-
// Listeners
199-
this.$nextTick(function () {
200-
// Windows resize listener
201-
window.addEventListener('resize', this.getWidth)
202-
203-
// Get width on start
204-
this.getWidth()
205-
206-
// Mouse and touch events
207-
if ('ontouchstart' in window) {
208-
this.el.track.addEventListener('touchstart', this.handleMouseDown)
209-
this.el.track.addEventListener('touchend', this.handleMouseUp)
210-
this.el.track.addEventListener('touchmove', this.handleMouseMove)
211-
} else {
212-
this.el.track.addEventListener('mousedown', this.handleMouseDown)
213-
this.el.track.addEventListener('mouseup', this.handleMouseUp)
214-
this.el.track.addEventListener('mousemove', this.handleMouseMove)
215-
}
198+
// Windows resize listener
199+
window.addEventListener('resize', this.getWidth)
216200
217-
// Autoplay
218-
if (this.autoplay_) {
219-
if (this.pauseOnHover_) {
220-
this.el.track.addEventListener('mouseover', this.stopAutoplay)
221-
this.el.track.addEventListener('mouseout', this.startAutoplay)
222-
}
201+
// Get width on start
202+
this.getWidth()
203+
204+
// Mouse and touch events
205+
if ('ontouchstart' in window) {
206+
this.el.track.addEventListener('touchstart', this.handleMouseDown)
207+
this.el.track.addEventListener('touchend', this.handleMouseUp)
208+
this.el.track.addEventListener('touchmove', this.handleMouseMove)
209+
} else {
210+
this.el.track.addEventListener('mousedown', this.handleMouseDown)
211+
this.el.track.addEventListener('mouseup', this.handleMouseUp)
212+
this.el.track.addEventListener('mousemove', this.handleMouseMove)
213+
}
223214
224-
if (this.pauseOnDotsHover_) {
225-
for (let i = 0; i < this.slidesCount; ++i) {
226-
this.el.dots[i].addEventListener('mouseover', this.stopAutoplay)
227-
this.el.dots[i].addEventListener('mouseout', this.startAutoplay)
228-
}
215+
// Autoplay
216+
if (this.autoplay_) {
217+
if (this.pauseOnHover_) {
218+
this.el.track.addEventListener('mouseover', this.stopAutoplay)
219+
this.el.track.addEventListener('mouseout', this.startAutoplay)
220+
}
221+
222+
if (this.pauseOnDotsHover_) {
223+
for (let i = 0; i < this.slidesCount; ++i) {
224+
this.el.dots[i].addEventListener('mouseover', this.stopAutoplay)
225+
this.el.dots[i].addEventListener('mouseout', this.startAutoplay)
229226
}
230227
}
231-
})
228+
}
232229
},
233230
234231
beforeDestroy () {
235232
window.removeEventListener('resize', this.getWidth)
236233
237234
if ('ontouchstart' in window) {
238-
this.el.track.removeEventListener('touchstart')
239-
this.el.track.removeEventListener('touchend')
240-
this.el.track.removeEventListener('touchmove')
235+
this.el.track.removeEventListener('touchstart', this.handleMouseDown)
236+
this.el.track.removeEventListener('touchend', this.handleMouseUp)
237+
this.el.track.removeEventListener('touchmove', this.handleMouseMove)
241238
} else {
242-
this.el.track.removeEventListener('mousedown')
243-
this.el.track.removeEventListener('mouseup')
244-
this.el.track.removeEventListener('mousemove')
239+
this.el.track.removeEventListener('mousedown', this.handleMouseDown)
240+
this.el.track.removeEventListener('mouseup', this.handleMouseUp)
241+
this.el.track.removeEventListener('mousemove', this.handleMouseMove)
245242
}
246243
247244
if (this.autoplay_) {
248245
if (this.pauseOnHover_) {
249-
this.el.track.removeEventListener('mouseover')
250-
this.el.track.removeEventListener('mouseout')
246+
this.el.track.removeEventListener('mouseover', this.stopAutoplay)
247+
this.el.track.removeEventListener('mouseout', this.startAutoplay)
251248
}
252249
253250
if (this.pauseOnDotsHover_) {
254251
for (let i = 0; i < this.slidesCount; ++i) {
255-
this.el.dots[i].removeEventListener('mouseover')
256-
this.el.dots[i].removeEventListener('mouseout')
252+
this.el.dots[i].removeEventListener('mouseover', this.stopAutoplay)
253+
this.el.dots[i].removeEventListener('mouseout', this.startAutoplay)
257254
}
258255
}
259256
}

0 commit comments

Comments
 (0)