Files
zulip/static/js/portico/help.js
Brock Whittaker a7f602fed6 /help/: Fix sidebar target bug.
This tries to toggle the next item when clicking on an <h2>
in the sidebar, however we want to first check the next item is
an <ul> element, so that we are collapsing or showing a list,
instead of something like an <h2> which currently happens with
the "#guides" element.
2017-10-03 16:38:47 -07:00

68 lines
1.6 KiB
JavaScript

(function () {
var html_map = {};
var loading = {
name: null,
};
var fetch_page = function (path, callback) {
$.get(path, function (res) {
var $html = $(res).find(".markdown .content");
$html.find(".back-to-home").remove();
callback($html.html().trim());
});
};
$(".sidebar h2").click(function (e) {
var $next = $(e.target).next();
if ($next.is("ul")) {
$next.slideToggle("fast");
}
});
$(".sidebar a").click(function (e) {
var path = $(this).attr("href");
if (loading.name === path) {
return;
}
history.pushState({}, "", path);
if (html_map[path]) {
$(".markdown .content").html(html_map[path]);
} else {
loading.name = path;
fetch_page(path, function (res) {
html_map[path] = res;
$(".markdown .content").html(html_map[path]);
loading.name = null;
});
}
$(".sidebar").removeClass("show");
e.preventDefault();
var container = $(".markdown")[0];
container.scrollTop = 0;
});
window.addEventListener("popstate", function () {
var path = window.location.pathname;
$(".markdown .content").html(html_map[path]);
});
$(".hamburger").click(function () {
$(".sidebar").toggleClass("show");
});
$(".markdown").click(function () {
if ($(".sidebar.show").length) {
$(".sidebar.show").toggleClass("show");
}
});
}());