2021-07-05 11:34:10 +00:00
|
|
|
/* When in mobile layout, the anchor navigation for submenus
|
|
|
|
* doesn't work due to fixed body height when menu is toggled.
|
|
|
|
* This script intercepts clicks on links, toggles the menu off
|
|
|
|
* and performs the anchor navigation. */
|
2023-06-23 10:05:32 +00:00
|
|
|
|
|
|
|
window.addEventListener("load", function () {
|
|
|
|
let href = window.location.pathname;
|
|
|
|
const hash = window.location.hash;
|
|
|
|
if (hash !== "") {
|
|
|
|
href = hash
|
|
|
|
}
|
|
|
|
const sidebar = document.querySelector('.sidebar .toctree');
|
2023-11-01 16:22:49 +00:00
|
|
|
const selector = function (href) {
|
|
|
|
return `a[href="${href}"]`
|
|
|
|
};
|
2023-06-23 10:05:32 +00:00
|
|
|
let element = sidebar.querySelector(selector(href));
|
|
|
|
if (!element) {
|
|
|
|
href = window.location.pathname;
|
|
|
|
element = document.querySelector(selector(href));
|
|
|
|
}
|
|
|
|
if (element) {
|
2023-11-01 16:22:49 +00:00
|
|
|
element.scrollIntoView({behavior: "smooth", block: "center", inline: "nearest"});
|
2023-06-23 10:05:32 +00:00
|
|
|
}
|
2023-11-01 16:22:49 +00:00
|
|
|
addNewDocsButton()
|
2023-06-23 10:05:32 +00:00
|
|
|
});
|
|
|
|
|
2023-11-01 16:22:49 +00:00
|
|
|
function addNewDocsButton() {
|
|
|
|
let navigationBox = document.querySelector(".navigation-top");
|
|
|
|
if (navigationBox) {
|
|
|
|
let newDocsButton = document.createElement('a');
|
|
|
|
newDocsButton.appendChild(document.createTextNode("Try New Docs"));
|
|
|
|
newDocsButton.className = "btn";
|
|
|
|
newDocsButton.title = "Try New Docs";
|
|
|
|
newDocsButton.href = "https://new.docs.victoriametrics.com";
|
|
|
|
let lastA = document.querySelector(".navigation-top > a");
|
|
|
|
if (lastA) {
|
|
|
|
lastA.parentNode.insertBefore(newDocsButton, lastA);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-06-23 10:05:32 +00:00
|
|
|
|
2023-11-01 16:22:49 +00:00
|
|
|
$(document).on("click", '.shift li.toc a', function (e) {
|
2021-07-05 11:34:10 +00:00
|
|
|
let segments = this.href.split('#');
|
|
|
|
if (segments.length < 2) {
|
|
|
|
/* ignore links without anchor */
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
e.preventDefault();
|
|
|
|
$("#toggle").click();
|
|
|
|
setTimeout(function () {
|
2023-11-01 16:22:49 +00:00
|
|
|
location.hash = segments.pop();
|
|
|
|
}, 1)
|
2021-07-05 11:34:10 +00:00
|
|
|
});
|
2021-07-06 05:23:39 +00:00
|
|
|
|
|
|
|
/* Clipboard-copy snippet from https://github.com/marcoaugustoandrade/jekyll-clipboardjs/blob/master/copy.js */
|
|
|
|
let codes = document.querySelectorAll('.with-copy .highlight > pre > code');
|
|
|
|
let countID = 0;
|
|
|
|
codes.forEach((code) => {
|
|
|
|
|
|
|
|
code.setAttribute("id", "code" + countID);
|
|
|
|
|
|
|
|
let btn = document.createElement('button');
|
|
|
|
btn.innerHTML = "Copy";
|
|
|
|
btn.className = "btn-copy";
|
|
|
|
btn.setAttribute("data-clipboard-action", "copy");
|
|
|
|
btn.setAttribute("data-clipboard-target", "#code" + countID);
|
|
|
|
code.before(btn);
|
|
|
|
countID++;
|
|
|
|
});
|
|
|
|
|
2023-06-23 10:05:32 +00:00
|
|
|
let clipboard = new ClipboardJS('.btn-copy');
|