summaryrefslogtreecommitdiff
path: root/program/js/tiny_mce/plugins/wordcount/editor_plugin_src.js
diff options
context:
space:
mode:
authorAleksander Machniak <alec@alec.pl>2012-05-08 11:38:39 +0200
committerAleksander Machniak <alec@alec.pl>2012-05-08 12:17:09 +0200
commit8a4cc52bd62bdf7b06bf8919f208cdfb035a5816 (patch)
tree4490a9c6cce25d440e0595003735815275889cb4 /program/js/tiny_mce/plugins/wordcount/editor_plugin_src.js
parentec23abec1103a452fa6b4f75077020df0785eef1 (diff)
TinyMCE 3.5
Diffstat (limited to 'program/js/tiny_mce/plugins/wordcount/editor_plugin_src.js')
-rw-r--r--program/js/tiny_mce/plugins/wordcount/editor_plugin_src.js20
1 files changed, 14 insertions, 6 deletions
diff --git a/program/js/tiny_mce/plugins/wordcount/editor_plugin_src.js b/program/js/tiny_mce/plugins/wordcount/editor_plugin_src.js
index e94743bae..34b265553 100644
--- a/program/js/tiny_mce/plugins/wordcount/editor_plugin_src.js
+++ b/program/js/tiny_mce/plugins/wordcount/editor_plugin_src.js
@@ -16,10 +16,12 @@
cleanre : null,
init : function(ed, url) {
- var t = this, last = 0;
+ var t = this, last = 0, VK = tinymce.VK;
t.countre = ed.getParam('wordcount_countregex', /[\w\u2019\'-]+/g); // u2019 == &rsquo;
t.cleanre = ed.getParam('wordcount_cleanregex', /[0-9.(),;:!?%#$?\'\"_+=\\\/-]*/g);
+ t.update_rate = ed.getParam('wordcount_update_rate', 2000);
+ t.update_on_delete = ed.getParam('wordcount_update_on_delete', false);
t.id = ed.id + '-word-count';
ed.onPostRender.add(function(ed, cm) {
@@ -49,12 +51,18 @@
t._count(ed);
});
- ed.onKeyUp.add(function(ed, e) {
- if (e.keyCode == last)
- return;
+ function checkKeys(key) {
+ return key !== last && (key === VK.ENTER || last === VK.SPACEBAR || checkDelOrBksp(last));
+ }
+
+ function checkDelOrBksp(key) {
+ return key === VK.DELETE || key === VK.BACKSPACE;
+ }
- if (13 == e.keyCode || 8 == last || 46 == last)
+ ed.onKeyUp.add(function(ed, e) {
+ if (checkKeys(e.keyCode) || t.update_on_delete && checkDelOrBksp(e.keyCode)) {
t._count(ed);
+ }
last = e.keyCode;
});
@@ -94,7 +102,7 @@
if (!ed.destroyed) {
var tc = t._getCount(ed);
tinymce.DOM.setHTML(t.id, tc.toString());
- setTimeout(function() {t.block = 0;}, 2000);
+ setTimeout(function() {t.block = 0;}, t.update_rate);
}
}, 1);
},