Intermittent Problem with CuteEditor_OnInitialized

Last post 06-17-2008, 11:00 AM by Kevin Lowman. 7 replies.
Sort Posts: Previous Next
  •  06-03-2008, 10:17 AM 41044

    Intermittent Problem with CuteEditor_OnInitialized

    I've been seeing an intermittent problem with CuteEditor_OnInitialized failing to fire sometimes in slower loading pages, and especially with more than one cute editor in the page.  After delving into the JavaScript files, it appears to be related to Cute Editor calling it's internal CuteEditor_FireInitialized before the remainder of the page is loaded, unless I'm mistaken and Cute Editor is waiting on the entire HTML page to load.
     
    The problem would manifest itself in that it would call the stub function for CuteEditor_OnInitialized within your JavaScript rather than the yet unreached CuteEditor_OnInitialized within the HTML code.
     
    A way to solve this, if this is indeed the problem, would be to allow us to place our CuteEditor_OnInitialized above the cute editor within the page. To do this something like the following would facilitate it:
     
    if( typeof(CuteEditor_OnInitialized) == "function" )
         CuteEditor_OnInitialized(editor); 
     
    This way, the javascript in the page is guaranteed to be loaded prior to the CuteEditor_FireInitialized and there is no need for the stub function.
     
    Am I incorrect in that CuteEditor can be initialized before the page is loaded?
     
    Also, the problem appears to occur more frequently in Internet Explorer.
  •  06-03-2008, 1:04 PM 41055 in reply to 41044

    Re: Intermittent Problem with CuteEditor_OnInitialized

    A little more information.
     
    It seems that if I set a large linked script as the last script tag in the head of the html, this causes it more often than putting it above other script in the head of the html.  I can refresh the page  repeatedly and get the OnInitialized to not fire sometimes.  If I put this linked script toward the top of the head, it appears to not occur as often, which would indicate a load timing issue.
     
    One more updated... I added an alert to the IE Implementation CuteEditor_OnInitialized stub and in repeated refreshes, I would get that alert rather than my overridden alert in the html after the cute editor.
  •  06-03-2008, 1:24 PM 41056 in reply to 41055

    Re: Intermittent Problem with CuteEditor_OnInitialized

    Here's a sample page with no linked script.  Just load this in Internet Explorer (I'm using version 7.0) and hit the refresh after each load.  The problem occurs sporadically, but does happen.  It's more apparent if you add an alert to the CuteEditor_OnInitialized stub as well so that you can see it fire instead:
     
    <%@ Page Language="C#"%>
    <%@ Register TagPrefix="CE" Namespace="CuteEditor" Assembly="CuteEditor" %>

    <html>
        <head>
            <title>ASP and ASP.NET WYSIWYG Editor - Default Configuration </title>
            <link rel="stylesheet" href="../example.css" type="text/css" />
            <script type="text/javascript" language='javascript'>
                function AddEventSimple(obj,evt,fn) {
                    if (obj.addEventListener)
                        obj.addEventListener(evt,fn,false);
                    else if (obj.attachEvent)
                        obj.attachEvent('on'+evt,fn);
                }
                function RemoveEventSimple(obj,evt,fn) {
                    if (obj.removeEventListener)
                        obj.removeEventListener(evt,fn,false);
                    else if (obj.detachEvent)
                        obj.detachEvent('on'+evt,fn);
                }
               
                function showSomething()
                {
                    var theEditor = document.getElementById('<%=StemEditor.ClientID%>');
                    var theDocument = theEditor.GetDocument();
                    alert(theDocument.body.innerHTML);
                }

                function addToolbarEvents(imageObject, clickFunction)
                {
                    AddEventSimple(imageObject, 'mouseup', tbarup);
                    AddEventSimple(imageObject, 'mousedown', tbardown);
                    AddEventSimple(imageObject, 'click', function() { clickFunction(document.getElementById('<%=OptionEditor.ClientID%>'), document.getElementById('<%=AnswerKey.ClientID%>')); return false; });
                }
               
                function setupImages()
                {
                }
               
                function tbarup(e)
                {
                    tbarhilite(e, 'v');
                }
               
                function tbardown(e)
                {
                    tbarhilite(e, 'd');
                }

                //toolbar presentation function
                function tbarhilite(e, ev)
                {
                    var e = (e) ? e : window.event;
                    var el = (e.target) ? e.target : e.srcElement;
                    if( typeof(el.tagName) != "undefined" && el.tagName=="IMG" )
                    {
                        if (el.disabled != true)
                        {
                            if (el.className != "tbarBtnSelected")
                            {
                                switch(ev){
                                    case "o":
                                        el.className="tbarBtn";
                                        break;
                                    case "u":
                                        el.className="tbarBtnOutset";
                                        break;
                                    case "v":
                                        el.className="tbarBtnOutset";
                                        break;
                                    case "d":
                                        el.className="tbarBtnInset";
                                        break;
                                }
                            }
                        }
                    }
                }
            </script>
            <!--<script type="text/javascript" language='javascript' src='ItemEditor.js'></script>-->
        </head>
        <body onload="setupImages();">
        <form runat="server">
                <table cellspacing=0 cellpadding=0 border=0 style="width:100%; height:100%;">
                    <tr style="width:100%">
                        <td valign=top colspan=3>Stem:</td>
                    </tr>
                    <tr style="height:40%; width:100%">
                        <td valign=top colspan=3>
                            <CE:Editor id="StemEditor" EditorWysiwygModeCss="../example.css" runat="server" ShowHtmlMode="False" ShowPreviewMode="False" TemplateItemList="Bold, Italic, Underline, StrikeThrough|ForeColor, BackColor|Justify, JustifyLeft, JustifyCenter, JustifyRight, JustifyFull, JustifyNone|Superscript, Subscript, RemoveFormat|Find|Cut, Copy, Paste, Undo, Redo|Indent, Outdent|OrderedList, UnorderedList" Width="100%" ShowBottomBar="False" ></CE:Editor>
                        </td>
                    </tr>
                    <tr style="width:100%">
                        <td valign=top colspan=3>Options:</td>
                    </tr>
                    <tr style="height:40%; width:100%">
                        <td valign=top colspan=2>
                            <CE:Editor id="OptionEditor" EditorWysiwygModeCss="../example.css" runat="server" ShowHtmlMode="False" ShowPreviewMode="False" TemplateItemList="Bold, Italic, Underline, StrikeThrough, ForeColor, BackColor, Justify, JustifyLeft, JustifyCenter, JustifyRight, JustifyFull, JustifyNone, Superscript, Subscript, RemoveFormat" Width="100%" ShowBottomBar="False"></CE:Editor>
                        </td>
                        <td valign=top width=1%>
                            <asp:Image ID="ToolbarUp" CssClass="tbarBtnOutset" BorderStyle="NotSet" BorderWidth="1" AlternateText="Up" runat=server /><br />
                            <asp:Image ID="ToolbarDown" CssClass="tbarBtnOutset" BorderStyle="NotSet" BorderWidth="1" AlternateText="Down" runat=server /><br />
                            <asp:Image ID="ToolbarScramble" CssClass="tbarBtnOutset" BorderStyle="NotSet" BorderWidth="1" AlternateText="Scrambe" runat=server /><br />
                            <asp:Image ID="ToolbarLengthList" CssClass="tbarBtnOutset" BorderStyle="NotSet" BorderWidth="1" AlternateText="Sort by Length" runat=server /><br />
                            <asp:Image ID="ToolbarSort" CssClass="tbarBtnOutset" BorderStyle="NotSet" BorderWidth="1" AlternateText="Sort By Value" runat=server />
                        </td>
                    </tr>
                    <tr style="width:100%">
                        <td valign=top colspan=3>Key:</td>
                    </tr>
                    <tr style="width:100%">
                        <td style="width:50%;" valign=top>
                            <asp:TextBox ID="AnswerKey" Runat="server" />
                        </td>
                        <td align=right valign=top>
                            <asp:Button id="btnUpdate" onclick="Submit" Runat="server" Text="Show HTML"></asp:Button>
                        </td>
                        <td></td>
                    </tr>
                    <tr style="width:100%">
                        <td colspan=3>
                            <asp:Literal ID="Literal1" Runat="server" />
                        </td>
                    </tr>
                </table>
                <input type='button' onclick='showSomething();' value='ClickMe!'>
            </form>
        </body>
    </html>
    <script runat="server">
        void Page_Load(object sender, System.EventArgs e)
        {
            if (IsPostBack)
            {
                Literal1.Text = "<h2>The HTML you typed is...</h2><br>";
                Literal1.Text += Server.HtmlEncode(StemEditor.Text);
            }
            else
            {
                ToolbarUp.ImageUrl = "../images/toolbar/up.gif";
                ToolbarDown.ImageUrl = "../images/toolbar/down.gif";
                ToolbarScramble.ImageUrl = "../images/toolbar/scramble.gif";
                ToolbarLengthList.ImageUrl = "../images/toolbar/lengthlist.gif";
                ToolbarSort.ImageUrl = "../images/toolbar/sort.gif";
                StemEditor.Text = ""; //"<OL ID='Options' style='list-style-type:upper-alpha'><LI keyed='' translated='false' partid='0' isoption='true'></LI></OL>";
            }
        }
        public void Submit(object sender, System.EventArgs e)
        {
            Literal1.Text = "<h2>The HTML you typed is...</h2><br>";
            Literal1.Text += Server.HtmlEncode(StemEditor.Text);
        }
       
    </script>
    <script language='JavaScript'>
        var stemEditor = document.getElementById('<%=StemEditor.ClientID%>');
        var optionEditor = document.getElementById('<%=OptionEditor.ClientID%>');
        var keyElement = document.getElementById('<%=AnswerKey.ClientID%>');

        function CuteEditor_OnInitialized(editor) {
            alert("Event Fired!");
        }

        function CuteEditor_OnChange(editor)
        {   
        }
    </script>


     
  •  06-04-2008, 9:19 AM 41104 in reply to 41056

    Re: Intermittent Problem with CuteEditor_OnInitialized

    Anyone looking into this issue?
  •  06-06-2008, 2:46 PM 41215 in reply to 41104

    Re: Intermittent Problem with CuteEditor_OnInitialized

    I wonder if this is the cause of our problems too.  Seems like about 25% of the time the control is disabled after loading...
  •  06-06-2008, 3:12 PM 41216 in reply to 41056

    Re: Intermittent Problem with CuteEditor_OnInitialized

    Frank,
     
    I've tried your example and it work here.
     
    Can you try the following example and create 10 editors in the same page?
     
     
    We will get our team discuss this issue as well.
     

    asp.net Chat http://cutesoft.net/ASP.NET+Chat/default.aspx
    Web Messenger: http://cutesoft.net/Web-Messenger/default.aspx
    asp.net wysiwyg editor: http://cutesoft.net/ASP.NET+WYSIWYG+Editor/default.aspx
    asp wysiwyg html editor: http://cutesoft.net/ASP
    asp.net Image Gallery: http://cutesoft.net/ASP.NET+Image+Gallery/default.aspx
    Live Support: http://cutesoft.net/live-support/default.aspx

  •  06-06-2008, 4:07 PM 41217 in reply to 41216

    Re: Intermittent Problem with CuteEditor_OnInitialized

    Adam,
     
    The problem is related to initial page load, not dynamically creating the editors within an alrea
     
    When the client browser loads the cute editor, especially IE, it begins execution before the entire page is loaded.  The cute editor requires us to redefine the stub version of CuteEditor_OnInitialized and any other client side function we wish to implement after the cute editor within the page.  The problem this causes is that, if the initialization of the cute editor completes before the bottom portion of the page is loaded, the stub version fires rather than the event at the bottom of the page.
     
    I've proven this out by putting an alert inside the cute editor code itself and refreshing the page repeatedly in IE.  If you remove the alert("Event Fired!"); from my example and put this in your CuteEditorImplementation.js and/or Loader.js inside the "function CuteEditor_OnInitialized {}" stub function, this alert will fire occasionally upon repeated refreshes within IE.

    In more slower loading pages, the problem becomes worse.

    In order to fix it I had to put an initialization function at the top of the page, like:
     
    <script language='javascript'>
    function InitializeEditor(editor)
    {
        // Do Something
    }
    </script>
     
    And then change the cute editor stub function within Cute Editor from:
     
    function CuteEditor_OnInitialized {}
     
    to:
     
    function CuteEditor_OnInitialized { if( typeof(InitializeEditor) == "function") InitializedEditor(editor); }
     
    I don't want to have to constantly change the cute editor code every time there is an update to guarantee that I get an event fired.
     
    If the cute editor waited until the entire page was loaded prior to firing the function, this would not be a problem.  As it stands now, this method does not guarantee that my initialize event is fired.
  •  06-17-2008, 11:00 AM 41494 in reply to 41217

    Re: Intermittent Problem with CuteEditor_OnInitialized

    I've just downloaded the current version, this problem still exists.  We're using Frank's workaround because otherwise the control is unreliable, but it would be nice if this were fixed...

View as RSS news feed in XML