1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Real Time Post Characters / Words Counter

Discussion in 'Resource and Add-on Requests' started by TheBigK, Nov 9, 2012.

  1. TheBigK

    TheBigK Well-Known Member

    I've just enabled an add-on that forces minimum characters in a post rules. My members are requesting a simple real time characters / words counter. I think it'd be cool to have one. What say?
     
  2. ENF

    ENF Well-Known Member

    TinyMCE has a Wordcount plugin --- but it's not included in the XenForo version.

    I've not personally dug into the TinyMCE integration, so I'm not sure how much work that would be. However, I do know that you probably need to enable the status bar which is where the would count would be shown. (Refer to the TinyMCE demo shown here: http://www.tinymce.com/tryit/full.php)

    For individual character counting... don't think I've seen that with TinyMCE or just never paid attention to it, if it does.
     
  3. cclaerhout

    cclaerhout Well-Known Member

    The status bar can only be activated with the TinyMCE advanced Theme. XenForo is using its own theme. So it's not directly possible to use the wordcount plugin unless to integrate the status bar from the advanced Theme to XenForo Theme. It's still possible but I don't know (and I will not verify) if it requires a lot of coding.

    For individual characters counting, there are some individual jQuery plugin for textareas, but since TinyMCE with XenForo is using an Iframe, all html tags will need to be take out from the counting. So it requires two things: 1) update the jquery plugin to TinyMCE (to match different events such as change of state [paste code], keydown, etc.) 2) a regex to match only tag content. I'm not sure this will not slow down the editor.
     
  4. ENF

    ENF Well-Known Member

    Based on Cedric's post, I did some research into this and determined that it's not worth it, lol.

    If anything, raise it as a feature request.
     
  5. cclaerhout

    cclaerhout Well-Known Member

    ... I've been curious and I've looked at it. If you want the TinyMCE plugin to count words, it's easy to release it (*) and I can do it tonight or tomorrow. But it seems it's not a 100% real-time words counting plugin. I guess it's to avoid to slow down the browser.

    *Why? Because it seems XenForo theme is based on the Advanced theme... so the status bar is available but with another name: "theme_xenforo_statusbar_location"
     
  6. ENF

    ENF Well-Known Member

    Correct me if I'm wrong, but you would need to load the plugin as well within the tinyMCE.init. Also, you would need to upload the plugin files to the server, since they aren't included with the default XenForo file structure. (but come with the default TinyMCE package)
     
  7. cclaerhout

    cclaerhout Well-Known Member

    Correct:
    1) upload the plugin
    2) modify the template editor_js_setup (add plugin command & statusbar location)

    I will do this tomorrow and release it the same day (it's really easy to do).
     
    TheBigK likes this.
  8. TheBigK

    TheBigK Well-Known Member

    Just a suggestion if you can implement. Why not display a message along with the counter that says one of the following messages depending on character/word count? -

    < 15 words : Post too short!
    15-100 words: Looks like you're typing something nice
    100-500 words: Salute, typing master!
    > 500 words: Hope it's not a copy+paste job

    :D ..would make posting business funnier (maybe!).
     
  9. cclaerhout

    cclaerhout Well-Known Member

    Let's do something simple if you don't mind ;) If you want to customize after, feel free to modify the Javascript file, but if you do it you will need to support the multilingual option and make a few more tweaks then ;)
     
  10. cclaerhout

    cclaerhout Well-Known Member

    Here it is.
     
    ENF and TheBigK like this.
  11. ENF

    ENF Well-Known Member

    Very nice work as usual Cedric, will take a look at this in more detail tomorrow.
     
  12. TheBigK

    TheBigK Well-Known Member

    Thanks a lot. Will try this out soon.
     

Share This Page