summaryrefslogtreecommitdiffstats
path: root/assets/js/settings.js
blob: 9a76ea523bfde8393c76fca30dffe9b6242d4a40 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// settings.js -- TODO

async function setLanguage(langCode)  {
    localforage.setItem("chosenLang", langCode).then((value) => {
        console.log("Language set: " + value);
        UIAlert(D("languageSet"), "setLanguage(): languageSet");
    });
}

async function setTheme(targetTheme) {
    localforage.setItem("targetTheme", targetTheme).then((value) => {
        console.log("Theme set: " + value);
        UIAlert(D("themeSet"), "setTheme(): themeSet");
    });
}

document.addEventListener("DOMContentLoaded", async () => {

    $("#select-language").on("change", () => {
        let languageToSet = $(this).find(":selected").data("language");
        setLanguage(languageToSet);
    });

    $("#select-theme").on("change", () => {
        let themeToSet = $(this).find(":selected").data("theme");
        setTheme(themeToSet);
    });

    localforage.getItem("chosenLang").then((value) => {
        let selectedLanguage = value ?? "sl";
        $(`#option-${selectedLanguage}`).attr("selected", true);
    }).catch(() => {});

    localforage.getItem("theme").then((value) => {
        let selectedTheme = value ?? "themeLight";
        $(`#option-${selectedTheme}`).attr("selected", true);
    }).catch(() => {});

    // Setup side menu
    const menus = document.querySelectorAll(".side-menu");
    M.Sidenav.init(menus, { edge: "right", draggable: true });

    // Setup language select dropdown
    var elems = document.querySelectorAll('select');
    M.FormSelect.init(elems, {});
});