mirror of
https://github.com/lospec/pixel-editor.git
synced 2023-08-10 21:12:51 +03:00
![unsettledgames](/assets/img/avatar_default.png)
It includes the old _createButton and _newPixel functions and a few private methods to divide the huge newPixel function into smaller chunks depending on their purpose. Those chunks could probably be part of other IIFEs, but we'll think about that in the future. Fixed Input bug that caused the on function to pass an array of arguments instead of single arguments. Removed data_asdfgasd.hbs
26 lines
983 B
JavaScript
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, ...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);
|
|
}
|
|
}
|
|
} |