2019-12-12 14:44:23 +00:00
|
|
|
@JS()
|
|
|
|
library main;
|
|
|
|
|
|
|
|
import 'dart:html';
|
|
|
|
|
|
|
|
import 'package:js/js.dart';
|
2019-12-26 14:57:18 +00:00
|
|
|
|
2019-12-12 14:44:23 +00:00
|
|
|
import './cookie.dart';
|
|
|
|
|
|
|
|
void main() {
|
|
|
|
reorganizeHtml();
|
|
|
|
createThemeSwitcher();
|
2019-12-26 14:57:18 +00:00
|
|
|
themeSwitch(isThemeDark());
|
|
|
|
querySelector('.themeBtn').onClick.listen(themeSwitchMouse);
|
2019-12-12 14:44:23 +00:00
|
|
|
}
|
|
|
|
|
2019-12-26 14:57:18 +00:00
|
|
|
String cookieThemeName = 'theme';
|
|
|
|
|
2019-12-12 14:44:23 +00:00
|
|
|
void createThemeSwitcher() {
|
|
|
|
// set the correct CSS depending on the cookie, dark is enabled by default
|
|
|
|
var isDark = isThemeDark();
|
|
|
|
// Set the correct symbol in the theme switcher button
|
|
|
|
querySelector('body').append(DivElement()..className = 'themeBtn');
|
|
|
|
querySelector('.themeBtn')
|
|
|
|
.children
|
|
|
|
.add(Element.tag('i')..className = 'fas fa-' + (isDark ? 'sun' : 'moon'));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isThemeDark() {
|
2019-12-26 14:57:18 +00:00
|
|
|
if (Cookies.get(cookieThemeName) == 'light') {
|
2019-12-12 14:44:23 +00:00
|
|
|
return false;
|
|
|
|
}
|
2019-12-26 14:57:18 +00:00
|
|
|
Cookies.set(cookieThemeName, 'dark');
|
2019-12-12 14:44:23 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void reorganizeHtml() {
|
|
|
|
// Add a <hr> element after the content div
|
|
|
|
querySelector('#content').appendHtml('<hr>');
|
|
|
|
|
|
|
|
// Move the postamble in the content div
|
|
|
|
querySelector('#content').append(querySelector('#postamble'));
|
|
|
|
|
|
|
|
for (var table in querySelectorAll('table')) {
|
|
|
|
var largetable = DivElement();
|
|
|
|
largetable.className = 'largetable';
|
|
|
|
table.before(largetable);
|
|
|
|
largetable.children.add(table);
|
|
|
|
}
|
|
|
|
}
|
2019-12-26 14:57:18 +00:00
|
|
|
|
|
|
|
bool setTheme(bool dark) {
|
|
|
|
Cookies.set(cookieThemeName, (dark ? 'dark' : 'light'));
|
|
|
|
return !dark;
|
|
|
|
}
|
|
|
|
|
|
|
|
void themeSwitch(bool isDark) {
|
|
|
|
querySelector('.fas').className = 'fas fa-' + (isDark ? 'sun' : 'moon');
|
|
|
|
querySelector('#theme').attributes['href'] =
|
2020-02-14 15:15:22 +00:00
|
|
|
'https://langue.phundrak.com/css/' + (isDark ? 'dark' : 'light') + '.css';
|
2019-12-26 14:57:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void themeSwitchMouse(MouseEvent event) {
|
|
|
|
bool isDark = setTheme(!isThemeDark());
|
|
|
|
themeSwitch(isDark);
|
|
|
|
}
|