[Dart] Cleaner code, force the web page to reload on modifier code
The code in `navbar.dart' is now more declarative and cleaner. If the `lastUpdate' variable’s content change, then it will force the user to reload the page, bypassing their cache. This can be useful in case of an update with which the cache could break the website.
This commit is contained in:
parent
e710c594f1
commit
16f23c08c6
@ -51,15 +51,11 @@ Future<Element> makeHome() async {
|
|||||||
// Create a clickable icon
|
// Create a clickable icon
|
||||||
// `t_elem` must be an SVG declared in the above `icons` variable.
|
// `t_elem` must be an SVG declared in the above `icons` variable.
|
||||||
Element makeIcon(SvgElement t_elem) {
|
Element makeIcon(SvgElement t_elem) {
|
||||||
final icon = t_elem..classes.add('nav-icon');
|
return t_elem..classes.add('nav-icon');
|
||||||
return icon;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the dropdown sitemap
|
// Create the dropdown sitemap
|
||||||
Future<Element> makePages() async {
|
Future<Element> makePages() async {
|
||||||
var pages = Element.ul()
|
|
||||||
..attributes['id'] = 'drop-page'
|
|
||||||
..classes.add('dropdown');
|
|
||||||
return Element.li()
|
return Element.li()
|
||||||
..attributes['tabindex'] = '0'
|
..attributes['tabindex'] = '0'
|
||||||
..append(Element.a()
|
..append(Element.a()
|
||||||
@ -67,7 +63,9 @@ Future<Element> makePages() async {
|
|||||||
..attributes['href'] = 'javascript:void(0)'
|
..attributes['href'] = 'javascript:void(0)'
|
||||||
..append(makeIcon(icons['pages'])))
|
..append(makeIcon(icons['pages'])))
|
||||||
..classes.addAll(['nav-item', 'has-dropdown'])
|
..classes.addAll(['nav-item', 'has-dropdown'])
|
||||||
..append(pages);
|
..append(Element.ul()
|
||||||
|
..attributes['id'] = 'drop-page'
|
||||||
|
..classes.add('dropdown'));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the array of share icons
|
// Create the array of share icons
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import 'dart:html' show DivElement, Element, querySelector, querySelectorAll;
|
import 'dart:html'
|
||||||
|
show DivElement, Element, querySelector, querySelectorAll, window;
|
||||||
|
|
||||||
import './navbar.dart' show makeNavbar;
|
import './navbar.dart' show makeNavbar;
|
||||||
|
|
||||||
@ -40,6 +41,13 @@ Future<void> linkifyImg() async {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> reorganizeHtml() async {
|
Future<void> reorganizeHtml() async {
|
||||||
|
final ls = window.localStorage;
|
||||||
|
final lastUpdate = '20200828';
|
||||||
|
if (ls['last-update'] != lastUpdate) {
|
||||||
|
ls['last-update'] = lastUpdate;
|
||||||
|
window.location.reload();
|
||||||
|
}
|
||||||
|
|
||||||
// Make navbar
|
// Make navbar
|
||||||
final navbar = await makeNavbar();
|
final navbar = await makeNavbar();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user