diff options
author | Aleksander Machniak <alec@alec.pl> | 2012-05-08 11:38:39 +0200 |
---|---|---|
committer | Aleksander Machniak <alec@alec.pl> | 2012-05-08 11:38:39 +0200 |
commit | e6e0d410ac92818679c03fc9bf5359562df81921 (patch) | |
tree | fff5c213ce3e88b448ca1365b375137a52f6fa4c /program/js/tiny_mce/plugins/wordcount/editor_plugin_src.js | |
parent | 5b0b034387715a18910a7e574b71afcfae293ecf (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.js | 20 |
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 == ’
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);
},
|