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

68 lines
3.9 KiB
JavaScript

// Enable styling body background while using vue hotreload
// Tags with side effect (<script> and <style>) are ignored in client component templates.
const backgrounds = new Map();
backgrounds.set('default', "url(/static/radiocampus/backgrounds/campus-degrade.png) repeat-x center top scroll");
backgrounds.set('/', "url(/static/radiocampus/backgrounds/home.jpg) no-repeat center center fixed");
//backgrounds.set('default', "linear-gradient(rgba(115, 142, 242, 0.9), white)");
//backgrounds.set('default', "white");
/*
backgrounds.set('default', "linear-gradient(#738ef2, white)");
backgrounds.set('/', "url(/static/radiocampus/backgrounds/photo-04-20.jpg) no-repeat center center fixed");
backgrounds.set('/publications/', "url(/static/radiocampus/backgrounds/photo-04-20.jpg) no-repeat center center fixed");
backgrounds.set('/pages/a-propos/', "white");
backgrounds.set('/emissions/', "url(/static/radiocampus/backgrounds/08.jpeg) no-repeat center center fixed");
backgrounds.set('/emissions/c/musicale/', "url(/static/radiocampus/backgrounds/08.jpeg) no-repeat center center fixed");
backgrounds.set('/emissions/c/communautaire/', "url(/static/radiocampus/backgrounds/08.jpeg) no-repeat center center fixed");
backgrounds.set('/emissions/c/magazine/', "url(/static/radiocampus/backgrounds/08.jpeg) no-repeat center center fixed");
backgrounds.set('/emissions/c/creation/', "url(/static/radiocampus/backgrounds/08.jpeg) no-repeat center center fixed");
backgrounds.set('/emissions/c/agenda-culturel/', "url(/static/radiocampus/backgrounds/08.jpeg) no-repeat center center fixed");
backgrounds.set('/grille/', "url(/static/radiocampus/backgrounds/photo-04-19.jpg) no-repeat center center fixed");
backgrounds.set('/podcasts/', "url(/static/radiocampus/backgrounds/09.jpeg) no-repeat center center fixed");
backgrounds.set('/podcasts/c/musicale/', "url(/static/radiocampus/backgrounds/09.jpeg) no-repeat center center fixed");
backgrounds.set('/podcasts/c/communautaire/', "url(/static/radiocampus/backgrounds/09.jpeg) no-repeat center center fixed");
backgrounds.set('/podcasts/c/magazine/', "url(/static/radiocampus/backgrounds/09.jpeg) no-repeat center center fixed");
backgrounds.set('/podcasts/c/creation/', "url(/static/radiocampus/backgrounds/09.jpeg) no-repeat center center fixed");
backgrounds.set('/podcasts/c/agenda-culturel/', "url(/static/radiocampus/backgrounds/09.jpeg) no-repeat center center fixed");
*/
class BackgroundLoad {
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 background = backgrounds.get(this.path) || backgrounds.get("default");
let target = document.body;
// let target = document.getElementsByClassName("page")[0];
//let target = document.getElementById("background");
target.style.background = background;
if (this.path == '/') {
target.style.backgroundSize = "cover";
const styleEl = document.createElement("style");
document.head.appendChild(styleEl);
const styleSheet = styleEl.sheet;
styleSheet.insertRule('.preview .headings a { color: white; }', styleSheet.cssRules.length);
styleSheet.insertRule('.preview .headings a:hover { color: #ffcdee !important; }', styleSheet.cssRules.length);
} else {
const styleEl = document.createElement("style");
document.head.appendChild(styleEl);
const styleSheet = styleEl.sheet;
styleSheet.insertRule('.preview .headings a { color: #75124e; }', styleSheet.cssRules.length);
styleSheet.insertRule('.preview .headings a:hover { color: #75124e !important; }', styleSheet.cssRules.length);
}
}
}
window.onload = function() {
let backgroundLoad = new BackgroundLoad();
}