theme selection should now take into account site root

This commit is contained in:
unknown 2020-05-10 11:36:27 +01:00
parent 7bfb5ac4b4
commit cbbd0ea31b
7 changed files with 16 additions and 12 deletions

1
.gitignore vendored
View file

@ -1,2 +1,3 @@
public/ public/
node_modules/ node_modules/
.gitconfig

View file

@ -1,4 +1,4 @@
(function(switch_css) { (function (switch_css) {
//Constants //Constants
const THEME_KEY = "ZULMA_THEME"; const THEME_KEY = "ZULMA_THEME";
const THEME = localStorage.getItem(THEME_KEY); const THEME = localStorage.getItem(THEME_KEY);
@ -7,6 +7,7 @@
//Variables //Variables
let previousLink = null; let previousLink = null;
let baseUrl = "";
//Events //Events
/* The function called when the css has finished loading */ /* The function called when the css has finished loading */
@ -56,7 +57,7 @@
var fileref = document.createElement("link"); var fileref = document.createElement("link");
fileref.rel = "stylesheet"; fileref.rel = "stylesheet";
fileref.type = "text/css"; fileref.type = "text/css";
fileref.href = `/${themeName}.css`; fileref.href = `${baseUrl}/${themeName}.css`;
fileref.id = themeName; fileref.id = themeName;
//append it to the head //append it to the head
@ -141,7 +142,8 @@
} }
//Public Methods //Public Methods
switch_css.init = function() { switch_css.init = function (url) {
baseUrl = url
//if user has selected and theme and it is not the current theme //if user has selected and theme and it is not the current theme
if (THEME && !document.getElementById(THEME)) { if (THEME && !document.getElementById(THEME)) {
//hide the body to stop FOUC //hide the body to stop FOUC
@ -153,11 +155,9 @@
} }
//when the DOM is loaded, set the dropdown to trigger the theme change //when the DOM is loaded, set the dropdown to trigger the theme change
window.addEventListener("DOMContentLoaded", () => { window.addEventListener("DOMContentLoaded", () => {
document.getElementById("theme-select").onchange = function() { document.getElementById("theme-select").onchange = function () {
changeTheme(this.value); changeTheme(this.value);
}; };
}); });
}; };
})((switch_css = window.switch_css || {})); // eslint-disable-line })((switch_css = window.switch_css || {})); // eslint-disable-line
switch_css.init(); // eslint-disable-line

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -1,2 +1,2 @@
!function(e){var t={};function n(o){if(t[o])return t[o].exports;var r=t[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}n.m=e,n.c=t,n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(o,r,function(t){return e[t]}.bind(null,r));return o},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=2)}({2:function(e,t){!function(e){var t="ZULMA_THEME",n=localStorage.getItem(t),o="stop-blink",r="stylesheet",c=null,l=function e(t){var n=t.currentTarget;n.removeEventListener("load",e),n.removeEventListener("error",i),a(),n.className+=r,c=null,d()},i=function e(n){var o=n.currentTarget;o.removeEventListener("load",l),o.removeEventListener("error",e),localStorage.removeItem(t),s(o.id,!1),o.remove(),c&&document.getElementsByTagName("head")[0].appendChild(c),s(document.querySelectorAll(".".concat(r))[0].id,!0),d()};function u(e,n){var o=document.createElement("link");o.rel="stylesheet",o.type="text/css",o.href="/".concat(e,".css"),o.id=e;var u=document.getElementsByTagName("head")[0].appendChild(o);u.addEventListener("load",l),u.addEventListener("error",i),n&&(c=document.querySelectorAll(".".concat(r))[0],a()),function(e){localStorage.setItem(t,e)}(e)}function a(){document.querySelectorAll(".".concat(r)).forEach((function(e){e.remove()}))}function d(){var e=document.getElementById(o);e&&e.remove()}function s(e,t){var n=document.querySelectorAll("#theme-select>option");n.length?n.forEach((function(n){n.value===e&&(t?n.selected="selected":n.remove())})):window.addEventListener("DOMContentLoaded",(function(){s(e,t)}))}e.init=function(){var e,t,r;n&&!document.getElementById(n)&&(e=document.getElementsByTagName("head")[0],t=document.createElement("style"),r="body{visibility:hidden;}",t.id=o,t.setAttribute("type","text/css"),t.styleSheet?t.styleSheet.cssText=r:t.appendChild(document.createTextNode(r)),e.appendChild(t),u(n,!0),s(n,!0)),window.addEventListener("DOMContentLoaded",(function(){document.getElementById("theme-select").onchange=function(){u(this.value)}}))}}(switch_css=window.switch_css||{}),switch_css.init()}}); !function(e){var t={};function n(o){if(t[o])return t[o].exports;var r=t[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}n.m=e,n.c=t,n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(o,r,function(t){return e[t]}.bind(null,r));return o},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=2)}({2:function(e,t){!function(e){var t="ZULMA_THEME",n=localStorage.getItem(t),o="stop-blink",r="stylesheet",c=null,l="",i=function e(t){var n=t.currentTarget;n.removeEventListener("load",e),n.removeEventListener("error",u),d(),n.className+=r,c=null,s()},u=function e(n){var o=n.currentTarget;o.removeEventListener("load",i),o.removeEventListener("error",e),localStorage.removeItem(t),m(o.id,!1),o.remove(),c&&document.getElementsByTagName("head")[0].appendChild(c),m(document.querySelectorAll(".".concat(r))[0].id,!0),s()};function a(e,n){var o=document.createElement("link");o.rel="stylesheet",o.type="text/css",o.href="".concat(l,"/").concat(e,".css"),o.id=e;var a=document.getElementsByTagName("head")[0].appendChild(o);a.addEventListener("load",i),a.addEventListener("error",u),n&&(c=document.querySelectorAll(".".concat(r))[0],d()),function(e){localStorage.setItem(t,e)}(e)}function d(){document.querySelectorAll(".".concat(r)).forEach((function(e){e.remove()}))}function s(){var e=document.getElementById(o);e&&e.remove()}function m(e,t){var n=document.querySelectorAll("#theme-select>option");n.length?n.forEach((function(n){n.value===e&&(t?n.selected="selected":n.remove())})):window.addEventListener("DOMContentLoaded",(function(){m(e,t)}))}e.init=function(e){var t,r,c;l=e,n&&!document.getElementById(n)&&(t=document.getElementsByTagName("head")[0],r=document.createElement("style"),c="body{visibility:hidden;}",r.id=o,r.setAttribute("type","text/css"),r.styleSheet?r.styleSheet.cssText=c:r.appendChild(document.createTextNode(c)),t.appendChild(r),a(n,!0),m(n,!0)),window.addEventListener("DOMContentLoaded",(function(){document.getElementById("theme-select").onchange=function(){a(this.value)}}))}}(switch_css=window.switch_css||{})}});
//# sourceMappingURL=zulma_switchcss.js.map //# sourceMappingURL=zulma_switchcss.js.map

File diff suppressed because one or more lines are too long

View file

@ -20,6 +20,9 @@
<!-- This script must follow css --> <!-- This script must follow css -->
{% if config.extra.zulma_allow_theme_selection %} {% if config.extra.zulma_allow_theme_selection %}
<script type="text/javascript" src="{{ get_url(path="js/zulma_switchcss.js") }}"></script> <script type="text/javascript" src="{{ get_url(path="js/zulma_switchcss.js") }}"></script>
<script>
switch_css.init("{{config.base_url | safe}}");
</script>
{% endif %} {% endif %}
{% if config.generate_rss %} {% if config.generate_rss %}