0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-15 06:12:54 +01:00
discourse-custom-wizard/assets/javascripts/discourse/helpers/wizard-char-counter.js.es6

26 Zeilen
801 B
Text

import { registerUnbound } from "discourse-common/lib/helpers";
import I18n from "I18n";
import Handlebars from "handlebars";
2023-03-30 06:09:00 +02:00
export default registerUnbound(
"wizard-char-counter",
function (body, maxLength) {
let bodyLength = body ? body.length : 0;
let finalString;
2021-01-19 07:47:07 +01:00
2023-03-30 06:09:00 +02: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, 10) }
)}</div>`;
} else {
finalString = `<div class="body-length">${I18n.t("wizard.x_characters", {
count: parseInt(bodyLength, 10),
})}</div>`;
}
2021-01-20 09:52:52 +01:00
2023-03-30 06:09:00 +02:00
return new Handlebars.SafeString(finalString);
}
);