Hash fix for API page and inline documentation

This commit is contained in:
ポール ウェッブ 2018-08-22 14:08:44 -05:00
parent a92480742a
commit d31d26b2df
2 changed files with 46 additions and 7 deletions

View file

@ -2,20 +2,34 @@
/**
* Initiate search functionality
*/
let jets = new Jets({
searchTag: "#input-search",
contentTag: "#toc"
contentTag: "#toc",
searchTag: "#input-search"
});
/**
* Reset search on page load
*/
$("#input-search")[0].value = "";
$("#input-search")[0].value = ""; // reset on page load
/**
* Activate search
*/
$("#input-search").on("keyup", () => {
if ($("#input-search").val()) $(".api__toc__search__clear").addClass("active");
else $(".api__toc__search__clear").removeClass("active");
});
/**
* Cancel search
*/
$(".api__toc__search__clear").on("click", () => {
$("#input-search")[0].value = "";
$(".api__toc__search__clear").removeClass("active");
@ -23,14 +37,27 @@ $(".api__toc__search__clear").on("click", () => {
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}`);
});
// H E L P E R
/**
* Reinitialize search functionality
*/
function reinitJets() {
jets = new Jets({
searchTag: "#input-search",
contentTag: "#toc"
contentTag: "#toc",
searchTag: "#input-search"
});
$("#input-search").focus();

View file

@ -2,13 +2,25 @@
/**
* Add page-specific styling
*/
document.getElementsByTagName("body")[0].classList.add("glossary");
$("[data-action='toggle glossary sidebar']").on("click", () => { // Toggle sidebar
/**
* Toggle sidebar
*/
$("[data-action='toggle glossary sidebar']").on("click", () => {
$("body").toggleClass("sidebar-closed");
});
$(".component--glossary-toc li a").on("click", event => { // Add hash to URL bar
/**
* Add hash to URL bar when sidebar links are clicked
*/
$(".component--glossary-toc li a").on("click", event => {
const hash = event.currentTarget.href.split("#")[1];
history.replaceState({}, "", `#${hash}`);
});