minsky-kit
Version:
Kit of components for MINSKY web agency
56 lines (44 loc) • 1.32 kB
JavaScript
// imports
import Base from '../core/Base';
// static properties
let id = 0;
// class definition
export default class Event extends Base {
// constructor
constructor (args = {}, objectName = 'Event') {
// call super constructor
super(args, objectName);
this.id = id++;
this.type = args.type;
this.currentTarget = args.currentTarget;
this.data = args.data || {};
this.timestamp = Date.now();
this._defaultPrevented = false;
this._allDefaultPrevented = false;
}
// methods
preventDefault () {
this._defaultPrevented = true;
// check if data contains originalEvent
// if so => push prevent default to that instance as well
if (this.data.originalEvent && this.data.originalEvent.preventDefault) {
this.data.originalEvent.preventDefault();
}
}
preventAllDefaults () {
this.preventDefault();
this._allDefaultPrevented = true;
}
destroy () {
// remove all references
// this.currentTarget = this.data = null;
super.destoy();
}
// getters & setters
get defaultPrevented () {
return this._defaultPrevented;
}
get allDefaultPrevented () {
return this._allDefaultPrevented;
}
}