Upgrade web assets (#219)
* Update assets * Upgrade linting and other improvments * Correct linting * Correction and type check improvements * Correct type check lib * Fix lint pathing for VSCode * Remove duplicate babel config * Remove editorconfig root attribute from web subdir * Use double quotes around message * Simplify ESLint config * Update web assets * Allow AMD loader in WebPack * Bump web dependencies * Only include FA icons in-use
This commit is contained in:
42
web/js/lib/theme.mjs
Normal file
42
web/js/lib/theme.mjs
Normal file
@ -0,0 +1,42 @@
|
||||
export default class {
|
||||
/**
|
||||
* @property {boolean} dark Interal state for dark theme activation.
|
||||
* @private
|
||||
*/
|
||||
static #dark = false;
|
||||
|
||||
/**
|
||||
* Inialize the theme class.
|
||||
*/
|
||||
static init() {
|
||||
// Check LocalStorage for dark theme selection
|
||||
if (localStorage.getItem('darkTheme') === 'true') {
|
||||
// Update page theme
|
||||
this.set(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set page theme and update local storage variable.
|
||||
*
|
||||
* @param {boolean} dark Whether to activate dark theme.
|
||||
*/
|
||||
static set(dark = false) {
|
||||
// Swap CSS to selected theme
|
||||
document.getElementById('pagestyle')
|
||||
.setAttribute('href', 'static/css/' + (dark ? 'dark' : 'main') + '.css');
|
||||
|
||||
// Update local storage
|
||||
localStorage.setItem('darkTheme', dark);
|
||||
|
||||
// Update internal state
|
||||
this.#dark = dark;
|
||||
}
|
||||
|
||||
/**
|
||||
* Swap page theme.
|
||||
*/
|
||||
static swap() {
|
||||
this.set(!this.#dark);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user