From c05506a2a5bab31a9e19af6c41fd0bc7ff944665 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Thu, 10 Jan 2019 17:07:42 +0100 Subject: [PATCH] Dark theme persistant on page reload. --- assets/js/common/system.js | 5 +++++ assets/js/components/darkTheme.js | 18 +++++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/assets/js/common/system.js b/assets/js/common/system.js index da60d0b3..0bb43b47 100644 --- a/assets/js/common/system.js +++ b/assets/js/common/system.js @@ -81,6 +81,11 @@ ComunicWeb.common.system = { }), 25000); ComunicWeb.common.cacheManager.registerInterval(autoRefresh); + /** + * Refresh dark theme mode + */ + ComunicWeb.components.darkTheme.refresh(); + //Success return true; }, diff --git a/assets/js/components/darkTheme.js b/assets/js/components/darkTheme.js index 03ea3e7c..9b71de54 100644 --- a/assets/js/components/darkTheme.js +++ b/assets/js/components/darkTheme.js @@ -7,9 +7,9 @@ ComunicWeb.components.darkTheme = { /** - * This variable contains the dark theme status + * Specify whether dark theme has to be enabled or not */ - _enabled: false, + _local_storage_name: "dark_theme_mode", /** * CSS element that contains dark theme CSS rules @@ -22,7 +22,7 @@ ComunicWeb.components.darkTheme = { * @return {boolean} TRUE if enabled / FALSE else */ isEnabled: function(){ - return this._enabled; + return localStorage.getItem(this._local_storage_name) == "true"; }, /** @@ -31,10 +31,18 @@ ComunicWeb.components.darkTheme = { * @param {boolean} enable TRUE to enable / FALSE else */ setEnabled: function(enable){ - this._enabled = enable; + localStorage.setItem(this._local_storage_name, enable ? "true" : "false"); + + this.refresh(); + }, + + /** + * Refresh dark theme state + */ + refresh: function(){ //Check if the theme has to be disabled - if(!this._enabled){ + if(!this.isEnabled()){ if(this._cssElem != null) this._cssElem.disabled = true; return;