mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
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>
This commit is contained in:
parent
14ed6e1657
commit
167bbb259f
@ -0,0 +1,50 @@
|
|||||||
|
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();
|
||||||
|
},
|
||||||
|
});
|
@ -23,8 +23,6 @@ export default Component.extend(
|
|||||||
"topic.is_warning",
|
"topic.is_warning",
|
||||||
"topic.category.read_restricted:read_restricted",
|
"topic.category.read_restricted:read_restricted",
|
||||||
"topic.deleted:deleted-topic",
|
"topic.deleted:deleted-topic",
|
||||||
"topic.categoryClass",
|
|
||||||
"topic.tagClasses",
|
|
||||||
],
|
],
|
||||||
menuVisible: true,
|
menuVisible: true,
|
||||||
SHORT_POST: 1200,
|
SHORT_POST: 1200,
|
||||||
|
@ -218,13 +218,6 @@ const Topic = RestModel.extend({
|
|||||||
return Category.findById(categoryId);
|
return Category.findById(categoryId);
|
||||||
},
|
},
|
||||||
|
|
||||||
categoryClass: fmt("category.fullSlug", "category-%@"),
|
|
||||||
|
|
||||||
@discourseComputed("tags")
|
|
||||||
tagClasses(tags) {
|
|
||||||
return tags && tags.map((t) => `tag-${t}`).join(" ");
|
|
||||||
},
|
|
||||||
|
|
||||||
@discourseComputed("url")
|
@discourseComputed("url")
|
||||||
shareUrl(url) {
|
shareUrl(url) {
|
||||||
const user = User.current();
|
const user = User.current();
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
{{#discourse-topic multiSelect=multiSelect enteredAt=enteredAt topic=model hasScrolled=hasScrolled}}
|
{{#discourse-topic multiSelect=multiSelect enteredAt=enteredAt topic=model hasScrolled=hasScrolled}}
|
||||||
{{#if model}}
|
{{#if model}}
|
||||||
{{add-category-tag-classes category=model.category tags=model.tags}}
|
{{add-category-tag-classes category=model.category tags=model.tags}}
|
||||||
|
{{add-topic-status-classes topic=model}}
|
||||||
<div class="container">
|
<div class="container">
|
||||||
{{discourse-banner user=currentUser banner=site.banner overlay=hasScrolled hide=model.errorLoading}}
|
{{discourse-banner user=currentUser banner=site.banner overlay=hasScrolled hide=model.errorLoading}}
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user