-
Notifications
You must be signed in to change notification settings - Fork 254
/
Copy pathFullPage.vue
executable file
·90 lines (83 loc) · 2.19 KB
/
FullPage.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<template>
<div ref="fullpage">
<slot></slot>
</div>
</template>
<script>
import 'fullpage.js/dist/fullpage.min.css'
import fullpage from 'fullpage.js/dist/fullpage.extensions.min.js'
import * as constants from './constants'
export default {
name: 'FullPage',
props: {
options: {
type: Object,
default () {}
},
skipInit: {
type: Boolean,
default: false,
},
},
data() {
return {
events: constants.EVENTS.reduce((eventsHandlers, event) => {
return {
...eventsHandlers,
[event]: (...args) => {
this.emitEvent(event, args)
},
}
}, {}),
api: undefined,
}
},
watch: {
options: {
deep: true,
handler() {
this.build()
},
},
},
mounted() {
!this.skipInit && this.init()
},
beforeUnmount() {
if (typeof this.api !== 'undefined') {
this.destroy()
}
},
methods: {
build() {
let slideSelector = this.options.slideSelector || '.slide'
let sectionSelector = this.options.sectionSelector || '.section'
const activeSectionIndex = window.fp_utils.index(document.querySelector(sectionSelector + '.active'))
const activeSlide = document.querySelector(sectionSelector + '.active ' + slideSelector + '.active')
const activeSlideIndex = activeSlide ? window.fp_utils.index(activeSlide) : -1
this.destroy()
if (activeSectionIndex > -1) {
window.fp_utils.addClass(document.querySelectorAll(sectionSelector)[activeSectionIndex], 'active')
}
if (activeSlideIndex > -1) {
window.fp_utils.addClass(activeSlide, 'active')
}
this.init()
},
destroy() {
if (typeof window.fullpage_api !== 'undefined' && typeof window.fullpage_api.destroy !== 'undefined') {
window.fullpage_api.destroy('all')
}
},
emitEvent(name, args) {
this.$emit(name.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase(), ...args)
if (Object.prototype.hasOwnProperty.call(this.options, name)) {
this.options[name].apply(this, args)
}
},
init() {
this.api = new fullpage(this.$refs.fullpage, this.options)
},
},
}
</script>