summaryrefslogtreecommitdiffstats
path: root/assets/js/settings.js
diff options
context:
space:
mode:
authorsijanec <sijanecantonluka@gmail.com>2020-05-20 21:18:40 +0200
committersijanec <sijanecantonluka@gmail.com>2020-05-20 21:18:40 +0200
commit9957e1be89076c2a7612d2055b776f2c8354909a (patch)
tree5abe3bf5bfc54165e65686e7b539ef4495b2615b /assets/js/settings.js
parenttesting minification with jsmin (diff)
parentStyling fix (diff)
downloadbeziapp-9957e1be89076c2a7612d2055b776f2c8354909a.tar
beziapp-9957e1be89076c2a7612d2055b776f2c8354909a.tar.gz
beziapp-9957e1be89076c2a7612d2055b776f2c8354909a.tar.bz2
beziapp-9957e1be89076c2a7612d2055b776f2c8354909a.tar.lz
beziapp-9957e1be89076c2a7612d2055b776f2c8354909a.tar.xz
beziapp-9957e1be89076c2a7612d2055b776f2c8354909a.tar.zst
beziapp-9957e1be89076c2a7612d2055b776f2c8354909a.zip
Diffstat (limited to 'assets/js/settings.js')
-rw-r--r--assets/js/settings.js160
1 files changed, 84 insertions, 76 deletions
diff --git a/assets/js/settings.js b/assets/js/settings.js
index f9e3c79..2cc6029 100644
--- a/assets/js/settings.js
+++ b/assets/js/settings.js
@@ -1,66 +1,67 @@
// settings.js -- TODO
async function setLanguage(langCode) {
- localforage.setItem("chosenLang", langCode).then((value) => {
- console.log("Language set: " + value);
- UIAlert(D("languageSet"), "setLanguage(): languageSet");
- });
+ localforage.setItem("chosenLang", langCode).then((value) => {
+ console.log("Language set: " + value);
+ UIAlert(D("languageSet"), "setLanguage(): languageSet");
+ });
}
async function setTheme(targetTheme) {
- localforage.setItem("theme", targetTheme).then((value) => {
- console.log("Theme set: " + value);
- UIAlert(D("themeSet"), "setTheme(): themeSet");
- });
+ localforage.setItem("theme", targetTheme).then((value) => {
+ console.log("Theme set: " + value);
+ UIAlert(D("themeSet"), "setTheme(): themeSet");
+ });
}
async function setErrorReporting(targetE) {
- localforage.setItem("errorReporting", targetE).then((value) => {
- console.log("ErrorReporing set: " + value);
- UIAlert(D("errorReportingSet"), "setErrorReporting(): errorReportingSet");
- });
+ localforage.setItem("errorReporting", targetE).then((value) => {
+ console.log("ErrorReporing set: " + value);
+ UIAlert(D("errorReportingSet"), "setErrorReporting(): errorReportingSet");
+ });
}
function shuffleArray(array) {
- for (var i = array.length - 1; i > 0; i--) {
- var j = Math.floor(Math.random() * (i + 1));
- var temp = array[i];
- array[i] = array[j];
- array[j] = temp;
- }
+ for (var i = array.length - 1; i > 0; i--) {
+ var j = Math.floor(Math.random() * (i + 1));
+ var temp = array[i];
+ array[i] = array[j];
+ array[j] = temp;
+ }
}
function setUIAdditionalOptions(state) {
- var SENSITIVE_THEMES = {
- "left": "Left / leva",
- "right": "Right / desna"
- };
- if (state === true) {
- var theme_keys = Object.keys(SENSITIVE_THEMES);
- shuffleArray(theme_keys);
- theme_keys.forEach((item) => {
- var option_element = $(`<option value="${item}" id="option-${item}" data-theme="${item}">${SENSITIVE_THEMES[item]}</option>`);
- $("#select-theme").append(option_element);
- });
- } else {
- Object.keys(SENSITIVE_THEMES).forEach((item) => {
- $("#option-" + item).remove();
- });
- }
- $("#select-theme").formSelect();
+ var SENSITIVE_THEMES = {
+ "left": "Left / leva",
+ "right": "Right / desna"
+ };
+ if (state === true) {
+ var theme_keys = Object.keys(SENSITIVE_THEMES);
+ shuffleArray(theme_keys);
+ theme_keys.forEach((item) => {
+ var option_element = $(`<option value="${item}" id="option-${item}" data-theme="${item}">${SENSITIVE_THEMES[item]}</option>`);
+ $("#select-theme").append(option_element);
+ });
+ } else {
+ Object.keys(SENSITIVE_THEMES).forEach((item) => {
+ $("#option-" + item).remove();
+ });
+ }
+ var elems = document.querySelectorAll('#select-theme');
+ M.FormSelect.init(elems, {});
}
async function setAdditionalOptions(state) {
- localforage.setItem("triggerWarningAccepted", state).then((value) => {
- console.log("TriggerWarning set: " + value);
- UIAlert(D("triggerWarningSet"), "setAdditionalOptions(): triggerWarningSet");
- setUIAdditionalOptions(value);
- });
+ localforage.setItem("triggerWarningAccepted", state).then((value) => {
+ console.log("TriggerWarning set: " + value);
+ UIAlert(D("triggerWarningSet"), "setAdditionalOptions(): triggerWarningSet");
+ setUIAdditionalOptions(value);
+ });
}
document.addEventListener("DOMContentLoaded", async () => {
- // Setup checkbox handler
+ // Setup checkbox handler
$("#triggered-checkbox").change(function() {
if (this.checked) {
setAdditionalOptions(true);
@@ -69,53 +70,60 @@ document.addEventListener("DOMContentLoaded", async () => {
}
});
- $("#select-language").on("change", function() {
- setLanguage($(this).find(":selected").val());
- });
+ $("#select-language").on("change", function() {
+ setLanguage($(this).find(":selected").val());
+ });
- $("#select-theme").on("change", function() {
- setTheme($(this).find(":selected").val());
- });
+ $("#select-theme").on("change", function() {
+ setTheme($(this).find(":selected").val());
+ });
- $("#select-errorreporting").on("change", function() {
- setErrorReporting($(this).find(":selected").val());
- });
+ $("#select-errorreporting").on("change", function() {
+ setErrorReporting($(this).find(":selected").val());
+ });
- localforage.getItem("chosenLang").then((value) => {
- let selectedLanguage = value;
+ localforage.getItem("chosenLang").then((value) => {
+ let selectedLanguage = value;
if(value == null || value.length < 1) {
selectedLanguage = "sl";
}
- $(`#option-${selectedLanguage}`).attr("selected", true);
- }).catch(() => {});
+ $(`#option-${selectedLanguage}`).attr("selected", true);
+ }).catch(() => {});
- localforage.getItem("theme").then((value) => {
- let selectedTheme = value;
+ localforage.getItem("theme").then((value) => {
+ let selectedTheme = value;
if(value == null || value.length < 1) {
selectedTheme = "themeLight";
}
- $(`#option-${selectedTheme}`).attr("selected", true);
- }).catch(() => {});
+ $(`#option-${selectedTheme}`).attr("selected", true);
+ }).catch(() => {});
- localforage.getItem("errorReporting").then((value) => {
- let selectedE = value;
+ localforage.getItem("errorReporting").then((value) => {
+ let selectedE = value;
if(value == null || value.length < 1) {
selectedE = "on";
}
- $(`#option-${selectedE}`).attr("selected", true);
- }).catch(() => {});
-
- // Setup side menu
- const menus = document.querySelectorAll(".side-menu");
- M.Sidenav.init(menus, { edge: "right", draggable: true });
-
- var elems = document.querySelectorAll(".theme-select");
- M.FormSelect.init(elems, {});
-
- var elems = document.querySelectorAll(".errorreporting-select");
- M.FormSelect.init(elems, {});
-
- // Setup language select dropdown
- var elems = document.querySelectorAll(".lang-select");
- M.FormSelect.init(elems, {});
+ $(`#option-${selectedE}`).attr("selected", true);
+ }).catch(() => {});
+
+ localforage.getItem("triggerWarningAccepted").then((value) => {
+ if (value === true) {
+ $("#triggered-checkbox").attr("checked", true);
+ setUIAdditionalOptions(true);
+ }
+ }).catch(() => {});
+
+ // Setup side menu
+ const menus = document.querySelectorAll(".side-menu");
+ M.Sidenav.init(menus, { edge: "right", draggable: true });
+
+ var elems = document.querySelectorAll(".theme-select");
+ M.FormSelect.init(elems, {});
+
+ var elems = document.querySelectorAll(".errorreporting-select");
+ M.FormSelect.init(elems, {});
+
+ // Setup language select dropdown
+ var elems = document.querySelectorAll(".lang-select");
+ M.FormSelect.init(elems, {});
});