计算单词的时间
Get the count of words in tinymce
我在tinymce外有一个单词计数div,它显示单词计数,但不使用wordCount插件,而是使用regex来计数单词。
但是当我在已经键入的文本中添加项目符号或应用粗体时,这个计数没有显示正确的值[它显示计数为3,而我在使用项目符号时只输入了一个单词,并在突出显示已经键入的文本时增加计数2]
有没有人可以建议在正则表达式中做些什么来获得正确的计数,当使用粗体或,斜体,下划线或子弹或使用wordCount插件使用它的输出在统计栏外[在这种情况下,在我的单词计数div]
代码如下:
tinymceConfig = {
mode:"exact",
elements:"essay",
menubar: false,
statusbar: false,
plugins: "autoresize",
content_css : '../../theme/css/Language/editor.css',
toolbar : "bold italic underline bullist",
resize:"height",
autoresize_max_height: 325,
setup : function(editor) {
if ($('#essay').prop('readonly')) {
editor.settings.readonly = true;
}
editor.on('keydown', function (evt) {
var wordCount = 0;
var valid_keys = [8, 46];
text = editor.getContent().replace(/(< ([^>]+)<)/g, '').replace(/'s+/g, ' ');
text = text.replace(/^'s's*/, '').replace(/'s's*$/, '');
wordCount = text.split(' ').length-1;
if(wordCount >= Helpers.constants.MAX_WORDS && valid_keys.indexOf(evt.keyCode) == -1)
{
evt.preventDefault();
Helpers.prompt('You have reached the maximum word limit.');
//evt.stopPropagation();
return false;
}
});
editor.on('keyup', function (evt) {
var text = '';
clearTimeout(saveEssayIntervalId);
saveEssayIntervalId = setTimeout(function() {
saveEssay('silent');
}, 3000);
text = editor.getContent().replace(/(< ([^>]+)<)/g, '').replace(/'s+/g, ' ');
text = text.replace(/^'s's*/, '').replace(/'s's*$/, '');
var wordCount = text.split(' ').length;
$("#essayContainer .textAreaAfter").html("[ Words entered: "+wordCount+" ]");
});
} };
tinyMCE.init(tinymceConfig);
你可以从TinyMCE的WordCount插件中获得当前的单词计数-你不需要自己计算这个。
theEditor = tinymce.activeEditor;
wordCount = theEditor.plugins.wordcount.getCount();
如果您有一个旧的tinyMCE版本,您可能没有getCount()
函数,在这种情况下,您可以为活动编辑器编写(否则传递编辑器的对象):
var editor = tinyMCE.activeEditor,
words = editor.plugins.wordcount._getCount(editor);
相关文章:
- Java脚本时间添加
- 当鼠标悬停在文本中的单词上时显示警报
- Json数据包含日期和时间格式
- 如何根据时间运行不同的脚本
- 匹配一个单词,其中候选人可以跨越顺序组(跨度)
- 用每小时的差值填充数组/列表-从下拉列表中给定两个时间值
- 如何使用jquery强制一个单词更改大小写等以保留品牌
- 拆分单词jquery
- 在wordpress一定时间后更改自定义字段
- 如何让程序检查所选单词中是否有按键
- 更改angularjs中的日期-时间格式
- 将当前时间添加到我的页面上的特定部分
- 门户网站:当地时间有多有用
- 显示时间的脚本
- 如何在窗体打开时从javascript倒计时计时器值中节省时间
- 淡入段落的每个单词在不同的随机时间效果中
- 正在分析字符串以获取与单词相关联的时间戳数组
- 每个单词时间戳语音Api
- 计算单词的时间
- Javascript时间函数按字母拼写单词