UNPKG

function-events-extension

Version:

Extension 'Function' prototype to be able to use event pattern

1 lines 1.51 kB
!function(n){function t(o){if(e[o])return e[o].exports;var r=e[o]={exports:{},id:o,loaded:!1};return n[o].call(r.exports,r,r.exports,t),r.loaded=!0,r.exports}var e={};return t.m=n,t.c=e,t.p="",t(0)}([function(n,t,e){e(4),e(1),e(2),e(3),n.exports=e(5)},function(n,t){Function._events||(Function._events={},Object.defineProperty(Function._events,"length",{get:function(){return Object.keys(Function._events).length}}))},function(n,t){Function.prototype.addEventListener||(Function.prototype.addEventListener=function(n){if(!n)throw new Error("Event name is required!");return this._id=this._id||idGenerator.generate(),Function._events[n]=Function._events[n]||[],Function._events[n].push({functionId:this._id,handler:this}),this})},function(n,t){Function.prototype.dispatch||(Function.prototype.dispatch=function(n){var t,e=Function._events[n]||[],o=e.length,r={name:n,args:Array.prototype.slice.call(arguments,1)};for(t=0;t<o;t++)e[t].handler(r)})},function(n,t){window.idGenerator=function(n){function t(n,t){return Math.floor(Math.random()*(t-n+1))+n}function e(){}return e.prototype.asciiPart=function(n,e){var o=t(40,126);return n=n||"",e=e||t(11,31),1===e?n:this.asciiPart(n+String.fromCharCode(o),--e)},e.prototype.generate=function(){return this.asciiPart()+"-"+n.now()},new e}(window.Date)},function(n,t){Function.prototype.removeEventListener||(Function.prototype.removeEventListener=function(n){var t,e=Function._events[n],o=e.length;for(t=0;t<o;t++)if(e[t].functionId===this._id){e.splice(t,1);break}})}]);