mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-29 07:09:48 +03:00
983110d931
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
32 lines
755 B
JavaScript
32 lines
755 B
JavaScript
import {helper} from '@ember/component/helper';
|
|
import {htmlSafe} from '@ember/string';
|
|
|
|
export function countCharacters(params) {
|
|
if (!params || !params.length) {
|
|
return;
|
|
}
|
|
|
|
let el = document.createElement('span');
|
|
let content = params[0] || '';
|
|
|
|
// 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 > 180) {
|
|
el.style.color = '#f05230';
|
|
} else {
|
|
el.style.color = '#738a94';
|
|
}
|
|
|
|
el.innerHTML = 200 - length;
|
|
|
|
return htmlSafe(el.outerHTML);
|
|
}
|
|
|
|
export default helper(function (params) {
|
|
return countCharacters(params);
|
|
});
|