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