function ReadtheDokus()
{
this._currentPage;
this._currentPageIndex;
this._pages;
this._toc = document.getElementById("dw__toc");
this._sidebar =document.querySelector("#dokuwiki__aside");
}
ReadtheDokus.prototype.run = function()
{
var isFound = false;
this._pages = [];
// Enum sidebar items to
// - embed toc in the corresponding sidebar item
// - collect all page links
if (JSINFO["ACT"] == "show")
{
this._enumSidebarLinks(function(elem) {
// Embed toc
if (elem.href.indexOf(JSINFO["id"]) > -1)
{
this._embedToc(elem);
if (this._toc)
{
this._toc.scrollIntoView(true);
}
isFound = true;
}
// Collect page links
this._pages.push(elem.href);
}.bind(this));
}
// Show toc on top of sidebar if item was not found in sidebar
if (!isFound)
{
if (this._toc)
{
this._showToc();
this._toc.scrollIntoView(true);
}
}
this._initToc();
this._initMobileHeader();
this._initPageButtons();
this._sidebar.querySelector("#sidebarheader #qsearch__in").setAttribute("placeholder", "Search docs");
};
ReadtheDokus.prototype._enumSidebarLinks = function(callback)
{
callback = ( typeof callback === "function" ? callback : function(){} );
//var links = document.querySelectorAll("#dokuwiki__aside .aside > ul .level1 a");
var links = this._sidebar.querySelectorAll("#dokuwiki__aside .aside > ul .level1 a");
links.forEach(function(elem) {
callback(elem);
});
};
ReadtheDokus.prototype._embedToc = function(target)
{
if (target && this._toc)
{
target.parentNode.parentNode.appendChild(this._toc);
target.parentNode.style.display = "none";
}
};
ReadtheDokus.prototype._showToc = function()
{
if (this._toc)
{
this._toc.parentNode.style.display = "block";
}
};
ReadtheDokus.prototype._initToc = function()
{
if (this._toc)
{
// Add click event handler to highlight an menu item
this._toc.querySelectorAll(".level2 a").forEach(function(elem) {
elem.addEventListener("click", function() {
this._toc.querySelectorAll(".current").forEach(function(elem) {
elem.classList.remove("current");
});
elem.classList.add("current");
elem.scrollIntoView(true);
}.bind(this));
}.bind(this));
// Add click event handler to expand/collapse menu
this._toc.querySelectorAll(".level1 a").forEach(function(elem) {
if (elem.parentNode.parentNode.querySelector(".toc"))
{
// elem.insertAdjacentHTML("afterbegin", '');
// elem.insertAdjacentHTML("afterbegin", '
');
elem.insertAdjacentHTML("afterbegin", '