-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathindex.js
executable file
·67 lines (54 loc) · 1.51 KB
/
index.js
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
const sr = require('scrollreveal').default();
function generateOptions(defaultOptions, bindingValue, bindingModifiers) {
const options = Object.assign({}, defaultOptions, bindingValue);
if (bindingModifiers) {
if (bindingModifiers.reset) {
options.reset = true;
}
if (bindingModifiers.nomobile) {
options.mobile = false;
}
if (bindingModifiers.nodesktop) {
options.desktop = false;
}
}
return options;
}
const VueScrollReveal = {
install(Vue, defaultOptions) {
Vue.directive('scroll-reveal', {
inserted: (el, binding) => {
const options = generateOptions(defaultOptions, binding.value, binding.modifiers);
if (typeof options.class === 'string') {
el.classList.add(options.class);
delete options.class;
}
sr.reveal(el, options);
},
update: (el, binding) => {
if (binding.value != binding.oldValue) {
const options = generateOptions(defaultOptions, binding.value, binding.modifiers);
sr.reveal(el, options);
}
},
});
const $sr = {
isSupported() {
return sr.isSupported();
},
sync() {
sr.sync();
},
reveal(target, config, interval, sync) {
const options = generateOptions(defaultOptions, config);
sr.reveal(target, config, interval, sync);
},
};
Object.defineProperty(Vue.prototype, '$sr', {
get() {
return $sr;
},
});
},
};
export default VueScrollReveal;