This repository has been archived on 2023-02-26. You can view files and clone it, but cannot push or open issues or pull requests.
langue-phundrak-com/js/main.js
Phuntsok Drak-pa 3567ae5d5b removed unused code
The LaTeX conlang class has been added to my dotspacemacs instead
2019-09-03 16:36:41 +02:00

63 lines
1.9 KiB
JavaScript

/*jshint esversion: 6 */
window.onload = function() {
reorganize_html();
create_theme_switcher();
console.log("JS loaded!");
};
function reorganize_html() {
// Move the postamble in the content div
$('#content').append('<hr>');
$('#postamble').appendTo($('#content'));
// Move each table in a div to handle large tables' overflow
$('table').each(function() {
$table = $(this);
$table.before('<div class="largetable"></div>');
$table.prependTo($table.prev());
});
}
function create_theme_switcher() {
// set the correct CSS depending on the cookie, dark is default
var light = isThemeLight();
$('body').append('<div class="themeBtn"><i class="fas fa-'
.concat(light ? 'moon' : 'sun').concat('"></i></div>'));
$('head').append('<link id="theme" rel="stylesheet" href="./css/'
.concat(light ? 'light' : 'dark').concat('.css">'));
// switch CSS files and button icon, set new cookie on theme switcher click
$('.themeBtn').click(function() {
var light = !isThemeLight();
$("#theme").first().attr('href', './css/'
.concat(light ? 'light' : 'dark')
.concat('.css'));
$('.themeBtn').html('<i class="fas fa-'
.concat(light ? 'moon' : 'sun')
.concat('"></i>'));
Cookies.set('light-theme', light ? 'true' : 'false');
});
}
function isThemeLight() {
// set the css and button depending on the cookie found, dark is default
var light;
switch (Cookies.get('light-theme')) {
case 'true':
light = true;
break;
case null: // If no theme cookie is found, set dark by default
Cookies.set('light-theme', false);
/* falls through */
default:
light = false;
break;
}
return light;
}
function isEmpty(el) {
return !$.trim(el.html());
}