Files
profile/assets/js/admin/tinymce.plugin.charcount.js
Andrey Kuvshinov 8fc8cbae32 add files
2025-07-09 21:21:17 +03:00

49 lines
1.9 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

tinymce.PluginManager.add('charactercount', function (editor) {
var _self = this;
function update() {
editor.theme.panel.find('#charactercount').text('Количество символов: '+ _self.getCount() + '(с пробелами) | ' + _self.getCountWithoutSpaces() + '(без пробелов)' );
}
editor.on('init', function () {
var statusbar = editor.theme.panel && editor.theme.panel.find('#statusbar')[0];
if (statusbar) {
window.setTimeout(function () {
statusbar.insert({
type: 'label',
name: 'charactercount',
text: 'Количество символов: '+ _self.getCount() + '(с пробелами) | ' + _self.getCountWithoutSpaces() + '(без пробелов)',
classes: 'charactercount',
disabled: editor.settings.readonly
}, 0);
editor.on('setcontent beforeaddundo keyup', update);
}, 0);
}
});
_self.getCount = function () {
var tx = editor.getContent({ format: 'raw' });
var decoded = decodeHtml(tx);
var decodedStripped = decoded.replace(/(<([^>]+)>)/ig, '');
var tc = decodedStripped.length;
return tc;
};
_self.getCountWithoutSpaces = function () {
var tx = editor.getContent({ format: 'raw' });
var decoded = decodeHtml(tx);
var decodedStripped = decoded.replace(/(<([^>]+)>)/ig, '');
var tc = decodedStripped.replace(/(?:\r\n|\r|\n)/g, '').replace('/ /g', '').split(' ').join('').replace(/\s\s+/g, '');
console.log(tc);
return tc.length;
};
function decodeHtml(html) {
var txt = document.createElement('textarea');
txt.innerHTML = html;
return txt.value;
}
});