View Full Version : Reference Ext problem

31 Mar 2011, 2:13 AM

i stuck with the following problem:
When loading a page in a frame, i try not to load ExtJs again and use a simple bootstrap:

if (top && top.Ext) {
Ext = top.Ext;
} else {
document.write('<script type="text/javascript" src="contrib/extjs/adapter/ext/ext-base-debug.js"></script>');
document.write('<script type="text/javascript" src="contrib/extjs/ext-all-debug.js"></script>');
document.write('<script type="text/javascript" src="contrib/extjs/locale/ext-lang-" + ExtLocale ".js"></script>');


This works, but then in head i get an error with this line(s):

Ext.BLANK_IMAGE_URL = "http://localhost/lts/typo3/gfx/clear.gif";
TYPO3.lang = {...

The error given is "TYPO3 is undefined". When i break there is see Ext is referenced correct, but it seems that Ext.ns doesn't work.

Why is this error given and how can i prevent this?

1 Apr 2011, 2:10 AM
*push for another try*

1 Apr 2011, 5:40 AM
I think you'll still need an Ext.onReady(function() { }) block in which you declare your namespace and such.

2 Apr 2011, 1:23 AM
no, that works fine if i include the files instead of referenceing.

Ext.onReady is needed to render components or load data, but definitions work fine without.

2 Apr 2011, 2:21 AM
IIRC, document.write doesn't guarantee script execution happening in the order you document.write them. So in your case, this error would occur if your lang file DL'ed first (makes sense as it's by far the smallest JS file I'm guessing).

2 Apr 2011, 3:16 AM
That's right Mats. But i debugged and stopped at this point and Ext is completely referenced (note - this error only happens for the first part of the if-clause when referencing Ext=top.Ext)

So everything is there, that's what puzzles me, the error shouldn't be there.
It's only the Ext.ns('TYPO3').
if i define it
TYPO3 = top.TYPO3 || ()
everything is fine, but it's dangerous as the frame might overwrite top objects.

2 Apr 2011, 4:50 PM
Sounds like ns doesn't use the window object that you expect...as you're in a frame, debug and make sure ns doesnt reference the parent window.

3 Apr 2011, 4:13 AM
Hi Mats,

it turns out that this is a real problem. You're right that the context of ns is the parent window.

But how can i use the scope of the iframe? It seems that any usage of Ext is in the scope of parent window now. I tried to reference it like
self.Ext = top.Ext
but this don't change the scope.

Do you have an idea how to solve this?

3 Apr 2011, 6:09 AM
I doubt Ext was designed to work in such an advanced way...