2018-08-14 12:11:49 +00:00
|
|
|
/*
|
|
|
|
* noVNC: HTML5 VNC client
|
2020-08-11 12:05:09 +00:00
|
|
|
* Copyright (C) 2019 The noVNC Authors
|
2018-08-14 12:11:49 +00:00
|
|
|
* Licensed under MPL 2.0 (see LICENSE.txt)
|
|
|
|
*
|
|
|
|
* See README.md for usage and integration instructions.
|
|
|
|
*/
|
|
|
|
|
2019-06-24 11:26:25 +00:00
|
|
|
export default class EventTargetMixin {
|
|
|
|
constructor() {
|
|
|
|
this._listeners = new Map();
|
|
|
|
}
|
2018-08-14 12:11:49 +00:00
|
|
|
|
2019-06-24 11:26:25 +00:00
|
|
|
addEventListener(type, callback) {
|
|
|
|
if (!this._listeners.has(type)) {
|
|
|
|
this._listeners.set(type, new Set());
|
|
|
|
}
|
|
|
|
this._listeners.get(type).add(callback);
|
|
|
|
}
|
2018-08-14 12:11:49 +00:00
|
|
|
|
2019-06-24 11:26:25 +00:00
|
|
|
removeEventListener(type, callback) {
|
|
|
|
if (this._listeners.has(type)) {
|
|
|
|
this._listeners.get(type).delete(callback);
|
|
|
|
}
|
|
|
|
}
|
2018-08-14 12:11:49 +00:00
|
|
|
|
2019-06-24 11:26:25 +00:00
|
|
|
dispatchEvent(event) {
|
|
|
|
if (!this._listeners.has(event.type)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
this._listeners.get(event.type)
|
|
|
|
.forEach(callback => callback.call(this, event));
|
|
|
|
return !event.defaultPrevented;
|
|
|
|
}
|
|
|
|
}
|