2017-10-17 02:22:24 +02:00
|
|
|
const Ps = require('perfect-scrollbar');
|
|
|
|
|
2017-07-10 20:50:11 +02:00
|
|
|
(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());
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-10-01 23:00:00 +02:00
|
|
|
$(".sidebar h2").click(function (e) {
|
2017-10-04 01:38:47 +02:00
|
|
|
var $next = $(e.target).next();
|
|
|
|
|
|
|
|
if ($next.is("ul")) {
|
2017-10-17 02:22:24 +02:00
|
|
|
$next.slideToggle("fast", "swing", function () {
|
|
|
|
Ps.update($(".markdown")[0]);
|
|
|
|
});
|
2017-10-04 01:38:47 +02:00
|
|
|
}
|
2017-10-01 23:00:00 +02:00
|
|
|
});
|
|
|
|
|
2017-07-10 20:50:11 +02:00
|
|
|
$(".sidebar a").click(function (e) {
|
|
|
|
var path = $(this).attr("href");
|
2017-10-17 02:22:24 +02:00
|
|
|
var container = $(".markdown")[0];
|
|
|
|
|
2017-07-10 20:50:11 +02:00
|
|
|
|
|
|
|
if (loading.name === path) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
history.pushState({}, "", path);
|
|
|
|
|
|
|
|
if (html_map[path]) {
|
|
|
|
$(".markdown .content").html(html_map[path]);
|
2017-10-17 02:22:24 +02:00
|
|
|
Ps.update(container);
|
2017-07-10 20:50:11 +02:00
|
|
|
} else {
|
|
|
|
loading.name = path;
|
|
|
|
|
|
|
|
fetch_page(path, function (res) {
|
|
|
|
html_map[path] = res;
|
|
|
|
$(".markdown .content").html(html_map[path]);
|
|
|
|
loading.name = null;
|
2017-10-17 02:22:24 +02:00
|
|
|
Ps.update(container);
|
2017-07-10 20:50:11 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-10-17 02:22:24 +02:00
|
|
|
container.scrollTop = 0;
|
2017-07-10 20:50:11 +02:00
|
|
|
$(".sidebar").removeClass("show");
|
|
|
|
|
|
|
|
e.preventDefault();
|
2017-10-17 02:22:24 +02:00
|
|
|
});
|
2017-08-07 16:24:31 +02:00
|
|
|
|
2017-10-17 02:22:24 +02:00
|
|
|
Ps.initialize($(".markdown")[0], {
|
|
|
|
suppressScrollX: true,
|
|
|
|
useKeyboard: false,
|
|
|
|
wheelSpeed: 0.68,
|
|
|
|
});
|
|
|
|
|
|
|
|
Ps.initialize($(".sidebar")[0], {
|
|
|
|
suppressScrollX: true,
|
|
|
|
useKeyboard: false,
|
|
|
|
wheelSpeed: 0.68,
|
2017-07-10 20:50:11 +02:00
|
|
|
});
|
|
|
|
|
2017-10-17 02:22:24 +02:00
|
|
|
window.onresize = function () {
|
|
|
|
Ps.update($(".markdown")[0]);
|
|
|
|
};
|
|
|
|
|
2017-07-10 20:50:11 +02:00
|
|
|
window.addEventListener("popstate", function () {
|
|
|
|
var path = window.location.pathname;
|
|
|
|
$(".markdown .content").html(html_map[path]);
|
|
|
|
});
|
|
|
|
|
|
|
|
$(".hamburger").click(function () {
|
|
|
|
$(".sidebar").toggleClass("show");
|
|
|
|
});
|
2017-08-22 21:03:28 +02:00
|
|
|
|
|
|
|
$(".markdown").click(function () {
|
|
|
|
if ($(".sidebar.show").length) {
|
|
|
|
$(".sidebar.show").toggleClass("show");
|
|
|
|
}
|
|
|
|
});
|
2017-07-10 20:50:11 +02:00
|
|
|
}());
|