htmlArea

A directory of browser-based WYSIWYG editors

  MAIN
INDEX
SEARCH
POSTS
WHO'S
ONLINE
LOG
IN

Home: htmlArea 3 (beta): htmlArea 2 & 3 archive (read only): htmlArea v3.0 - Discussion:
count char - max char


The htmlArea 2 & 3 editors have been discontinued.

We've made these forums available as a read-only reference and knowledge-base for people using or developing editors based on htmlArea 2 or 3.

Anyone who is interested in taking over version 2 or 3 is free to do so. All we ask is that you choose a new name that doesn't have "htmlarea" in it to avoid confusion with this site. We'll even give you a link in the directory to make it easier for people to find you. If you are developing or hosting an htmlArea based-editor under a new name, please submit it to our directory.

 


Memby
New User

Jun 29, 2004, 5:26 AM

Post #1 of 10 (70021 views)
Shortcut
count char - max char Can't Post

I'd like to have a char counter for the version 3, and how can I limit the number of char.

Thanks. (soory for my english)


demuire
Novice

Oct 12, 2004, 7:42 PM

Post #2 of 10 (69886 views)
Shortcut
Re: [Memby] count char - max char [In reply to] Can't Post

Hmm, I'd like to know too. I saw the threads for the previous version, but can't figure out how to adapt it to fit v3?


demuire
Novice

Oct 13, 2004, 6:06 PM

Post #3 of 10 (69872 views)
Shortcut
Re: [demuire] count char - max char [In reply to] Can't Post

I've started working on one, I made a plugin called CharCounter. It's still very much work-in-progress, but the main thing in the plugin is this:


Quote
CharCounter.prototype.onKeyPress = function(editor, obj) {
updateCounter();
};


And then in the page calling I have this:


Quote
function updateCounter() {
var myText = editor.getHTML();
document.forms[0].counter.value = myText.length;

// alert("update the counter here!");
}


This still counts the HTML tags, but I think this can be fixed by including this code (from franknitty69 on [url=http://www.interactivetools.com/forum/gforum.cgi?post=18936;search_string=count%20no%20html;#18936]this thread) :


Quote
contents = contents.replace(/<(.+?)>/g, '');//Don't count HTML tags
contents = contents.replace(/&nbsp;/g, ' ');//Count nbsp; as one keystroke


For some reason I couldn't put all of the code into the plugin, I don't know how to call the text field from within the plugin?


demuire
Novice

Oct 13, 2004, 6:47 PM

Post #4 of 10 (69871 views)
Shortcut
Re: [demuire] count char - max char [In reply to] Can't Post

Actually, I should say that I don't know how to get the value of the HTMLArea box from within the plugin... I tried editor.getHTML() but it doesn't work? Might have to look at some other plugins and see how they work...


demuire
Novice

Oct 13, 2004, 8:28 PM

Post #5 of 10 (69869 views)
Shortcut
Re: [demuire] count char - max char [In reply to] Can't Post

Here's something I've come up with that seems to work...

In the calling page I have:


Quote
editor.registerPlugin(CharCounter, "counter");


where "counter" is the name of the text field that displays the number of characters

And this is what I have in char-counter.js:


Quote
function CharCounter(editor, params) {
this.editor = editor;
fieldID = params[0];
};

CharCounter._pluginInfo = {
name : "CharCounter",
version : "1.0",
developer : "Fook Lee",
developer_url : "http://www.fookstar.com",
c_owner : "Fook Lee",
sponsor : "",
sponsor_url : "",
license : "htmlArea"
};

CharCounter.prototype.onGenerate = function() {
var self = this;
var doc = this.editordoc = this.editor._iframe.contentWindow.document;
HTMLArea._addEvents(doc, ["keypress"],
function (event) {
return self.keyPress(editor, HTMLArea.is_ie ? self.editor._iframe.contentWindow.event : event);
});
};

CharCounter.prototype.keyPress = function(editor, ev) {
var self = this;
var i18n = CharCounter.I18N;

var contents = editor.getHTML();
contents = contents.replace(/<(.+?)>/g, '');//Don't count HTML tags
contents = contents.replace(/&nbsp;/g, ' ');//Count nbsp; as one keystroke
var counterField = document.getElementById(fieldID);
counterField.value = contents.length;
}

var fieldID = null;


It more or less works, there's something strange with the way it counts when you put carriage returns in, but otherwise it seems to work fine?

Hope this helps someone...


BRULIK
New User

Feb 20, 2005, 11:33 AM

Post #6 of 10 (69576 views)
Shortcut
Re: [demuire] count char - max char [In reply to] Can't Post

  1. button "Backspase" not counted :(
  2. HTML tags not counted :(


This plugin is verry necessary !!! Please change this code Wink

Thanks.


demuire
Novice

Feb 20, 2005, 6:47 PM

Post #7 of 10 (69555 views)
Shortcut
Re: [BRULIK] count char - max char [In reply to] Can't Post

What do you mean by backspace not counted?

Secondly if you want to count HTML tags just take out the code that says "don't count HTML code"!


BRULIK
New User

Feb 21, 2005, 1:52 AM

Post #8 of 10 (69542 views)
Shortcut
Re: [demuire] count char - max char [In reply to] Can't Post

If im use to 'Del' or 'Backspase' button , a count not autodecrement :(


demuire
Novice

Feb 21, 2005, 1:58 AM

Post #9 of 10 (69541 views)
Shortcut
Re: [BRULIK] count char - max char [In reply to] Can't Post

Really? Interesting, I'll have to look into that.


BRULIK
New User

Feb 21, 2005, 2:02 AM

Post #10 of 10 (69540 views)
Shortcut
Re: [demuire] count char - max char [In reply to] Can't Post

Beside you work?

 
 
 


Search for (options)