Skip to content

Commit a1e1500

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

1 file changed

Lines changed: 25 additions & 20 deletions

File tree

docs/assets/topbar.js

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,22 @@
154154
});
155155
}
156156

157+
function ensureStyle() {
158+
/* Re-inject the hiding style if Material's instant navigation removed it. */
159+
if (!document.getElementById('utplsql-topbar-style')) {
160+
var s = document.createElement('style');
161+
s.id = 'utplsql-topbar-style';
162+
s.textContent =
163+
'.md-header__button:not([for="__search"]) { display: none !important; }' +
164+
'.md-header__option { position: absolute !important; left: -9999px !important; }' +
165+
'.md-top { top: 4.4rem !important; z-index: 11; }';
166+
document.head.appendChild(s);
167+
}
168+
}
169+
157170
function inject() {
171+
ensureStyle();
172+
158173
/* Topbar already in DOM — just sync state. */
159174
if (document.getElementById('utplsql-topbar')) {
160175
updateActiveLink();
@@ -243,26 +258,16 @@
243258
});
244259
}
245260

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-
}
261+
/* Hide Material's built-in header controls immediately to prevent a flash
262+
where logo/palette appear before the topbar is painted. */
263+
ensureStyle();
264+
/* Fallback: if topbar not in DOM after 4 s, restore Material's navigation. */
265+
setTimeout(function () {
266+
if (!document.getElementById('utplsql-topbar')) {
267+
var s = document.getElementById('utplsql-topbar-style');
268+
if (s) s.parentNode.removeChild(s);
269+
}
270+
}, 4000);
266271

267272
/* Apply initial scheme as early as possible to avoid flash. */
268273
applyScheme(effectiveScheme(getPreference()));

0 commit comments

Comments
 (0)