/** * @license MIT * taksim.io/emitter v0.2.2 * https://github.com/taksim-io/emitter * Copyright (c) 2015 taksim.io */ !function(t,n){if("function"==typeof define&&define.amd)define(n);else if("object"==typeof exports)module.exports=n(t);else{var e=n(t);t.Emitter||(t.Emitter=e),t.taksim||(t.taksim={}),t.taksim.Emitter=e}}(this,function(){"use strict";function t(t){return t?o(t,l):void 0}function n(t,n,e){return function i(){t.off(n,i),e.apply(t,arguments)}}function e(t,n,e){t[n]=function(){t[n]=e}}function i(t,n,e){for(var i in e)e.hasOwnProperty(i)&&t[n](i,e[i])}function r(t){return t._t||(t._t={}),t._t[u]||(t._t[u]={})}function o(t){var n=arguments.length;t||(t={});for(var e=1;n>e;e++){var i=arguments[e];if(i)for(var r in i)i.hasOwnProperty(r)&&(t[r]=i[r])}return t}function f(t,n){var e=t.prototype,i=function(){this.constructor=t};i.prototype=n.prototype,t.prototype=new i,t.__super__=n.prototype,o(t.prototype,e)}var s=1,u="emitter",l=t.prototype;return l.emit=function(t){var n,e=r(this).listeners,i=[].slice.call(arguments,1);if(e&&e[t]){var o=e[t];if("function"==typeof o)n=o.apply(this,i);else{var f=o.length;o=o.slice();for(var s=0;f>s&&(n=o[s].apply(this,i),n!==!1);s++);}}return n},l.on=function(t,n){if("object"==typeof t)i(this,"on",t);else if("function"==typeof n){var e=t.split(" "),o=e.length,f=r(this),s=f.listeners;for(s||(s=f.listeners={});o--;){var u=e[o];"function"!=typeof s[u]&&(s[u]||(s[u]=[]),s[u].push(n))}}return this},l.once=function(t,e){if("object"==typeof t)i(this,"once",t);else if("function"==typeof e)for(var r=t.split(" "),o=r.length;o--;)this.on(t,n(this,r[o],e));return this},l.only=function(t,n){if("object"==typeof t)i(this,"only",t);else if("function"==typeof n){var e=t.split(" "),o=e.length,f=r(this),s=f.listeners;for(s||(s=f.listeners={});o--;){var u=e[o];"function"!=typeof s[u]&&(s[u]=n)}}return this},l.off=function(t,e){var i=arguments.length,o=r(this),f=o.listeners;if(!f)return this;if(0===i)o.listeners=null;else if(f[t])if(1!==i&&e&&"function"!=typeof f[t])for(var s=f[t],u=s.length,l=0;u>l;l++){var c=String(s[l]);if(c===String(e)||c===String(n(this,t,e))){s.splice(l,1);break}}else f[t]=null;else{var a=t.split(" "),p=a.length;if(p>1)for(;p--;)this.off(a[p],e)}return this},l.offence=function(t,i){var o,f=arguments.length,s=r(this),u=s.listeners;if(!u)return this;if(0===f)for(var l in u)u.hasOwnProperty(l)&&this.offence(l);else if(u[t])if(1!==f&&i&&"function"!=typeof o){if(i){o=u[t];for(var c=o.length,a=0;c>a;a++){var p=String(o[a]);if(p===String(i)||p===String(n(this,t,i))){e(o,a,o[a]);break}}}}else o=u[t],"function() {on[event] = callbacks;}"!==String(o)&&(u[t]=function(){u[t]=o});else{var h=t.split(" "),y=h.length;if(y>1)for(;y--;)this.offence(h[y],i)}return this},l.getListeners=function(t){return(r(this).listeners||{})[t]||[]},l.hasListeners=function(t){return!!this.getListeners(t).length},l._tid=function(){var t=this;return t._t||(t._t={}),t._t.tid||(t._t.tid=s++)},t.extend=function(t,n){"function"!=typeof t&&(n=t,t=null);var e,i=this;return e=t?t:function(){return i.apply(this,arguments)},f(e,i),o(e,i),o(e.prototype,n),e},t.mixin=o,t});