js-hoverintent
Version:
Hover intent in javascript
2 lines (1 loc) • 2.19 kB
JavaScript
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e=e||self).hoverintent=n()}(this,function(){"use strict";function e(e,n){for(var t=0;n.length>t;t++){var r=n[t];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function n(e,n){return function(e){if(Array.isArray(e))return e}(e)||function(e,n){var t=[],r=!0,o=!1,i=void 0;try{for(var c,a=e[Symbol.iterator]();!(r=(c=a.next()).done)&&(t.push(c.value),!n||t.length!==n);r=!0);}catch(e){o=!0,i=e}finally{try{r||null==a.return||a.return()}finally{if(o)throw i}}return t}(e,n)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var t=function(e,t,r,o,i){if("function"!=typeof o)throw new TypeError("Expected a function");var c=function(e,n){var t,r=function(){clearTimeout(t)},o=function(){r();for(var o=arguments.length,i=Array(o),c=0;o>c;c++)i[c]=arguments[c];t=setTimeout.apply(void 0,[e,+n].concat(i))};return o.cancel=r,o}(o,+i),a=function(n){return n.addEventListener(e,c),function(){return n.removeEventListener(e,c)}},u=function(e){return e.addEventListener(t,c.cancel),function(){return e.removeEventListener(t,c.cancel)}},f=[];r.forEach(function(e){f.push([a(e),u(e)])});return function(){f.forEach(function(e){var t=n(e,2),r=t[1];(0,t[0])(),r()}),c.cancel()}},r=function(){for(var e=arguments.length,n=Array(e),r=0;e>r;r++)n[r]=arguments[r];return t.apply(void 0,["mouseenter","mouseleave"].concat(n))},o=function(){for(var e=arguments.length,n=Array(e),r=0;e>r;r++)n[r]=arguments[r];return t.apply(void 0,["mouseleave","mouseenter"].concat(n))};return function(){function n(e,t,i,c){!function(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}(this,n);this.selector=document.querySelectorAll(e),this.options=Object.assign({},{enterWait:100,leaveWait:100},c),this.cancelEnter=r(this.selector,t,this.options.enterWait),this.cancelLeave=o(this.selector,i,this.options.leaveWait)}var t,i,c;return t=n,(i=[{key:"cancel",value:function(){this.cancelEnter(),this.cancelLeave()}}])&&e(t.prototype,i),c&&e(t,c),n}()});