From 8eefbb2158c43b51a8c33e6c480cbe61539b9535 Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Mon, 27 Aug 2012 04:16:04 -0400
Subject: [PATCH] Add option to enable HTML editor on forwarding (#1488517)

---
 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 e94743b..34b2655 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));
+			}
 
-				if (13 == e.keyCode || 8 == last || 46 == last)
+			function checkDelOrBksp(key) {
+				return key === VK.DELETE || key === VK.BACKSPACE;
+			}
+
+			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);
 		},

--
Gitblit v1.9.1