diff --git a/plugins/counter/plugin.js b/plugins/counter/plugin.js index 28ce728..2c66e28 100644 --- a/plugins/counter/plugin.js +++ b/plugins/counter/plugin.js @@ -3,6 +3,7 @@ */ ( function(){ var emptyHtml = ' '; + var countTimeout = ''; CKEDITOR.plugins.add( 'counter', { init : function( editor ) @@ -52,11 +53,29 @@ editor.on( 'dataReady', count ); editor.on( 'blur', count ); - editor.on( 'focus', count ); + editor.on ( 'focus', count ); // Almost useless //editor.on( 'saveSnapshot', count ); // Requires too much resources //editor.on( 'key', count ); + editor.on('key', function(e) { + switch (e.data.keyCode) { + case 32: + if (countTimeout) { + clearTimeout(countTimeout); + } + count(e); + break; + default: + if (countTimeout) { + clearTimeout(countTimeout); + } + countTimeout = setTimeout(function(){ + count(e); + }, 2000); + break; + } + }); } }); })();