#19 changing the title on page navigation
This commit is contained in:
parent
05a4a730ec
commit
150d6bcfbb
|
@ -1,10 +1,21 @@
|
||||||
|
let __notificationCount = '';
|
||||||
|
|
||||||
runAfterLoad(() => {
|
runAfterLoad(() => {
|
||||||
|
__notificationCount = getNotificationCount();
|
||||||
displayNotificationsInTitle();
|
displayNotificationsInTitle();
|
||||||
}, ".*");
|
}, ".*");
|
||||||
|
|
||||||
function displayNotificationsInTitle(){
|
runAfterPathnameChange(() => {
|
||||||
|
displayNotificationsInTitle();
|
||||||
|
}, ".*");
|
||||||
|
|
||||||
|
function getNotificationCount() {
|
||||||
let menu = document.getElementById('materialize-menu-dropdown');
|
let menu = document.getElementById('materialize-menu-dropdown');
|
||||||
let menuDropdowns = Array.from(menu.querySelectorAll('ul.dropdown')).slice(-1)[0];
|
let menuDropdowns = Array.from(menu.querySelectorAll('ul.dropdown')).slice(-1)[0];
|
||||||
let notificationText = menuDropdowns.innerText.split(" ")[3];
|
let notificationText = menuDropdowns.innerText.split(" ")[3];
|
||||||
document.title = notificationText.split(" ")[1] + ' ' + document.title;
|
return notificationText.split(" ")[1] + ' ';
|
||||||
|
}
|
||||||
|
|
||||||
|
function displayNotificationsInTitle(){
|
||||||
|
document.title = __notificationCount + document.title;
|
||||||
}
|
}
|
|
@ -1,5 +1,7 @@
|
||||||
let __scripts = [];
|
let __scripts = [];
|
||||||
let __afterLoadScripts = [];
|
let __afterLoadScripts = [];
|
||||||
|
let __afterPopstateScripts = [];
|
||||||
|
let __afterPathnameChangeScripts = [];
|
||||||
|
|
||||||
function registerScript(func, pattern = '.*') {
|
function registerScript(func, pattern = '.*') {
|
||||||
__scripts.push({ "function": func, "pattern": pattern });
|
__scripts.push({ "function": func, "pattern": pattern });
|
||||||
|
@ -52,3 +54,34 @@ function awaitPageLoaded() {
|
||||||
}
|
}
|
||||||
}, 100);
|
}, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function runAfterPathnameChange(func, pattern = '.*') {
|
||||||
|
__afterPathnameChangeScripts.push({ "function": func, "pattern": pattern});
|
||||||
|
}
|
||||||
|
|
||||||
|
let locationPath = location.pathname;
|
||||||
|
let __loop = setInterval(() => {
|
||||||
|
if (locationPath != location.pathname) {
|
||||||
|
locationPath = location.pathname;
|
||||||
|
awaitPathnameChange();
|
||||||
|
}
|
||||||
|
}, 100);
|
||||||
|
|
||||||
|
function awaitPathnameChange() {
|
||||||
|
let preLoader = document.getElementById('preloader');
|
||||||
|
|
||||||
|
if (typeof preLoader === 'undefined') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let loop = setInterval(() => {
|
||||||
|
if (preLoader.style.display === "none") {
|
||||||
|
clearInterval(loop);
|
||||||
|
__afterPathnameChangeScripts.forEach(script => {
|
||||||
|
if (window.location.pathname.match(script.pattern)) {
|
||||||
|
script.function();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}, 100);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue