excav_demo-light / langNav.js
cm107's picture
Made it so that the style of the language buttons change after being clicked.
f33e4d0
raw
history blame
1.24 kB
const langNavMap = {
"langBtnEng": "info_eng.html",
"langBtnJp": "info_jp.html"
};
function load_info(path) {
fetch(path /*, options */)
.then((response) => {
return response.text();
}
)
.then((html) => {
document.getElementById("infoBox").innerHTML = html;
})
.catch((error) => {
console.warn(error);
});
}
var langNavigator = document.getElementById('langNavigator');
for (let ele of langNavigator.children) {
if (ele.tagName == "BUTTON") {
ele.addEventListener(
'mouseup',
(e) => {
for (let btn of document.getElementsByClassName('activeLangBtn')) {
btn.className = 'nonactiveLangBtn';
}
let path = langNavMap[ele.id];
console.log("Loading " + path);
load_info(path);
ele.className = 'activeLangBtn';
}
);
}
}
for (let ele of langNavigator.children) {
if (ele.tagName == "BUTTON" && ele.className == "activeLangBtn") {
let path = langNavMap[ele.id];
console.log("Loading " + path);
load_info(path);
break;
}
}