mirror of
https://github.com/kiwix/kiwix-js-pwa.git
synced 2025-09-08 19:57:46 -04:00
Load and remove dark themes dynamically #54
Former-commit-id: 13161c5d35f03c8b28662f407686831db3a845e2 [formerly 4691121a0d38bd33e558742d22775a0d4f0ecd90] Former-commit-id: c442478fb2080c8be1316f02714ee3e8cbafcf69
This commit is contained in:
parent
6b09a663b3
commit
7304fea803
@ -4,5 +4,5 @@
|
||||
}
|
||||
|
||||
body {
|
||||
background: black;
|
||||
background: black !important;
|
||||
}
|
||||
|
@ -613,14 +613,32 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies', 'q', 'module'
|
||||
document.getElementById('darkInvert').style.display = this.checked ? "inline" : "none";
|
||||
params.cssTheme = document.getElementById('cssWikiDarkThemeInvertCheck').checked && params.cssTheme == 'dark' ? 'invert' : params.cssTheme;
|
||||
cookies.setItem('cssTheme', params.cssTheme, Infinity);
|
||||
params.themeChanged = true;
|
||||
switchTheme();
|
||||
});
|
||||
$('input:checkbox[name=cssWikiDarkThemeInvert]').on('change', function (e) {
|
||||
if (params.cssTheme == "light" && this.checked) document.getElementById('cssWikiDarkThemeInvertCheck').checked = true;
|
||||
params.cssTheme = this.checked ? 'invert' : 'dark';
|
||||
cookies.setItem('cssTheme', params.cssTheme, Infinity);
|
||||
params.themeChanged = true;
|
||||
switchTheme();
|
||||
});
|
||||
function switchTheme() {
|
||||
var doc = window.frames[0].frameElement.contentDocument;
|
||||
var styleSheets = doc.getElementsByTagName("link");
|
||||
//Remove any dark theme, as we don't know whether user switched from light to dark or from inverted to dark, etc.
|
||||
for (var i = 0; i < styleSheets.length; i++) {
|
||||
if (~styleSheets[i].href.search(/\/style-dark/)) {
|
||||
styleSheets[i].disabled = true;
|
||||
styleSheets[i].parentNode.removeChild(styleSheets[i]);
|
||||
}
|
||||
}
|
||||
if (params.cssTheme != "light") {
|
||||
var link = doc.createElement("link");
|
||||
link.setAttribute("rel", "stylesheet");
|
||||
link.setAttribute("type", "text/css");
|
||||
link.setAttribute("href", (params.cssTheme == "dark" ? "../-/s/style-dark.css" : "../-/s/style-dark-invert.css"));
|
||||
doc.head.appendChild(link);
|
||||
}
|
||||
}
|
||||
$('input:checkbox[name=rememberLastPage]').on('change', function (e) {
|
||||
if (params.rememberLastPage && this.checked) document.getElementById('rememberLastPageCheck').checked = true;
|
||||
params.rememberLastPage = this.checked ? true : false;
|
||||
|
Loading…
x
Reference in New Issue
Block a user