discourse/app/assets/javascripts/discourse/widgets/toggle-topic-summary.js.es6

41 lines
1.2 KiB
Plaintext
Raw Normal View History

2018-06-15 23:03:24 +08:00
import RawHtml from "discourse/widgets/raw-html";
import { createWidget } from "discourse/widgets/widget";
2018-06-15 23:03:24 +08:00
createWidget("toggle-summary-description", {
description(attrs) {
if (attrs.topicSummaryEnabled) {
2018-06-15 23:03:24 +08:00
return I18n.t("summary.enabled_description");
}
if (attrs.topicWordCount) {
2018-06-15 23:03:24 +08:00
const readingTime = Math.floor(
attrs.topicWordCount / this.siteSettings.read_time_word_count
);
return I18n.t("summary.description_time", {
replyCount: attrs.topicReplyCount,
readingTime
});
}
2018-06-15 23:03:24 +08:00
return I18n.t("summary.description", { replyCount: attrs.topicReplyCount });
},
html(attrs) {
// vdom makes putting html in the i18n difficult
return new RawHtml({ html: `<p>${this.description(attrs)}</p>` });
}
});
2018-06-15 23:03:24 +08:00
export default createWidget("toggle-topic-summary", {
tagName: "section.information.toggle-summary",
html(attrs) {
2018-06-15 23:03:24 +08:00
return [
this.attach("toggle-summary-description", attrs),
this.attach("button", {
className: "btn btn-primary",
label: attrs.topicSummaryEnabled ? "summary.disable" : "summary.enable",
action: "toggleSummary"
})
];
}
});