diff --git a/ui/index.html b/ui/index.html index 4f5b7ee4..9d28ee9a 100644 --- a/ui/index.html +++ b/ui/index.html @@ -43,7 +43,7 @@
  • - +
    diff --git a/ui/media/js/auto-save.js b/ui/media/js/auto-save.js index 1d0cf4b5..e3d85dd0 100644 --- a/ui/media/js/auto-save.js +++ b/ui/media/js/auto-save.js @@ -62,6 +62,9 @@ function getSetting(element) { return element.value } function setSetting(element, value) { + if (typeof element === "string" || element instanceof String) { + element = SETTINGS_TO_SAVE.find(e => e.id == element); + } if (getSetting(element) == value) { return // no setting necessary } @@ -85,10 +88,11 @@ function saveSettings() { var CURRENTLY_LOADING_SETTINGS = false function loadSettings() { - if (!saveSettingsCheckbox.checked) { + var saved_settings = JSON.parse(localStorage.getItem(SETTINGS_KEY)) + if (!saved_settings.values["auto_save_settings"]) { + setSetting("auto_save_settings", false); return } - var saved_settings = JSON.parse(localStorage.getItem(SETTINGS_KEY)) if (saved_settings) { var values = saved_settings.values var should_save = saved_settings.should_save diff --git a/ui/media/js/utils.js b/ui/media/js/utils.js index 9a119e7a..a0d0c2fe 100644 --- a/ui/media/js/utils.js +++ b/ui/media/js/utils.js @@ -26,7 +26,7 @@ const COLLAPSIBLE_PANELS = []; // filled in by createCollapsibles with all the e // on-init call this for any panels that are marked open function toggleCollapsible(element) { var collapsibleHeader = element.querySelector(".collapsible"); - var handle = element.firstChild; + var handle = element.querySelector(".collapsible-handle"); collapsibleHeader.classList.toggle("active") let content = getNextSibling(collapsibleHeader, '.collapsible-content') if (content.style.display === "block") { @@ -37,16 +37,16 @@ function toggleCollapsible(element) { handle.innerHTML = '➖' // minus } - if (COLLAPSIBLES_INITIALIZED && COLLAPSIBLE_PANELS.includes(element.parentElement)) { + if (COLLAPSIBLES_INITIALIZED && COLLAPSIBLE_PANELS.includes(element)) { saveCollapsibles(); } } function saveCollapsibles() { var values = {}; - console.log(COLLAPSIBLE_PANELS); COLLAPSIBLE_PANELS.forEach(element => { - values[element.id] = element.querySelector(".collapsible").className.indexOf("active") !== -1; + var value = element.querySelector(".collapsible").className.indexOf("active") !== -1; + values[element.id] = value; }); localStorage.setItem(COLLAPSIBLES_KEY, JSON.stringify(values)); } @@ -57,10 +57,6 @@ function createCollapsibles(node) { node = document; save = true; } - // FIX: problem here is that the elements we're getting in c are the buttons, and they are the children of the things with collapsible stuff - // FIX: gotta get parent - - // default closed. let collapsibles = node.querySelectorAll(".collapsible") collapsibles.forEach(function(c) { if (save && c.parentElement.id) { @@ -87,12 +83,12 @@ function createCollapsibles(node) { saved = localStorage.getItem(COLLAPSIBLES_KEY); } var values = JSON.parse(saved); - Object.keys(values).forEach(element_id => { - if (values[element_id]) { - var element = COLLAPSIBLE_PANELS.find(e => e.id == element_id); + COLLAPSIBLE_PANELS.forEach(element => { + var value = element.querySelector(".collapsible").className.indexOf("active") !== -1; + if (values[element.id] != value) { toggleCollapsible(element); } - }); + }) COLLAPSIBLES_INITIALIZED = true; } }