Introduce dark/light mode theme switch into framework

This commit is contained in:
Hadi Nategh
2020-12-15 20:24:25 +01:00
parent 7011faba18
commit f21ac58c87
13 changed files with 143 additions and 2 deletions

View File

@@ -63,6 +63,9 @@ var fw_base = (function(){ "use strict"; return Class.extend(
// keep track of opened popups
this.popups = [];
// initiate dark mode
this._setDarkMode(egw.preference('darkmode', 'common'));
},
/**
@@ -1299,5 +1302,10 @@ var fw_base = (function(){ "use strict"; return Class.extend(
isAnInternalApp: function(_app)
{
return _app && _app.appName != _app.internalName;
},
_setDarkMode: function(_state)
{
jQuery('html').attr('data-darkmode', _state);
}
});}).call(this);

View File

@@ -535,6 +535,27 @@
execPushBroadcastAppStatus: function(_data)
{
if (app.status) app.status.mergeContent(_data, true);
},
/**
*
* @param node
*/
toggle_darkmode: function(node)
{
let state = node.firstElementChild.classList.contains('darkmode_on');
egw.set_preference('common', 'darkmode',state?'0':'1');
this._setDarkMode(state?'0':'1');
if (state == 1)
{
node.firstElementChild.classList.remove('darkmode_on');
node.firstElementChild.title = egw.lang('light mode');
}
else
{
node.firstElementChild.classList.add('darkmode_on');
node.firstElementChild.title = egw.lang('dark mode');
}
}
});
})(window);