CKEditor – Detect when typing stopped
I was trying to figure out a way to detect when the user typing in the editor has paused / stopped. The documentation of CKEditor and Stackoverflow do not have my answer, fortunately I was able to come up with a simple solution!
I first started with the basics – I played with a simple <textarea /> without CKEditor and the code bellow worked for me:
Type in the text box. it will time out and run the function when you stop for the time alotted. <textarea id="editor"></textarea>
var timer = null; $('#editor').keydown(function(){ clearTimeout(timer); timer = setTimeout(doStuff, 1000) }); function doStuff() { alert('do stuff'); }
And next – I applied the code above to a CKEditor instance.
CKEditor doesn’t have keyup or keydown events, but what they have is key
So I did the following using closures and it worked for me!
var timer = null; CKEDITOR.instances['#editor'].on('key', function(){ clearTimeout(timer); timer = setTimeout(doStuff.bind(textarea, $('#editor')), 1000) }); function doStuff(textarea) { alert(textarea.val()); }
Do you need help with a project? or have a new project in mind that you need help with?
Contact Me