Files

52 lines
1.5 KiB
JavaScript
Raw Permalink Normal View History

/* Open up the table of contents to a specified level in the hierarchy: */
/*
function show_all() {
let level_buttons = K.getv(".depthchoice");
level_buttons[level_buttons.length-1].click();
}
function show_highlighted(node) {
//let carets = K.getv(".caret");
let node_caret = node.parentNode.previousElementSibling;
console.log(node_caret);
}
*/
window.addEventListener("load", function (event) {
K.map(".depthchoice", function (depthchoice) {
depthchoice.addEventListener("click", function (event) {
//save_position();
let max_depth = K.text(event.srcElement);
K.map(".caret", function (e) {
let level = K.attr(e, "data-level");
let open = K.has_class(e, "caret-down");
if (level < max_depth) {
if (!open) {
e.click();
}
} else {
if (open) {
e.click();
}
}
});
//restore_position();
});
});
K.get("html").addEventListener("keypress", function (event) {
const max_depth = K.getv(".depthchoice").length;
const zero = 48; // Hah!
let depth = 1;
for (depth = 1; depth <= max_depth; depth += 1) {
if (event.which === zero + depth) {
K.get('.depthchoice[data-depth="' + depth + '"]').click();
}
}
});
highlight_headers_in_toc();
});