/*! * eventful v0.4.1 * https://github.com/AlphaHydrae/eventful * * Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php * Alpha Hydrae (hydrae.alpha@gmail.com) */(function(a){function b(){this._callbacks={}}function c(a,b,c,d){f(b),this.emitter=a,this.callback=b,this.eventName=c,this.scope=d&&d.scope?d.scope:undefined,this.once=d?!!d.once:undefined,this.klass=d?!!d.klass:undefined}function d(a,b){this.emitter=a,this.eventName=b}function e(a){if(typeof a!="string"||!a.match(/^\w+$/i))throw new Error("Event names must be non-empty word strings.")}function f(a){if(typeof a!="function")throw new Error("Event callbacks must be functions.")}function g(a){if(typeof a!="undefined"&&typeof a!="string")throw new Error("Namespaces must be strings.")}function h(a,b){for(var c in a.prototype)c.match(/^_?[a-z]/)&&(b.prototype[c]=a.prototype[c])}function i(a,b){this._emitter=a,this._namespace=b,this._callbacks=this._emitter._callbacks}function j(a,b,d,e,f){c.call(this,b,d,e,f),this.namespace=a}function k(a,b,c){d.call(this,b,c),this.namespace=a}"use strict",b.prototype.on=function(a,b,c){e(a);if(typeof b=="undefined"&&typeof c=="undefined"){var d=[];return this._eachCallback(a,function(a){d.push(a.callback)}),d}return this._callbacks[a]||(this._callbacks[a]=[]),this._callbacks[a].push(this._wrapCallback(b,a,c)),this},b.prototype.off=function(a,b){if(typeof a=="undefined"){for(var c in this._callbacks)this._callbacks.hasOwnProperty(c)&&this._removeAllCallbacks(c);return this}return this._callbacks[a]?typeof b=="undefined"?(this._removeAllCallbacks(a),this):(this._eachCallback(a,function(c,d){if(c.callback===b)return this._callbacks[a].splice(d,1),-1}),this._callbacks[a].length<=0&&this._removeAllCallbacks(a),this):this},b.prototype.emit=function(a){var b=Array.prototype.slice.call(arguments,1);return this._fireCallbacks(this._wrapEvent(a),b),this},b.prototype.namespace=function(a){return g(a),a&&a.length?new i(this,a):this},b.prototype._fireCallbacks=function(a,b){this._eachCallback(a.eventName,function(c,d){a.shouldFire(c)&&c.shouldBeFired(a)&&c.callIt.apply(c,b)})},b.prototype._eachCallback=function(a,b){if(!this._callbacks[a])return this;var c=null,d=this._callbacks[a].length;for(var e=0;e