1
0
Fork 0
mirror of https://github.com/TryGhost/Ghost-Admin.git synced 2023-12-14 02:33:04 +01:00
Ghost-Admin/app/helpers/gh-count-down-characters.js
Kevin Ansfield 88449ed639 Switched from ember-cli-shims to new module imports (#779)
no issue

- add eslint-plugin-ember, configure no-old-shims rule
- run `eslint --fix` on `app`, `lib`, `mirage`, and `tests` to move imports to the new module imports
- further cleanup of Ember globals usage
- remove event-dispatcher initializer now that `canDispatchToEventManager` is deprecated
2017-08-22 14:53:26 +07:00

32 lines
784 B
JavaScript

import {helper} from '@ember/component/helper';
import {htmlSafe} from '@ember/string';
export function countDownCharacters(params) {
if (!params || params.length < 2) {
return;
}
let el = document.createElement('span');
let [content, maxCharacters] = params;
// convert to array so that we get accurate symbol counts for multibyte chars
// this will still count emoji+modifer as two chars
let {length} = Array.from(content || '');
el.className = 'word-count';
if (length > maxCharacters) {
el.style.color = '#E25440';
} else {
el.style.color = '#9FBB58';
}
el.innerHTML = length;
return htmlSafe(el.outerHTML);
}
export default helper(function (params) {
return countDownCharacters(params);
});