GT2/GT2-Android/node_modules/min-document/event/dispatch-event.js

32 lines
625 B
JavaScript
Raw Normal View History

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)
}
}