idealista-enhancer/src/Event.js
Jorge Bolois Guerrero 9098f42a93 WIP - Information for locations.
Better configuration menu.
Testing retrieving JSON from GitHub (uploading).
2022-10-15 18:46:49 +02:00

23 lines
678 B
JavaScript

import Log from "./Log.js";
import StringUtil from "./StringUtil.js";
export default class Event {
static click(selector, callback) {
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) => {
if (!event.target.matches(selector)) return;
Log.debug(`${StringUtil.capitalizeFirstLetter(eventName)} on: ${selector}`);
callback(event.target);
});
}
}