@salla.sa/event
Advanced tools
Comparing version 1.0.15 to 1.0.16
@@ -8,3 +8,3 @@ !function(e){"function"==typeof define&&define.amd?define(e):e()}((function(){"use strict";var e,t={exports:{}}; | ||
* Licensed under the MIT license. | ||
*/e=t,function(t){var i=Object.hasOwnProperty,n=Array.isArray?Array.isArray:function(e){return"[object Array]"===Object.prototype.toString.call(e)},r="object"==typeof process&&"function"==typeof process.nextTick,s="function"==typeof Symbol,o="object"==typeof Reflect,l="function"==typeof setImmediate?setImmediate:setTimeout,a=s?o&&"function"==typeof Reflect.ownKeys?Reflect.ownKeys:function(e){var t=Object.getOwnPropertyNames(e);return t.push.apply(t,Object.getOwnPropertySymbols(e)),t}:Object.keys;function c(){this._events={},this._conf&&h.call(this,this._conf)}function h(e){e&&(this._conf=e,e.delimiter&&(this.delimiter=e.delimiter),e.maxListeners!==t&&(this._maxListeners=e.maxListeners),e.wildcard&&(this.wildcard=e.wildcard),e.newListener&&(this._newListener=e.newListener),e.removeListener&&(this._removeListener=e.removeListener),e.verboseMemoryLeak&&(this.verboseMemoryLeak=e.verboseMemoryLeak),e.ignoreErrors&&(this.ignoreErrors=e.ignoreErrors),this.wildcard&&(this.listenerTree={}))}function f(e,t){var i="(node) warning: possible EventEmitter memory leak detected. "+e+" listeners added. Use emitter.setMaxListeners() to increase limit.";if(this.verboseMemoryLeak&&(i+=" Event name: "+t+"."),"undefined"!=typeof process&&process.emitWarning){var n=new Error(i);n.name="MaxListenersExceededWarning",n.emitter=this,n.count=e,process.emitWarning(n)}else console.error(i),console.trace&&console.trace()}var u=function(e,t,i){var n=arguments.length;switch(n){case 0:return[];case 1:return[e];case 2:return[e,t];case 3:return[e,t,i];default:for(var r=new Array(n);n--;)r[n]=arguments[n];return r}};function p(e,i){for(var n={},r=e.length,s=i?i.length:0,o=0;o<r;o++)n[e[o]]=o<s?i[o]:t;return n}function v(e,t,i){var n,r;if(this._emitter=e,this._target=t,this._listeners={},this._listenersCount=0,(i.on||i.off)&&(n=i.on,r=i.off),t.addEventListener?(n=t.addEventListener,r=t.removeEventListener):t.addListener?(n=t.addListener,r=t.removeListener):t.on&&(n=t.on,r=t.off),!n&&!r)throw Error("target does not implement any known event API");if("function"!=typeof n)throw TypeError("on method must be a function");if("function"!=typeof r)throw TypeError("off method must be a function");this._on=n,this._off=r;var s=e._observers;s?s.push(this):e._observers=[this]}function y(e,n,r,s){var o=Object.assign({},n);if(!e)return o;if("object"!=typeof e)throw TypeError("options must be an object");var l,a,c,h=Object.keys(e),f=h.length;function u(e){throw Error('Invalid "'+l+'" option value'+(e?". Reason: "+e:""))}for(var p=0;p<f;p++){if(l=h[p],!s&&!i.call(n,l))throw Error('Unknown "'+l+'" option');(a=e[l])!==t&&(c=r[l],o[l]=c?c(a,u):a)}return o}function d(e,t){return"function"==typeof e&&e.hasOwnProperty("prototype")||t("value must be a constructor"),e}function _(e){var t="value must be type of "+e.join("|"),i=e.length,n=e[0],r=e[1];return 1===i?function(e,i){if(typeof e===n)return e;i(t)}:2===i?function(e,i){var s=typeof e;if(s===n||s===r)return e;i(t)}:function(n,r){for(var s=typeof n,o=i;o-- >0;)if(s===e[o])return n;r(t)}}Object.assign(v.prototype,{subscribe:function(e,t,i){var n=this,r=this._target,s=this._emitter,o=this._listeners,l=function(){var n=u.apply(null,arguments),o={data:n,name:t,original:e};if(i){var l=i.call(r,o);!1!==l&&s.emit.apply(s,[o.name].concat(n))}else s.emit.apply(s,[t].concat(n))};if(o[e])throw Error("Event '"+e+"' is already listening");this._listenersCount++,s._newListener&&s._removeListener&&!n._onNewListener?(this._onNewListener=function(i){i===t&&null===o[e]&&(o[e]=l,n._on.call(r,e,l))},s.on("newListener",this._onNewListener),this._onRemoveListener=function(i){i===t&&!s.hasListeners(i)&&o[e]&&(o[e]=null,n._off.call(r,e,l))},o[e]=null,s.on("removeListener",this._onRemoveListener)):(o[e]=l,n._on.call(r,e,l))},unsubscribe:function(e){var t,i,n,r=this,s=this._listeners,o=this._emitter,l=this._off,c=this._target;if(e&&"string"!=typeof e)throw TypeError("event must be a string");function h(){r._onNewListener&&(o.off("newListener",r._onNewListener),o.off("removeListener",r._onRemoveListener),r._onNewListener=null,r._onRemoveListener=null);var e=w.call(o,r);o._observers.splice(e,1)}if(e){if(!(t=s[e]))return;l.call(c,e,t),delete s[e],--this._listenersCount||h()}else{for(n=(i=a(s)).length;n-- >0;)e=i[n],l.call(c,e,s[e]);this._listeners={},this._listenersCount=0,h()}}});var m=_(["function"]),b=_(["object","function"]);function g(e,t,i){var n,r,s,o=0,l=new e((function(a,c,h){function f(){r&&(r=null),o&&(clearTimeout(o),o=0)}i=y(i,{timeout:0,overload:!1},{timeout:function(e,t){return("number"!=typeof(e*=1)||e<0||!Number.isFinite(e))&&t("timeout must be a positive number"),e}}),n=!i.overload&&"function"==typeof e.prototype.cancel&&"function"==typeof h;var u=function(e){f(),a(e)},p=function(e){f(),c(e)};n?t(u,p,h):(r=[function(e){p(e||Error("canceled"))}],t(u,p,(function(e){if(s)throw Error("Unable to subscribe on cancel event asynchronously");if("function"!=typeof e)throw TypeError("onCancel callback must be a function");r.push(e)})),s=!0),i.timeout>0&&(o=setTimeout((function(){var e=Error("timeout");e.code="ETIMEDOUT",o=0,l.cancel(e),c(e)}),i.timeout))}));return n||(l.cancel=function(e){if(r){for(var t=r.length,i=1;i<t;i++)r[i](e);r[0](e),r=null}}),l}function w(e){var t=this._observers;if(!t)return-1;for(var i=t.length,n=0;n<i;n++)if(t[n]._target===e)return n;return-1}function L(e,t,i,n,r){if(!i)return null;if(0===n){var s=typeof t;if("string"===s){var o,l,c=0,h=0,f=this.delimiter,u=f.length;if(-1!==(l=t.indexOf(f))){o=new Array(5);do{o[c++]=t.slice(h,l),h=l+u}while(-1!==(l=t.indexOf(f,h)));o[c++]=t.slice(h),t=o,r=c}else t=[t],r=1}else"object"===s?r=t.length:(t=[t],r=1)}var p,v,y,d,_,m,b,g=null,w=t[n],E=t[n+1];if(n===r)i._listeners&&("function"==typeof i._listeners?(e&&e.push(i._listeners),g=[i]):(e&&e.push.apply(e,i._listeners),g=[i]));else{if("*"===w){for(l=(m=a(i)).length;l-- >0;)"_listeners"!==(p=m[l])&&(b=L(e,t,i[p],n+1,r))&&(g?g.push.apply(g,b):g=b);return g}if("**"===w){for((_=n+1===r||n+2===r&&"*"===E)&&i._listeners&&(g=L(e,t,i,r,r)),l=(m=a(i)).length;l-- >0;)"_listeners"!==(p=m[l])&&("*"===p||"**"===p?(i[p]._listeners&&!_&&(b=L(e,t,i[p],r,r))&&(g?g.push.apply(g,b):g=b),b=L(e,t,i[p],n,r)):b=L(e,t,i[p],p===E?n+2:n,r),b&&(g?g.push.apply(g,b):g=b));return g}i[w]&&(g=L(e,t,i[w],n+1,r))}if((v=i["*"])&&L(e,t,v,n+1,r),y=i["**"])if(n<r)for(y._listeners&&L(e,t,y,r,r),l=(m=a(y)).length;l-- >0;)"_listeners"!==(p=m[l])&&(p===E?L(e,t,y[p],n+2,r):p===w?L(e,t,y[p],n+1,r):((d={})[p]=y[p],L(e,t,{"**":d},n+1,r)));else y._listeners?L(e,t,y,r,r):y["*"]&&y["*"]._listeners&&L(e,t,y["*"],r,r);return g}function E(e,t,i){var n,r,s=0,o=0,l=this.delimiter,a=l.length;if("string"==typeof e)if(-1!==(n=e.indexOf(l))){r=new Array(5);do{r[s++]=e.slice(o,n),o=n+a}while(-1!==(n=e.indexOf(l,o)));r[s++]=e.slice(o)}else r=[e],s=1;else r=e,s=e.length;if(s>1)for(n=0;n+1<s;n++)if("**"===r[n]&&"**"===r[n+1])return;var c,h=this.listenerTree;for(n=0;n<s;n++)if(h=h[c=r[n]]||(h[c]={}),n===s-1)return h._listeners?("function"==typeof h._listeners&&(h._listeners=[h._listeners]),i?h._listeners.unshift(t):h._listeners.push(t),!h._listeners.warned&&this._maxListeners>0&&h._listeners.length>this._maxListeners&&(h._listeners.warned=!0,f.call(this,h._listeners.length,c))):h._listeners=t,!0;return!0}function k(e,t,i,n){for(var r,s,o,l,c=a(e),h=c.length,f=e._listeners;h-- >0;)r=e[s=c[h]],o="_listeners"===s?i:i?i.concat(s):[s],l=n||"symbol"==typeof s,f&&t.push(l?o:o.join(this.delimiter)),"object"==typeof r&&k.call(this,r,t,o,l);return t}function j(e){for(var t,i,n,r=a(e),s=r.length;s-- >0;)(t=e[i=r[s]])&&(n=!0,"_listeners"===i||j(t)||delete e[i]);return n}function T(e,t,i){this.emitter=e,this.event=t,this.listener=i}function x(e,i,n){if(!0===n)o=!0;else if(!1===n)s=!0;else{if(!n||"object"!=typeof n)throw TypeError("options should be an object or true");var s=n.async,o=n.promisify,a=n.nextTick,c=n.objectify}if(s||a||o){var h=i,f=i._origin||i;if(a&&!r)throw Error("process.nextTick is not supported");o===t&&(o="AsyncFunction"===i.constructor.name),i=function(){var e=arguments,t=this,i=this.event;return o?a?Promise.resolve():new Promise((function(e){l(e)})).then((function(){return t.event=i,h.apply(t,e)})):(a?process.nextTick:l)((function(){t.event=i,h.apply(t,e)}))},i._async=!0,i._origin=f}return[i,c?new T(this,e,i):this]}function A(e){this._events={},this._newListener=!1,this._removeListener=!1,this.verboseMemoryLeak=!1,h.call(this,e)}T.prototype.off=function(){return this.emitter.off(this.event,this.listener),this},A.EventEmitter2=A,A.prototype.listenTo=function(e,i,r){if("object"!=typeof e)throw TypeError("target musts be an object");var s=this;function o(t){if("object"!=typeof t)throw TypeError("events must be an object");var i,n=r.reducers,o=w.call(s,e);i=-1===o?new v(s,e,r):s._observers[o];for(var l,c=a(t),h=c.length,f="function"==typeof n,u=0;u<h;u++)l=c[u],i.subscribe(l,t[l]||l,f?n:n&&n[l])}return r=y(r,{on:t,off:t,reducers:t},{on:m,off:m,reducers:b}),n(i)?o(p(i)):o("string"==typeof i?p(i.split(/\s+/)):i),this},A.prototype.stopListeningTo=function(e,t){var i=this._observers;if(!i)return!1;var n,r=i.length,s=!1;if(e&&"object"!=typeof e)throw TypeError("target should be an object");for(;r-- >0;)n=i[r],e&&n._target!==e||(n.unsubscribe(t),s=!0);return s},A.prototype.delimiter=".",A.prototype.setMaxListeners=function(e){e!==t&&(this._maxListeners=e,this._conf||(this._conf={}),this._conf.maxListeners=e)},A.prototype.getMaxListeners=function(){return this._maxListeners},A.prototype.event="",A.prototype.once=function(e,t,i){return this._once(e,t,!1,i)},A.prototype.prependOnceListener=function(e,t,i){return this._once(e,t,!0,i)},A.prototype._once=function(e,t,i,n){return this._many(e,1,t,i,n)},A.prototype.many=function(e,t,i,n){return this._many(e,t,i,!1,n)},A.prototype.prependMany=function(e,t,i,n){return this._many(e,t,i,!0,n)},A.prototype._many=function(e,t,i,n,r){var s=this;if("function"!=typeof i)throw new Error("many only accepts instances of Function");function o(){return 0==--t&&s.off(e,o),i.apply(this,arguments)}return o._origin=i,this._on(e,o,n,r)},A.prototype.emit=function(){if(!this._events&&!this._all)return!1;this._events||c.call(this);var e,t,i,n,r,o,l=arguments[0],a=this.wildcard;if("newListener"===l&&!this._newListener&&!this._events.newListener)return!1;if(a&&(e=l,"newListener"!==l&&"removeListener"!==l&&"object"==typeof l)){if(i=l.length,s)for(n=0;n<i;n++)if("symbol"==typeof l[n]){o=!0;break}o||(l=l.join(this.delimiter))}var h,f=arguments.length;if(this._all&&this._all.length)for(n=0,i=(h=this._all.slice()).length;n<i;n++)switch(this.event=l,f){case 1:h[n].call(this,l);break;case 2:h[n].call(this,l,arguments[1]);break;case 3:h[n].call(this,l,arguments[1],arguments[2]);break;default:h[n].apply(this,arguments)}if(a)h=[],L.call(this,h,e,this.listenerTree,0,i);else{if("function"==typeof(h=this._events[l])){switch(this.event=l,f){case 1:h.call(this);break;case 2:h.call(this,arguments[1]);break;case 3:h.call(this,arguments[1],arguments[2]);break;default:for(t=new Array(f-1),r=1;r<f;r++)t[r-1]=arguments[r];h.apply(this,t)}return!0}h&&(h=h.slice())}if(h&&h.length){if(f>3)for(t=new Array(f-1),r=1;r<f;r++)t[r-1]=arguments[r];for(n=0,i=h.length;n<i;n++)switch(this.event=l,f){case 1:h[n].call(this);break;case 2:h[n].call(this,arguments[1]);break;case 3:h[n].call(this,arguments[1],arguments[2]);break;default:h[n].apply(this,t)}return!0}if(!this.ignoreErrors&&!this._all&&"error"===l)throw arguments[1]instanceof Error?arguments[1]:new Error("Uncaught, unspecified 'error' event.");return!!this._all},A.prototype.emitAsync=function(){if(!this._events&&!this._all)return!1;this._events||c.call(this);var e,t,i,n,r,o,l=arguments[0],a=this.wildcard;if("newListener"===l&&!this._newListener&&!this._events.newListener)return Promise.resolve([!1]);if(a&&(e=l,"newListener"!==l&&"removeListener"!==l&&"object"==typeof l)){if(n=l.length,s)for(r=0;r<n;r++)if("symbol"==typeof l[r]){t=!0;break}t||(l=l.join(this.delimiter))}var h,f=[],u=arguments.length;if(this._all)for(r=0,n=this._all.length;r<n;r++)switch(this.event=l,u){case 1:f.push(this._all[r].call(this,l));break;case 2:f.push(this._all[r].call(this,l,arguments[1]));break;case 3:f.push(this._all[r].call(this,l,arguments[1],arguments[2]));break;default:f.push(this._all[r].apply(this,arguments))}if(a?(h=[],L.call(this,h,e,this.listenerTree,0)):h=this._events[l],"function"==typeof h)switch(this.event=l,u){case 1:f.push(h.call(this));break;case 2:f.push(h.call(this,arguments[1]));break;case 3:f.push(h.call(this,arguments[1],arguments[2]));break;default:for(i=new Array(u-1),o=1;o<u;o++)i[o-1]=arguments[o];f.push(h.apply(this,i))}else if(h&&h.length){if(h=h.slice(),u>3)for(i=new Array(u-1),o=1;o<u;o++)i[o-1]=arguments[o];for(r=0,n=h.length;r<n;r++)switch(this.event=l,u){case 1:f.push(h[r].call(this));break;case 2:f.push(h[r].call(this,arguments[1]));break;case 3:f.push(h[r].call(this,arguments[1],arguments[2]));break;default:f.push(h[r].apply(this,i))}}else if(!this.ignoreErrors&&!this._all&&"error"===l)return arguments[1]instanceof Error?Promise.reject(arguments[1]):Promise.reject("Uncaught, unspecified 'error' event.");return Promise.all(f)},A.prototype.on=function(e,t,i){return this._on(e,t,!1,i)},A.prototype.prependListener=function(e,t,i){return this._on(e,t,!0,i)},A.prototype.onAny=function(e){return this._onAny(e,!1)},A.prototype.prependAny=function(e){return this._onAny(e,!0)},A.prototype.addListener=A.prototype.on,A.prototype._onAny=function(e,t){if("function"!=typeof e)throw new Error("onAny only accepts instances of Function");return this._all||(this._all=[]),t?this._all.unshift(e):this._all.push(e),this},A.prototype._on=function(e,i,n,r){if("function"==typeof e)return this._onAny(e,i),this;if("function"!=typeof i)throw new Error("on only accepts instances of Function");this._events||c.call(this);var s,o=this;return r!==t&&(i=(s=x.call(this,e,i,r))[0],o=s[1]),this._newListener&&this.emit("newListener",e,i),this.wildcard?(E.call(this,e,i,n),o):(this._events[e]?("function"==typeof this._events[e]&&(this._events[e]=[this._events[e]]),n?this._events[e].unshift(i):this._events[e].push(i),!this._events[e].warned&&this._maxListeners>0&&this._events[e].length>this._maxListeners&&(this._events[e].warned=!0,f.call(this,this._events[e].length,e))):this._events[e]=i,o)},A.prototype.off=function(e,t){if("function"!=typeof t)throw new Error("removeListener only takes instances of Function");var i,r=[];if(this.wildcard){var s="string"==typeof e?e.split(this.delimiter):e.slice();if(!(r=L.call(this,null,s,this.listenerTree,0)))return this}else{if(!this._events[e])return this;i=this._events[e],r.push({_listeners:i})}for(var o=0;o<r.length;o++){var l=r[o];if(i=l._listeners,n(i)){for(var a=-1,c=0,h=i.length;c<h;c++)if(i[c]===t||i[c].listener&&i[c].listener===t||i[c]._origin&&i[c]._origin===t){a=c;break}if(a<0)continue;return this.wildcard?l._listeners.splice(a,1):this._events[e].splice(a,1),0===i.length&&(this.wildcard?delete l._listeners:delete this._events[e]),this._removeListener&&this.emit("removeListener",e,t),this}(i===t||i.listener&&i.listener===t||i._origin&&i._origin===t)&&(this.wildcard?delete l._listeners:delete this._events[e],this._removeListener&&this.emit("removeListener",e,t))}return this.listenerTree&&j(this.listenerTree),this},A.prototype.offAny=function(e){var t,i=0,n=0;if(e&&this._all&&this._all.length>0){for(i=0,n=(t=this._all).length;i<n;i++)if(e===t[i])return t.splice(i,1),this._removeListener&&this.emit("removeListenerAny",e),this}else{if(t=this._all,this._removeListener)for(i=0,n=t.length;i<n;i++)this.emit("removeListenerAny",t[i]);this._all=[]}return this},A.prototype.removeListener=A.prototype.off,A.prototype.removeAllListeners=function(e){if(e===t)return!this._events||c.call(this),this;if(this.wildcard){var i,n=L.call(this,null,e,this.listenerTree,0);if(!n)return this;for(i=0;i<n.length;i++)n[i]._listeners=null;this.listenerTree&&j(this.listenerTree)}else this._events&&(this._events[e]=null);return this},A.prototype.listeners=function(e){var i,n,r,s,o,l=this._events;if(e===t){if(this.wildcard)throw Error("event name required for wildcard emitter");if(!l)return[];for(s=(i=a(l)).length,r=[];s-- >0;)"function"==typeof(n=l[i[s]])?r.push(n):r.push.apply(r,n);return r}if(this.wildcard){if(!(o=this.listenerTree))return[];var c=[],h="string"==typeof e?e.split(this.delimiter):e.slice();return L.call(this,c,h,o,0),c}return l&&(n=l[e])?"function"==typeof n?[n]:n:[]},A.prototype.eventNames=function(e){var t=this._events;return this.wildcard?k.call(this,this.listenerTree,[],null,e):t?a(t):[]},A.prototype.listenerCount=function(e){return this.listeners(e).length},A.prototype.hasListeners=function(e){if(this.wildcard){var i=[],n="string"==typeof e?e.split(this.delimiter):e.slice();return L.call(this,i,n,this.listenerTree,0),i.length>0}var r=this._events,s=this._all;return!!(s&&s.length||r&&(e===t?a(r).length:r[e]))},A.prototype.listenersAny=function(){return this._all?this._all:[]},A.prototype.waitFor=function(e,i){var n=this,r=typeof i;return"number"===r?i={timeout:i}:"function"===r&&(i={filter:i}),g((i=y(i,{timeout:0,filter:t,handleError:!1,Promise:Promise,overload:!1},{filter:m,Promise:d})).Promise,(function(t,r,s){function o(){var s=i.filter;if(!s||s.apply(n,arguments))if(n.off(e,o),i.handleError){var l=arguments[0];l?r(l):t(u.apply(null,arguments).slice(1))}else t(u.apply(null,arguments))}s((function(){n.off(e,o)})),n._on(e,o,!1)}),{timeout:i.timeout,overload:i.overload})};var O=A.prototype;Object.defineProperties(A,{defaultMaxListeners:{get:function(){return O._maxListeners},set:function(e){if("number"!=typeof e||e<0||Number.isNaN(e))throw TypeError("n must be a non-negative number");O._maxListeners=e},enumerable:!0},once:{value:function(e,t,i){return g((i=y(i,{Promise:Promise,timeout:0,overload:!1},{Promise:d})).Promise,(function(i,n,r){var s;if("function"==typeof e.addEventListener)return s=function(){i(u.apply(null,arguments))},r((function(){e.removeEventListener(t,s)})),void e.addEventListener(t,s,{once:!0});var o,l=function(){o&&e.removeListener("error",o),i(u.apply(null,arguments))};"error"!==t&&(o=function(i){e.removeListener(t,l),n(i)},e.once("error",o)),r((function(){o&&e.removeListener("error",o),e.removeListener(t,l)})),e.once(t,l)}),{timeout:i.timeout,overload:i.overload})},writable:!0,configurable:!0}}),Object.defineProperties(O,{_maxListeners:{value:10,writable:!0,configurable:!0},_observers:{value:null,writable:!0,configurable:!0}}),e.exports=A}();var i=t.exports;global?(global.salla=global.salla||global.Salla||{},global.Salla=global.salla):(window.salla=window.salla||window.Salla||{},window.Salla=window.salla),Salla.event=new class extends i{constructor(){super({wildcard:!0,delimiter:"::",newListener:!1,removeListener:!1,maxListeners:10,verboseMemoryLeak:!1,ignoreErrors:!1}),this.globalListners={},this.delimiter="::",this.body=document.querySelector("body"),this.logableEvents=["cart::item.added.failed","cart::item.deleted.failed"],this.ingoreLogEvents=["document::click","document::keyup","document::change"],this.noneFireableActions=["document.request"],this.on("twilight::initiated",this.initiateSallaInAllClasses)}initiateSallaInAllClasses(){let e=this;Object.keys(salla).forEach((t=>{"object"==typeof(t=salla[t])&&(e.callSallaInitiate(t),Object.keys(t).forEach((i=>{e.callSallaInitiate(t[i])})))}))}callSallaInitiate(e){e&&e.sallaInitiated&&!e.initiated&&(e.sallaInitiated(),e.initiated=!0)}createAndDispatch(e,...t){this.dispatch(e,...t)}dispatch(e,...t){let i=e.replace("::",".");if(!this.noneFireableActions.includes(i)&&void 0!==salla.call&&"function"==typeof salla.call(i))return salla.log(`'salla.${i}(...)' triggered using event '${e}'`),i=i.split("."),void salla[i[0]][i[1]](...t);this.emit(e,...t),"undefined"!=typeof window&&(window.dataLayer=window.dataLayer||[],window.dataLayer.push(Object.assign({event:e},...t.values()))),this.ingoreLogEvents.includes(e)||!salla.config.get("debug")&&!this.logableEvents.includes(e)||void 0===salla.logger||salla.logger.event(e,...t);let n=this;Object.keys(this.globalListners).forEach((function(i){n.globalListners[i](e,...t)})),this.dispatchMobileEvent(e,{...t.values()})}dispatchEvents(e){if(e&&"object"==typeof e)for(const[t,i]of Object.entries(e))this.dispatch(t,i);else salla.log("No Events To Dispatch!",e)}addListener(e,t){this.on(e,t)}addEventListener(e,t){this.addListener(e,t)}listen(e,t){this.addListener(e,t)}registerGlobalListener(e,t){this.globalListners[e]=t}dispatchMobileEvent(e,t={}){if(!(window.dataLayer&&dataLayer[0]&&dataLayer[0].page&&dataLayer[0].page.mobileApp))return"";if(window.webkit)try{window.webkit.messageHandlers.callbackHandler.postMessage(JSON.stringify({event:e,details:t}))}catch(e){salla.log(e,"The native context does not exist yet")}else if(Android)try{Android.customEventWithData(e,JSON.stringify({details:t}))}catch(e){salla.log(e,"The native context does not exist yet")}}}})); | ||
*/e=t,function(t){var i=Object.hasOwnProperty,n=Array.isArray?Array.isArray:function(e){return"[object Array]"===Object.prototype.toString.call(e)},r="object"==typeof process&&"function"==typeof process.nextTick,s="function"==typeof Symbol,o="object"==typeof Reflect,l="function"==typeof setImmediate?setImmediate:setTimeout,a=s?o&&"function"==typeof Reflect.ownKeys?Reflect.ownKeys:function(e){var t=Object.getOwnPropertyNames(e);return t.push.apply(t,Object.getOwnPropertySymbols(e)),t}:Object.keys;function c(){this._events={},this._conf&&h.call(this,this._conf)}function h(e){e&&(this._conf=e,e.delimiter&&(this.delimiter=e.delimiter),e.maxListeners!==t&&(this._maxListeners=e.maxListeners),e.wildcard&&(this.wildcard=e.wildcard),e.newListener&&(this._newListener=e.newListener),e.removeListener&&(this._removeListener=e.removeListener),e.verboseMemoryLeak&&(this.verboseMemoryLeak=e.verboseMemoryLeak),e.ignoreErrors&&(this.ignoreErrors=e.ignoreErrors),this.wildcard&&(this.listenerTree={}))}function f(e,t){var i="(node) warning: possible EventEmitter memory leak detected. "+e+" listeners added. Use emitter.setMaxListeners() to increase limit.";if(this.verboseMemoryLeak&&(i+=" Event name: "+t+"."),"undefined"!=typeof process&&process.emitWarning){var n=new Error(i);n.name="MaxListenersExceededWarning",n.emitter=this,n.count=e,process.emitWarning(n)}else console.error(i),console.trace&&console.trace()}var u=function(e,t,i){var n=arguments.length;switch(n){case 0:return[];case 1:return[e];case 2:return[e,t];case 3:return[e,t,i];default:for(var r=new Array(n);n--;)r[n]=arguments[n];return r}};function p(e,i){for(var n={},r=e.length,s=i?i.length:0,o=0;o<r;o++)n[e[o]]=o<s?i[o]:t;return n}function v(e,t,i){var n,r;if(this._emitter=e,this._target=t,this._listeners={},this._listenersCount=0,(i.on||i.off)&&(n=i.on,r=i.off),t.addEventListener?(n=t.addEventListener,r=t.removeEventListener):t.addListener?(n=t.addListener,r=t.removeListener):t.on&&(n=t.on,r=t.off),!n&&!r)throw Error("target does not implement any known event API");if("function"!=typeof n)throw TypeError("on method must be a function");if("function"!=typeof r)throw TypeError("off method must be a function");this._on=n,this._off=r;var s=e._observers;s?s.push(this):e._observers=[this]}function d(e,n,r,s){var o=Object.assign({},n);if(!e)return o;if("object"!=typeof e)throw TypeError("options must be an object");var l,a,c,h=Object.keys(e),f=h.length;function u(e){throw Error('Invalid "'+l+'" option value'+(e?". Reason: "+e:""))}for(var p=0;p<f;p++){if(l=h[p],!s&&!i.call(n,l))throw Error('Unknown "'+l+'" option');(a=e[l])!==t&&(c=r[l],o[l]=c?c(a,u):a)}return o}function y(e,t){return"function"==typeof e&&e.hasOwnProperty("prototype")||t("value must be a constructor"),e}function _(e){var t="value must be type of "+e.join("|"),i=e.length,n=e[0],r=e[1];return 1===i?function(e,i){if(typeof e===n)return e;i(t)}:2===i?function(e,i){var s=typeof e;if(s===n||s===r)return e;i(t)}:function(n,r){for(var s=typeof n,o=i;o-- >0;)if(s===e[o])return n;r(t)}}Object.assign(v.prototype,{subscribe:function(e,t,i){var n=this,r=this._target,s=this._emitter,o=this._listeners,l=function(){var n=u.apply(null,arguments),o={data:n,name:t,original:e};if(i){var l=i.call(r,o);!1!==l&&s.emit.apply(s,[o.name].concat(n))}else s.emit.apply(s,[t].concat(n))};if(o[e])throw Error("Event '"+e+"' is already listening");this._listenersCount++,s._newListener&&s._removeListener&&!n._onNewListener?(this._onNewListener=function(i){i===t&&null===o[e]&&(o[e]=l,n._on.call(r,e,l))},s.on("newListener",this._onNewListener),this._onRemoveListener=function(i){i===t&&!s.hasListeners(i)&&o[e]&&(o[e]=null,n._off.call(r,e,l))},o[e]=null,s.on("removeListener",this._onRemoveListener)):(o[e]=l,n._on.call(r,e,l))},unsubscribe:function(e){var t,i,n,r=this,s=this._listeners,o=this._emitter,l=this._off,c=this._target;if(e&&"string"!=typeof e)throw TypeError("event must be a string");function h(){r._onNewListener&&(o.off("newListener",r._onNewListener),o.off("removeListener",r._onRemoveListener),r._onNewListener=null,r._onRemoveListener=null);var e=g.call(o,r);o._observers.splice(e,1)}if(e){if(!(t=s[e]))return;l.call(c,e,t),delete s[e],--this._listenersCount||h()}else{for(n=(i=a(s)).length;n-- >0;)e=i[n],l.call(c,e,s[e]);this._listeners={},this._listenersCount=0,h()}}});var m=_(["function"]),b=_(["object","function"]);function w(e,t,i){var n,r,s,o=0,l=new e((function(a,c,h){function f(){r&&(r=null),o&&(clearTimeout(o),o=0)}i=d(i,{timeout:0,overload:!1},{timeout:function(e,t){return("number"!=typeof(e*=1)||e<0||!Number.isFinite(e))&&t("timeout must be a positive number"),e}}),n=!i.overload&&"function"==typeof e.prototype.cancel&&"function"==typeof h;var u=function(e){f(),a(e)},p=function(e){f(),c(e)};n?t(u,p,h):(r=[function(e){p(e||Error("canceled"))}],t(u,p,(function(e){if(s)throw Error("Unable to subscribe on cancel event asynchronously");if("function"!=typeof e)throw TypeError("onCancel callback must be a function");r.push(e)})),s=!0),i.timeout>0&&(o=setTimeout((function(){var e=Error("timeout");e.code="ETIMEDOUT",o=0,l.cancel(e),c(e)}),i.timeout))}));return n||(l.cancel=function(e){if(r){for(var t=r.length,i=1;i<t;i++)r[i](e);r[0](e),r=null}}),l}function g(e){var t=this._observers;if(!t)return-1;for(var i=t.length,n=0;n<i;n++)if(t[n]._target===e)return n;return-1}function L(e,t,i,n,r){if(!i)return null;if(0===n){var s=typeof t;if("string"===s){var o,l,c=0,h=0,f=this.delimiter,u=f.length;if(-1!==(l=t.indexOf(f))){o=new Array(5);do{o[c++]=t.slice(h,l),h=l+u}while(-1!==(l=t.indexOf(f,h)));o[c++]=t.slice(h),t=o,r=c}else t=[t],r=1}else"object"===s?r=t.length:(t=[t],r=1)}var p,v,d,y,_,m,b,w=null,g=t[n],E=t[n+1];if(n===r)i._listeners&&("function"==typeof i._listeners?(e&&e.push(i._listeners),w=[i]):(e&&e.push.apply(e,i._listeners),w=[i]));else{if("*"===g){for(l=(m=a(i)).length;l-- >0;)"_listeners"!==(p=m[l])&&(b=L(e,t,i[p],n+1,r))&&(w?w.push.apply(w,b):w=b);return w}if("**"===g){for((_=n+1===r||n+2===r&&"*"===E)&&i._listeners&&(w=L(e,t,i,r,r)),l=(m=a(i)).length;l-- >0;)"_listeners"!==(p=m[l])&&("*"===p||"**"===p?(i[p]._listeners&&!_&&(b=L(e,t,i[p],r,r))&&(w?w.push.apply(w,b):w=b),b=L(e,t,i[p],n,r)):b=L(e,t,i[p],p===E?n+2:n,r),b&&(w?w.push.apply(w,b):w=b));return w}i[g]&&(w=L(e,t,i[g],n+1,r))}if((v=i["*"])&&L(e,t,v,n+1,r),d=i["**"])if(n<r)for(d._listeners&&L(e,t,d,r,r),l=(m=a(d)).length;l-- >0;)"_listeners"!==(p=m[l])&&(p===E?L(e,t,d[p],n+2,r):p===g?L(e,t,d[p],n+1,r):((y={})[p]=d[p],L(e,t,{"**":y},n+1,r)));else d._listeners?L(e,t,d,r,r):d["*"]&&d["*"]._listeners&&L(e,t,d["*"],r,r);return w}function E(e,t,i){var n,r,s=0,o=0,l=this.delimiter,a=l.length;if("string"==typeof e)if(-1!==(n=e.indexOf(l))){r=new Array(5);do{r[s++]=e.slice(o,n),o=n+a}while(-1!==(n=e.indexOf(l,o)));r[s++]=e.slice(o)}else r=[e],s=1;else r=e,s=e.length;if(s>1)for(n=0;n+1<s;n++)if("**"===r[n]&&"**"===r[n+1])return;var c,h=this.listenerTree;for(n=0;n<s;n++)if(h=h[c=r[n]]||(h[c]={}),n===s-1)return h._listeners?("function"==typeof h._listeners&&(h._listeners=[h._listeners]),i?h._listeners.unshift(t):h._listeners.push(t),!h._listeners.warned&&this._maxListeners>0&&h._listeners.length>this._maxListeners&&(h._listeners.warned=!0,f.call(this,h._listeners.length,c))):h._listeners=t,!0;return!0}function k(e,t,i,n){for(var r,s,o,l,c=a(e),h=c.length,f=e._listeners;h-- >0;)r=e[s=c[h]],o="_listeners"===s?i:i?i.concat(s):[s],l=n||"symbol"==typeof s,f&&t.push(l?o:o.join(this.delimiter)),"object"==typeof r&&k.call(this,r,t,o,l);return t}function j(e){for(var t,i,n,r=a(e),s=r.length;s-- >0;)(t=e[i=r[s]])&&(n=!0,"_listeners"===i||j(t)||delete e[i]);return n}function T(e,t,i){this.emitter=e,this.event=t,this.listener=i}function x(e,i,n){if(!0===n)o=!0;else if(!1===n)s=!0;else{if(!n||"object"!=typeof n)throw TypeError("options should be an object or true");var s=n.async,o=n.promisify,a=n.nextTick,c=n.objectify}if(s||a||o){var h=i,f=i._origin||i;if(a&&!r)throw Error("process.nextTick is not supported");o===t&&(o="AsyncFunction"===i.constructor.name),i=function(){var e=arguments,t=this,i=this.event;return o?a?Promise.resolve():new Promise((function(e){l(e)})).then((function(){return t.event=i,h.apply(t,e)})):(a?process.nextTick:l)((function(){t.event=i,h.apply(t,e)}))},i._async=!0,i._origin=f}return[i,c?new T(this,e,i):this]}function A(e){this._events={},this._newListener=!1,this._removeListener=!1,this.verboseMemoryLeak=!1,h.call(this,e)}T.prototype.off=function(){return this.emitter.off(this.event,this.listener),this},A.EventEmitter2=A,A.prototype.listenTo=function(e,i,r){if("object"!=typeof e)throw TypeError("target musts be an object");var s=this;function o(t){if("object"!=typeof t)throw TypeError("events must be an object");var i,n=r.reducers,o=g.call(s,e);i=-1===o?new v(s,e,r):s._observers[o];for(var l,c=a(t),h=c.length,f="function"==typeof n,u=0;u<h;u++)l=c[u],i.subscribe(l,t[l]||l,f?n:n&&n[l])}return r=d(r,{on:t,off:t,reducers:t},{on:m,off:m,reducers:b}),n(i)?o(p(i)):o("string"==typeof i?p(i.split(/\s+/)):i),this},A.prototype.stopListeningTo=function(e,t){var i=this._observers;if(!i)return!1;var n,r=i.length,s=!1;if(e&&"object"!=typeof e)throw TypeError("target should be an object");for(;r-- >0;)n=i[r],e&&n._target!==e||(n.unsubscribe(t),s=!0);return s},A.prototype.delimiter=".",A.prototype.setMaxListeners=function(e){e!==t&&(this._maxListeners=e,this._conf||(this._conf={}),this._conf.maxListeners=e)},A.prototype.getMaxListeners=function(){return this._maxListeners},A.prototype.event="",A.prototype.once=function(e,t,i){return this._once(e,t,!1,i)},A.prototype.prependOnceListener=function(e,t,i){return this._once(e,t,!0,i)},A.prototype._once=function(e,t,i,n){return this._many(e,1,t,i,n)},A.prototype.many=function(e,t,i,n){return this._many(e,t,i,!1,n)},A.prototype.prependMany=function(e,t,i,n){return this._many(e,t,i,!0,n)},A.prototype._many=function(e,t,i,n,r){var s=this;if("function"!=typeof i)throw new Error("many only accepts instances of Function");function o(){return 0==--t&&s.off(e,o),i.apply(this,arguments)}return o._origin=i,this._on(e,o,n,r)},A.prototype.emit=function(){if(!this._events&&!this._all)return!1;this._events||c.call(this);var e,t,i,n,r,o,l=arguments[0],a=this.wildcard;if("newListener"===l&&!this._newListener&&!this._events.newListener)return!1;if(a&&(e=l,"newListener"!==l&&"removeListener"!==l&&"object"==typeof l)){if(i=l.length,s)for(n=0;n<i;n++)if("symbol"==typeof l[n]){o=!0;break}o||(l=l.join(this.delimiter))}var h,f=arguments.length;if(this._all&&this._all.length)for(n=0,i=(h=this._all.slice()).length;n<i;n++)switch(this.event=l,f){case 1:h[n].call(this,l);break;case 2:h[n].call(this,l,arguments[1]);break;case 3:h[n].call(this,l,arguments[1],arguments[2]);break;default:h[n].apply(this,arguments)}if(a)h=[],L.call(this,h,e,this.listenerTree,0,i);else{if("function"==typeof(h=this._events[l])){switch(this.event=l,f){case 1:h.call(this);break;case 2:h.call(this,arguments[1]);break;case 3:h.call(this,arguments[1],arguments[2]);break;default:for(t=new Array(f-1),r=1;r<f;r++)t[r-1]=arguments[r];h.apply(this,t)}return!0}h&&(h=h.slice())}if(h&&h.length){if(f>3)for(t=new Array(f-1),r=1;r<f;r++)t[r-1]=arguments[r];for(n=0,i=h.length;n<i;n++)switch(this.event=l,f){case 1:h[n].call(this);break;case 2:h[n].call(this,arguments[1]);break;case 3:h[n].call(this,arguments[1],arguments[2]);break;default:h[n].apply(this,t)}return!0}if(!this.ignoreErrors&&!this._all&&"error"===l)throw arguments[1]instanceof Error?arguments[1]:new Error("Uncaught, unspecified 'error' event.");return!!this._all},A.prototype.emitAsync=function(){if(!this._events&&!this._all)return!1;this._events||c.call(this);var e,t,i,n,r,o,l=arguments[0],a=this.wildcard;if("newListener"===l&&!this._newListener&&!this._events.newListener)return Promise.resolve([!1]);if(a&&(e=l,"newListener"!==l&&"removeListener"!==l&&"object"==typeof l)){if(n=l.length,s)for(r=0;r<n;r++)if("symbol"==typeof l[r]){t=!0;break}t||(l=l.join(this.delimiter))}var h,f=[],u=arguments.length;if(this._all)for(r=0,n=this._all.length;r<n;r++)switch(this.event=l,u){case 1:f.push(this._all[r].call(this,l));break;case 2:f.push(this._all[r].call(this,l,arguments[1]));break;case 3:f.push(this._all[r].call(this,l,arguments[1],arguments[2]));break;default:f.push(this._all[r].apply(this,arguments))}if(a?(h=[],L.call(this,h,e,this.listenerTree,0)):h=this._events[l],"function"==typeof h)switch(this.event=l,u){case 1:f.push(h.call(this));break;case 2:f.push(h.call(this,arguments[1]));break;case 3:f.push(h.call(this,arguments[1],arguments[2]));break;default:for(i=new Array(u-1),o=1;o<u;o++)i[o-1]=arguments[o];f.push(h.apply(this,i))}else if(h&&h.length){if(h=h.slice(),u>3)for(i=new Array(u-1),o=1;o<u;o++)i[o-1]=arguments[o];for(r=0,n=h.length;r<n;r++)switch(this.event=l,u){case 1:f.push(h[r].call(this));break;case 2:f.push(h[r].call(this,arguments[1]));break;case 3:f.push(h[r].call(this,arguments[1],arguments[2]));break;default:f.push(h[r].apply(this,i))}}else if(!this.ignoreErrors&&!this._all&&"error"===l)return arguments[1]instanceof Error?Promise.reject(arguments[1]):Promise.reject("Uncaught, unspecified 'error' event.");return Promise.all(f)},A.prototype.on=function(e,t,i){return this._on(e,t,!1,i)},A.prototype.prependListener=function(e,t,i){return this._on(e,t,!0,i)},A.prototype.onAny=function(e){return this._onAny(e,!1)},A.prototype.prependAny=function(e){return this._onAny(e,!0)},A.prototype.addListener=A.prototype.on,A.prototype._onAny=function(e,t){if("function"!=typeof e)throw new Error("onAny only accepts instances of Function");return this._all||(this._all=[]),t?this._all.unshift(e):this._all.push(e),this},A.prototype._on=function(e,i,n,r){if("function"==typeof e)return this._onAny(e,i),this;if("function"!=typeof i)throw new Error("on only accepts instances of Function");this._events||c.call(this);var s,o=this;return r!==t&&(i=(s=x.call(this,e,i,r))[0],o=s[1]),this._newListener&&this.emit("newListener",e,i),this.wildcard?(E.call(this,e,i,n),o):(this._events[e]?("function"==typeof this._events[e]&&(this._events[e]=[this._events[e]]),n?this._events[e].unshift(i):this._events[e].push(i),!this._events[e].warned&&this._maxListeners>0&&this._events[e].length>this._maxListeners&&(this._events[e].warned=!0,f.call(this,this._events[e].length,e))):this._events[e]=i,o)},A.prototype.off=function(e,t){if("function"!=typeof t)throw new Error("removeListener only takes instances of Function");var i,r=[];if(this.wildcard){var s="string"==typeof e?e.split(this.delimiter):e.slice();if(!(r=L.call(this,null,s,this.listenerTree,0)))return this}else{if(!this._events[e])return this;i=this._events[e],r.push({_listeners:i})}for(var o=0;o<r.length;o++){var l=r[o];if(i=l._listeners,n(i)){for(var a=-1,c=0,h=i.length;c<h;c++)if(i[c]===t||i[c].listener&&i[c].listener===t||i[c]._origin&&i[c]._origin===t){a=c;break}if(a<0)continue;return this.wildcard?l._listeners.splice(a,1):this._events[e].splice(a,1),0===i.length&&(this.wildcard?delete l._listeners:delete this._events[e]),this._removeListener&&this.emit("removeListener",e,t),this}(i===t||i.listener&&i.listener===t||i._origin&&i._origin===t)&&(this.wildcard?delete l._listeners:delete this._events[e],this._removeListener&&this.emit("removeListener",e,t))}return this.listenerTree&&j(this.listenerTree),this},A.prototype.offAny=function(e){var t,i=0,n=0;if(e&&this._all&&this._all.length>0){for(i=0,n=(t=this._all).length;i<n;i++)if(e===t[i])return t.splice(i,1),this._removeListener&&this.emit("removeListenerAny",e),this}else{if(t=this._all,this._removeListener)for(i=0,n=t.length;i<n;i++)this.emit("removeListenerAny",t[i]);this._all=[]}return this},A.prototype.removeListener=A.prototype.off,A.prototype.removeAllListeners=function(e){if(e===t)return!this._events||c.call(this),this;if(this.wildcard){var i,n=L.call(this,null,e,this.listenerTree,0);if(!n)return this;for(i=0;i<n.length;i++)n[i]._listeners=null;this.listenerTree&&j(this.listenerTree)}else this._events&&(this._events[e]=null);return this},A.prototype.listeners=function(e){var i,n,r,s,o,l=this._events;if(e===t){if(this.wildcard)throw Error("event name required for wildcard emitter");if(!l)return[];for(s=(i=a(l)).length,r=[];s-- >0;)"function"==typeof(n=l[i[s]])?r.push(n):r.push.apply(r,n);return r}if(this.wildcard){if(!(o=this.listenerTree))return[];var c=[],h="string"==typeof e?e.split(this.delimiter):e.slice();return L.call(this,c,h,o,0),c}return l&&(n=l[e])?"function"==typeof n?[n]:n:[]},A.prototype.eventNames=function(e){var t=this._events;return this.wildcard?k.call(this,this.listenerTree,[],null,e):t?a(t):[]},A.prototype.listenerCount=function(e){return this.listeners(e).length},A.prototype.hasListeners=function(e){if(this.wildcard){var i=[],n="string"==typeof e?e.split(this.delimiter):e.slice();return L.call(this,i,n,this.listenerTree,0),i.length>0}var r=this._events,s=this._all;return!!(s&&s.length||r&&(e===t?a(r).length:r[e]))},A.prototype.listenersAny=function(){return this._all?this._all:[]},A.prototype.waitFor=function(e,i){var n=this,r=typeof i;return"number"===r?i={timeout:i}:"function"===r&&(i={filter:i}),w((i=d(i,{timeout:0,filter:t,handleError:!1,Promise:Promise,overload:!1},{filter:m,Promise:y})).Promise,(function(t,r,s){function o(){var s=i.filter;if(!s||s.apply(n,arguments))if(n.off(e,o),i.handleError){var l=arguments[0];l?r(l):t(u.apply(null,arguments).slice(1))}else t(u.apply(null,arguments))}s((function(){n.off(e,o)})),n._on(e,o,!1)}),{timeout:i.timeout,overload:i.overload})};var O=A.prototype;Object.defineProperties(A,{defaultMaxListeners:{get:function(){return O._maxListeners},set:function(e){if("number"!=typeof e||e<0||Number.isNaN(e))throw TypeError("n must be a non-negative number");O._maxListeners=e},enumerable:!0},once:{value:function(e,t,i){return w((i=d(i,{Promise:Promise,timeout:0,overload:!1},{Promise:y})).Promise,(function(i,n,r){var s;if("function"==typeof e.addEventListener)return s=function(){i(u.apply(null,arguments))},r((function(){e.removeEventListener(t,s)})),void e.addEventListener(t,s,{once:!0});var o,l=function(){o&&e.removeListener("error",o),i(u.apply(null,arguments))};"error"!==t&&(o=function(i){e.removeListener(t,l),n(i)},e.once("error",o)),r((function(){o&&e.removeListener("error",o),e.removeListener(t,l)})),e.once(t,l)}),{timeout:i.timeout,overload:i.overload})},writable:!0,configurable:!0}}),Object.defineProperties(O,{_maxListeners:{value:10,writable:!0,configurable:!0},_observers:{value:null,writable:!0,configurable:!0}}),e.exports=A}();var i=t.exports;global?(global.salla=global.salla||global.Salla||{},global.Salla=global.salla):(window.salla=window.salla||window.Salla||{},window.Salla=window.salla),Salla.event=new class extends i{constructor(){super({wildcard:!0,delimiter:"::",newListener:!1,removeListener:!1,maxListeners:10,verboseMemoryLeak:!1,ignoreErrors:!1}),this.globalListners={},this.delimiter="::",this.body=document.querySelector("body"),this.logableEvents=["cart::item.added.failed","cart::item.deleted.failed"],this.ingoreLogEvents=["document::click","document::keyup","document::change"],this.noneFireableActions=["document.request"],this.on("twilight::initiated",this.initiateSallaInAllClasses)}initiateSallaInAllClasses(){let e=this;Object.keys(salla).forEach((t=>{"object"==typeof(t=salla[t])&&(e.callSallaInitiate(t),Object.keys(t).forEach((i=>{e.callSallaInitiate(t[i])})))}))}callSallaInitiate(e){e&&e.sallaInitiated&&!e.initiated&&(e.sallaInitiated(),e.initiated=!0)}createAndDispatch(e,...t){this.dispatch(e,...t)}dispatch(e,...t){let i=e.replace("::",".");if(!this.noneFireableActions.includes(i)&&void 0!==salla.call&&"function"==typeof salla.call(i))return salla.log(`'salla.${i}(...)' triggered using event '${e}'`),i=i.split("."),void salla[i[0]][i[1]](...t);this.emit(e,...t),"undefined"!=typeof window&&(window.dataLayer=window.dataLayer||[],window.dataLayer.push(Object.assign({event:e},...t.values()))),this.ingoreLogEvents.includes(e)||!salla.config.get("debug")&&!this.logableEvents.includes(e)||void 0===salla.logger||salla.logger.event(e,...t);let n=this;Object.keys(this.globalListners).forEach((function(i){n.globalListners[i](e,...t)})),this.dispatchMobileEvent(e,{...t.values()})}dispatchEvents(e){if(e&&"object"==typeof e)for(const[t,i]of Object.entries(e))this.dispatch(t,i);else salla.log("No Events To Dispatch!",e)}addListener(e,t){this.on(e,t)}addEventListener(e,t){this.addListener(e,t)}listen(e,t){this.addListener(e,t)}registerGlobalListener(e,t){this.globalListners[e]=t}dispatchMobileEvent(e,t={}){if(!("undefined"!=typeof window&&window.dataLayer&&dataLayer[0]&&dataLayer[0].page&&dataLayer[0].page.mobileApp))return"";if(window.webkit)try{window.webkit.messageHandlers.callbackHandler.postMessage(JSON.stringify({event:e,details:t}))}catch(e){salla.log(e,"The native context does not exist yet")}else if(Android)try{Android.customEventWithData(e,JSON.stringify({details:t}))}catch(e){salla.log(e,"The native context does not exist yet")}}}})); | ||
//# sourceMappingURL=event.min.js.map |
@@ -8,3 +8,3 @@ "use strict";var e,t={exports:{}}; | ||
* Licensed under the MIT license. | ||
*/e=t,function(t){var i=Object.hasOwnProperty,n=Array.isArray?Array.isArray:function(e){return"[object Array]"===Object.prototype.toString.call(e)},r="object"==typeof process&&"function"==typeof process.nextTick,s="function"==typeof Symbol,o="object"==typeof Reflect,l="function"==typeof setImmediate?setImmediate:setTimeout,a=s?o&&"function"==typeof Reflect.ownKeys?Reflect.ownKeys:function(e){var t=Object.getOwnPropertyNames(e);return t.push.apply(t,Object.getOwnPropertySymbols(e)),t}:Object.keys;function c(){this._events={},this._conf&&h.call(this,this._conf)}function h(e){e&&(this._conf=e,e.delimiter&&(this.delimiter=e.delimiter),e.maxListeners!==t&&(this._maxListeners=e.maxListeners),e.wildcard&&(this.wildcard=e.wildcard),e.newListener&&(this._newListener=e.newListener),e.removeListener&&(this._removeListener=e.removeListener),e.verboseMemoryLeak&&(this.verboseMemoryLeak=e.verboseMemoryLeak),e.ignoreErrors&&(this.ignoreErrors=e.ignoreErrors),this.wildcard&&(this.listenerTree={}))}function f(e,t){var i="(node) warning: possible EventEmitter memory leak detected. "+e+" listeners added. Use emitter.setMaxListeners() to increase limit.";if(this.verboseMemoryLeak&&(i+=" Event name: "+t+"."),"undefined"!=typeof process&&process.emitWarning){var n=new Error(i);n.name="MaxListenersExceededWarning",n.emitter=this,n.count=e,process.emitWarning(n)}else console.error(i),console.trace&&console.trace()}var u=function(e,t,i){var n=arguments.length;switch(n){case 0:return[];case 1:return[e];case 2:return[e,t];case 3:return[e,t,i];default:for(var r=new Array(n);n--;)r[n]=arguments[n];return r}};function p(e,i){for(var n={},r=e.length,s=i?i.length:0,o=0;o<r;o++)n[e[o]]=o<s?i[o]:t;return n}function v(e,t,i){var n,r;if(this._emitter=e,this._target=t,this._listeners={},this._listenersCount=0,(i.on||i.off)&&(n=i.on,r=i.off),t.addEventListener?(n=t.addEventListener,r=t.removeEventListener):t.addListener?(n=t.addListener,r=t.removeListener):t.on&&(n=t.on,r=t.off),!n&&!r)throw Error("target does not implement any known event API");if("function"!=typeof n)throw TypeError("on method must be a function");if("function"!=typeof r)throw TypeError("off method must be a function");this._on=n,this._off=r;var s=e._observers;s?s.push(this):e._observers=[this]}function y(e,n,r,s){var o=Object.assign({},n);if(!e)return o;if("object"!=typeof e)throw TypeError("options must be an object");var l,a,c,h=Object.keys(e),f=h.length;function u(e){throw Error('Invalid "'+l+'" option value'+(e?". Reason: "+e:""))}for(var p=0;p<f;p++){if(l=h[p],!s&&!i.call(n,l))throw Error('Unknown "'+l+'" option');(a=e[l])!==t&&(c=r[l],o[l]=c?c(a,u):a)}return o}function d(e,t){return"function"==typeof e&&e.hasOwnProperty("prototype")||t("value must be a constructor"),e}function _(e){var t="value must be type of "+e.join("|"),i=e.length,n=e[0],r=e[1];return 1===i?function(e,i){if(typeof e===n)return e;i(t)}:2===i?function(e,i){var s=typeof e;if(s===n||s===r)return e;i(t)}:function(n,r){for(var s=typeof n,o=i;o-- >0;)if(s===e[o])return n;r(t)}}Object.assign(v.prototype,{subscribe:function(e,t,i){var n=this,r=this._target,s=this._emitter,o=this._listeners,l=function(){var n=u.apply(null,arguments),o={data:n,name:t,original:e};if(i){var l=i.call(r,o);!1!==l&&s.emit.apply(s,[o.name].concat(n))}else s.emit.apply(s,[t].concat(n))};if(o[e])throw Error("Event '"+e+"' is already listening");this._listenersCount++,s._newListener&&s._removeListener&&!n._onNewListener?(this._onNewListener=function(i){i===t&&null===o[e]&&(o[e]=l,n._on.call(r,e,l))},s.on("newListener",this._onNewListener),this._onRemoveListener=function(i){i===t&&!s.hasListeners(i)&&o[e]&&(o[e]=null,n._off.call(r,e,l))},o[e]=null,s.on("removeListener",this._onRemoveListener)):(o[e]=l,n._on.call(r,e,l))},unsubscribe:function(e){var t,i,n,r=this,s=this._listeners,o=this._emitter,l=this._off,c=this._target;if(e&&"string"!=typeof e)throw TypeError("event must be a string");function h(){r._onNewListener&&(o.off("newListener",r._onNewListener),o.off("removeListener",r._onRemoveListener),r._onNewListener=null,r._onRemoveListener=null);var e=w.call(o,r);o._observers.splice(e,1)}if(e){if(!(t=s[e]))return;l.call(c,e,t),delete s[e],--this._listenersCount||h()}else{for(n=(i=a(s)).length;n-- >0;)e=i[n],l.call(c,e,s[e]);this._listeners={},this._listenersCount=0,h()}}});var m=_(["function"]),b=_(["object","function"]);function g(e,t,i){var n,r,s,o=0,l=new e((function(a,c,h){function f(){r&&(r=null),o&&(clearTimeout(o),o=0)}i=y(i,{timeout:0,overload:!1},{timeout:function(e,t){return("number"!=typeof(e*=1)||e<0||!Number.isFinite(e))&&t("timeout must be a positive number"),e}}),n=!i.overload&&"function"==typeof e.prototype.cancel&&"function"==typeof h;var u=function(e){f(),a(e)},p=function(e){f(),c(e)};n?t(u,p,h):(r=[function(e){p(e||Error("canceled"))}],t(u,p,(function(e){if(s)throw Error("Unable to subscribe on cancel event asynchronously");if("function"!=typeof e)throw TypeError("onCancel callback must be a function");r.push(e)})),s=!0),i.timeout>0&&(o=setTimeout((function(){var e=Error("timeout");e.code="ETIMEDOUT",o=0,l.cancel(e),c(e)}),i.timeout))}));return n||(l.cancel=function(e){if(r){for(var t=r.length,i=1;i<t;i++)r[i](e);r[0](e),r=null}}),l}function w(e){var t=this._observers;if(!t)return-1;for(var i=t.length,n=0;n<i;n++)if(t[n]._target===e)return n;return-1}function L(e,t,i,n,r){if(!i)return null;if(0===n){var s=typeof t;if("string"===s){var o,l,c=0,h=0,f=this.delimiter,u=f.length;if(-1!==(l=t.indexOf(f))){o=new Array(5);do{o[c++]=t.slice(h,l),h=l+u}while(-1!==(l=t.indexOf(f,h)));o[c++]=t.slice(h),t=o,r=c}else t=[t],r=1}else"object"===s?r=t.length:(t=[t],r=1)}var p,v,y,d,_,m,b,g=null,w=t[n],E=t[n+1];if(n===r)i._listeners&&("function"==typeof i._listeners?(e&&e.push(i._listeners),g=[i]):(e&&e.push.apply(e,i._listeners),g=[i]));else{if("*"===w){for(l=(m=a(i)).length;l-- >0;)"_listeners"!==(p=m[l])&&(b=L(e,t,i[p],n+1,r))&&(g?g.push.apply(g,b):g=b);return g}if("**"===w){for((_=n+1===r||n+2===r&&"*"===E)&&i._listeners&&(g=L(e,t,i,r,r)),l=(m=a(i)).length;l-- >0;)"_listeners"!==(p=m[l])&&("*"===p||"**"===p?(i[p]._listeners&&!_&&(b=L(e,t,i[p],r,r))&&(g?g.push.apply(g,b):g=b),b=L(e,t,i[p],n,r)):b=L(e,t,i[p],p===E?n+2:n,r),b&&(g?g.push.apply(g,b):g=b));return g}i[w]&&(g=L(e,t,i[w],n+1,r))}if((v=i["*"])&&L(e,t,v,n+1,r),y=i["**"])if(n<r)for(y._listeners&&L(e,t,y,r,r),l=(m=a(y)).length;l-- >0;)"_listeners"!==(p=m[l])&&(p===E?L(e,t,y[p],n+2,r):p===w?L(e,t,y[p],n+1,r):((d={})[p]=y[p],L(e,t,{"**":d},n+1,r)));else y._listeners?L(e,t,y,r,r):y["*"]&&y["*"]._listeners&&L(e,t,y["*"],r,r);return g}function E(e,t,i){var n,r,s=0,o=0,l=this.delimiter,a=l.length;if("string"==typeof e)if(-1!==(n=e.indexOf(l))){r=new Array(5);do{r[s++]=e.slice(o,n),o=n+a}while(-1!==(n=e.indexOf(l,o)));r[s++]=e.slice(o)}else r=[e],s=1;else r=e,s=e.length;if(s>1)for(n=0;n+1<s;n++)if("**"===r[n]&&"**"===r[n+1])return;var c,h=this.listenerTree;for(n=0;n<s;n++)if(h=h[c=r[n]]||(h[c]={}),n===s-1)return h._listeners?("function"==typeof h._listeners&&(h._listeners=[h._listeners]),i?h._listeners.unshift(t):h._listeners.push(t),!h._listeners.warned&&this._maxListeners>0&&h._listeners.length>this._maxListeners&&(h._listeners.warned=!0,f.call(this,h._listeners.length,c))):h._listeners=t,!0;return!0}function k(e,t,i,n){for(var r,s,o,l,c=a(e),h=c.length,f=e._listeners;h-- >0;)r=e[s=c[h]],o="_listeners"===s?i:i?i.concat(s):[s],l=n||"symbol"==typeof s,f&&t.push(l?o:o.join(this.delimiter)),"object"==typeof r&&k.call(this,r,t,o,l);return t}function j(e){for(var t,i,n,r=a(e),s=r.length;s-- >0;)(t=e[i=r[s]])&&(n=!0,"_listeners"===i||j(t)||delete e[i]);return n}function T(e,t,i){this.emitter=e,this.event=t,this.listener=i}function x(e,i,n){if(!0===n)o=!0;else if(!1===n)s=!0;else{if(!n||"object"!=typeof n)throw TypeError("options should be an object or true");var s=n.async,o=n.promisify,a=n.nextTick,c=n.objectify}if(s||a||o){var h=i,f=i._origin||i;if(a&&!r)throw Error("process.nextTick is not supported");o===t&&(o="AsyncFunction"===i.constructor.name),i=function(){var e=arguments,t=this,i=this.event;return o?a?Promise.resolve():new Promise((function(e){l(e)})).then((function(){return t.event=i,h.apply(t,e)})):(a?process.nextTick:l)((function(){t.event=i,h.apply(t,e)}))},i._async=!0,i._origin=f}return[i,c?new T(this,e,i):this]}function A(e){this._events={},this._newListener=!1,this._removeListener=!1,this.verboseMemoryLeak=!1,h.call(this,e)}T.prototype.off=function(){return this.emitter.off(this.event,this.listener),this},A.EventEmitter2=A,A.prototype.listenTo=function(e,i,r){if("object"!=typeof e)throw TypeError("target musts be an object");var s=this;function o(t){if("object"!=typeof t)throw TypeError("events must be an object");var i,n=r.reducers,o=w.call(s,e);i=-1===o?new v(s,e,r):s._observers[o];for(var l,c=a(t),h=c.length,f="function"==typeof n,u=0;u<h;u++)l=c[u],i.subscribe(l,t[l]||l,f?n:n&&n[l])}return r=y(r,{on:t,off:t,reducers:t},{on:m,off:m,reducers:b}),n(i)?o(p(i)):o("string"==typeof i?p(i.split(/\s+/)):i),this},A.prototype.stopListeningTo=function(e,t){var i=this._observers;if(!i)return!1;var n,r=i.length,s=!1;if(e&&"object"!=typeof e)throw TypeError("target should be an object");for(;r-- >0;)n=i[r],e&&n._target!==e||(n.unsubscribe(t),s=!0);return s},A.prototype.delimiter=".",A.prototype.setMaxListeners=function(e){e!==t&&(this._maxListeners=e,this._conf||(this._conf={}),this._conf.maxListeners=e)},A.prototype.getMaxListeners=function(){return this._maxListeners},A.prototype.event="",A.prototype.once=function(e,t,i){return this._once(e,t,!1,i)},A.prototype.prependOnceListener=function(e,t,i){return this._once(e,t,!0,i)},A.prototype._once=function(e,t,i,n){return this._many(e,1,t,i,n)},A.prototype.many=function(e,t,i,n){return this._many(e,t,i,!1,n)},A.prototype.prependMany=function(e,t,i,n){return this._many(e,t,i,!0,n)},A.prototype._many=function(e,t,i,n,r){var s=this;if("function"!=typeof i)throw new Error("many only accepts instances of Function");function o(){return 0==--t&&s.off(e,o),i.apply(this,arguments)}return o._origin=i,this._on(e,o,n,r)},A.prototype.emit=function(){if(!this._events&&!this._all)return!1;this._events||c.call(this);var e,t,i,n,r,o,l=arguments[0],a=this.wildcard;if("newListener"===l&&!this._newListener&&!this._events.newListener)return!1;if(a&&(e=l,"newListener"!==l&&"removeListener"!==l&&"object"==typeof l)){if(i=l.length,s)for(n=0;n<i;n++)if("symbol"==typeof l[n]){o=!0;break}o||(l=l.join(this.delimiter))}var h,f=arguments.length;if(this._all&&this._all.length)for(n=0,i=(h=this._all.slice()).length;n<i;n++)switch(this.event=l,f){case 1:h[n].call(this,l);break;case 2:h[n].call(this,l,arguments[1]);break;case 3:h[n].call(this,l,arguments[1],arguments[2]);break;default:h[n].apply(this,arguments)}if(a)h=[],L.call(this,h,e,this.listenerTree,0,i);else{if("function"==typeof(h=this._events[l])){switch(this.event=l,f){case 1:h.call(this);break;case 2:h.call(this,arguments[1]);break;case 3:h.call(this,arguments[1],arguments[2]);break;default:for(t=new Array(f-1),r=1;r<f;r++)t[r-1]=arguments[r];h.apply(this,t)}return!0}h&&(h=h.slice())}if(h&&h.length){if(f>3)for(t=new Array(f-1),r=1;r<f;r++)t[r-1]=arguments[r];for(n=0,i=h.length;n<i;n++)switch(this.event=l,f){case 1:h[n].call(this);break;case 2:h[n].call(this,arguments[1]);break;case 3:h[n].call(this,arguments[1],arguments[2]);break;default:h[n].apply(this,t)}return!0}if(!this.ignoreErrors&&!this._all&&"error"===l)throw arguments[1]instanceof Error?arguments[1]:new Error("Uncaught, unspecified 'error' event.");return!!this._all},A.prototype.emitAsync=function(){if(!this._events&&!this._all)return!1;this._events||c.call(this);var e,t,i,n,r,o,l=arguments[0],a=this.wildcard;if("newListener"===l&&!this._newListener&&!this._events.newListener)return Promise.resolve([!1]);if(a&&(e=l,"newListener"!==l&&"removeListener"!==l&&"object"==typeof l)){if(n=l.length,s)for(r=0;r<n;r++)if("symbol"==typeof l[r]){t=!0;break}t||(l=l.join(this.delimiter))}var h,f=[],u=arguments.length;if(this._all)for(r=0,n=this._all.length;r<n;r++)switch(this.event=l,u){case 1:f.push(this._all[r].call(this,l));break;case 2:f.push(this._all[r].call(this,l,arguments[1]));break;case 3:f.push(this._all[r].call(this,l,arguments[1],arguments[2]));break;default:f.push(this._all[r].apply(this,arguments))}if(a?(h=[],L.call(this,h,e,this.listenerTree,0)):h=this._events[l],"function"==typeof h)switch(this.event=l,u){case 1:f.push(h.call(this));break;case 2:f.push(h.call(this,arguments[1]));break;case 3:f.push(h.call(this,arguments[1],arguments[2]));break;default:for(i=new Array(u-1),o=1;o<u;o++)i[o-1]=arguments[o];f.push(h.apply(this,i))}else if(h&&h.length){if(h=h.slice(),u>3)for(i=new Array(u-1),o=1;o<u;o++)i[o-1]=arguments[o];for(r=0,n=h.length;r<n;r++)switch(this.event=l,u){case 1:f.push(h[r].call(this));break;case 2:f.push(h[r].call(this,arguments[1]));break;case 3:f.push(h[r].call(this,arguments[1],arguments[2]));break;default:f.push(h[r].apply(this,i))}}else if(!this.ignoreErrors&&!this._all&&"error"===l)return arguments[1]instanceof Error?Promise.reject(arguments[1]):Promise.reject("Uncaught, unspecified 'error' event.");return Promise.all(f)},A.prototype.on=function(e,t,i){return this._on(e,t,!1,i)},A.prototype.prependListener=function(e,t,i){return this._on(e,t,!0,i)},A.prototype.onAny=function(e){return this._onAny(e,!1)},A.prototype.prependAny=function(e){return this._onAny(e,!0)},A.prototype.addListener=A.prototype.on,A.prototype._onAny=function(e,t){if("function"!=typeof e)throw new Error("onAny only accepts instances of Function");return this._all||(this._all=[]),t?this._all.unshift(e):this._all.push(e),this},A.prototype._on=function(e,i,n,r){if("function"==typeof e)return this._onAny(e,i),this;if("function"!=typeof i)throw new Error("on only accepts instances of Function");this._events||c.call(this);var s,o=this;return r!==t&&(i=(s=x.call(this,e,i,r))[0],o=s[1]),this._newListener&&this.emit("newListener",e,i),this.wildcard?(E.call(this,e,i,n),o):(this._events[e]?("function"==typeof this._events[e]&&(this._events[e]=[this._events[e]]),n?this._events[e].unshift(i):this._events[e].push(i),!this._events[e].warned&&this._maxListeners>0&&this._events[e].length>this._maxListeners&&(this._events[e].warned=!0,f.call(this,this._events[e].length,e))):this._events[e]=i,o)},A.prototype.off=function(e,t){if("function"!=typeof t)throw new Error("removeListener only takes instances of Function");var i,r=[];if(this.wildcard){var s="string"==typeof e?e.split(this.delimiter):e.slice();if(!(r=L.call(this,null,s,this.listenerTree,0)))return this}else{if(!this._events[e])return this;i=this._events[e],r.push({_listeners:i})}for(var o=0;o<r.length;o++){var l=r[o];if(i=l._listeners,n(i)){for(var a=-1,c=0,h=i.length;c<h;c++)if(i[c]===t||i[c].listener&&i[c].listener===t||i[c]._origin&&i[c]._origin===t){a=c;break}if(a<0)continue;return this.wildcard?l._listeners.splice(a,1):this._events[e].splice(a,1),0===i.length&&(this.wildcard?delete l._listeners:delete this._events[e]),this._removeListener&&this.emit("removeListener",e,t),this}(i===t||i.listener&&i.listener===t||i._origin&&i._origin===t)&&(this.wildcard?delete l._listeners:delete this._events[e],this._removeListener&&this.emit("removeListener",e,t))}return this.listenerTree&&j(this.listenerTree),this},A.prototype.offAny=function(e){var t,i=0,n=0;if(e&&this._all&&this._all.length>0){for(i=0,n=(t=this._all).length;i<n;i++)if(e===t[i])return t.splice(i,1),this._removeListener&&this.emit("removeListenerAny",e),this}else{if(t=this._all,this._removeListener)for(i=0,n=t.length;i<n;i++)this.emit("removeListenerAny",t[i]);this._all=[]}return this},A.prototype.removeListener=A.prototype.off,A.prototype.removeAllListeners=function(e){if(e===t)return!this._events||c.call(this),this;if(this.wildcard){var i,n=L.call(this,null,e,this.listenerTree,0);if(!n)return this;for(i=0;i<n.length;i++)n[i]._listeners=null;this.listenerTree&&j(this.listenerTree)}else this._events&&(this._events[e]=null);return this},A.prototype.listeners=function(e){var i,n,r,s,o,l=this._events;if(e===t){if(this.wildcard)throw Error("event name required for wildcard emitter");if(!l)return[];for(s=(i=a(l)).length,r=[];s-- >0;)"function"==typeof(n=l[i[s]])?r.push(n):r.push.apply(r,n);return r}if(this.wildcard){if(!(o=this.listenerTree))return[];var c=[],h="string"==typeof e?e.split(this.delimiter):e.slice();return L.call(this,c,h,o,0),c}return l&&(n=l[e])?"function"==typeof n?[n]:n:[]},A.prototype.eventNames=function(e){var t=this._events;return this.wildcard?k.call(this,this.listenerTree,[],null,e):t?a(t):[]},A.prototype.listenerCount=function(e){return this.listeners(e).length},A.prototype.hasListeners=function(e){if(this.wildcard){var i=[],n="string"==typeof e?e.split(this.delimiter):e.slice();return L.call(this,i,n,this.listenerTree,0),i.length>0}var r=this._events,s=this._all;return!!(s&&s.length||r&&(e===t?a(r).length:r[e]))},A.prototype.listenersAny=function(){return this._all?this._all:[]},A.prototype.waitFor=function(e,i){var n=this,r=typeof i;return"number"===r?i={timeout:i}:"function"===r&&(i={filter:i}),g((i=y(i,{timeout:0,filter:t,handleError:!1,Promise:Promise,overload:!1},{filter:m,Promise:d})).Promise,(function(t,r,s){function o(){var s=i.filter;if(!s||s.apply(n,arguments))if(n.off(e,o),i.handleError){var l=arguments[0];l?r(l):t(u.apply(null,arguments).slice(1))}else t(u.apply(null,arguments))}s((function(){n.off(e,o)})),n._on(e,o,!1)}),{timeout:i.timeout,overload:i.overload})};var O=A.prototype;Object.defineProperties(A,{defaultMaxListeners:{get:function(){return O._maxListeners},set:function(e){if("number"!=typeof e||e<0||Number.isNaN(e))throw TypeError("n must be a non-negative number");O._maxListeners=e},enumerable:!0},once:{value:function(e,t,i){return g((i=y(i,{Promise:Promise,timeout:0,overload:!1},{Promise:d})).Promise,(function(i,n,r){var s;if("function"==typeof e.addEventListener)return s=function(){i(u.apply(null,arguments))},r((function(){e.removeEventListener(t,s)})),void e.addEventListener(t,s,{once:!0});var o,l=function(){o&&e.removeListener("error",o),i(u.apply(null,arguments))};"error"!==t&&(o=function(i){e.removeListener(t,l),n(i)},e.once("error",o)),r((function(){o&&e.removeListener("error",o),e.removeListener(t,l)})),e.once(t,l)}),{timeout:i.timeout,overload:i.overload})},writable:!0,configurable:!0}}),Object.defineProperties(O,{_maxListeners:{value:10,writable:!0,configurable:!0},_observers:{value:null,writable:!0,configurable:!0}}),e.exports=A}();var i=t.exports;global?(global.salla=global.salla||global.Salla||{},global.Salla=global.salla):(window.salla=window.salla||window.Salla||{},window.Salla=window.salla),Salla.event=new class extends i{constructor(){super({wildcard:!0,delimiter:"::",newListener:!1,removeListener:!1,maxListeners:10,verboseMemoryLeak:!1,ignoreErrors:!1}),this.globalListners={},this.delimiter="::",this.body=document.querySelector("body"),this.logableEvents=["cart::item.added.failed","cart::item.deleted.failed"],this.ingoreLogEvents=["document::click","document::keyup","document::change"],this.noneFireableActions=["document.request"],this.on("twilight::initiated",this.initiateSallaInAllClasses)}initiateSallaInAllClasses(){let e=this;Object.keys(salla).forEach((t=>{"object"==typeof(t=salla[t])&&(e.callSallaInitiate(t),Object.keys(t).forEach((i=>{e.callSallaInitiate(t[i])})))}))}callSallaInitiate(e){e&&e.sallaInitiated&&!e.initiated&&(e.sallaInitiated(),e.initiated=!0)}createAndDispatch(e,...t){this.dispatch(e,...t)}dispatch(e,...t){let i=e.replace("::",".");if(!this.noneFireableActions.includes(i)&&void 0!==salla.call&&"function"==typeof salla.call(i))return salla.log(`'salla.${i}(...)' triggered using event '${e}'`),i=i.split("."),void salla[i[0]][i[1]](...t);this.emit(e,...t),"undefined"!=typeof window&&(window.dataLayer=window.dataLayer||[],window.dataLayer.push(Object.assign({event:e},...t.values()))),this.ingoreLogEvents.includes(e)||!salla.config.get("debug")&&!this.logableEvents.includes(e)||void 0===salla.logger||salla.logger.event(e,...t);let n=this;Object.keys(this.globalListners).forEach((function(i){n.globalListners[i](e,...t)})),this.dispatchMobileEvent(e,{...t.values()})}dispatchEvents(e){if(e&&"object"==typeof e)for(const[t,i]of Object.entries(e))this.dispatch(t,i);else salla.log("No Events To Dispatch!",e)}addListener(e,t){this.on(e,t)}addEventListener(e,t){this.addListener(e,t)}listen(e,t){this.addListener(e,t)}registerGlobalListener(e,t){this.globalListners[e]=t}dispatchMobileEvent(e,t={}){if(!(window.dataLayer&&dataLayer[0]&&dataLayer[0].page&&dataLayer[0].page.mobileApp))return"";if(window.webkit)try{window.webkit.messageHandlers.callbackHandler.postMessage(JSON.stringify({event:e,details:t}))}catch(e){salla.log(e,"The native context does not exist yet")}else if(Android)try{Android.customEventWithData(e,JSON.stringify({details:t}))}catch(e){salla.log(e,"The native context does not exist yet")}}}; | ||
*/e=t,function(t){var i=Object.hasOwnProperty,n=Array.isArray?Array.isArray:function(e){return"[object Array]"===Object.prototype.toString.call(e)},r="object"==typeof process&&"function"==typeof process.nextTick,s="function"==typeof Symbol,o="object"==typeof Reflect,l="function"==typeof setImmediate?setImmediate:setTimeout,a=s?o&&"function"==typeof Reflect.ownKeys?Reflect.ownKeys:function(e){var t=Object.getOwnPropertyNames(e);return t.push.apply(t,Object.getOwnPropertySymbols(e)),t}:Object.keys;function c(){this._events={},this._conf&&h.call(this,this._conf)}function h(e){e&&(this._conf=e,e.delimiter&&(this.delimiter=e.delimiter),e.maxListeners!==t&&(this._maxListeners=e.maxListeners),e.wildcard&&(this.wildcard=e.wildcard),e.newListener&&(this._newListener=e.newListener),e.removeListener&&(this._removeListener=e.removeListener),e.verboseMemoryLeak&&(this.verboseMemoryLeak=e.verboseMemoryLeak),e.ignoreErrors&&(this.ignoreErrors=e.ignoreErrors),this.wildcard&&(this.listenerTree={}))}function f(e,t){var i="(node) warning: possible EventEmitter memory leak detected. "+e+" listeners added. Use emitter.setMaxListeners() to increase limit.";if(this.verboseMemoryLeak&&(i+=" Event name: "+t+"."),"undefined"!=typeof process&&process.emitWarning){var n=new Error(i);n.name="MaxListenersExceededWarning",n.emitter=this,n.count=e,process.emitWarning(n)}else console.error(i),console.trace&&console.trace()}var u=function(e,t,i){var n=arguments.length;switch(n){case 0:return[];case 1:return[e];case 2:return[e,t];case 3:return[e,t,i];default:for(var r=new Array(n);n--;)r[n]=arguments[n];return r}};function p(e,i){for(var n={},r=e.length,s=i?i.length:0,o=0;o<r;o++)n[e[o]]=o<s?i[o]:t;return n}function v(e,t,i){var n,r;if(this._emitter=e,this._target=t,this._listeners={},this._listenersCount=0,(i.on||i.off)&&(n=i.on,r=i.off),t.addEventListener?(n=t.addEventListener,r=t.removeEventListener):t.addListener?(n=t.addListener,r=t.removeListener):t.on&&(n=t.on,r=t.off),!n&&!r)throw Error("target does not implement any known event API");if("function"!=typeof n)throw TypeError("on method must be a function");if("function"!=typeof r)throw TypeError("off method must be a function");this._on=n,this._off=r;var s=e._observers;s?s.push(this):e._observers=[this]}function y(e,n,r,s){var o=Object.assign({},n);if(!e)return o;if("object"!=typeof e)throw TypeError("options must be an object");var l,a,c,h=Object.keys(e),f=h.length;function u(e){throw Error('Invalid "'+l+'" option value'+(e?". Reason: "+e:""))}for(var p=0;p<f;p++){if(l=h[p],!s&&!i.call(n,l))throw Error('Unknown "'+l+'" option');(a=e[l])!==t&&(c=r[l],o[l]=c?c(a,u):a)}return o}function d(e,t){return"function"==typeof e&&e.hasOwnProperty("prototype")||t("value must be a constructor"),e}function _(e){var t="value must be type of "+e.join("|"),i=e.length,n=e[0],r=e[1];return 1===i?function(e,i){if(typeof e===n)return e;i(t)}:2===i?function(e,i){var s=typeof e;if(s===n||s===r)return e;i(t)}:function(n,r){for(var s=typeof n,o=i;o-- >0;)if(s===e[o])return n;r(t)}}Object.assign(v.prototype,{subscribe:function(e,t,i){var n=this,r=this._target,s=this._emitter,o=this._listeners,l=function(){var n=u.apply(null,arguments),o={data:n,name:t,original:e};if(i){var l=i.call(r,o);!1!==l&&s.emit.apply(s,[o.name].concat(n))}else s.emit.apply(s,[t].concat(n))};if(o[e])throw Error("Event '"+e+"' is already listening");this._listenersCount++,s._newListener&&s._removeListener&&!n._onNewListener?(this._onNewListener=function(i){i===t&&null===o[e]&&(o[e]=l,n._on.call(r,e,l))},s.on("newListener",this._onNewListener),this._onRemoveListener=function(i){i===t&&!s.hasListeners(i)&&o[e]&&(o[e]=null,n._off.call(r,e,l))},o[e]=null,s.on("removeListener",this._onRemoveListener)):(o[e]=l,n._on.call(r,e,l))},unsubscribe:function(e){var t,i,n,r=this,s=this._listeners,o=this._emitter,l=this._off,c=this._target;if(e&&"string"!=typeof e)throw TypeError("event must be a string");function h(){r._onNewListener&&(o.off("newListener",r._onNewListener),o.off("removeListener",r._onRemoveListener),r._onNewListener=null,r._onRemoveListener=null);var e=g.call(o,r);o._observers.splice(e,1)}if(e){if(!(t=s[e]))return;l.call(c,e,t),delete s[e],--this._listenersCount||h()}else{for(n=(i=a(s)).length;n-- >0;)e=i[n],l.call(c,e,s[e]);this._listeners={},this._listenersCount=0,h()}}});var m=_(["function"]),b=_(["object","function"]);function w(e,t,i){var n,r,s,o=0,l=new e((function(a,c,h){function f(){r&&(r=null),o&&(clearTimeout(o),o=0)}i=y(i,{timeout:0,overload:!1},{timeout:function(e,t){return("number"!=typeof(e*=1)||e<0||!Number.isFinite(e))&&t("timeout must be a positive number"),e}}),n=!i.overload&&"function"==typeof e.prototype.cancel&&"function"==typeof h;var u=function(e){f(),a(e)},p=function(e){f(),c(e)};n?t(u,p,h):(r=[function(e){p(e||Error("canceled"))}],t(u,p,(function(e){if(s)throw Error("Unable to subscribe on cancel event asynchronously");if("function"!=typeof e)throw TypeError("onCancel callback must be a function");r.push(e)})),s=!0),i.timeout>0&&(o=setTimeout((function(){var e=Error("timeout");e.code="ETIMEDOUT",o=0,l.cancel(e),c(e)}),i.timeout))}));return n||(l.cancel=function(e){if(r){for(var t=r.length,i=1;i<t;i++)r[i](e);r[0](e),r=null}}),l}function g(e){var t=this._observers;if(!t)return-1;for(var i=t.length,n=0;n<i;n++)if(t[n]._target===e)return n;return-1}function L(e,t,i,n,r){if(!i)return null;if(0===n){var s=typeof t;if("string"===s){var o,l,c=0,h=0,f=this.delimiter,u=f.length;if(-1!==(l=t.indexOf(f))){o=new Array(5);do{o[c++]=t.slice(h,l),h=l+u}while(-1!==(l=t.indexOf(f,h)));o[c++]=t.slice(h),t=o,r=c}else t=[t],r=1}else"object"===s?r=t.length:(t=[t],r=1)}var p,v,y,d,_,m,b,w=null,g=t[n],E=t[n+1];if(n===r)i._listeners&&("function"==typeof i._listeners?(e&&e.push(i._listeners),w=[i]):(e&&e.push.apply(e,i._listeners),w=[i]));else{if("*"===g){for(l=(m=a(i)).length;l-- >0;)"_listeners"!==(p=m[l])&&(b=L(e,t,i[p],n+1,r))&&(w?w.push.apply(w,b):w=b);return w}if("**"===g){for((_=n+1===r||n+2===r&&"*"===E)&&i._listeners&&(w=L(e,t,i,r,r)),l=(m=a(i)).length;l-- >0;)"_listeners"!==(p=m[l])&&("*"===p||"**"===p?(i[p]._listeners&&!_&&(b=L(e,t,i[p],r,r))&&(w?w.push.apply(w,b):w=b),b=L(e,t,i[p],n,r)):b=L(e,t,i[p],p===E?n+2:n,r),b&&(w?w.push.apply(w,b):w=b));return w}i[g]&&(w=L(e,t,i[g],n+1,r))}if((v=i["*"])&&L(e,t,v,n+1,r),y=i["**"])if(n<r)for(y._listeners&&L(e,t,y,r,r),l=(m=a(y)).length;l-- >0;)"_listeners"!==(p=m[l])&&(p===E?L(e,t,y[p],n+2,r):p===g?L(e,t,y[p],n+1,r):((d={})[p]=y[p],L(e,t,{"**":d},n+1,r)));else y._listeners?L(e,t,y,r,r):y["*"]&&y["*"]._listeners&&L(e,t,y["*"],r,r);return w}function E(e,t,i){var n,r,s=0,o=0,l=this.delimiter,a=l.length;if("string"==typeof e)if(-1!==(n=e.indexOf(l))){r=new Array(5);do{r[s++]=e.slice(o,n),o=n+a}while(-1!==(n=e.indexOf(l,o)));r[s++]=e.slice(o)}else r=[e],s=1;else r=e,s=e.length;if(s>1)for(n=0;n+1<s;n++)if("**"===r[n]&&"**"===r[n+1])return;var c,h=this.listenerTree;for(n=0;n<s;n++)if(h=h[c=r[n]]||(h[c]={}),n===s-1)return h._listeners?("function"==typeof h._listeners&&(h._listeners=[h._listeners]),i?h._listeners.unshift(t):h._listeners.push(t),!h._listeners.warned&&this._maxListeners>0&&h._listeners.length>this._maxListeners&&(h._listeners.warned=!0,f.call(this,h._listeners.length,c))):h._listeners=t,!0;return!0}function k(e,t,i,n){for(var r,s,o,l,c=a(e),h=c.length,f=e._listeners;h-- >0;)r=e[s=c[h]],o="_listeners"===s?i:i?i.concat(s):[s],l=n||"symbol"==typeof s,f&&t.push(l?o:o.join(this.delimiter)),"object"==typeof r&&k.call(this,r,t,o,l);return t}function j(e){for(var t,i,n,r=a(e),s=r.length;s-- >0;)(t=e[i=r[s]])&&(n=!0,"_listeners"===i||j(t)||delete e[i]);return n}function T(e,t,i){this.emitter=e,this.event=t,this.listener=i}function x(e,i,n){if(!0===n)o=!0;else if(!1===n)s=!0;else{if(!n||"object"!=typeof n)throw TypeError("options should be an object or true");var s=n.async,o=n.promisify,a=n.nextTick,c=n.objectify}if(s||a||o){var h=i,f=i._origin||i;if(a&&!r)throw Error("process.nextTick is not supported");o===t&&(o="AsyncFunction"===i.constructor.name),i=function(){var e=arguments,t=this,i=this.event;return o?a?Promise.resolve():new Promise((function(e){l(e)})).then((function(){return t.event=i,h.apply(t,e)})):(a?process.nextTick:l)((function(){t.event=i,h.apply(t,e)}))},i._async=!0,i._origin=f}return[i,c?new T(this,e,i):this]}function A(e){this._events={},this._newListener=!1,this._removeListener=!1,this.verboseMemoryLeak=!1,h.call(this,e)}T.prototype.off=function(){return this.emitter.off(this.event,this.listener),this},A.EventEmitter2=A,A.prototype.listenTo=function(e,i,r){if("object"!=typeof e)throw TypeError("target musts be an object");var s=this;function o(t){if("object"!=typeof t)throw TypeError("events must be an object");var i,n=r.reducers,o=g.call(s,e);i=-1===o?new v(s,e,r):s._observers[o];for(var l,c=a(t),h=c.length,f="function"==typeof n,u=0;u<h;u++)l=c[u],i.subscribe(l,t[l]||l,f?n:n&&n[l])}return r=y(r,{on:t,off:t,reducers:t},{on:m,off:m,reducers:b}),n(i)?o(p(i)):o("string"==typeof i?p(i.split(/\s+/)):i),this},A.prototype.stopListeningTo=function(e,t){var i=this._observers;if(!i)return!1;var n,r=i.length,s=!1;if(e&&"object"!=typeof e)throw TypeError("target should be an object");for(;r-- >0;)n=i[r],e&&n._target!==e||(n.unsubscribe(t),s=!0);return s},A.prototype.delimiter=".",A.prototype.setMaxListeners=function(e){e!==t&&(this._maxListeners=e,this._conf||(this._conf={}),this._conf.maxListeners=e)},A.prototype.getMaxListeners=function(){return this._maxListeners},A.prototype.event="",A.prototype.once=function(e,t,i){return this._once(e,t,!1,i)},A.prototype.prependOnceListener=function(e,t,i){return this._once(e,t,!0,i)},A.prototype._once=function(e,t,i,n){return this._many(e,1,t,i,n)},A.prototype.many=function(e,t,i,n){return this._many(e,t,i,!1,n)},A.prototype.prependMany=function(e,t,i,n){return this._many(e,t,i,!0,n)},A.prototype._many=function(e,t,i,n,r){var s=this;if("function"!=typeof i)throw new Error("many only accepts instances of Function");function o(){return 0==--t&&s.off(e,o),i.apply(this,arguments)}return o._origin=i,this._on(e,o,n,r)},A.prototype.emit=function(){if(!this._events&&!this._all)return!1;this._events||c.call(this);var e,t,i,n,r,o,l=arguments[0],a=this.wildcard;if("newListener"===l&&!this._newListener&&!this._events.newListener)return!1;if(a&&(e=l,"newListener"!==l&&"removeListener"!==l&&"object"==typeof l)){if(i=l.length,s)for(n=0;n<i;n++)if("symbol"==typeof l[n]){o=!0;break}o||(l=l.join(this.delimiter))}var h,f=arguments.length;if(this._all&&this._all.length)for(n=0,i=(h=this._all.slice()).length;n<i;n++)switch(this.event=l,f){case 1:h[n].call(this,l);break;case 2:h[n].call(this,l,arguments[1]);break;case 3:h[n].call(this,l,arguments[1],arguments[2]);break;default:h[n].apply(this,arguments)}if(a)h=[],L.call(this,h,e,this.listenerTree,0,i);else{if("function"==typeof(h=this._events[l])){switch(this.event=l,f){case 1:h.call(this);break;case 2:h.call(this,arguments[1]);break;case 3:h.call(this,arguments[1],arguments[2]);break;default:for(t=new Array(f-1),r=1;r<f;r++)t[r-1]=arguments[r];h.apply(this,t)}return!0}h&&(h=h.slice())}if(h&&h.length){if(f>3)for(t=new Array(f-1),r=1;r<f;r++)t[r-1]=arguments[r];for(n=0,i=h.length;n<i;n++)switch(this.event=l,f){case 1:h[n].call(this);break;case 2:h[n].call(this,arguments[1]);break;case 3:h[n].call(this,arguments[1],arguments[2]);break;default:h[n].apply(this,t)}return!0}if(!this.ignoreErrors&&!this._all&&"error"===l)throw arguments[1]instanceof Error?arguments[1]:new Error("Uncaught, unspecified 'error' event.");return!!this._all},A.prototype.emitAsync=function(){if(!this._events&&!this._all)return!1;this._events||c.call(this);var e,t,i,n,r,o,l=arguments[0],a=this.wildcard;if("newListener"===l&&!this._newListener&&!this._events.newListener)return Promise.resolve([!1]);if(a&&(e=l,"newListener"!==l&&"removeListener"!==l&&"object"==typeof l)){if(n=l.length,s)for(r=0;r<n;r++)if("symbol"==typeof l[r]){t=!0;break}t||(l=l.join(this.delimiter))}var h,f=[],u=arguments.length;if(this._all)for(r=0,n=this._all.length;r<n;r++)switch(this.event=l,u){case 1:f.push(this._all[r].call(this,l));break;case 2:f.push(this._all[r].call(this,l,arguments[1]));break;case 3:f.push(this._all[r].call(this,l,arguments[1],arguments[2]));break;default:f.push(this._all[r].apply(this,arguments))}if(a?(h=[],L.call(this,h,e,this.listenerTree,0)):h=this._events[l],"function"==typeof h)switch(this.event=l,u){case 1:f.push(h.call(this));break;case 2:f.push(h.call(this,arguments[1]));break;case 3:f.push(h.call(this,arguments[1],arguments[2]));break;default:for(i=new Array(u-1),o=1;o<u;o++)i[o-1]=arguments[o];f.push(h.apply(this,i))}else if(h&&h.length){if(h=h.slice(),u>3)for(i=new Array(u-1),o=1;o<u;o++)i[o-1]=arguments[o];for(r=0,n=h.length;r<n;r++)switch(this.event=l,u){case 1:f.push(h[r].call(this));break;case 2:f.push(h[r].call(this,arguments[1]));break;case 3:f.push(h[r].call(this,arguments[1],arguments[2]));break;default:f.push(h[r].apply(this,i))}}else if(!this.ignoreErrors&&!this._all&&"error"===l)return arguments[1]instanceof Error?Promise.reject(arguments[1]):Promise.reject("Uncaught, unspecified 'error' event.");return Promise.all(f)},A.prototype.on=function(e,t,i){return this._on(e,t,!1,i)},A.prototype.prependListener=function(e,t,i){return this._on(e,t,!0,i)},A.prototype.onAny=function(e){return this._onAny(e,!1)},A.prototype.prependAny=function(e){return this._onAny(e,!0)},A.prototype.addListener=A.prototype.on,A.prototype._onAny=function(e,t){if("function"!=typeof e)throw new Error("onAny only accepts instances of Function");return this._all||(this._all=[]),t?this._all.unshift(e):this._all.push(e),this},A.prototype._on=function(e,i,n,r){if("function"==typeof e)return this._onAny(e,i),this;if("function"!=typeof i)throw new Error("on only accepts instances of Function");this._events||c.call(this);var s,o=this;return r!==t&&(i=(s=x.call(this,e,i,r))[0],o=s[1]),this._newListener&&this.emit("newListener",e,i),this.wildcard?(E.call(this,e,i,n),o):(this._events[e]?("function"==typeof this._events[e]&&(this._events[e]=[this._events[e]]),n?this._events[e].unshift(i):this._events[e].push(i),!this._events[e].warned&&this._maxListeners>0&&this._events[e].length>this._maxListeners&&(this._events[e].warned=!0,f.call(this,this._events[e].length,e))):this._events[e]=i,o)},A.prototype.off=function(e,t){if("function"!=typeof t)throw new Error("removeListener only takes instances of Function");var i,r=[];if(this.wildcard){var s="string"==typeof e?e.split(this.delimiter):e.slice();if(!(r=L.call(this,null,s,this.listenerTree,0)))return this}else{if(!this._events[e])return this;i=this._events[e],r.push({_listeners:i})}for(var o=0;o<r.length;o++){var l=r[o];if(i=l._listeners,n(i)){for(var a=-1,c=0,h=i.length;c<h;c++)if(i[c]===t||i[c].listener&&i[c].listener===t||i[c]._origin&&i[c]._origin===t){a=c;break}if(a<0)continue;return this.wildcard?l._listeners.splice(a,1):this._events[e].splice(a,1),0===i.length&&(this.wildcard?delete l._listeners:delete this._events[e]),this._removeListener&&this.emit("removeListener",e,t),this}(i===t||i.listener&&i.listener===t||i._origin&&i._origin===t)&&(this.wildcard?delete l._listeners:delete this._events[e],this._removeListener&&this.emit("removeListener",e,t))}return this.listenerTree&&j(this.listenerTree),this},A.prototype.offAny=function(e){var t,i=0,n=0;if(e&&this._all&&this._all.length>0){for(i=0,n=(t=this._all).length;i<n;i++)if(e===t[i])return t.splice(i,1),this._removeListener&&this.emit("removeListenerAny",e),this}else{if(t=this._all,this._removeListener)for(i=0,n=t.length;i<n;i++)this.emit("removeListenerAny",t[i]);this._all=[]}return this},A.prototype.removeListener=A.prototype.off,A.prototype.removeAllListeners=function(e){if(e===t)return!this._events||c.call(this),this;if(this.wildcard){var i,n=L.call(this,null,e,this.listenerTree,0);if(!n)return this;for(i=0;i<n.length;i++)n[i]._listeners=null;this.listenerTree&&j(this.listenerTree)}else this._events&&(this._events[e]=null);return this},A.prototype.listeners=function(e){var i,n,r,s,o,l=this._events;if(e===t){if(this.wildcard)throw Error("event name required for wildcard emitter");if(!l)return[];for(s=(i=a(l)).length,r=[];s-- >0;)"function"==typeof(n=l[i[s]])?r.push(n):r.push.apply(r,n);return r}if(this.wildcard){if(!(o=this.listenerTree))return[];var c=[],h="string"==typeof e?e.split(this.delimiter):e.slice();return L.call(this,c,h,o,0),c}return l&&(n=l[e])?"function"==typeof n?[n]:n:[]},A.prototype.eventNames=function(e){var t=this._events;return this.wildcard?k.call(this,this.listenerTree,[],null,e):t?a(t):[]},A.prototype.listenerCount=function(e){return this.listeners(e).length},A.prototype.hasListeners=function(e){if(this.wildcard){var i=[],n="string"==typeof e?e.split(this.delimiter):e.slice();return L.call(this,i,n,this.listenerTree,0),i.length>0}var r=this._events,s=this._all;return!!(s&&s.length||r&&(e===t?a(r).length:r[e]))},A.prototype.listenersAny=function(){return this._all?this._all:[]},A.prototype.waitFor=function(e,i){var n=this,r=typeof i;return"number"===r?i={timeout:i}:"function"===r&&(i={filter:i}),w((i=y(i,{timeout:0,filter:t,handleError:!1,Promise:Promise,overload:!1},{filter:m,Promise:d})).Promise,(function(t,r,s){function o(){var s=i.filter;if(!s||s.apply(n,arguments))if(n.off(e,o),i.handleError){var l=arguments[0];l?r(l):t(u.apply(null,arguments).slice(1))}else t(u.apply(null,arguments))}s((function(){n.off(e,o)})),n._on(e,o,!1)}),{timeout:i.timeout,overload:i.overload})};var O=A.prototype;Object.defineProperties(A,{defaultMaxListeners:{get:function(){return O._maxListeners},set:function(e){if("number"!=typeof e||e<0||Number.isNaN(e))throw TypeError("n must be a non-negative number");O._maxListeners=e},enumerable:!0},once:{value:function(e,t,i){return w((i=y(i,{Promise:Promise,timeout:0,overload:!1},{Promise:d})).Promise,(function(i,n,r){var s;if("function"==typeof e.addEventListener)return s=function(){i(u.apply(null,arguments))},r((function(){e.removeEventListener(t,s)})),void e.addEventListener(t,s,{once:!0});var o,l=function(){o&&e.removeListener("error",o),i(u.apply(null,arguments))};"error"!==t&&(o=function(i){e.removeListener(t,l),n(i)},e.once("error",o)),r((function(){o&&e.removeListener("error",o),e.removeListener(t,l)})),e.once(t,l)}),{timeout:i.timeout,overload:i.overload})},writable:!0,configurable:!0}}),Object.defineProperties(O,{_maxListeners:{value:10,writable:!0,configurable:!0},_observers:{value:null,writable:!0,configurable:!0}}),e.exports=A}();var i=t.exports;global?(global.salla=global.salla||global.Salla||{},global.Salla=global.salla):(window.salla=window.salla||window.Salla||{},window.Salla=window.salla),Salla.event=new class extends i{constructor(){super({wildcard:!0,delimiter:"::",newListener:!1,removeListener:!1,maxListeners:10,verboseMemoryLeak:!1,ignoreErrors:!1}),this.globalListners={},this.delimiter="::",this.body=document.querySelector("body"),this.logableEvents=["cart::item.added.failed","cart::item.deleted.failed"],this.ingoreLogEvents=["document::click","document::keyup","document::change"],this.noneFireableActions=["document.request"],this.on("twilight::initiated",this.initiateSallaInAllClasses)}initiateSallaInAllClasses(){let e=this;Object.keys(salla).forEach((t=>{"object"==typeof(t=salla[t])&&(e.callSallaInitiate(t),Object.keys(t).forEach((i=>{e.callSallaInitiate(t[i])})))}))}callSallaInitiate(e){e&&e.sallaInitiated&&!e.initiated&&(e.sallaInitiated(),e.initiated=!0)}createAndDispatch(e,...t){this.dispatch(e,...t)}dispatch(e,...t){let i=e.replace("::",".");if(!this.noneFireableActions.includes(i)&&void 0!==salla.call&&"function"==typeof salla.call(i))return salla.log(`'salla.${i}(...)' triggered using event '${e}'`),i=i.split("."),void salla[i[0]][i[1]](...t);this.emit(e,...t),"undefined"!=typeof window&&(window.dataLayer=window.dataLayer||[],window.dataLayer.push(Object.assign({event:e},...t.values()))),this.ingoreLogEvents.includes(e)||!salla.config.get("debug")&&!this.logableEvents.includes(e)||void 0===salla.logger||salla.logger.event(e,...t);let n=this;Object.keys(this.globalListners).forEach((function(i){n.globalListners[i](e,...t)})),this.dispatchMobileEvent(e,{...t.values()})}dispatchEvents(e){if(e&&"object"==typeof e)for(const[t,i]of Object.entries(e))this.dispatch(t,i);else salla.log("No Events To Dispatch!",e)}addListener(e,t){this.on(e,t)}addEventListener(e,t){this.addListener(e,t)}listen(e,t){this.addListener(e,t)}registerGlobalListener(e,t){this.globalListners[e]=t}dispatchMobileEvent(e,t={}){if(!("undefined"!=typeof window&&window.dataLayer&&dataLayer[0]&&dataLayer[0].page&&dataLayer[0].page.mobileApp))return"";if(window.webkit)try{window.webkit.messageHandlers.callbackHandler.postMessage(JSON.stringify({event:e,details:t}))}catch(e){salla.log(e,"The native context does not exist yet")}else if(Android)try{Android.customEventWithData(e,JSON.stringify({details:t}))}catch(e){salla.log(e,"The native context does not exist yet")}}}; | ||
//# sourceMappingURL=index.js.map |
@@ -8,3 +8,3 @@ var e,t={exports:{}}; | ||
* Licensed under the MIT license. | ||
*/e=t,function(t){var i=Object.hasOwnProperty,n=Array.isArray?Array.isArray:function(e){return"[object Array]"===Object.prototype.toString.call(e)},r="object"==typeof process&&"function"==typeof process.nextTick,s="function"==typeof Symbol,o="object"==typeof Reflect,l="function"==typeof setImmediate?setImmediate:setTimeout,a=s?o&&"function"==typeof Reflect.ownKeys?Reflect.ownKeys:function(e){var t=Object.getOwnPropertyNames(e);return t.push.apply(t,Object.getOwnPropertySymbols(e)),t}:Object.keys;function c(){this._events={},this._conf&&h.call(this,this._conf)}function h(e){e&&(this._conf=e,e.delimiter&&(this.delimiter=e.delimiter),e.maxListeners!==t&&(this._maxListeners=e.maxListeners),e.wildcard&&(this.wildcard=e.wildcard),e.newListener&&(this._newListener=e.newListener),e.removeListener&&(this._removeListener=e.removeListener),e.verboseMemoryLeak&&(this.verboseMemoryLeak=e.verboseMemoryLeak),e.ignoreErrors&&(this.ignoreErrors=e.ignoreErrors),this.wildcard&&(this.listenerTree={}))}function f(e,t){var i="(node) warning: possible EventEmitter memory leak detected. "+e+" listeners added. Use emitter.setMaxListeners() to increase limit.";if(this.verboseMemoryLeak&&(i+=" Event name: "+t+"."),"undefined"!=typeof process&&process.emitWarning){var n=new Error(i);n.name="MaxListenersExceededWarning",n.emitter=this,n.count=e,process.emitWarning(n)}else console.error(i),console.trace&&console.trace()}var u=function(e,t,i){var n=arguments.length;switch(n){case 0:return[];case 1:return[e];case 2:return[e,t];case 3:return[e,t,i];default:for(var r=new Array(n);n--;)r[n]=arguments[n];return r}};function p(e,i){for(var n={},r=e.length,s=i?i.length:0,o=0;o<r;o++)n[e[o]]=o<s?i[o]:t;return n}function v(e,t,i){var n,r;if(this._emitter=e,this._target=t,this._listeners={},this._listenersCount=0,(i.on||i.off)&&(n=i.on,r=i.off),t.addEventListener?(n=t.addEventListener,r=t.removeEventListener):t.addListener?(n=t.addListener,r=t.removeListener):t.on&&(n=t.on,r=t.off),!n&&!r)throw Error("target does not implement any known event API");if("function"!=typeof n)throw TypeError("on method must be a function");if("function"!=typeof r)throw TypeError("off method must be a function");this._on=n,this._off=r;var s=e._observers;s?s.push(this):e._observers=[this]}function y(e,n,r,s){var o=Object.assign({},n);if(!e)return o;if("object"!=typeof e)throw TypeError("options must be an object");var l,a,c,h=Object.keys(e),f=h.length;function u(e){throw Error('Invalid "'+l+'" option value'+(e?". Reason: "+e:""))}for(var p=0;p<f;p++){if(l=h[p],!s&&!i.call(n,l))throw Error('Unknown "'+l+'" option');(a=e[l])!==t&&(c=r[l],o[l]=c?c(a,u):a)}return o}function d(e,t){return"function"==typeof e&&e.hasOwnProperty("prototype")||t("value must be a constructor"),e}function _(e){var t="value must be type of "+e.join("|"),i=e.length,n=e[0],r=e[1];return 1===i?function(e,i){if(typeof e===n)return e;i(t)}:2===i?function(e,i){var s=typeof e;if(s===n||s===r)return e;i(t)}:function(n,r){for(var s=typeof n,o=i;o-- >0;)if(s===e[o])return n;r(t)}}Object.assign(v.prototype,{subscribe:function(e,t,i){var n=this,r=this._target,s=this._emitter,o=this._listeners,l=function(){var n=u.apply(null,arguments),o={data:n,name:t,original:e};if(i){var l=i.call(r,o);!1!==l&&s.emit.apply(s,[o.name].concat(n))}else s.emit.apply(s,[t].concat(n))};if(o[e])throw Error("Event '"+e+"' is already listening");this._listenersCount++,s._newListener&&s._removeListener&&!n._onNewListener?(this._onNewListener=function(i){i===t&&null===o[e]&&(o[e]=l,n._on.call(r,e,l))},s.on("newListener",this._onNewListener),this._onRemoveListener=function(i){i===t&&!s.hasListeners(i)&&o[e]&&(o[e]=null,n._off.call(r,e,l))},o[e]=null,s.on("removeListener",this._onRemoveListener)):(o[e]=l,n._on.call(r,e,l))},unsubscribe:function(e){var t,i,n,r=this,s=this._listeners,o=this._emitter,l=this._off,c=this._target;if(e&&"string"!=typeof e)throw TypeError("event must be a string");function h(){r._onNewListener&&(o.off("newListener",r._onNewListener),o.off("removeListener",r._onRemoveListener),r._onNewListener=null,r._onRemoveListener=null);var e=w.call(o,r);o._observers.splice(e,1)}if(e){if(!(t=s[e]))return;l.call(c,e,t),delete s[e],--this._listenersCount||h()}else{for(n=(i=a(s)).length;n-- >0;)e=i[n],l.call(c,e,s[e]);this._listeners={},this._listenersCount=0,h()}}});var m=_(["function"]),b=_(["object","function"]);function g(e,t,i){var n,r,s,o=0,l=new e((function(a,c,h){function f(){r&&(r=null),o&&(clearTimeout(o),o=0)}i=y(i,{timeout:0,overload:!1},{timeout:function(e,t){return("number"!=typeof(e*=1)||e<0||!Number.isFinite(e))&&t("timeout must be a positive number"),e}}),n=!i.overload&&"function"==typeof e.prototype.cancel&&"function"==typeof h;var u=function(e){f(),a(e)},p=function(e){f(),c(e)};n?t(u,p,h):(r=[function(e){p(e||Error("canceled"))}],t(u,p,(function(e){if(s)throw Error("Unable to subscribe on cancel event asynchronously");if("function"!=typeof e)throw TypeError("onCancel callback must be a function");r.push(e)})),s=!0),i.timeout>0&&(o=setTimeout((function(){var e=Error("timeout");e.code="ETIMEDOUT",o=0,l.cancel(e),c(e)}),i.timeout))}));return n||(l.cancel=function(e){if(r){for(var t=r.length,i=1;i<t;i++)r[i](e);r[0](e),r=null}}),l}function w(e){var t=this._observers;if(!t)return-1;for(var i=t.length,n=0;n<i;n++)if(t[n]._target===e)return n;return-1}function L(e,t,i,n,r){if(!i)return null;if(0===n){var s=typeof t;if("string"===s){var o,l,c=0,h=0,f=this.delimiter,u=f.length;if(-1!==(l=t.indexOf(f))){o=new Array(5);do{o[c++]=t.slice(h,l),h=l+u}while(-1!==(l=t.indexOf(f,h)));o[c++]=t.slice(h),t=o,r=c}else t=[t],r=1}else"object"===s?r=t.length:(t=[t],r=1)}var p,v,y,d,_,m,b,g=null,w=t[n],E=t[n+1];if(n===r)i._listeners&&("function"==typeof i._listeners?(e&&e.push(i._listeners),g=[i]):(e&&e.push.apply(e,i._listeners),g=[i]));else{if("*"===w){for(l=(m=a(i)).length;l-- >0;)"_listeners"!==(p=m[l])&&(b=L(e,t,i[p],n+1,r))&&(g?g.push.apply(g,b):g=b);return g}if("**"===w){for((_=n+1===r||n+2===r&&"*"===E)&&i._listeners&&(g=L(e,t,i,r,r)),l=(m=a(i)).length;l-- >0;)"_listeners"!==(p=m[l])&&("*"===p||"**"===p?(i[p]._listeners&&!_&&(b=L(e,t,i[p],r,r))&&(g?g.push.apply(g,b):g=b),b=L(e,t,i[p],n,r)):b=L(e,t,i[p],p===E?n+2:n,r),b&&(g?g.push.apply(g,b):g=b));return g}i[w]&&(g=L(e,t,i[w],n+1,r))}if((v=i["*"])&&L(e,t,v,n+1,r),y=i["**"])if(n<r)for(y._listeners&&L(e,t,y,r,r),l=(m=a(y)).length;l-- >0;)"_listeners"!==(p=m[l])&&(p===E?L(e,t,y[p],n+2,r):p===w?L(e,t,y[p],n+1,r):((d={})[p]=y[p],L(e,t,{"**":d},n+1,r)));else y._listeners?L(e,t,y,r,r):y["*"]&&y["*"]._listeners&&L(e,t,y["*"],r,r);return g}function E(e,t,i){var n,r,s=0,o=0,l=this.delimiter,a=l.length;if("string"==typeof e)if(-1!==(n=e.indexOf(l))){r=new Array(5);do{r[s++]=e.slice(o,n),o=n+a}while(-1!==(n=e.indexOf(l,o)));r[s++]=e.slice(o)}else r=[e],s=1;else r=e,s=e.length;if(s>1)for(n=0;n+1<s;n++)if("**"===r[n]&&"**"===r[n+1])return;var c,h=this.listenerTree;for(n=0;n<s;n++)if(h=h[c=r[n]]||(h[c]={}),n===s-1)return h._listeners?("function"==typeof h._listeners&&(h._listeners=[h._listeners]),i?h._listeners.unshift(t):h._listeners.push(t),!h._listeners.warned&&this._maxListeners>0&&h._listeners.length>this._maxListeners&&(h._listeners.warned=!0,f.call(this,h._listeners.length,c))):h._listeners=t,!0;return!0}function k(e,t,i,n){for(var r,s,o,l,c=a(e),h=c.length,f=e._listeners;h-- >0;)r=e[s=c[h]],o="_listeners"===s?i:i?i.concat(s):[s],l=n||"symbol"==typeof s,f&&t.push(l?o:o.join(this.delimiter)),"object"==typeof r&&k.call(this,r,t,o,l);return t}function j(e){for(var t,i,n,r=a(e),s=r.length;s-- >0;)(t=e[i=r[s]])&&(n=!0,"_listeners"===i||j(t)||delete e[i]);return n}function T(e,t,i){this.emitter=e,this.event=t,this.listener=i}function x(e,i,n){if(!0===n)o=!0;else if(!1===n)s=!0;else{if(!n||"object"!=typeof n)throw TypeError("options should be an object or true");var s=n.async,o=n.promisify,a=n.nextTick,c=n.objectify}if(s||a||o){var h=i,f=i._origin||i;if(a&&!r)throw Error("process.nextTick is not supported");o===t&&(o="AsyncFunction"===i.constructor.name),i=function(){var e=arguments,t=this,i=this.event;return o?a?Promise.resolve():new Promise((function(e){l(e)})).then((function(){return t.event=i,h.apply(t,e)})):(a?process.nextTick:l)((function(){t.event=i,h.apply(t,e)}))},i._async=!0,i._origin=f}return[i,c?new T(this,e,i):this]}function A(e){this._events={},this._newListener=!1,this._removeListener=!1,this.verboseMemoryLeak=!1,h.call(this,e)}T.prototype.off=function(){return this.emitter.off(this.event,this.listener),this},A.EventEmitter2=A,A.prototype.listenTo=function(e,i,r){if("object"!=typeof e)throw TypeError("target musts be an object");var s=this;function o(t){if("object"!=typeof t)throw TypeError("events must be an object");var i,n=r.reducers,o=w.call(s,e);i=-1===o?new v(s,e,r):s._observers[o];for(var l,c=a(t),h=c.length,f="function"==typeof n,u=0;u<h;u++)l=c[u],i.subscribe(l,t[l]||l,f?n:n&&n[l])}return r=y(r,{on:t,off:t,reducers:t},{on:m,off:m,reducers:b}),n(i)?o(p(i)):o("string"==typeof i?p(i.split(/\s+/)):i),this},A.prototype.stopListeningTo=function(e,t){var i=this._observers;if(!i)return!1;var n,r=i.length,s=!1;if(e&&"object"!=typeof e)throw TypeError("target should be an object");for(;r-- >0;)n=i[r],e&&n._target!==e||(n.unsubscribe(t),s=!0);return s},A.prototype.delimiter=".",A.prototype.setMaxListeners=function(e){e!==t&&(this._maxListeners=e,this._conf||(this._conf={}),this._conf.maxListeners=e)},A.prototype.getMaxListeners=function(){return this._maxListeners},A.prototype.event="",A.prototype.once=function(e,t,i){return this._once(e,t,!1,i)},A.prototype.prependOnceListener=function(e,t,i){return this._once(e,t,!0,i)},A.prototype._once=function(e,t,i,n){return this._many(e,1,t,i,n)},A.prototype.many=function(e,t,i,n){return this._many(e,t,i,!1,n)},A.prototype.prependMany=function(e,t,i,n){return this._many(e,t,i,!0,n)},A.prototype._many=function(e,t,i,n,r){var s=this;if("function"!=typeof i)throw new Error("many only accepts instances of Function");function o(){return 0==--t&&s.off(e,o),i.apply(this,arguments)}return o._origin=i,this._on(e,o,n,r)},A.prototype.emit=function(){if(!this._events&&!this._all)return!1;this._events||c.call(this);var e,t,i,n,r,o,l=arguments[0],a=this.wildcard;if("newListener"===l&&!this._newListener&&!this._events.newListener)return!1;if(a&&(e=l,"newListener"!==l&&"removeListener"!==l&&"object"==typeof l)){if(i=l.length,s)for(n=0;n<i;n++)if("symbol"==typeof l[n]){o=!0;break}o||(l=l.join(this.delimiter))}var h,f=arguments.length;if(this._all&&this._all.length)for(n=0,i=(h=this._all.slice()).length;n<i;n++)switch(this.event=l,f){case 1:h[n].call(this,l);break;case 2:h[n].call(this,l,arguments[1]);break;case 3:h[n].call(this,l,arguments[1],arguments[2]);break;default:h[n].apply(this,arguments)}if(a)h=[],L.call(this,h,e,this.listenerTree,0,i);else{if("function"==typeof(h=this._events[l])){switch(this.event=l,f){case 1:h.call(this);break;case 2:h.call(this,arguments[1]);break;case 3:h.call(this,arguments[1],arguments[2]);break;default:for(t=new Array(f-1),r=1;r<f;r++)t[r-1]=arguments[r];h.apply(this,t)}return!0}h&&(h=h.slice())}if(h&&h.length){if(f>3)for(t=new Array(f-1),r=1;r<f;r++)t[r-1]=arguments[r];for(n=0,i=h.length;n<i;n++)switch(this.event=l,f){case 1:h[n].call(this);break;case 2:h[n].call(this,arguments[1]);break;case 3:h[n].call(this,arguments[1],arguments[2]);break;default:h[n].apply(this,t)}return!0}if(!this.ignoreErrors&&!this._all&&"error"===l)throw arguments[1]instanceof Error?arguments[1]:new Error("Uncaught, unspecified 'error' event.");return!!this._all},A.prototype.emitAsync=function(){if(!this._events&&!this._all)return!1;this._events||c.call(this);var e,t,i,n,r,o,l=arguments[0],a=this.wildcard;if("newListener"===l&&!this._newListener&&!this._events.newListener)return Promise.resolve([!1]);if(a&&(e=l,"newListener"!==l&&"removeListener"!==l&&"object"==typeof l)){if(n=l.length,s)for(r=0;r<n;r++)if("symbol"==typeof l[r]){t=!0;break}t||(l=l.join(this.delimiter))}var h,f=[],u=arguments.length;if(this._all)for(r=0,n=this._all.length;r<n;r++)switch(this.event=l,u){case 1:f.push(this._all[r].call(this,l));break;case 2:f.push(this._all[r].call(this,l,arguments[1]));break;case 3:f.push(this._all[r].call(this,l,arguments[1],arguments[2]));break;default:f.push(this._all[r].apply(this,arguments))}if(a?(h=[],L.call(this,h,e,this.listenerTree,0)):h=this._events[l],"function"==typeof h)switch(this.event=l,u){case 1:f.push(h.call(this));break;case 2:f.push(h.call(this,arguments[1]));break;case 3:f.push(h.call(this,arguments[1],arguments[2]));break;default:for(i=new Array(u-1),o=1;o<u;o++)i[o-1]=arguments[o];f.push(h.apply(this,i))}else if(h&&h.length){if(h=h.slice(),u>3)for(i=new Array(u-1),o=1;o<u;o++)i[o-1]=arguments[o];for(r=0,n=h.length;r<n;r++)switch(this.event=l,u){case 1:f.push(h[r].call(this));break;case 2:f.push(h[r].call(this,arguments[1]));break;case 3:f.push(h[r].call(this,arguments[1],arguments[2]));break;default:f.push(h[r].apply(this,i))}}else if(!this.ignoreErrors&&!this._all&&"error"===l)return arguments[1]instanceof Error?Promise.reject(arguments[1]):Promise.reject("Uncaught, unspecified 'error' event.");return Promise.all(f)},A.prototype.on=function(e,t,i){return this._on(e,t,!1,i)},A.prototype.prependListener=function(e,t,i){return this._on(e,t,!0,i)},A.prototype.onAny=function(e){return this._onAny(e,!1)},A.prototype.prependAny=function(e){return this._onAny(e,!0)},A.prototype.addListener=A.prototype.on,A.prototype._onAny=function(e,t){if("function"!=typeof e)throw new Error("onAny only accepts instances of Function");return this._all||(this._all=[]),t?this._all.unshift(e):this._all.push(e),this},A.prototype._on=function(e,i,n,r){if("function"==typeof e)return this._onAny(e,i),this;if("function"!=typeof i)throw new Error("on only accepts instances of Function");this._events||c.call(this);var s,o=this;return r!==t&&(i=(s=x.call(this,e,i,r))[0],o=s[1]),this._newListener&&this.emit("newListener",e,i),this.wildcard?(E.call(this,e,i,n),o):(this._events[e]?("function"==typeof this._events[e]&&(this._events[e]=[this._events[e]]),n?this._events[e].unshift(i):this._events[e].push(i),!this._events[e].warned&&this._maxListeners>0&&this._events[e].length>this._maxListeners&&(this._events[e].warned=!0,f.call(this,this._events[e].length,e))):this._events[e]=i,o)},A.prototype.off=function(e,t){if("function"!=typeof t)throw new Error("removeListener only takes instances of Function");var i,r=[];if(this.wildcard){var s="string"==typeof e?e.split(this.delimiter):e.slice();if(!(r=L.call(this,null,s,this.listenerTree,0)))return this}else{if(!this._events[e])return this;i=this._events[e],r.push({_listeners:i})}for(var o=0;o<r.length;o++){var l=r[o];if(i=l._listeners,n(i)){for(var a=-1,c=0,h=i.length;c<h;c++)if(i[c]===t||i[c].listener&&i[c].listener===t||i[c]._origin&&i[c]._origin===t){a=c;break}if(a<0)continue;return this.wildcard?l._listeners.splice(a,1):this._events[e].splice(a,1),0===i.length&&(this.wildcard?delete l._listeners:delete this._events[e]),this._removeListener&&this.emit("removeListener",e,t),this}(i===t||i.listener&&i.listener===t||i._origin&&i._origin===t)&&(this.wildcard?delete l._listeners:delete this._events[e],this._removeListener&&this.emit("removeListener",e,t))}return this.listenerTree&&j(this.listenerTree),this},A.prototype.offAny=function(e){var t,i=0,n=0;if(e&&this._all&&this._all.length>0){for(i=0,n=(t=this._all).length;i<n;i++)if(e===t[i])return t.splice(i,1),this._removeListener&&this.emit("removeListenerAny",e),this}else{if(t=this._all,this._removeListener)for(i=0,n=t.length;i<n;i++)this.emit("removeListenerAny",t[i]);this._all=[]}return this},A.prototype.removeListener=A.prototype.off,A.prototype.removeAllListeners=function(e){if(e===t)return!this._events||c.call(this),this;if(this.wildcard){var i,n=L.call(this,null,e,this.listenerTree,0);if(!n)return this;for(i=0;i<n.length;i++)n[i]._listeners=null;this.listenerTree&&j(this.listenerTree)}else this._events&&(this._events[e]=null);return this},A.prototype.listeners=function(e){var i,n,r,s,o,l=this._events;if(e===t){if(this.wildcard)throw Error("event name required for wildcard emitter");if(!l)return[];for(s=(i=a(l)).length,r=[];s-- >0;)"function"==typeof(n=l[i[s]])?r.push(n):r.push.apply(r,n);return r}if(this.wildcard){if(!(o=this.listenerTree))return[];var c=[],h="string"==typeof e?e.split(this.delimiter):e.slice();return L.call(this,c,h,o,0),c}return l&&(n=l[e])?"function"==typeof n?[n]:n:[]},A.prototype.eventNames=function(e){var t=this._events;return this.wildcard?k.call(this,this.listenerTree,[],null,e):t?a(t):[]},A.prototype.listenerCount=function(e){return this.listeners(e).length},A.prototype.hasListeners=function(e){if(this.wildcard){var i=[],n="string"==typeof e?e.split(this.delimiter):e.slice();return L.call(this,i,n,this.listenerTree,0),i.length>0}var r=this._events,s=this._all;return!!(s&&s.length||r&&(e===t?a(r).length:r[e]))},A.prototype.listenersAny=function(){return this._all?this._all:[]},A.prototype.waitFor=function(e,i){var n=this,r=typeof i;return"number"===r?i={timeout:i}:"function"===r&&(i={filter:i}),g((i=y(i,{timeout:0,filter:t,handleError:!1,Promise:Promise,overload:!1},{filter:m,Promise:d})).Promise,(function(t,r,s){function o(){var s=i.filter;if(!s||s.apply(n,arguments))if(n.off(e,o),i.handleError){var l=arguments[0];l?r(l):t(u.apply(null,arguments).slice(1))}else t(u.apply(null,arguments))}s((function(){n.off(e,o)})),n._on(e,o,!1)}),{timeout:i.timeout,overload:i.overload})};var O=A.prototype;Object.defineProperties(A,{defaultMaxListeners:{get:function(){return O._maxListeners},set:function(e){if("number"!=typeof e||e<0||Number.isNaN(e))throw TypeError("n must be a non-negative number");O._maxListeners=e},enumerable:!0},once:{value:function(e,t,i){return g((i=y(i,{Promise:Promise,timeout:0,overload:!1},{Promise:d})).Promise,(function(i,n,r){var s;if("function"==typeof e.addEventListener)return s=function(){i(u.apply(null,arguments))},r((function(){e.removeEventListener(t,s)})),void e.addEventListener(t,s,{once:!0});var o,l=function(){o&&e.removeListener("error",o),i(u.apply(null,arguments))};"error"!==t&&(o=function(i){e.removeListener(t,l),n(i)},e.once("error",o)),r((function(){o&&e.removeListener("error",o),e.removeListener(t,l)})),e.once(t,l)}),{timeout:i.timeout,overload:i.overload})},writable:!0,configurable:!0}}),Object.defineProperties(O,{_maxListeners:{value:10,writable:!0,configurable:!0},_observers:{value:null,writable:!0,configurable:!0}}),e.exports=A}();var i=t.exports;global?(global.salla=global.salla||global.Salla||{},global.Salla=global.salla):(window.salla=window.salla||window.Salla||{},window.Salla=window.salla),Salla.event=new class extends i{constructor(){super({wildcard:!0,delimiter:"::",newListener:!1,removeListener:!1,maxListeners:10,verboseMemoryLeak:!1,ignoreErrors:!1}),this.globalListners={},this.delimiter="::",this.body=document.querySelector("body"),this.logableEvents=["cart::item.added.failed","cart::item.deleted.failed"],this.ingoreLogEvents=["document::click","document::keyup","document::change"],this.noneFireableActions=["document.request"],this.on("twilight::initiated",this.initiateSallaInAllClasses)}initiateSallaInAllClasses(){let e=this;Object.keys(salla).forEach((t=>{"object"==typeof(t=salla[t])&&(e.callSallaInitiate(t),Object.keys(t).forEach((i=>{e.callSallaInitiate(t[i])})))}))}callSallaInitiate(e){e&&e.sallaInitiated&&!e.initiated&&(e.sallaInitiated(),e.initiated=!0)}createAndDispatch(e,...t){this.dispatch(e,...t)}dispatch(e,...t){let i=e.replace("::",".");if(!this.noneFireableActions.includes(i)&&void 0!==salla.call&&"function"==typeof salla.call(i))return salla.log(`'salla.${i}(...)' triggered using event '${e}'`),i=i.split("."),void salla[i[0]][i[1]](...t);this.emit(e,...t),"undefined"!=typeof window&&(window.dataLayer=window.dataLayer||[],window.dataLayer.push(Object.assign({event:e},...t.values()))),this.ingoreLogEvents.includes(e)||!salla.config.get("debug")&&!this.logableEvents.includes(e)||void 0===salla.logger||salla.logger.event(e,...t);let n=this;Object.keys(this.globalListners).forEach((function(i){n.globalListners[i](e,...t)})),this.dispatchMobileEvent(e,{...t.values()})}dispatchEvents(e){if(e&&"object"==typeof e)for(const[t,i]of Object.entries(e))this.dispatch(t,i);else salla.log("No Events To Dispatch!",e)}addListener(e,t){this.on(e,t)}addEventListener(e,t){this.addListener(e,t)}listen(e,t){this.addListener(e,t)}registerGlobalListener(e,t){this.globalListners[e]=t}dispatchMobileEvent(e,t={}){if(!(window.dataLayer&&dataLayer[0]&&dataLayer[0].page&&dataLayer[0].page.mobileApp))return"";if(window.webkit)try{window.webkit.messageHandlers.callbackHandler.postMessage(JSON.stringify({event:e,details:t}))}catch(e){salla.log(e,"The native context does not exist yet")}else if(Android)try{Android.customEventWithData(e,JSON.stringify({details:t}))}catch(e){salla.log(e,"The native context does not exist yet")}}}; | ||
*/e=t,function(t){var i=Object.hasOwnProperty,n=Array.isArray?Array.isArray:function(e){return"[object Array]"===Object.prototype.toString.call(e)},r="object"==typeof process&&"function"==typeof process.nextTick,s="function"==typeof Symbol,o="object"==typeof Reflect,l="function"==typeof setImmediate?setImmediate:setTimeout,a=s?o&&"function"==typeof Reflect.ownKeys?Reflect.ownKeys:function(e){var t=Object.getOwnPropertyNames(e);return t.push.apply(t,Object.getOwnPropertySymbols(e)),t}:Object.keys;function c(){this._events={},this._conf&&h.call(this,this._conf)}function h(e){e&&(this._conf=e,e.delimiter&&(this.delimiter=e.delimiter),e.maxListeners!==t&&(this._maxListeners=e.maxListeners),e.wildcard&&(this.wildcard=e.wildcard),e.newListener&&(this._newListener=e.newListener),e.removeListener&&(this._removeListener=e.removeListener),e.verboseMemoryLeak&&(this.verboseMemoryLeak=e.verboseMemoryLeak),e.ignoreErrors&&(this.ignoreErrors=e.ignoreErrors),this.wildcard&&(this.listenerTree={}))}function f(e,t){var i="(node) warning: possible EventEmitter memory leak detected. "+e+" listeners added. Use emitter.setMaxListeners() to increase limit.";if(this.verboseMemoryLeak&&(i+=" Event name: "+t+"."),"undefined"!=typeof process&&process.emitWarning){var n=new Error(i);n.name="MaxListenersExceededWarning",n.emitter=this,n.count=e,process.emitWarning(n)}else console.error(i),console.trace&&console.trace()}var u=function(e,t,i){var n=arguments.length;switch(n){case 0:return[];case 1:return[e];case 2:return[e,t];case 3:return[e,t,i];default:for(var r=new Array(n);n--;)r[n]=arguments[n];return r}};function p(e,i){for(var n={},r=e.length,s=i?i.length:0,o=0;o<r;o++)n[e[o]]=o<s?i[o]:t;return n}function v(e,t,i){var n,r;if(this._emitter=e,this._target=t,this._listeners={},this._listenersCount=0,(i.on||i.off)&&(n=i.on,r=i.off),t.addEventListener?(n=t.addEventListener,r=t.removeEventListener):t.addListener?(n=t.addListener,r=t.removeListener):t.on&&(n=t.on,r=t.off),!n&&!r)throw Error("target does not implement any known event API");if("function"!=typeof n)throw TypeError("on method must be a function");if("function"!=typeof r)throw TypeError("off method must be a function");this._on=n,this._off=r;var s=e._observers;s?s.push(this):e._observers=[this]}function y(e,n,r,s){var o=Object.assign({},n);if(!e)return o;if("object"!=typeof e)throw TypeError("options must be an object");var l,a,c,h=Object.keys(e),f=h.length;function u(e){throw Error('Invalid "'+l+'" option value'+(e?". Reason: "+e:""))}for(var p=0;p<f;p++){if(l=h[p],!s&&!i.call(n,l))throw Error('Unknown "'+l+'" option');(a=e[l])!==t&&(c=r[l],o[l]=c?c(a,u):a)}return o}function d(e,t){return"function"==typeof e&&e.hasOwnProperty("prototype")||t("value must be a constructor"),e}function _(e){var t="value must be type of "+e.join("|"),i=e.length,n=e[0],r=e[1];return 1===i?function(e,i){if(typeof e===n)return e;i(t)}:2===i?function(e,i){var s=typeof e;if(s===n||s===r)return e;i(t)}:function(n,r){for(var s=typeof n,o=i;o-- >0;)if(s===e[o])return n;r(t)}}Object.assign(v.prototype,{subscribe:function(e,t,i){var n=this,r=this._target,s=this._emitter,o=this._listeners,l=function(){var n=u.apply(null,arguments),o={data:n,name:t,original:e};if(i){var l=i.call(r,o);!1!==l&&s.emit.apply(s,[o.name].concat(n))}else s.emit.apply(s,[t].concat(n))};if(o[e])throw Error("Event '"+e+"' is already listening");this._listenersCount++,s._newListener&&s._removeListener&&!n._onNewListener?(this._onNewListener=function(i){i===t&&null===o[e]&&(o[e]=l,n._on.call(r,e,l))},s.on("newListener",this._onNewListener),this._onRemoveListener=function(i){i===t&&!s.hasListeners(i)&&o[e]&&(o[e]=null,n._off.call(r,e,l))},o[e]=null,s.on("removeListener",this._onRemoveListener)):(o[e]=l,n._on.call(r,e,l))},unsubscribe:function(e){var t,i,n,r=this,s=this._listeners,o=this._emitter,l=this._off,c=this._target;if(e&&"string"!=typeof e)throw TypeError("event must be a string");function h(){r._onNewListener&&(o.off("newListener",r._onNewListener),o.off("removeListener",r._onRemoveListener),r._onNewListener=null,r._onRemoveListener=null);var e=g.call(o,r);o._observers.splice(e,1)}if(e){if(!(t=s[e]))return;l.call(c,e,t),delete s[e],--this._listenersCount||h()}else{for(n=(i=a(s)).length;n-- >0;)e=i[n],l.call(c,e,s[e]);this._listeners={},this._listenersCount=0,h()}}});var m=_(["function"]),b=_(["object","function"]);function w(e,t,i){var n,r,s,o=0,l=new e((function(a,c,h){function f(){r&&(r=null),o&&(clearTimeout(o),o=0)}i=y(i,{timeout:0,overload:!1},{timeout:function(e,t){return("number"!=typeof(e*=1)||e<0||!Number.isFinite(e))&&t("timeout must be a positive number"),e}}),n=!i.overload&&"function"==typeof e.prototype.cancel&&"function"==typeof h;var u=function(e){f(),a(e)},p=function(e){f(),c(e)};n?t(u,p,h):(r=[function(e){p(e||Error("canceled"))}],t(u,p,(function(e){if(s)throw Error("Unable to subscribe on cancel event asynchronously");if("function"!=typeof e)throw TypeError("onCancel callback must be a function");r.push(e)})),s=!0),i.timeout>0&&(o=setTimeout((function(){var e=Error("timeout");e.code="ETIMEDOUT",o=0,l.cancel(e),c(e)}),i.timeout))}));return n||(l.cancel=function(e){if(r){for(var t=r.length,i=1;i<t;i++)r[i](e);r[0](e),r=null}}),l}function g(e){var t=this._observers;if(!t)return-1;for(var i=t.length,n=0;n<i;n++)if(t[n]._target===e)return n;return-1}function L(e,t,i,n,r){if(!i)return null;if(0===n){var s=typeof t;if("string"===s){var o,l,c=0,h=0,f=this.delimiter,u=f.length;if(-1!==(l=t.indexOf(f))){o=new Array(5);do{o[c++]=t.slice(h,l),h=l+u}while(-1!==(l=t.indexOf(f,h)));o[c++]=t.slice(h),t=o,r=c}else t=[t],r=1}else"object"===s?r=t.length:(t=[t],r=1)}var p,v,y,d,_,m,b,w=null,g=t[n],E=t[n+1];if(n===r)i._listeners&&("function"==typeof i._listeners?(e&&e.push(i._listeners),w=[i]):(e&&e.push.apply(e,i._listeners),w=[i]));else{if("*"===g){for(l=(m=a(i)).length;l-- >0;)"_listeners"!==(p=m[l])&&(b=L(e,t,i[p],n+1,r))&&(w?w.push.apply(w,b):w=b);return w}if("**"===g){for((_=n+1===r||n+2===r&&"*"===E)&&i._listeners&&(w=L(e,t,i,r,r)),l=(m=a(i)).length;l-- >0;)"_listeners"!==(p=m[l])&&("*"===p||"**"===p?(i[p]._listeners&&!_&&(b=L(e,t,i[p],r,r))&&(w?w.push.apply(w,b):w=b),b=L(e,t,i[p],n,r)):b=L(e,t,i[p],p===E?n+2:n,r),b&&(w?w.push.apply(w,b):w=b));return w}i[g]&&(w=L(e,t,i[g],n+1,r))}if((v=i["*"])&&L(e,t,v,n+1,r),y=i["**"])if(n<r)for(y._listeners&&L(e,t,y,r,r),l=(m=a(y)).length;l-- >0;)"_listeners"!==(p=m[l])&&(p===E?L(e,t,y[p],n+2,r):p===g?L(e,t,y[p],n+1,r):((d={})[p]=y[p],L(e,t,{"**":d},n+1,r)));else y._listeners?L(e,t,y,r,r):y["*"]&&y["*"]._listeners&&L(e,t,y["*"],r,r);return w}function E(e,t,i){var n,r,s=0,o=0,l=this.delimiter,a=l.length;if("string"==typeof e)if(-1!==(n=e.indexOf(l))){r=new Array(5);do{r[s++]=e.slice(o,n),o=n+a}while(-1!==(n=e.indexOf(l,o)));r[s++]=e.slice(o)}else r=[e],s=1;else r=e,s=e.length;if(s>1)for(n=0;n+1<s;n++)if("**"===r[n]&&"**"===r[n+1])return;var c,h=this.listenerTree;for(n=0;n<s;n++)if(h=h[c=r[n]]||(h[c]={}),n===s-1)return h._listeners?("function"==typeof h._listeners&&(h._listeners=[h._listeners]),i?h._listeners.unshift(t):h._listeners.push(t),!h._listeners.warned&&this._maxListeners>0&&h._listeners.length>this._maxListeners&&(h._listeners.warned=!0,f.call(this,h._listeners.length,c))):h._listeners=t,!0;return!0}function k(e,t,i,n){for(var r,s,o,l,c=a(e),h=c.length,f=e._listeners;h-- >0;)r=e[s=c[h]],o="_listeners"===s?i:i?i.concat(s):[s],l=n||"symbol"==typeof s,f&&t.push(l?o:o.join(this.delimiter)),"object"==typeof r&&k.call(this,r,t,o,l);return t}function j(e){for(var t,i,n,r=a(e),s=r.length;s-- >0;)(t=e[i=r[s]])&&(n=!0,"_listeners"===i||j(t)||delete e[i]);return n}function T(e,t,i){this.emitter=e,this.event=t,this.listener=i}function x(e,i,n){if(!0===n)o=!0;else if(!1===n)s=!0;else{if(!n||"object"!=typeof n)throw TypeError("options should be an object or true");var s=n.async,o=n.promisify,a=n.nextTick,c=n.objectify}if(s||a||o){var h=i,f=i._origin||i;if(a&&!r)throw Error("process.nextTick is not supported");o===t&&(o="AsyncFunction"===i.constructor.name),i=function(){var e=arguments,t=this,i=this.event;return o?a?Promise.resolve():new Promise((function(e){l(e)})).then((function(){return t.event=i,h.apply(t,e)})):(a?process.nextTick:l)((function(){t.event=i,h.apply(t,e)}))},i._async=!0,i._origin=f}return[i,c?new T(this,e,i):this]}function A(e){this._events={},this._newListener=!1,this._removeListener=!1,this.verboseMemoryLeak=!1,h.call(this,e)}T.prototype.off=function(){return this.emitter.off(this.event,this.listener),this},A.EventEmitter2=A,A.prototype.listenTo=function(e,i,r){if("object"!=typeof e)throw TypeError("target musts be an object");var s=this;function o(t){if("object"!=typeof t)throw TypeError("events must be an object");var i,n=r.reducers,o=g.call(s,e);i=-1===o?new v(s,e,r):s._observers[o];for(var l,c=a(t),h=c.length,f="function"==typeof n,u=0;u<h;u++)l=c[u],i.subscribe(l,t[l]||l,f?n:n&&n[l])}return r=y(r,{on:t,off:t,reducers:t},{on:m,off:m,reducers:b}),n(i)?o(p(i)):o("string"==typeof i?p(i.split(/\s+/)):i),this},A.prototype.stopListeningTo=function(e,t){var i=this._observers;if(!i)return!1;var n,r=i.length,s=!1;if(e&&"object"!=typeof e)throw TypeError("target should be an object");for(;r-- >0;)n=i[r],e&&n._target!==e||(n.unsubscribe(t),s=!0);return s},A.prototype.delimiter=".",A.prototype.setMaxListeners=function(e){e!==t&&(this._maxListeners=e,this._conf||(this._conf={}),this._conf.maxListeners=e)},A.prototype.getMaxListeners=function(){return this._maxListeners},A.prototype.event="",A.prototype.once=function(e,t,i){return this._once(e,t,!1,i)},A.prototype.prependOnceListener=function(e,t,i){return this._once(e,t,!0,i)},A.prototype._once=function(e,t,i,n){return this._many(e,1,t,i,n)},A.prototype.many=function(e,t,i,n){return this._many(e,t,i,!1,n)},A.prototype.prependMany=function(e,t,i,n){return this._many(e,t,i,!0,n)},A.prototype._many=function(e,t,i,n,r){var s=this;if("function"!=typeof i)throw new Error("many only accepts instances of Function");function o(){return 0==--t&&s.off(e,o),i.apply(this,arguments)}return o._origin=i,this._on(e,o,n,r)},A.prototype.emit=function(){if(!this._events&&!this._all)return!1;this._events||c.call(this);var e,t,i,n,r,o,l=arguments[0],a=this.wildcard;if("newListener"===l&&!this._newListener&&!this._events.newListener)return!1;if(a&&(e=l,"newListener"!==l&&"removeListener"!==l&&"object"==typeof l)){if(i=l.length,s)for(n=0;n<i;n++)if("symbol"==typeof l[n]){o=!0;break}o||(l=l.join(this.delimiter))}var h,f=arguments.length;if(this._all&&this._all.length)for(n=0,i=(h=this._all.slice()).length;n<i;n++)switch(this.event=l,f){case 1:h[n].call(this,l);break;case 2:h[n].call(this,l,arguments[1]);break;case 3:h[n].call(this,l,arguments[1],arguments[2]);break;default:h[n].apply(this,arguments)}if(a)h=[],L.call(this,h,e,this.listenerTree,0,i);else{if("function"==typeof(h=this._events[l])){switch(this.event=l,f){case 1:h.call(this);break;case 2:h.call(this,arguments[1]);break;case 3:h.call(this,arguments[1],arguments[2]);break;default:for(t=new Array(f-1),r=1;r<f;r++)t[r-1]=arguments[r];h.apply(this,t)}return!0}h&&(h=h.slice())}if(h&&h.length){if(f>3)for(t=new Array(f-1),r=1;r<f;r++)t[r-1]=arguments[r];for(n=0,i=h.length;n<i;n++)switch(this.event=l,f){case 1:h[n].call(this);break;case 2:h[n].call(this,arguments[1]);break;case 3:h[n].call(this,arguments[1],arguments[2]);break;default:h[n].apply(this,t)}return!0}if(!this.ignoreErrors&&!this._all&&"error"===l)throw arguments[1]instanceof Error?arguments[1]:new Error("Uncaught, unspecified 'error' event.");return!!this._all},A.prototype.emitAsync=function(){if(!this._events&&!this._all)return!1;this._events||c.call(this);var e,t,i,n,r,o,l=arguments[0],a=this.wildcard;if("newListener"===l&&!this._newListener&&!this._events.newListener)return Promise.resolve([!1]);if(a&&(e=l,"newListener"!==l&&"removeListener"!==l&&"object"==typeof l)){if(n=l.length,s)for(r=0;r<n;r++)if("symbol"==typeof l[r]){t=!0;break}t||(l=l.join(this.delimiter))}var h,f=[],u=arguments.length;if(this._all)for(r=0,n=this._all.length;r<n;r++)switch(this.event=l,u){case 1:f.push(this._all[r].call(this,l));break;case 2:f.push(this._all[r].call(this,l,arguments[1]));break;case 3:f.push(this._all[r].call(this,l,arguments[1],arguments[2]));break;default:f.push(this._all[r].apply(this,arguments))}if(a?(h=[],L.call(this,h,e,this.listenerTree,0)):h=this._events[l],"function"==typeof h)switch(this.event=l,u){case 1:f.push(h.call(this));break;case 2:f.push(h.call(this,arguments[1]));break;case 3:f.push(h.call(this,arguments[1],arguments[2]));break;default:for(i=new Array(u-1),o=1;o<u;o++)i[o-1]=arguments[o];f.push(h.apply(this,i))}else if(h&&h.length){if(h=h.slice(),u>3)for(i=new Array(u-1),o=1;o<u;o++)i[o-1]=arguments[o];for(r=0,n=h.length;r<n;r++)switch(this.event=l,u){case 1:f.push(h[r].call(this));break;case 2:f.push(h[r].call(this,arguments[1]));break;case 3:f.push(h[r].call(this,arguments[1],arguments[2]));break;default:f.push(h[r].apply(this,i))}}else if(!this.ignoreErrors&&!this._all&&"error"===l)return arguments[1]instanceof Error?Promise.reject(arguments[1]):Promise.reject("Uncaught, unspecified 'error' event.");return Promise.all(f)},A.prototype.on=function(e,t,i){return this._on(e,t,!1,i)},A.prototype.prependListener=function(e,t,i){return this._on(e,t,!0,i)},A.prototype.onAny=function(e){return this._onAny(e,!1)},A.prototype.prependAny=function(e){return this._onAny(e,!0)},A.prototype.addListener=A.prototype.on,A.prototype._onAny=function(e,t){if("function"!=typeof e)throw new Error("onAny only accepts instances of Function");return this._all||(this._all=[]),t?this._all.unshift(e):this._all.push(e),this},A.prototype._on=function(e,i,n,r){if("function"==typeof e)return this._onAny(e,i),this;if("function"!=typeof i)throw new Error("on only accepts instances of Function");this._events||c.call(this);var s,o=this;return r!==t&&(i=(s=x.call(this,e,i,r))[0],o=s[1]),this._newListener&&this.emit("newListener",e,i),this.wildcard?(E.call(this,e,i,n),o):(this._events[e]?("function"==typeof this._events[e]&&(this._events[e]=[this._events[e]]),n?this._events[e].unshift(i):this._events[e].push(i),!this._events[e].warned&&this._maxListeners>0&&this._events[e].length>this._maxListeners&&(this._events[e].warned=!0,f.call(this,this._events[e].length,e))):this._events[e]=i,o)},A.prototype.off=function(e,t){if("function"!=typeof t)throw new Error("removeListener only takes instances of Function");var i,r=[];if(this.wildcard){var s="string"==typeof e?e.split(this.delimiter):e.slice();if(!(r=L.call(this,null,s,this.listenerTree,0)))return this}else{if(!this._events[e])return this;i=this._events[e],r.push({_listeners:i})}for(var o=0;o<r.length;o++){var l=r[o];if(i=l._listeners,n(i)){for(var a=-1,c=0,h=i.length;c<h;c++)if(i[c]===t||i[c].listener&&i[c].listener===t||i[c]._origin&&i[c]._origin===t){a=c;break}if(a<0)continue;return this.wildcard?l._listeners.splice(a,1):this._events[e].splice(a,1),0===i.length&&(this.wildcard?delete l._listeners:delete this._events[e]),this._removeListener&&this.emit("removeListener",e,t),this}(i===t||i.listener&&i.listener===t||i._origin&&i._origin===t)&&(this.wildcard?delete l._listeners:delete this._events[e],this._removeListener&&this.emit("removeListener",e,t))}return this.listenerTree&&j(this.listenerTree),this},A.prototype.offAny=function(e){var t,i=0,n=0;if(e&&this._all&&this._all.length>0){for(i=0,n=(t=this._all).length;i<n;i++)if(e===t[i])return t.splice(i,1),this._removeListener&&this.emit("removeListenerAny",e),this}else{if(t=this._all,this._removeListener)for(i=0,n=t.length;i<n;i++)this.emit("removeListenerAny",t[i]);this._all=[]}return this},A.prototype.removeListener=A.prototype.off,A.prototype.removeAllListeners=function(e){if(e===t)return!this._events||c.call(this),this;if(this.wildcard){var i,n=L.call(this,null,e,this.listenerTree,0);if(!n)return this;for(i=0;i<n.length;i++)n[i]._listeners=null;this.listenerTree&&j(this.listenerTree)}else this._events&&(this._events[e]=null);return this},A.prototype.listeners=function(e){var i,n,r,s,o,l=this._events;if(e===t){if(this.wildcard)throw Error("event name required for wildcard emitter");if(!l)return[];for(s=(i=a(l)).length,r=[];s-- >0;)"function"==typeof(n=l[i[s]])?r.push(n):r.push.apply(r,n);return r}if(this.wildcard){if(!(o=this.listenerTree))return[];var c=[],h="string"==typeof e?e.split(this.delimiter):e.slice();return L.call(this,c,h,o,0),c}return l&&(n=l[e])?"function"==typeof n?[n]:n:[]},A.prototype.eventNames=function(e){var t=this._events;return this.wildcard?k.call(this,this.listenerTree,[],null,e):t?a(t):[]},A.prototype.listenerCount=function(e){return this.listeners(e).length},A.prototype.hasListeners=function(e){if(this.wildcard){var i=[],n="string"==typeof e?e.split(this.delimiter):e.slice();return L.call(this,i,n,this.listenerTree,0),i.length>0}var r=this._events,s=this._all;return!!(s&&s.length||r&&(e===t?a(r).length:r[e]))},A.prototype.listenersAny=function(){return this._all?this._all:[]},A.prototype.waitFor=function(e,i){var n=this,r=typeof i;return"number"===r?i={timeout:i}:"function"===r&&(i={filter:i}),w((i=y(i,{timeout:0,filter:t,handleError:!1,Promise:Promise,overload:!1},{filter:m,Promise:d})).Promise,(function(t,r,s){function o(){var s=i.filter;if(!s||s.apply(n,arguments))if(n.off(e,o),i.handleError){var l=arguments[0];l?r(l):t(u.apply(null,arguments).slice(1))}else t(u.apply(null,arguments))}s((function(){n.off(e,o)})),n._on(e,o,!1)}),{timeout:i.timeout,overload:i.overload})};var O=A.prototype;Object.defineProperties(A,{defaultMaxListeners:{get:function(){return O._maxListeners},set:function(e){if("number"!=typeof e||e<0||Number.isNaN(e))throw TypeError("n must be a non-negative number");O._maxListeners=e},enumerable:!0},once:{value:function(e,t,i){return w((i=y(i,{Promise:Promise,timeout:0,overload:!1},{Promise:d})).Promise,(function(i,n,r){var s;if("function"==typeof e.addEventListener)return s=function(){i(u.apply(null,arguments))},r((function(){e.removeEventListener(t,s)})),void e.addEventListener(t,s,{once:!0});var o,l=function(){o&&e.removeListener("error",o),i(u.apply(null,arguments))};"error"!==t&&(o=function(i){e.removeListener(t,l),n(i)},e.once("error",o)),r((function(){o&&e.removeListener("error",o),e.removeListener(t,l)})),e.once(t,l)}),{timeout:i.timeout,overload:i.overload})},writable:!0,configurable:!0}}),Object.defineProperties(O,{_maxListeners:{value:10,writable:!0,configurable:!0},_observers:{value:null,writable:!0,configurable:!0}}),e.exports=A}();var i=t.exports;global?(global.salla=global.salla||global.Salla||{},global.Salla=global.salla):(window.salla=window.salla||window.Salla||{},window.Salla=window.salla),Salla.event=new class extends i{constructor(){super({wildcard:!0,delimiter:"::",newListener:!1,removeListener:!1,maxListeners:10,verboseMemoryLeak:!1,ignoreErrors:!1}),this.globalListners={},this.delimiter="::",this.body=document.querySelector("body"),this.logableEvents=["cart::item.added.failed","cart::item.deleted.failed"],this.ingoreLogEvents=["document::click","document::keyup","document::change"],this.noneFireableActions=["document.request"],this.on("twilight::initiated",this.initiateSallaInAllClasses)}initiateSallaInAllClasses(){let e=this;Object.keys(salla).forEach((t=>{"object"==typeof(t=salla[t])&&(e.callSallaInitiate(t),Object.keys(t).forEach((i=>{e.callSallaInitiate(t[i])})))}))}callSallaInitiate(e){e&&e.sallaInitiated&&!e.initiated&&(e.sallaInitiated(),e.initiated=!0)}createAndDispatch(e,...t){this.dispatch(e,...t)}dispatch(e,...t){let i=e.replace("::",".");if(!this.noneFireableActions.includes(i)&&void 0!==salla.call&&"function"==typeof salla.call(i))return salla.log(`'salla.${i}(...)' triggered using event '${e}'`),i=i.split("."),void salla[i[0]][i[1]](...t);this.emit(e,...t),"undefined"!=typeof window&&(window.dataLayer=window.dataLayer||[],window.dataLayer.push(Object.assign({event:e},...t.values()))),this.ingoreLogEvents.includes(e)||!salla.config.get("debug")&&!this.logableEvents.includes(e)||void 0===salla.logger||salla.logger.event(e,...t);let n=this;Object.keys(this.globalListners).forEach((function(i){n.globalListners[i](e,...t)})),this.dispatchMobileEvent(e,{...t.values()})}dispatchEvents(e){if(e&&"object"==typeof e)for(const[t,i]of Object.entries(e))this.dispatch(t,i);else salla.log("No Events To Dispatch!",e)}addListener(e,t){this.on(e,t)}addEventListener(e,t){this.addListener(e,t)}listen(e,t){this.addListener(e,t)}registerGlobalListener(e,t){this.globalListners[e]=t}dispatchMobileEvent(e,t={}){if(!("undefined"!=typeof window&&window.dataLayer&&dataLayer[0]&&dataLayer[0].page&&dataLayer[0].page.mobileApp))return"";if(window.webkit)try{window.webkit.messageHandlers.callbackHandler.postMessage(JSON.stringify({event:e,details:t}))}catch(e){salla.log(e,"The native context does not exist yet")}else if(Android)try{Android.customEventWithData(e,JSON.stringify({details:t}))}catch(e){salla.log(e,"The native context does not exist yet")}}}; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@salla.sa/event", | ||
"version": "1.0.15", | ||
"version": "1.0.16", | ||
"description": "Twilight events", | ||
@@ -5,0 +5,0 @@ "main": "dist/cjs/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
321812
267