You can subscribe to this list here.
2005 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(204) |
Dec
(147) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2006 |
Jan
(52) |
Feb
(33) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(1) |
Nov
|
Dec
|
From: Dion O. <dol...@us...> - 2006-01-23 08:33:15
|
Update of /cvsroot/magicajax/magicajax/Core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26088/magicajax/Core Modified Files: MagicAjaxModule.cs Log Message: - Fixed problem with EnableEventValidation on normal postback (.NET 2.0) - Added some comments Index: MagicAjaxModule.cs =================================================================== RCS file: /cvsroot/magicajax/magicajax/Core/MagicAjaxModule.cs,v retrieving revision 1.60 retrieving revision 1.61 diff -C2 -d -r1.60 -r1.61 *** MagicAjaxModule.cs 23 Jan 2006 01:28:41 -0000 1.60 --- MagicAjaxModule.cs 23 Jan 2006 08:33:05 -0000 1.61 *************** *** 459,476 **** } - _magicAjaxContext.IsAjaxCall = (_request.Form["__AJAXCALL"] != null); - - Page currentPage = HttpContext.Current.Handler as Page; - - // On Page-init, we're going to replace the regular HTMLForm control with an AjaxHMTLForm - //if (currentPage != null) - // currentPage.Init += new EventHandler(currentPage_Init); - // Continue only if it is a postback or an AjaxCall if ("GET" == _request.HttpMethod) return; #if NET_2_0 ! if (currentPage != null && _magicAjaxContext.IsAjaxCall) { // For ASP.NET 2.0, disable event validation on the page --- 459,470 ---- } // Continue only if it is a postback or an AjaxCall if ("GET" == _request.HttpMethod) return; + Page currentPage = HttpContext.Current.Handler as Page; + #if NET_2_0 ! if (currentPage != null) { // For ASP.NET 2.0, disable event validation on the page *************** *** 480,483 **** --- 474,478 ---- #endif + _magicAjaxContext.IsAjaxCall = (_request.Form["__AJAXCALL"] != null); string configState = _request.Form["__MAGICAJAX_CONFIG"]; if (configState != null) *************** *** 611,668 **** } - - // /// <summary> - // /// On Page init, we're going to we're going to replace - // /// the regular HTMLForm control with our own AjaxHMTLForm. - // /// This way we can implement a custom rendering of the form, - // /// which reflects added scripts and hidden fields on Ajax callbacks - // /// </summary> - // /// <param name="sender">The current page</param> - // /// <param name="e"></param> - // void currentPage_Init(object sender, EventArgs e) - // { - // Page thePage = (Page)sender; - // if (thePage != null) - // { - // HtmlForm oldFrm = (HtmlForm)Util.GetPrivateField(thePage, typeof(Page), "_form"); - - // //thePage.Form.SetRenderMethodDelegate - - // AjaxHtmlForm newFrm = new AjaxHtmlForm(); - - // // Copy all properties over - // Util.ForceShallowCopyOnObject(newFrm, oldFrm); - - // // when adding a control - the framework will try to disconnect it from its parent - // // so we better make sure it it has no parent. - // Util.SetPrivateField(newFrm, typeof(Control), "_parent", null); - // Util.SetPrivateField(thePage, typeof(Page), "_form", newFrm); - - // // Now replace the current Form control by our own - // Control hostingControl = (Control)thePage; - //#if NET_2_0 - // if (thePage.Master != null) - // { - // MasterPage master = thePage.Master; - // while (master.Master != null) - // master = master.Master; - - // hostingControl = (Control)master; - // } - //#else - // object readOnlyErrorMsg = Util.GetPrivateField(hostingControl.Controls, typeof(ControlCollection), "_readOnlyErrorMsg"); - // Util.SetPrivateField(hostingControl.Controls, typeof(ControlCollection), "_readOnlyErrorMsg", null); - //#endif - - // int formIndex = hostingControl.Controls.IndexOf(oldFrm); - // hostingControl.Controls.RemoveAt(formIndex); - // hostingControl.Controls.AddAt(formIndex, newFrm); - - //#if !NET_2_0 - // Util.SetPrivateField(hostingControl.Controls, typeof(ControlCollection), "_readOnlyErrorMsg", readOnlyErrorMsg); - //#endif - // } - // } - /// <summary> /// Handles the EndRequest event of the Application --- 606,609 ---- |
From: Dion O. <dol...@us...> - 2006-01-23 01:28:52
|
Update of /cvsroot/magicajax/magicajax/Core/script In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27153/magicajax/Core/script Modified Files: AjaxCallObject.js Log Message: Fix for .NET 1,1 Stylesheet updates on callback Index: AjaxCallObject.js =================================================================== RCS file: /cvsroot/magicajax/magicajax/Core/script/AjaxCallObject.js,v retrieving revision 1.47 retrieving revision 1.48 diff -C2 -d -r1.47 -r1.48 *** AjaxCallObject.js 20 Jan 2006 01:35:56 -0000 1.47 --- AjaxCallObject.js 23 Jan 2006 01:28:41 -0000 1.48 *************** *** 406,414 **** if (target != null && target.type == "image" && target.name && target.name != '') { ! //image callbacks only supported for IE (for now). For other browsers force a postback. if (window.event) theData += target.name + ".x=" + window.event.offsetX + "&" + target.name + ".y=" + (window.event.offsetY - target.offsetTop) + "&"; - else - return false; } --- 406,412 ---- if (target != null && target.type == "image" && target.name && target.name != '') { ! //image callbacks only supported for IE (for now). For other browsers, no .x and .y is sent yet. if (window.event) theData += target.name + ".x=" + window.event.offsetX + "&" + target.name + ".y=" + (window.event.offsetY - target.offsetTop) + "&"; } *************** *** 786,789 **** --- 784,833 ---- } + AjaxCallObject.prototype.AddHeaderElement = function(tagName, innerText, attributes) + { + switch (tagName) + { + case "link": + var link = document.getElementsByTagName("head")[0].appendChild(document.createElement("link")); + for (i=0; i < attributes.length; i+=2) + link.setAttribute(attributes[i], attributes[i+1]); + break; + case "title": + document.title = innerText; + break; + case "style": + if (document.styleSheets) + { + if (document.styleSheets.length == 0) + { + //no stylesheets yet, so create empty one + var head = document.getElementsByTagName("head")[0]; + var style = document.createElement("style"); + style.type = "text/css"; + head.appendChild(style); + } + + //add style rule to last stylesheet (forces proper cascading) + var lastStyle = document.styleSheets[document.styleSheets.length - 1]; + if (typeof lastStyle.insertRule == "function") + { + //Mozilla + lastStyle.insertRule(innerText, lastStyle.cssRules.length); + } + else if (typeof lastStyle.addRule == "object") + { + //IE + var splitRules = innerText.split('}'); + for (i=0; i<splitRules.length-1; i++) + { + var splitNameValue = splitRules[i].split('{'); + lastStyle.addRule(splitNameValue[0], splitNameValue[1]); + } + } + } + break; + } + } + AjaxCallObject.prototype.SetFieldIfEmpty = function(fieldName, fieldValue) { |
From: Dion O. <dol...@us...> - 2006-01-23 01:28:52
|
Update of /cvsroot/magicajax/magicajax/Core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27153/magicajax/Core Modified Files: AjaxCallHelper.cs MagicAjaxModule.cs Util.cs Log Message: Fix for .NET 1,1 Stylesheet updates on callback Index: AjaxCallHelper.cs =================================================================== RCS file: /cvsroot/magicajax/magicajax/Core/AjaxCallHelper.cs,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** AjaxCallHelper.cs 20 Jan 2006 01:35:56 -0000 1.20 --- AjaxCallHelper.cs 23 Jan 2006 01:28:41 -0000 1.21 *************** *** 307,310 **** --- 307,324 ---- } + public static void WriteAddHeaderElementScript(string tagName, string innerText, NameValueCollection attributes) + { + StringBuilder sbuilder = new StringBuilder("new Array("); + for (int i = 0; i < attributes.Count; i++) + { + if (i > 0) + sbuilder.Append(","); + sbuilder.AppendFormat("\"{0}\",\"{1}\"", attributes.Keys[i], attributes[i]); + } + sbuilder.Append(")"); + + Write(String.Format("AJAXCbo.AddHeaderElement(\"{0}\",{1},{2});\r\n", tagName, EncodeString(innerText), sbuilder.ToString())); + } + /// <summary> /// Produces the javascript that will add a script element to the page. Index: Util.cs =================================================================== RCS file: /cvsroot/magicajax/magicajax/Core/Util.cs,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** Util.cs 20 Jan 2006 01:35:56 -0000 1.24 --- Util.cs 23 Jan 2006 01:28:41 -0000 1.25 *************** *** 37,40 **** --- 37,41 ---- public const string ScriptPattern = "<script.[^>]*>"; public const string FormElementPattern = @"<(?<tag>input|textarea|select)\s+(?<attribute>(?<attrname>[-\w]+)=((""|')(?<attrvalue>.*?)(""|')\s*|(?<attrvalue>[-\w]+)\s*))*.*?(/>|>(?<inner>.*?)</\k'tag'>)"; + public const string HeadElementPattern = @"<(?<tag>title|style|link)\s*(?<attribute>(?<attrname>[-\w]+)=((""|')(?<attrvalue>.*?)(""|')\s*|(?<attrvalue>[-\w]+)\s*))*.*?(/>|>[\r\n\t]*(?<inner>.*?)[\r\n]*</\k'tag'>)"; #region Global Regular Expressions *************** *** 44,48 **** public static Regex FormElementOptionSelectedRegEx = new Regex(@"<option.*?(?<selected>selected=(""|'|)selected(""|'|)(\s+|(?=>))).*?>", _options); public static Regex ScriptPatternRegEx = new Regex(Util.ScriptPattern, RegexOptions.IgnoreCase); ! public static Regex ScriptTagsRegEx = new Regex("<script\\s((?<attrname>[-\\w]+)=\"(?<attrvalue>.*?)\"\\s?)*\\s*>(?<script>.*?)</script>", _options); #endregion --- 45,50 ---- public static Regex FormElementOptionSelectedRegEx = new Regex(@"<option.*?(?<selected>selected=(""|'|)selected(""|'|)(\s+|(?=>))).*?>", _options); public static Regex ScriptPatternRegEx = new Regex(Util.ScriptPattern, RegexOptions.IgnoreCase); ! public static Regex ScriptTagsRegEx = new Regex("<script\\s((?<attrname>[-\\w]+)=[\"'](?<attrvalue>.*?)[\"']\\s?)*\\s*>(?<script>.*?)</script>", _options); ! public static Regex HeaderTagsRegEx = new Regex(HeadElementPattern, _options); #endregion *************** *** 270,275 **** /// Copies all fields (private and public) from the source object to /// the destination object thereby performing shallow copy - /// Unlike shallow copy however, the objects do not need to be of the same type - /// and destination can be a decendant of source in the class heirarchy /// </summary> /// <param name="destination">object to copy fields on</param> --- 272,275 ---- Index: MagicAjaxModule.cs =================================================================== RCS file: /cvsroot/magicajax/magicajax/Core/MagicAjaxModule.cs,v retrieving revision 1.59 retrieving revision 1.60 diff -C2 -d -r1.59 -r1.60 *** MagicAjaxModule.cs 20 Jan 2006 01:35:56 -0000 1.59 --- MagicAjaxModule.cs 23 Jan 2006 01:28:41 -0000 1.60 *************** *** 463,472 **** Page currentPage = HttpContext.Current.Handler as Page; - #if NET_2_0 // On Page-init, we're going to replace the regular HTMLForm control with an AjaxHMTLForm ! // For now, only supported for .NET 2.0 ! if (currentPage != null) ! currentPage.Init += new EventHandler(currentPage_Init); ! #endif // Continue only if it is a postback or an AjaxCall --- 463,469 ---- Page currentPage = HttpContext.Current.Handler as Page; // On Page-init, we're going to replace the regular HTMLForm control with an AjaxHMTLForm ! //if (currentPage != null) ! // currentPage.Init += new EventHandler(currentPage_Init); // Continue only if it is a postback or an AjaxCall *************** *** 482,485 **** --- 479,483 ---- } #endif + string configState = _request.Form["__MAGICAJAX_CONFIG"]; if (configState != null) *************** *** 614,658 **** ! /// <summary> ! /// On Page init, we're going to we're going to replace ! /// the regular HTMLForm control with our own AjaxHMTLForm. ! /// This way we can implement a custom rendering of the form, ! /// which reflects added scripts and hidden fields on Ajax callbacks ! /// </summary> ! /// <param name="sender">The current page</param> ! /// <param name="e"></param> ! void currentPage_Init(object sender, EventArgs e) ! { ! Page thePage = (Page)sender; ! if (thePage != null) ! { ! HtmlForm oldFrm = (HtmlForm)Util.GetPrivateField(thePage, typeof(Page), "_form"); ! AjaxHtmlForm newFrm = new AjaxHtmlForm(); ! // Copy all properties over ! Util.ForceShallowCopyOnObject(newFrm, oldFrm); ! // when adding a control - the framework will try to disconnect it from its parent ! // so we better make sure it it has no parent. ! Util.SetPrivateField(newFrm, typeof(Control), "_parent", null); ! Util.SetPrivateField(thePage, typeof(Page), "_form", newFrm); ! // Now replace the current Form control by our own ! Control hostingControl = (Control)thePage; ! #if NET_2_0 ! if (thePage.Master != null) ! { ! MasterPage master = thePage.Master; ! while (master.Master != null) ! master = master.Master; ! hostingControl = (Control)master; ! } ! #endif ! int formIndex = hostingControl.Controls.IndexOf(oldFrm); ! hostingControl.Controls.RemoveAt(formIndex); ! hostingControl.Controls.AddAt(formIndex, newFrm); ! } ! } /// <summary> --- 612,667 ---- ! // /// <summary> ! // /// On Page init, we're going to we're going to replace ! // /// the regular HTMLForm control with our own AjaxHMTLForm. ! // /// This way we can implement a custom rendering of the form, ! // /// which reflects added scripts and hidden fields on Ajax callbacks ! // /// </summary> ! // /// <param name="sender">The current page</param> ! // /// <param name="e"></param> ! // void currentPage_Init(object sender, EventArgs e) ! // { ! // Page thePage = (Page)sender; ! // if (thePage != null) ! // { ! // HtmlForm oldFrm = (HtmlForm)Util.GetPrivateField(thePage, typeof(Page), "_form"); ! // //thePage.Form.SetRenderMethodDelegate ! // AjaxHtmlForm newFrm = new AjaxHtmlForm(); ! ! // // Copy all properties over ! // Util.ForceShallowCopyOnObject(newFrm, oldFrm); ! ! // // when adding a control - the framework will try to disconnect it from its parent ! // // so we better make sure it it has no parent. ! // Util.SetPrivateField(newFrm, typeof(Control), "_parent", null); ! // Util.SetPrivateField(thePage, typeof(Page), "_form", newFrm); ! // // Now replace the current Form control by our own ! // Control hostingControl = (Control)thePage; ! //#if NET_2_0 ! // if (thePage.Master != null) ! // { ! // MasterPage master = thePage.Master; ! // while (master.Master != null) ! // master = master.Master; ! // hostingControl = (Control)master; ! // } ! //#else ! // object readOnlyErrorMsg = Util.GetPrivateField(hostingControl.Controls, typeof(ControlCollection), "_readOnlyErrorMsg"); ! // Util.SetPrivateField(hostingControl.Controls, typeof(ControlCollection), "_readOnlyErrorMsg", null); ! //#endif ! ! // int formIndex = hostingControl.Controls.IndexOf(oldFrm); ! // hostingControl.Controls.RemoveAt(formIndex); ! // hostingControl.Controls.AddAt(formIndex, newFrm); ! ! //#if !NET_2_0 ! // Util.SetPrivateField(hostingControl.Controls, typeof(ControlCollection), "_readOnlyErrorMsg", readOnlyErrorMsg); ! //#endif ! // } ! // } /// <summary> |
From: Dion O. <dol...@us...> - 2006-01-23 01:28:52
|
Update of /cvsroot/magicajax/magicajax/Core/UI/Controls In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27153/magicajax/Core/UI/Controls Modified Files: AjaxHtmlForm.cs AjaxPanel.cs Log Message: Fix for .NET 1,1 Stylesheet updates on callback Index: AjaxHtmlForm.cs =================================================================== RCS file: /cvsroot/magicajax/magicajax/Core/UI/Controls/AjaxHtmlForm.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** AjaxHtmlForm.cs 20 Jan 2006 01:35:56 -0000 1.1 --- AjaxHtmlForm.cs 23 Jan 2006 01:28:41 -0000 1.2 *************** *** 1,216 **** ! using System; ! using System.Data; ! using System.Configuration; ! using System.Web; ! using System.Web.Security; ! using System.Web.UI; ! using System.Web.UI.WebControls; ! using System.Web.UI.WebControls.WebParts; ! using System.Web.UI.HtmlControls; ! using System.Collections; ! using System.Collections.Specialized; ! using System.Text.RegularExpressions; ! using System.Text; ! namespace MagicAjax.UI.Controls ! { ! /// <summary> ! /// TODO. As you can see, this code is not yet finished ! /// </summary> ! public class AjaxHtmlForm : System.Web.UI.HtmlControls.HtmlForm ! { ! public AjaxHtmlForm() { } ! private ArrayList _previousScriptFPs = new ArrayList(); ! private ArrayList _currentScriptFPs = new ArrayList(); ! protected override void RenderChildren(HtmlTextWriter writer) ! { ! if (MagicAjaxContext.Current.IsAjaxCall) ! { ! // Get the fingerprints of the scripts sent previous time ! if (Page.Request.Form["__MAGICAJAX_SCRIPT_FINGERPRINTS"] != null) ! { ! _previousScriptFPs.AddRange(Page.Request.Form["__MAGICAJAX_SCRIPT_FINGERPRINTS"].Split(';')); ! } ! ReflectHiddenFields(); ! //ReflectWebFormScript(); ?? ! ReflectClientScriptBlocks(); ! } ! else ! { ! SetAllScriptFingerPrints(); ! ! Page.ClientScript.RegisterHiddenField("__MAGICAJAX_SCRIPT_FINGERPRINTS", ! string.Join(";", (string[])_currentScriptFPs.ToArray(typeof(string)))); ! } ! base.RenderChildren(writer); ! ! if (MagicAjaxContext.Current.IsAjaxCall) ! { ! ReflectArrayDeclares(); ! //ReflectExpandoAttribute(); !! ! ReflectClientStartupScripts(); ! //set __MAGICAJAX_SCRIPT_FINGERPRINTS field ! string newFingerprints = string.Join(";", (string[])_currentScriptFPs.ToArray(typeof(string))); ! ! if (Page.Request.Form["__MAGICAJAX_SCRIPT_FINGERPRINTS"] != newFingerprints) ! { ! AjaxCallHelper.WriteSetFieldScript("__MAGICAJAX_SCRIPT_FINGERPRINTS", ! string.Join(";", (string[])_currentScriptFPs.ToArray(typeof(string)))); ! } ! } ! } ! ! private void ReflectClientScriptBlocks() ! { ! IDictionary regScripts = (IDictionary)(Util.GetPrivateField(Page.ClientScript, typeof(ClientScriptManager), "_registeredClientScriptBlocks")); ! SetScriptDictionaryFingerPrints(regScripts, true); ! //TODO: _registeredOnSubmitStatements !! ! } ! private void ReflectClientStartupScripts() ! { ! IDictionary regScripts = (IDictionary)(Util.GetPrivateField(Page.ClientScript, typeof(ClientScriptManager), "_registeredClientStartupScripts")); ! SetScriptDictionaryFingerPrints(regScripts, true); ! } ! ! private void ReflectArrayDeclares() ! { ! IDictionary regArrays = (IDictionary)(Util.GetPrivateField(Page.ClientScript, typeof(ClientScriptManager), "_registeredArrayDeclares")); ! SetArrayDictionaryFingerPrints(regArrays, true); ! } ! ! private void SetAllScriptFingerPrints() ! { ! IDictionary regScripts; ! ! //ReflectWebFormScript(); ?? ! regScripts = (IDictionary)(Util.GetPrivateField(Page.ClientScript, typeof(ClientScriptManager), "_registeredClientScriptBlocks")); ! SetScriptDictionaryFingerPrints(regScripts, false); ! IDictionary regArrays = (IDictionary)(Util.GetPrivateField(Page.ClientScript, typeof(ClientScriptManager), "_registeredArrayDeclares")); ! SetArrayDictionaryFingerPrints(regArrays, false); ! ! //ReflectExpandoAttribute(); !! ! regScripts = (IDictionary)(Util.GetPrivateField(Page.ClientScript, typeof(ClientScriptManager), "_registeredClientStartupScripts")); ! SetScriptDictionaryFingerPrints(regScripts, false); ! } ! private void SetArrayDictionaryFingerPrints(IDictionary regArrays, bool reflectScripts) ! { ! if (regArrays != null) ! { ! foreach (DictionaryEntry fld in regArrays) ! { ! StringBuilder sb = new StringBuilder(); ! string key = (string)fld.Key; ! ArrayList values = (ArrayList)fld.Value; ! sb.Append("var "); ! sb.Append(key); ! sb.Append(" = new Array("); ! for (int i = 0; i<values.Count; i++) ! { ! if (i >0) ! sb.Append(", "); ! sb.Append((string)values[i]); ! } ! sb.Append(");"); ! string script = sb.ToString(); ! string scriptFP = Util.GetFingerprint(script); ! _currentScriptFPs.Add(scriptFP); ! ! if (reflectScripts && !_previousScriptFPs.Contains(scriptFP)) ! { ! NameValueCollection scriptAttributes = new NameValueCollection(); ! scriptAttributes.Add("type", "text/javascript"); ! AjaxCallHelper.WriteAddScriptElementScript(script, scriptAttributes); ! } ! } ! } ! } ! private void SetScriptDictionaryFingerPrints(IDictionary regScripts, bool reflectScripts) ! { ! if (regScripts != null) ! { ! foreach (DictionaryEntry fld in regScripts) ! { ! int keyHash = fld.Key.GetHashCode(); ! string script = (string)fld.Value; ! string scriptFP = Util.GetFingerprint(string.Format("{0}:{1}", keyHash, script)); ! _currentScriptFPs.Add(scriptFP); ! if (reflectScripts && !_previousScriptFPs.Contains(scriptFP)) ! { ! if (!script.StartsWith("\r\n<script")) ! { ! NameValueCollection scriptAttributes = new NameValueCollection(); ! scriptAttributes.Add("type", "text/javascript"); ! AjaxCallHelper.WriteAddScriptElementScript(script, scriptAttributes); ! } ! else ! { ! Match match = Util.ScriptTagsRegEx.Match(script); ! if (match.Success) ! { ! CaptureCollection attrnamesOption = match.Groups["attrname"].Captures; ! CaptureCollection attrvaluesOption = match.Groups["attrvalue"].Captures; ! NameValueCollection scriptAttributes = new NameValueCollection(); ! for (int j = 0; j < attrnamesOption.Count; j++) ! { ! scriptAttributes.Add(attrnamesOption[j].Value, attrvaluesOption[j].Value); ! } ! string scriptText = match.Groups["script"].Value; ! AjaxCallHelper.WriteAddScriptElementScript(scriptText, scriptAttributes); ! } ! } ! } ! } ! } ! } ! /// <summary> ! /// Reflects hidden fields back to client ! /// </summary> ! /// <param name="page"></param> ! private void ReflectHiddenFields() ! { ! IDictionary regFields = (IDictionary)(Util.GetPrivateField(Page.ClientScript, typeof(ClientScriptManager), "_registeredHiddenFields")); ! // for 1.1: IDictionary regFields = (IDictionary)(Util.GetPrivateField(Page, typeof(Page), "_registeredHiddenFields")); ! if (regFields != null) ! { ! foreach (DictionaryEntry fld in regFields) ! { ! string key = (string)fld.Key; ! string value = (string)fld.Value; ! // For now, don't reflect system hidden fields (starting with "__"). ! // TODO: find out why __VIEWSTATE is never registered...? ! if (key != null && !key.StartsWith("__")) ! { ! if (Page.Request.Form[key] == null) ! AjaxCallHelper.WriteAddHiddenFieldScript(key, value); ! else ! AjaxCallHelper.WriteSetFieldScript(key, value); ! } ! } ! } ! } ! } ! } \ No newline at end of file --- 1,356 ---- ! //using System; ! //using System.Data; ! //using System.Configuration; ! //using System.Web; ! //using System.Web.Security; ! //using System.Web.UI; ! //using System.Web.UI.WebControls; ! //using System.Web.UI.HtmlControls; ! //using System.Collections; ! //using System.Collections.Specialized; ! //using System.Text.RegularExpressions; ! //using System.Text; ! //using System.Globalization; ! //namespace MagicAjax.UI.Controls ! //{ ! // /// <summary> ! // /// This special Ajax form is injected into the Page object on Init. ! // /// It handles reflecting scripts, stylesheet and hidden fields that ! // /// were added or changed on an Ajax callback. ! // /// </summary> ! // public class AjaxHtmlForm : System.Web.UI.HtmlControls.HtmlForm ! // { ! // public AjaxHtmlForm() {} ! // /// <summary> List of previous fingerprints of all script blocks </summary> ! // private ArrayList _previousScriptFPs = new ArrayList(); ! // /// <summary> List of current fingerprints of all script blocks </summary> ! // private ArrayList _currentScriptFPs = new ArrayList(); ! // protected override void RenderChildren(HtmlTextWriter writer) ! // { ! //#if NET_2_0 ! // // For ASP.NET 2.0, reflect the head-tag's stylesheet- or ! // // title-changes back to client ! // HandleHeader(MagicAjaxContext.Current.IsAjaxCall); ! //#endif ! // if (MagicAjaxContext.Current.IsAjaxCall) ! // { ! // // Get the fingerprints of the scripts sent previous time ! // if (Page.Request.Form["__MAGICAJAX_SCRIPT_FINGERPRINTS"] != null) ! // { ! // _previousScriptFPs.AddRange(Page.Request.Form["__MAGICAJAX_SCRIPT_FINGERPRINTS"].Split(';')); ! // } ! // HandleHiddenFields(); ! // HandleClientScriptBlocks(true); ! // HandleOnSubmitStatements(true); ! // } ! // else ! // { ! // // Not in Ajax call, so create fingerprints of all script blocks ! // HandleClientScriptBlocks(false); ! // HandleArrayDeclares(false); ! // HandleClientStartupScripts(false); ! // HandleOnSubmitStatements(false); ! // // Store scriptblock fingerprints in hidden field ! // Page.RegisterHiddenField("__MAGICAJAX_SCRIPT_FINGERPRINTS", ! // string.Join(";", (string[])_currentScriptFPs.ToArray(typeof(string)))); ! // } ! // // Original render method ! // base.RenderChildren(writer); ! // // Reflect added startup-scripts and arrays AFTER reflecting the controls HTML ! // if (MagicAjaxContext.Current.IsAjaxCall) ! // { ! // HandleArrayDeclares(true); ! // HandleClientStartupScripts(true); ! // // Store scriptblock fingerprints in hidden field ! // string allScriptFPs = string.Join(";", (string[])_currentScriptFPs.ToArray(typeof(string))); ! // if (Page.Request.Form["__MAGICAJAX_SCRIPT_FINGERPRINTS"] != allScriptFPs) ! // AjaxCallHelper.WriteSetFieldScript("__MAGICAJAX_SCRIPT_FINGERPRINTS", allScriptFPs); ! // } ! // } ! // /// <summary> ! // /// Reflects registered Hidden fields if added/changed on callback ! // /// </summary> ! // /// <param name="page"></param> ! // private void HandleHiddenFields() ! // { ! // IDictionary regFields = GetPageHiddenDictionary("_registeredHiddenFields"); ! // if (regFields != null) ! // { ! // foreach (DictionaryEntry fld in regFields) ! // { ! // string key = (string)fld.Key; ! // string value = (string)fld.Value; ! // // For now, don't reflect system hidden fields (starting with "__"). ! // // TODO: find out why __VIEWSTATE is never registered...? ! // if (key != null && !key.StartsWith("__") && value != Page.Request.Form[key]) ! // { ! // if (Page.Request.Form[key] == null) ! // AjaxCallHelper.WriteAddHiddenFieldScript(key, value); ! // else ! // AjaxCallHelper.WriteSetFieldScript(key, value); ! // } ! // } ! // } ! // } ! ! // /// <summary> ! // /// Handle registered ClientScriptBlocks to see if some where added/changed on callback/postback ! // /// </summary> ! // private void HandleClientScriptBlocks(bool reflectToClient) ! // { ! // IDictionary regScripts = GetPageHiddenDictionary("_registeredClientScriptBlocks"); ! // SetScriptDictionaryFingerPrints(regScripts, reflectToClient); ! // } ! ! // /// <summary> ! // /// Handle registered OnSubmitStatements to see if some where added/changed on callback/postback ! // /// </summary> ! // /// <param name="reflectToClient"></param> ! // private void HandleOnSubmitStatements(bool reflectToClient) ! // { ! // IDictionary regScripts = GetPageHiddenDictionary("_registeredOnSubmitStatements"); ! // if (regScripts != null) ! // { ! // ListDictionary onSubmitStatementItem = new ListDictionary(); ! // StringBuilder onSubmitStringBuilder = new StringBuilder(); ! // onSubmitStringBuilder.Append("\r\n<script type=\"text/javascript\">\r\n<!--\r\n"); ! // onSubmitStringBuilder.Append("function WebForm_OnSubmit() {\r\n"); ! ! // foreach (string value in regScripts.Values) ! // onSubmitStringBuilder.Append(value); ! ! // onSubmitStringBuilder.Append("\r\nreturn true;\r\n}"); ! // onSubmitStringBuilder.Append("// -->\r\n</script>\r\n"); ! ! // onSubmitStatementItem.Add("_registeredOnSubmitStatements", onSubmitStringBuilder.ToString()); ! ! // SetScriptDictionaryFingerPrints(onSubmitStatementItem, reflectToClient); ! // } ! // } ! ! // /// <summary> ! // /// Handle registered ClientStartupScripts to see if some where added/changed on callback/postback ! // /// </summary> ! // /// <param name="reflectToClient"></param> ! // private void HandleClientStartupScripts(bool reflectToClient) ! // { ! // IDictionary regScripts = GetPageHiddenDictionary("_registeredClientStartupScripts"); ! // SetScriptDictionaryFingerPrints(regScripts, reflectToClient); ! // } ! ! // /// <summary> ! // /// Handle declared client-Arrays to see if some where added/changed on callback/postback ! // /// </summary> ! // /// <param name="reflectToClient"></param> ! // private void HandleArrayDeclares(bool reflectToClient) ! // { ! // IDictionary regArrays = GetPageHiddenDictionary("_registeredArrayDeclares"); ! // SetArrayDictionaryFingerPrints(regArrays, reflectToClient); ! // } ! // //private void SetAllScriptFingerPrints() ! // //{ ! // // IDictionary regDictionary = GetPageHiddenDictionary("_registeredClientScriptBlocks"); ! // // SetScriptDictionaryFingerPrints(regDictionary, false); ! // // regDictionary = GetPageHiddenDictionary("_registeredArrayDeclares"); ! // // SetArrayDictionaryFingerPrints(regDictionary, false); ! ! // // regDictionary = GetPageHiddenDictionary("_registeredClientStartupScripts"); ! // // SetScriptDictionaryFingerPrints(regDictionary, false); ! // //} ! ! // /// <summary> ! // /// Sets fingerprints for declared Arrays. ! // /// When reflectToClient is set to true, reflects added/changed Array-declarations ! // /// back to the client. ! // /// </summary> ! // /// <param name="regArrays"></param> ! // /// <param name="reflectToClient"></param> ! // private void SetArrayDictionaryFingerPrints(IDictionary regArrays, bool reflectToClient) ! // { ! // if (regArrays != null) ! // { ! // foreach (DictionaryEntry fld in regArrays) ! // { ! // StringBuilder sb = new StringBuilder(); ! ! // string key = (string)fld.Key; ! // ArrayList values = (ArrayList)fld.Value; ! // sb.Append("var "); ! // sb.Append(key); ! // sb.Append(" = new Array("); ! // for (int i = 0; i<values.Count; i++) ! // { ! // if (i >0) ! // sb.Append(", "); ! // sb.Append((string)values[i]); ! // } ! // sb.Append(");"); ! // string script = sb.ToString(); ! // string scriptFP = Util.GetFingerprint(script); ! // _currentScriptFPs.Add(scriptFP); ! // if (reflectToClient && !_previousScriptFPs.Contains(scriptFP)) ! // { ! // NameValueCollection scriptAttributes = new NameValueCollection(); ! // scriptAttributes.Add("type", "text/javascript"); ! // AjaxCallHelper.WriteAddScriptElementScript(script, scriptAttributes); ! // } ! // } ! // } ! // } ! ! // /// <summary> ! // /// Sets fingerprints for registered Script blocks. ! // /// When reflectToClient is set to true, reflects added/changed scripts ! // /// back to the client. ! // /// </summary> ! // /// <param name="regScripts"></param> ! // /// <param name="reflectToClient"></param> ! // private void SetScriptDictionaryFingerPrints(IDictionary regScripts, bool reflectToClient) ! // { ! // if (regScripts != null) ! // { ! // foreach (DictionaryEntry fld in regScripts) ! // { ! // int keyHash = fld.Key.GetHashCode(); ! // string script = (string)fld.Value; ! // string scriptFP = Util.GetFingerprint(string.Format("{0}:{1}", keyHash, script)); ! // _currentScriptFPs.Add(scriptFP); ! // if (reflectToClient && !_previousScriptFPs.Contains(scriptFP)) ! // { ! // if (script.IndexOf("<script") == -1) ! // { ! // NameValueCollection scriptAttributes = new NameValueCollection(); ! // scriptAttributes.Add("type", "text/javascript"); ! // AjaxCallHelper.WriteAddScriptElementScript(script, scriptAttributes); ! // } ! // else ! // { ! // Match match = Util.ScriptTagsRegEx.Match(script); ! // if (match.Success) ! // { ! // CaptureCollection attrnamesOption = match.Groups["attrname"].Captures; ! // CaptureCollection attrvaluesOption = match.Groups["attrvalue"].Captures; ! // NameValueCollection scriptAttributes = new NameValueCollection(); ! // for (int j = 0; j < attrnamesOption.Count; j++) ! // { ! // scriptAttributes.Add(attrnamesOption[j].Value, attrvaluesOption[j].Value); ! // } ! // string scriptText = match.Groups["script"].Value; ! // AjaxCallHelper.WriteAddScriptElementScript(scriptText, scriptAttributes); ! // } ! // } ! // } ! // } ! // } ! // } ! // /// <summary> ! // /// Uses reflection to get the private dictionary field 'fieldName'. ! // /// Uses Page.ClientScript for .NET 2.0, and the Page-object for .NET 1.1 ! // /// </summary> ! // /// <param name="fieldName"></param> ! // /// <returns></returns> ! // private IDictionary GetPageHiddenDictionary(string fieldName) ! // { ! //#if NET_2_0 ! // return (IDictionary)(Util.GetPrivateField(Page.ClientScript, typeof(ClientScriptManager), fieldName)); ! //#else ! // return (IDictionary)(Util.GetPrivateField(Page, typeof(Page), fieldName)); ! //#endif ! // } ! //#if NET_2_0 ! // /// <summary> ! // /// Handles style,title and link tags (inside HEAD) that were added/changed during callback. ! // /// For first page-request, only stores hidden field containing fingerprints ! // /// of the tags inside the html head section. ! // /// When reflectToClient is true, also reflects the changed tags inside head. ! // /// </summary> ! // /// <param name="reflectToClient"></param> ! // private void HandleHeader(bool reflectToClient) ! // { ! // if (Page.Header != null) ! // { ! // ArrayList _previousHeaderFPs = new ArrayList(); ! // ArrayList _currentHeaderFPs = new ArrayList(); ! ! // // Get the fingerprints of the head-tags sent previous time ! // if (Page.Request.Form["__MAGICAJAX_HEAD_FINGERPRINTS"] != null) ! // { ! // _previousHeaderFPs.AddRange(Page.Request.Form["__MAGICAJAX_HEAD_FINGERPRINTS"].Split(';')); ! // } ! ! // StringBuilder sbHeader = new StringBuilder(); ! // HtmlTextWriter headerWriter = new HtmlTextWriter(new System.IO.StringWriter(sbHeader)); ! // Page.Header.RenderControl(headerWriter); ! ! // //strip <header> tag ! // string header = sbHeader.ToString(); ! ! // MatchCollection matches = Util.HeaderTagsRegEx.Matches(header); ! // for (int i=0; i<matches.Count; i++) ! // { ! // Match match = matches[i]; ! ! // string matchFP = Util.GetFingerprint(match.Value); ! // _currentHeaderFPs.Add(matchFP); ! ! // if (reflectToClient && !_previousHeaderFPs.Contains(matchFP)) ! // { ! // string tagName = match.Groups["tag"].Value.ToLower(CultureInfo.InvariantCulture); ! // string innerText = match.Groups["inner"].Success ? match.Groups["inner"].Value.ToLower(CultureInfo.InvariantCulture) : String.Empty; ! ! // NameValueCollection attrNameValues = new NameValueCollection(); ! ! // if (tagName == "link") ! // { ! // CaptureCollection attributes = match.Groups["attribute"].Captures; ! // CaptureCollection attrnames = match.Groups["attrname"].Captures; ! // CaptureCollection attrvalues = match.Groups["attrvalue"].Captures; ! ! // for (int j=0; j < attributes.Count; j++) ! // { ! // string attrname = attrnames[j].Value.ToLower(System.Globalization.CultureInfo.InvariantCulture); ! // attrNameValues.Add (attrname, attrvalues[j].Value); ! // } ! // } ! ! // AjaxCallHelper.WriteAddHeaderElementScript(tagName, innerText, attrNameValues); ! // } ! // } ! ! // string allHeadFPs = string.Join(";", (string[])_currentHeaderFPs.ToArray(typeof(string))); ! ! // // Store head-tag fingerprints in hidden field ! // if (reflectToClient && Page.Request.Form["__MAGICAJAX_HEAD_FINGERPRINTS"] != allHeadFPs) ! // AjaxCallHelper.WriteSetFieldScript("__MAGICAJAX_HEAD_FINGERPRINTS", allHeadFPs); ! // else if (!reflectToClient) ! // Page.RegisterHiddenField("__MAGICAJAX_HEAD_FINGERPRINTS", allHeadFPs); ! // } ! // } ! //#endif ! // } ! //} \ No newline at end of file Index: AjaxPanel.cs =================================================================== RCS file: /cvsroot/magicajax/magicajax/Core/UI/Controls/AjaxPanel.cs,v retrieving revision 1.50 retrieving revision 1.51 diff -C2 -d -r1.50 -r1.51 *** AjaxPanel.cs 20 Jan 2006 01:35:56 -0000 1.50 --- AjaxPanel.cs 23 Jan 2006 01:28:41 -0000 1.51 *************** *** 273,276 **** --- 273,278 ---- { Page.RegisterHiddenField (ControlCollectionState.GetControlFingerprintsField(this.ClientID), String.Empty); + Page.RegisterHiddenField("__MAGICAJAX_SCRIPT_FINGERPRINTS", String.Empty); + Page.RegisterHiddenField("__MAGICAJAX_HEAD_FINGERPRINTS", String.Empty); } *************** *** 286,292 **** --- 288,330 ---- DisableClientValidators(); } + + if (Context != null) + { + if (!Context.Items.Contains("__MAGICAJAX_FIRST_PANELID")) + Context.Items.Add("__MAGICAJAX_FIRST_PANELID", this.ClientID); + + if (!Context.Items.Contains("__MAGICAJAX_LAST_PANELID")) + Context.Items.Add("__MAGICAJAX_LAST_PANELID", this.ClientID); + else + Context.Items["__MAGICAJAX_LAST_PANELID"] = this.ClientID; + } } #endregion + protected override void OnPreRender(EventArgs e) + { + base.OnPreRender(e); + + #region Reflect hidden fields + scripts + if (MagicAjaxContext.Current.IsAjaxCall && (string)Context.Items["__MAGICAJAX_FIRST_PANELID"] == this.ClientID) + { + #if NET_2_0 + // For ASP.NET 2.0, reflect the head-tag's stylesheet- or + // title-changes back to client + HandleHeader(true, null); + #endif + // Get the fingerprints of the scripts sent previous time + if (Page.Request.Form["__MAGICAJAX_SCRIPT_FINGERPRINTS"] != null) + { + _previousScriptFPs.AddRange(Page.Request.Form["__MAGICAJAX_SCRIPT_FINGERPRINTS"].Split(';')); + } + + HandleHiddenFields(); + HandleClientScriptBlocks(true); + HandleOnSubmitStatements(true); + } + #endregion + } + #region override OnAjaxCallEnd protected override void OnAjaxCallEnd(EventArgs e) *************** *** 350,353 **** --- 388,422 ---- #region override RenderChildren + + /// <summary> List of previous fingerprints of all script blocks </summary> + private ArrayList _previousScriptFPs + { + get + { + if (!Context.Items.Contains("_previousScriptFPs")) + Context.Items.Add("_previousScriptFPs", new ArrayList()); + return (ArrayList)Context.Items["_previousScriptFPs"]; + } + set + { + Context.Items["_previousScriptFPs"] = value; + } + } + + /// <summary> List of current fingerprints of all script blocks </summary> + private ArrayList _currentScriptFPs + { + get + { + if (!Context.Items.Contains("_currentScriptFPs")) + Context.Items.Add("_currentScriptFPs", new ArrayList()); + return (ArrayList)Context.Items["_currentScriptFPs"]; + } + set + { + Context.Items["_currentScriptFPs"] = value; + } + } + /// <summary> /// Does a normal rendering of the child controls. *************** *** 360,370 **** protected override void RenderChildren(HtmlTextWriter writer) { ! if (MagicAjaxContext == null) ! { ! // It's in VS Designer, do the default render ! base.RenderChildren(writer); ! return; ! } System.Text.StringBuilder sbFull = new System.Text.StringBuilder(); System.Text.StringBuilder sb = new System.Text.StringBuilder(); --- 429,460 ---- protected override void RenderChildren(HtmlTextWriter writer) { ! if (MagicAjaxContext == null) ! { ! // It's in VS Designer, do the default render ! base.RenderChildren(writer); ! return; ! } ! ! #region Reflect hidden fields + scripts ! if ((string)Context.Items["__MAGICAJAX_FIRST_PANELID"] == this.ClientID) ! { ! #if NET_2_0 ! // For ASP.NET 2.0, reflect the head-tag's stylesheet- or ! // title-changes back to client ! HandleHeader(false, writer); ! #endif ! // Not in Ajax call, so create fingerprints of all script blocks ! HandleClientScriptBlocks(false); ! HandleArrayDeclares(false); ! HandleClientStartupScripts(false); ! HandleOnSubmitStatements(false); + // Store scriptblock fingerprints in hidden field + writer.WriteLine( + string.Format("<script type='text/javascript'>AJAXCbo.SetField('__MAGICAJAX_SCRIPT_FINGERPRINTS','{0}');</script>", + string.Join(";", (string[])_currentScriptFPs.ToArray(typeof(string))))); + } + #endregion + System.Text.StringBuilder sbFull = new System.Text.StringBuilder(); System.Text.StringBuilder sb = new System.Text.StringBuilder(); *************** *** 899,902 **** --- 989,1007 ---- if ( IsPageNoStoreMode ) SaveControlState(); + + if ((string)Context.Items["__MAGICAJAX_LAST_PANELID"] == this.ClientID) + { + // Reflect added startup-scripts and arrays AFTER reflecting the controls HTML + if (MagicAjaxContext.Current.IsAjaxCall) + { + HandleArrayDeclares(true); + HandleClientStartupScripts(true); + + // Store scriptblock fingerprints in hidden field + string allScriptFPs = string.Join(";", (string[])_currentScriptFPs.ToArray(typeof(string))); + if (Page.Request.Form["__MAGICAJAX_SCRIPT_FINGERPRINTS"] != allScriptFPs) + AjaxCallHelper.WriteSetFieldScript("__MAGICAJAX_SCRIPT_FINGERPRINTS", allScriptFPs); + } + } } #endregion *************** *** 1510,1513 **** --- 1615,1885 ---- } #endregion + + #region temp + /// <summary> + /// Reflects registered Hidden fields if added/changed on callback + /// </summary> + /// <param name="page"></param> + private void HandleHiddenFields() + { + IDictionary regFields = GetPageHiddenDictionary("_registeredHiddenFields"); + if (regFields != null) + { + foreach (DictionaryEntry fld in regFields) + { + string key = (string)fld.Key; + string value = (string)fld.Value; + // For now, don't reflect system hidden fields (starting with "__"). + // TODO: find out why __VIEWSTATE is never registered...? + if (key != null && !key.StartsWith("__") && value != Page.Request.Form[key]) + { + if (Page.Request.Form[key] == null) + AjaxCallHelper.WriteAddHiddenFieldScript(key, value); + else + AjaxCallHelper.WriteSetFieldScript(key, value); + } + } + } + } + + /// <summary> + /// Handle registered ClientScriptBlocks to see if some where added/changed on callback/postback + /// </summary> + private void HandleClientScriptBlocks(bool reflectToClient) + { + IDictionary regScripts = GetPageHiddenDictionary("_registeredClientScriptBlocks"); + SetScriptDictionaryFingerPrints(regScripts, reflectToClient); + } + + /// <summary> + /// Handle registered OnSubmitStatements to see if some where added/changed on callback/postback + /// </summary> + /// <param name="reflectToClient"></param> + private void HandleOnSubmitStatements(bool reflectToClient) + { + IDictionary regScripts = GetPageHiddenDictionary("_registeredOnSubmitStatements"); + if (regScripts != null) + { + ListDictionary onSubmitStatementItem = new ListDictionary(); + StringBuilder onSubmitStringBuilder = new StringBuilder(); + onSubmitStringBuilder.Append("\r\n<script type=\"text/javascript\">\r\n<!--\r\n"); + onSubmitStringBuilder.Append("function WebForm_OnSubmit() {\r\n"); + + foreach (string value in regScripts.Values) + onSubmitStringBuilder.Append(value); + + onSubmitStringBuilder.Append("\r\nreturn true;\r\n}"); + onSubmitStringBuilder.Append("// -->\r\n</script>\r\n"); + + onSubmitStatementItem.Add("_registeredOnSubmitStatements", onSubmitStringBuilder.ToString()); + + SetScriptDictionaryFingerPrints(onSubmitStatementItem, reflectToClient); + } + } + + /// <summary> + /// Handle registered ClientStartupScripts to see if some where added/changed on callback/postback + /// </summary> + /// <param name="reflectToClient"></param> + private void HandleClientStartupScripts(bool reflectToClient) + { + IDictionary regScripts = GetPageHiddenDictionary("_registeredClientStartupScripts"); + SetScriptDictionaryFingerPrints(regScripts, reflectToClient); + } + + /// <summary> + /// Handle declared client-Arrays to see if some where added/changed on callback/postback + /// </summary> + /// <param name="reflectToClient"></param> + private void HandleArrayDeclares(bool reflectToClient) + { + IDictionary regArrays = GetPageHiddenDictionary("_registeredArrayDeclares"); + SetArrayDictionaryFingerPrints(regArrays, reflectToClient); + } + + /// <summary> + /// Sets fingerprints for declared Arrays. + /// When reflectToClient is set to true, reflects added/changed Array-declarations + /// back to the client. + /// </summary> + /// <param name="regArrays"></param> + /// <param name="reflectToClient"></param> + private void SetArrayDictionaryFingerPrints(IDictionary regArrays, bool reflectToClient) + { + if (regArrays != null) + { + foreach (DictionaryEntry fld in regArrays) + { + StringBuilder sb = new StringBuilder(); + + string key = (string)fld.Key; + ArrayList values = (ArrayList)fld.Value; + + sb.Append("var "); + sb.Append(key); + sb.Append(" = new Array("); + + for (int i = 0; i<values.Count; i++) + { + if (i >0) + sb.Append(", "); + sb.Append((string)values[i]); + } + sb.Append(");"); + + string script = sb.ToString(); + string scriptFP = Util.GetFingerprint(script); + + _currentScriptFPs.Add(scriptFP); + + if (reflectToClient && !_previousScriptFPs.Contains(scriptFP)) + { + NameValueCollection scriptAttributes = new NameValueCollection(); + scriptAttributes.Add("type", "text/javascript"); + AjaxCallHelper.WriteAddScriptElementScript(script, scriptAttributes); + } + } + } + } + + /// <summary> + /// Sets fingerprints for registered Script blocks. + /// When reflectToClient is set to true, reflects added/changed scripts + /// back to the client. + /// </summary> + /// <param name="regScripts"></param> + /// <param name="reflectToClient"></param> + private void SetScriptDictionaryFingerPrints(IDictionary regScripts, bool reflectToClient) + { + if (regScripts != null) + { + foreach (DictionaryEntry fld in regScripts) + { + int keyHash = fld.Key.GetHashCode(); + string script = (string)fld.Value; + string scriptFP = Util.GetFingerprint(string.Format("{0}:{1}", keyHash, script)); + + _currentScriptFPs.Add(scriptFP); + + if (reflectToClient && !_previousScriptFPs.Contains(scriptFP)) + { + if (script.IndexOf("<script") == -1) + { + NameValueCollection scriptAttributes = new NameValueCollection(); + scriptAttributes.Add("type", "text/javascript"); + AjaxCallHelper.WriteAddScriptElementScript(script, scriptAttributes); + } + else + { + Match match = Util.ScriptTagsRegEx.Match(script); + if (match.Success) + { + CaptureCollection attrnamesOption = match.Groups["attrname"].Captures; + CaptureCollection attrvaluesOption = match.Groups["attrvalue"].Captures; + + NameValueCollection scriptAttributes = new NameValueCollection(); + for (int j = 0; j < attrnamesOption.Count; j++) + { + scriptAttributes.Add(attrnamesOption[j].Value, attrvaluesOption[j].Value); + } + + string scriptText = match.Groups["script"].Value; + + AjaxCallHelper.WriteAddScriptElementScript(scriptText, scriptAttributes); + } + } + } + } + } + } + + /// <summary> + /// Uses reflection to get the private dictionary field 'fieldName'. + /// Uses Page.ClientScript for .NET 2.0, and the Page-object for .NET 1.1 + /// </summary> + /// <param name="fieldName"></param> + /// <returns></returns> + private IDictionary GetPageHiddenDictionary(string fieldName) + { + #if NET_2_0 + return (IDictionary)(Util.GetPrivateField(Page.ClientScript, typeof(ClientScriptManager), fieldName)); + #else + return (IDictionary)(Util.GetPrivateField(Page, typeof(Page), fieldName)); + #endif + } + + #if NET_2_0 + /// <summary> + /// Handles style,title and link tags (inside HEAD) that were added/changed during callback. + /// For first page-request, only stores hidden field containing fingerprints + /// of the tags inside the html head section. + /// When reflectToClient is true, also reflects the changed tags inside head. + /// </summary> + /// <param name="reflectToClient"></param> + private void HandleHeader(bool reflectToClient, HtmlTextWriter writer) + { + if (Page.Header != null) + { + ArrayList _previousHeaderFPs = new ArrayList(); + ArrayList _currentHeaderFPs = new ArrayList(); + + // Get the fingerprints of the head-tags sent previous time + if (Page.Request.Form["__MAGICAJAX_HEAD_FINGERPRINTS"] != null) + { + _previousHeaderFPs.AddRange(Page.Request.Form["__MAGICAJAX_HEAD_FINGERPRINTS"].Split(';')); + } + + StringBuilder sbHeader = new StringBuilder(); + HtmlTextWriter headerWriter = new HtmlTextWriter(new System.IO.StringWriter(sbHeader)); + Page.Header.RenderControl(headerWriter); + + //strip <header> tag + string header = sbHeader.ToString(); + + MatchCollection matches = Util.HeaderTagsRegEx.Matches(header); + for (int i=0; i<matches.Count; i++) + { + Match match = matches[i]; + + string matchFP = Util.GetFingerprint(match.Value); + _currentHeaderFPs.Add(matchFP); + + if (reflectToClient && !_previousHeaderFPs.Contains(matchFP)) + { + string tagName = match.Groups["tag"].Value.ToLower(CultureInfo.InvariantCulture); + string innerText = match.Groups["inner"].Success ? match.Groups["inner"].Value.ToLower(CultureInfo.InvariantCulture) : String.Empty; + + NameValueCollection attrNameValues = new NameValueCollection(); + + if (tagName == "link") + { + CaptureCollection attributes = match.Groups["attribute"].Captures; + CaptureCollection attrnames = match.Groups["attrname"].Captures; + CaptureCollection attrvalues = match.Groups["attrvalue"].Captures; + + for (int j=0; j < attributes.Count; j++) + { + string attrname = attrnames[j].Value.ToLower(System.Globalization.CultureInfo.InvariantCulture); + attrNameValues.Add (attrname, attrvalues[j].Value); + } + } + + AjaxCallHelper.WriteAddHeaderElementScript(tagName, innerText, attrNameValues); + } + } + + string allHeadFPs = string.Join(";", (string[])_currentHeaderFPs.ToArray(typeof(string))); + + // Store head-tag fingerprints in hidden field + if (reflectToClient && Page.Request.Form["__MAGICAJAX_HEAD_FINGERPRINTS"] != allHeadFPs) + AjaxCallHelper.WriteSetFieldScript("__MAGICAJAX_HEAD_FINGERPRINTS", allHeadFPs); + else if (!reflectToClient) + writer.WriteLine( + string.Format("<script type='text/javascript'>AJAXCbo.SetField('__MAGICAJAX_HEAD_FINGERPRINTS','{0}');</script>", allHeadFPs)); + //Page.RegisterHiddenField("__MAGICAJAX_HEAD_FINGERPRINTS", allHeadFPs); + } + } + #endif + #endregion } } \ No newline at end of file |
From: Dion O. <dol...@us...> - 2006-01-20 01:36:07
|
Update of /cvsroot/magicajax/magicajax/Core/UI In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21237/magicajax/Core/UI Modified Files: RenderedByScriptControl.cs Log Message: First support for scripts and hidden fields that were added during callback. Still beta! Index: RenderedByScriptControl.cs =================================================================== RCS file: /cvsroot/magicajax/magicajax/Core/UI/RenderedByScriptControl.cs,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** RenderedByScriptControl.cs 11 Jan 2006 20:27:32 -0000 1.19 --- RenderedByScriptControl.cs 20 Jan 2006 01:35:56 -0000 1.20 *************** *** 194,198 **** // We cannot avoid this because Firefox also keeps any changes that occured // to ViewState, so we need the controls to keep their changes. ! hiddenStore = this.ClientID + "$RBS_Store"; } else --- 194,198 ---- // We cannot avoid this because Firefox also keeps any changes that occured // to ViewState, so we need the controls to keep their changes. ! hiddenStore = "__" + this.ClientID + "$RBS_Store"; } else *************** *** 201,205 **** // a different name for the hidden field at each page request so that // it can be reset for Firefox's "Refresh". ! hiddenStore = this.ClientID + "$RBS_Store" + DateTime.Now.Ticks; } --- 201,205 ---- // a different name for the hidden field at each page request so that // it can be reset for Firefox's "Refresh". ! hiddenStore = "__" + this.ClientID + "$RBS_Store" + DateTime.Now.Ticks; } |
From: Dion O. <dol...@us...> - 2006-01-20 01:36:07
|
Update of /cvsroot/magicajax/magicajax/Core/script In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21237/magicajax/Core/script Modified Files: AjaxCallObject.js Log Message: First support for scripts and hidden fields that were added during callback. Still beta! Index: AjaxCallObject.js =================================================================== RCS file: /cvsroot/magicajax/magicajax/Core/script/AjaxCallObject.js,v retrieving revision 1.46 retrieving revision 1.47 diff -C2 -d -r1.46 -r1.47 *** AjaxCallObject.js 11 Jan 2006 20:27:32 -0000 1.46 --- AjaxCallObject.js 20 Jan 2006 01:35:56 -0000 1.47 *************** *** 748,759 **** } ! AjaxCallObject.prototype.AddScript = function(scriptHtml) { ! var scriptHolder = document.createElement("span"); ! scriptHolder.style.visibility = "hidden"; ! scriptHolder.innerHTML = " "+ scriptHtml.replace("<script","<script defer"); document.forms[0].appendChild(scriptHolder); } AjaxCallObject.prototype.RemoveElement = function(parentID, elementID) { --- 748,774 ---- } ! AjaxCallObject.prototype.AddScript = function(scriptText, scriptAttributes) { ! var scriptHolder = document.createElement('script'); ! scriptHolder.text = scriptText; ! ! if (scriptAttributes != null) ! for (i=0; i < scriptAttributes.length; i+=2) ! scriptHolder.setAttribute(scriptAttributes[i], scriptAttributes[i+1]); ! document.forms[0].appendChild(scriptHolder); } + AjaxCallObject.prototype.AddHiddenField = function(elementName, elementValue) + { + var hiddenField = document.createElement('input'); + hiddenField.type = "hidden"; + hiddenField.name = elementName; + hiddenField.id = elementName; + hiddenField.value = elementValue; + + document.forms[0].appendChild(hiddenField); + } + AjaxCallObject.prototype.RemoveElement = function(parentID, elementID) { |
From: Dion O. <dol...@us...> - 2006-01-20 01:36:07
|
Update of /cvsroot/magicajax/magicajax/Core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21237/magicajax/Core Modified Files: AjaxCallHelper.cs MagicAjax NET 2.0.csproj MagicAjax.csproj MagicAjaxModule.cs Util.cs Log Message: First support for scripts and hidden fields that were added during callback. Still beta! Index: AjaxCallHelper.cs =================================================================== RCS file: /cvsroot/magicajax/magicajax/Core/AjaxCallHelper.cs,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** AjaxCallHelper.cs 11 Jan 2006 20:27:32 -0000 1.19 --- AjaxCallHelper.cs 20 Jan 2006 01:35:56 -0000 1.20 *************** *** 25,28 **** --- 25,29 ---- using System.Web.UI; using System.Collections; + using System.Collections.Specialized; using System.Text; *************** *** 307,310 **** --- 308,334 ---- /// <summary> + /// Produces the javascript that will add a script element to the page. + /// </summary> + /// <param name="scriptText">The script text</param> + /// <param name="scriptText">The script attributes</param> + public static void WriteAddScriptElementScript(string scriptText, NameValueCollection scriptAttributes) + { + StringBuilder sbuilder = new StringBuilder("new Array("); + for (int i = 0; i < scriptAttributes.Count; i++) + { + if (i > 0) + sbuilder.Append(","); + sbuilder.AppendFormat("\"{0}\",\"{1}\"", scriptAttributes.Keys[i], scriptAttributes[i]); + } + sbuilder.Append(")"); + Write(String.Format("AJAXCbo.AddScript({0},{1});\r\n", EncodeString(scriptText), sbuilder.ToString())); + } + + public static void WriteAddHiddenFieldScript(string fieldName, string fieldValue) + { + Write(String.Format("AJAXCbo.AddHiddenField(\"{0}\",{1});\r\n", fieldName, EncodeString(fieldValue))); + } + + /// <summary> /// Provides the javascript that will se the innerHTML of an element of the page. /// </summary> Index: Util.cs =================================================================== RCS file: /cvsroot/magicajax/magicajax/Core/Util.cs,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** Util.cs 11 Jan 2006 20:27:32 -0000 1.23 --- Util.cs 20 Jan 2006 01:35:56 -0000 1.24 *************** *** 44,47 **** --- 44,48 ---- public static Regex FormElementOptionSelectedRegEx = new Regex(@"<option.*?(?<selected>selected=(""|'|)selected(""|'|)(\s+|(?=>))).*?>", _options); public static Regex ScriptPatternRegEx = new Regex(Util.ScriptPattern, RegexOptions.IgnoreCase); + public static Regex ScriptTagsRegEx = new Regex("<script\\s((?<attrname>[-\\w]+)=\"(?<attrvalue>.*?)\"\\s?)*\\s*>(?<script>.*?)</script>", _options); #endregion *************** *** 267,270 **** --- 268,298 ---- /// <summary> + /// Copies all fields (private and public) from the source object to + /// the destination object thereby performing shallow copy + /// Unlike shallow copy however, the objects do not need to be of the same type + /// and destination can be a decendant of source in the class heirarchy + /// </summary> + /// <param name="destination">object to copy fields on</param> + /// <param name="source">object to copy fields from</param> + public static void ForceShallowCopyOnObject(object destination, object source) + { + Type dstType = destination.GetType(); + Type srcType = source.GetType(); + // get all fields of source type + // to get all private fields loop over all base classes. + for (Type t = srcType; t != typeof(Object); t = t.BaseType) + { + System.Reflection.FieldInfo[] srcFields = t.GetFields(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public); + foreach (System.Reflection.FieldInfo fld in srcFields) + { + string fldName = fld.Name; + object fldValue = fld.GetValue(source); + System.Reflection.FieldInfo dstFld = t.GetField(fldName, System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public); + dstFld.SetValue(destination, fldValue); + } + } + } + + /// <summary> /// Gets all child controls of a specific type. /// </summary> Index: MagicAjax.csproj =================================================================== RCS file: /cvsroot/magicajax/magicajax/Core/MagicAjax.csproj,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** MagicAjax.csproj 3 Jan 2006 01:49:09 -0000 1.10 --- MagicAjax.csproj 20 Jan 2006 01:35:56 -0000 1.11 *************** *** 203,206 **** --- 203,211 ---- /> <File + RelPath = "UI\Controls\AjaxHtmlForm.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "UI\Controls\AjaxHtmlImage.cs" SubType = "Code" Index: MagicAjax NET 2.0.csproj =================================================================== RCS file: /cvsroot/magicajax/magicajax/Core/MagicAjax NET 2.0.csproj,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** MagicAjax NET 2.0.csproj 3 Jan 2006 01:49:09 -0000 1.13 --- MagicAjax NET 2.0.csproj 20 Jan 2006 01:35:56 -0000 1.14 *************** *** 124,127 **** --- 124,128 ---- <SubType>Code</SubType> </Compile> + <Compile Include="UI\Controls\AjaxHtmlForm.cs" /> <Compile Include="UI\Controls\ClientEventControls\BaseClientEventWrapper.cs" /> <Compile Include="UI\Controls\ClientEventControls\ClientEventControl.cs" /> Index: MagicAjaxModule.cs =================================================================== RCS file: /cvsroot/magicajax/magicajax/Core/MagicAjaxModule.cs,v retrieving revision 1.58 retrieving revision 1.59 diff -C2 -d -r1.58 -r1.59 *** MagicAjaxModule.cs 11 Jan 2006 20:27:32 -0000 1.58 --- MagicAjaxModule.cs 20 Jan 2006 01:35:56 -0000 1.59 *************** *** 27,30 **** --- 27,31 ---- using System.Web.UI; using System.Web.UI.WebControls; + using System.Web.UI.HtmlControls; using System.IO; using System.Text; *************** *** 33,36 **** --- 34,38 ---- using MagicAjax.Configuration; using MagicAjax.UI; + using MagicAjax.UI.Controls; namespace MagicAjax *************** *** 457,469 **** } // Continue only if it is a postback or an AjaxCall if ("GET" == _request.HttpMethod) return; - Page currentPage = HttpContext.Current.Handler as Page; - #if NET_2_0 ! ! if (currentPage != null) { // For ASP.NET 2.0, disable event validation on the page --- 459,479 ---- } + _magicAjaxContext.IsAjaxCall = (_request.Form["__AJAXCALL"] != null); + + Page currentPage = HttpContext.Current.Handler as Page; + + #if NET_2_0 + // On Page-init, we're going to replace the regular HTMLForm control with an AjaxHMTLForm + // For now, only supported for .NET 2.0 + if (currentPage != null) + currentPage.Init += new EventHandler(currentPage_Init); + #endif + // Continue only if it is a postback or an AjaxCall if ("GET" == _request.HttpMethod) return; #if NET_2_0 ! if (currentPage != null && _magicAjaxContext.IsAjaxCall) { // For ASP.NET 2.0, disable event validation on the page *************** *** 472,477 **** } #endif - - _magicAjaxContext.IsAjaxCall = (_request.Form["__AJAXCALL"] != null); string configState = _request.Form["__MAGICAJAX_CONFIG"]; if (configState != null) --- 482,485 ---- *************** *** 605,608 **** --- 613,659 ---- } + + /// <summary> + /// On Page init, we're going to we're going to replace + /// the regular HTMLForm control with our own AjaxHMTLForm. + /// This way we can implement a custom rendering of the form, + /// which reflects added scripts and hidden fields on Ajax callbacks + /// </summary> + /// <param name="sender">The current page</param> + /// <param name="e"></param> + void currentPage_Init(object sender, EventArgs e) + { + Page thePage = (Page)sender; + if (thePage != null) + { + HtmlForm oldFrm = (HtmlForm)Util.GetPrivateField(thePage, typeof(Page), "_form"); + AjaxHtmlForm newFrm = new AjaxHtmlForm(); + + // Copy all properties over + Util.ForceShallowCopyOnObject(newFrm, oldFrm); + + // when adding a control - the framework will try to disconnect it from its parent + // so we better make sure it it has no parent. + Util.SetPrivateField(newFrm, typeof(Control), "_parent", null); + Util.SetPrivateField(thePage, typeof(Page), "_form", newFrm); + + // Now replace the current Form control by our own + Control hostingControl = (Control)thePage; + #if NET_2_0 + if (thePage.Master != null) + { + MasterPage master = thePage.Master; + while (master.Master != null) + master = master.Master; + + hostingControl = (Control)master; + } + #endif + int formIndex = hostingControl.Controls.IndexOf(oldFrm); + hostingControl.Controls.RemoveAt(formIndex); + hostingControl.Controls.AddAt(formIndex, newFrm); + } + } + /// <summary> /// Handles the EndRequest event of the Application *************** *** 628,632 **** // If the ViewState wasn't excluded from the post data, retrieve // it and send it to client. ! if ( _magicAjaxContext.IsPageNoStoreMode && _request.Form["__VIEWSTATE"] != null ) { string vsValue = _filter.GetViewStateFieldValue(); --- 679,683 ---- // If the ViewState wasn't excluded from the post data, retrieve // it and send it to client. ! if (_magicAjaxContext.IsPageNoStoreMode && _request.Form["__VIEWSTATE"] != null) { string vsValue = _filter.GetViewStateFieldValue(); |
From: Dion O. <dol...@us...> - 2006-01-20 01:36:07
|
Update of /cvsroot/magicajax/magicajax/Core/UI/Controls In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21237/magicajax/Core/UI/Controls Modified Files: AjaxPanel.cs Added Files: AjaxHtmlForm.cs Log Message: First support for scripts and hidden fields that were added during callback. Still beta! --- NEW FILE: AjaxHtmlForm.cs --- using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Collections; using System.Collections.Specialized; using System.Text.RegularExpressions; using System.Text; namespace MagicAjax.UI.Controls { /// <summary> /// TODO. As you can see, this code is not yet finished /// </summary> public class AjaxHtmlForm : System.Web.UI.HtmlControls.HtmlForm { public AjaxHtmlForm() { } private ArrayList _previousScriptFPs = new ArrayList(); private ArrayList _currentScriptFPs = new ArrayList(); protected override void RenderChildren(HtmlTextWriter writer) { if (MagicAjaxContext.Current.IsAjaxCall) { // Get the fingerprints of the scripts sent previous time if (Page.Request.Form["__MAGICAJAX_SCRIPT_FINGERPRINTS"] != null) { _previousScriptFPs.AddRange(Page.Request.Form["__MAGICAJAX_SCRIPT_FINGERPRINTS"].Split(';')); } ReflectHiddenFields(); //ReflectWebFormScript(); ?? ReflectClientScriptBlocks(); } else { SetAllScriptFingerPrints(); Page.ClientScript.RegisterHiddenField("__MAGICAJAX_SCRIPT_FINGERPRINTS", string.Join(";", (string[])_currentScriptFPs.ToArray(typeof(string)))); } base.RenderChildren(writer); if (MagicAjaxContext.Current.IsAjaxCall) { ReflectArrayDeclares(); //ReflectExpandoAttribute(); !! ReflectClientStartupScripts(); //set __MAGICAJAX_SCRIPT_FINGERPRINTS field string newFingerprints = string.Join(";", (string[])_currentScriptFPs.ToArray(typeof(string))); if (Page.Request.Form["__MAGICAJAX_SCRIPT_FINGERPRINTS"] != newFingerprints) { AjaxCallHelper.WriteSetFieldScript("__MAGICAJAX_SCRIPT_FINGERPRINTS", string.Join(";", (string[])_currentScriptFPs.ToArray(typeof(string)))); } } } private void ReflectClientScriptBlocks() { IDictionary regScripts = (IDictionary)(Util.GetPrivateField(Page.ClientScript, typeof(ClientScriptManager), "_registeredClientScriptBlocks")); SetScriptDictionaryFingerPrints(regScripts, true); //TODO: _registeredOnSubmitStatements !! } private void ReflectClientStartupScripts() { IDictionary regScripts = (IDictionary)(Util.GetPrivateField(Page.ClientScript, typeof(ClientScriptManager), "_registeredClientStartupScripts")); SetScriptDictionaryFingerPrints(regScripts, true); } private void ReflectArrayDeclares() { IDictionary regArrays = (IDictionary)(Util.GetPrivateField(Page.ClientScript, typeof(ClientScriptManager), "_registeredArrayDeclares")); SetArrayDictionaryFingerPrints(regArrays, true); } private void SetAllScriptFingerPrints() { IDictionary regScripts; //ReflectWebFormScript(); ?? regScripts = (IDictionary)(Util.GetPrivateField(Page.ClientScript, typeof(ClientScriptManager), "_registeredClientScriptBlocks")); SetScriptDictionaryFingerPrints(regScripts, false); IDictionary regArrays = (IDictionary)(Util.GetPrivateField(Page.ClientScript, typeof(ClientScriptManager), "_registeredArrayDeclares")); SetArrayDictionaryFingerPrints(regArrays, false); //ReflectExpandoAttribute(); !! regScripts = (IDictionary)(Util.GetPrivateField(Page.ClientScript, typeof(ClientScriptManager), "_registeredClientStartupScripts")); SetScriptDictionaryFingerPrints(regScripts, false); } private void SetArrayDictionaryFingerPrints(IDictionary regArrays, bool reflectScripts) { if (regArrays != null) { foreach (DictionaryEntry fld in regArrays) { StringBuilder sb = new StringBuilder(); string key = (string)fld.Key; ArrayList values = (ArrayList)fld.Value; sb.Append("var "); sb.Append(key); sb.Append(" = new Array("); for (int i = 0; i<values.Count; i++) { if (i >0) sb.Append(", "); sb.Append((string)values[i]); } sb.Append(");"); string script = sb.ToString(); string scriptFP = Util.GetFingerprint(script); _currentScriptFPs.Add(scriptFP); if (reflectScripts && !_previousScriptFPs.Contains(scriptFP)) { NameValueCollection scriptAttributes = new NameValueCollection(); scriptAttributes.Add("type", "text/javascript"); AjaxCallHelper.WriteAddScriptElementScript(script, scriptAttributes); } } } } private void SetScriptDictionaryFingerPrints(IDictionary regScripts, bool reflectScripts) { if (regScripts != null) { foreach (DictionaryEntry fld in regScripts) { int keyHash = fld.Key.GetHashCode(); string script = (string)fld.Value; string scriptFP = Util.GetFingerprint(string.Format("{0}:{1}", keyHash, script)); _currentScriptFPs.Add(scriptFP); if (reflectScripts && !_previousScriptFPs.Contains(scriptFP)) { if (!script.StartsWith("\r\n<script")) { NameValueCollection scriptAttributes = new NameValueCollection(); scriptAttributes.Add("type", "text/javascript"); AjaxCallHelper.WriteAddScriptElementScript(script, scriptAttributes); } else { Match match = Util.ScriptTagsRegEx.Match(script); if (match.Success) { CaptureCollection attrnamesOption = match.Groups["attrname"].Captures; CaptureCollection attrvaluesOption = match.Groups["attrvalue"].Captures; NameValueCollection scriptAttributes = new NameValueCollection(); for (int j = 0; j < attrnamesOption.Count; j++) { scriptAttributes.Add(attrnamesOption[j].Value, attrvaluesOption[j].Value); } string scriptText = match.Groups["script"].Value; AjaxCallHelper.WriteAddScriptElementScript(scriptText, scriptAttributes); } } } } } } /// <summary> /// Reflects hidden fields back to client /// </summary> /// <param name="page"></param> private void ReflectHiddenFields() { IDictionary regFields = (IDictionary)(Util.GetPrivateField(Page.ClientScript, typeof(ClientScriptManager), "_registeredHiddenFields")); // for 1.1: IDictionary regFields = (IDictionary)(Util.GetPrivateField(Page, typeof(Page), "_registeredHiddenFields")); if (regFields != null) { foreach (DictionaryEntry fld in regFields) { string key = (string)fld.Key; string value = (string)fld.Value; // For now, don't reflect system hidden fields (starting with "__"). // TODO: find out why __VIEWSTATE is never registered...? if (key != null && !key.StartsWith("__")) { if (Page.Request.Form[key] == null) AjaxCallHelper.WriteAddHiddenFieldScript(key, value); else AjaxCallHelper.WriteSetFieldScript(key, value); } } } } } } Index: AjaxPanel.cs =================================================================== RCS file: /cvsroot/magicajax/magicajax/Core/UI/Controls/AjaxPanel.cs,v retrieving revision 1.49 retrieving revision 1.50 diff -C2 -d -r1.49 -r1.50 *** AjaxPanel.cs 7 Jan 2006 08:03:47 -0000 1.49 --- AjaxPanel.cs 20 Jan 2006 01:35:56 -0000 1.50 *************** *** 275,279 **** } ! //disabling clientside validation inside AjaxPanels (not yet handled correctly) // Clientside validation throws errors when a validator becomes invisible // during an AjaxCall (the validator is gone while the script checking for --- 275,279 ---- } ! //disabling clientside validation inside AjaxPanels (not yet handled correctly for Page-store mode) // Clientside validation throws errors when a validator becomes invisible // during an AjaxCall (the validator is gone while the script checking for *************** *** 281,285 **** // TODO: Find a way to avoid problems of scripts that invisible controls // leave behind. ! DisableClientValidators(); } #endregion --- 281,289 ---- // TODO: Find a way to avoid problems of scripts that invisible controls // leave behind. ! ! if ( !this.MagicAjaxContext.IsPageNoStoreMode ) ! { ! DisableClientValidators(); ! } } #endregion *************** *** 1334,1338 **** if (HttpContext.Current.Request.Form[panelKey] != serializedPanelFingerprints) { ! AjaxCallHelper.WriteSetFieldScript(panelKey, serializedPanelFingerprints); } } --- 1338,1343 ---- if (HttpContext.Current.Request.Form[panelKey] != serializedPanelFingerprints) { ! //NOTE: reflecting hidden hields is done elsewhere ! //AjaxCallHelper.WriteSetFieldScript(panelKey, serializedPanelFingerprints); } } |
From: Dion O. <dol...@us...> - 2006-01-11 20:27:46
|
Update of /cvsroot/magicajax/magicajax/Core/UI In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25664/magicajax/Core/UI Modified Files: RenderedByScriptControl.cs Log Message: Reverted changes... Index: RenderedByScriptControl.cs =================================================================== RCS file: /cvsroot/magicajax/magicajax/Core/UI/RenderedByScriptControl.cs,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** RenderedByScriptControl.cs 8 Jan 2006 21:14:02 -0000 1.18 --- RenderedByScriptControl.cs 11 Jan 2006 20:27:32 -0000 1.19 *************** *** 194,198 **** // We cannot avoid this because Firefox also keeps any changes that occured // to ViewState, so we need the controls to keep their changes. ! hiddenStore = string.Format("__{0}$RBS_Store", this.ClientID); } else --- 194,198 ---- // We cannot avoid this because Firefox also keeps any changes that occured // to ViewState, so we need the controls to keep their changes. ! hiddenStore = this.ClientID + "$RBS_Store"; } else *************** *** 201,205 **** // a different name for the hidden field at each page request so that // it can be reset for Firefox's "Refresh". ! hiddenStore = string.Format("__{0}$RBS_Store{1}", this.ClientID, DateTime.Now.Ticks); } --- 201,205 ---- // a different name for the hidden field at each page request so that // it can be reset for Firefox's "Refresh". ! hiddenStore = this.ClientID + "$RBS_Store" + DateTime.Now.Ticks; } |
From: Dion O. <dol...@us...> - 2006-01-11 20:27:46
|
Update of /cvsroot/magicajax/magicajax/Core/script In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25664/magicajax/Core/script Modified Files: AjaxCallObject.js Log Message: Reverted changes... Index: AjaxCallObject.js =================================================================== RCS file: /cvsroot/magicajax/magicajax/Core/script/AjaxCallObject.js,v retrieving revision 1.45 retrieving revision 1.46 diff -C2 -d -r1.45 -r1.46 *** AjaxCallObject.js 8 Jan 2006 21:14:02 -0000 1.45 --- AjaxCallObject.js 11 Jan 2006 20:27:32 -0000 1.46 *************** *** 748,774 **** } ! AjaxCallObject.prototype.AddScript = function(scriptText, scriptAttributes) { ! var scriptHolder = document.createElement('script'); ! scriptHolder.text = scriptText; ! ! if (scriptAttributes != null) ! for (i=0; i < scriptAttributes.length; i+=2) ! scriptHolder.setAttribute(scriptAttributes[i], scriptAttributes[i+1]); ! document.forms[0].appendChild(scriptHolder); } - AjaxCallObject.prototype.AddHiddenField = function(elementName, elementValue) - { - var hiddenField = document.createElement('input'); - hiddenField.type = "hidden"; - hiddenField.name = elementName; - hiddenField.id = elementName; - hiddenField.value = elementValue; - - document.forms[0].appendChild(hiddenField); - } - AjaxCallObject.prototype.RemoveElement = function(parentID, elementID) { --- 748,759 ---- } ! AjaxCallObject.prototype.AddScript = function(scriptHtml) { ! var scriptHolder = document.createElement("span"); ! scriptHolder.style.visibility = "hidden"; ! scriptHolder.innerHTML = " "+ scriptHtml.replace("<script","<script defer"); document.forms[0].appendChild(scriptHolder); } AjaxCallObject.prototype.RemoveElement = function(parentID, elementID) { |
From: Dion O. <dol...@us...> - 2006-01-11 20:27:43
|
Update of /cvsroot/magicajax/magicajax/Core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25664/magicajax/Core Modified Files: AjaxCallHelper.cs MagicAjaxModule.cs PageFilter.cs Util.cs Log Message: Reverted changes... Index: PageFilter.cs =================================================================== RCS file: /cvsroot/magicajax/magicajax/Core/PageFilter.cs,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** PageFilter.cs 8 Jan 2006 21:14:02 -0000 1.9 --- PageFilter.cs 11 Jan 2006 20:27:32 -0000 1.10 *************** *** 36,55 **** private Stream _memStream; private MagicAjaxContext _magicAjaxContext; - private bool _forceMemoryStreamWriting = false; ! /// <summary> ! /// Filters the response stream, and stores everyting in a memorystream ! /// </summary> ! /// <param name="_responseStream"></param> ! /// <param name="forceMemoryStreamWriting">Force writing to memory, no mather if in ajaxcall or not</param> ! public PageFilter(Stream responseStream, bool forceMemoryStreamWriting) { ! _responseStream = responseStream; ! _memStream = new MemoryStream(); ! _magicAjaxContext = MagicAjaxContext.Current; ! _forceMemoryStreamWriting = forceMemoryStreamWriting; } - - public PageFilter(Stream _responseStream): this(_responseStream, false) {} #if NET_2_0 --- 36,67 ---- private Stream _memStream; private MagicAjaxContext _magicAjaxContext; ! public PageFilter(Stream _responseStream) { ! this._responseStream = _responseStream; ! this._memStream = new MemoryStream(); ! this._magicAjaxContext = MagicAjaxContext.Current; ! } ! ! public string GetViewStateFieldValue() ! { ! //TODO: use regular expression (much faster) ! #if NET_2_0 ! string search = "<input type=\"hidden\" name=\"__VIEWSTATE\" id=\"__VIEWSTATE\" value=\""; ! #else ! string search = "<input type=\"hidden\" name=\"__VIEWSTATE\" value=\""; ! #endif ! string html = GetHtmlPage(); ! int si = html.IndexOf(search); ! if (si == -1) ! return null; ! ! si += search.Length; ! int ei = html.IndexOf('\"', si); ! if (ei == -1) ! return null; ! ! return html.Substring(si, ei - si); } #if NET_2_0 *************** *** 62,73 **** string html = GetHtmlPage(); ! //// Look for webpartmanager object creation script ! //string searchWPManager = "<script type=\"text\\/javascript\">\\r\\n\\r\\n__wpm = new WebPartManager\\(\\);\\r\\n(?<WPManagerScript>.*?)<\\/script>"; ! //Regex regExWPManager = new Regex(searchWPManager, RegexOptions.Singleline | RegexOptions.Compiled); ! //Match match = regExWPManager.Match(html); ! //// If no webpartmanager script exists in html -> exit ! //if (!match.Success) ! // return null; // Stringbuilder to hold the output script --- 74,85 ---- string html = GetHtmlPage(); ! // Look for webpartmanager object creation script ! string searchWPManager = "<script type=\"text\\/javascript\">\\r\\n\\r\\n__wpm = new WebPartManager\\(\\);\\r\\n(?<WPManagerScript>.*?)<\\/script>"; ! Regex regExWPManager = new Regex(searchWPManager, RegexOptions.Singleline | RegexOptions.Compiled); ! Match match = regExWPManager.Match(html); ! // If no webpartmanager script exists in html -> exit ! if (!match.Success) ! return null; // Stringbuilder to hold the output script *************** *** 86,100 **** } ! //// Now append the WebpartManager script ! //wpmScript.AppendLine(match.Groups["WPManagerScript"].Value); ! //// Now append the webpart menu scripts ! //string searchWPMenus = "<script type=\"text\\/javascript\">\\r\\n(?<MenuScript>var menuWebPart_.*?)<\\/script>"; ! //Regex regExMenuScripts = new Regex(searchWPMenus, RegexOptions.Singleline | RegexOptions.Compiled); ! //MatchCollection matches = regExMenuScripts.Matches(html); //ei ! //for (int i = 0; i < matches.Count; i++) ! //{ ! // wpmScript.AppendLine(matches[i].Groups["MenuScript"].Value); ! //} return wpmScript.ToString(); --- 98,112 ---- } ! // Now append the WebpartManager script ! wpmScript.AppendLine(match.Groups["WPManagerScript"].Value); ! // Now append the webpart menu scripts ! string searchWPMenus = "<script type=\"text\\/javascript\">\\r\\n(?<MenuScript>var menuWebPart_.*?)<\\/script>"; ! Regex regExMenuScripts = new Regex(searchWPMenus, RegexOptions.Singleline | RegexOptions.Compiled); ! MatchCollection matches = regExMenuScripts.Matches(html); //ei ! for (int i = 0; i < matches.Count; i++) ! { ! wpmScript.AppendLine(matches[i].Groups["MenuScript"].Value); ! } return wpmScript.ToString(); *************** *** 171,180 **** public override void Write(byte[] buffer, int offset, int count) { - if (_forceMemoryStreamWriting) - { - _memStream.Write(buffer, offset, count); - return; - } - if (_magicAjaxContext.IsAjaxCall) { --- 183,186 ---- Index: AjaxCallHelper.cs =================================================================== RCS file: /cvsroot/magicajax/magicajax/Core/AjaxCallHelper.cs,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** AjaxCallHelper.cs 8 Jan 2006 21:14:02 -0000 1.18 --- AjaxCallHelper.cs 11 Jan 2006 20:27:32 -0000 1.19 *************** *** 25,29 **** using System.Web.UI; using System.Collections; - using System.Collections.Specialized; using System.Text; --- 25,28 ---- *************** *** 271,275 **** /// <summary> ! /// Produces the javascript that will add a new element on the page. /// </summary> /// <param name="parentID">The id of the element that will contain the new element</param> --- 270,274 ---- /// <summary> ! /// Produces the javascript that will a new element on the page. /// </summary> /// <param name="parentID">The id of the element that will contain the new element</param> *************** *** 279,310 **** public static void WriteAddElementScript(string parentID, string tagName, string elementID, string html, string beforeElemID) { - parentID = parentID.StartsWith("document.") ? parentID : string.Format("\"{0}\"", parentID); string before = (beforeElemID != null) ? String.Format("\"{0}\"", beforeElemID) : "null"; ! Write( String.Format("AJAXCbo.AddElement({0},\"{1}\",\"{2}\",{3},{4});\r\n", parentID, tagName, elementID, EncodeString(html), before) ); ! } ! ! /// <summary> ! /// Produces the javascript that will add a script element to the page. ! /// </summary> ! /// <param name="scriptText">The script text</param> ! /// <param name="scriptText">The script attributes</param> ! public static void WriteAddScriptElementScript(string scriptText, NameValueCollection scriptAttributes) ! { ! StringBuilder sbuilder = new StringBuilder("new Array("); ! for (int i=0; i<scriptAttributes.Count; i++) ! { ! if (i>0) ! sbuilder.Append(","); ! sbuilder.AppendFormat("\"{0}\",\"{1}\"", scriptAttributes.Keys[i], scriptAttributes[i]); ! } ! sbuilder.Append(")"); ! Write(String.Format("AJAXCbo.AddScript({0},{1});\r\n", EncodeString(scriptText), sbuilder.ToString())); } - public static void WriteAddHiddenFieldScript(string elementName, string elementValue) - { - Write(String.Format("AJAXCbo.AddHiddenField(\"{0}\",{1});\r\n", elementName, EncodeString(elementValue))); - } - /// <summary> /// Provides the javascript that will remove an existing element from the page. --- 278,285 ---- public static void WriteAddElementScript(string parentID, string tagName, string elementID, string html, string beforeElemID) { string before = (beforeElemID != null) ? String.Format("\"{0}\"", beforeElemID) : "null"; ! Write( String.Format("AJAXCbo.AddElement(\"{0}\",\"{1}\",\"{2}\",{3},{4});\r\n", parentID, tagName, elementID, EncodeString(html), before) ); } /// <summary> /// Provides the javascript that will remove an existing element from the page. *************** *** 446,456 **** throw new MagicAjaxException("Script writing level should be 0 at the end of AjaxCall. IncreaseWritingLevel calls do not match DecreaseWritingLevel calls."); HttpResponse hr = HttpContext.Current.Response; hr.Clear(); MergeNextWritingLevelRecursive (0); - - WriteEndSignature(); - hr.Write ((_sbWritingLevels[0] as StringBuilder).ToString()); --- 421,430 ---- throw new MagicAjaxException("Script writing level should be 0 at the end of AjaxCall. IncreaseWritingLevel calls do not match DecreaseWritingLevel calls."); + WriteEndSignature(); + HttpResponse hr = HttpContext.Current.Response; hr.Clear(); MergeNextWritingLevelRecursive (0); hr.Write ((_sbWritingLevels[0] as StringBuilder).ToString()); Index: Util.cs =================================================================== RCS file: /cvsroot/magicajax/magicajax/Core/Util.cs,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** Util.cs 8 Jan 2006 21:14:02 -0000 1.22 --- Util.cs 11 Jan 2006 20:27:32 -0000 1.23 *************** *** 44,49 **** public static Regex FormElementOptionSelectedRegEx = new Regex(@"<option.*?(?<selected>selected=(""|'|)selected(""|'|)(\s+|(?=>))).*?>", _options); public static Regex ScriptPatternRegEx = new Regex(Util.ScriptPattern, RegexOptions.IgnoreCase); - public static Regex ScriptTagsRegEx = new Regex("<script\\s((?<attrname>[-\\w]+)=\"(?<attrvalue>.*?)\"\\s?)*\\s*>(?<script>.*?)</script>", _options); - public static Regex HiddenInputTagsRegEx = new Regex("<input type=\"hidden\" name=\"(?<name>[-\\w]+)\"\\s.*?\\svalue=\"(?<value>[-\\w]*)\" />", _options); #endregion --- 44,47 ---- *************** *** 97,101 **** public static string GetFingerprint(string input) { ! input = GetHtmlWithClearedFormValues(input); MagicAjax.Configuration.OutputCompareMode compareMode = MagicAjaxContext.Current.Configuration.CompareMode; --- 95,99 ---- public static string GetFingerprint(string input) { ! input = GetHtmlWithClearedFormValues(input); MagicAjax.Configuration.OutputCompareMode compareMode = MagicAjaxContext.Current.Configuration.CompareMode; Index: MagicAjaxModule.cs =================================================================== RCS file: /cvsroot/magicajax/magicajax/Core/MagicAjaxModule.cs,v retrieving revision 1.57 retrieving revision 1.58 diff -C2 -d -r1.57 -r1.58 *** MagicAjaxModule.cs 8 Jan 2006 21:46:00 -0000 1.57 --- MagicAjaxModule.cs 11 Jan 2006 20:27:32 -0000 1.58 *************** *** 151,157 **** } } - - // Register hidden field to hold script fingerprints - page.RegisterHiddenField("__MAGICAJAX_SCRIPT_FINGERPRINTS", string.Empty); // Save to page any changes that may occured to Configuration --- 151,154 ---- *************** *** 448,453 **** { return; //if this wasn't a .aspx request, don't process ! } ! string pageKey = _request.QueryString["__AJAX_PAGEUNLOAD"]; if (pageKey != null) --- 445,450 ---- { return; //if this wasn't a .aspx request, don't process ! } ! string pageKey = _request.QueryString["__AJAX_PAGEUNLOAD"]; if (pageKey != null) *************** *** 459,481 **** application.CompleteRequest(); } - - _magicAjaxContext.IsAjaxCall = (_request.Form["__AJAXCALL"] != null); - - // Set the pagefilter for non-ajax calls, so we can find the script blocks - // written to the client, and also write fingerprints for them. - // This way, on a callback we can see which script blocks were added since - // last call. - //HACK: it would be better to only set a filter when page contains AjaxPanels - if (!_magicAjaxContext.IsAjaxCall) - { - _filter = new PageFilter(_response.Filter, true); - _response.Filter = _filter; - } // Continue only if it is a postback or an AjaxCall ! if (_request.HttpMethod == "GET") ! { return; - } Page currentPage = HttpContext.Current.Handler as Page; --- 456,463 ---- application.CompleteRequest(); } // Continue only if it is a postback or an AjaxCall ! if ("GET" == _request.HttpMethod) return; Page currentPage = HttpContext.Current.Handler as Page; *************** *** 490,494 **** } #endif ! string configState = _request.Form["__MAGICAJAX_CONFIG"]; if (configState != null) --- 472,477 ---- } #endif ! ! _magicAjaxContext.IsAjaxCall = (_request.Form["__AJAXCALL"] != null); string configState = _request.Form["__MAGICAJAX_CONFIG"]; if (configState != null) *************** *** 514,522 **** AjaxCallHelper.Init(); - - // Increase writing level just after Init. So in ApplicationEndRequest we - // can decrease it to write script before all scripts already written. - //HACK: replace this with a more elegant solution - AjaxCallHelper.IncreaseWritingLevel(); try --- 497,500 ---- *************** *** 610,618 **** AjaxCallHelper.Init(); - // Increase writing level just after Init. So in ApplicationEndRequest we - // can decrease it to write script before all scripts already written. - //HACK: replace this with a more elegant solution - AjaxCallHelper.IncreaseWritingLevel(); - try { --- 588,591 ---- *************** *** 649,721 **** try { ! string html = _filter.GetHtmlPage(); ! ! #region Reflect new/updated script elements ! ArrayList previousScriptFPs = new ArrayList(); ! if (_request["__MAGICAJAX_SCRIPT_FINGERPRINTS"] != null) ! { ! previousScriptFPs.AddRange(_request["__MAGICAJAX_SCRIPT_FINGERPRINTS"].Split(';')); ! } ! ! string scriptfingerprintSearch = "id=\"__MAGICAJAX_SCRIPT_FINGERPRINTS\" value=\""; ! ! // Find all scripts, and send fingerprints to client (in a hidden field) ! StringBuilder sbuilder = new StringBuilder(); ! MatchCollection matches = Util.ScriptTagsRegEx.Matches(html); ! for (int i = 0; i < matches.Count; i++) { ! Match match = matches[i]; ! string fullScript = match.Value; ! string scriptFP = Util.GetFingerprint(fullScript); ! ! if (i == 0) ! sbuilder.Append(";"); ! sbuilder.Append(scriptFP); ! ! if (_magicAjaxContext.IsAjaxCall && _processedAjaxCall) { ! // If this is a new script block, create call to create script ! // on client ! if (!previousScriptFPs.Contains(scriptFP)) { ! CaptureCollection attrnamesOption = match.Groups["attrname"].Captures; ! CaptureCollection attrvaluesOption = match.Groups["attrvalue"].Captures; ! ! NameValueCollection scriptAttributes = new NameValueCollection(); ! for (int j = 0; j < attrnamesOption.Count; j++) { ! scriptAttributes.Add(attrnamesOption[j].Value, attrvaluesOption[j].Value); } - - string scriptText = match.Groups["script"].Value; - - AjaxCallHelper.WriteAddScriptElementScript(scriptText, scriptAttributes); } - } - } - string scriptFPs = sbuilder.ToString(); - if (!_magicAjaxContext.IsAjaxCall) - { - // This is a non-ajax request. Add a hidden field to the output html that contains - // the fingerprints of all script elements. - html = html.Replace(scriptfingerprintSearch, scriptfingerprintSearch + scriptFPs); - _response.Write(html); - _response.End(); - } - else if (_processedAjaxCall) - { - AjaxCallHelper.WriteSetFieldScript("__MAGICAJAX_SCRIPT_FINGERPRINTS", scriptFPs); - } - #endregion - - if ( _magicAjaxContext.IsAjaxCall ) - { - // Decrease writing level to write script before all scripts already written. - //HACK: replace this with a more elegant solution - AjaxCallHelper.DecreaseWritingLevel(); - - if ( _processedAjaxCall ) - { #if NET_2_0 Page currentPage = HttpContext.Current.Handler as Page; --- 622,640 ---- try { ! if ( _magicAjaxContext.IsAjaxCall ) { ! if ( _processedAjaxCall ) { ! // If the ViewState wasn't excluded from the post data, retrieve ! // it and send it to client. ! if ( _magicAjaxContext.IsPageNoStoreMode && _request.Form["__VIEWSTATE"] != null ) { ! string vsValue = _filter.GetViewStateFieldValue(); ! if (vsValue != null && _request.Form["__VIEWSTATE"] != vsValue) { ! AjaxCallHelper.WriteSetFieldScript("__VIEWSTATE", vsValue); } } #if NET_2_0 Page currentPage = HttpContext.Current.Handler as Page; *************** *** 736,768 **** } #endif - #region Reflect hidden fields added on callback - if ( _magicAjaxContext.IsPageNoStoreMode) - { - //Reflect hidden fields newly added on callback - //Aside for __VIEWSTATE, hidden fields that have a name starting - //with "__" are never reflected to the client. These fields are considered - //system hidden fields. - //HACK:is this the way to reflect newly added hidden fields? - MatchCollection hiddenFieldMatches = Util.HiddenInputTagsRegEx.Matches(html); - for (int i = 0; i < hiddenFieldMatches.Count; i++) - { - Match hiddenFieldMatch = hiddenFieldMatches[i]; - string name = hiddenFieldMatch.Groups["name"].Value; - string value = hiddenFieldMatch.Groups["value"].Value; - - // Don't reflect system hidden fields (starting with "__"). - // However, do send "__VIEWSTATE" if it wasn't excluded from the post data - if (!name.StartsWith("__") || (name == "__VIEWSTATE" && _request.Form["__VIEWSTATE"] != null)) - { - if (_request.Form[name] == null) - AjaxCallHelper.WriteAddHiddenFieldScript(name, value); - else - AjaxCallHelper.WriteSetFieldScript(name, value); - } - } - } - #endregion AjaxCallHelper.End(); } else if ( _threadAbortExceptionThrown && !_magicAjaxContext.CompletedAjaxCall ) --- 655,661 ---- } #endif AjaxCallHelper.End(); + } else if ( _threadAbortExceptionThrown && !_magicAjaxContext.CompletedAjaxCall ) *************** *** 779,782 **** --- 672,676 ---- // Handle Server.Transfer AjaxCallHelper.Init(); + string html = _filter.GetHtmlPage(); if (_request.Browser != null && _request.Browser.Browser == "IE") { |
From: Dion O. <dol...@us...> - 2006-01-08 21:46:08
|
Update of /cvsroot/magicajax/magicajax/Core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29861/magicajax/Core Modified Files: MagicAjaxModule.cs Log Message: added some comments Index: MagicAjaxModule.cs =================================================================== RCS file: /cvsroot/magicajax/magicajax/Core/MagicAjaxModule.cs,v retrieving revision 1.56 retrieving revision 1.57 diff -C2 -d -r1.56 -r1.57 *** MagicAjaxModule.cs 8 Jan 2006 21:14:02 -0000 1.56 --- MagicAjaxModule.cs 8 Jan 2006 21:46:00 -0000 1.57 *************** *** 739,743 **** if ( _magicAjaxContext.IsPageNoStoreMode) { ! //reflect hidden fields newly added on callback MatchCollection hiddenFieldMatches = Util.HiddenInputTagsRegEx.Matches(html); for (int i = 0; i < hiddenFieldMatches.Count; i++) --- 739,747 ---- if ( _magicAjaxContext.IsPageNoStoreMode) { ! //Reflect hidden fields newly added on callback ! //Aside for __VIEWSTATE, hidden fields that have a name starting ! //with "__" are never reflected to the client. These fields are considered ! //system hidden fields. ! //HACK:is this the way to reflect newly added hidden fields? MatchCollection hiddenFieldMatches = Util.HiddenInputTagsRegEx.Matches(html); for (int i = 0; i < hiddenFieldMatches.Count; i++) |
From: Dion O. <dol...@us...> - 2006-01-08 21:14:11
|
Update of /cvsroot/magicajax/magicajax/Core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21156/magicajax/Core Modified Files: AjaxCallHelper.cs MagicAjaxModule.cs PageFilter.cs Util.cs Log Message: Added functionality to MagicAjaxModule to track all script blocks, and write back to the client the script blocks that were added on a callback. Same for hidden fields, except the hidden fields starting with "__" (these are considered system hidden fields) Index: PageFilter.cs =================================================================== RCS file: /cvsroot/magicajax/magicajax/Core/PageFilter.cs,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** PageFilter.cs 20 Dec 2005 23:51:40 -0000 1.8 --- PageFilter.cs 8 Jan 2006 21:14:02 -0000 1.9 *************** *** 36,67 **** private Stream _memStream; private MagicAjaxContext _magicAjaxContext; ! public PageFilter(Stream _responseStream) ! { ! this._responseStream = _responseStream; ! this._memStream = new MemoryStream(); ! this._magicAjaxContext = MagicAjaxContext.Current; ! } ! ! public string GetViewStateFieldValue() { ! //TODO: use regular expression (much faster) ! #if NET_2_0 ! string search = "<input type=\"hidden\" name=\"__VIEWSTATE\" id=\"__VIEWSTATE\" value=\""; ! #else ! string search = "<input type=\"hidden\" name=\"__VIEWSTATE\" value=\""; ! #endif ! string html = GetHtmlPage(); ! int si = html.IndexOf(search); ! if (si == -1) ! return null; ! ! si += search.Length; ! int ei = html.IndexOf('\"', si); ! if (ei == -1) ! return null; ! ! return html.Substring(si, ei - si); } #if NET_2_0 --- 36,55 ---- private Stream _memStream; private MagicAjaxContext _magicAjaxContext; + private bool _forceMemoryStreamWriting = false; ! /// <summary> ! /// Filters the response stream, and stores everyting in a memorystream ! /// </summary> ! /// <param name="_responseStream"></param> ! /// <param name="forceMemoryStreamWriting">Force writing to memory, no mather if in ajaxcall or not</param> ! public PageFilter(Stream responseStream, bool forceMemoryStreamWriting) { ! _responseStream = responseStream; ! _memStream = new MemoryStream(); ! _magicAjaxContext = MagicAjaxContext.Current; ! _forceMemoryStreamWriting = forceMemoryStreamWriting; } + + public PageFilter(Stream _responseStream): this(_responseStream, false) {} #if NET_2_0 *************** *** 74,85 **** string html = GetHtmlPage(); ! // Look for webpartmanager object creation script ! string searchWPManager = "<script type=\"text\\/javascript\">\\r\\n\\r\\n__wpm = new WebPartManager\\(\\);\\r\\n(?<WPManagerScript>.*?)<\\/script>"; ! Regex regExWPManager = new Regex(searchWPManager, RegexOptions.Singleline | RegexOptions.Compiled); ! Match match = regExWPManager.Match(html); ! // If no webpartmanager script exists in html -> exit ! if (!match.Success) ! return null; // Stringbuilder to hold the output script --- 62,73 ---- string html = GetHtmlPage(); ! //// Look for webpartmanager object creation script ! //string searchWPManager = "<script type=\"text\\/javascript\">\\r\\n\\r\\n__wpm = new WebPartManager\\(\\);\\r\\n(?<WPManagerScript>.*?)<\\/script>"; ! //Regex regExWPManager = new Regex(searchWPManager, RegexOptions.Singleline | RegexOptions.Compiled); ! //Match match = regExWPManager.Match(html); ! //// If no webpartmanager script exists in html -> exit ! //if (!match.Success) ! // return null; // Stringbuilder to hold the output script *************** *** 98,112 **** } ! // Now append the WebpartManager script ! wpmScript.AppendLine(match.Groups["WPManagerScript"].Value); ! // Now append the webpart menu scripts ! string searchWPMenus = "<script type=\"text\\/javascript\">\\r\\n(?<MenuScript>var menuWebPart_.*?)<\\/script>"; ! Regex regExMenuScripts = new Regex(searchWPMenus, RegexOptions.Singleline | RegexOptions.Compiled); ! MatchCollection matches = regExMenuScripts.Matches(html); //ei ! for (int i = 0; i < matches.Count; i++) ! { ! wpmScript.AppendLine(matches[i].Groups["MenuScript"].Value); ! } return wpmScript.ToString(); --- 86,100 ---- } ! //// Now append the WebpartManager script ! //wpmScript.AppendLine(match.Groups["WPManagerScript"].Value); ! //// Now append the webpart menu scripts ! //string searchWPMenus = "<script type=\"text\\/javascript\">\\r\\n(?<MenuScript>var menuWebPart_.*?)<\\/script>"; ! //Regex regExMenuScripts = new Regex(searchWPMenus, RegexOptions.Singleline | RegexOptions.Compiled); ! //MatchCollection matches = regExMenuScripts.Matches(html); //ei ! //for (int i = 0; i < matches.Count; i++) ! //{ ! // wpmScript.AppendLine(matches[i].Groups["MenuScript"].Value); ! //} return wpmScript.ToString(); *************** *** 183,186 **** --- 171,180 ---- public override void Write(byte[] buffer, int offset, int count) { + if (_forceMemoryStreamWriting) + { + _memStream.Write(buffer, offset, count); + return; + } + if (_magicAjaxContext.IsAjaxCall) { Index: AjaxCallHelper.cs =================================================================== RCS file: /cvsroot/magicajax/magicajax/Core/AjaxCallHelper.cs,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** AjaxCallHelper.cs 22 Dec 2005 23:06:51 -0000 1.17 --- AjaxCallHelper.cs 8 Jan 2006 21:14:02 -0000 1.18 *************** *** 25,28 **** --- 25,29 ---- using System.Web.UI; using System.Collections; + using System.Collections.Specialized; using System.Text; *************** *** 270,274 **** /// <summary> ! /// Produces the javascript that will a new element on the page. /// </summary> /// <param name="parentID">The id of the element that will contain the new element</param> --- 271,275 ---- /// <summary> ! /// Produces the javascript that will add a new element on the page. /// </summary> /// <param name="parentID">The id of the element that will contain the new element</param> *************** *** 278,285 **** public static void WriteAddElementScript(string parentID, string tagName, string elementID, string html, string beforeElemID) { string before = (beforeElemID != null) ? String.Format("\"{0}\"", beforeElemID) : "null"; ! Write( String.Format("AJAXCbo.AddElement(\"{0}\",\"{1}\",\"{2}\",{3},{4});\r\n", parentID, tagName, elementID, EncodeString(html), before) ); } /// <summary> /// Provides the javascript that will remove an existing element from the page. --- 279,310 ---- public static void WriteAddElementScript(string parentID, string tagName, string elementID, string html, string beforeElemID) { + parentID = parentID.StartsWith("document.") ? parentID : string.Format("\"{0}\"", parentID); string before = (beforeElemID != null) ? String.Format("\"{0}\"", beforeElemID) : "null"; ! Write( String.Format("AJAXCbo.AddElement({0},\"{1}\",\"{2}\",{3},{4});\r\n", parentID, tagName, elementID, EncodeString(html), before) ); ! } ! ! /// <summary> ! /// Produces the javascript that will add a script element to the page. ! /// </summary> ! /// <param name="scriptText">The script text</param> ! /// <param name="scriptText">The script attributes</param> ! public static void WriteAddScriptElementScript(string scriptText, NameValueCollection scriptAttributes) ! { ! StringBuilder sbuilder = new StringBuilder("new Array("); ! for (int i=0; i<scriptAttributes.Count; i++) ! { ! if (i>0) ! sbuilder.Append(","); ! sbuilder.AppendFormat("\"{0}\",\"{1}\"", scriptAttributes.Keys[i], scriptAttributes[i]); ! } ! sbuilder.Append(")"); ! Write(String.Format("AJAXCbo.AddScript({0},{1});\r\n", EncodeString(scriptText), sbuilder.ToString())); } + public static void WriteAddHiddenFieldScript(string elementName, string elementValue) + { + Write(String.Format("AJAXCbo.AddHiddenField(\"{0}\",{1});\r\n", elementName, EncodeString(elementValue))); + } + /// <summary> /// Provides the javascript that will remove an existing element from the page. *************** *** 421,430 **** throw new MagicAjaxException("Script writing level should be 0 at the end of AjaxCall. IncreaseWritingLevel calls do not match DecreaseWritingLevel calls."); - WriteEndSignature(); - HttpResponse hr = HttpContext.Current.Response; hr.Clear(); MergeNextWritingLevelRecursive (0); hr.Write ((_sbWritingLevels[0] as StringBuilder).ToString()); --- 446,456 ---- throw new MagicAjaxException("Script writing level should be 0 at the end of AjaxCall. IncreaseWritingLevel calls do not match DecreaseWritingLevel calls."); HttpResponse hr = HttpContext.Current.Response; hr.Clear(); MergeNextWritingLevelRecursive (0); + + WriteEndSignature(); + hr.Write ((_sbWritingLevels[0] as StringBuilder).ToString()); Index: Util.cs =================================================================== RCS file: /cvsroot/magicajax/magicajax/Core/Util.cs,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** Util.cs 7 Jan 2006 08:03:47 -0000 1.21 --- Util.cs 8 Jan 2006 21:14:02 -0000 1.22 *************** *** 44,47 **** --- 44,49 ---- public static Regex FormElementOptionSelectedRegEx = new Regex(@"<option.*?(?<selected>selected=(""|'|)selected(""|'|)(\s+|(?=>))).*?>", _options); public static Regex ScriptPatternRegEx = new Regex(Util.ScriptPattern, RegexOptions.IgnoreCase); + public static Regex ScriptTagsRegEx = new Regex("<script\\s((?<attrname>[-\\w]+)=\"(?<attrvalue>.*?)\"\\s?)*\\s*>(?<script>.*?)</script>", _options); + public static Regex HiddenInputTagsRegEx = new Regex("<input type=\"hidden\" name=\"(?<name>[-\\w]+)\"\\s.*?\\svalue=\"(?<value>[-\\w]*)\" />", _options); #endregion *************** *** 95,99 **** public static string GetFingerprint(string input) { ! input = GetHtmlWithClearedFormValues(input); MagicAjax.Configuration.OutputCompareMode compareMode = MagicAjaxContext.Current.Configuration.CompareMode; --- 97,101 ---- public static string GetFingerprint(string input) { ! input = GetHtmlWithClearedFormValues(input); MagicAjax.Configuration.OutputCompareMode compareMode = MagicAjaxContext.Current.Configuration.CompareMode; Index: MagicAjaxModule.cs =================================================================== RCS file: /cvsroot/magicajax/magicajax/Core/MagicAjaxModule.cs,v retrieving revision 1.55 retrieving revision 1.56 diff -C2 -d -r1.55 -r1.56 *** MagicAjaxModule.cs 6 Jan 2006 00:58:37 -0000 1.55 --- MagicAjaxModule.cs 8 Jan 2006 21:14:02 -0000 1.56 *************** *** 151,154 **** --- 151,157 ---- } } + + // Register hidden field to hold script fingerprints + page.RegisterHiddenField("__MAGICAJAX_SCRIPT_FINGERPRINTS", string.Empty); // Save to page any changes that may occured to Configuration *************** *** 445,450 **** { return; //if this wasn't a .aspx request, don't process ! } ! string pageKey = _request.QueryString["__AJAX_PAGEUNLOAD"]; if (pageKey != null) --- 448,453 ---- { return; //if this wasn't a .aspx request, don't process ! } ! string pageKey = _request.QueryString["__AJAX_PAGEUNLOAD"]; if (pageKey != null) *************** *** 456,463 **** application.CompleteRequest(); } // Continue only if it is a postback or an AjaxCall ! if ("GET" == _request.HttpMethod) return; Page currentPage = HttpContext.Current.Handler as Page; --- 459,481 ---- application.CompleteRequest(); } + + _magicAjaxContext.IsAjaxCall = (_request.Form["__AJAXCALL"] != null); + + // Set the pagefilter for non-ajax calls, so we can find the script blocks + // written to the client, and also write fingerprints for them. + // This way, on a callback we can see which script blocks were added since + // last call. + //HACK: it would be better to only set a filter when page contains AjaxPanels + if (!_magicAjaxContext.IsAjaxCall) + { + _filter = new PageFilter(_response.Filter, true); + _response.Filter = _filter; + } // Continue only if it is a postback or an AjaxCall ! if (_request.HttpMethod == "GET") ! { return; + } Page currentPage = HttpContext.Current.Handler as Page; *************** *** 472,477 **** } #endif ! ! _magicAjaxContext.IsAjaxCall = (_request.Form["__AJAXCALL"] != null); string configState = _request.Form["__MAGICAJAX_CONFIG"]; if (configState != null) --- 490,494 ---- } #endif ! string configState = _request.Form["__MAGICAJAX_CONFIG"]; if (configState != null) *************** *** 497,500 **** --- 514,522 ---- AjaxCallHelper.Init(); + + // Increase writing level just after Init. So in ApplicationEndRequest we + // can decrease it to write script before all scripts already written. + //HACK: replace this with a more elegant solution + AjaxCallHelper.IncreaseWritingLevel(); try *************** *** 588,591 **** --- 610,618 ---- AjaxCallHelper.Init(); + // Increase writing level just after Init. So in ApplicationEndRequest we + // can decrease it to write script before all scripts already written. + //HACK: replace this with a more elegant solution + AjaxCallHelper.IncreaseWritingLevel(); + try { *************** *** 622,640 **** try { ! if ( _magicAjaxContext.IsAjaxCall ) { ! if ( _processedAjaxCall ) { ! // If the ViewState wasn't excluded from the post data, retrieve ! // it and send it to client. ! if ( _magicAjaxContext.IsPageNoStoreMode && _request.Form["__VIEWSTATE"] != null ) { ! string vsValue = _filter.GetViewStateFieldValue(); ! if (vsValue != null && _request.Form["__VIEWSTATE"] != vsValue) { ! AjaxCallHelper.WriteSetFieldScript("__VIEWSTATE", vsValue); } } #if NET_2_0 Page currentPage = HttpContext.Current.Handler as Page; --- 649,721 ---- try { ! string html = _filter.GetHtmlPage(); ! ! #region Reflect new/updated script elements ! ArrayList previousScriptFPs = new ArrayList(); ! if (_request["__MAGICAJAX_SCRIPT_FINGERPRINTS"] != null) { ! previousScriptFPs.AddRange(_request["__MAGICAJAX_SCRIPT_FINGERPRINTS"].Split(';')); ! } ! ! string scriptfingerprintSearch = "id=\"__MAGICAJAX_SCRIPT_FINGERPRINTS\" value=\""; ! ! // Find all scripts, and send fingerprints to client (in a hidden field) ! StringBuilder sbuilder = new StringBuilder(); ! MatchCollection matches = Util.ScriptTagsRegEx.Matches(html); ! for (int i = 0; i < matches.Count; i++) ! { ! Match match = matches[i]; ! string fullScript = match.Value; ! string scriptFP = Util.GetFingerprint(fullScript); ! ! if (i == 0) ! sbuilder.Append(";"); ! sbuilder.Append(scriptFP); ! ! if (_magicAjaxContext.IsAjaxCall && _processedAjaxCall) { ! // If this is a new script block, create call to create script ! // on client ! if (!previousScriptFPs.Contains(scriptFP)) { ! CaptureCollection attrnamesOption = match.Groups["attrname"].Captures; ! CaptureCollection attrvaluesOption = match.Groups["attrvalue"].Captures; ! ! NameValueCollection scriptAttributes = new NameValueCollection(); ! for (int j = 0; j < attrnamesOption.Count; j++) { ! scriptAttributes.Add(attrnamesOption[j].Value, attrvaluesOption[j].Value); } + + string scriptText = match.Groups["script"].Value; + + AjaxCallHelper.WriteAddScriptElementScript(scriptText, scriptAttributes); } + } + } + string scriptFPs = sbuilder.ToString(); + if (!_magicAjaxContext.IsAjaxCall) + { + // This is a non-ajax request. Add a hidden field to the output html that contains + // the fingerprints of all script elements. + html = html.Replace(scriptfingerprintSearch, scriptfingerprintSearch + scriptFPs); + _response.Write(html); + _response.End(); + } + else if (_processedAjaxCall) + { + AjaxCallHelper.WriteSetFieldScript("__MAGICAJAX_SCRIPT_FINGERPRINTS", scriptFPs); + } + #endregion + + if ( _magicAjaxContext.IsAjaxCall ) + { + // Decrease writing level to write script before all scripts already written. + //HACK: replace this with a more elegant solution + AjaxCallHelper.DecreaseWritingLevel(); + + if ( _processedAjaxCall ) + { #if NET_2_0 Page currentPage = HttpContext.Current.Handler as Page; *************** *** 655,661 **** } #endif ! AjaxCallHelper.End(); } else if ( _threadAbortExceptionThrown && !_magicAjaxContext.CompletedAjaxCall ) --- 736,764 ---- } #endif + #region Reflect hidden fields added on callback + if ( _magicAjaxContext.IsPageNoStoreMode) + { + //reflect hidden fields newly added on callback + MatchCollection hiddenFieldMatches = Util.HiddenInputTagsRegEx.Matches(html); + for (int i = 0; i < hiddenFieldMatches.Count; i++) + { + Match hiddenFieldMatch = hiddenFieldMatches[i]; + string name = hiddenFieldMatch.Groups["name"].Value; + string value = hiddenFieldMatch.Groups["value"].Value; ! // Don't reflect system hidden fields (starting with "__"). ! // However, do send "__VIEWSTATE" if it wasn't excluded from the post data ! if (!name.StartsWith("__") || (name == "__VIEWSTATE" && _request.Form["__VIEWSTATE"] != null)) ! { ! if (_request.Form[name] == null) ! AjaxCallHelper.WriteAddHiddenFieldScript(name, value); ! else ! AjaxCallHelper.WriteSetFieldScript(name, value); ! } ! } ! } ! #endregion + AjaxCallHelper.End(); } else if ( _threadAbortExceptionThrown && !_magicAjaxContext.CompletedAjaxCall ) *************** *** 672,676 **** // Handle Server.Transfer AjaxCallHelper.Init(); - string html = _filter.GetHtmlPage(); if (_request.Browser != null && _request.Browser.Browser == "IE") { --- 775,778 ---- |
From: Dion O. <dol...@us...> - 2006-01-08 21:14:11
|
Update of /cvsroot/magicajax/magicajax/Core/UI In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21156/magicajax/Core/UI Modified Files: RenderedByScriptControl.cs Log Message: Added functionality to MagicAjaxModule to track all script blocks, and write back to the client the script blocks that were added on a callback. Same for hidden fields, except the hidden fields starting with "__" (these are considered system hidden fields) Index: RenderedByScriptControl.cs =================================================================== RCS file: /cvsroot/magicajax/magicajax/Core/UI/RenderedByScriptControl.cs,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** RenderedByScriptControl.cs 3 Jan 2006 01:49:09 -0000 1.17 --- RenderedByScriptControl.cs 8 Jan 2006 21:14:02 -0000 1.18 *************** *** 194,198 **** // We cannot avoid this because Firefox also keeps any changes that occured // to ViewState, so we need the controls to keep their changes. ! hiddenStore = this.ClientID + "$RBS_Store"; } else --- 194,198 ---- // We cannot avoid this because Firefox also keeps any changes that occured // to ViewState, so we need the controls to keep their changes. ! hiddenStore = string.Format("__{0}$RBS_Store", this.ClientID); } else *************** *** 201,205 **** // a different name for the hidden field at each page request so that // it can be reset for Firefox's "Refresh". ! hiddenStore = this.ClientID + "$RBS_Store" + DateTime.Now.Ticks; } --- 201,205 ---- // a different name for the hidden field at each page request so that // it can be reset for Firefox's "Refresh". ! hiddenStore = string.Format("__{0}$RBS_Store{1}", this.ClientID, DateTime.Now.Ticks); } |
From: Dion O. <dol...@us...> - 2006-01-08 21:14:11
|
Update of /cvsroot/magicajax/magicajax/Core/script In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21156/magicajax/Core/script Modified Files: AjaxCallObject.js Log Message: Added functionality to MagicAjaxModule to track all script blocks, and write back to the client the script blocks that were added on a callback. Same for hidden fields, except the hidden fields starting with "__" (these are considered system hidden fields) Index: AjaxCallObject.js =================================================================== RCS file: /cvsroot/magicajax/magicajax/Core/script/AjaxCallObject.js,v retrieving revision 1.44 retrieving revision 1.45 diff -C2 -d -r1.44 -r1.45 *** AjaxCallObject.js 7 Jan 2006 12:30:59 -0000 1.44 --- AjaxCallObject.js 8 Jan 2006 21:14:02 -0000 1.45 *************** *** 748,759 **** } ! AjaxCallObject.prototype.AddScript = function(scriptHtml) { ! var scriptHolder = document.createElement("span"); ! scriptHolder.style.visibility = "hidden"; ! scriptHolder.innerHTML = " "+ scriptHtml.replace("<script","<script defer"); document.forms[0].appendChild(scriptHolder); } AjaxCallObject.prototype.RemoveElement = function(parentID, elementID) { --- 748,774 ---- } ! AjaxCallObject.prototype.AddScript = function(scriptText, scriptAttributes) { ! var scriptHolder = document.createElement('script'); ! scriptHolder.text = scriptText; ! ! if (scriptAttributes != null) ! for (i=0; i < scriptAttributes.length; i+=2) ! scriptHolder.setAttribute(scriptAttributes[i], scriptAttributes[i+1]); ! document.forms[0].appendChild(scriptHolder); } + AjaxCallObject.prototype.AddHiddenField = function(elementName, elementValue) + { + var hiddenField = document.createElement('input'); + hiddenField.type = "hidden"; + hiddenField.name = elementName; + hiddenField.id = elementName; + hiddenField.value = elementValue; + + document.forms[0].appendChild(hiddenField); + } + AjaxCallObject.prototype.RemoveElement = function(parentID, elementID) { |
From: Dion O. <dol...@us...> - 2006-01-07 12:31:07
|
Update of /cvsroot/magicajax/magicajax/Core/script In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22509/magicajax/Core/script Modified Files: AjaxCallObject.js Log Message: Added 'AddScript' function, that is able to add complete script tags to the form. Index: AjaxCallObject.js =================================================================== RCS file: /cvsroot/magicajax/magicajax/Core/script/AjaxCallObject.js,v retrieving revision 1.43 retrieving revision 1.44 diff -C2 -d -r1.43 -r1.44 *** AjaxCallObject.js 6 Jan 2006 00:58:37 -0000 1.43 --- AjaxCallObject.js 7 Jan 2006 12:30:59 -0000 1.44 *************** *** 748,751 **** --- 748,759 ---- } + AjaxCallObject.prototype.AddScript = function(scriptHtml) + { + var scriptHolder = document.createElement("span"); + scriptHolder.style.visibility = "hidden"; + scriptHolder.innerHTML = " "+ scriptHtml.replace("<script","<script defer"); + document.forms[0].appendChild(scriptHolder); + } + AjaxCallObject.prototype.RemoveElement = function(parentID, elementID) { |
From: Argiris K. <be...@us...> - 2006-01-07 08:03:58
|
Update of /cvsroot/magicajax/magicajax/Core/UI/Controls In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11742/Core/UI/Controls Modified Files: AjaxPanel.cs Log Message: Reverted the changes that checked for <input> tags of type 'hidden' inside an AjaxPanel Index: AjaxPanel.cs =================================================================== RCS file: /cvsroot/magicajax/magicajax/Core/UI/Controls/AjaxPanel.cs,v retrieving revision 1.48 retrieving revision 1.49 diff -C2 -d -r1.48 -r1.49 *** AjaxPanel.cs 6 Jan 2006 04:04:05 -0000 1.48 --- AjaxPanel.cs 7 Jan 2006 08:03:47 -0000 1.49 *************** *** 541,545 **** { case "text": - case "hidden": if (value != form[name]) AjaxCallHelper.WriteSetFieldScript (clientID, value); --- 541,544 ---- |
From: Argiris K. <be...@us...> - 2006-01-07 08:03:58
|
Update of /cvsroot/magicajax/magicajax/Core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11742/Core Modified Files: Util.cs Log Message: Reverted the changes that checked for <input> tags of type 'hidden' inside an AjaxPanel Index: Util.cs =================================================================== RCS file: /cvsroot/magicajax/magicajax/Core/Util.cs,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** Util.cs 6 Jan 2006 04:04:05 -0000 1.20 --- Util.cs 7 Jan 2006 08:03:47 -0000 1.21 *************** *** 166,170 **** { case "text": - case "hidden": if (attrNameValues.ContainsKey("value")) { --- 166,169 ---- |
From: Argiris K. <be...@us...> - 2006-01-06 04:04:14
|
Update of /cvsroot/magicajax/magicajax/Core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21657/Core Modified Files: Util.cs Log Message: Added automatic handling for the INPUT tags of type 'hidden' (those that are found inside an AjaxPanel, like FCKeditor's control) Index: Util.cs =================================================================== RCS file: /cvsroot/magicajax/magicajax/Core/Util.cs,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** Util.cs 22 Dec 2005 23:06:51 -0000 1.19 --- Util.cs 6 Jan 2006 04:04:05 -0000 1.20 *************** *** 166,169 **** --- 166,170 ---- { case "text": + case "hidden": if (attrNameValues.ContainsKey("value")) { |
From: Argiris K. <be...@us...> - 2006-01-06 04:04:13
|
Update of /cvsroot/magicajax/magicajax/Core/UI/Controls In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21657/Core/UI/Controls Modified Files: AjaxPanel.cs Log Message: Added automatic handling for the INPUT tags of type 'hidden' (those that are found inside an AjaxPanel, like FCKeditor's control) Index: AjaxPanel.cs =================================================================== RCS file: /cvsroot/magicajax/magicajax/Core/UI/Controls/AjaxPanel.cs,v retrieving revision 1.47 retrieving revision 1.48 diff -C2 -d -r1.47 -r1.48 *** AjaxPanel.cs 5 Jan 2006 01:07:33 -0000 1.47 --- AjaxPanel.cs 6 Jan 2006 04:04:05 -0000 1.48 *************** *** 541,544 **** --- 541,545 ---- { case "text": + case "hidden": if (value != form[name]) AjaxCallHelper.WriteSetFieldScript (clientID, value); |
From: Argiris K. <be...@us...> - 2006-01-06 00:58:45
|
Update of /cvsroot/magicajax/magicajax/Core/script In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23394/Core/script Modified Files: AjaxCallObject.js Log Message: Change in the AjaxCallObject.js. MagicAjax now invokes all listeners for the 'submit' event (fixes a FCKEditor issue) Index: AjaxCallObject.js =================================================================== RCS file: /cvsroot/magicajax/magicajax/Core/script/AjaxCallObject.js,v retrieving revision 1.42 retrieving revision 1.43 diff -C2 -d -r1.42 -r1.43 *** AjaxCallObject.js 5 Jan 2006 11:26:00 -0000 1.42 --- AjaxCallObject.js 6 Jan 2006 00:58:37 -0000 1.43 *************** *** 3,11 **** __bUnloadStoredPage = false; __bTracing = false; ! __PreviousOnFormSubmit = null; __PreviousPostBack = null; - __PreviousOnPageLoad = null; - __PreviousOnPageBeforeUnload = null; - __PreviousOnPageUnload = null; __TraceWindows = new Array(); __ClockID = 0; --- 3,8 ---- __bUnloadStoredPage = false; __bTracing = false; ! __doingSubmit = false; __PreviousPostBack = null; __TraceWindows = new Array(); __ClockID = 0; *************** *** 197,206 **** } AjaxCallObject.prototype.HookAjaxCall = function(bPageIsStored, bUnloadStoredPage, bTracing) { __Netscape8AndUp = navigator.appName == "Netscape" && navigator.vendor == "Netscape" && parseInt(navigator.appVersion) >= 5; ! __PreviousOnFormSubmit = document.forms[0].onsubmit; ! document.forms[0].onsubmit = this.OnFormSubmit; if (typeof __doPostBack != 'undefined') --- 194,222 ---- } + AjaxCallObject.prototype.AddEventListener = function(obj, eventName, fn) + { + if (obj.addEventListener) + obj.addEventListener(eventName, fn, false); + else + obj.attachEvent("on"+eventName, fn); + } + + AjaxCallObject.prototype.DispatchEvent = function(obj, eventName) + { + if (obj.fireEvent) + obj.fireEvent("on"+eventName); + else + { + var evt = document.createEvent("Events") + evt.initEvent(eventName, true, true); + obj.dispatchEvent(evt); + } + } + AjaxCallObject.prototype.HookAjaxCall = function(bPageIsStored, bUnloadStoredPage, bTracing) { __Netscape8AndUp = navigator.appName == "Netscape" && navigator.vendor == "Netscape" && parseInt(navigator.appVersion) >= 5; ! this.AddEventListener(document.forms[0], "submit", this.OnFormSubmit); if (typeof __doPostBack != 'undefined') *************** *** 222,238 **** if ( !bPageIsStored || !bUnloadStoredPage ) { ! __PreviousOnPageLoad = window.onload; ! window.onload = this.OnPageLoad; ! ! __PreviousOnPageBeforeUnload = window.onbeforeunload; ! window.onbeforeunload = this.OnPageBeforeUnload; } ! __PreviousOnPageUnload = window.onunload; ! window.onunload = this.OnPageUnload; } ! AjaxCallObject.prototype.OnFormSubmit = function() { // Empty the cached html of RenderedByScript controls if (typeof(RBS_Controls) != "undefined") --- 238,257 ---- if ( !bPageIsStored || !bUnloadStoredPage ) { ! this.AddEventListener(window, "load", this.OnPageLoad); ! this.AddEventListener(window, "beforeunload", this.OnPageBeforeUnload); } ! this.AddEventListener(window, "unload", this.OnPageUnload); } ! AjaxCallObject.prototype.OnFormSubmit = function(e) { + if (__doingSubmit) + { + if (e.preventDefault) + e.preventDefault(); + return false; + } + // Empty the cached html of RenderedByScript controls if (typeof(RBS_Controls) != "undefined") *************** *** 254,265 **** } - if (__PreviousOnFormSubmit != null) - if ( __PreviousOnFormSubmit() == false ) - return false; - var cbType = AJAXCbo.GetAjaxCallType(target); if (cbType != "none") { ! return !AJAXCbo.DoAjaxCall(target.name, "", cbType, AJAXCbo.GetAjaxScopeID(target)); } else --- 273,291 ---- } var cbType = AJAXCbo.GetAjaxCallType(target); if (cbType != "none") { ! __doingSubmit = true; ! AJAXCbo.DispatchEvent(document.forms[0], "submit"); ! __doingSubmit = false; ! ! if (AJAXCbo.DoAjaxCall(target.name, "", cbType, AJAXCbo.GetAjaxScopeID(target))) ! { ! if (e.preventDefault) ! e.preventDefault(); ! return false; ! } ! else ! return true; } else *************** *** 284,287 **** --- 310,317 ---- if (cbType != "none") { + __doingSubmit = true; + AJAXCbo.DispatchEvent(document.forms[0], "submit"); + __doingSubmit = false; + AJAXCbo.DoAjaxCall(eventTarget, eventArgument, cbType, AJAXCbo.GetAjaxScopeID(target)); } *************** *** 310,315 **** } } - if (__PreviousOnPageLoad != null) - return __PreviousOnPageLoad(); } --- 340,343 ---- *************** *** 323,328 **** RBS_Controls_Store[i].value = "HTML:" + RBS_Controls[i].innerHTML; } - if (__PreviousOnPageBeforeUnload != null) - return __PreviousOnPageBeforeUnload(); } --- 351,354 ---- *************** *** 355,361 **** oThis.XmlHttp.send(null); } - - if (__PreviousOnPageUnload != null) - return __PreviousOnPageUnload(); } --- 381,384 ---- |
From: Argiris K. <be...@us...> - 2006-01-06 00:58:44
|
Update of /cvsroot/magicajax/magicajax/Core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23394/Core Modified Files: MagicAjaxModule.cs Log Message: Change in the AjaxCallObject.js. MagicAjax now invokes all listeners for the 'submit' event (fixes a FCKEditor issue) Index: MagicAjaxModule.cs =================================================================== RCS file: /cvsroot/magicajax/magicajax/Core/MagicAjaxModule.cs,v retrieving revision 1.54 retrieving revision 1.55 diff -C2 -d -r1.54 -r1.55 *** MagicAjaxModule.cs 27 Dec 2005 22:03:42 -0000 1.54 --- MagicAjaxModule.cs 6 Jan 2006 00:58:37 -0000 1.55 *************** *** 101,105 **** string STARTUP_SCRIPT_FORMAT = @" ! <script language='javascript'> if (typeof(AJAXCbo) == 'undefined') alert(""Unable to find script library '{0}/{1}'. Copy the file to the required location, or change the 'scriptPath' setting at magicAjax section of web.config.""); --- 101,105 ---- string STARTUP_SCRIPT_FORMAT = @" ! <script type=""text/javascript""> if (typeof(AJAXCbo) == 'undefined') alert(""Unable to find script library '{0}/{1}'. Copy the file to the required location, or change the 'scriptPath' setting at magicAjax section of web.config.""); |
From: Argiris K. <be...@us...> - 2006-01-05 11:26:11
|
Update of /cvsroot/magicajax/magicajax/Docs In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25472/Docs Modified Files: Changelog.html Log Message: --Fix for incompatibility with flash applets --Fix for an Opera bug Index: Changelog.html =================================================================== RCS file: /cvsroot/magicajax/magicajax/Docs/Changelog.html,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** Changelog.html 5 Jan 2006 01:07:34 -0000 1.21 --- Changelog.html 5 Jan 2006 11:26:00 -0000 1.22 *************** *** 58,61 **** --- 58,63 ---- <ul> <LI> + Fix for incompatibility with flash applets + <LI> Fix for the problem of the AjaxPanel not displaying its contents on VS 2005 when in a UserControl |
From: Argiris K. <be...@us...> - 2006-01-05 11:26:11
|
Update of /cvsroot/magicajax/magicajax/Core/script In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25472/Core/script Modified Files: AjaxCallObject.js Log Message: --Fix for incompatibility with flash applets --Fix for an Opera bug Index: AjaxCallObject.js =================================================================== RCS file: /cvsroot/magicajax/magicajax/Core/script/AjaxCallObject.js,v retrieving revision 1.41 retrieving revision 1.42 diff -C2 -d -r1.41 -r1.42 *** AjaxCallObject.js 3 Jan 2006 01:49:09 -0000 1.41 --- AjaxCallObject.js 5 Jan 2006 11:26:00 -0000 1.42 *************** *** 397,401 **** curElem = theform.elements[i]; eName = curElem.name; ! if( eName && eName != '') { if( eName == '__EVENTTARGET' || eName == '__EVENTARGUMENT' ) --- 397,401 ---- curElem = theform.elements[i]; eName = curElem.name; ! if( eName && eName != '' && curElem.tagName != "EMBED") { if( eName == '__EVENTTARGET' || eName == '__EVENTARGUMENT' ) *************** *** 534,537 **** --- 534,544 ---- AjaxCallObject.prototype.OnError = function(status, statusText, responseText) { + if (status==200) + { + // a weird bug of Opera sometimes invokes OnError when there's no error + this.OnComplete(responseText); + return; + } + if (__bTracing) { |
From: Argiris K. <be...@us...> - 2006-01-05 01:07:44
|
Update of /cvsroot/magicajax/magicajax/Docs In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19417/Docs Modified Files: Changelog.html Log Message: Fix for the problem of the AjaxPanel not displaying its contents on VS 2005 when in a UserControl Index: Changelog.html =================================================================== RCS file: /cvsroot/magicajax/magicajax/Docs/Changelog.html,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** Changelog.html 3 Jan 2006 01:49:09 -0000 1.20 --- Changelog.html 5 Jan 2006 01:07:34 -0000 1.21 *************** *** 58,61 **** --- 58,64 ---- <ul> <LI> + Fix for the problem of the AjaxPanel not displaying its contents on VS + 2005 when in a UserControl + <LI> New MagicAjax attributes for ASP.NET controls (AjaxLocalScope, ExcludeFlags) <LI> |