Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

trigger keyup event on a tinymce window

I have a webpage/form with multiple tinymce instances and setup to respond with count of words/characters. everything works fine but could not get the display of word/character count on page load with initial content. here is my setup portion in tinymce setup.

setup: function(ed) {
    var text = ''; 
    var wordcount = false;
    ed.onKeyUp.add(function(ed, e) {
        var contents = new Object();

        for(i=0; i < tinyMCE.editors.length; i++){
           if (tinyMCE.editors[i].getContent())
               contents[i] = tinyMCE.editors[i].getContent();
           text = contents[i].replace(/(<([^>]+)>)/g,'').replace(/\s+/g,' ');
           text = $.trim(text);
           $('#' + tinyMCE.editors[i].id + '_path_row').text(text.split(' ').length + ' words, ' + text.length + ' characters.');
        }
    }
}

Now the part i am struggling is how to trigger key up when the page is displayed with initial content so that it displays word/character count.

I tried $('#' + tinyMCE.editor(0).id + '_ifr').keyup(); and $('#textarea1').keyup(); but no use.

Can some one help me to get it right?

like image 996
Srikanth S Avatar asked May 09 '11 11:05

Srikanth S


People also ask

How do you use Keyup events?

The keyup event occurs when a keyboard key is released. The keyup() method triggers the keyup event, or attaches a function to run when a keyup event occurs. Tip: Use the event. which property to return which key was pressed.

What is Keyup event?

The keyup event is fired when a key is released. The keydown and keyup events provide a code indicating which key is pressed, while keypress indicates which character was entered. For example, a lowercase "a" will be reported as 65 by keydown and keyup , but as 97 by keypress .

How do I reinitialize TinyMCE?

Use tinymce. remove() method to remove TinyMCE editor from the HTML element and again call tinymce. init() on the selector to reinitialize.


2 Answers

Add this to your setup:

ed.onInit.add(function(ed) {ed.onKeyUp.dispatch();});

Doc: http://tinymce.moxiecode.com/wiki.php/API3:class.tinymce.util.Dispatcher

like image 134
Dr.Molle Avatar answered Oct 13 '22 12:10

Dr.Molle


After:

tinymce.init

you place the code:

  init_instance_callback: function(editor) {
    editor.on('keyUp', function(e) {
      observa_boton_ir_paso1();
    });
  }
like image 42
OfficeYA Avatar answered Oct 13 '22 10:10

OfficeYA