Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

nuxt-interpolation

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nuxt-interpolation - npm Package Compare versions

Comparing version
0.1.6
to
0.1.7
+54
index.js
import Vue from 'vue'
export default ({ app: { router } }) => {
// https://vuejs.org/v2/guide/custom-directive.html
Vue.directive('interpolation', {
// Called only once, when the directive is first bound to the element. This is where you can do one-time setup work.
bind (el) {
const navigate = event => {
const href = event.target.getAttribute('href')
if (href && href[0] === '/') {
event.preventDefault()
router.push(href)
}
}
let links = el.getElementsByTagName('a')
const addListeners = links => {
for (let i = 0; i < links.length; i++) {
const target = links[i].getAttribute('target')
// For improved security `rel="noopener"` will be added automatically if target is `_blank`
// https://github.com/mathiasbynens/rel-noopener/
if (target && target === '_blank') {
links[i].setAttribute('rel', 'noopener')
}
links[i].addEventListener('click', navigate, false)
}
}
const removeListeners = links => {
for (let i = 0; i < links.length; i++) {
links[i].removeEventListener('click', navigate, false)
}
links = []
}
addListeners(links)
el.$componentUpdated = () => {
removeListeners(links)
Vue.nextTick(() => addListeners(links))
}
el.$destroy = () => el.removeEventListener('click', removeListeners(links))
},
// Called after the containing component’s VNode and the VNodes of its children have updated.
componentUpdated: el => el.$componentUpdated(),
// Called only once, when the directive is unbound from the element.
unbind: el => el.$destroy()
})
}
+10
-0

@@ -5,2 +5,12 @@ # Change Log

<a name="0.1.7"></a>
## [0.1.7](https://github.com/daliborgogic/nuxt-interpolation/compare/v0.1.6...v0.1.7) (2018-09-13)
### Bug Fixes
* directive not found ([c2004d8](https://github.com/daliborgogic/nuxt-interpolation/commit/c2004d8))
<a name="0.1.6"></a>

@@ -7,0 +17,0 @@ ## [0.1.6](https://github.com/daliborgogic/nuxt-interpolation/compare/v0.1.5...v0.1.6) (2018-09-13)

+1
-1
{
"name": "nuxt-interpolation",
"version": "0.1.6",
"version": "0.1.7",
"description": "Directive for binding every link to catch the click event, and if it's a relative link router will push.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -8,7 +8,7 @@ # interpolation

- Add ```nuxt-interpolation``` as dependency
- Add ```nuxt-interpolation``` to plugins section of ```nuxt.config.js```
- Point ```nuxt-interpolation``` to plugins section of ```nuxt.config.js```
```javascript
{
plugins: ['nuxt-interpolation']
plugins: ['./node_modules/nuxt-interpolation']
}

@@ -15,0 +15,0 @@ ```

const { resolve } = require('path')
module.exports = function module (moduleOptions) {
this.addPlugin({
src: resolve(__dirname, './templates/plugin.js'),
fileName: 'interpolation.js'
})
}
import Vue from 'vue'
export default ({ app: { router } }) => {
// https://vuejs.org/v2/guide/custom-directive.html
Vue.directive('interpolation', {
// Called only once, when the directive is first bound to the element. This is where you can do one-time setup work.
bind (el) {
const navigate = event => {
const href = event.target.getAttribute('href')
if (href && href[0] === '/') {
event.preventDefault()
router.push(href)
}
}
let links = el.getElementsByTagName('a')
const addListeners = links => {
for (let i = 0; i < links.length; i++) {
const target = links[i].getAttribute('target')
// For improved security `rel="noopener"` will be added automatically if target is `_blank`
// https://github.com/mathiasbynens/rel-noopener/
if (target && target === '_blank') {
links[i].setAttribute('rel', 'noopener')
}
links[i].addEventListener('click', navigate, false)
}
}
const removeListeners = links => {
for (let i = 0; i < links.length; i++) {
links[i].removeEventListener('click', navigate, false)
}
links = []
}
addListeners(links)
el.$componentUpdated = () => {
removeListeners(links)
Vue.nextTick(() => addListeners(links))
}
el.$destroy = () => el.removeEventListener('click', removeListeners(links))
},
// Called after the containing component’s VNode and the VNodes of its children have updated.
componentUpdated: el => el.$componentUpdated(),
// Called only once, when the directive is unbound from the element.
unbind: el => el.$destroy()
})
}