-
Notifications
You must be signed in to change notification settings - Fork 1
/
evented.min.js
4 lines (4 loc) · 1.54 KB
/
evented.min.js
1
2
3
4
var Evented={v:.45,events:{},events_once:{},filters:{},filters_once:{},stop:!1,debug:!1,on:function(a,c,b,d){"object"!=typeof Evented.events[a]&&(Evented.events[a]={});if(!d)for(b=b?b:50;"function"==typeof Evented.events[a][b];)b++;Evented.events[a][b]=c;this.debug&&console.log("Evented.on",arguments);return Evented},off:function(a,c){c?delete Evented.events[a][c]:delete Evented.events[a]},trigger:function(a,c,b,d,g){Evented._run_functions(!1,a,c,b,d,g);this.debug&&console.log("Evented.trigger",arguments)},
filter:function(a,c,b){this.debug&&console.log("Evented.filter",arguments);return Evented.has_filters(a)?Evented._run_functions(!0,a,c,b,!1,!0):c[0]},has_filters:function(a){for(var c in Evented.filters[a])return!0;return!1},add_filter:function(a,c,b,d){"object"!=typeof Evented.filters[a]&&(Evented.filters[a]={});if(!d)for(b=b?b:50;"function"==typeof Evented.filters[a][b];)b++;Evented.filters[a][b]=c;this.debug&&console.log("Evented.add_filter",arguments)},remove_filter:function(a,c){c?delete Evented.filters[a][c]:
delete Evented.filters[a];this.debug&&console.log("Evented.remove_filter",arguments);return!0},_run_functions:function(a,c,b,d,g){Evented.stop=!1;var e=a?Evented.filters:Evented.events;if(e[c]){"undefined"==typeof b&&(b=[]);0==a&&b.unshift({type:"Evented"});for(var k=Object.keys(e[c]),h=0;h<k.length;h++){var f=k[h];if("function"==typeof e[c][f])try{g?setTimeout(function(){e[c][f].apply(d,b)},0):0==Evented.stop&&(a?(filtered=e[c][f].apply(d,b),"undefined"!==typeof filtered&&(b[1]=filtered)):e[c][f].apply(d,
b))}catch(l){}}return a?b[1]:!0}}};