2019-08-25 02:48:03 +00:00
|
|
|
/*jshint esversion: 6 */
|
|
|
|
|
|
|
|
var light = false;
|
|
|
|
|
2019-08-24 23:28:24 +00:00
|
|
|
window.onload = function() {
|
2019-08-25 02:48:03 +00:00
|
|
|
reorganize_html();
|
|
|
|
create_theme_switcher();
|
2019-08-26 14:58:30 +00:00
|
|
|
roll_elems();
|
2019-08-25 02:48:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
function roll_elems() {
|
2019-08-24 23:28:24 +00:00
|
|
|
// Add the possibility for all headers to roll what follows them
|
2019-08-25 02:48:03 +00:00
|
|
|
['h2', 'h3', 'h4', 'h5', 'h6'].forEach(htitle => {
|
2019-08-24 23:28:24 +00:00
|
|
|
$(htitle).addClass('rolled');
|
|
|
|
});
|
|
|
|
|
|
|
|
// Except for the footnotes
|
|
|
|
$('.footnotes').removeClass('rolled');
|
|
|
|
|
2019-08-26 14:58:30 +00:00
|
|
|
// // Make the rollable headers actually rollable and rolled
|
|
|
|
$('.header-container').each(function($header) {
|
2019-08-24 23:28:24 +00:00
|
|
|
$header = $(this);
|
2019-08-26 14:58:30 +00:00
|
|
|
$header.click(function() {
|
|
|
|
$header.nextAll().each(function() {
|
|
|
|
$(this).slideToggle(500);
|
|
|
|
});
|
|
|
|
$header.find('>:first-child').toggleClass('unrolled');
|
|
|
|
$header.find('>:first-child').toggleClass('rolled');
|
2019-08-24 23:28:24 +00:00
|
|
|
});
|
|
|
|
});
|
2019-08-25 02:48:03 +00:00
|
|
|
}
|
2019-08-24 23:35:23 +00:00
|
|
|
|
2019-08-25 02:48:03 +00:00
|
|
|
function reorganize_html() {
|
2019-08-29 11:51:20 +00:00
|
|
|
// Remove table of contents
|
|
|
|
$("#table-of-contents").remove();
|
|
|
|
|
2019-08-24 23:35:23 +00:00
|
|
|
// Move the title out of the content div
|
2019-08-26 14:58:30 +00:00
|
|
|
$('#content').before('<div class="h1-container"><div class="highlight-h1"></div></div>');
|
|
|
|
$('.title').prependTo($('.h1-container'));
|
2019-08-24 23:35:23 +00:00
|
|
|
|
|
|
|
// Move the postamble in the content div
|
2019-08-25 02:48:03 +00:00
|
|
|
$('#postamble').appendTo($('#content'));
|
2019-08-24 23:35:23 +00:00
|
|
|
|
2019-08-26 14:58:30 +00:00
|
|
|
// Move to container the various heads
|
|
|
|
[2, 3, 4, 5, 6].forEach(htitle => {
|
|
|
|
$('h' + htitle).each(function() {
|
|
|
|
$header = $(this);
|
|
|
|
$header.before('<div class="header-container"><div class="highlight-h' +
|
|
|
|
htitle + '"></div></div>');
|
|
|
|
$header.prependTo($header.prev());
|
|
|
|
});
|
2019-08-26 14:59:28 +00:00
|
|
|
$('.outline-text-' + htitle).each(function() {
|
|
|
|
if (isEmpty($(this))) {
|
2019-08-26 14:58:30 +00:00
|
|
|
$(this).remove();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-08-24 23:35:23 +00:00
|
|
|
// Move each table in a div to handle large tables' overflow
|
2019-08-25 02:48:03 +00:00
|
|
|
$('table').each(function() {
|
2019-08-24 23:28:24 +00:00
|
|
|
$table = $(this);
|
|
|
|
$table.before('<div class="largetable"></div>');
|
|
|
|
$table.prependTo($table.prev());
|
|
|
|
});
|
2019-08-25 02:48:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function create_theme_switcher() {
|
|
|
|
// If no theme cookie is found, set dark by default
|
|
|
|
if (Cookies.get('theme') == null) {
|
|
|
|
Cookies.set('theme', 'dark');
|
|
|
|
}
|
|
|
|
|
|
|
|
// set the css and button depending on the cookie found, dark is default
|
2019-08-25 03:20:06 +00:00
|
|
|
if (Cookies.get('theme') == 'light') {
|
2019-08-25 02:48:03 +00:00
|
|
|
$('body').append('<div class="themeBtn"><i class="fas fa-moon"></i></div>');
|
2019-08-25 03:20:06 +00:00
|
|
|
$('head').append('<link id="theme" rel="stylesheet" href="./css/light.css">');
|
|
|
|
} else {
|
|
|
|
$('body').append('<div class="themeBtn"><i class="fas fa-sun"></i></div>');
|
|
|
|
$('head').append('<link id="theme" rel="stylesheet" href="./css/dark.css">');
|
2019-08-25 02:48:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// switch CSS files and button icon, set new cookie
|
|
|
|
$('.themeBtn').click(function() {
|
|
|
|
if (Cookies.get('theme') == 'dark') {
|
|
|
|
$('link[href="./css/dark.css"]').attr('href', './css/light.css');
|
|
|
|
$('.themeBtn').html('<i class="fas fa-moon"></i>');
|
|
|
|
Cookies.set('theme', 'light');
|
|
|
|
} else {
|
|
|
|
$('link[href="./css/light.css"]').attr('href', './css/dark.css');
|
|
|
|
$('.themeBtn').html('<i class="fas fa-sun"></i>');
|
|
|
|
Cookies.set('theme', 'dark');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2019-08-26 14:58:30 +00:00
|
|
|
|
2019-08-26 14:59:28 +00:00
|
|
|
function isEmpty(el) {
|
2019-08-29 11:51:20 +00:00
|
|
|
return !$.trim(el.html());
|
2019-08-26 14:58:30 +00:00
|
|
|
}
|