PDA

View Full Version : [UNKNOWN][3.0rc2/2.2x] Ext.isReady may not be true in Fx/Opera if scripts in BODY



rrutkows
23 Sep 2008, 6:53 AM
Consider the following example


<html>
<head>
</head>

<body>
<script type="text/javascript" src="../adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="../ext-all-debug.js"></script>
<script type="text/javascript">
function test()
{
if (!Ext.isReady)
{
Ext.onReady(test);
return;
}
document.write("Ext.isReady");
}
setTimeout(test, 1000);//make sure test is executed after load/DOMContentLoaded events
</script>
</body>
</html>


The expected output is to see an "Ext.isReady" string.

On Fx 2.0.0.16 and Opera 9.52 no such string appears.

The suspected reason: The fireDocReady function of the EventManager has no chance to be executed if there were no onDocumentReady call before the load/DOMContentLoaded events. The example works in IE, because, for IE, the initDocReady function calls the fireDocReady directly.

And why does it works, if the scripts are included in the HEAD? My guess, by accident (there is no BODY yet, while the following is being executed, and hence the onReady(=onDocumentReady) is being called):


// Initialize doc classes
(function(){
var initExtCss = function(){
// find the body element
var bd = document.body || document.getElementsByTagName('body')[0];
if(!bd){ return false; }
//do something
return true;
}

if(!initExtCss()){
Ext.onReady(initExtCss);
}
})();


Now, why would one want to include the scripts in the BODY instead of the HEAD? Well, for example, if one uses the ASP.NET AJAX ScriptManager to load the scripts embedded in a dll.

Regards
Rudy

hendricd
23 Sep 2008, 8:55 AM
One would expect that. Doing a document.write after the page is rendered wipes out the whole page. :-?

See this thread/post (http://extjs.com/forum/showthread.php?p=226068#post226068).

rrutkows
23 Sep 2008, 11:23 PM
OK, replace document.write with an alert. It will pop up on Ext 2.0.1. It won't pop up on 2.2 (Opera/Firefox). The solution may be to call initDocReady in the EventManager constructor.

Regards
Rudy

rrutkows
25 Mar 2009, 4:25 AM
Bump. Bug still present in 2.2.1. Except now it doesn't even work in IE, because the rolled-back IE part of the initDocReady function indeed wipes out the whole page.

hendricd
25 Mar 2009, 5:31 AM
The latest (unofficial) fixes for all browsers (and supports dynamic loading of Ext 2.x) is located here (http://extjs.com/forum/showthread.php?p=242010#post242010).

rrutkows
25 Mar 2009, 6:34 AM
Thanks for the quick response. Being able to call the fireDocReady method solves my problem.

rrutkows
29 Jun 2009, 1:46 AM
Yet another bump. Doug's patch, which made the fireDocReady method public, somehow didn't make its way into the 3.0 version (as of 3.0 RC 2). Do you consider applying the patch before releasing the 3.0?

Edit: This fix (http://extjs.com/forum/showthread.php?p=348126#post348126) also seems to work and it doesn't require calling the fireDocReady method.

Condor
29 Jun 2009, 2:42 AM
The discussion on Ext.onReady is continuing here (http://extjs.com/forum/showthread.php?t=72159).