MaketTahta/assets/js/initialize.js

121 lines
2.6 KiB
JavaScript
Raw Normal View History

2023-10-26 01:26:55 +03:00
// 2023 © Aliberk Sandıı
// Initialize Variables / Arrays / Maps and first functions
// Import after utils, updates, and mid js files!
// CONSTANT VARIABLES
const allButtons = [
"timers-button",
"yemekhane-button",
"ders-programi",
"animation-button",
"settings-button",
"stopwatch-button",
"timer-button"
];
const allCheckboxes = [
"chx-clockSecond",
"chx-timerMsec",
"chx-devVersion",
"chx-yksTimer",
"chx-fullscreenClock",
"chx-hideHeader",
];
const midItems = ["timers", "yemek-listesi", "animations", "ders-programi"];
const timersItems = ["stopwatch", "timer"];
const schoolPeriods = {
["lessonStarts"]: ["08-40", "09-30", "10-20", "11-10", "12-00", "13-30", "14-20", "15-10"],
["lessonEnds"]: ["09-20", "10-10", "11-00", "11-50", "12-40", "14-10", "15-00", "15-50"],
};
// VARIABLES
var specialPeriods = {
["launchStart"]: "12-40",
["schoolEnds"]: "15-50",
};
var localSettings = {
["local-grade"]: "Sınıf",
["local-class"]: "Şube",
}
var curVals = [
"clockSecond",
"timerMsec",
"devVersion",
"yksTimer",
"fullscreenClock",
"hideHeader",
]
var curSeconds;
var curMin;
var curHour;
const confs = new Map();
FirstInitialization();
var t = setInterval(DEVupdateSettings, 100);
var t2 = setInterval(updateComponents, 100);
function FirstInitialization() {
getVariablesToConfig();
getFormInputs();
getURLSettings();
updateFormInputs();
// Update Beginning Components
console.log(confs.get("local-grade"));
setToID("grade", confs.get("local-grade"), "Sınıf");
setToID("class", confs.get("local-class"), "Şube");
updateComponents();
}
function getVariablesToConfig() {
addObjectToConfig(localSettings, 1);
}
function getFormInputs() {
allCheckboxes.forEach(element => {
let chx = document.getElementById(element);
if (chx.checked) {
confs.set(element.slice(4), "1");
} else {
confs.set(element.slice(4), "0");
}
});
}
function getURLSettings() {
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
addArrayToConfig(allCheckboxes, urlParams);
addArrayToConfig(curVals, urlParams);
addObjectToConfig(localSettings, urlParams);
addObjectToConfig(specialPeriods, urlParams);
}
/**
* Update form inputs with local variables and user changed options
*/
function updateFormInputs() {
confs.forEach((val, key) => {
if (allCheckboxes.includes("chx-" + key)) {
if (val == "0") {
document.getElementById("chx-" + key).checked = false;
} else {
document.getElementById("chx-" + key).checked = true;
}
}
});
}