diff --git a/www/js/channel/cpanel.js b/www/js/channel/cpanel.js index b426857..22d65e7 100644 --- a/www/js/channel/cpanel.js +++ b/www/js/channel/cpanel.js @@ -406,6 +406,9 @@ class poppedPanel{ * Fills container window with Popped Panel container elements */ fillContainer(){ + //Apply theme + this.window.document.head.appendChild(ThemeManager.genThemeLink()); + //Set Element Nodes this.panelDiv = this.window.document.querySelector("#cpanel-div"); this.panelTitle = this.window.document.querySelector("#cpanel-title"); diff --git a/www/js/channel/panels/settingsPanel.js b/www/js/channel/panels/settingsPanel.js index 5df8369..84e5395 100644 --- a/www/js/channel/panels/settingsPanel.js +++ b/www/js/channel/panels/settingsPanel.js @@ -111,6 +111,16 @@ class settingsPanel extends panelObj{ } fillThemes(){ + //Find theme selector + const selector = this.theme.querySelector('select'); + + //If the theme selector has already been filled or doesnt exist + if(selector == null || selector.childElementCount > 0){ + //Stop while we're ahead + return; + } + + //For each theme for(let themeName of ThemeManager.themes.keys()){ //Create theme option let option = document.createElement('option'); @@ -120,7 +130,7 @@ class settingsPanel extends panelObj{ option.innerText = themeName; //Add option to theme selector - this.theme.querySelector('select').appendChild(option); + selector.appendChild(option); } } diff --git a/www/js/themeManager.js b/www/js/themeManager.js index b7d2570..e5a260e 100644 --- a/www/js/themeManager.js +++ b/www/js/themeManager.js @@ -49,7 +49,7 @@ class themeManager{ * Sets theme by name * @param {String} theme - name of theme to set, keep blank for default theme */ - setTheme(theme){ + setTheme(theme = localStorage.getItem("theme")){ //If we didnt get a theme to set if(theme == null){ //Use the first theme in the list @@ -63,14 +63,7 @@ class themeManager{ } //Create new link element and use it to set themeLink - this.themeLink = document.createElement('link'); - - //Set themeLink attributes - this.themeLink.type = "text/css"; - this.themeLink.rel = "stylesheet"; - - //Set theme href to theme location - this.themeLink.href = this.themes.get(theme); + this.themeLink = this.genThemeLink(theme); //Append themeLink to header document.querySelector('head').appendChild(this.themeLink); @@ -78,6 +71,20 @@ class themeManager{ //Save theme choice to local storage localStorage.setItem("theme", theme); } + + genThemeLink(theme = localStorage.getItem("theme")){ + //Create new link element and use it to set themeLink + const themeLink = document.createElement('link'); + + //Set themeLink attributes + themeLink.type = "text/css"; + themeLink.rel = "stylesheet"; + + //Set theme href to theme location + themeLink.href = this.themes.get(theme); + + return themeLink; + } } ThemeManager = new themeManager(); \ No newline at end of file