Skip to content

Commit

Permalink
click outside issue
Browse files Browse the repository at this point in the history
  • Loading branch information
vishu3011 committed Oct 31, 2020
1 parent 8419f98 commit d279313
Show file tree
Hide file tree
Showing 8 changed files with 482 additions and 529 deletions.
482 changes: 225 additions & 257 deletions dist/nitrozen.common.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/nitrozen.common.js.map

Large diffs are not rendered by default.

482 changes: 225 additions & 257 deletions dist/nitrozen.umd.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/nitrozen.umd.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/nitrozen.umd.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/nitrozen.umd.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gofynd/nitrozen-vue",
"version": "0.0.22",
"version": "0.0.23",
"description": "Fynd Design Library for Vue",
"homepage": "https://github.com/gofynd/nitrozen-vue#readme",
"author": "Aayush Jain<aayushjain3011@gmail.com>",
Expand Down
37 changes: 27 additions & 10 deletions src/directives/NClickOutside.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,35 @@
import Vue from 'vue';

const clickOutside = Vue.directive('click-outside', {
bind: function (el, binding, vnode) {
el.clickOutsideEvent = function (event) {
// Check that click was outside the element
if (!(el === event.target || el.contains(event.target))) {
// call function expression assigned
vnode.context[binding.expression](event);
bind: function (el, binding, vNode) {
// Provided expression must evaluate to a function.
if (typeof binding.value !== 'function') {
const compName = vNode.context.name
let warn = `[Nitrozen-click-outside:] provided expression '${binding.expression}' is not a function, but has to be`
if (compName) {
warn += ` Found in component '${compName}'`
}
};
document.body.addEventListener('click', el.clickOutsideEvent);

console.warn(warn)
}
// Define Handler and cache it on the element
const bubble = binding.modifiers.bubble
const handler = (e) => {
if (bubble || -1 == e.path.indexOf(el)) {
binding.value(e)
}
}
el.__nitrozenClickOutside__ = handler

// add Event Listeners
document.addEventListener('click', handler)
},
unbind: function (el) {
document.body.removeEventListener('click', el.clickOutsideEvent);

unbind: function (el, binding) {
// Remove Event Listeners
document.removeEventListener('click', el.__nitrozenClickOutside__)
el.__nitrozenClickOutside__ = null

}
});

Expand Down

0 comments on commit d279313

Please sign in to comment.