Syllabus/static/js/sandpoints.js

56 lines
2.3 KiB
JavaScript

window.addEventListener('scroll', function(e) {
let rightcolumn = document.querySelector('.rightcolumn');
let element = document.querySelector('.topicstitle')
let topicbar = document.querySelector('.topicbar')
let grid = document.querySelector('.grid')
let rect = element.getBoundingClientRect();
if (rect.top < 12 && !grid.classList.contains('moved')) {
topicbar.style.display = "inline";
element.style.visibility = "hidden";
grid.classList.add('moved');
grid.style.display = "none";
rightcolumn.classList.add('shown');
if (document.querySelector('body').clientHeight > 1024) {
window.scrollBy({top: grid.clientHeight + element.clientHeight, behavior: 'smooth'})
}
} else if (rect.top > 11 && grid.classList.contains('moved')) {
if (document.querySelector('body').clientHeight > 1024) {
grid.classList.remove('moved');
element.style.visibility = "visible";
topicbar.style.display = "none";
window.scroll({top: 0, behavior: 'smooth'})
} else {
rightcolumn.classList.remove('shown');
grid.style.display = "grid";
grid.classList.remove('moved');
topicbar.style.display = "none";
element.style.visibility = "visible";
window.scroll({top: 0, behavior: 'smooth'})
}
}
})
window.addEventListener('DOMContentLoaded', (e) => {
let par = document.querySelector("#TableOfContents > ol:first-child > li:first-child");
let s = document.createElement("span");
s.appendChild(par.cloneNode(true))
par.remove()
document.querySelector("#TableOfContents > ol:first-child").insertBefore(s, document.querySelector("#TableOfContents > ol:first-child").firstChild)
})
var toggle = function(ts) {
let rightcolumn = document.querySelector('.rightcolumn');
let leftcolumn = document.querySelector('.leftcolumn');
let grid = document.querySelector('.grid');
if (rightcolumn.classList.contains('shown')) {
rightcolumn.classList.remove('shown');
rightcolumn.style.display = "none";
grid.style.display = "none";
} else {
rightcolumn.classList.add('shown');
grid.style.cssText = "display: block; padding: 0;";
leftcolumn.style.display = "none";
rightcolumn.style.display = "grid";
}
}