szurubooru/client/js/events.js

40 lines
902 B
JavaScript
Raw Normal View History

"use strict";
2016-04-07 19:03:49 +02:00
class EventTarget {
constructor() {
this.eventTarget = document.createDocumentFragment();
for (let method of [
"addEventListener",
"dispatchEvent",
"removeEventListener",
]) {
this[method] = this.eventTarget[method].bind(this.eventTarget);
}
}
2020-06-04 20:09:35 +02:00
}
function proxyEvent(source, target, sourceEventType, targetEventType) {
if (!source.addEventListener) {
return;
}
if (!targetEventType) {
targetEventType = sourceEventType;
}
source.addEventListener(sourceEventType, (e) => {
target.dispatchEvent(
new CustomEvent(targetEventType, {
detail: e.detail,
})
);
});
}
2016-04-07 19:03:49 +02:00
module.exports = {
Success: "success",
Error: "error",
Info: "info",
2016-04-07 19:03:49 +02:00
proxyEvent: proxyEvent,
EventTarget: EventTarget,
2016-04-07 19:03:49 +02:00
};