wysihtml5 icon indicating copy to clipboard operation
wysihtml5 copied to clipboard

Character Counter/Limit

Open pimago opened this issue 12 years ago • 13 comments

Hi, i hope this is the place to post this.

Is there a character counter/limiter in wysihtml5 or are planning on adding one?

cheers, Phil

pimago avatar Jun 01 '12 08:06 pimago

On a side note the Raptor Editor has a character limit plugin, which you can see here http://www.raptor-editor.com/demo/docking

Petah avatar Jun 01 '12 08:06 Petah

Yeah thanks. But raptor doesn't play nice with older browsers as wysihtml5 does …

pimago avatar Jun 01 '12 09:06 pimago

If there is a limitation in the backend, the user should see it in the frontend while she types. So I think a counter is a valid UX requirement for the common usecase of text lenght limitation. (What about a image count limitation then -- just kidding).

But I'd leave further requirements on word count and statistics to MS Word. Please.

ingochao avatar Jun 01 '12 09:06 ingochao

Yep, Raptor is only just released. Post your issues/feature requests and we will give you priority support. It works well in IE 9, what are your other target browsers?

Petah avatar Jun 01 '12 11:06 Petah

@Petah can you please use a different way for promoting your editor. Raptor looks nice. I especially like the "raptorize" option. Thanks.

@pimago Having a character limit option could be neat. A good approach would be to copy over the maxlength attribute from the original textarea and simulate its behavior. But what about images and similar objects?

tiff avatar Jun 01 '12 11:06 tiff

Sorry Tiff, will do :)

Petah avatar Jun 01 '12 11:06 Petah

@tiff that's what I am trying right know. Actually with several editors, but I cannot mange to workt it out. Then I stumpled upon wysihtml5, I thought it could do it.

In my case I don't need an image limit. I will keep a look on wysihtml5 until it features a counter :)

pimago avatar Jun 01 '12 12:06 pimago

I was able to implement this for the "composer" area but am having issues in the html "textarea". What tag should I be looking at to count the value when I'm in the html "textarea"? Here is the current code:

var wysihtml5_max_length = 1000;
var wysihtml5_cur_length = 0;

function verifyWysihtml5CurLength()
{
  wysihtml5_cur_length = document.getElementsByClassName('wysihtml5-sandbox')[0].contentWindow.document.body.innerHTML.length;

  if (wysihtml5_cur_length > wysihtml5_max_length)
    $("#wysihtml5_length_counter").html("<font style='color:red'>You've exceeded the maximum by " + (wysihtml5_cur_length - wysihtml5_max_length) + " characters.  Anything past the limit will not be saved.</font>");
  else
    $("#wysihtml5_length_counter").html((wysihtml5_max_length - wysihtml5_cur_length) + " characters left.");
}

editor.on("aftercommand:composer", verifyWysihtml5CurLength);
editor.on("change:composer", verifyWysihtml5CurLength); //Works
editor.on("change:textarea", verifyWysihtml5CurLength); //Does not work

RoyLee avatar Jun 13 '12 23:06 RoyLee

How to add Code? plz help me

thuatnha avatar Apr 15 '13 02:04 thuatnha

Any word on this? Does anyone have a decent workaround?

elsurudo avatar Jan 26 '15 19:01 elsurudo

@elsurudo this repo is not maintained any longer. I just opened an issue on the maintained version here: https://github.com/Voog/wysihtml/issues/149

constantm avatar Feb 19 '15 14:02 constantm