Skip navbar theme update when not fixed

This commit is contained in:
Mark Dumay
2024-08-21 10:41:07 +02:00
parent a0293cc081
commit 628eb99f62
3 changed files with 6 additions and 5 deletions

View File

@@ -2,6 +2,7 @@ assets/js/critical/languageSelector.js
assets/js/critical/color.js assets/js/critical/color.js
assets/js/analytics.js assets/js/analytics.js
assets/js/flexsearch.js assets/js/flexsearch.js
assets/js/navbar.js
assets/js/sharing.js assets/js/sharing.js
assets/js/vendor assets/js/vendor
node_modules node_modules

View File

@@ -1,3 +1,4 @@
const fixed = {{ site.Params.navigation.fixed }}
const navbar = document.querySelector('.navbar') const navbar = document.querySelector('.navbar')
const togglers = document.querySelectorAll('.main-nav-toggler') const togglers = document.querySelectorAll('.main-nav-toggler')
const modeSelectors = document.querySelectorAll('.switch-mode-collapsed') const modeSelectors = document.querySelectorAll('.switch-mode-collapsed')
@@ -20,7 +21,7 @@ function updateNavbar () {
if ((navbar !== null) && (window.performance.getEntriesByType)) { if ((navbar !== null) && (window.performance.getEntriesByType)) {
if (window.performance.getEntriesByType('navigation')[0].type === 'reload') { if (window.performance.getEntriesByType('navigation')[0].type === 'reload') {
updateNavbar() fixed && updateNavbar()
} }
} }
@@ -32,7 +33,7 @@ if (navbar !== null && togglers !== null) {
attributeFilter: ['data-bs-theme'] attributeFilter: ['data-bs-theme']
} }
const Observer = new MutationObserver((mutationrecords) => { const Observer = new MutationObserver((mutationrecords) => {
updateNavbar() fixed && updateNavbar()
}) })
Observer.observe(html, config) Observer.observe(html, config)
@@ -43,7 +44,7 @@ if (navbar !== null && togglers !== null) {
// set the navbar background color to opaque when scrolling past a breakpoint // set the navbar background color to opaque when scrolling past a breakpoint
window.onscroll = () => { window.onscroll = () => {
updateNavbar() fixed && updateNavbar()
} }
// set the navbar background color to opaque when expanded // set the navbar background color to opaque when expanded

View File

@@ -237,7 +237,6 @@
"fade", "fade",
"fas", "fas",
"figure-caption", "figure-caption",
"fixed-top",
"flex-column", "flex-column",
"flex-fill", "flex-fill",
"flex-grow-1", "flex-grow-1",
@@ -333,10 +332,10 @@
"navbar-container", "navbar-container",
"navbar-contrast", "navbar-contrast",
"navbar-expand-md", "navbar-expand-md",
"navbar-fixed-top",
"navbar-mode-selector", "navbar-mode-selector",
"navbar-nav", "navbar-nav",
"navbar-nav-scroll", "navbar-nav-scroll",
"navbar-overlay",
"navbar-title", "navbar-title",
"navbar-toggler", "navbar-toggler",
"next", "next",