@salla.sa/event
Advanced tools
Comparing version 1.0.17 to 1.0.18
@@ -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 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=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=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 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,d,y,_,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),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===w?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 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=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}),g((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 g((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")}}},Salla.log=console.log})); | ||
*/e=t,function(t){var n=Object.hasOwnProperty,i=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 n="(node) warning: possible EventEmitter memory leak detected. "+e+" listeners added. Use emitter.setMaxListeners() to increase limit.";if(this.verboseMemoryLeak&&(n+=" Event name: "+t+"."),"undefined"!=typeof process&&process.emitWarning){var i=new Error(n);i.name="MaxListenersExceededWarning",i.emitter=this,i.count=e,process.emitWarning(i)}else console.error(n),console.trace&&console.trace()}var u=function(e,t,n){var i=arguments.length;switch(i){case 0:return[];case 1:return[e];case 2:return[e,t];case 3:return[e,t,n];default:for(var r=new Array(i);i--;)r[i]=arguments[i];return r}};function p(e,n){for(var i={},r=e.length,s=n?n.length:0,o=0;o<r;o++)i[e[o]]=o<s?n[o]:t;return i}function v(e,t,n){var i,r;if(this._emitter=e,this._target=t,this._listeners={},this._listenersCount=0,(n.on||n.off)&&(i=n.on,r=n.off),t.addEventListener?(i=t.addEventListener,r=t.removeEventListener):t.addListener?(i=t.addListener,r=t.removeListener):t.on&&(i=t.on,r=t.off),!i&&!r)throw Error("target does not implement any known event API");if("function"!=typeof i)throw TypeError("on method must be a function");if("function"!=typeof r)throw TypeError("off method must be a function");this._on=i,this._off=r;var s=e._observers;s?s.push(this):e._observers=[this]}function d(e,i,r,s){var o=Object.assign({},i);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&&!n.call(i,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("|"),n=e.length,i=e[0],r=e[1];return 1===n?function(e,n){if(typeof e===i)return e;n(t)}:2===n?function(e,n){var s=typeof e;if(s===i||s===r)return e;n(t)}:function(i,r){for(var s=typeof i,o=n;o-- >0;)if(s===e[o])return i;r(t)}}Object.assign(v.prototype,{subscribe:function(e,t,n){var i=this,r=this._target,s=this._emitter,o=this._listeners,l=function(){var i=u.apply(null,arguments),o={data:i,name:t,original:e};if(n){var l=n.call(r,o);!1!==l&&s.emit.apply(s,[o.name].concat(i))}else s.emit.apply(s,[t].concat(i))};if(o[e])throw Error("Event '"+e+"' is already listening");this._listenersCount++,s._newListener&&s._removeListener&&!i._onNewListener?(this._onNewListener=function(n){n===t&&null===o[e]&&(o[e]=l,i._on.call(r,e,l))},s.on("newListener",this._onNewListener),this._onRemoveListener=function(n){n===t&&!s.hasListeners(n)&&o[e]&&(o[e]=null,i._off.call(r,e,l))},o[e]=null,s.on("removeListener",this._onRemoveListener)):(o[e]=l,i._on.call(r,e,l))},unsubscribe:function(e){var t,n,i,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(i=(n=a(s)).length;i-- >0;)e=n[i],l.call(c,e,s[e]);this._listeners={},this._listenersCount=0,h()}}});var m=_(["function"]),b=_(["object","function"]);function g(e,t,n){var i,r,s,o=0,l=new e((function(a,c,h){function f(){r&&(r=null),o&&(clearTimeout(o),o=0)}n=d(n,{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}}),i=!n.overload&&"function"==typeof e.prototype.cancel&&"function"==typeof h;var u=function(e){f(),a(e)},p=function(e){f(),c(e)};i?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),n.timeout>0&&(o=setTimeout((function(){var e=Error("timeout");e.code="ETIMEDOUT",o=0,l.cancel(e),c(e)}),n.timeout))}));return i||(l.cancel=function(e){if(r){for(var t=r.length,n=1;n<t;n++)r[n](e);r[0](e),r=null}}),l}function w(e){var t=this._observers;if(!t)return-1;for(var n=t.length,i=0;i<n;i++)if(t[i]._target===e)return i;return-1}function L(e,t,n,i,r){if(!n)return null;if(0===i){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,g=null,w=t[i],E=t[i+1];if(i===r)n._listeners&&("function"==typeof n._listeners?(e&&e.push(n._listeners),g=[n]):(e&&e.push.apply(e,n._listeners),g=[n]));else{if("*"===w){for(l=(m=a(n)).length;l-- >0;)"_listeners"!==(p=m[l])&&(b=L(e,t,n[p],i+1,r))&&(g?g.push.apply(g,b):g=b);return g}if("**"===w){for((_=i+1===r||i+2===r&&"*"===E)&&n._listeners&&(g=L(e,t,n,r,r)),l=(m=a(n)).length;l-- >0;)"_listeners"!==(p=m[l])&&("*"===p||"**"===p?(n[p]._listeners&&!_&&(b=L(e,t,n[p],r,r))&&(g?g.push.apply(g,b):g=b),b=L(e,t,n[p],i,r)):b=L(e,t,n[p],p===E?i+2:i,r),b&&(g?g.push.apply(g,b):g=b));return g}n[w]&&(g=L(e,t,n[w],i+1,r))}if((v=n["*"])&&L(e,t,v,i+1,r),d=n["**"])if(i<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],i+2,r):p===w?L(e,t,d[p],i+1,r):((y={})[p]=d[p],L(e,t,{"**":y},i+1,r)));else d._listeners?L(e,t,d,r,r):d["*"]&&d["*"]._listeners&&L(e,t,d["*"],r,r);return g}function E(e,t,n){var i,r,s=0,o=0,l=this.delimiter,a=l.length;if("string"==typeof e)if(-1!==(i=e.indexOf(l))){r=new Array(5);do{r[s++]=e.slice(o,i),o=i+a}while(-1!==(i=e.indexOf(l,o)));r[s++]=e.slice(o)}else r=[e],s=1;else r=e,s=e.length;if(s>1)for(i=0;i+1<s;i++)if("**"===r[i]&&"**"===r[i+1])return;var c,h=this.listenerTree;for(i=0;i<s;i++)if(h=h[c=r[i]]||(h[c]={}),i===s-1)return h._listeners?("function"==typeof h._listeners&&(h._listeners=[h._listeners]),n?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,n,i){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?n:n?n.concat(s):[s],l=i||"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,n,i,r=a(e),s=r.length;s-- >0;)(t=e[n=r[s]])&&(i=!0,"_listeners"===n||j(t)||delete e[n]);return i}function T(e,t,n){this.emitter=e,this.event=t,this.listener=n}function x(e,n,i){if(!0===i)o=!0;else if(!1===i)s=!0;else{if(!i||"object"!=typeof i)throw TypeError("options should be an object or true");var s=i.async,o=i.promisify,a=i.nextTick,c=i.objectify}if(s||a||o){var h=n,f=n._origin||n;if(a&&!r)throw Error("process.nextTick is not supported");o===t&&(o="AsyncFunction"===n.constructor.name),n=function(){var e=arguments,t=this,n=this.event;return o?a?Promise.resolve():new Promise((function(e){l(e)})).then((function(){return t.event=n,h.apply(t,e)})):(a?process.nextTick:l)((function(){t.event=n,h.apply(t,e)}))},n._async=!0,n._origin=f}return[n,c?new T(this,e,n):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,n,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 n,i=r.reducers,o=w.call(s,e);n=-1===o?new v(s,e,r):s._observers[o];for(var l,c=a(t),h=c.length,f="function"==typeof i,u=0;u<h;u++)l=c[u],n.subscribe(l,t[l]||l,f?i:i&&i[l])}return r=d(r,{on:t,off:t,reducers:t},{on:m,off:m,reducers:b}),i(n)?o(p(n)):o("string"==typeof n?p(n.split(/\s+/)):n),this},A.prototype.stopListeningTo=function(e,t){var n=this._observers;if(!n)return!1;var i,r=n.length,s=!1;if(e&&"object"!=typeof e)throw TypeError("target should be an object");for(;r-- >0;)i=n[r],e&&i._target!==e||(i.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,n){return this._once(e,t,!1,n)},A.prototype.prependOnceListener=function(e,t,n){return this._once(e,t,!0,n)},A.prototype._once=function(e,t,n,i){return this._many(e,1,t,n,i)},A.prototype.many=function(e,t,n,i){return this._many(e,t,n,!1,i)},A.prototype.prependMany=function(e,t,n,i){return this._many(e,t,n,!0,i)},A.prototype._many=function(e,t,n,i,r){var s=this;if("function"!=typeof n)throw new Error("many only accepts instances of Function");function o(){return 0==--t&&s.off(e,o),n.apply(this,arguments)}return o._origin=n,this._on(e,o,i,r)},A.prototype.emit=function(){if(!this._events&&!this._all)return!1;this._events||c.call(this);var e,t,n,i,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(n=l.length,s)for(i=0;i<n;i++)if("symbol"==typeof l[i]){o=!0;break}o||(l=l.join(this.delimiter))}var h,f=arguments.length;if(this._all&&this._all.length)for(i=0,n=(h=this._all.slice()).length;i<n;i++)switch(this.event=l,f){case 1:h[i].call(this,l);break;case 2:h[i].call(this,l,arguments[1]);break;case 3:h[i].call(this,l,arguments[1],arguments[2]);break;default:h[i].apply(this,arguments)}if(a)h=[],L.call(this,h,e,this.listenerTree,0,n);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(i=0,n=h.length;i<n;i++)switch(this.event=l,f){case 1:h[i].call(this);break;case 2:h[i].call(this,arguments[1]);break;case 3:h[i].call(this,arguments[1],arguments[2]);break;default:h[i].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,n,i,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(i=l.length,s)for(r=0;r<i;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,i=this._all.length;r<i;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(n=new Array(u-1),o=1;o<u;o++)n[o-1]=arguments[o];f.push(h.apply(this,n))}else if(h&&h.length){if(h=h.slice(),u>3)for(n=new Array(u-1),o=1;o<u;o++)n[o-1]=arguments[o];for(r=0,i=h.length;r<i;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,n))}}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,n){return this._on(e,t,!1,n)},A.prototype.prependListener=function(e,t,n){return this._on(e,t,!0,n)},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,n,i,r){if("function"==typeof e)return this._onAny(e,n),this;if("function"!=typeof n)throw new Error("on only accepts instances of Function");this._events||c.call(this);var s,o=this;return r!==t&&(n=(s=x.call(this,e,n,r))[0],o=s[1]),this._newListener&&this.emit("newListener",e,n),this.wildcard?(E.call(this,e,n,i),o):(this._events[e]?("function"==typeof this._events[e]&&(this._events[e]=[this._events[e]]),i?this._events[e].unshift(n):this._events[e].push(n),!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]=n,o)},A.prototype.off=function(e,t){if("function"!=typeof t)throw new Error("removeListener only takes instances of Function");var n,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;n=this._events[e],r.push({_listeners:n})}for(var o=0;o<r.length;o++){var l=r[o];if(n=l._listeners,i(n)){for(var a=-1,c=0,h=n.length;c<h;c++)if(n[c]===t||n[c].listener&&n[c].listener===t||n[c]._origin&&n[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===n.length&&(this.wildcard?delete l._listeners:delete this._events[e]),this._removeListener&&this.emit("removeListener",e,t),this}(n===t||n.listener&&n.listener===t||n._origin&&n._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,n=0,i=0;if(e&&this._all&&this._all.length>0){for(n=0,i=(t=this._all).length;n<i;n++)if(e===t[n])return t.splice(n,1),this._removeListener&&this.emit("removeListenerAny",e),this}else{if(t=this._all,this._removeListener)for(n=0,i=t.length;n<i;n++)this.emit("removeListenerAny",t[n]);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 n,i=L.call(this,null,e,this.listenerTree,0);if(!i)return this;for(n=0;n<i.length;n++)i[n]._listeners=null;this.listenerTree&&j(this.listenerTree)}else this._events&&(this._events[e]=null);return this},A.prototype.listeners=function(e){var n,i,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=(n=a(l)).length,r=[];s-- >0;)"function"==typeof(i=l[n[s]])?r.push(i):r.push.apply(r,i);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&&(i=l[e])?"function"==typeof i?[i]:i:[]},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 n=[],i="string"==typeof e?e.split(this.delimiter):e.slice();return L.call(this,n,i,this.listenerTree,0),n.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,n){var i=this,r=typeof n;return"number"===r?n={timeout:n}:"function"===r&&(n={filter:n}),g((n=d(n,{timeout:0,filter:t,handleError:!1,Promise:Promise,overload:!1},{filter:m,Promise:y})).Promise,(function(t,r,s){function o(){var s=n.filter;if(!s||s.apply(i,arguments))if(i.off(e,o),n.handleError){var l=arguments[0];l?r(l):t(u.apply(null,arguments).slice(1))}else t(u.apply(null,arguments))}s((function(){i.off(e,o)})),i._on(e,o,!1)}),{timeout:n.timeout,overload:n.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,n){return g((n=d(n,{Promise:Promise,timeout:0,overload:!1},{Promise:y})).Promise,(function(n,i,r){var s;if("function"==typeof e.addEventListener)return s=function(){n(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),n(u.apply(null,arguments))};"error"!==t&&(o=function(n){e.removeListener(t,l),i(n)},e.once("error",o)),r((function(){o&&e.removeListener("error",o),e.removeListener(t,l)})),e.once(t,l)}),{timeout:n.timeout,overload:n.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 n=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 n{constructor(){super({wildcard:!0,delimiter:"::",newListener:!1,removeListener:!1,maxListeners:10,verboseMemoryLeak:!1,ignoreErrors:!1}),this.globalListners={},this.delimiter="::","undefined"!=typeof document&&(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((n=>{e.callSallaInitiate(t[n])})))}))}callSallaInitiate(e){e&&e.sallaInitiated&&!e.initiated&&(e.sallaInitiated(),e.initiated=!0)}createAndDispatch(e,...t){this.dispatch(e,...t)}dispatch(e,...t){let n=e.replace("::",".");if(!this.noneFireableActions.includes(n)&&void 0!==salla.call&&"function"==typeof salla.call(n))return salla.log(`'salla.${n}(...)' triggered using event '${e}'`),n=n.split("."),void salla[n[0]][n[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 i=this;Object.keys(this.globalListners).forEach((function(n){i.globalListners[n](e,...t)})),this.dispatchMobileEvent(e,{...t.values()})}dispatchEvents(e){if(e&&"object"==typeof e)for(const[t,n]of Object.entries(e))this.dispatch(t,n);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")}}},Salla.log=console.log})); | ||
//# 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(!("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")}}},Salla.log=console.log; | ||
*/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=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=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 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,d,y,_,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),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===w?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 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=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}),g((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 g((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="::","undefined"!=typeof document&&(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")}}},Salla.log=console.log; | ||
//# 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(!("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")}}},Salla.log=console.log; | ||
*/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=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=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 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,d,y,_,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),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===w?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 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=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}),g((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 g((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="::","undefined"!=typeof document&&(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")}}},Salla.log=console.log; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@salla.sa/event", | ||
"version": "1.0.17", | ||
"version": "1.0.18", | ||
"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
322394