From a089699c8915636ba4f158d77dba9b012bc93208 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Fri, 4 Mar 2011 19:02:28 +0300 Subject: build custom layer of Dojo to speed up loading of tt-rss (refs #293) --- lib/dojo/io/script.js | 356 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 249 insertions(+), 107 deletions(-) (limited to 'lib/dojo/io/script.js') diff --git a/lib/dojo/io/script.js b/lib/dojo/io/script.js index 9a940634d..9730c977d 100644 --- a/lib/dojo/io/script.js +++ b/lib/dojo/io/script.js @@ -5,114 +5,256 @@ */ -if(!dojo._hasResource["dojo.io.script"]){ -dojo._hasResource["dojo.io.script"]=true; +if(!dojo._hasResource["dojo.io.script"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code. +dojo._hasResource["dojo.io.script"] = true; dojo.provide("dojo.io.script"); -(function(){ -var _1=dojo.isIE?"onreadystatechange":"load",_2=/complete|loaded/; -dojo.io.script={get:function(_3){ -var _4=this._makeScriptDeferred(_3); -var _5=_4.ioArgs; -dojo._ioAddQueryToUrl(_5); -dojo._ioNotifyStart(_4); -if(this._canAttach(_5)){ -var _6=this.attach(_5.id,_5.url,_3.frameDoc); -if(!_5.jsonp&&!_5.args.checkString){ -var _7=dojo.connect(_6,_1,function(_8){ -if(_8.type=="load"||_2.test(_6.readyState)){ -dojo.disconnect(_7); -_5.scriptLoaded=_8; -} + +/*===== +dojo.declare("dojo.io.script.__ioArgs", dojo.__IoArgs, { + constructor: function(){ + // summary: + // All the properties described in the dojo.__ioArgs type, apply to this + // type as well, EXCEPT "handleAs". It is not applicable to + // dojo.io.script.get() calls, since it is implied by the usage of + // "jsonp" (response will be a JSONP call returning JSON) + // or the response is pure JavaScript defined in + // the body of the script that was attached. + // callbackParamName: String + // Deprecated as of Dojo 1.4 in favor of "jsonp", but still supported for + // legacy code. See notes for jsonp property. + // jsonp: String + // The URL parameter name that indicates the JSONP callback string. + // For instance, when using Yahoo JSONP calls it is normally, + // jsonp: "callback". For AOL JSONP calls it is normally + // jsonp: "c". + // checkString: String + // A string of JavaScript that when evaluated like so: + // "typeof(" + checkString + ") != 'undefined'" + // being true means that the script fetched has been loaded. + // Do not use this if doing a JSONP type of call (use callbackParamName instead). + // frameDoc: Document + // The Document object for a child iframe. If this is passed in, the script + // will be attached to that document. This can be helpful in some comet long-polling + // scenarios with Firefox and Opera. + this.callbackParamName = callbackParamName; + this.jsonp = jsonp; + this.checkString = checkString; + this.frameDoc = frameDoc; + } }); -} -} -dojo._ioWatch(_4,this._validCheck,this._ioCheck,this._resHandle); -return _4; -},attach:function(id,_9,_a){ -var _b=(_a||dojo.doc); -var _c=_b.createElement("script"); -_c.type="text/javascript"; -_c.src=_9; -_c.id=id; -_c.charset="utf-8"; -return _b.getElementsByTagName("head")[0].appendChild(_c); -},remove:function(id,_d){ -dojo.destroy(dojo.byId(id,_d)); -if(this["jsonp_"+id]){ -delete this["jsonp_"+id]; -} -},_makeScriptDeferred:function(_e){ -var _f=dojo._ioSetArgs(_e,this._deferredCancel,this._deferredOk,this._deferredError); -var _10=_f.ioArgs; -_10.id=dojo._scopeName+"IoScript"+(this._counter++); -_10.canDelete=false; -_10.jsonp=_e.callbackParamName||_e.jsonp; -if(_10.jsonp){ -_10.query=_10.query||""; -if(_10.query.length>0){ -_10.query+="&"; -} -_10.query+=_10.jsonp+"="+(_e.frameDoc?"parent.":"")+dojo._scopeName+".io.script.jsonp_"+_10.id+"._jsonpCallback"; -_10.frameDoc=_e.frameDoc; -_10.canDelete=true; -_f._jsonpCallback=this._jsonpCallback; -this["jsonp_"+_10.id]=_f; -} -return _f; -},_deferredCancel:function(dfd){ -dfd.canceled=true; -if(dfd.ioArgs.canDelete){ -dojo.io.script._addDeadScript(dfd.ioArgs); -} -},_deferredOk:function(dfd){ -var _11=dfd.ioArgs; -if(_11.canDelete){ -dojo.io.script._addDeadScript(_11); -} -return _11.json||_11.scriptLoaded||_11; -},_deferredError:function(_12,dfd){ -if(dfd.ioArgs.canDelete){ -if(_12.dojoType=="timeout"){ -dojo.io.script.remove(dfd.ioArgs.id,dfd.ioArgs.frameDoc); -}else{ -dojo.io.script._addDeadScript(dfd.ioArgs); -} -} -return _12; -},_deadScripts:[],_counter:1,_addDeadScript:function(_13){ -dojo.io.script._deadScripts.push({id:_13.id,frameDoc:_13.frameDoc}); -_13.frameDoc=null; -},_validCheck:function(dfd){ -var _14=dojo.io.script; -var _15=_14._deadScripts; -if(_15&&_15.length>0){ -for(var i=0;i<_15.length;i++){ -_14.remove(_15[i].id,_15[i].frameDoc); -_15[i].frameDoc=null; -} -dojo.io.script._deadScripts=[]; -} -return true; -},_ioCheck:function(dfd){ -var _16=dfd.ioArgs; -if(_16.json||(_16.scriptLoaded&&!_16.args.checkString)){ -return true; -} -var _17=_16.args.checkString; -if(_17&&eval("typeof("+_17+") != 'undefined'")){ -return true; -} -return false; -},_resHandle:function(dfd){ -if(dojo.io.script._ioCheck(dfd)){ -dfd.callback(dfd); -}else{ -dfd.errback(new Error("inconceivable dojo.io.script._resHandle error")); -} -},_canAttach:function(_18){ -return true; -},_jsonpCallback:function(_19){ -this.ioArgs.json=_19; -}}; +=====*/ +;(function(){ + var loadEvent = dojo.isIE ? "onreadystatechange" : "load", + readyRegExp = /complete|loaded/; + + dojo.io.script = { + get: function(/*dojo.io.script.__ioArgs*/args){ + // summary: + // sends a get request using a dynamically created script tag. + var dfd = this._makeScriptDeferred(args); + var ioArgs = dfd.ioArgs; + dojo._ioAddQueryToUrl(ioArgs); + + dojo._ioNotifyStart(dfd); + + if(this._canAttach(ioArgs)){ + var node = this.attach(ioArgs.id, ioArgs.url, args.frameDoc); + + //If not a jsonp callback or a polling checkString case, bind + //to load event on the script tag. + if(!ioArgs.jsonp && !ioArgs.args.checkString){ + var handle = dojo.connect(node, loadEvent, function(evt){ + if(evt.type == "load" || readyRegExp.test(node.readyState)){ + dojo.disconnect(handle); + ioArgs.scriptLoaded = evt; + } + }); + } + } + + dojo._ioWatch(dfd, this._validCheck, this._ioCheck, this._resHandle); + return dfd; + }, + + attach: function(/*String*/id, /*String*/url, /*Document?*/frameDocument){ + // summary: + // creates a new