some cleanup
This commit is contained in:
parent
34905fb69f
commit
d56d45f19f
1 changed files with 12 additions and 8 deletions
|
@ -2,6 +2,7 @@
|
||||||
//Constants
|
//Constants
|
||||||
const THEME_KEY = "ZULMA_THEME";
|
const THEME_KEY = "ZULMA_THEME";
|
||||||
const STOP_LINK_CSS_ID = "stop-blink";
|
const STOP_LINK_CSS_ID = "stop-blink";
|
||||||
|
const STYLESHEET_CLASSNAME = "stylesheet"
|
||||||
|
|
||||||
//Variables
|
//Variables
|
||||||
let link = null;
|
let link = null;
|
||||||
|
@ -24,23 +25,25 @@
|
||||||
|
|
||||||
//if this is the first load of the page, remove the current stylesheet early to avoid flash of wrongly styled content
|
//if this is the first load of the page, remove the current stylesheet early to avoid flash of wrongly styled content
|
||||||
if (firstLoad) {
|
if (firstLoad) {
|
||||||
document.querySelectorAll('.stylesheet').forEach((el) => {
|
removeStylesheets();
|
||||||
el.remove();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
saveTheme(themeName);
|
saveTheme(themeName);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function removeStylesheets() {
|
||||||
|
document.querySelectorAll(`.${STYLESHEET_CLASSNAME}`).forEach((el) => {
|
||||||
|
el.remove();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/* The function called when the css has finished loading */
|
/* The function called when the css has finished loading */
|
||||||
function onLinkLoad() {
|
function onLinkLoad() {
|
||||||
link.removeEventListener('load', onLinkLoad);
|
link.removeEventListener('load', onLinkLoad);
|
||||||
//remove the previous stylesheet(s)
|
//remove the previous stylesheet(s)
|
||||||
document.querySelectorAll('.stylesheet').forEach((el) => {
|
removeStylesheets();
|
||||||
el.remove();
|
|
||||||
});
|
|
||||||
//add stylesheet class
|
//add stylesheet class
|
||||||
link.className += 'stylesheet';
|
link.className += STYLESHEET_CLASSNAME;
|
||||||
//make body visible again if it was hidden
|
//make body visible again if it was hidden
|
||||||
showBody();
|
showBody();
|
||||||
};
|
};
|
||||||
|
@ -50,7 +53,7 @@
|
||||||
localStorage.setItem(THEME_KEY, themeName);
|
localStorage.setItem(THEME_KEY, themeName);
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Adds the given css to the head. */
|
/* Hides the body of the page */
|
||||||
function hideBody() {
|
function hideBody() {
|
||||||
var head = document.getElementsByTagName('head')[0];
|
var head = document.getElementsByTagName('head')[0];
|
||||||
var style = document.createElement('style');
|
var style = document.createElement('style');
|
||||||
|
@ -66,6 +69,7 @@
|
||||||
head.appendChild(style);
|
head.appendChild(style);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* Shows the body of the page */
|
||||||
function showBody() {
|
function showBody() {
|
||||||
let css = document.getElementById(STOP_LINK_CSS_ID);
|
let css = document.getElementById(STOP_LINK_CSS_ID);
|
||||||
if (css)
|
if (css)
|
||||||
|
|
Loading…
Add table
Reference in a new issue