Re: onchange event does not fire when font size is changed

  •  05-13-2010, 8:12 AM

    Re: onchange event does not fire when font size is changed

    I have used the following code to test, when you set font style, CuteEditor_OnChange will be fired

    <%@ Page Language="C#" %>
    <%@ Register TagPrefix="CE" Namespace="CuteEditor" Assembly="CuteEditor" %>
    <html>
    <head>
        <title>JavaScript API</title>
        <script language="JavaScript" type="text/javascript">
            function FocusDocument() {
                var editor1 = document.getElementById('<% = Editor1.ClientID%>');

                // setting input focus to Cute Editor
                editor1.FocusDocument();
                editor1.SetWidth("1000");
                editor1.SetHeight("1000");
                // retrieving the content of Cute Editor as HTML
                var content = editor1.getHTML();
                alert(content);
            }
            function getHTML() {
                alert("getHTML is called");
                // get the cute editor instance
                var editor1 = document.getElementById('<%=Editor1.ClientID%>');
                // Get the editor HTML
                document.getElementById("myTextArea").value = editor1.getHTML();
            }
            function setHTML() {
                alert("setHTML is called");
                // get the cute editor instance
                var editor1 = document.getElementById('<%=Editor1.ClientID%>');
                // Set the editor
                editor1.setHTML(document.getElementById("myTextArea").value);
            }
            function PasteHTML(html) {
                alert("PasteHTML is called");
                // get the cute editor instance
                var editor1 = document.getElementById('<%=Editor1.ClientID%>');
                editor1.PasteHTML(html);
            }
            function SetActiveTab(tab) {
                alert("SetActiveTab is called");
                // get the cute editor instance
                var editor1 = document.getElementById('<%=Editor1.ClientID%>');
                editor1.SetActiveTab(tab);
            }
            function setFocus() {
                alert("setFocus is called");
                // get the cute editor instance
                var editor1 = document.getElementById('<%=Editor1.ClientID%>');
                editor1.FocusDocument();
            }
            function ExecCommand() {
                alert("ExecCommand is called");
                // get the cute editor instance
                var editor1 = document.getElementById('<%=Editor1.ClientID%>');
                var CommandObj = document.getElementById('Commands');
                var cmd = CommandObj.options[CommandObj.selectedIndex].text;
                var val = CommandObj.options[CommandObj.selectedIndex].value;
                editor1.ExecCommand(cmd, false, val);
            }
            function CE_attachEvent() {
                alert("CE_attachEvent is called");
                // get the cute editor instance
                var editor1 = document.getElementById('<%=Editor1.ClientID%>');
                //Get the editor content 
                var editdoc = editor1.GetDocument();
                // attach Event
                if (editdoc.attachEvent)
                    editdoc.attachEvent('onkeypress', HandleChange);
                else if (editdoc.addEventListener)
                    editdoc.addEventListener('keypress', HandleChange, true);
            }
            function CE_detachEvent() {
                alert("CE_detachEvent is called");
                // get the cute editor instance
                var editor1 = document.getElementById('<%=Editor1.ClientID%>');
                //Get the editor content 
                var editdoc = editor1.GetDocument();
                // detach Event
                if (editdoc.detachEvent)
                    editdoc.detachEvent('onkeypress', HandleChange);
                else if (editdoc.removeEventListener)
                    editdoc.removeEventListener('keypress', HandleChange, true);
            }
            function HandleChange() {
                alert("HandleChange is called");
                // get the cute editor instance
                var editor1 = document.getElementById('<%=Editor1.ClientID%>');
                //Get the editor content 
                var editdoc = editor1.GetDocument();
                alert(editdoc.body.innerHTML);
            }  
        
        </script>
        <script runat="server">
            override protected void OnInit(EventArgs e)
            {
                base.OnInit(e);
                Editor1.Text = @"<table cellspacing=""4"" cellpadding=""4"" bgcolor=""#ffffff"" border=""0""> <tbody> <tr> <td> <p> <img src=""http://cutesoft.net/Uploads/j0262681.jpg"" width=""80"" alt=""""/></p></td> <td> <p>When your algorithmic and programming skills have reached a level which you cannot improve any further, refining your team strategy will give you that extra edge you need to reach the top. We practiced programming contests with different team members and strategies for many years, and saw a lot of other teams do so too.  </p></td></tr> <tr> <td> <p>  <img src=""http://cutesoft.net/Uploads/PH02366J.jpg"" width=""80"" alt="""" /></p></td> <td> <p>From this we developed a theory about how an optimal team should behave during a contest. However, a refined strategy is not a must: The World Champions of 1995, Freiburg University, were a rookie team, and the winners of the 1994 Northwestern European Contest, Warsaw University, met only two weeks before that contest.  </p></td></tr></tbody></table> <br /> <br />";
                Editor1.SetScriptProperty("ServerTime", DateTime.Now.ToString("HH:mm:ss"));      
            }
        </script>
        <body>
            <form id="Form1" runat="server">      
            <table cellpadding="15">
                <tr>              
                    <td>
                        <h1>JavaScript API</h1>                 
                        <br />                  
                        <CE:Editor ID="Editor1" Width="560" TemplateItemList="[Save,Bold,Italic,Underline,InsertChars,InsertEmotion]"
                            ThemeType="OfficeXP" Height="250" runat="server">
                        </CE:Editor>
                        <br />
                        <textarea cols="60" rows="5" id="myTextArea" style="width: 550px" name="myTextArea">Try click the "get HTML" button</textarea>
                        <br />
                        <br />
                        <p style="width: 600">
                            <input type="button" value="get HTML" onclick="getHTML()" id="Button1">
                            <input type="button" value="set HTML" onclick="setHTML()" id="Button2">
                            <input type="button" value="insert HTML" onclick="PasteHTML('This is a test!')">
                            <input type="button" value="set ActiveTab to Code" onclick="SetActiveTab('Code')">
                            <input type="button" value="set Focus" onclick="setFocus()">
                            <input type="button" value="attach Event (onkeypress)" onclick="CE_attachEvent()">
                            <input type="button" value="detach Event (onkeypress)" onclick="CE_detachEvent()">
                        </p>
                        <br>
                        <select id="Commands">
                            <option value="Cut">Cut</option>
                            <option value="Copy">Copy</option>
                        </select>
                        <input type="button" value="ExecCommand" onclick="ExecCommand()">
                    </td>               
                </tr>
            </table>
            </form>
        </body>
    </html>
    <script language="JavaScript" type="text/javascript">
        var editor1 = document.getElementById("<%=Editor1.ClientID%>");
        if (editor1.IsReady) CuteEditor_OnInitialized(editor);

        function CuteEditor_OnChange(editor) {
            alert("CuteEditor_OnChange is called");
            //when the content be changed..
            document.getElementById("ctl_onchange").innerHTML = editor.id + " changed at " + new Date().toLocaleTimeString();
        }
        function CuteEditor_OnCommand(editor, command, ui, value) {
            alert("CuteEditor_OnCommand is called");
            //handle the command by yourself
            if (command == "InsertEmotion") {
                var answer = confirm("Click OK to stop this command.")
                if (answer) {
                    return true;
                }
                else {
                    return false;
                }
            }
        }
        function CuteEditor_OnInitialized(editor) {
            alert("CuteEditor_OnInitialized is called");
            var oldexec = editor1.ExecCommand;
            editor1.ExecCommand = function (cmd, ui, val) {
                if (cmd == "InsertChars") {
                    alert("Run some code here ....");
                    //return;
                }
                return oldexec.apply(this, arguments);
            }
        }
    </script>

     
     
     
    Regards,
    Eric
View Complete Thread