2022-07-08 22:12:05 +02:00
|
|
|
import Log from "./Log.js";
|
2022-10-15 18:46:49 +02:00
|
|
|
import StringUtil from "./StringUtil.js";
|
2022-07-08 22:12:05 +02:00
|
|
|
|
|
|
|
export default class Event {
|
|
|
|
|
|
|
|
static click(selector, callback) {
|
2022-10-15 18:46:49 +02:00
|
|
|
this._addEvent('click', selector, callback)
|
|
|
|
}
|
|
|
|
|
|
|
|
static change(selector, callback) {
|
|
|
|
this._addEvent('change', selector, callback)
|
|
|
|
}
|
|
|
|
|
|
|
|
static _addEvent(eventName, selector, callback) {
|
|
|
|
Log.debug(`Adding event: ${eventName} to: ${selector}`);
|
|
|
|
document.addEventListener(eventName, (event) => {
|
2022-07-08 22:12:05 +02:00
|
|
|
if (!event.target.matches(selector)) return;
|
2022-10-15 18:46:49 +02:00
|
|
|
Log.debug(`${StringUtil.capitalizeFirstLetter(eventName)} on: ${selector}`);
|
2022-07-08 22:12:05 +02:00
|
|
|
callback(event.target);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|