feature: improve page loading + intl collator

This commit is contained in:
Jean-Baptiste Pasquier
2021-01-26 18:19:42 +01:00
parent 7c0f237bd0
commit a936a343b5
6 changed files with 102 additions and 91 deletions

View File

@ -187,13 +187,15 @@ document.addEventListener("DOMContentLoaded", () => {
// Detect the lang & initialize, based on the browser or "language" item from localstorage
jsI18n.detectLanguage();
let timer;
(new MutationObserver((mutations) => {
mutations.forEach(mutation => {
if(mutation.target.attributes["data-trans"] != null) {
// Render the target of the mutation instantly
jsI18n.processNode(mutation.target);
// Then wait one arbitrary second to re-render the whole document in case a widget re-rendered
setTimeout(() => jsI18n.processNode(document.querySelector('body')), 1000);
clearTimeout(timer);
timer = setTimeout(() => jsI18n.processNode(document.querySelector('body')), 500);
}
});
}).observe(document.body, {

View File

@ -7,6 +7,9 @@ document.addEventListener("DOMContentLoaded", function () {
document
.querySelectorAll(".notLoggedIn")
.forEach(el => (el.style.visibility = "visible"));
document
.querySelectorAll(".loggedIn")
.forEach(el => (el.style.display = "none"));
}
});
});