blob: b040b9b83b191196868018151b968a9add5cf42e [file] [log] [blame]
Xander Uiterlinden6d5c1062012-06-06 07:03:59 +00001/*
2 Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
3 Available via Academic Free License >= 2.1 OR the modified BSD license.
4 see: http://dojotoolkit.org/license for details
5*/
6
7//>>built
8define("dojo/io/script",["../main"],function(_1){
9_1.getObject("io",true,_1);
10var _2=_1.isIE?"onreadystatechange":"load",_3=/complete|loaded/;
11_1.io.script={get:function(_4){
12var _5=this._makeScriptDeferred(_4);
13var _6=_5.ioArgs;
14_1._ioAddQueryToUrl(_6);
15_1._ioNotifyStart(_5);
16if(this._canAttach(_6)){
17var _7=this.attach(_6.id,_6.url,_4.frameDoc);
18if(!_6.jsonp&&!_6.args.checkString){
19var _8=_1.connect(_7,_2,function(_9){
20if(_9.type=="load"||_3.test(_7.readyState)){
21_1.disconnect(_8);
22_6.scriptLoaded=_9;
23}
24});
25}
26}
27_1._ioWatch(_5,this._validCheck,this._ioCheck,this._resHandle);
28return _5;
29},attach:function(id,_a,_b){
30var _c=(_b||_1.doc);
31var _d=_c.createElement("script");
32_d.type="text/javascript";
33_d.src=_a;
34_d.id=id;
35_d.async=true;
36_d.charset="utf-8";
37return _c.getElementsByTagName("head")[0].appendChild(_d);
38},remove:function(id,_e){
39_1.destroy(_1.byId(id,_e));
40if(this["jsonp_"+id]){
41delete this["jsonp_"+id];
42}
43},_makeScriptDeferred:function(_f){
44var dfd=_1._ioSetArgs(_f,this._deferredCancel,this._deferredOk,this._deferredError);
45var _10=dfd.ioArgs;
46_10.id=_1._scopeName+"IoScript"+(this._counter++);
47_10.canDelete=false;
48_10.jsonp=_f.callbackParamName||_f.jsonp;
49if(_10.jsonp){
50_10.query=_10.query||"";
51if(_10.query.length>0){
52_10.query+="&";
53}
54_10.query+=_10.jsonp+"="+(_f.frameDoc?"parent.":"")+_1._scopeName+".io.script.jsonp_"+_10.id+"._jsonpCallback";
55_10.frameDoc=_f.frameDoc;
56_10.canDelete=true;
57dfd._jsonpCallback=this._jsonpCallback;
58this["jsonp_"+_10.id]=dfd;
59}
60return dfd;
61},_deferredCancel:function(dfd){
62dfd.canceled=true;
63if(dfd.ioArgs.canDelete){
64_1.io.script._addDeadScript(dfd.ioArgs);
65}
66},_deferredOk:function(dfd){
67var _11=dfd.ioArgs;
68if(_11.canDelete){
69_1.io.script._addDeadScript(_11);
70}
71return _11.json||_11.scriptLoaded||_11;
72},_deferredError:function(_12,dfd){
73if(dfd.ioArgs.canDelete){
74if(_12.dojoType=="timeout"){
75_1.io.script.remove(dfd.ioArgs.id,dfd.ioArgs.frameDoc);
76}else{
77_1.io.script._addDeadScript(dfd.ioArgs);
78}
79}
80return _12;
81},_deadScripts:[],_counter:1,_addDeadScript:function(_13){
82_1.io.script._deadScripts.push({id:_13.id,frameDoc:_13.frameDoc});
83_13.frameDoc=null;
84},_validCheck:function(dfd){
85var _14=_1.io.script;
86var _15=_14._deadScripts;
87if(_15&&_15.length>0){
88for(var i=0;i<_15.length;i++){
89_14.remove(_15[i].id,_15[i].frameDoc);
90_15[i].frameDoc=null;
91}
92_1.io.script._deadScripts=[];
93}
94return true;
95},_ioCheck:function(dfd){
96var _16=dfd.ioArgs;
97if(_16.json||(_16.scriptLoaded&&!_16.args.checkString)){
98return true;
99}
100var _17=_16.args.checkString;
101return _17&&eval("typeof("+_17+") != 'undefined'");
102},_resHandle:function(dfd){
103if(_1.io.script._ioCheck(dfd)){
104dfd.callback(dfd);
105}else{
106dfd.errback(new Error("inconceivable dojo.io.script._resHandle error"));
107}
108},_canAttach:function(_18){
109return true;
110},_jsonpCallback:function(_19){
111this.ioArgs.json=_19;
112}};
113return _1.io.script;
114});