Browse Source

Improved theme selection. Added changeTheme method.

n1474335 5 years ago
parent
commit
383aab5f85
2 changed files with 18 additions and 3 deletions
  1. 2 1
      src/web/App.mjs
  2. 16 2
      src/web/waiters/OptionsWaiter.mjs

+ 2 - 1
src/web/App.mjs

@@ -492,8 +492,9 @@ class App {
             } catch (err) {}
         }
 
+        // Read in theme from URI params
         if (this.uriParams.theme) {
-            document.querySelector(":root").className = this.uriParams.theme;
+            this.manager.options.changeTheme(Utils.escapeHtml(this.uriParams.theme));
         }
 
         this.autoBakePause = false;

+ 16 - 2
src/web/waiters/OptionsWaiter.mjs

@@ -153,14 +153,28 @@ class OptionsWaiter {
 
 
     /**
-     * Changes the theme by setting the class of the <html> element.
+     * Theme change event listener
      *
      * @param {Event} e
      */
     themeChange(e) {
         const themeClass = e.target.value;
 
-        document.querySelector(":root").className = themeClass;
+        this.changeTheme(themeClass);
+    }
+
+
+    /**
+     * Changes the theme by setting the class of the <html> element.
+     *
+     * @param (string} theme
+     */
+    changeTheme(theme) {
+        document.querySelector(":root").className = theme;
+
+        // Update theme selection
+        const themeSelect = document.getElementById("theme");
+        themeSelect.selectedIndex = themeSelect.querySelector(`option[value="${theme}"`).index;
     }