diff options
author | Aleksander Machniak <alec@alec.pl> | 2021-09-25 10:59:23 +0300 |
---|---|---|
committer | Aleksander Machniak <alec@alec.pl> | 2021-09-25 10:59:23 +0300 |
commit | 5db6dd0317e7c0ae98bf5ce5d3e117b74803b86b (patch) | |
tree | 396d9b77e853e3b0a799381615b4c1638b264bca /skins | |
parent | 800832612c909735f15f95743b3c7a05fae56363 (diff) |
Fix handling of dark_mode_support:false setting in skins meta.json (#8186)
Diffstat (limited to 'skins')
-rw-r--r-- | skins/elastic/ui.js | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/skins/elastic/ui.js b/skins/elastic/ui.js index 699936e6a..967f3eb23 100644 --- a/skins/elastic/ui.js +++ b/skins/elastic/ui.js @@ -771,8 +771,12 @@ function rcube_elastic_ui() return; } - var pref, + // We deliberately use only cookies here, not local storage + var pref = rcmail.get_cookie('colorMode'), color_scheme = window.matchMedia('(prefers-color-scheme: dark)'), + reset_cookie = function() { + rcmail.set_cookie('colorMode', '', new Date()); // delete the cookie + }, switch_iframe_color_mode = function() { try { $(this.contentWindow.document).find('html')[color_mode == 'dark' ? 'addClass' : 'removeClass']('dark-mode'); @@ -793,6 +797,14 @@ function rcube_elastic_ui() $('iframe').each(switch_iframe_color_mode); }; + if (rcmail.env.dark_mode_support === false) { + if (pref == 'dark') { + reset_cookie(); + $('iframe').each(switch_iframe_color_mode); + } + return; + } + // Add onclick action to the menu button $('#taskmenu a.theme').on('click', function() { color_mode = $(this).is('.dark') ? 'dark' : 'light'; @@ -804,11 +816,10 @@ function rcube_elastic_ui() color_scheme.addListener(function(e) { color_mode = e.matches ? 'dark' : 'light'; switch_color_mode(); - rcmail.set_cookie('colorMode', '', new Date()); // delete the cookie + reset_cookie(); }); - // We deliberately use only cookies here, not local storage - if (pref = rcmail.get_cookie('colorMode')) { + if (pref) { color_mode = pref; } else if (color_scheme.matches) { |