2019-07-10 23:48:45 +02:00
|
|
|
"use strict"; /* global document, Jets, send, window */
|
2018-08-02 00:18:39 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2019-07-10 23:48:45 +02:00
|
|
|
// NOTE:
|
|
|
|
// We declare `contentTag` and `jets` with `var` here so
|
|
|
|
// when a visitor toggles the API page version, they are
|
|
|
|
// not incorrectly declared multiple times via `let || const`
|
|
|
|
|
2018-10-02 00:11:20 +02:00
|
|
|
// Initiate search functionality
|
2019-07-10 23:48:45 +02:00
|
|
|
if (!contentTag)
|
|
|
|
var contentTag;
|
|
|
|
|
|
|
|
contentTag = window.location.pathname.split("/").pop() === "sdk" ?
|
2019-04-12 21:08:35 +02:00
|
|
|
".api-toc__section" :
|
|
|
|
"#toc";
|
|
|
|
|
2019-07-10 23:48:45 +02:00
|
|
|
if (!jets)
|
|
|
|
var jets;
|
|
|
|
|
|
|
|
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
|
|
|
});
|
|
|
|
|
2019-01-30 23:15:10 +01:00
|
|
|
|
|
|
|
|
|
|
|
// H E L P E R S
|
|
|
|
|
2019-07-10 23:48:45 +02:00
|
|
|
function changeDocumentationVersion(desiredVersion) { // eslint-disable-line no-unused-vars
|
|
|
|
send({
|
|
|
|
message: "view different documentation version",
|
|
|
|
version: desiredVersion
|
|
|
|
});
|
2019-07-10 19:34:19 +02:00
|
|
|
}
|
|
|
|
|
2019-01-30 23:15:10 +01:00
|
|
|
function handleApiLanguageToggles(language) {
|
2019-05-10 00:37:52 +02:00
|
|
|
if (!document.getElementById(`toggle-${language}`))
|
|
|
|
return;
|
|
|
|
|
2019-01-30 23:15:10 +01:00
|
|
|
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
|
|
|
|
2019-07-10 23:48:45 +02:00
|
|
|
function initializeApiFunctionality() { // eslint-disable-line no-unused-vars
|
|
|
|
// Reset search on page load
|
|
|
|
document.getElementById("input-search").value = "";
|
|
|
|
|
|
|
|
// Activate search
|
|
|
|
document.getElementById("input-search").addEventListener("keyup", () => {
|
|
|
|
if (document.getElementById("input-search").value)
|
|
|
|
document.querySelector(".api-toc__search-clear").classList.add("active");
|
|
|
|
else
|
|
|
|
document.querySelector(".api-toc__search-clear").classList.remove("active");
|
|
|
|
});
|
|
|
|
|
|
|
|
// Cancel search
|
|
|
|
document.querySelector(".api-toc__search-clear").addEventListener("click", () => {
|
|
|
|
document.getElementById("input-search").value = "";
|
|
|
|
document.querySelector(".api-toc__search-clear").classList.remove("active");
|
|
|
|
|
|
|
|
jets.destroy();
|
|
|
|
reinitJets();
|
|
|
|
});
|
|
|
|
|
|
|
|
// Handle menu toggle for mobile
|
|
|
|
if (document.getElementById("toggle-menu")) {
|
|
|
|
document.getElementById("toggle-menu").addEventListener("click", () => {
|
|
|
|
document.querySelector("body").classList.toggle("disable-scrolling");
|
|
|
|
document.querySelector(".api-toc").classList.toggle("active");
|
|
|
|
});
|
|
|
|
|
|
|
|
// Handle menu toggle when clicking on commands
|
|
|
|
document.querySelectorAll(".api-toc__command a").forEach(command => {
|
|
|
|
command.addEventListener("click", () => {
|
|
|
|
document.querySelector("body").classList.remove("disable-scrolling");
|
|
|
|
document.querySelector(".api-toc").classList.remove("active");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// Code toggles
|
|
|
|
handleApiLanguageToggles("cli");
|
|
|
|
handleApiLanguageToggles("curl");
|
|
|
|
handleApiLanguageToggles("lbrynet");
|
|
|
|
handleApiLanguageToggles("python");
|
2019-07-11 23:20:50 +02:00
|
|
|
|
|
|
|
// Ensure version selector shows correct version, even on page reloads
|
|
|
|
const currentValue = document.querySelector(".api-content__body h2").textContent.split(/\s/g).pop();
|
|
|
|
const { children } = document.querySelector(".api-toc__select");
|
|
|
|
|
|
|
|
for (const child of children) {
|
|
|
|
if (currentValue === child.text)
|
|
|
|
document.querySelector(".api-toc__select").selectedIndex = child.index;
|
|
|
|
}
|
2019-07-10 23:48:45 +02:00
|
|
|
}
|
|
|
|
|
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
|
|
|
});
|
2019-05-14 21:40:35 +02:00
|
|
|
|
2018-10-02 00:11:20 +02:00
|
|
|
document.getElementById("input-search").focus();
|
2018-08-02 00:18:39 +02:00
|
|
|
}
|