diff options
author | Evgeny Zinoviev <me@ch1p.io> | 2022-07-11 15:01:02 +0300 |
---|---|---|
committer | Evgeny Zinoviev <me@ch1p.io> | 2022-07-11 15:01:02 +0300 |
commit | c2f382aba86aaebb9806ff1b43c1af69992e9a10 (patch) | |
tree | aee205721fd675926c5e7163eec0dddc448f7813 /htdocs | |
parent | 24982a48f570b89e537850dda4a4d1ac33ea919f (diff) |
support dark mode for images with alpha channel
Diffstat (limited to 'htdocs')
-rw-r--r-- | htdocs/js/common/35-theme-switcher.js | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/htdocs/js/common/35-theme-switcher.js b/htdocs/js/common/35-theme-switcher.js index e716e4b..c612152 100644 --- a/htdocs/js/common/35-theme-switcher.js +++ b/htdocs/js/common/35-theme-switcher.js @@ -15,6 +15,11 @@ var ThemeSwitcher = (function() { var systemState = null; /** + * @type {function[]} + */ + var changeListeners = []; + + /** * @returns {boolean} */ function isSystemModeSupported() { @@ -71,6 +76,13 @@ var ThemeSwitcher = (function() { var onDone = function() { window.requestAnimationFrame(function() { removeClass(document.body, 'theme-changing'); + changeListeners.forEach(function(f) { + try { + f(dark) + } catch (e) { + console.error('[ThemeSwitcher->changeTheme->onDone] error while calling user callback:', e) + } + }) }) }; @@ -171,7 +183,7 @@ var ThemeSwitcher = (function() { currentModeIndex = (currentModeIndex + 1) % modes.length; switch (modes[currentModeIndex]) { case 'auto': - if (systemState !== null) + if (systemState !== null && systemState !== isDarkModeApplied()) changeTheme(systemState); break; @@ -190,6 +202,13 @@ var ThemeSwitcher = (function() { setCookie('theme', modes[currentModeIndex]); return cancelEvent(e); + }, + + /** + * @param {function} f + */ + addOnChangeListener: function(f) { + changeListeners.push(f); } }; })();
\ No newline at end of file |