This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/app/components/add-topic-status-classes.js
Vinoth Kannan 167bbb259f
UX: add CSS classes on body tag based on topic statuses. (#12729)
This commit will add CSS classes like `unlisted`, `pinned`, and `unpinned` on the body tag.

* DEV: we no longer using the `categoryClass` & `tagClasses` methods.
* Update app/assets/javascripts/discourse/app/components/add-topic-status-classes.js

Co-authored-by: Joffrey JAFFEUX <j.jaffeux@gmail.com>
2021-05-04 11:07:54 +05:30

51 lines
1.1 KiB
JavaScript

import Component from "@ember/component";
import { scheduleOnce } from "@ember/runloop";
export default Component.extend({
tagName: "",
didInsertElement() {
this._super(...arguments);
this.refreshClass();
},
_updateClass() {
if (this.isDestroying || this.isDestroyed) {
return;
}
const body = document.getElementsByTagName("body")[0];
this._removeClass();
if (this.topic.invisible) {
body.classList.add("topic-status-unlisted");
}
if (this.topic.pinned) {
body.classList.add("topic-status-pinned");
}
if (this.topic.unpinned) {
body.classList.add("topic-status-unpinned");
}
},
didReceiveAttrs() {
this._super(...arguments);
this.refreshClass();
},
refreshClass() {
scheduleOnce("afterRender", this, this._updateClass);
},
_removeClass() {
const regx = new RegExp(/\btopic-status-\S+/, "g");
const body = document.getElementsByTagName("body")[0];
body.className = body.className.replace(regx, "");
},
willDestroyElement() {
this._super(...arguments);
this._removeClass();
},
});