help: Refactor code in help.js.

This commit organizes the code properly i.e.
declaring variable on top of the function and
moving window events in the bottom.

Fixes: #9617.
This commit is contained in:
Akash Nimare 2018-06-06 03:00:15 +05:30
parent 5145b24635
commit 5a2c19c67e
1 changed files with 18 additions and 18 deletions

View File

@ -89,6 +89,13 @@ function scrollToHash(container) {
name: null,
};
var markdownPS = new PerfectScrollbar($(".markdown")[0], {
suppressScrollX: true,
useKeyboard: false,
wheelSpeed: 0.68,
scrollingThreshold: 50,
});
var fetch_page = function (path, callback) {
$.get(path, function (res) {
var $html = $(res).find(".markdown .content");
@ -99,13 +106,6 @@ function scrollToHash(container) {
});
};
var markdownPS = new PerfectScrollbar($(".markdown")[0], {
suppressScrollX: true,
useKeyboard: false,
wheelSpeed: 0.68,
scrollingThreshold: 50,
});
new PerfectScrollbar($(".sidebar")[0], {
suppressScrollX: true,
useKeyboard: false,
@ -127,14 +127,13 @@ function scrollToHash(container) {
var path = $(this).attr("href");
var path_dir = path.split('/')[1];
var current_dir = window.location.pathname.split('/')[1];
var container = $(".markdown")[0];
// Do not block redirecting to external URLs
if (path_dir !== current_dir) {
return;
}
var container = $(".markdown")[0];
if (loading.name === path) {
return;
}
@ -174,15 +173,6 @@ function scrollToHash(container) {
window.location.href = window.location.href.replace(/#.*/, '') + '#' + $(this).attr("id");
});
window.onresize = function () {
markdownPS.update();
};
window.addEventListener("popstate", function () {
var path = window.location.pathname;
$(".markdown .content").html(html_map[path]);
});
$(".hamburger").click(function () {
$(".sidebar").toggleClass("show");
});
@ -199,4 +189,14 @@ function scrollToHash(container) {
// to the right place.
var container = $(".markdown")[0];
scrollToHash(container);
window.onresize = function () {
markdownPS.update();
};
window.addEventListener("popstate", function () {
var path = window.location.pathname;
$(".markdown .content").html(html_map[path]);
});
}());