1
0
Fork 0
discourse-custom-wizard-unl.../assets/javascripts/wizard/helpers/char-counter.js.es6

22 Zeilen
713 B
Text

import { registerUnbound } from "discourse-common/lib/helpers";
import I18n from "I18n";
export default registerUnbound("char-counter", function (body, maxLength) {
let bodyLength = body ? body.length : 0;
let finalString;
2021-01-19 07:47:07 +01:00
if (maxLength) {
let isOverMax = bodyLength > maxLength ? "true" : "false";
finalString = `<div class="body-length" data-length=${bodyLength} data-over-max=${isOverMax}>${bodyLength} / ${I18n.t(
"wizard.x_characters",
{ count: parseInt(maxLength) }
)}</div>`;
} else {
finalString = `<div class="body-length">${I18n.t("wizard.x_characters", {
count: parseInt(bodyLength),
})}</div>`;
}
2021-01-20 09:52:52 +01:00
return new Handlebars.SafeString(finalString);
2021-01-08 07:54:51 +01:00
});