2017-08-22 10:53:26 +03:00
|
|
|
import {helper} from '@ember/component/helper';
|
|
|
|
import {htmlSafe} from '@ember/string';
|
2015-08-19 14:55:40 +03:00
|
|
|
|
2017-01-11 16:45:22 +03:00
|
|
|
export function countCharacters(params) {
|
2015-09-03 14:06:50 +03:00
|
|
|
if (!params || !params.length) {
|
2015-02-09 18:57:50 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
let el = document.createElement('span');
|
|
|
|
let content = params[0] || '';
|
2017-01-11 16:45:22 +03:00
|
|
|
|
|
|
|
// 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);
|
2014-06-24 00:02:09 +04:00
|
|
|
|
|
|
|
el.className = 'word-count';
|
2014-10-25 01:09:50 +04:00
|
|
|
|
2014-06-24 00:02:09 +04:00
|
|
|
if (length > 180) {
|
2017-05-17 15:24:31 +03:00
|
|
|
el.style.color = '#f05230';
|
2014-06-24 00:02:09 +04:00
|
|
|
} else {
|
2017-05-17 15:24:31 +03:00
|
|
|
el.style.color = '#738a94';
|
2014-06-24 00:02:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
el.innerHTML = 200 - length;
|
|
|
|
|
2016-06-11 19:52:36 +03:00
|
|
|
return htmlSafe(el.outerHTML);
|
2017-01-11 16:45:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
export default helper(function (params) {
|
|
|
|
return countCharacters(params);
|
2014-06-24 00:02:09 +04:00
|
|
|
});
|