2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-09-10 21:01:33 +08:00
discourse/app/assets/javascripts/discourse/components/topic-status.js.es6
Penar Musaraj 005e1ecb9b
FEATURE: Update Font Awesome to v5.4.1 and SVGs (#6557)
* First take on subsetting svg icons

* FontAwesome 5 svg subset WIP

* Include icons from plugins/badges into svg sprite subset

* add svg icon support to themes

* Add spec for SvgSprite

* Misc. SVG icon fixes

* Use FA5 svgs in local-dates plugin

* CSS adjustments, fix SVG icons in group flair

* Use SVG icons in poll plugin

* Add SVG icons to /wizard
2018-11-07 13:05:43 -05:00

71 lines
2.1 KiB
JavaScript

import { iconHTML } from "discourse-common/lib/icon-library";
import { bufferedRender } from "discourse-common/lib/buffered-render";
import { escapeExpression } from "discourse/lib/utilities";
export default Ember.Component.extend(
bufferedRender({
classNames: ["topic-statuses"],
rerenderTriggers: [
"topic.archived",
"topic.closed",
"topic.pinned",
"topic.visible",
"topic.unpinned",
"topic.is_warning"
],
click(e) {
// only pin unpin for now
if (this.get("canAct") && $(e.target).hasClass("d-icon-thumbtack")) {
const topic = this.get("topic");
topic.get("pinned") ? topic.clearPin() : topic.rePin();
}
return false;
},
canAct: function() {
return Discourse.User.current() && !this.get("disableActions");
}.property("disableActions"),
buildBuffer(buffer) {
const renderIcon = function(name, key, actionable) {
const title = escapeExpression(I18n.t(`topic_statuses.${key}.help`)),
startTag = actionable ? "a href" : "span",
endTag = actionable ? "a" : "span",
iconArgs = key === "unpinned" ? { class: "unpinned" } : null,
icon = iconHTML(name, iconArgs);
buffer.push(
`<${startTag} title='${title}' class='topic-status'>${icon}</${endTag}>`
);
};
const renderIconIf = (conditionProp, name, key, actionable) => {
if (!this.get(conditionProp)) {
return;
}
renderIcon(name, key, actionable);
};
renderIconIf("topic.is_warning", "envelope", "warning");
if (this.get("topic.closed") && this.get("topic.archived")) {
renderIcon("lock", "locked_and_archived");
} else {
renderIconIf("topic.closed", "lock", "locked");
renderIconIf("topic.archived", "lock", "archived");
}
renderIconIf("topic.pinned", "thumbtack", "pinned", this.get("canAct"));
renderIconIf(
"topic.unpinned",
"thumbtack",
"unpinned",
this.get("canAct")
);
renderIconIf("topic.invisible", "eye-slash", "invisible");
}
})
);