Ticket #234: FCKeditor_Net.patch

File FCKeditor_Net.patch, 4.3 KB (added by Juraj Skripsky, 16 years ago)

Patch implementing the above mentioned optimizations

  • FCKeditor.cs

     
    2727using System.ComponentModel ;
    2828using System.Text.RegularExpressions ;
    2929using System.Globalization ;
    30 using System.Security.Permissions ;
     30using System.Security.Permissions ;
     31using System.Reflection ;
    3132
    3233namespace FredCK.FCKeditorV2
    3334{
     
    4344        [ Designer("FredCK.FCKeditorV2.FCKeditorDesigner") ]
    4445        [ ParseChildren(false) ]
    4546        public class FCKeditor : System.Web.UI.Control, IPostBackDataHandler
    46         {
    47                 private bool _IsCompatible ;
     47        {
     48                private static MethodInfo getCurrentScriptManagerMethod, registerOnSubmitStatementMethod ;
     49                private static PropertyInfo supportsPartialRenderingProperty ;
     50                private static readonly string onSubmitScriptTemplate =
     51                        "(function()\n{{\n" +
     52                        "\tvar editor = FCKeditorAPI.GetInstance('{0}');\n" +
     53                        "\tif (editor)\n" +
     54                        "\t\teditor.UpdateLinkedField();\n" +
     55                        "}})();\n" ;
    4856
     57                static FCKeditor()
     58                {
     59                        Type scriptManagerType = Type.GetType( "System.Web.UI.ScriptManager, System.Web.Extensions" ) ;
     60                        if ( scriptManagerType != null )
     61                        {
     62                                getCurrentScriptManagerMethod = scriptManagerType.GetMethod( "GetCurrent", new Type[] { typeof( Page ) } ) ;
     63                                supportsPartialRenderingProperty = scriptManagerType.GetProperty( "SupportsPartialRendering" ) ;
     64                                registerOnSubmitStatementMethod = scriptManagerType.GetMethod( "RegisterOnSubmitStatement", new Type[] { typeof( Control ), typeof( Type ), typeof( String ), typeof( String ) } ) ;
     65                        }
     66                }
     67
     68                private bool _IsCompatible ;
     69               
    4970                public FCKeditor()
    5071                {}
    5172
     
    399420                       
    400421                        _IsCompatible = this.CheckBrowserCompatibility();
    401422
    402                         if ( !_IsCompatible )
     423                        if ( !_IsCompatible || getCurrentScriptManagerMethod == null )
    403424                                return;
     425
     426                        object oScriptManager = getCurrentScriptManagerMethod.Invoke( null, new object[] { Page } ) ;
    404427
    405                         object oScriptManager = null;
    406 
    407                         // Search for the ScriptManager control in the page.
    408                         Control oParent = this.Parent;
    409                         while ( oParent != null )
    410                         {
    411                                 foreach ( object control in oParent.Controls )
    412                                 {
    413                                         // Match by type name.
    414                                         if ( control.GetType().FullName == "System.Web.UI.ScriptManager" )
    415                                         {
    416                                                 oScriptManager = control;
    417                                                 break;
    418                                         }
    419                                 }
    420 
    421                                 if ( oScriptManager != null )
    422                                         break;
    423 
    424                                 oParent = oParent.Parent;
    425                         }
    426 
    427428                        // If the ScriptManager control is available.
    428429                        if ( oScriptManager != null )
    429430                        {
    430                                 try
     431                                // Use reflection to check the SupportsPartialRendering
     432                                // property value.
     433                                bool bSupportsPartialRendering = ((bool)(supportsPartialRenderingProperty.GetValue( oScriptManager, null )));
     434
     435                                if ( bSupportsPartialRendering )
    431436                                {
    432                                         // Use reflection to check the SupportsPartialRendering
    433                                         // property value.
    434                                         bool bSupportsPartialRendering = ((bool)(oScriptManager.GetType().GetProperty( "SupportsPartialRendering" ).GetValue( oScriptManager, null )));
     437                                        string sScript = String.Format( onSubmitScriptTemplate, this.ClientID );
     438
     439                                        // Call the RegisterOnSubmitStatement method through
     440                                        // reflection.
     441                                        registerOnSubmitStatementMethod.Invoke( oScriptManager, new object[] {
     442                                                this,
     443                                                this.GetType(),
     444                                                "FCKeditorAjaxOnSubmit_" + this.ClientID,
     445                                                sScript } );
    435446
    436                                         if ( bSupportsPartialRendering )
    437                                         {
    438                                                 string sScript = "(function()\n{\n" +
    439                                                         "\tvar editor = FCKeditorAPI.GetInstance('" + this.ClientID + "');\n" +
    440                                                         "\tif (editor)\n" +
    441                                                         "\t\teditor.UpdateLinkedField();\n" +
    442                                                         "})();\n";
    443 
    444                                                 // Call the RegisterOnSubmitStatement method through
    445                                                 // reflection.
    446                                                 oScriptManager.GetType().GetMethod( "RegisterOnSubmitStatement", new Type[] { typeof( Control ), typeof( Type ), typeof( String ), typeof( String ) } ).Invoke( oScriptManager, new object[] {
    447                                                         this,
    448                                                         this.GetType(),
    449                                                         "FCKeditorAjaxOnSubmit_" + this.ClientID,
    450                                                         sScript } );
    451 
    452                                                 // Tell the editor that we are handling the submit.
    453                                                 this.Config[ "PreventSubmitHandler" ] = "true";
    454                                         }
     447                                        // Tell the editor that we are handling the submit.
     448                                        this.Config[ "PreventSubmitHandler" ] = "true";
    455449                                }
    456                                 catch { }
    457450                        }
    458451                }
    459452
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy