summaryrefslogtreecommitdiff
path: root/htdocs
diff options
context:
space:
mode:
authorEvgeny Zinoviev <me@ch1p.io>2022-07-11 15:01:02 +0300
committerEvgeny Zinoviev <me@ch1p.io>2022-07-11 15:01:02 +0300
commitc2f382aba86aaebb9806ff1b43c1af69992e9a10 (patch)
treeaee205721fd675926c5e7163eec0dddc448f7813 /htdocs
parent24982a48f570b89e537850dda4a4d1ac33ea919f (diff)
support dark mode for images with alpha channel
Diffstat (limited to 'htdocs')
-rw-r--r--htdocs/js/common/35-theme-switcher.js21
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