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