Xander Uiterlinden | 6d5c106 | 2012-06-06 07:03:59 +0000 | [diff] [blame] | 1 | /* |
| 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 |
| 8 | define("dojo/io/script",["../main"],function(_1){ |
| 9 | _1.getObject("io",true,_1); |
| 10 | var _2=_1.isIE?"onreadystatechange":"load",_3=/complete|loaded/; |
| 11 | _1.io.script={get:function(_4){ |
| 12 | var _5=this._makeScriptDeferred(_4); |
| 13 | var _6=_5.ioArgs; |
| 14 | _1._ioAddQueryToUrl(_6); |
| 15 | _1._ioNotifyStart(_5); |
| 16 | if(this._canAttach(_6)){ |
| 17 | var _7=this.attach(_6.id,_6.url,_4.frameDoc); |
| 18 | if(!_6.jsonp&&!_6.args.checkString){ |
| 19 | var _8=_1.connect(_7,_2,function(_9){ |
| 20 | if(_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); |
| 28 | return _5; |
| 29 | },attach:function(id,_a,_b){ |
| 30 | var _c=(_b||_1.doc); |
| 31 | var _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"; |
| 37 | return _c.getElementsByTagName("head")[0].appendChild(_d); |
| 38 | },remove:function(id,_e){ |
| 39 | _1.destroy(_1.byId(id,_e)); |
| 40 | if(this["jsonp_"+id]){ |
| 41 | delete this["jsonp_"+id]; |
| 42 | } |
| 43 | },_makeScriptDeferred:function(_f){ |
| 44 | var dfd=_1._ioSetArgs(_f,this._deferredCancel,this._deferredOk,this._deferredError); |
| 45 | var _10=dfd.ioArgs; |
| 46 | _10.id=_1._scopeName+"IoScript"+(this._counter++); |
| 47 | _10.canDelete=false; |
| 48 | _10.jsonp=_f.callbackParamName||_f.jsonp; |
| 49 | if(_10.jsonp){ |
| 50 | _10.query=_10.query||""; |
| 51 | if(_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; |
| 57 | dfd._jsonpCallback=this._jsonpCallback; |
| 58 | this["jsonp_"+_10.id]=dfd; |
| 59 | } |
| 60 | return dfd; |
| 61 | },_deferredCancel:function(dfd){ |
| 62 | dfd.canceled=true; |
| 63 | if(dfd.ioArgs.canDelete){ |
| 64 | _1.io.script._addDeadScript(dfd.ioArgs); |
| 65 | } |
| 66 | },_deferredOk:function(dfd){ |
| 67 | var _11=dfd.ioArgs; |
| 68 | if(_11.canDelete){ |
| 69 | _1.io.script._addDeadScript(_11); |
| 70 | } |
| 71 | return _11.json||_11.scriptLoaded||_11; |
| 72 | },_deferredError:function(_12,dfd){ |
| 73 | if(dfd.ioArgs.canDelete){ |
| 74 | if(_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 | } |
| 80 | return _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){ |
| 85 | var _14=_1.io.script; |
| 86 | var _15=_14._deadScripts; |
| 87 | if(_15&&_15.length>0){ |
| 88 | for(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 | } |
| 94 | return true; |
| 95 | },_ioCheck:function(dfd){ |
| 96 | var _16=dfd.ioArgs; |
| 97 | if(_16.json||(_16.scriptLoaded&&!_16.args.checkString)){ |
| 98 | return true; |
| 99 | } |
| 100 | var _17=_16.args.checkString; |
| 101 | return _17&&eval("typeof("+_17+") != 'undefined'"); |
| 102 | },_resHandle:function(dfd){ |
| 103 | if(_1.io.script._ioCheck(dfd)){ |
| 104 | dfd.callback(dfd); |
| 105 | }else{ |
| 106 | dfd.errback(new Error("inconceivable dojo.io.script._resHandle error")); |
| 107 | } |
| 108 | },_canAttach:function(_18){ |
| 109 | return true; |
| 110 | },_jsonpCallback:function(_19){ |
| 111 | this.ioArgs.json=_19; |
| 112 | }}; |
| 113 | return _1.io.script; |
| 114 | }); |