lbry.tech/app/components/client/api-scripts.js

65 lines
1 KiB
JavaScript
Raw Normal View History

2018-08-02 00:18:39 +02:00
/* global $, Jets */ "use strict";
/**
* Initiate search functionality
*/
2018-08-02 00:18:39 +02:00
let jets = new Jets({
contentTag: "#toc",
searchTag: "#input-search"
2018-08-02 00:18:39 +02:00
});
/**
* Reset search on page load
*/
2018-08-02 00:18:39 +02:00
$("#input-search")[0].value = "";
2018-08-02 00:18:39 +02:00
/**
* Activate search
*/
2018-08-02 00:18:39 +02:00
$("#input-search").on("keyup", () => {
if ($("#input-search").val()) $(".api__toc__search__clear").addClass("active");
else $(".api__toc__search__clear").removeClass("active");
});
/**
* Cancel search
*/
2018-08-02 00:18:39 +02:00
$(".api__toc__search__clear").on("click", () => {
$("#input-search")[0].value = "";
$(".api__toc__search__clear").removeClass("active");
jets.destroy();
reinitJets();
});
/**
* Add hash to URL bar when sidebar links are clicked
*/
$(".api__toc__item a").on("click", event => {
const hash = event.currentTarget.href.split("#")[1];
history.replaceState({}, "", `#${hash}`);
});
2018-08-02 00:18:39 +02:00
// H E L P E R
/**
* Reinitialize search functionality
*/
2018-08-02 00:18:39 +02:00
function reinitJets() {
jets = new Jets({
contentTag: "#toc",
searchTag: "#input-search"
2018-08-02 00:18:39 +02:00
});
$("#input-search").focus();
}