final-events
Version:
Event Dispatcher with bubbling feature
2 lines • 3.56 kB
JavaScript
/*! final-events 2015-02-13 */
Object.keys||(Object.keys=function(){"use strict";var a=Object.prototype.hasOwnProperty,b=!{toString:null}.propertyIsEnumerable("toString"),c=["toString","toLocaleString","valueOf","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","constructor"],d=c.length;return function(e){if("object"!=typeof e&&("function"!=typeof e||null===e))throw new TypeError("Object.keys called on non-object");var f,g,h=[];for(f in e)a.call(e,f)&&h.push(f);if(b)for(g=0;d>g;g++)a.call(e,c[g])&&h.push(c[g]);return h}}()),Array.prototype.forEach||(Array.prototype.forEach=function(a,b){"use strict";var c,d;if(null==this)throw new TypeError("this is null or not defined");var e,f=Object(this),g=f.length>>>0;if("[object Function]"!=={}.toString.call(a))throw new TypeError(a+" is not a function");for(arguments.length>=2&&(c=b),d=0;g>d;)d in f&&(e=f[d],a.call(c,e,d,f)),d++}),Object.defineProperty||(Object.defineProperty=function(a,b,c){a[b]=c.value}),Object.defineProperties||(Object.defineProperties=function(a,b){Object.keys(b).forEach(function(c){Object.defineProperty(a,c,b[c])})}),"undefined"!=typeof window&&(window.finalEvents={}),function(a){function b(){return{"@propagationStopped":{writable:!0,value:!1},stopPropagation:{value:function(){this["@propagationStopped"]=!0}}}}a.event=function(a){return"string"==typeof a&&(a={type:a}),a["@propagationStopped"]||Object.defineProperties(a,b()),a}}("undefined"==typeof exports?this.finalEvents:exports),function(a){function b(a,b){b.hasEventListener(a)||(b["@eventListeners"][a]=[])}function c(a,c,d){if(!(c instanceof Function))throw new TypeError("eventHandler is not a function");return b(a,this),this["@eventListeners"][a].push({handler:c,useCapture:d,once:!1}),this}function d(a,c,d){return b(a,this),this["@eventListeners"][a].push({handler:c,useCapture:d,once:!0}),this}function e(a,b,c){var d=c["@eventListeners"][a];if(!d)return-1;for(var e=0;e<d.length;e+=1)if(d[e].handler===b)return e;return-1}function f(a,b){var c=this["@eventListeners"][a],d=e(a,b,this);return-1!==d&&c.splice(d,1),this}function g(a){return this["@eventListeners"][a]=[],this}function h(a){return void 0!==this["@eventListeners"][a]&&this["@eventListeners"][a].length>0}function i(b){b.currentTarget.hasEventListener(b.type)&&b.currentTarget["@eventListeners"][b.type].forEach(function(c){c.useCapture&&b.phase!==a.CAPTURE_PHASE||(c.useCapture||b.phase!==a.CAPTURE_PHASE)&&(c.handler.call(b.currentTarget,b),c.once&&b.currentTarget.removeEventListener(b.type,c.handler))})}function j(a){for(var b=[];a=a.parent;)b.push(a);return b}function k(b){var c=j(b.target);for(b.phase=a.CAPTURE_PHASE;!b["@propagationStopped"]&&c.length>0;)b.currentTarget=c.pop(),i(b)}function l(b){b["@propagationStopped"]||(b.phase=a.TARGET_PHASE,b.currentTarget=b.target,i(b))}function m(b){for(b.phase=a.BUBBLING_PHASE;!b["@propagationStopped"]&&b.currentTarget.parent;)b.currentTarget=b.currentTarget.parent,i(b)}function n(b){return b=a.event(b),b.target=this,k(b),l(b),m(b),this}function o(){return{"@eventListeners":{value:{}},addEventListener:{value:c},on:{value:c},once:{value:d},removeEventListener:{value:f},off:{value:f},removeEventListeners:{value:g},hasEventListener:{value:h},dispatchEvent:{value:n},trigger:{value:n},emit:{value:n},fire:{value:n}}}"undefined"==typeof finalEvents&&(a.event=require("./event.js").event),a.dispatcher=function(a){return a["@eventListeners"]||Object.defineProperties(a,o()),a},a.CAPTURE_PHASE=1,a.TARGET_PHASE=2,a.BUBBLING_PHASE=3}("undefined"==typeof exports?this.finalEvents:exports);