From 33248f07a98fa9be713384c64e84a1ffff1a891f Mon Sep 17 00:00:00 2001 From: Jaifroid Date: Wed, 28 Feb 2018 23:04:50 +0000 Subject: [PATCH] Take account of baseUrl when changing theme on the fly Former-commit-id: f1111d9ca9f0cf57a486a1ef122b1c3993cab131 [formerly 714f9ed8d90bb70730c35fd76ce7dd431037fa85] Former-commit-id: 130d170a9c4a49f90926bda2042fbbdf5432f62c --- www/js/app.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/www/js/app.js b/www/js/app.js index a0ccc1d5..57e42388 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -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(/ 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); } }