Skip to content
Snippets Groups Projects
Commit 8e113dee authored by Thomas Hackl's avatar Thomas Hackl
Browse files

check for sidebar existence, fixes #2918

parent de66a942
No related branches found
No related tags found
No related merge requests found
...@@ -2,8 +2,11 @@ const Sidebar = { ...@@ -2,8 +2,11 @@ const Sidebar = {
place() { place() {
const header = document.getElementById('main-header'); const header = document.getElementById('main-header');
document.getElementById('sidebar').style.top = const sidebar = document.getElementById('sidebar');
header.offsetTop + header.offsetHeight + 'px'; if (sidebar) {
sidebar.style.top =
header.offsetTop + header.offsetHeight + 'px';
}
}, },
observeSidebar() { observeSidebar() {
...@@ -16,8 +19,11 @@ const Sidebar = { ...@@ -16,8 +19,11 @@ const Sidebar = {
/** /**
* Observe if sidebar fits into viewport. * Observe if sidebar fits into viewport.
*/ */
const sObserver = new IntersectionObserver(STUDIP.Sidebar.fits, options); const sidebar = document.getElementById('sidebar');
sObserver.observe(document.getElementById('sidebar')); if (sidebar) {
const sObserver = new IntersectionObserver(STUDIP.Sidebar.fits, options);
sObserver.observe();
}
}, },
observeBody() { observeBody() {
...@@ -87,18 +93,20 @@ const Sidebar = { ...@@ -87,18 +93,20 @@ const Sidebar = {
footerVisible(entries, observer) { footerVisible(entries, observer) {
const sidebar = document.getElementById('sidebar'); const sidebar = document.getElementById('sidebar');
entries.forEach(entry => { if (sidebar) {
// Footer is visible on current page. entries.forEach(entry => {
if (entry.isIntersecting) { // Footer is visible on current page.
if (sidebar.classList.contains('no-footer')) { if (entry.isIntersecting) {
sidebar.classList.remove('no-footer'); if (sidebar.classList.contains('no-footer')) {
} sidebar.classList.remove('no-footer');
} else { }
if (!sidebar.classList.contains('no-footer')) { } else {
sidebar.classList.add('no-footer'); if (!sidebar.classList.contains('no-footer')) {
sidebar.classList.add('no-footer');
}
} }
} });
}); }
} }
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment