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