From: Dion O. <dol...@us...> - 2005-11-16 22:54:39
|
Update of /cvsroot/magicajax/magicajax/Core/script In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20348/magicajax/Core/script Modified Files: AjaxCallObject.js Log Message: Firefox keeps the form data of a page when doing a page reload or using the back/forward button. However, the 'RenderedByScriptControls' will disappear after a reload. To redraw these controls on the page, we will force a callback from the client's window.onload when the value of hidden field '__RBSCONTROLSEXIST' equals '1'. This hidden field is set to '1' whenever a callback is made. On first page rendering, the value of this hidden field is '0'. Internet Explorer always resets all form data on a page refresh (also the hidden field '__RBSCONTROLSEXIST'), so for IE no extra callback will be forced. Index: AjaxCallObject.js =================================================================== RCS file: /cvsroot/magicajax/magicajax/Core/script/AjaxCallObject.js,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** AjaxCallObject.js 14 Nov 2005 18:50:44 -0000 1.1 --- AjaxCallObject.js 16 Nov 2005 22:54:31 -0000 1.2 *************** *** 6,9 **** --- 6,10 ---- __PreviousOnPageBeforeUnload = null; __PreviousOnPageUnload = null; + __RBSExistField = null; function AjaxCallObject() *************** *** 63,67 **** __PreviousOnFormSubmit = document.forms[0].onsubmit; document.forms[0].onsubmit = this.OnFormSubmit; ! if (typeof __doPostBack != 'undefined') { --- 64,68 ---- __PreviousOnFormSubmit = document.forms[0].onsubmit; document.forms[0].onsubmit = this.OnFormSubmit; ! if (typeof __doPostBack != 'undefined') { *************** *** 69,121 **** __doPostBack = this.DoPostBack; } ! ! if (typeof(RBS_Controls) != "undefined") { ! for (var i=0; i < RBS_Controls.length; i++) ! RBS_Controls_Store[i].setAttribute("ExcludeFromPost", "true"); } - - __PreviousOnPageLoad = window.onload; - window.onload = - function() - { - // Restore the html of RenderedByScript controls - if (typeof(RBS_Controls) != "undefined") - { - for (var i=0; i < RBS_Controls.length; i++) - { - var html = RBS_Controls_Store[i].value; - if (html != "") - { - AJAXCbo.RestoreHtml(RBS_Controls[i], decodeURIComponent(html.substring(5, html.length))); - RBS_Controls_Store[i].value = ""; - } - } - } - if (__PreviousOnPageLoad != null) - return __PreviousOnPageLoad(); - }; - - __PreviousOnPageBeforeUnload = window.onbeforeunload; - window.onbeforeunload = - function() - { - // Save the html of RenderedByScript controls, so that it can be restored for the - // browser's "Back Button" - if (typeof(RBS_Controls) != "undefined") - { - for (var i=0; i < RBS_Controls.length; i++) - RBS_Controls_Store[i].value = "HTML:" + encodeURIComponent(RBS_Controls[i].innerHTML); - } - if (__PreviousOnPageBeforeUnload != null) - return __PreviousOnPageBeforeUnload(); - }; if (bPageIsStored) { __PreviousOnPageUnload = window.onunload; window.onunload = this.OnPageUnload; } ! __bPageIsStored = bPageIsStored; } --- 70,102 ---- __doPostBack = this.DoPostBack; } ! ! // Check if callback should be forced after a browser page reload in FireFox, so all ! // controls rendered by MagicAjax-script will we redrawn on the page. ! __RBSExistField = document.getElementById("__RBSCONTROLSEXIST"); ! if (__RBSExistField != null && __RBSExistField.value == '1') { ! //alert('forcing callback for FireFox'); ! AJAXCbo.DoAjaxCall("",""); ! return; } if (bPageIsStored) { + if (typeof(RBS_Controls) != "undefined") + { + for (var i=0; i < RBS_Controls.length; i++) + RBS_Controls_Store[i].setAttribute("ExcludeFromPost", "true"); + } + + __PreviousOnPageLoad = window.onload; + window.onload = this.OnPageLoad; + + __PreviousOnPageBeforeUnload = window.onbeforeunload; + window.onbeforeunload = this.OnPageBeforeUnload; + __PreviousOnPageUnload = window.onunload; window.onunload = this.OnPageUnload; } ! __bPageIsStored = bPageIsStored; } *************** *** 157,161 **** var elemUniqueID = eventTarget.split("$").join(":"); var ids = elemUniqueID.split(":"); ! // Checks the unique id and its parents until it finds a target element // i.e. for ajaxPanel_grid:row:field it checks --- 138,142 ---- var elemUniqueID = eventTarget.split("$").join(":"); var ids = elemUniqueID.split(":"); ! // Checks the unique id and its parents until it finds a target element // i.e. for ajaxPanel_grid:row:field it checks *************** *** 173,177 **** break; } ! var cbType = AJAXCbo.GetAjaxCallType(target); if (cbType != "none") --- 154,158 ---- break; } ! var cbType = AJAXCbo.GetAjaxCallType(target); if (cbType != "none") *************** *** 186,189 **** --- 167,202 ---- } + AjaxCallObject.prototype.OnPageLoad = function() + { + // Restore the html of RenderedByScript controls + if (typeof(RBS_Controls) != "undefined") + { + for (var i=0; i < RBS_Controls.length; i++) + { + var html = RBS_Controls_Store[i].value; + if (html != "") + { + AJAXCbo.RestoreHtml(RBS_Controls[i], decodeURIComponent(html.substring(5, html.length))); + RBS_Controls_Store[i].value = ""; + } + } + } + if (__PreviousOnPageLoad != null) + return __PreviousOnPageLoad(); + } + + AjaxCallObject.prototype.OnPageBeforeUnload = function() + { + // Save the html of RenderedByScript controls, so that it can be restored for the + // browser's "Back Button" + if (typeof(RBS_Controls) != "undefined") + { + for (var i=0; i < RBS_Controls.length; i++) + RBS_Controls_Store[i].value = "HTML:" + encodeURIComponent(RBS_Controls[i].innerHTML); + } + if (__PreviousOnPageBeforeUnload != null) + return __PreviousOnPageBeforeUnload(); + } + AjaxCallObject.prototype.OnPageUnload = function() { *************** *** 192,201 **** if (index != -1) thePage = thePage.substring(0, index); ! thePage = thePage + "?__AJAX_PAGEUNLOAD=" + encodeURIComponent(document.all["__AJAX_PAGEKEY"].value); ! ! var oThis = AJAXCbo; ! __AJAXCboList.push(oThis); ! AJAXCbo = new AjaxCallObject(); if( oThis.XmlHttp ) --- 205,214 ---- if (index != -1) thePage = thePage.substring(0, index); ! thePage = thePage + "?__AJAX_PAGEUNLOAD=" + encodeURIComponent(document.all["__AJAX_PAGEKEY"].value); ! ! var oThis = AJAXCbo; ! __AJAXCboList.push(oThis); ! AJAXCbo = new AjaxCallObject(); if( oThis.XmlHttp ) *************** *** 206,210 **** oThis.XmlHttp.send(null); } ! if (__PreviousOnPageUnload != null) return __PreviousOnPageUnload(); --- 219,223 ---- oThis.XmlHttp.send(null); } ! if (__PreviousOnPageUnload != null) return __PreviousOnPageUnload(); *************** *** 217,228 **** var thePage = theform.action; var eName = ''; ! theData = '__EVENTTARGET=' + escape(eventTarget.split("$").join(":")) + '&'; theData += '__EVENTARGUMENT=' + encodeURIComponent(eventArgument) + '&'; theData += '__AJAXCALL=true&'; ! if ( ! __bPageIsStored ) theData += '__VIEWSTATE=' + escape(theform.__VIEWSTATE.value).replace(new RegExp('\\+', 'g'), '%2b') + '&'; ! for( var i=0; i<theform.elements.length; i++ ) { --- 230,241 ---- var thePage = theform.action; var eName = ''; ! theData = '__EVENTTARGET=' + escape(eventTarget.split("$").join(":")) + '&'; theData += '__EVENTARGUMENT=' + encodeURIComponent(eventArgument) + '&'; theData += '__AJAXCALL=true&'; ! if ( ! __bPageIsStored ) theData += '__VIEWSTATE=' + escape(theform.__VIEWSTATE.value).replace(new RegExp('\\+', 'g'), '%2b') + '&'; ! for( var i=0; i<theform.elements.length; i++ ) { *************** *** 241,245 **** if ( type == "submit" ) continue; ! if ( type == "textarea" ) { --- 254,258 ---- if ( type == "submit" ) continue; ! if ( type == "textarea" ) { *************** *** 248,254 **** val = val.split("\r\n").join("\n").split("\n").join("\r\n"); } ! val = encodeURIComponent(val); ! if ( type == "select-multiple" ) { --- 261,267 ---- val = val.split("\r\n").join("\n").split("\n").join("\r\n"); } ! val = encodeURIComponent(val); ! if ( type == "select-multiple" ) { *************** *** 269,273 **** if (theData.substring(theData.length-1, theData.length) == "&") theData = theData.substring(0, theData.length-1); ! if( this.XmlHttp ) { --- 282,286 ---- if (theData.substring(theData.length-1, theData.length) == "&") theData = theData.substring(0, theData.length-1); ! if( this.XmlHttp ) { *************** *** 277,281 **** MoveWaitElement(); } ! var oThis = this; __AJAXCboList.push(oThis); --- 290,294 ---- MoveWaitElement(); } ! var oThis = this; __AJAXCboList.push(oThis); *************** *** 314,333 **** } } ! AjaxCallObject.prototype.OnLoading = function() { // Loading } ! AjaxCallObject.prototype.OnLoaded = function() { // Loaded } ! AjaxCallObject.prototype.OnInteractive = function() { // Interactive } ! AjaxCallObject.prototype.OnComplete = function(responseText, responseXml) { --- 327,346 ---- } } ! AjaxCallObject.prototype.OnLoading = function() { // Loading } ! AjaxCallObject.prototype.OnLoaded = function() { // Loaded } ! AjaxCallObject.prototype.OnInteractive = function() { // Interactive } ! AjaxCallObject.prototype.OnComplete = function(responseText, responseXml) { *************** *** 343,350 **** if (waitElement) waitElement.style.visibility = 'hidden'; ! return true; } ! AjaxCallObject.prototype.OnAbort = function() { --- 356,367 ---- if (waitElement) waitElement.style.visibility = 'hidden'; ! ! // Set hidden field to indicate callback was done (used for FireFox page redraw on browser page reload) ! if (__RBSExistField != null) ! __RBSExistField.value = '1'; ! return true; } ! AjaxCallObject.prototype.OnAbort = function() { *************** *** 352,356 **** waitElement.style.visibility = 'hidden'; } ! AjaxCallObject.prototype.OnError = function(status, statusText, responseText) { --- 369,373 ---- waitElement.style.visibility = 'hidden'; } ! AjaxCallObject.prototype.OnError = function(status, statusText, responseText) { *************** *** 359,363 **** document.body.innerHTML = responseText; } ! AjaxCallObject.prototype.ReadyStateChange = function() { --- 376,380 ---- document.body.innerHTML = responseText; } ! AjaxCallObject.prototype.ReadyStateChange = function() { *************** *** 413,421 **** var store = document.createElement("form"); store.innerHTML = html; ! var scripts = store.getElementsByTagName("script"); while (scripts.length > 0) scripts[0].parentNode.removeChild(scripts[0]); ! var elements = new Array(); var coll = store.getElementsByTagName("INPUT"); --- 430,438 ---- var store = document.createElement("form"); store.innerHTML = html; ! var scripts = store.getElementsByTagName("script"); while (scripts.length > 0) scripts[0].parentNode.removeChild(scripts[0]); ! var elements = new Array(); var coll = store.getElementsByTagName("INPUT"); *************** *** 458,462 **** } } ! destElem.innerHTML = store.innerHTML; --- 475,479 ---- } } ! destElem.innerHTML = store.innerHTML; *************** *** 492,496 **** } - AjaxCallObject.prototype.SetAttributesOfControl = function(clientID, attributes) { --- 509,512 ---- *************** *** 518,522 **** place.insertBefore(child, before); } - this.SetHtmlOfElementScript (html, elementID); } --- 534,537 ---- *************** *** 582,586 **** } - var AJAXCbo = new AjaxCallObject(); --- 597,600 ---- *************** *** 622,625 **** } waitElement = elem; ! } ! // end wait element --- 636,639 ---- } waitElement = elem; ! } ! // end wait element \ No newline at end of file |