2When showing the sticky version warning, the warning will cover the
3scroll target when navigating to #id hash locations. Take over scrolling
4to adjust the position to account for the height of the warning.
7 const versionWarning = $('.version-warning')
9 // Skip if there is no version warning, regular browser behavior is
11 if (versionWarning.length) {
12 const height = versionWarning.outerHeight(true)
13 const target = $(':target')
15 // Adjust position when the initial link has a hash.
17 // Use absolute scrollTo instead of relative scrollBy to avoid
18 // scrolling when the viewport is already at the bottom of the
19 // document and has space.
20 const y = target.offset().top - height
21 // Delayed because the initial browser scroll doesn't seem to
22 // happen until after the document ready event, so scrolling
23 // immediately will be overridden.
24 setTimeout(() => scrollTo(0, y), 100)
27 // Listen to clicks on hash anchors.
28 $('a[href^="#"]').on('click', e => {
29 // Stop default scroll. Also stops the automatic URL hash update.
31 // Get the id to scroll to and set the URL hash manually.
32 const id = $(e.currentTarget).attr('href').substring(1)
34 // Use getElementById since the hash may have dots in it.
35 const target = $(document.getElementById(id))
36 // Scroll to top of target with space for the version warning.
37 scrollTo(0, target.offset().top - height)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list