Word and Character Counter to update with every key press?

Last post 12-14-2011, 6:23 AM by Kenneth. 3 replies.
Sort Posts: Previous Next
  •  12-13-2011, 2:47 AM 71975

    Word and Character Counter to update with every key press?

    The word and character counter at the bottom right of the editor seems to only update when you press enter, back space or don't press something for a certain amount of seconds, how can I make it so that it updates after every key press?
  •  12-13-2011, 7:27 AM 71979 in reply to 71975

    Re: Word and Character Counter to update with every key press?

    Hi davideo,
     
    The developer hard code on that function. So for now can not change it.
     
    The example below shows you how to shows the work count out side the editor when the key press. Hope it help.
     
    <?php include_once("cuteeditor_files/include_CuteEditor.php") ; ?>
    <html>
        <head>
    </head>
        <body>
    <form name="form1">
            <?php
                $editor=new CuteEditor();
                $editor->ID="Editor1";
                $editor->Draw();
                $editor=null;
            ?>
              <input type="text" id="text1" />
            <div id="plainText" style="visibility: hidden">
            </div>
    </form>
    </body>
    </html>
    <script>
    var text1=document.getElementById("text1");
    function isIE() {
        if (window.navigator.userAgent.toLowerCase().indexOf("msie") != -1) return true;
        else return false;
    }
    function GetPlainText() {
        var editor1 = document.getElementById('CE_Editor1_ID');
        var plainText = document.getElementById("plainText");
        plainText.innerHTML = editor1.GetHTML();
        var text;
        if (isIE()) {
            text = plainText.innerText;
        }
        else {
            text = plainText.textContent;
        }
        var words = text.replace(/\s+/g, "-").split("-");
        var count = 0;
        for (var i = 0; i < words.length; i++) {
            if (words[i] != "") {
                count++;
            }
        }
        text1.value=count;
        plainText.innerHTML = "";
    }
    function showWordCount(oEvent)
    {
        GetPlainText();
       
    }
    function CuteEditor_OnInitialized(editor)
    {
        var editdoc = editor.GetDocument();
        if(window.addEventListener)
        {
            
            editdoc.addEventListener("keypress",showWordCount,"false");
        }
       
        editdoc.body.onkeydown=function()
        {
           GetPlainText();
        }
    }
    </script>
     
    Regards,
     
    Ken 
  •  12-13-2011, 12:14 PM 71995 in reply to 71979

    Re: Word and Character Counter to update with every key press?

    That didn't work
  •  12-14-2011, 6:23 AM 72002 in reply to 71995

    Re: Word and Character Counter to update with every key press?

    Hi davides7,
     
    Can you explain it in detail? what do you mean it didn't work?
     
    The text box did not shows the work count? Get error?
     
    Regards,
     
    Ken 
View as RSS news feed in XML