UNPKG

exit-intent

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