Skip to content

Commit 828795f

Browse files
author
Jacek Gębal
committed
Fixes to shared navigation
1 parent b8c2ac0 commit 828795f

1 file changed

Lines changed: 21 additions & 15 deletions

File tree

docs/assets/topbar.js

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -230,21 +230,6 @@
230230
controls.appendChild(themeBtn);
231231
bar.appendChild(controls);
232232

233-
/* Injected only after the topbar is successfully built so that a JS failure
234-
leaves Material's original header navigation intact as a fallback. */
235-
if (!document.getElementById('utplsql-topbar-style')) {
236-
var style = document.createElement('style');
237-
style.id = 'utplsql-topbar-style';
238-
style.textContent =
239-
/* Hide Material's hamburger/logo — our topbar has both */
240-
'.md-header__button:not([for="__search"]) { display: none !important; }' +
241-
/* Move palette toggle off-screen — our topbar handles theme switching */
242-
'.md-header__option { position: absolute !important; left: -9999px !important; }' +
243-
/* Back-to-top button: clear topbar + header */
244-
'.md-top { top: 4.4rem !important; z-index: 11; }';
245-
document.head.appendChild(style);
246-
}
247-
248233
savedBar = bar;
249234
document.body.insertBefore(bar, document.body.firstChild);
250235
updateActiveLink();
@@ -258,6 +243,27 @@
258243
});
259244
}
260245

246+
/* Hide Material's built-in header controls immediately — same pattern as
247+
applyScheme — to prevent a flash where logo/palette appear before the
248+
topbar is painted. A fallback timeout removes the style if the topbar
249+
never gets built (e.g. script error), restoring Material's navigation. */
250+
if (!document.getElementById('utplsql-topbar-style')) {
251+
var _style = document.createElement('style');
252+
_style.id = 'utplsql-topbar-style';
253+
_style.textContent =
254+
'.md-header__button:not([for="__search"]) { display: none !important; }' +
255+
'.md-header__option { position: absolute !important; left: -9999px !important; }' +
256+
'.md-top { top: 4.4rem !important; z-index: 11; }';
257+
document.head.appendChild(_style);
258+
/* Fallback: if topbar not in DOM after 4 s, restore Material's navigation */
259+
setTimeout(function () {
260+
if (!document.getElementById('utplsql-topbar')) {
261+
var s = document.getElementById('utplsql-topbar-style');
262+
if (s) s.parentNode.removeChild(s);
263+
}
264+
}, 4000);
265+
}
266+
261267
/* Apply initial scheme as early as possible to avoid flash. */
262268
applyScheme(effectiveScheme(getPreference()));
263269

0 commit comments

Comments
 (0)