1

Topic: tinyMCE charcount plugin? Character Count Plugin?

Hi All,

Does anyone know what every became of the "charcount" plugin that happy_noodle_boy (Ryan) had been developing?

I have seen references to a "charcount" plugin in other tinyMCE javascript code out there on the net, but all current references to where that plugin might be have vanished into thin air.

Please let me know if you have this plugin.

Cheers!

Justin

2

Re: tinyMCE charcount plugin? Character Count Plugin?

Sorry no, but what is the functionality and maybe we can come up with something?

3

Re: tinyMCE charcount plugin? Character Count Plugin?

Hi Jamie,

The functionality for a "tinyMCE charcount plugin" that I am looking for would display the current total character count (all the text, including the html being generated) and would alert the user when the maximum number of characters has been reached.

I have been able to get the character count from the text being entered into the iFrame/Textarea using
alert(tinyMCE.get('[id_of_the_textarea]').getContent().length);

And I think that I could use this if I could somehow reference the onKeyUp event of the iFrame, but have so far been unable to figure out how to reference the iFrame that replaces the Textarea AND assign an in-line javascript event to it.

I understand that the iFrame has the following name/id assigned to it when it replaces the Textarea (textarea id and
"_ifr" added to the end. eg [id_of_the_textarea]_ifr

Any additional insight or comments would be appreciated.

Cheers!

Justin

4

Re: tinyMCE charcount plugin? Character Count Plugin?

How about getDoc(), it refers to the iframes document object.
Apply some cleaning with some prototype.js methods to have a clean charcount (no tags, scripts, special characters).
var charcount below returns the exact number of characters, spaces included (the gsub-part is especially for IE, else it keeps counting following spaces as 6 from the second up, FF has enough with the unescapeHTML-part in that matter).

function myHandleEvent(e) {
if(e.type == 'keyup'){
   var charcount = tinyMCE.activeEditor.getDoc().body.innerHTML.stripScripts().stripTags().gsub(' ',' ').unescapeHTML().length;
   alert(charcount);
}
tinyMCE.init({
   ...
   handle_event_callback : "myHandleEvent"
});

Last edited by Dietrich (2008-03-22 03:42:51)

5

Re: tinyMCE charcount plugin? Character Count Plugin?

I wrote the code to do a word and char count as you type in tinyMCE:
It shows in the tinyMCE status bar.

tinyMCE.init({
    ....

     //Character count
     theme_advanced_path : false,
     setup : function(ed) {
          ed.onKeyUp.add(function(ed, e) {   
               var strip = (tinyMCE.activeEditor.getContent()).replace(/(<([^>]+)>)/ig,"");
               var text = strip.split(' ').length + " Words, " +  strip.length + " Characters"
        tinymce.DOM.setHTML(tinymce.DOM.get(tinyMCE.activeEditor.id + '_path_row'), text);   
    });
     }

});

6

Re: tinyMCE charcount plugin? Character Count Plugin?

Hi Iam new to this forum ........
first off all thanks to the forum members for sharing the valuable information ..........
I implemented the below code for character count display in status bar . but it is not working properly
One thing I want to know from the below code snippet
1. From where we are calling from '(function(ed, e) '  and wat are the parameters of "ed" and "e"
Please give me some brief information. I need this functionality urgent ......
Thanks in advance ......
tinyMCE.init({
    ....

     //Character count
     theme_advanced_path : false,
     setup : function(ed) {
          ed.onKeyUp.add(function(ed, e) {   
               var strip = (tinyMCE.activeEditor.getContent()).replace(/(<([^>]+)>)/ig,"");
               var text = strip.split(' ').length + " Words, " +  strip.length + " Characters"
        tinymce.DOM.setHTML(tinymce.DOM.get(tinyMCE.activeEditor.id + '_path_row'), text);   
    });
     }

});

7

Re: tinyMCE charcount plugin? Character Count Plugin?

Usually the variable "ed" refers to an editor instance. In your configuration you use a setup function which "installs" a function into your editor's "onKeyUp" event listener which in turn will call your function in the event that a user has stopped pressing a key. And as you can see in the documentation the first argument ("ed") is a reference to your editor instance and the second is a reference to the event object.

Next time you take a look into the API yourself, OK?

Greetings from Germany,

Felix Riesterer.
(-> about me and this forum <-)