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

32 lines
625 B
JavaScript
Raw Normal View History

2019-09-13 00:38:13 +10: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)
}
}