Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make Vue 3.x compatible (breaking!) #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
10 changes: 5 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,18 @@ function isServer(vNode) {
}

exports = module.exports = {
bind: function (el, binding, vNode) {
beforeMount: function (el, binding, vNode) {
if (!validate(binding)) return

// Define Handler and cache it on the element
function handler(e) {
if (!vNode.context) return
if (!binding.instance) return

// some components may have related popup item, on which we shall prevent the click outside event handler.
var elements = e.path || (e.composedPath && e.composedPath())
elements && elements.length > 0 && elements.unshift(e.target)

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

el.__vueClickOutside__.callback(e)
}
Expand All @@ -57,11 +57,11 @@ exports = module.exports = {
!isServer(vNode) && document.addEventListener(clickHandler, handler)
},

update: function (el, binding) {
updated: function (el, binding) {
if (validate(binding)) el.__vueClickOutside__.callback = binding.value
},

unbind: function (el, binding, vNode) {
unmounted: function (el, binding, vNode) {
// Remove Event Listeners
const clickHandler = 'ontouchstart' in document.documentElement ? 'touchstart' : 'click';
!isServer(vNode) && el.__vueClickOutside__ && document.removeEventListener(clickHandler, el.__vueClickOutside__.handler)
Expand Down