2019-04-12 21:08:35 +02:00
|
|
|
"use strict"; /* global document, Jets, window */
|
2018-08-02 00:18:39 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2018-10-02 00:11:20 +02:00
|
|
|
// Initiate search functionality
|
2019-04-12 21:08:35 +02:00
|
|
|
const contentTag = window.location.pathname.split("/").pop() === "sdk" ?
|
|
|
|
".api-toc__section" :
|
|
|
|
"#toc";
|
|
|
|
|
2018-08-02 00:18:39 +02:00
|
|
|
let jets = new Jets({
|
2019-04-12 21:08:35 +02:00
|
|
|
contentTag,
|
2018-08-22 21:08:44 +02:00
|
|
|
searchTag: "#input-search"
|
2018-08-02 00:18:39 +02:00
|
|
|
});
|
|
|
|
|
2018-10-02 00:11:20 +02:00
|
|
|
// Reset search on page load
|
|
|
|
document.getElementById("input-search").value = "";
|
2018-08-02 00:18:39 +02:00
|
|
|
|
2018-10-02 00:11:20 +02:00
|
|
|
// Activate search
|
|
|
|
document.getElementById("input-search").addEventListener("keyup", () => {
|
|
|
|
if (document.getElementById("input-search").value)
|
2019-01-30 23:15:10 +01:00
|
|
|
document.querySelector(".api-toc__search-clear").classList.add("active");
|
2018-10-02 00:11:20 +02:00
|
|
|
else
|
2019-01-30 23:15:10 +01:00
|
|
|
document.querySelector(".api-toc__search-clear").classList.remove("active");
|
2018-08-02 00:18:39 +02:00
|
|
|
});
|
|
|
|
|
2018-10-02 00:11:20 +02:00
|
|
|
// Cancel search
|
2019-01-30 23:15:10 +01:00
|
|
|
document.querySelector(".api-toc__search-clear").addEventListener("click", () => {
|
2018-10-02 00:11:20 +02:00
|
|
|
document.getElementById("input-search").value = "";
|
2019-01-30 23:15:10 +01:00
|
|
|
document.querySelector(".api-toc__search-clear").classList.remove("active");
|
2019-04-12 21:08:35 +02:00
|
|
|
|
2018-08-02 00:18:39 +02:00
|
|
|
jets.destroy();
|
|
|
|
reinitJets();
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-01-30 23:15:10 +01:00
|
|
|
// Code toggles
|
|
|
|
handleApiLanguageToggles("curl");
|
|
|
|
handleApiLanguageToggles("lbrynet");
|
|
|
|
handleApiLanguageToggles("python");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// H E L P E R S
|
|
|
|
|
|
|
|
function handleApiLanguageToggles(language) {
|
|
|
|
document.getElementById(`toggle-${language}`).addEventListener("click", () => {
|
|
|
|
const codeExamples = document.querySelectorAll(`[data-api-example-type="${language}"]`);
|
|
|
|
const examples = document.querySelectorAll("[data-api-example-type]");
|
|
|
|
const toggles = document.querySelectorAll("*[id^='toggle-']");
|
|
|
|
|
2019-02-18 21:31:48 +01:00
|
|
|
examples.forEach(example => example.classList.remove("active"));
|
|
|
|
codeExamples.forEach(example => example.classList.add("active"));
|
|
|
|
toggles.forEach(example => example.classList.remove("active"));
|
2019-01-30 23:15:10 +01:00
|
|
|
|
|
|
|
document.getElementById(`toggle-${language}`).classList.add("active");
|
|
|
|
});
|
|
|
|
}
|
2018-08-02 00:18:39 +02:00
|
|
|
|
|
|
|
function reinitJets() {
|
|
|
|
jets = new Jets({
|
2019-04-12 21:08:35 +02:00
|
|
|
contentTag,
|
2018-08-22 21:08:44 +02:00
|
|
|
searchTag: "#input-search"
|
2018-08-02 00:18:39 +02:00
|
|
|
});
|
|
|
|
|
2018-10-02 00:11:20 +02:00
|
|
|
document.getElementById("input-search").focus();
|
2018-08-02 00:18:39 +02:00
|
|
|
}
|