1 | define(["dojo/main", "dojo/io/script", "dojo/io/iframe"], function(dojo, ioScript, iframe){ |
---|
2 | dojo.deprecated("dojox.io.scriptFrame", "dojo.io.script now supports parallel requests without dojox.io.scriptFrame", "2.0"); |
---|
3 | dojo.getObject("io.scriptFrame", true, dojox); |
---|
4 | |
---|
5 | //This module extends dojo.io.script to use an iframe for the dojo.io.script.attach calls |
---|
6 | //if the frameDoc argument is passed to dojo.io.script.get(), and if frameDoc is a string (representing |
---|
7 | //the DOM ID of an iframe that should be used for the connection. If frameDoc is not a string, then |
---|
8 | //it is probably a document object, and dojox.io.scriptFrame should not get involved with the request. |
---|
9 | //This is useful in some long-polling comet situations in Firefox and Opera. Those browsers execute scripts |
---|
10 | //in DOM order, not network-receive order, so a long-polling script will block other |
---|
11 | //dynamically appended scripts from running until it completes. By using an iframe |
---|
12 | //for the dojo.io.script requests, this issue can be avoided. |
---|
13 | |
---|
14 | //WARNING: the url argument to dojo.io.script MUST BE relative to the iframe document's location, |
---|
15 | //NOT the parent page location. This iframe document's URL will be (dojo.moduleUrl("dojo", "resources/blank.html") |
---|
16 | //or djConfig.dojoBlankHtmlUrl (for xdomain loading). |
---|
17 | |
---|
18 | dojox.io.scriptFrame = { |
---|
19 | _waiters: {}, |
---|
20 | _loadedIds: {}, |
---|
21 | |
---|
22 | _getWaiters: function(/*String*/frameId){ |
---|
23 | return this._waiters[frameId] || (this._waiters[frameId] = []); |
---|
24 | }, |
---|
25 | |
---|
26 | _fixAttachUrl: function(/*String*/url){ |
---|
27 | // summary: |
---|
28 | // fixes the URL so that |
---|
29 | }, |
---|
30 | |
---|
31 | _loaded: function(/*String*/frameId){ |
---|
32 | // summary: |
---|
33 | // callback used when waiting for a frame to load (related to the usage of |
---|
34 | // the frameId argument to dojo.io.script.get(). |
---|
35 | var waiters = this._getWaiters(frameId); |
---|
36 | this._loadedIds[frameId] = true; |
---|
37 | this._waiters[frameId] = null; |
---|
38 | |
---|
39 | for(var i = 0; i < waiters.length; i++){ |
---|
40 | var ioArgs = waiters[i]; |
---|
41 | ioArgs.frameDoc = iframe.doc(dojo.byId(frameId)); |
---|
42 | ioScript.attach(ioArgs.id, ioArgs.url, ioArgs.frameDoc); |
---|
43 | } |
---|
44 | } |
---|
45 | }; |
---|
46 | |
---|
47 | //Hold on to the old _canAttach function. |
---|
48 | var oldCanAttach = ioScript._canAttach; |
---|
49 | var scriptFrame = dojox.io.scriptFrame; |
---|
50 | |
---|
51 | //Define frame-aware _canAttach method on dojo.io.script |
---|
52 | ioScript._canAttach = function(/*Object*/ioArgs){ |
---|
53 | // summary: |
---|
54 | // provides an override of dojo.io.script._canAttach to check for |
---|
55 | // the existence of a the args.frameDoc property. If it is there, and it is a string, |
---|
56 | // not a document, then create the iframe with an ID of frameDoc, and use that for the calls. |
---|
57 | // If frameDoc is a document, then dojox.io.scriptFrame should not get involved. |
---|
58 | var fId = ioArgs.args.frameDoc; |
---|
59 | |
---|
60 | if(fId && dojo.isString(fId)){ |
---|
61 | var frame = dojo.byId(fId); |
---|
62 | var waiters = scriptFrame._getWaiters(fId); |
---|
63 | if(!frame){ |
---|
64 | //Need to create frame, but the frame document, which *must* be |
---|
65 | //on the same domain as the page (set djConfig.dojoBlankHtmlUrl |
---|
66 | //if using xdomain loading). Loading of the frame document is asynchronous, |
---|
67 | //so we need to do callback stuff. |
---|
68 | waiters.push(ioArgs); |
---|
69 | iframe.create(fId, dojox._scopeName + ".io.scriptFrame._loaded('" + fId + "');"); |
---|
70 | }else{ |
---|
71 | //Frame loading could still be happening. Only call attach if the frame has loaded. |
---|
72 | if(scriptFrame._loadedIds[fId]){ |
---|
73 | ioArgs.frameDoc = iframe.doc(frame); |
---|
74 | this.attach(ioArgs.id, ioArgs.url, ioArgs.frameDoc); |
---|
75 | }else{ |
---|
76 | waiters.push(ioArgs); |
---|
77 | } |
---|
78 | } |
---|
79 | return false; |
---|
80 | }else{ |
---|
81 | return oldCanAttach.apply(this, arguments); |
---|
82 | } |
---|
83 | }; |
---|
84 | |
---|
85 | return dojox.io.scriptFrame; |
---|
86 | }); |
---|
87 | |
---|