2018-05-06 21:43:17 +02:00
|
|
|
/* eslint indent: "off" */
|
2018-07-12 19:18:40 +02:00
|
|
|
import SimpleBar from 'simplebar';
|
2019-01-14 20:26:32 +01:00
|
|
|
import {activate_correct_tab} from './tabbed-instructions.js';
|
2017-10-17 02:22:24 +02:00
|
|
|
|
2017-10-31 06:46:35 +01:00
|
|
|
function registerCodeSection($codeSection) {
|
|
|
|
const $li = $codeSection.find("ul.nav li");
|
|
|
|
const $blocks = $codeSection.find(".blocks div");
|
|
|
|
|
|
|
|
$li.click(function () {
|
|
|
|
const language = this.dataset.language;
|
|
|
|
|
|
|
|
$li.removeClass("active");
|
2018-06-04 21:13:07 +02:00
|
|
|
$li.filter("[data-language=" + language + "]").addClass("active");
|
2017-10-31 06:46:35 +01:00
|
|
|
|
|
|
|
$blocks.removeClass("active");
|
2018-06-04 21:13:07 +02:00
|
|
|
$blocks.filter("[data-language=" + language + "]").addClass("active");
|
2017-10-31 06:46:35 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-12-24 18:22:33 +01:00
|
|
|
function highlight_current_article() {
|
|
|
|
$('.help .sidebar a').removeClass('highlighted');
|
2018-07-23 02:13:59 +02:00
|
|
|
var path = window.location.pathname;
|
2017-12-24 18:22:33 +01:00
|
|
|
|
|
|
|
if (!path) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-07-23 02:13:59 +02:00
|
|
|
var hash = window.location.hash;
|
|
|
|
var article = $('.help .sidebar a[href="' + path + hash + '"]');
|
|
|
|
if (!article.length) {
|
|
|
|
// If there isn't an entry in the left sidebar that matches
|
|
|
|
// the full url+hash pair, instead highlight an entry in the
|
|
|
|
// left sidebar that just matches the url part.
|
|
|
|
article = $('.help .sidebar a[href="' + path + '"]');
|
|
|
|
}
|
2018-06-06 23:46:04 +02:00
|
|
|
// Highlight current article link and the heading of the same
|
|
|
|
article.closest('ul').css('display', 'block');
|
2017-12-24 18:22:33 +01:00
|
|
|
article.addClass('highlighted');
|
|
|
|
}
|
|
|
|
|
2017-10-31 06:46:35 +01:00
|
|
|
function render_code_sections() {
|
|
|
|
$(".code-section").each(function () {
|
2019-01-14 20:26:32 +01:00
|
|
|
activate_correct_tab($(this));
|
2017-10-31 06:46:35 +01:00
|
|
|
registerCodeSection($(this));
|
|
|
|
});
|
2017-12-24 18:22:33 +01:00
|
|
|
|
|
|
|
highlight_current_article();
|
2017-12-23 06:11:25 +01:00
|
|
|
|
2019-06-10 09:22:55 +02:00
|
|
|
common.adjust_mac_shortcuts(".markdown .content code", true);
|
2018-05-26 19:02:18 +02:00
|
|
|
|
|
|
|
$("table").each(function () {
|
|
|
|
$(this).addClass("table table-striped");
|
|
|
|
});
|
2017-10-31 06:46:35 +01:00
|
|
|
}
|
|
|
|
|
2018-07-14 19:28:12 +02:00
|
|
|
function scrollToHash(simplebar) {
|
2018-02-12 20:14:24 +01:00
|
|
|
var hash = window.location.hash;
|
2018-07-14 19:28:12 +02:00
|
|
|
var scrollbar = simplebar.getScrollElement();
|
2018-02-12 20:14:24 +01:00
|
|
|
if (hash !== '') {
|
2018-07-17 02:13:52 +02:00
|
|
|
var position = $(hash).position().top - $(scrollbar.firstChild).position().top;
|
2018-07-14 19:28:12 +02:00
|
|
|
scrollbar.scrollTop = position;
|
2018-02-12 20:14:24 +01:00
|
|
|
} else {
|
2018-07-14 19:28:12 +02:00
|
|
|
scrollbar.scrollTop = 0;
|
2018-02-12 20:14:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-10 20:50:11 +02:00
|
|
|
(function () {
|
|
|
|
var html_map = {};
|
|
|
|
var loading = {
|
|
|
|
name: null,
|
|
|
|
};
|
|
|
|
|
2018-07-12 19:18:40 +02:00
|
|
|
var markdownSB = new SimpleBar($(".markdown")[0]);
|
2018-06-05 23:30:15 +02:00
|
|
|
|
2017-07-10 20:50:11 +02:00
|
|
|
var fetch_page = function (path, callback) {
|
|
|
|
$.get(path, function (res) {
|
|
|
|
var $html = $(res).find(".markdown .content");
|
|
|
|
|
|
|
|
callback($html.html().trim());
|
2017-10-31 06:53:41 +01:00
|
|
|
render_code_sections();
|
2017-07-10 20:50:11 +02:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2018-07-14 19:28:12 +02:00
|
|
|
var update_page = function (html_map, path) {
|
2018-06-05 23:43:56 +02:00
|
|
|
if (html_map[path]) {
|
|
|
|
$(".markdown .content").html(html_map[path]);
|
|
|
|
render_code_sections();
|
2018-07-14 19:28:12 +02:00
|
|
|
scrollToHash(markdownSB);
|
2018-06-05 23:43:56 +02:00
|
|
|
} else {
|
|
|
|
loading.name = path;
|
|
|
|
fetch_page(path, function (res) {
|
|
|
|
html_map[path] = res;
|
|
|
|
$(".markdown .content").html(html_map[path]);
|
|
|
|
loading.name = null;
|
2018-07-14 19:28:12 +02:00
|
|
|
scrollToHash(markdownSB);
|
2018-06-05 23:43:56 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-07-12 19:18:40 +02:00
|
|
|
new SimpleBar($(".sidebar")[0]);
|
2018-03-20 04:10:20 +01:00
|
|
|
|
2017-11-08 21:48:45 +01:00
|
|
|
$(".sidebar.slide h2").click(function (e) {
|
2017-10-04 01:38:47 +02:00
|
|
|
var $next = $(e.target).next();
|
|
|
|
|
|
|
|
if ($next.is("ul")) {
|
2018-06-07 18:46:17 +02:00
|
|
|
// Close other article's headings first
|
|
|
|
$('.sidebar ul').not($next).hide();
|
|
|
|
// Toggle the heading
|
2019-04-24 08:33:34 +02:00
|
|
|
$next.slideToggle("fast", "swing");
|
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-12-22 19:49:24 +01:00
|
|
|
var path_dir = path.split('/')[1];
|
|
|
|
var current_dir = window.location.pathname.split('/')[1];
|
|
|
|
|
|
|
|
// Do not block redirecting to external URLs
|
|
|
|
if (path_dir !== current_dir) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-07-10 20:50:11 +02:00
|
|
|
if (loading.name === path) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
history.pushState({}, "", path);
|
|
|
|
|
2018-07-14 19:28:12 +02:00
|
|
|
update_page(html_map, path);
|
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
|
|
|
|
2018-06-07 18:58:13 +02:00
|
|
|
if (window.location.pathname === '/help/') {
|
|
|
|
// Expand the Guides user docs section in sidebar in the /help/ homepage.
|
|
|
|
$('.help .sidebar h2#guides + ul').show();
|
|
|
|
}
|
2017-11-13 01:46:19 +01:00
|
|
|
// Remove ID attributes from sidebar links so they don't conflict with index page anchor links
|
|
|
|
$('.help .sidebar h1, .help .sidebar h2, .help .sidebar h3').removeAttr('id');
|
|
|
|
|
|
|
|
// Scroll to anchor link when clicked
|
2018-06-15 20:48:00 +02:00
|
|
|
$(document).on('click', '.markdown .content h1, .markdown .content h2, .markdown .content h3', function () {
|
2018-07-17 02:13:52 +02:00
|
|
|
window.location.hash = $(this).attr("id");
|
|
|
|
scrollToHash(markdownSB);
|
2017-11-13 01:46:19 +01:00
|
|
|
});
|
|
|
|
|
2017-07-10 20:50:11 +02:00
|
|
|
$(".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-10-31 06:46:35 +01:00
|
|
|
|
|
|
|
render_code_sections();
|
2018-02-14 18:26:42 +01:00
|
|
|
|
|
|
|
// Finally, make sure if we loaded a window with a hash, we scroll
|
|
|
|
// to the right place.
|
2018-07-14 19:28:12 +02:00
|
|
|
scrollToHash(markdownSB);
|
2018-06-05 23:30:15 +02:00
|
|
|
|
|
|
|
window.addEventListener("popstate", function () {
|
|
|
|
var path = window.location.pathname;
|
2018-07-14 19:28:12 +02:00
|
|
|
update_page(html_map, path);
|
2018-06-05 23:30:15 +02:00
|
|
|
});
|
|
|
|
|
2018-05-26 19:18:06 +02:00
|
|
|
$('body').addClass('noscroll');
|
2017-07-10 20:50:11 +02:00
|
|
|
}());
|