mirror of
https://github.com/FlipsideCrypto/convox.git
synced 2026-02-06 10:56:56 +00:00
* stub out docs * add docs app * remove unused gcp code for packr * handle toc ajax * use SEGMENT_TOKEN for segment * remove manual install directory * docs first pass * remove loggin docs for now * remove webhooks docs for now * tweak docs list to first pass intentions * fix header links and add gen2
76 lines
1.7 KiB
JavaScript
76 lines
1.7 KiB
JavaScript
$(window).ready(function () {
|
|
$("a").each(hijackLocalLink);
|
|
|
|
scrollActiveToc();
|
|
addHeadingAnchors();
|
|
});
|
|
|
|
$(window).on('popstate', function (e) {
|
|
if (e.originalEvent.state) {
|
|
loadDocument(e.originalEvent.state.href)
|
|
} else {
|
|
loadDocument(window.location.href);
|
|
}
|
|
})
|
|
|
|
function addHeadingAnchors() {
|
|
$("h2, h3, h4, h5, h6").each(function (i, el) {
|
|
$(el).prepend($('<a class="heading-link"><i class="fa fa-link"></a>').attr("href", "#" + $(el).attr("id")));
|
|
});
|
|
}
|
|
|
|
function hijackLocalLink(i, a) {
|
|
if (window.location.host == a.host) {
|
|
$(a).on('click', function (e) {
|
|
loadDocument(a.href);
|
|
history.pushState({ href: a.href }, '', a.href);
|
|
return (false);
|
|
})
|
|
}
|
|
}
|
|
|
|
function loadDocument(href) {
|
|
$('nav#toc a').blur().removeClass('active');
|
|
var url = new URL(href);
|
|
console.log('url', url);
|
|
$.get('/toc' + url.pathname, function (data) {
|
|
$('nav#toc').html(data);
|
|
scrollActiveToc();
|
|
});
|
|
$.get(href + '?partial', function (data) {
|
|
$('main').html(data);
|
|
$('main').scrollTop(0);
|
|
$('main a').each(hijackLocalLink);
|
|
addHeadingAnchors();
|
|
var anchor = href.split('#')[1];
|
|
if (anchor) {
|
|
var anchorlink = $(`main a[href="#${anchor}"]`).get(0)
|
|
if (anchorlink) {
|
|
anchorlink.scrollIntoView({ behavior: 'smooth', block: 'start' });
|
|
}
|
|
}
|
|
})
|
|
|
|
}
|
|
|
|
function queryChange() {
|
|
if ($('#search-query').val() != '') {
|
|
queryShow();
|
|
}
|
|
}
|
|
|
|
function queryClose() {
|
|
window.setTimeout(function () { $('#search-hits').hide(200); }, 500);
|
|
}
|
|
|
|
function queryShow() {
|
|
$('#search-hits').show(200);
|
|
}
|
|
|
|
function scrollActiveToc() {
|
|
var active = $('nav#toc a.active').get(0);
|
|
if (active) {
|
|
active.scrollIntoView({ block: 'center' });
|
|
}
|
|
}
|