UNPKG

exit-intent-quattro

Version:

Exit intent detection library - detects all 4 edges.

2 lines (1 loc) 4.81 kB
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.ExitIntent=e()}(this,function(){"use strict";var t=function(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)},e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n="object"==typeof e&&e&&e.Object===Object&&e,o="object"==typeof self&&self&&self.Object===Object&&self,r=n||o||Function("return this")(),i=function(){return r.Date.now()},u=r.Symbol,c=Object.prototype,a=c.hasOwnProperty,f=c.toString,l=u?u.toStringTag:void 0,s=function(t){var e=a.call(t,l),n=t[l];try{t[l]=void 0;var o=!0}catch(t){}var r=f.call(t);return o&&(e?t[l]=n:delete t[l]),r},d=Object.prototype.toString,v=function(t){return d.call(t)},p="[object Null]",h="[object Undefined]",m=u?u.toStringTag:void 0,y=function(t){return null==t?void 0===t?h:p:m&&m in Object(t)?s(t):v(t)},g=function(t){return null!=t&&"object"==typeof t},b="[object Symbol]",x=function(t){return"symbol"==typeof t||g(t)&&y(t)==b},w=NaN,j=/^\s+|\s+$/g,O=/^[-+]0x[0-9a-f]+$/i,E=/^0b[01]+$/i,T=/^0o[0-7]+$/i,k=parseInt,S=function(e){if("number"==typeof e)return e;if(x(e))return w;if(t(e)){var n="function"==typeof e.valueOf?e.valueOf():e;e=t(n)?n+"":n}if("string"!=typeof e)return 0===e?e:+e;e=e.replace(j,"");var o=E.test(e);return o||T.test(e)?k(e.slice(2),o?2:8):O.test(e)?w:+e},D="Expected a function",I=Math.max,M=Math.min,N=function(e,n,o){function r(t){var n=d,o=v;return d=v=void 0,g=t,h=e.apply(o,n)}function u(t){return g=t,m=setTimeout(f,n),b?r(t):h}function c(t){var e=t-g,o=n-(t-y);return x?M(o,p-e):o}function a(t){var e=t-y,o=t-g;return void 0===y||e>=n||e<0||x&&o>=p}function f(){var t=i();if(a(t))return l(t);m=setTimeout(f,c(t))}function l(t){return m=void 0,w&&d?r(t):(d=v=void 0,h)}function s(){var t=i(),e=a(t);if(d=arguments,v=this,y=t,e){if(void 0===m)return u(y);if(x)return clearTimeout(m),m=setTimeout(f,n),r(y)}return void 0===m&&(m=setTimeout(f,n)),h}var d,v,p,h,m,y,g=0,b=!1,x=!1,w=!0;if("function"!=typeof e)throw new TypeError(D);return n=S(n)||0,t(o)&&(b=!!o.leading,p=(x="maxWait"in o)?I(S(o.maxWait)||0,n):p,w="trailing"in o?!!o.trailing:w),s.cancel=function(){void 0!==m&&clearTimeout(m),g=0,d=y=v=m=void 0},s.flush=function(){return void 0===m?h:l(i())},s},W="Expected a function",P=function(e,n,o){var r=!0,i=!0;if("function"!=typeof e)throw new TypeError(W);return t(o)&&(r="leading"in o?!!o.leading:r,i="trailing"in o?!!o.trailing:i),N(e,n,{leading:r,maxWait:n,trailing:i})},$=(function(){function t(t){this.value=t}function e(e){function n(r,i){try{var u=e[r](i),c=u.value;c instanceof t?Promise.resolve(c.value).then(function(t){n("next",t)},function(t){n("throw",t)}):o(u.done?"return":"normal",u.value)}catch(t){o("throw",t)}}function o(t,e){switch(t){case"return":r.resolve({value:e,done:!0});break;case"throw":r.reject(e);break;default:r.resolve({value:e,done:!1})}(r=r.next)?n(r.key,r.arg):i=null}var r,i;this._invoke=function(t,e){return new Promise(function(o,u){var c={key:t,arg:e,resolve:o,reject:u,next:null};i?i=i.next=c:(r=i=c,n(t,e))})},"function"!=typeof e.return&&(this.return=void 0)}"function"==typeof Symbol&&Symbol.asyncIterator&&(e.prototype[Symbol.asyncIterator]=function(){return this}),e.prototype.next=function(t){return this._invoke("next",t)},e.prototype.throw=function(t){return this._invoke("throw",t)},e.prototype.return=function(t){return this._invoke("return",t)}}(),Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(t[o]=n[o])}return t});return function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e={edges:{top:!0,right:!1,bottom:!1,left:!1},threshold:20,maxDisplays:1,eventThrottle:200,onExitIntent:function(){}};return function(){var n=$({},e,t,{edges:$({},e.edges,t.edges)}),o=new Map,r=0,i=function(t){var e=o.get(t),n=e.eventName,r=e.callback;document.removeEventListener(n,r),o.delete(t)},u=function(t,e){return n.edges.top&&e<=n.threshold&&r<n.maxDisplays?(r++,"top"):n.edges.right&&t>=a()-n.threshold&&r<n.maxDisplays?(r++,"right"):n.edges.bottom&&e>=f()-n.threshold&&r<n.maxDisplays?(r++,"bottom"):!!(n.edges.left&&t<=n.threshold&&r<n.maxDisplays)&&(r++,"left")},c=function(){o.forEach(function(t,e,n){return i(e)})},a=function(){return Math.max(document.documentElement.clientWidth||0,window.innerWidth||0)},f=function(){return Math.max(document.documentElement.clientHeight||0,window.innerHeight||0)};return function(t,e){document.addEventListener(t,e,!1),o.set("document:"+t,{eventName:t,callback:e})}("mousemove",P(function(t){var e=u(t.clientX,t.clientY);e&&(n.onExitIntent({side:e,position:{x:t.clientX,y:t.clientY}}),r>=n.maxDisplays&&c())},n.eventThrottle)),c}()}});