Files
zulip/static/js/portico/help.js
Brock Whittaker 7cb7158a42 /help/: Re-add perfectScrollbar for sidebar and markdown.
This adds back the perfectScrollbar for the sidebar and markdown
sections because we already lost CTRL-F functionality, so we may
as well bring back the pretty, non-obtrusive scrollbars.

This updates the scrollbar after a successful `slideToggle` of
one of the sidebar sections.

Fixes: #6999.
2017-10-17 17:14:36 -07:00

90 lines
2.1 KiB
JavaScript

const Ps = require('perfect-scrollbar');
(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", "swing", function () {
Ps.update($(".markdown")[0]);
});
}
});
$(".sidebar a").click(function (e) {
var path = $(this).attr("href");
var container = $(".markdown")[0];
if (loading.name === path) {
return;
}
history.pushState({}, "", path);
if (html_map[path]) {
$(".markdown .content").html(html_map[path]);
Ps.update(container);
} else {
loading.name = path;
fetch_page(path, function (res) {
html_map[path] = res;
$(".markdown .content").html(html_map[path]);
loading.name = null;
Ps.update(container);
});
}
container.scrollTop = 0;
$(".sidebar").removeClass("show");
e.preventDefault();
});
Ps.initialize($(".markdown")[0], {
suppressScrollX: true,
useKeyboard: false,
wheelSpeed: 0.68,
});
Ps.initialize($(".sidebar")[0], {
suppressScrollX: true,
useKeyboard: false,
wheelSpeed: 0.68,
});
window.onresize = function () {
Ps.update($(".markdown")[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");
}
});
}());