2021-06-29 02:54:54 +03:00
|
|
|
// Acts as a public static class
|
|
|
|
class Util {
|
2021-07-11 13:40:48 +03:00
|
|
|
/** Returns elementOrElementId if the argument is already an element, otherwise it finds
|
|
|
|
* the element by its ID (given by the argument) and returns it
|
|
|
|
*
|
|
|
|
* @param {*} elementOrElementId The element to return, or the ID of the element to return
|
|
|
|
* @returns The desired element
|
|
|
|
*/
|
2021-06-29 02:54:54 +03:00
|
|
|
static getElement(elementOrElementId) {
|
2021-07-10 12:05:56 +03:00
|
|
|
if (typeof(elementOrElementId) == "object") {
|
|
|
|
return elementOrElementId;
|
|
|
|
}
|
|
|
|
else if (typeof(elementOrElementId) == "string") {
|
|
|
|
return document.getElementById(elementOrElementId);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
console.log("Type not supported: " + typeof(elementOrElementId));
|
|
|
|
}
|
2021-06-29 02:54:54 +03:00
|
|
|
}
|
2021-07-11 13:40:48 +03:00
|
|
|
|
|
|
|
// Returns the text content of the element with ID elementId
|
2021-06-29 02:54:54 +03:00
|
|
|
static getText(elementId) {
|
2021-07-10 12:05:56 +03:00
|
|
|
return Util.getElement(elementId).textContent;
|
2021-06-29 02:54:54 +03:00
|
|
|
}
|
2021-07-11 13:40:48 +03:00
|
|
|
// Sets the text content of the element with ID elementId
|
2021-06-29 02:54:54 +03:00
|
|
|
static setText(elementId, text) {
|
2021-07-10 12:05:56 +03:00
|
|
|
Util.getElement(elementId).textContent = text;
|
2021-06-29 02:54:54 +03:00
|
|
|
}
|
2021-07-11 13:40:48 +03:00
|
|
|
|
|
|
|
// Gets the value of the element with ID elementId
|
2021-06-29 02:54:54 +03:00
|
|
|
static getValue(elementId) {
|
2021-07-10 12:05:56 +03:00
|
|
|
return Util.getElement(elementId).value;
|
2021-06-29 02:54:54 +03:00
|
|
|
}
|
2021-07-11 13:40:48 +03:00
|
|
|
// Sets the value of the element with ID elementId
|
2021-06-29 02:54:54 +03:00
|
|
|
static setValue(elementId, value) {
|
2021-07-10 12:05:56 +03:00
|
|
|
Util.getElement(elementId).value = value;
|
2021-06-29 02:54:54 +03:00
|
|
|
}
|
2021-07-11 13:40:48 +03:00
|
|
|
|
2021-06-29 02:54:54 +03:00
|
|
|
//add class .selected to specified element
|
|
|
|
static select(elementId) {
|
2021-07-10 12:05:56 +03:00
|
|
|
Util.getElement(elementId).classList.add('selected');
|
2021-06-29 02:54:54 +03:00
|
|
|
}
|
|
|
|
//remove .selected class from specified element
|
|
|
|
static deselect(elementId) {
|
2021-07-10 12:05:56 +03:00
|
|
|
Util.getElement(elementId).classList.remove('selected');
|
2021-06-29 02:54:54 +03:00
|
|
|
}
|
|
|
|
//toggle the status of the .selected class on the specified element
|
|
|
|
static toggle(elementId) {
|
2021-07-10 12:05:56 +03:00
|
|
|
Util.getElement(elementId).classList.toggle('selected');
|
2021-06-29 02:54:54 +03:00
|
|
|
}
|
|
|
|
}
|