diff options
author | Phil Hughes <me@iamphill.com> | 2018-11-28 16:37:49 +0300 |
---|---|---|
committer | Phil Hughes <me@iamphill.com> | 2018-11-28 16:37:49 +0300 |
commit | 28380670fe4783cf29345673e63b22ea35621f44 (patch) | |
tree | a804ccaa2afbdfc5dd1dcf46859f7301a2cbcae5 | |
parent | d4c11c53833fbdb95a6d63417028d62438497b1d (diff) |
Fix doc navigation not moving to the sidebar
-rw-r--r-- | content/assets/javascripts/docs.js | 112 |
1 files changed, 55 insertions, 57 deletions
diff --git a/content/assets/javascripts/docs.js b/content/assets/javascripts/docs.js index c5e5b969..56b60b49 100644 --- a/content/assets/javascripts/docs.js +++ b/content/assets/javascripts/docs.js @@ -2,39 +2,39 @@ version: 1 --- -var NAV_INLINE_BREAKPOINT = 1100; - -var landingHeaderBar = document.getElementById('landing-header-bar'); -var headerLinks = document.getElementsByClassName('header-link'); - -if (landingHeaderBar) { - window.addEventListener('scroll', function() { - if (window.scrollY >= 100) { - landingHeaderBar.classList.add('scrolling-header'); - for (var i = 0; i < headerLinks.length; i++) { - headerLinks[i].classList.add('scrolling-header-links'); - } - } else { - landingHeaderBar.classList.remove('scrolling-header'); - for (var i = 0; i < headerLinks.length; i++) { - headerLinks[i].classList.remove('scrolling-header-links'); +document.addEventListener('DOMContentLoaded', function() { + var NAV_INLINE_BREAKPOINT = 1100; + + var landingHeaderBar = document.getElementById('landing-header-bar'); + var headerLinks = document.getElementsByClassName('header-link'); + + if (landingHeaderBar) { + window.addEventListener('scroll', function() { + if (window.scrollY >= 100) { + landingHeaderBar.classList.add('scrolling-header'); + for (var i = 0; i < headerLinks.length; i++) { + headerLinks[i].classList.add('scrolling-header-links'); + } + } else { + landingHeaderBar.classList.remove('scrolling-header'); + for (var i = 0; i < headerLinks.length; i++) { + headerLinks[i].classList.remove('scrolling-header-links'); + } } - } - }); -} + }); + } -var navtoggle = document.getElementById('docs-nav-toggle'); -if (navtoggle) { - navtoggle.addEventListener('click', toggleNavigation); -} + var navtoggle = document.getElementById('docs-nav-toggle'); + if (navtoggle) { + navtoggle.addEventListener('click', toggleNavigation); + } -function toggleNavigation() { - nav = document.getElementsByClassName('header')[0]; - nav.classList.toggle('active'); -} + function toggleNavigation() { + nav = document.getElementsByClassName('header')[0]; + nav.classList.toggle('active'); + } -// move document nav to sidebar -(function() { + // move document nav to sidebar var timeofday = document.getElementById('timeofday'); var tocList = document.querySelector('.js-article-content > ul#markdown-toc'); var main = document.querySelector('.js-main-wrapper'); @@ -125,36 +125,34 @@ function toggleNavigation() { } } - document.addEventListener('DOMContentLoaded', function() { - var globalNav = document.getElementById('global-nav'); - var media = window.matchMedia('(max-width: 1099px)'); - - window.addEventListener('scroll', function(e) { - var isTouchingBottom = false; + var globalNav = document.getElementById('global-nav'); + var media = window.matchMedia('(max-width: 1099px)'); - if (!media.matches) { - isTouchingBottom = - window.scrollY + window.innerHeight >= - document.querySelector('.footer').offsetTop; - } + window.addEventListener('scroll', function(e) { + var isTouchingBottom = false; - if (isTouchingBottom) { - globalNav.style.top = - main.offsetHeight - - (window.scrollY + globalNav.offsetHeight) + - 80 + - 'px'; - } else { - globalNav.style.top = ''; - } - }); + if (!media.matches) { + isTouchingBottom = + window.scrollY + window.innerHeight >= + document.querySelector('.footer').offsetTop; + } - if (media.matches) { - var el = document.getElementById('markdown-toc'); - el.classList.add('collapse'); - el.classList.add('out'); - el.style.height = '34px'; - el.previousElementSibling.classList.add('collapsed'); + if (isTouchingBottom) { + globalNav.style.top = + main.offsetHeight - + (window.scrollY + globalNav.offsetHeight) + + 80 + + 'px'; + } else { + globalNav.style.top = ''; } }); -})(); + + if (media.matches) { + var el = document.getElementById('markdown-toc'); + el.classList.add('collapse'); + el.classList.add('out'); + el.style.height = '34px'; + el.previousElementSibling.classList.add('collapsed'); + } +}); |