(function (){ var FWDMEventDispatcher = function (){ this.listeners = {events_ar:[]}; this.addListener = function (type, listener){ if(type == undefined) throw Error("type is required."); if(typeof type === "object") throw Error("type must be of type String."); if(typeof listener != "function") throw Error("listener must be of type Function."); var event = {}; event.type = type; event.listener = listener; event.target = this; this.listeners.events_ar.push(event); }; this.dispatchEvent = function(type, props){ if(this.listeners == null) return; if(type == undefined) throw Error("type is required."); if(typeof type === "object") throw Error("type must be of type String."); for (var i=0, len=this.listeners.events_ar.length; i < len; i++){ if(this.listeners.events_ar[i].target === this && this.listeners.events_ar[i].type === type){ if(props){ for(var prop in props){ this.listeners.events_ar[i][prop] = props[prop]; } } this.listeners.events_ar[i].listener.call(this, this.listeners.events_ar[i]); } } }; this.removeListener = function(type, listener){ if(type == undefined) throw Error("type is required."); if(typeof type === "object") throw Error("type must be of type String."); if(typeof listener != "function") throw Error("listener must be of type Function." + type); for (var i=0, len=this.listeners.events_ar.length; i < len; i++){ if(this.listeners.events_ar[i].target === this && this.listeners.events_ar[i].type === type && this.listeners.events_ar[i].listener === listener ){ this.listeners.events_ar.splice(i,1); break; } } }; /* destroy */ this.destroy = function(){ this.listeners = null; this.addListener = null; this.dispatchEvent = null; this.removeListener = null; }; }; window.FWDMEventDispatcher = FWDMEventDispatcher; }(window));