mirror of
https://github.com/kiwix/kiwix-js-pwa.git
synced 2025-09-08 19:57:46 -04:00
Take account of baseUrl when changing theme on the fly
Former-commit-id: f1111d9ca9f0cf57a486a1ef122b1c3993cab131 [formerly 714f9ed8d90bb70730c35fd76ce7dd431037fa85] Former-commit-id: 130d170a9c4a49f90926bda2042fbbdf5432f62c
This commit is contained in:
parent
7304fea803
commit
33248f07a9
@ -623,9 +623,17 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies', 'q', 'module'
|
||||
});
|
||||
function switchTheme() {
|
||||
var doc = window.frames[0].frameElement.contentDocument;
|
||||
var baseUrl = doc.head.innerHTML.match(/<base\s*href\s*=\s*["']([^"']+)/);
|
||||
baseUrl = baseUrl && baseUrl.length > 1 ? baseUrl[1] : false;
|
||||
var treePath = baseUrl ? baseUrl.replace(/([^/]+\/)/g, "../") : false;
|
||||
//If something went wrong, use the page reload method
|
||||
if (!treePath) {
|
||||
params.themeChanged = true;
|
||||
return;
|
||||
}
|
||||
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++) {
|
||||
for (var i = styleSheets.length-1; i > -1; i--) {
|
||||
if (~styleSheets[i].href.search(/\/style-dark/)) {
|
||||
styleSheets[i].disabled = true;
|
||||
styleSheets[i].parentNode.removeChild(styleSheets[i]);
|
||||
@ -635,7 +643,7 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies', 'q', 'module'
|
||||
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"));
|
||||
link.setAttribute("href", (params.cssTheme == "dark" ? treePath + "-/s/style-dark.css" : treePath + "-/s/style-dark-invert.css"));
|
||||
doc.head.appendChild(link);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user