pixel-editor/js/Input.js
unsettledgames 4457d2178c Added Input.js
Got rid of the "on" files, refactored the rest of the code to use the functions declared in Input.js
2021-07-12 11:36:30 +02:00

26 lines
983 B
JavaScript

class Input {
static on(event, elementId, functionCallback, ...args) {
//if element provided is string, get the actual element
const element = Util.getElement(elementId);
element.addEventListener(event,
function (e) {
// e = event
//this = element clicked
functionCallback(e, this, args);
//if you need to access the event or this variable, you need to add them
//when you define the callback, but you cant use the word this, eg:
//on('click', menuButton, function (e, button) {});
});
}
static onChildren(event, parentElement, functionCallback, ...args) {
parentElement = Util.getElement(parentElement);
const children = parentElement.children;
//loop through children and add onClick listener
for (var i = 0; i < children.length; i++) {
on(event, children[i], functionCallback, args);
}
}
}