-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathObjectEventTarget.min.js
6 lines (5 loc) · 5.02 KB
/
ObjectEventTarget.min.js
1
2
3
4
5
6
//! ObjectEventTarget - v1.3.1 - 2015-06-08
//* https://github.com/gartz/ObjectEventTarget/
//* Copyright (c) 2015 Gabriel Reitz Giannattasio <[email protected]>; Licensed
var ObjectEventTarget = {options: {VERSION: '1.3.1'}};
var ObjectEventTarget={options:{VERSION:"1.3.1"}};!function(a){"use strict";function b(a,b){if("string"!=typeof a||0===a.length)throw new TypeError("Type must be a string and can't be empty");if("function"!=typeof b)throw new TypeError("Callback must be a function")}function c(a,c,d){return b(c,d),n.has(a)?n.get(a)[c]?void n.get(a)[c].push(d):void(n.get(a)[c]=[d]):void n.set(a,new k(c,d))}function d(a,c,d){if(b(c,d),n.has(a)){var e=n.get(a),f=e[c];if(f){var g=f.indexOf(d);if(-1!==g){for(;-1!==g;)f.splice(g,1),g=f.indexOf(d);0===f.length&&delete e[c];for(var h in e)if(e.hasOwnProperty(h))return;n["delete"](a)}}}}function e(a,b){function c(a){a.eventPhase=f,a.cancelable=i,a.returnValue=h,a.defaultPrevented=!h,a.type=j,a.stack=m,a.target=o,a.currentTarget=p,a.bubbles=k,a.cancelBubble=l}if(!b||"string"!=typeof b.type)throw new TypeError("Illegal invocation");g.prototype.initEvent.call(b);var d=n.get(a);if(!d)return!0;var e=d[b.type];if(!e)return!0;var f=g.prototype.AT_TARGET;if(b.stack.length>0){if(!b.bubbles)return!0;if(b.cancelBubble)return!0;if(-1!==b.stack.indexOf(a))return!0;f=g.prototype.BUBBLING_PHASE}b.stack.push(a);var h=!0,i=!!b.cancelable,j=b.type,k=b.bubbles,l=b.cancelBubble,m=b.stack,o=m[m.length-1],p=m[0];e=e.slice();try{for(var q=0,r=e.length;r>q;q++)if(c(b),e[q].call(a,b),h=h&&!(i&&b.defaultPrevented),b.immediatePropagationStopped)return h}catch(s){setTimeout(function(){throw s})}return b.eventPhase=g.prototype.NONE,h}function f(){function a(a){if(a===f.prototype)throw new TypeError("Illegal invocation")}if(f.prototype.constructor===f)throw new TypeError("Illegal constructor");this.constructor=f,this.addEventListener=function(b,d){a(this),c(this,b,d)},this.removeEventListener=function(b,c){a(this),d(this,b,c)},this.dispatchEvent=function(b){return a(this),e(this,b)}}function g(a,b){if(0===arguments.length)throw new TypeError("Failed to construct 'ObjectEvent': An event name must be provided.");b=b||{},this.timeStamp=Date.now(),this.cancelable=b.cancelable===!0,this.bubbles=b.bubbles===!0,"undefined"!=typeof b.detail&&(this.detail=b.detail),this.eventPhase=g.prototype.NONE,this.stack=[],this.immediatePropagationStopped=!1,this.cancelBubble=!1,this.defaultPrevented=!1,this.returnValue=!0,this.type=String(a)}var h=a.ObjectEventTarget?a.ObjectEventTarget.options:{},i=a.DEBUG||h.DEBUG,j=h.VERSION||"development",k=h.EventsMap;k||(k=function(a,b){this[a]=[b]},k.prototype=Object.prototype);var l=h.WeakMap||a.WeakMap;if(!l){l=function(){this.map=[]};var m=function(a,b){for(var c=a.length-1,d=c;d>=0;d--)if(a[d].key===b){if(d!==c){var e=a.splice(d,1);a.push(e[0])}return a[c]}};l.prototype={get:function(a){var b=m(this.map,a);return b&&b.value},set:function(a,b){var c=m(this.map,a);c?c.value=b:this.map.push({key:a,value:b})},has:function(a){return!!m(this.map,a)},"delete":function(a){var b=m(this.map,a);b&&this.map.pop()}}}var n=new l;if(f.prototype=Object.prototype,f.prototype=new f,g.prototype.NONE=0,g.prototype.AT_TARGET=2,g.prototype.BUBBLING_PHASE=3,g.prototype.initEvent=function(){if(this.timeStamp=this.timeStamp||Date.now(),this.cancelable=this.cancelable===!0,this.eventPhase=g.prototype.NONE,!this.stack||!this.stack.push)try{this.stack=[]}catch(a){}if(this.immediatePropagationStopped=this.immediatePropagationStopped===!0,this.cancelBubble=this.cancelBubble===!0,this.defaultPrevented=this.cancelable&&this.defaultPrevented===!0,this.returnValue=!0,this.type=String(this.type),!(this instanceof g)){if(!this.hasOwnProperty("preventDefault")){var b=this.preventDefault;"function"!=typeof b&&(b=function(){}),this.preventDefault=function(){b.apply(this,arguments),g.prototype.preventDefault.apply(this,arguments)}}if(!this.hasOwnProperty("stopPropagation")){var c=this.stopPropagation;"function"!=typeof stopPropagation&&(c=function(){}),this.stopPropagation=function(){c.apply(this,arguments),g.prototype.stopPropagation.apply(this,arguments)}}if(!this.hasOwnProperty("stopImmediatePropagation")){var d=this.stopImmediatePropagation;"function"!=typeof stopImmediatePropagation&&(d=function(){}),this.stopImmediatePropagation=function(){d.apply(this,arguments),g.prototype.stopImmediatePropagation.apply(this,arguments)}}}},g.prototype.preventDefault=function(){this.defaultPrevented=!!this.cancelable},g.prototype.stopPropagation=function(){this.cancelBubble=!!this.bubbles},g.prototype.stopImmediatePropagation=function(){this.immediatePropagationStopped=!0},Object.defineProperties){var o=function(a){var b={};for(var c in a)a.hasOwnProperty(c)&&(b[c]={value:a[c],enumerable:!1});return[a,b]};Object.defineProperties.apply(Object,o(g.prototype)),Object.defineProperties.apply(Object,o(f.prototype))}f.VERSION=j,a.ObjectEventTarget=f,a.ObjectEvent=g,f.DEBUG=i,i&&(f.__debug={EventsMap:k,typeErrors:b,WeakMap:l,map:n}),"undefined"!=typeof module&&"undefined"!=typeof module.exports&&(module.exports={ObjectEventTarget:f,ObjectEvent:g})}(this);