mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-17 06:47:49 +00:00
Move everything into a “blog” directory
This commit is contained in:
40
blog/static/js/main.js
Normal file
40
blog/static/js/main.js
Normal file
@@ -0,0 +1,40 @@
|
||||
window.onload = function() {
|
||||
var container = document.querySelector('#toc');
|
||||
|
||||
if (container != null) {
|
||||
var toc = initTOC({
|
||||
selector: 'h2, h3',
|
||||
scope: '.post',
|
||||
overwrite: false,
|
||||
prefix: 'toc'
|
||||
});
|
||||
|
||||
var heading = document.createElement("H2");
|
||||
var heading_text = document.createTextNode("Table of Contents");
|
||||
heading.appendChild(heading_text);
|
||||
|
||||
container.appendChild(heading);
|
||||
container.appendChild(toc);
|
||||
|
||||
resize_toc(container);
|
||||
}
|
||||
}
|
||||
|
||||
function resize_toc(container) {
|
||||
var containerHeight = container.clientHeight;
|
||||
|
||||
var resize = function() {
|
||||
if (containerHeight > document.documentElement.clientHeight - 100) {
|
||||
container.classList.add('coarse');
|
||||
} else {
|
||||
container.classList.remove('coarse');
|
||||
}
|
||||
};
|
||||
resize();
|
||||
|
||||
var resizeId;
|
||||
window.onresize = function() {
|
||||
clearTimeout(resizeId);
|
||||
resizeId = setTimeout(resize, 300);
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user