mirror of
https://github.com/vichan-devel/vichan.git
synced 2025-01-31 12:23:48 +01:00
main.js: load styles with dyanamically provided resource version.
This is done because: - If the version is updated before the rebuild, someone might cache the old version in the meanwhile. - One could not rebuild javascript before updating the version. Now it's possible.
This commit is contained in:
parent
fcf5c3d73a
commit
3c5484a7c2
@ -141,7 +141,33 @@ function changeStyle(styleName, link) {
|
|||||||
x.appendChild(s);
|
x.appendChild(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
document.getElementById('stylesheet').href = styles[styleName];
|
let mainStylesheetElement = document.getElementById('stylesheet');
|
||||||
|
let userStylesheetElement = document.getElementById('stylesheet-user');
|
||||||
|
|
||||||
|
// Override main stylesheet with the user selected one.
|
||||||
|
if (!userStylesheetElement) {
|
||||||
|
userStylesheetElement = document.createElement('link');
|
||||||
|
userStylesheetElement.rel = 'stylesheet';
|
||||||
|
userStylesheetElement.media = 'none';
|
||||||
|
userStylesheetElement.type = 'text/css';
|
||||||
|
userStylesheetElement.id = 'stylesheet';
|
||||||
|
let x = document.getElementsByTagName('head')[0];
|
||||||
|
x.appendChild(userStylesheetElement);
|
||||||
|
}
|
||||||
|
|
||||||
|
// When the new one is loaded, disable the old one
|
||||||
|
userStylesheetElement.onload = function() {
|
||||||
|
this.media = 'all';
|
||||||
|
mainStylesheetElement.media = 'none';
|
||||||
|
}
|
||||||
|
|
||||||
|
let style = styles[styleName];
|
||||||
|
if (style !== '') {
|
||||||
|
// Add the version of the resource if the style is not the embedded one.
|
||||||
|
style += `?v=${resourceVersion}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
document.getElementById('stylesheet').href = style;
|
||||||
selectedstyle = styleName;
|
selectedstyle = styleName;
|
||||||
|
|
||||||
if (document.getElementsByClassName('styles').length != 0) {
|
if (document.getElementsByClassName('styles').length != 0) {
|
||||||
@ -162,6 +188,7 @@ function changeStyle(styleName, link) {
|
|||||||
|
|
||||||
|
|
||||||
{% endverbatim %}
|
{% endverbatim %}
|
||||||
|
var resourceVersion = document.currentScript.getAttribute('data-resource-version');
|
||||||
{% if config.stylesheets_board %}
|
{% if config.stylesheets_board %}
|
||||||
{% verbatim %}
|
{% verbatim %}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user