thedesk/app/node_modules/min-document/event/dispatch-event.js

32 lines
625 B
JavaScript
Raw Normal View History

2018-02-19 04:41:25 +11:00
module.exports = dispatchEvent
function dispatchEvent(ev) {
var elem = this
var type = ev.type
if (!ev.target) {
ev.target = elem
}
if (!elem.listeners) {
elem.listeners = {}
}
var listeners = elem.listeners[type]
if (listeners) {
return listeners.forEach(function (listener) {
ev.currentTarget = elem
if (typeof listener === 'function') {
listener(ev)
} else {
listener.handleEvent(ev)
}
})
}
if (elem.parentNode) {
elem.parentNode.dispatchEvent(ev)
}
}