REFACTOR: add-archetype-class mixin (#16546)

This commit is contained in:
Joffrey JAFFEUX 2022-04-25 13:16:43 +02:00 committed by GitHub
parent ab1fe24241
commit 7f55c9c502
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5,24 +5,26 @@ import { observes, on } from "discourse-common/utils/decorators";
// This is used for keeping the `body` style in sync for the background image.
export default {
_cleanUp() {
$("body").removeClass((_, css) =>
(css.match(/\barchetype-\S+/g) || []).join(" ")
);
document.body.classList.forEach((name) => {
if (/\barchetype-\S+/g.test(name)) {
document.body.classList.remove(name);
}
});
},
@observes("archetype")
@on("init")
_archetypeChanged() {
const archetype = this.archetype;
this._cleanUp();
if (archetype) {
$("body").addClass("archetype-" + archetype);
if (this.archetype) {
document.body.classList.add(`archetype-${this.archetype}`);
}
},
willDestroyElement() {
this._super(...arguments);
this._cleanUp();
},
};