2020-08-28 20:23:35 +00:00
|
|
|
import 'dart:html'
|
|
|
|
show DivElement, Element, querySelector, querySelectorAll, window;
|
2020-05-05 12:49:26 +00:00
|
|
|
|
|
|
|
import './navbar.dart' show makeNavbar;
|
|
|
|
|
2020-12-21 19:29:25 +00:00
|
|
|
const image_header = '/img/icon.webp';
|
2020-05-05 17:20:28 +00:00
|
|
|
|
2020-05-05 12:49:26 +00:00
|
|
|
Future<Element> makeHeader() async {
|
|
|
|
var header = Element.tag('header');
|
|
|
|
header
|
|
|
|
..append(Element.img()
|
2020-05-05 17:20:28 +00:00
|
|
|
..attributes['src'] = image_header
|
2020-12-21 19:38:24 +00:00
|
|
|
..attributes['alt'] = 'Logo'
|
|
|
|
..attributes['height'] = '150px'
|
|
|
|
..attributes['width'] = '150px')
|
2020-05-05 12:49:26 +00:00
|
|
|
..append(querySelector('h1'));
|
2020-05-26 00:14:13 +00:00
|
|
|
final subt = header.querySelector('.subtitle');
|
2020-05-05 12:49:26 +00:00
|
|
|
if (subt != null) {
|
|
|
|
header.append(subt);
|
|
|
|
}
|
|
|
|
return header;
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> wrapTables() async {
|
|
|
|
for (var table in querySelectorAll('table')) {
|
|
|
|
var largetable = DivElement()..className = 'largetable';
|
|
|
|
table.before(largetable);
|
|
|
|
largetable.children.add(table);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// All images that are not nested inside a link will be linkified to themselves.
|
2020-05-10 10:37:22 +00:00
|
|
|
Future<void> linkifyImg() async {
|
2020-05-05 12:49:26 +00:00
|
|
|
querySelectorAll('img').forEach((img) {
|
|
|
|
if (img.parent.tagName == 'P') {
|
|
|
|
final link = Element.a()..attributes['href'] = img.attributes['src'];
|
|
|
|
img.insertAdjacentElement('beforeBegin', link);
|
|
|
|
link.append(img);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> reorganizeHtml() async {
|
2020-08-28 20:23:35 +00:00
|
|
|
final ls = window.localStorage;
|
2020-12-21 19:38:24 +00:00
|
|
|
final lastUpdate = '20201221';
|
2020-08-28 20:23:35 +00:00
|
|
|
if (ls['last-update'] != lastUpdate) {
|
|
|
|
ls['last-update'] = lastUpdate;
|
|
|
|
window.location.reload();
|
|
|
|
}
|
|
|
|
|
2020-05-05 12:49:26 +00:00
|
|
|
// Make navbar
|
2020-05-10 10:37:22 +00:00
|
|
|
final navbar = await makeNavbar();
|
2020-05-05 12:49:26 +00:00
|
|
|
|
|
|
|
// Make header
|
2020-05-10 10:37:22 +00:00
|
|
|
final header = await makeHeader();
|
2020-05-05 12:49:26 +00:00
|
|
|
|
|
|
|
// wrap tables in container for better SCSS display
|
|
|
|
await wrapTables();
|
|
|
|
|
2020-05-10 10:37:22 +00:00
|
|
|
// Make images not linking somewhere link to themselves
|
|
|
|
await linkifyImg();
|
|
|
|
|
|
|
|
// Add navbar to page
|
|
|
|
querySelector('body').insertAdjacentElement('afterBegin', navbar);
|
|
|
|
|
|
|
|
// Add headet to page
|
|
|
|
querySelector('#content').insertAdjacentElement('beforeBegin', header);
|
2020-05-05 12:49:26 +00:00
|
|
|
|
|
|
|
// Add correct class to TOC
|
2020-05-09 12:45:26 +00:00
|
|
|
final toc = (querySelector('#table-of-contents') ??
|
|
|
|
(Element.div()
|
|
|
|
..attributes['id'] = 'table-of-contents'
|
2020-05-10 10:37:22 +00:00
|
|
|
..innerText = 'Table of Contents Unavailable'))
|
2020-05-09 12:45:26 +00:00
|
|
|
..classes.add('dropdown');
|
2020-05-10 10:37:22 +00:00
|
|
|
navbar.querySelector('#toc-drop').append(toc);
|
2020-05-05 12:49:26 +00:00
|
|
|
|
|
|
|
// Remove all <br> tags from HTML
|
|
|
|
querySelectorAll('br').forEach((br) => br.remove());
|
|
|
|
}
|