UNPKG

vue-on-click-outside

Version:

vue mixin/directive that does something when you click outside a container

1 lines 1.16 kB
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n(e["vue-on-click-outside"]=e["vue-on-click-outside"]||{})}(this,function(e){"use strict";function n(e,n,t){return e.addEventListener(n,t,!1),{destroy:function(){return e.removeEventListener(n,t,!1)}}}function t(e,t){var o=!1,i=n(e,"mouseenter",function(){o=!0}),u=n(e,"mouseleave",function(){o=!1});return{el:e,check:function(e){o||t(e)},destroy:function(){i.destroy(),u.destroy()}}}function o(e,n){return{el:e,check:function(t){e.contains(t.target)||n(t)},destroy:function(){}}}function i(e,i){var u=i.value,f=i.modifiers;c(e),d||(d=n(document.documentElement,"click",function(e){r.forEach(function(n){return n.check(e)})})),setTimeout(function(){r.push(f.static?o(e,u):t(e,u))},0)}function u(e,n){n.value!==n.oldValue&&i(e,n)}function c(e){for(var n=r.length-1;n>=0;)r[n].el===e&&(r[n].destroy(),r.splice(n,1)),n-=1;0===r.length&&d&&(d.destroy(),d=null)}var r=[],d=void 0,f={bind:i,unbind:c,update:u},s={directives:{"on-click-outside":f}};e.directive=f,e.mixin=s,Object.defineProperty(e,"__esModule",{value:!0})});