From 5ac32b0a1f4d5d0a610a44c08e1ec49757914b2f Mon Sep 17 00:00:00 2001 From: J Date: Fri, 9 Mar 2018 11:59:03 +0900 Subject: [PATCH 1/2] added ability to accept default options from Vue.use call --- dist/vue-scroll-reveal.js | 10 +++++----- index.js | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/dist/vue-scroll-reveal.js b/dist/vue-scroll-reveal.js index cec49c1..93cd2c6 100644 --- a/dist/vue-scroll-reveal.js +++ b/dist/vue-scroll-reveal.js @@ -5,8 +5,8 @@ Object.defineProperty(exports, "__esModule", { }); var sr = require('scrollreveal')(); -function generateOptions(bindingValue, bindingModifiers) { - var options = bindingValue || {}; +function generateOptions(defaultOptions, bindingValue, bindingModifiers) { + var options = Object.assign({}, defaultOptions, bindingValue); if (bindingModifiers) { if (bindingModifiers.reset) { @@ -22,16 +22,16 @@ function generateOptions(bindingValue, bindingModifiers) { } var VueScrollReveal = { - install: function install(Vue) { + install: function install(Vue, defaultOptions) { Vue.directive('scroll-reveal', { inserted: function inserted(el, binding) { - var options = generateOptions(binding.value); + var options = generateOptions(defaultOptions, binding.value, binding.modifiers); sr.reveal(el, options); }, update: function update(el, binding) { if (binding.value != binding.oldValue) { - var options = generateOptions(binding.value, binding.modifiers); + var options = generateOptions(defaultOptions, binding.value, binding.modifiers); sr.reveal(el, options); } diff --git a/index.js b/index.js index 045266e..3e18092 100755 --- a/index.js +++ b/index.js @@ -1,7 +1,7 @@ const sr = require('scrollreveal')(); -function generateOptions(bindingValue, bindingModifiers) { - const options = bindingValue || {}; +function generateOptions(defaultOptions, bindingValue, bindingModifiers) { + const options = Object.assign({}, defaultOptions, bindingValue); if (bindingModifiers) { if (bindingModifiers.reset) { @@ -17,16 +17,16 @@ function generateOptions(bindingValue, bindingModifiers) { } const VueScrollReveal = { - install(Vue) { + install(Vue, defaultOptions) { Vue.directive('scroll-reveal', { inserted: (el, binding) => { - const options = generateOptions(binding.value); + const options = generateOptions(defaultOptions, binding.value, binding.modifiers); sr.reveal(el, options); }, update: (el, binding) => { if (binding.value != binding.oldValue) { - const options = generateOptions(binding.value, binding.modifiers); + const options = generateOptions(defaultOptions, binding.value, binding.modifiers); sr.reveal(el, options); } From cabd0fdf4bf548d026223057ab19f8e77319cea9 Mon Sep 17 00:00:00 2001 From: J Date: Fri, 9 Mar 2018 12:11:58 +0900 Subject: [PATCH 2/2] updated readme :pencil2: --- README.md | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 80e66d6..aa51870 100755 --- a/README.md +++ b/README.md @@ -1,7 +1,8 @@ # vue-scroll-reveal [![license](https://img.shields.io/github/license/tserkov/vue-scroll-reveal.svg)]() A Vue directive to wrap [@jlmake](https://github.com/jlmakes)'s excellent [ScrollReveal](https://github.com/jlmakes/scrollreveal) library. -The directive exposes `reset` and `nomobile` as modifiers (ie. `v-scroll-reveal.reset.nomobile`), and all other options can be passed as a value (ie. `v-scroll-reveal={ delay: 250 }`). +The directive exposes `reset` and `nomobile` as modifiers (ie. `v-scroll-reveal.reset.nomobile`). +All other options can be passed to `Vue.use` or to individual elements as a value (ie. `v-scroll-reveal={ delay: 250 }`). ## Install @@ -22,12 +23,21 @@ yarn add vue-scroll-reveal import VueScrollReveal from 'vue-scroll-reveal'; Vue.use(VueScrollReveal); + +// You can also pass in default options +Vue.use(VueScrollReveal, { + duration: 800, + scale: 1, + distance: '10px', + mobile: false +}); ``` ```html @@ -47,4 +62,16 @@ Vue.use(VueScrollReveal); ## Methods -As of 1.0.4, the `isSupported()` and `sync()` are now exposed via `Vue.$sr` or `this.$sr`. \ No newline at end of file +As of 1.0.4, the `isSupported()` and `sync()` are now exposed via `Vue.$sr` or `this.$sr`. + +## Nuxt + +If using as a plugin with [Nuxt](https://github.com/nuxt/nuxt.js) be sure to disable server side rendering in `nuxt.config.js`. + +```javascript +module.exports = { + plugins: [ + { src: '~/plugins/vue-scroll-reveal', ssr: false } + ], +} +```