2018-08-14 12:11:49 +00:00
|
|
|
/*
|
|
|
|
* noVNC: HTML5 VNC client
|
|
|
|
* Copyright 2017 Pierre Ossman for Cendio AB
|
|
|
|
* Licensed under MPL 2.0 (see LICENSE.txt)
|
|
|
|
*
|
|
|
|
* See README.md for usage and integration instructions.
|
|
|
|
*/
|
|
|
|
|
|
|
|
var EventTargetMixin = {
|
2018-08-27 12:30:50 +00:00
|
|
|
_listeners: null,
|
2018-08-14 12:11:49 +00:00
|
|
|
|
2018-08-27 12:30:50 +00:00
|
|
|
addEventListener: function(type, callback) {
|
2018-08-14 12:11:49 +00:00
|
|
|
if (!this._listeners) {
|
|
|
|
this._listeners = new Map();
|
|
|
|
}
|
|
|
|
if (!this._listeners.has(type)) {
|
|
|
|
this._listeners.set(type, new Set());
|
|
|
|
}
|
|
|
|
this._listeners.get(type).add(callback);
|
|
|
|
},
|
|
|
|
|
2018-08-27 12:30:50 +00:00
|
|
|
removeEventListener: function(type, callback) {
|
2018-08-14 12:11:49 +00:00
|
|
|
if (!this._listeners || !this._listeners.has(type)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this._listeners.get(type).delete(callback);
|
|
|
|
},
|
|
|
|
|
2018-08-27 12:30:50 +00:00
|
|
|
dispatchEvent: function(event) {
|
2018-08-14 12:11:49 +00:00
|
|
|
if (!this._listeners || !this._listeners.has(event.type)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
this._listeners.get(event.type).forEach(function (callback) {
|
|
|
|
callback.call(this, event);
|
|
|
|
}, this);
|
|
|
|
return !event.defaultPrevented;
|
2018-08-27 12:30:50 +00:00
|
|
|
},
|
2018-08-14 12:11:49 +00:00
|
|
|
};
|
|
|
|
|
2018-08-27 12:30:50 +00:00
|
|
|
export default EventTargetMixin;
|