Reputation: 523
I need a rich text editor like this one used on this site, with a word counter on it, i will love to restrict the total work count like on twitter, preferrably written with jQuery, please any tip, i will greatly appreciate it.
Upvotes: 2
Views: 1618
Reputation: 42675
I would recommend TinyMCE for all your rich text editing needs. I haven't looked, but I bet there is a word count plugin for it.
Upvotes: 3
Reputation: 185862
The editor on SO isn't "rich" in any real sense of the word. It's just a <textarea>
. To do word-count limiting, simply access the relevant DOM field (text or value, I suppose; not my area of expertise, sorry), split on spaces, and refuse to submit if the resulting array is too long.
You will have to be careful with people trying to game the rules by, e.g., writing entire paragraphs with underscores instead of spaces. You could split on any non-word characters instead (which they might game by just mashing words together), or limit the number of characters as well as the number of words. By far the simplest option, however, is to just limit the character count like SO does.
Upvotes: 0