Search code examples
javascriptnicedit

nicEdit : Add key(press|up|down) events to editor


I'm using nicEdit to have a RTF textarea and I need to add a onkeypress, onkeyup or onkeydown event.

I create my instance like this:

var emailRtf = new nicEditor({  iconsPath : 'nicEdit/nicEditorIcons.gif', 
    buttonList : ['bold','italic','underline','fontSize','forecolor','ol','ul','link','unlink','removeformat'],
    maxHeight: 600}).panelInstance('REPLY_MESSAGE');

I tried the following (with keypress, keydown and keyup):

emailRtf.addEvent("keypress", function() { alert('test') }); // Not working
emailRtf.addEvent("keypress", function(evt) { alert('test') }); // Not working

However, the following works:

emailRtf.addEvent("blur", function() { alert('test') }); // Alert shows when I leave focus on the textArea

How can I add key(press|up|down) to a nicEdit editor?

NOTE: I have multiple instance of RTF textarea in my page and I need to add the key(press|down|up) event to only one. I found this question, which add the event on all instances. Also, I would like to leave nicEdit.js intact.


Solution

  • Take a look here Limit the number of characters in a WYSIWYG Editor (NicEdit)

    it should work without changes in nicedit.js

    $("div.nicEdit-main").keyup(function () { });
    

    Look at jsfiddle http://jsfiddle.net/jGLRn/15/