Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,53 @@ export default {
</script>
```

## Example for use argument

```vue
<template>
<div>
<div v-click-outside:[count]="hide" @click="toggle">Toggle</div>
<div v-show="opened">Popup item</div>
</div>
</template>

<script>
import ClickOutside from 'vue-click-outside'

export default {
data () {
return {
opened: false
count: 0
}
},

methods: {
toggle () {
this.opened = true

},

hide (el,arg) {
this.opened = false
this.arg ++;
}
},

mounted () {
// prevent click outside event with popupItem.
this.popupItem = this.$el
},

// do not forget this section
directives: {
ClickOutside
}
}
</script>
```


## Badges

![](https://img.shields.io/badge/license-MIT-blue.svg)
Expand Down
7 changes: 4 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function isPopup(popupItem, elements) {
if (elements[i].contains(popupItem)) {
return false
}
} catch(e) {
} catch (e) {
return false
}
}
Expand All @@ -45,13 +45,14 @@ exports = module.exports = {

if (el.contains(e.target) || isPopup(vNode.context.popupItem, elements)) return

el.__vueClickOutside__.callback(e)
el.__vueClickOutside__.callback(e, el.__vueClickOutside__.arg)
}

// add Event Listeners
el.__vueClickOutside__ = {
handler: handler,
callback: binding.value
callback: binding.value,
arg: binding.arg
}
const clickHandler = 'ontouchstart' in document.documentElement ? 'touchstart' : 'click';
!isServer(vNode) && document.addEventListener(clickHandler, handler)
Expand Down