Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed : SideBar Functionality #108

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 31 additions & 13 deletions frontend/javascript/page_navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,12 @@ export function setupSidebar() {
h2Elements.forEach(function (element) {
appendSidebarItem(element.textContent, 'h2');
});
}

export function saveAndRestoreNavigationPosition() {
var scrollPosition = sessionStorage.getItem('scrollPosition');
if (scrollPosition !== undefined) {
document.querySelector('#navigation-sidebar').scrollTop = parseInt(scrollPosition);
}
document.querySelector('#navigation-sidebar').addEventListener('click', function() {
var scrollPosition = document.querySelector('#navigation-sidebar').scrollTop;
sessionStorage.setItem('scrollPosition', scrollPosition);
console.log('clicked')

const h2Items = document.querySelectorAll('.sidebar-item-h2');
h2Items.forEach(item => {
item.style.paddingTop = '10px';
});
};
}

function appendSidebarItem(textContent, tagName) {
const sidebar = document.querySelector('.sidebar');
Expand All @@ -58,6 +51,19 @@ function appendSidebarItem(textContent, tagName) {
sidebar.appendChild(newItem);

newItem.addEventListener('click', function() {
const allSidebarItems = document.querySelectorAll('.sidebar a');
allSidebarItems.forEach(function(item) {
item.style.color = ''; // Reset color
item.style.fontWeight='';
});

// Change color of clicked item
if(tagName=='h2'){
newItem.style.color = '#34D399';
newItem.style.fontWeight='bold';
}


const currentVersion = newItem.textContent;
const headings = document.querySelectorAll('h2');
let targetElement = null;
Expand All @@ -69,5 +75,17 @@ function appendSidebarItem(textContent, tagName) {
if (targetElement) {
window.scrollTo(0, targetElement.offsetTop - 100);
}
});
});
}

export function saveAndRestoreNavigationPosition() {
var scrollPosition = sessionStorage.getItem('scrollPosition');
if (scrollPosition !== undefined) {
document.querySelector('#navigation-sidebar').scrollTop = parseInt(scrollPosition);
}
document.querySelector('#navigation-sidebar').addEventListener('click', function() {
var scrollPosition = document.querySelector('#navigation-sidebar').scrollTop;
sessionStorage.setItem('scrollPosition', scrollPosition);
console.log('clicked')
});
};
Loading