mirror of
https://github.com/kiwix/kiwix-js-pwa.git
synced 2025-09-09 12:19:46 -04:00
Fix glitch in dark mode switching and simplify treePath code
Former-commit-id: 0300b5a9f9ed0073ec26793b2f2006d6ae410da0 [formerly 58f926c850240aed2a974307492e9d7fb3d7ce13] Former-commit-id: 1c5f3b8f71a6d4be45308f3b90fa89cbc15a731c
This commit is contained in:
parent
15c6919b61
commit
e38423f83b
@ -378,7 +378,7 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies', 'q', 'module'
|
|||||||
//Use the "light" navbar if the content is "light" (otherwise it looks shite....)
|
//Use the "light" navbar if the content is "light" (otherwise it looks shite....)
|
||||||
if (params.cssTheme != params.cssUITheme) {
|
if (params.cssTheme != params.cssUITheme) {
|
||||||
if ((params.cssTheme == "light" && (!activeBtn || activeBtn == "btnHome" || activeBtn == "findText")) ||
|
if ((params.cssTheme == "light" && (!activeBtn || activeBtn == "btnHome" || activeBtn == "findText")) ||
|
||||||
(params.cssTheme == "dark" && activeBtn && activeBtn != "btnHome" && activeBtn != "findText")) {
|
(params.cssTheme != "light" && activeBtn && activeBtn != "btnHome" && activeBtn != "findText")) {
|
||||||
cssUIThemeSet("light");
|
cssUIThemeSet("light");
|
||||||
} else {
|
} else {
|
||||||
cssUIThemeSet("dark");
|
cssUIThemeSet("dark");
|
||||||
@ -576,7 +576,9 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies', 'q', 'module'
|
|||||||
params.cssUITheme = this.checked ? 'dark' : 'light';
|
params.cssUITheme = this.checked ? 'dark' : 'light';
|
||||||
cookies.setItem('cssUITheme', params.cssUITheme, Infinity);
|
cookies.setItem('cssUITheme', params.cssUITheme, Infinity);
|
||||||
cssUIThemeSet(params.cssUITheme);
|
cssUIThemeSet(params.cssUITheme);
|
||||||
if (params.cssUITheme !== params.cssTheme) $('#cssWikiDarkThemeCheck').click();
|
//Make subsequent check valid if params.cssTheme is "invert" rather than "dark"
|
||||||
|
var checkTheme = params.cssTheme == "light" ? "light" : "dark";
|
||||||
|
if (params.cssUITheme != checkTheme) $('#cssWikiDarkThemeCheck').click();
|
||||||
});
|
});
|
||||||
|
|
||||||
function cssUIThemeSet(value) {
|
function cssUIThemeSet(value) {
|
||||||
@ -623,9 +625,10 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies', 'q', 'module'
|
|||||||
});
|
});
|
||||||
function switchTheme() {
|
function switchTheme() {
|
||||||
var doc = window.frames[0].frameElement.contentDocument;
|
var doc = window.frames[0].frameElement.contentDocument;
|
||||||
var baseUrl = doc.head.innerHTML.match(/<base\s*href\s*=\s*["']([^"']+)/);
|
//var baseUrl = doc.head.innerHTML.match(/<base\s*href\s*=\s*["']([^"']+)/);
|
||||||
baseUrl = baseUrl && baseUrl.length > 1 ? baseUrl[1] : false;
|
var treePath = window.history.state.title.replace(/[^/]+\/(?:[^/]+$)?/g, "../");
|
||||||
var treePath = baseUrl ? baseUrl.replace(/([^/]+\/)/g, "../") : false;
|
//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 something went wrong, use the page reload method
|
||||||
if (!treePath) {
|
if (!treePath) {
|
||||||
params.themeChanged = true;
|
params.themeChanged = true;
|
||||||
@ -761,7 +764,7 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies', 'q', 'module'
|
|||||||
|
|
||||||
$(document).ready(function (e) {
|
$(document).ready(function (e) {
|
||||||
// Set initial behaviour (see also init.js)
|
// Set initial behaviour (see also init.js)
|
||||||
if (params.cssTheme == "dark") document.getElementById('footer').classList.add("darkfooter");
|
if (params.cssTheme != "light") document.getElementById('footer').classList.add("darkfooter");
|
||||||
cssUIThemeSet(params.cssUITheme);
|
cssUIThemeSet(params.cssUITheme);
|
||||||
//@TODO - this is initialization code, and should be in init.js (withoug jQuery)
|
//@TODO - this is initialization code, and should be in init.js (withoug jQuery)
|
||||||
$('input:radio[name=cssInjectionMode]').filter('[value="' + params.cssSource + '"]').prop('checked', true);
|
$('input:radio[name=cssInjectionMode]').filter('[value="' + params.cssSource + '"]').prop('checked', true);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user