开发者

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开发者_StackOverflow(0).id + '_ifr').keyup(); and $('#textarea1').keyup(); but no use.

Can some one help me to get it right?


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


After:

tinymce.init

you place the code:

  init_instance_callback: function(editor) {
    editor.on('keyUp', function(e) {
      observa_boton_ir_paso1();
    });
  }


There was a character missing. Try this (works at elast in my browser FF 3.6.17)

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.');
        }
    });
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜