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

  •  12-13-2011, 7:27 AM

    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 
View Complete Thread