Ticket #7283: 7283_3.patch

File 7283_3.patch, 8.7 KB (added by Wiktor Walc, 13 years ago)
  • _dev/msajax.js

     
    44*/
    55
    66// The following script is used in CKEditorControl:OnPreRender
    7 var CKEditor_Controls = [];
     7var CKEditor_Controls = [],
     8        CKEditor_Init = [];
    89
    910function CKEditor_TextBoxEncode(cID, inUpdatePanel) {
    1011        if (typeof CKEDITOR == 'undefined' || typeof CKEDITOR.instances[cID] == 'undefined') {
     
    2526        var onload = function()
    2627        {
    2728                var ids = CKEditor_Controls,
     29                        initFunctions = CKEditor_Init,
    2830                        oldPageLoad = window.pageLoad;
    2931
    30                 var fixValues = function () {
    31                         for (i = ids.length; i--;) {
     32                var loadEditors = function() {
     33                        for (var i = ids.length; i--;) {
    3234                                var e = document.getElementById(ids[i]);
    33                                 e.value = e.value.replace(/&lt;/g, '<').replace(/&gt;/g, '>');
     35                                if (e && e.value && (e.value.indexOf('<') ==-1 || e.value.indexOf('>') ==-1)) {
     36                                        e.value = e.value.replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&amp;/g, '&');
     37                                }
    3438                        }
     39                        if (typeof CKEDITOR != 'undefined') {
     40                                for (var i = 0; i < initFunctions.length; i++) {
     41                                        initFunctions[i].call(this);
     42                                }
     43                        }
    3544                };
    3645
    3746                window.pageLoad = function(sender, args) {
    3847                        if (args.get_isPartialLoad()) {
    39                                 fixValues();
     48                                setTimeout(loadEditors, 0);
    4049                        }
    41                         if (oldPageLoad && typeof oldPageLoad == 'function')
    42                         oldPageLoad.call(this, sender, args);
     50                        if (oldPageLoad && typeof oldPageLoad == 'function') {
     51                                oldPageLoad.call(this, sender, args);
     52                        }
    4353                };
    4454
    45                 fixValues();
     55                setTimeout(loadEditors, 0);
    4656        };
    4757
    4858        if ( window.addEventListener )
  • CKEditor.NET/CKEditorControl.cs

     
    2121        [ToolboxData("<{0}:CKEditorControl runat=server></{0}:CKEditorControl>")]
    2222        [ParseChildren(false)]
    2323        [Designer("CKEditor.NET.CKEditorControlDesigner")]
    24         public class CKEditorControl : TextBox
     24        public class CKEditorControl : TextBox, IPostBackDataHandler
    2525        {
    2626                #region Changed TextBox Property
    2727
     
    3232                {
    3333                        get
    3434                        {
    35                                 if (!string.IsNullOrEmpty(base.Text))
    36                                         base.Text = base.Text.Replace("&lt;", "<").Replace("&gt;", ">").Replace("&amp;", "&");
    3735                                return base.Text;
    3836                        }
    3937                        set
    4038                        {
    41                                 if (!string.IsNullOrEmpty(value))
    42                                         value = value.Replace("&lt;", "<").Replace("&gt;", ">").Replace("&amp;", "&");
    4339                                base.Text = value;
    4440                        }
    4541                }
     
    999995                {
    1000996                        this.RegisterStartupScript(this.GetType(), "CKEDITOR_BASEPATH", string.Format("window.CKEDITOR_BASEPATH = '{0}/';\n", (this.CKEditorJSFile.StartsWith("~") ? this.ResolveUrl(this.BasePath) : this.BasePath)), true);
    1001997                        this.RegisterStartupScript(this.GetType(), "ckeditor", "<script src=\"" + (this.CKEditorJSFile.StartsWith("~") ? this.ResolveUrl(this.CKEditorJSFile) : this.CKEditorJSFile) + timestamp + "\" type=\"text/javascript\"></script>", false);
    1002                         if (HasMsAjax)
    1003                         {
    1004                                 string scriptInit = string.Empty;
     998                        string scriptInit = string.Empty;
    1005999
    1006                                 // Sys.Application.add_load does not work on browsers != IE
    1007                                 // http://msdn.microsoft.com/en-us/library/bb386417.aspx
    1008                                 // Check _dev/msajax.js for an uncompressed version (available in CKEditor.Net downloaded from SVN).
    1009                                 scriptInit += @"var CKEditor_Controls=[];function CKEditor_TextBoxEncode(c,d){if(typeof CKEDITOR=='undefined'||typeof CKEDITOR.instances[c]=='undefined'){var e=document.getElementById(c);e.value=e.value.replace(/</g,'&lt;').replace(/>/g,'&gt;');}else{var f=CKEDITOR.instances[c];if(d)f.destroy();else f.updateElement();}};(function(){var c=function(){var d=CKEditor_Controls,e=window.pageLoad,f=function(){for(i=d.length;i--;){var g=document.getElementById(d[i]);g.value=g.value.replace(/&lt;/g,'<').replace(/&gt;/g,'>');}};window.pageLoad=function(g,h){if(h.get_isPartialLoad())f();if(e&&typeof e=='function')e.call(this,g,h);};f();};if(window.addEventListener)window.addEventListener('load',c,false);else if(window.attachEvent)window.attachEvent('onload',c);})();
     1000                        // Sys.Application.add_load does not work on browsers != IE
     1001                        // http://msdn.microsoft.com/en-us/library/bb386417.aspx
     1002                        // Check _dev/msajax.js for an uncompressed version (available in CKEditor.Net downloaded from SVN).
     1003                        scriptInit += @"var CKEditor_Controls=[],CKEditor_Init=[];function CKEditor_TextBoxEncode(d,e){if(typeof CKEDITOR=='undefined'||typeof CKEDITOR.instances[d]=='undefined'){var f=document.getElementById(d);f.value=f.value.replace(/</g,'&lt;').replace(/>/g,'&gt;');}else{var g=CKEDITOR.instances[d];if(e)g.destroy();else g.updateElement();}};(function(){var d=function(){var e=CKEditor_Controls,f=CKEditor_Init,g=window.pageLoad,h=function(){for(var i=e.length;i--;){var j=document.getElementById(e[i]);if(j&&j.value&&(j.value.indexOf('<')==-1||j.value.indexOf('>')==-1))j.value=j.value.replace(/&lt;/g,'<').replace(/&gt;/g,'>').replace(/&amp;/g,'&');}if(typeof CKEDITOR!='undefined')for(var i=0;i<f.length;i++)f[i].call(this);};window.pageLoad=function(i,j){if(j.get_isPartialLoad())setTimeout(h,0);if(g&&typeof g=='function')g.call(this,i,j);};setTimeout(h,0);};if(window.addEventListener)window.addEventListener('load',d,false);else if(window.attachEvent)window.attachEvent('onload',d);})();
    10101004";
    1011 
    1012                                 this.RegisterStartupScript(this.GetType(), "CKEditorForNet", scriptInit, true);
    1013                                 this.RegisterStartupScript(this.GetType(), this.ClientID + @"_addControl", string.Format(@"CKEditor_Controls.push('{0}');
     1005                        this.RegisterStartupScript(this.GetType(), "CKEditorForNet", scriptInit, true);
     1006                        this.RegisterStartupScript(this.GetType(), this.ClientID + @"_addControl", string.Format(@"CKEditor_Controls.push('{0}');
    10141007", this.ClientID), true);
    1015                         }
    10161008                        string script = string.Empty;
    10171009                        if (this.config.CKEditorEventHandler != null)
    10181010                                foreach (object[] item in this.config.CKEditorEventHandler)
    10191011                                {
    1020                                         script += string.Format(@"if(typeof CKEDITOR != 'undefined') CKEDITOR.on('{0}',{1});
     1012                                        script += string.Format(@"CKEditor_Init.push(function(){{CKEDITOR.on('{0}',{1});}});
    10211013", item[0], item[1]);
    10221014                                }
    1023                         script += string.Format(@"if(typeof CKEDITOR != 'undefined') CKEDITOR.replace('{0}',{1});
     1015                        if (this.config.protectedSource != null && this.config.protectedSource.Length > 0)
     1016                        {
     1017                                string proSour = string.Empty;
     1018                                foreach (string item in this.config.protectedSource)
     1019                                        proSour += @"
     1020ckeditor.config.protectedSource.push( " + item + " );";
     1021                                script += string.Format(@"CKEditor_Init.push(function(){{if(typeof CKEDITOR.instances['{0}']!='undefined') return;var ckeditor = CKEDITOR.replace('{0}',{1}); {2}}});
     1022", this.ClientID, prepareJSON(), proSour);
     1023                        }
     1024                        else
     1025                                script += string.Format(@"CKEditor_Init.push(function(){{if(typeof CKEDITOR.instances['{0}']!='undefined') return;CKEDITOR.replace('{0}',{1});}});
    10241026", this.ClientID, prepareJSON());
    10251027
    1026                         if (HasMsAjax)
    1027                         {
    1028                                 bool isInUpdatePanel = false;
    1029                                 Control con = this.Parent;
    1030                                 if (updatePanel != null)
    1031                                         while (con != null)
     1028                        bool isInUpdatePanel = false;
     1029                        Control con = this.Parent;
     1030                        if (updatePanel != null)
     1031                                while (con != null)
     1032                                {
     1033                                        if (con.GetType() == updatePanel)
    10321034                                        {
    1033                                                 if (con.GetType() == updatePanel)
    1034                                                 {
    1035                                                         isInUpdatePanel = true;
    1036                                                         break;
    1037                                                 }
    1038                                                 con = con.Parent;
     1035                                                isInUpdatePanel = true;
     1036                                                break;
    10391037                                        }
    1040                                 this.RegisterOnSubmitStatement(this.GetType(), "aspintegrator_Postback" + this.ClientID, string.Format("CKEditor_TextBoxEncode('{0}', {1}); ", this.ClientID, isInUpdatePanel ? 1 : 0));
    1041                         }
     1038                                        con = con.Parent;
     1039                                }
     1040                        this.RegisterOnSubmitStatement(this.GetType(), "aspintegrator_Postback" + this.ClientID, string.Format("CKEditor_TextBoxEncode('{0}', {1}); ", this.ClientID, isInUpdatePanel ? 1 : 0));
    10421041                        this.RegisterStartupScript(this.GetType(), "aspintegratorInitial_" + this.ClientID, script, true);
    10431042                }
    10441043
     
    10521051                }
    10531052
    10541053                #endregion
     1054
     1055                #region IPostBackDataHandler
     1056
     1057                bool IPostBackDataHandler.LoadPostData(string postDataKey, NameValueCollection postCollection)
     1058                {
     1059                        if (this.config.htmlEncodeOutput)
     1060                        {
     1061                                string postedValue = postCollection[postDataKey];
     1062                                postedValue = postedValue.Replace("&lt;", "<").Replace("&gt;", ">").Replace("&amp;", "&");
     1063                                if (this.Text != postedValue)
     1064                                {
     1065                                        this.Text = postedValue;
     1066                                        return true;
     1067                                }
     1068                        }
     1069                        return false;
     1070                }
     1071
     1072                void IPostBackDataHandler.RaisePostDataChangedEvent() { }
     1073
     1074                #endregion
    10551075        }
    10561076
    10571077        public class CKEditorControlDesigner : System.Web.UI.Design.ControlDesigner
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy