Topic: character counter
I am currrent looking for a character counter plugin. Anyone can help me?
Most appreciate if all of you can help me.
Thanks!!
Pages 1
I am currrent looking for a character counter plugin. Anyone can help me?
Most appreciate if all of you can help me.
Thanks!!
HTMLAREA Xingha provide counter in word or character....It can be either want to count ONLY real characters or with HTML character, as well as count WORD only. Hope someone can do in TinyMCE as well.
I a'm not very good in javascript, thus i need someone who expert in Javascript can help us to do this. I believe there were some others need this function as well.
Thanks
I had a go at making a Word/Character counter after seeing this, and its a success, so I'll post it up tomorrow. Just testing bit. Works like the MSWord Word Count. Just displays an alert box with the word count, character count, and character count including spaces.
Ryan.
hi Ryan,
i checked out your charcounter plugin -- do you have any plans to develop it further? i was looking for a dynamically updated representation of how many characters have been used to serve as a kind of a maxlength for a textarea.
thanks,
-cris
I too am trying to get a dynamic character counter into the display.
The problem I am having is that the user types tons of info and won't know until the page is submitted whether it is too long or not.
I would like to get a simple system to update the display in order to tell the user how many characters they have left.
I would like the count to include all html in the count so that it is accurate (filling a dB field)
I have done this with Javascript before using the .length and the onChange commands, but they appear to be 'disabled' for the tiny mce powered text areas. Can you direct me to a tool that will do this?
for every click of the keyboard, the count should update with the new count.
Thanks in advance. AND thank you for a great tool.
Im looking for the same thing; It will function as to count the total amount of chars, including html, (for db entry...). I was thinking about an execcommand_callback with a setTimeOut or so. Im kinda new to tinyMCE, so im not completely sure yet how it would be written...
regards,
Alex
http://wiki.moxiecode.com/index.php/Tin d_callback
this page shows how execcommand is handled, BUT, where are the variables loaded in? i didnt get that... (like the instance/editor_id, elm, command, etc...)
Last edited by AlexT82 (2007-02-14 17:45:39)
Has someone a working character counter ?
The following worked for me it restricts the user by limiting character to 450
tinyMCE.init({
mode : "exact",
elements : "description",
theme : "simple",
setup : function(ed) {
ed.onKeyUp.add(function(ed, e) {
txt = tinyMCE.activeEditor.getContent();
//strip the html
txt = txt.replace(/(<([^>]+)>)/ig,"");
txt = txt.replace(/ /g,"");
if (txt.length > 450) {
txt = txt.substring(0,450);
tinyMCE.execCommand('mceSetContent',false,txt);
}
});
}
});
forget it junaid!
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);
});
}
});
This function by charl works really well. Thanks!
Is there a way to get this to show up when the editor is first displayed?
Thanks for any hints...
Tom
it is useful code
thanks for giving
Fantastic work, thank you!
I've adjusted it slightly for my use as I only need a character count and v3.3 was counting , & etc as more than 1 character. Code below in case it is of any use to anyone:
var strip = (tinyMCE.activeEditor.getContent()).replace(/(<([^>]+)>)/ig,"").replace(/&[a-z]+;/ig, "-");
EDIT: Small fix $amp; -> &
Last edited by coptang (2010-03-19 20:19:53)
How can I get it to exclude spaces from the character count?
Figured it out, see replace at end of code below.
var strip=(tinyMCE.activeEditor.getContent()).replace(/(<([^>]+)>)/ig,"").replace(/&[a-z]+;/ig, "").replace(/ /g, "");Anyone can help me?
Most appreciate if all of you can help me.
Ryan,
I want to use your charcounter plugin...
But I want to exclude the spaces from character count from Fantasy Football
How can I do it?
Last edited by Janethalloren11 (2010-08-18 11:30:02)
You might want to check out the Text Metrics plugin, which counts white space separately: http://tinymce.moxiecode.com/punbb/view ?id=22195.
This jQuery counter plug-in allows you to count characters or words, either up or down. You can set a goal for the counter to reach.
It will insert a div with an id of the name of the input area you are counting with a "_counter" suffix. For example, if the input you want to count is called "countMe", the id of the div that keeps track of the count will be "countMe_counter".
For details Visit wplayground.comuv.com/counter/
Is it possible to convert the function provided by charl to a plugin?
Can someone advise me how I'd go about doing so?
Why would you need a plugin for that? Anyway you can take a look into the example plugin which is nothing but a plugin creation tutorial.
Hi Felix,
It'd be easier for me to integrate with a plugin, the TinyMCE I want to modify is integrated into a CMS (SilverStripe), and the way they've integrated it (using a dynamic config string) makes adding a setup event troublesome. However, it appears as though including a plugin is easy enough. Link below, if you're interested.
http://www.ssbits.com/tutorials/2009/customising-the-wysywig-editor-in-v2-3-2-tinymce/
Thanks for the tip, I'll check out the example plugin.
All the above mentioned did not work for me.
but this - based on the above and one this http://javascript.internet.com/snippets/remove-html-tags.html - did work:
setup: function(ed) {
var text = '';
var span = document.getElementById('counter-' + ed.id);
if(span) {
var max_length = span.innerHTML;
ed.onKeyUp.add(function(ed, e) {
text = ed.getContent().replace(/&(lt|gt);/g, function (strMatch, p1){
return (p1 == "lt")? "<" : ">";
});
var strTagStrippedText = text.replace(/<\/?[^>]+(>|$)/g, "");
currNumOfChars = (strTagStrippedText.length);
chars_left = max_length - currNumOfChars;
span.innerHTML = chars_left;
if(currNumOfChars > (max_length - 11))
{
//style numbers in red
$("#counter-my_text").html("").html(chars_left).css("color", "#FF0000");
}
else
{
//set the length of the text into the counter span
$("#counter-my_text").html("").html(chars_left).css("color", "#484848");
}
if((currNumOfChars > max_length) || (currNumOfChars == 0))
{
//$("#submit").attr("disabled", "disabled");
$("#submit").button({ disabled: true });
}
else
{
//$("#submit").removeAttr("disabled");
$("#submit").button({ disabled: false });
}
});
}
}
the above includes disable/enable submit button and changing the color of the counter
Pages 1
You are not logged in. Please login or register.