From 7102b25216abbac2cab4337c61400c6d68caffa1 Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Fri, 1 Apr 2022 23:53:34 +0100 Subject: [PATCH] :truck: Moves clickOutside into directives --- src/utils/ClickOutside.js | 37 ------------------------------------- 1 file changed, 37 deletions(-) delete mode 100644 src/utils/ClickOutside.js diff --git a/src/utils/ClickOutside.js b/src/utils/ClickOutside.js deleted file mode 100644 index 83bb4bbc..00000000 --- a/src/utils/ClickOutside.js +++ /dev/null @@ -1,37 +0,0 @@ -/** - * A simple Vue directive to trigger an event when the user - * clicks anywhere other than the specified element. - * Used to close context menu's popup menus and tips. - */ - -const instances = []; - -function onDocumentClick(e, el, fn) { - const { target } = e; - if (el !== target && !el.contains(target)) { - fn(e); - } -} - -export default { - bind(element, binding) { - const el = element; - el.dataset.outsideClickIndex = instances.length; - - const fn = binding.value; - const click = (e) => { - onDocumentClick(e, el, fn); - }; - - document.addEventListener('click', click); - document.addEventListener('touchstart', click); - instances.push(click); - }, - unbind(el) { - if (!el.dataset) return; - const index = el.dataset.outsideClickIndex; - const handler = instances[index]; - document.removeEventListener('click', handler); - instances.splice(index, 1); - }, -};