mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-03 16:21:14 +01:00
docs: add scroll to the selected element (#4508)
* docs: add scroll to the selected element * docs: scroll to root if element not found * docs: simplify code * docs: code cleanup * docs: fix comments (fix code formatting, check element only inside sidebar container)
This commit is contained in:
parent
a7d1ea5681
commit
d9ef1a5bff
@ -2,6 +2,26 @@
|
|||||||
* doesn't work due to fixed body height when menu is toggled.
|
* doesn't work due to fixed body height when menu is toggled.
|
||||||
* This script intercepts clicks on links, toggles the menu off
|
* This script intercepts clicks on links, toggles the menu off
|
||||||
* and performs the anchor navigation. */
|
* and performs the anchor navigation. */
|
||||||
|
|
||||||
|
window.addEventListener("load", function () {
|
||||||
|
let href = window.location.pathname;
|
||||||
|
const hash = window.location.hash;
|
||||||
|
if (hash !== "") {
|
||||||
|
href = hash
|
||||||
|
}
|
||||||
|
const sidebar = document.querySelector('.sidebar .toctree');
|
||||||
|
const selector = function(href) {return `a[href="${href}"]`};
|
||||||
|
let element = sidebar.querySelector(selector(href));
|
||||||
|
if (!element) {
|
||||||
|
href = window.location.pathname;
|
||||||
|
element = document.querySelector(selector(href));
|
||||||
|
}
|
||||||
|
if (element) {
|
||||||
|
element.scrollIntoView({ behavior: "smooth" });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
$(document).on("click", '.shift li.toc a', function(e) {
|
$(document).on("click", '.shift li.toc a', function(e) {
|
||||||
let segments = this.href.split('#');
|
let segments = this.href.split('#');
|
||||||
if (segments.length < 2) {
|
if (segments.length < 2) {
|
||||||
@ -32,4 +52,4 @@ codes.forEach((code) => {
|
|||||||
countID++;
|
countID++;
|
||||||
});
|
});
|
||||||
|
|
||||||
let clipboard = new ClipboardJS('.btn-copy');
|
let clipboard = new ClipboardJS('.btn-copy');
|
||||||
|
Loading…
Reference in New Issue
Block a user