add Try new Docs button in the current docs

Signed-off-by: Artem Navoiev <tenmozes@gmail.com>
This commit is contained in:
Artem Navoiev 2023-11-01 17:22:49 +01:00 committed by Aliaksandr Valialkin
parent ae9b4c94bc
commit 23d09684a6
No known key found for this signature in database
GPG key ID: A72BEC6CD3D0DED1
2 changed files with 35 additions and 5 deletions

View file

@ -10,19 +10,36 @@ window.addEventListener("load", function () {
href = hash href = hash
} }
const sidebar = document.querySelector('.sidebar .toctree'); const sidebar = document.querySelector('.sidebar .toctree');
const selector = function(href) {return `a[href="${href}"]`}; const selector = function (href) {
return `a[href="${href}"]`
};
let element = sidebar.querySelector(selector(href)); let element = sidebar.querySelector(selector(href));
if (!element) { if (!element) {
href = window.location.pathname; href = window.location.pathname;
element = document.querySelector(selector(href)); element = document.querySelector(selector(href));
} }
if (element) { if (element) {
element.scrollIntoView({ behavior: "smooth", block: "center", inline: "nearest" }); element.scrollIntoView({behavior: "smooth", block: "center", inline: "nearest"});
} }
addNewDocsButton()
}); });
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);
}
}
}
$(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) {
/* ignore links without anchor */ /* ignore links without anchor */
@ -32,8 +49,8 @@ $(document).on("click", '.shift li.toc a', function(e) {
e.preventDefault(); e.preventDefault();
$("#toggle").click(); $("#toggle").click();
setTimeout(function () { setTimeout(function () {
location.hash = segments.pop(); location.hash = segments.pop();
},1) }, 1)
}); });
/* Clipboard-copy snippet from https://github.com/marcoaugustoandrade/jekyll-clipboardjs/blob/master/copy.js */ /* Clipboard-copy snippet from https://github.com/marcoaugustoandrade/jekyll-clipboardjs/blob/master/copy.js */

View file

@ -49,3 +49,16 @@
.markdown-body h4 { .markdown-body h4 {
font-family: 'Lato', sans-serif !important; font-family: 'Lato', sans-serif !important;
} }
// try new page button
.navigation-top {
min-height: 32px;
}
.navigation-top > a:last-child{
padding-left: 5px
}
.navigation-top > .btn {
margin-left: auto
}