Skip to content

Commit

Permalink
Fix LHN toggle in responsive view!
Browse files Browse the repository at this point in the history
  • Loading branch information
Talha345 committed Sep 12, 2023
1 parent 95a0edc commit 87aec5f
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions docs/assets/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ function navigateBack() {

if (referrer.includes(currentHost) && window.history.length > 1) {
window.history.back();
toggleHeaderMenu();
return;
}

Expand Down Expand Up @@ -206,13 +207,6 @@ window.addEventListener('DOMContentLoaded', () => {

// If there is a fixed article scroll container, set to calculate titles' offset
scrollContainer: 'content-area',

// onclick function to apply to all links in toc. will be called with
// the event as the first parameter, and this can be used to stop,
// propagation, prevent default or perform action
onClick() {
toggleHeaderMenu();
},
});
}

Expand All @@ -226,6 +220,18 @@ window.addEventListener('DOMContentLoaded', () => {

const articleContent = document.getElementById('article-content');
const lhnContent = document.getElementById('lhn-content');

// This event listener checks if a link clicked in the LHN points to some section of the same page and toggles
// the LHN menu in responsive view.
lhnContent.addEventListener('click', (event) => {
const clickedLink = event.target;
if (clickedLink) {
const href = clickedLink.getAttribute('href');
if (href && href.startsWith('#') && !!document.getElementById(href.slice(1))) {
toggleHeaderMenu();
}
}
});
lhnContent.addEventListener('wheel', (e) => {
const scrollTop = lhnContent.scrollTop;
const isScrollingPastLHNTop = e.deltaY < 0 && scrollTop === 0;
Expand Down

0 comments on commit 87aec5f

Please sign in to comment.