|
31 | 31 | '<path d="M3 18h18v-2H3v2zm0-5h18v-2H3v2zm0-7v2h18V6H3z"/>' + |
32 | 32 | '</svg>'; |
33 | 33 |
|
34 | | - var SVG_SEARCH = |
35 | | - '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">' + |
36 | | - '<path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.516 6.516 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5z"/>' + |
37 | | - '</svg>'; |
38 | | - |
39 | 34 | var SVG_SUN = |
40 | 35 | '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">' + |
41 | 36 | '<path d="M12 7c-2.76 0-5 2.24-5 5s2.24 5 5 5 5-2.24 5-5-2.24-5-5-5zM2 13h2c.55 0 1-.45 1-1s-.45-1-1-1H2c-.55 0-1 .45-1 1s.45 1 1 1zm18 0h2c.55 0 1-.45 1-1s-.45-1-1-1h-2c-.55 0-1 .45-1 1s.45 1 1 1zM11 2v2c0 .55.45 1 1 1s1-.45 1-1V2c0-.55-.45-1-1-1s-1 .45-1 1zm0 18v2c0 .55.45 1 1 1s1-.45 1-1v-2c0-.55-.45-1-1-1s-1 .45-1 1zM5.99 4.58c-.39-.39-1.03-.39-1.41 0-.39.39-.39 1.03 0 1.41l1.06 1.06c.39.39 1.03.39 1.41 0s.39-1.03 0-1.41L5.99 4.58zm12.37 12.37c-.39-.39-1.03-.39-1.41 0-.39.39-.39 1.03 0 1.41l1.06 1.06c.39.39 1.03.39 1.41 0 .39-.39.39-1.03 0-1.41l-1.06-1.06zm1.06-10.96c.39-.39.39-1.03 0-1.41-.39-.39-1.03-.39-1.41 0l-1.06 1.06c-.39.39-.39 1.03 0 1.41s1.03.39 1.41 0l1.06-1.06zM7.05 18.36c.39-.39.39-1.03 0-1.41-.39-.39-1.03-.39-1.41 0l-1.06 1.06c-.39.39-.39 1.03 0 1.41s1.03.39 1.41 0l1.06-1.06z"/>' + |
|
46 | 41 | '<path d="M12 3c-4.97 0-9 4.03-9 9s4.03 9 9 9 9-4.03 9-9c0-.46-.04-.92-.1-1.36-.98 1.37-2.58 2.26-4.4 2.26-2.98 0-5.4-2.42-5.4-5.4 0-1.81.89-3.42 2.26-4.4-.44-.06-.9-.1-1.36-.1z"/>' + |
47 | 42 | '</svg>'; |
48 | 43 |
|
49 | | - /* Module-level reference so updateThemeIcon can be called from anywhere, |
50 | | - including the instant-navigation callback after the topbar is already built. */ |
| 44 | + /* Module-level references so the built bar can be re-inserted on instant |
| 45 | + navigation without recreating it (prevents the logo img from reloading). */ |
51 | 46 | var themeBtn = null; |
| 47 | + var savedBar = null; |
52 | 48 |
|
53 | 49 | function getScheme() { |
54 | 50 | /* Prefer our own stored key — avoids Material overwriting it on navigation */ |
|
100 | 96 | } |
101 | 97 |
|
102 | 98 | function inject() { |
103 | | - /* On instant navigation the topbar persists — sync state and exit. */ |
| 99 | + /* Topbar already in DOM — just sync state. */ |
104 | 100 | if (document.getElementById('utplsql-topbar')) { |
105 | 101 | updateActiveLink(); |
106 | | - /* Re-apply our scheme AFTER Material's navigation hook may have changed it */ |
107 | 102 | applyStoredScheme(); |
108 | 103 | return; |
109 | 104 | } |
110 | 105 |
|
111 | | - /* ── Bar ── */ |
| 106 | + /* Material's instant navigation removed the topbar — re-insert the same |
| 107 | + DOM node so the logo <img> is not recreated and doesn't flash/reload. */ |
| 108 | + if (savedBar) { |
| 109 | + document.body.insertBefore(savedBar, document.body.firstChild); |
| 110 | + updateActiveLink(); |
| 111 | + applyStoredScheme(); |
| 112 | + return; |
| 113 | + } |
| 114 | + |
| 115 | + /* ── First load: build the bar ── */ |
112 | 116 | var bar = document.createElement('nav'); |
113 | 117 | bar.id = 'utplsql-topbar'; |
114 | 118 | bar.setAttribute('aria-label', 'utPLSQL.org site navigation'); |
|
151 | 155 | var controls = document.createElement('div'); |
152 | 156 | controls.className = 'utplsql-controls'; |
153 | 157 |
|
154 | | - /* Search button — on mobile triggers Material's search overlay via its |
155 | | - own label (the form is hidden until that label is clicked); on desktop |
156 | | - the form is already visible so focusing the input is enough. */ |
157 | | - var searchBtn = document.createElement('button'); |
158 | | - searchBtn.setAttribute('aria-label', 'Search'); |
159 | | - searchBtn.innerHTML = SVG_SEARCH; |
160 | | - searchBtn.addEventListener('click', function () { |
161 | | - var searchLabel = document.querySelector('label[for="__search"]'); |
162 | | - if (searchLabel) { |
163 | | - searchLabel.click(); |
164 | | - } else { |
165 | | - var input = document.querySelector('.md-search__input'); |
166 | | - if (input) input.focus(); |
167 | | - } |
168 | | - }); |
169 | | - controls.appendChild(searchBtn); |
170 | | - |
171 | 158 | /* Theme toggle — assigned to module-level themeBtn so updateThemeIcon |
172 | 159 | can be called from the navigation callback without re-injecting. */ |
173 | 160 | themeBtn = document.createElement('button'); |
|
195 | 182 | controls.appendChild(themeBtn); |
196 | 183 | bar.appendChild(controls); |
197 | 184 |
|
| 185 | + savedBar = bar; |
198 | 186 | document.body.insertBefore(bar, document.body.firstChild); |
199 | 187 | updateActiveLink(); |
200 | 188 | } |
|
0 commit comments