Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

[OT] Limiting word count with TinyMCE

by VC (Novice)
on Apr 07, 2019 at 22:58 UTC ( [id://1232257]=perlquestion: print w/replies, xml ) Need Help??

VC has asked for the wisdom of the Perl Monks concerning the following question:

Tinymce ver 4.4

tinymce.init({ selector: "textarea.longdesc", mode: "specific_textareas", plugins: "preview wordcount code paste charmap", toolbar: "cut copy paste | charmap | bold | bullist numlis +t | outdent indent | undo redo | code | preview", menubar: false, toolbar_items_size: 'large', valid_elements: "a[href|target=_blank],strong/b,br,ol,ul,l +i,p,p/h1,p/h2,p/h3,p/h4", max_word: 1300, setup: function (ed) { ed.on('keyup', function (e) { var writtenWords = tinyMCE.activeEditor.getContent +().replace(/(<([^>]+)>)/ig,'').length; var maxWord = ed.settings.max_word; var limited = ""; var content = ed.getContent(); if (writtenWords >= maxWord) { $('.mce-wordcount').css("color", "red"); limited = $.trim(content).split(" ", maxWord); limited = limited.join(" "); ed.setContent(limited); }else if (writtenWords < maxWord) { $('.mce-wordcount').css("color", "green"); } }); } });

This code does not work correctly? help, it works just enough to make me nuts

Replies are listed 'Best First'.
Re: [OT] Limiting word count with TinyMCE
by markong (Pilgrim) on Apr 08, 2019 at 00:39 UTC
    This code does not work correctly?

    Who knows? perl does not even accept it! Have you tried executing the JS somewhere?

    Also:
    }else if (writtenWords < maxWord) {
    should be written as a simple } else {

    An "else if" clause is used when there are more than 2 branches.
      <script type="text/javascript" src="/js/tinymce/jquery.tinymce.min.js" +></script> <script type="text/javascript" src="/js/tinymce/tinymce.min.js"></scri +pt>

      I changed it to just "else"

      Still the same?

        I think this might have been irony.

        This is a Perl board, could you please elaborate the connection to Perl?

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

Re: [OT] Limiting word count with TinyMCE
by AnomalousMonk (Archbishop) on Apr 07, 2019 at 23:38 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1232257]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2024-04-25 01:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found