2021-11-01 14:52:29 +01:00
|
|
|
import { autoUpdatingRelativeAge } from "discourse/lib/formatter";
|
|
|
|
import { iconHTML } from "discourse-common/lib/icon-library";
|
|
|
|
import I18n from "I18n";
|
|
|
|
import { registerUnbound } from "discourse-common/lib/helpers";
|
|
|
|
import { htmlSafe } from "@ember/template";
|
|
|
|
|
2021-11-17 13:48:11 +01:00
|
|
|
registerUnbound("notice-badge", function (attrs) {
|
|
|
|
let tag = attrs.url ? "a" : "div";
|
|
|
|
let attrStr = "";
|
2021-11-01 14:52:29 +01:00
|
|
|
if (attrs.title) {
|
|
|
|
attrStr += `title='${I18n.t(attrs.title)}'`;
|
|
|
|
}
|
|
|
|
if (attrs.url) {
|
|
|
|
attrStr += `href='${attrs.url}'`;
|
|
|
|
}
|
2021-11-17 13:48:11 +01:00
|
|
|
let html = `<${tag} class="${
|
|
|
|
attrs.class ? `${attrs.class} ` : ""
|
|
|
|
}notice-badge" ${attrStr}>`;
|
2021-11-01 14:52:29 +01:00
|
|
|
if (attrs.icon) {
|
|
|
|
html += iconHTML(attrs.icon);
|
|
|
|
}
|
|
|
|
if (attrs.label) {
|
|
|
|
if (attrs.icon) {
|
2021-11-17 13:48:11 +01:00
|
|
|
html += " ";
|
2021-11-01 14:52:29 +01:00
|
|
|
}
|
|
|
|
html += `<span>${I18n.t(attrs.label)}</span>`;
|
|
|
|
}
|
|
|
|
if (attrs.date) {
|
|
|
|
if (attrs.icon || attrs.label) {
|
2021-11-17 13:48:11 +01:00
|
|
|
html += " ";
|
2021-11-01 14:52:29 +01:00
|
|
|
}
|
|
|
|
let dateAttrs = {};
|
|
|
|
if (attrs.leaveAgo) {
|
|
|
|
dateAttrs = {
|
|
|
|
format: "medium",
|
2021-11-17 13:48:11 +01:00
|
|
|
leaveAgo: true,
|
2021-11-01 14:52:29 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
html += autoUpdatingRelativeAge(new Date(attrs.date), dateAttrs);
|
|
|
|
}
|
|
|
|
html += `</${tag}>`;
|
|
|
|
return htmlSafe(html);
|
2021-11-17 13:48:11 +01:00
|
|
|
});
|