-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommonNav.js
More file actions
28 lines (28 loc) · 1.01 KB
/
commonNav.js
File metadata and controls
28 lines (28 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
if (typeof fetch === 'function') {
const init = () => {
if (typeof scrollToNavItem !== 'function') return false
scrollToNavItem()
// hideAllButCurrent not always loaded
if (typeof hideAllButCurrent === 'function') hideAllButCurrent()
return true
}
fetch('./nav.inc.html')
.then(response => response.ok ? response.text() : `${response.url} => ${response.status} ${response.statusText}`)
.then(body => {
document.querySelector('nav').innerHTML += body
// nav.js should be quicker to load than nav.inc.html, a fallback just in case
return init()
})
.then(done => {
if (done) return
let i = 0
;(function waitUntilNavJs () {
if (init()) return
if (i++ < 100) return setTimeout(waitUntilNavJs, 300)
console.error(Error('nav.js not loaded after 30s waiting for it'))
})()
})
.catch(error => console.error(error))
} else {
console.error(Error('Browser too old to display commonNav (remove commonNav docdash option)'))
}