I really need to be able to handle the 'keyup' event. I'm trying to create 'maxchar' functionality and get a char count. I currently have it working on 'blur', but it would be better to have it work on 'keyup' (or even handle ctrl-v), that way I could add more functionality to it. I could then block alphanumeric and enter, but allow for backspace, delete, etc. Maybe even open the events up to jQuery (it would make the events easier to handle for us jQuery users).
This is the handler code I would like to see working:
I took a look at the code for CKEditor, but it looks as though it's been obfuscated; which makes it difficult to follow or enhance.
This is the handler code I would like to see working:
CKEDITOR.instances["sampleInstance"].on('keyup', function() { $('#lengthText').val(CKEDITOR.instances.sampleInstance.getData().replace(/<[^>]*>|\s/g, '').length); if (parseInt($('#lengthText').val()) > 2000) { $('#lengthText').addClass('error'); } else { $('#lengthText').removeClass('error'); } });
I took a look at the code for CKEditor, but it looks as though it's been obfuscated; which makes it difficult to follow or enhance.
Re: handling the 'keyup' event
Hi, I guess you would check this out:
viewtopic.php?f=11&t=15716&p=39992&hilit=character+count#p39992
Re: handling the 'keyup' event
var addToKey = this;
oEditor.on( 'instanceReady', function(e)
{
this.document.on("keyup", function() {
addToKey._updateValue();
});
});
But as soon as I switch modes, the keyup event won't fire. Any suggestions? Thanks in advance.
Re: handling the 'keyup' event
CKEDITOR.instances["sampleInstance"].on('keyup', function() {
setTimeout('delayHook();',1000);
}
function delayHook () {
$('#lengthText').val(CKEDITOR.instances.sampleInstance.getData().replace(/<[^>]*>|\s/g, '').length);
if (parseInt($('#lengthText').val()) > 2000) {
$('#lengthText').addClass('error');
}
else {
$('#lengthText').removeClass('error');
}
});