aircox-radiocampus/radiocampus/static/radiocampus/backgroundLoad.js

49 lines
1.2 KiB
JavaScript

// Enable styling body background while using vue hotreload
// Tags with side effect (<script> and <style>) are ignored in client component templates.
class BackgroundLoad {
// change background style on load
// and also on vuejs pageLoaded event
constructor () {
let url = new URL(document.location);
this.path = url.pathname;
this.update();
document.addEventListener("pageLoaded", this.handlePageLoad.bind(this), false);
}
handlePageLoad (e) {
this.path = e.detail;
this.update();
}
update () {
let theme = this.get_theme_name();
document.body.className = theme;
// home page uses different theme
if (this.path == "/") {
document.body.classList.add('home');
}
}
get_theme_name () {
var currentTime = new Date().getHours();
if (document.body) {
if (3 <= currentTime && currentTime <15) {
return "yellow";
}
else {
return "blue";
}
}
}
}
window.onload = function() {
let backgroundLoad = new BackgroundLoad();
}