diff options
Diffstat (limited to 'lib/dojo/request')
-rw-r--r-- | lib/dojo/request/default.js | 8 | ||||
-rw-r--r-- | lib/dojo/request/default.js.uncompressed.js | 32 | ||||
-rw-r--r-- | lib/dojo/request/handlers.js | 8 | ||||
-rw-r--r-- | lib/dojo/request/handlers.js.uncompressed.js | 62 | ||||
-rw-r--r-- | lib/dojo/request/iframe.js | 8 | ||||
-rw-r--r-- | lib/dojo/request/iframe.js.uncompressed.js | 430 | ||||
-rw-r--r-- | lib/dojo/request/node.js | 8 | ||||
-rw-r--r-- | lib/dojo/request/node.js.uncompressed.js | 191 | ||||
-rw-r--r-- | lib/dojo/request/notify.js | 8 | ||||
-rw-r--r-- | lib/dojo/request/notify.js.uncompressed.js | 74 | ||||
-rw-r--r-- | lib/dojo/request/registry.js | 8 | ||||
-rw-r--r-- | lib/dojo/request/registry.js.uncompressed.js | 85 | ||||
-rw-r--r-- | lib/dojo/request/script.js | 8 | ||||
-rw-r--r-- | lib/dojo/request/script.js.uncompressed.js | 218 | ||||
-rw-r--r-- | lib/dojo/request/util.js | 8 | ||||
-rw-r--r-- | lib/dojo/request/util.js.uncompressed.js | 145 | ||||
-rw-r--r-- | lib/dojo/request/watch.js | 8 | ||||
-rw-r--r-- | lib/dojo/request/watch.js.uncompressed.js | 109 | ||||
-rw-r--r-- | lib/dojo/request/xhr.js | 8 | ||||
-rw-r--r-- | lib/dojo/request/xhr.js.uncompressed.js | 316 |
20 files changed, 1742 insertions, 0 deletions
diff --git a/lib/dojo/request/default.js b/lib/dojo/request/default.js new file mode 100644 index 000000000..ee379608a --- /dev/null +++ b/lib/dojo/request/default.js @@ -0,0 +1,8 @@ +/* + Copyright (c) 2004-2012, The Dojo Foundation All Rights Reserved. + Available via Academic Free License >= 2.1 OR the modified BSD license. + see: http://dojotoolkit.org/license for details +*/ + +//>>built +define("dojo/request/default",["exports","require","../has"],function(_1,_2,_3){var _4=_3("config-requestProvider"),_5;if(1){_5="./xhr";}else{if(0){_5="./node";}}if(!_4){_4=_5;}_1.getPlatformDefaultId=function(){return _5;};_1.load=function(id,_6,_7,_8){_2([id=="platform"?_5:_4],function(_9){_7(_9);});};});
\ No newline at end of file diff --git a/lib/dojo/request/default.js.uncompressed.js b/lib/dojo/request/default.js.uncompressed.js new file mode 100644 index 000000000..0b4ec22c2 --- /dev/null +++ b/lib/dojo/request/default.js.uncompressed.js @@ -0,0 +1,32 @@ +define("dojo/request/default", [ + 'exports', + 'require', + '../has' +], function(exports, require, has){ + var defId = has('config-requestProvider'), + platformId; + + if( 1 ){ + platformId = './xhr'; + }else if( 0 ){ + platformId = './node'; + /* TODO: + }else if( 0 ){ + platformId = './rhino'; + */ + } + + if(!defId){ + defId = platformId; + } + + exports.getPlatformDefaultId = function(){ + return platformId; + }; + + exports.load = function(id, parentRequire, loaded, config){ + require([id == 'platform' ? platformId : defId], function(provider){ + loaded(provider); + }); + }; +}); diff --git a/lib/dojo/request/handlers.js b/lib/dojo/request/handlers.js new file mode 100644 index 000000000..6718c461b --- /dev/null +++ b/lib/dojo/request/handlers.js @@ -0,0 +1,8 @@ +/* + Copyright (c) 2004-2012, The Dojo Foundation All Rights Reserved. + Available via Academic Free License >= 2.1 OR the modified BSD license. + see: http://dojotoolkit.org/license for details +*/ + +//>>built +define("dojo/request/handlers",["../json","../_base/kernel","../_base/array","../has"],function(_1,_2,_3,_4){_4.add("activex",typeof ActiveXObject!=="undefined");var _5;if(_4("activex")){var dp=["Msxml2.DOMDocument.6.0","Msxml2.DOMDocument.4.0","MSXML2.DOMDocument.3.0","MSXML.DOMDocument"];_5=function(_6){var _7=_6.data;if(!_7||!_7.documentElement){var _8=_6.text;_3.some(dp,function(p){try{var _9=new ActiveXObject(p);_9.async=false;_9.loadXML(_8);_7=_9;}catch(e){return false;}return true;});}return _7;};}var _a={"javascript":function(_b){return _2.eval(_b.text||"");},"json":function(_c){return _1.parse(_c.text||null);},"xml":_5};function _d(_e){var _f=_a[_e.options.handleAs];_e.data=_f?_f(_e):(_e.data||_e.text);return _e;};_d.register=function(_10,_11){_a[_10]=_11;};return _d;});
\ No newline at end of file diff --git a/lib/dojo/request/handlers.js.uncompressed.js b/lib/dojo/request/handlers.js.uncompressed.js new file mode 100644 index 000000000..7c0ed8302 --- /dev/null +++ b/lib/dojo/request/handlers.js.uncompressed.js @@ -0,0 +1,62 @@ +define("dojo/request/handlers", [ + '../json', + '../_base/kernel', + '../_base/array', + '../has' +], function(JSON, kernel, array, has){ + has.add('activex', typeof ActiveXObject !== 'undefined'); + + var handleXML; + if(has('activex')){ + // GUIDs obtained from http://msdn.microsoft.com/en-us/library/ms757837(VS.85).aspx + var dp = [ + 'Msxml2.DOMDocument.6.0', + 'Msxml2.DOMDocument.4.0', + 'MSXML2.DOMDocument.3.0', + 'MSXML.DOMDocument' // 2.0 + ]; + + handleXML = function(response){ + var result = response.data; + + if(!result || !result.documentElement){ + var text = response.text; + array.some(dp, function(p){ + try{ + var dom = new ActiveXObject(p); + dom.async = false; + dom.loadXML(text); + result = dom; + }catch(e){ return false; } + return true; + }); + } + + return result; + }; + } + + var handlers = { + 'javascript': function(response){ + return kernel.eval(response.text || ''); + }, + 'json': function(response){ + return JSON.parse(response.text || null); + }, + 'xml': handleXML + }; + + function handle(response){ + var handler = handlers[response.options.handleAs]; + + response.data = handler ? handler(response) : (response.data || response.text); + + return response; + } + + handle.register = function(name, handler){ + handlers[name] = handler; + }; + + return handle; +}); diff --git a/lib/dojo/request/iframe.js b/lib/dojo/request/iframe.js new file mode 100644 index 000000000..875b311c4 --- /dev/null +++ b/lib/dojo/request/iframe.js @@ -0,0 +1,8 @@ +/* + Copyright (c) 2004-2012, The Dojo Foundation All Rights Reserved. + Available via Academic Free License >= 2.1 OR the modified BSD license. + see: http://dojotoolkit.org/license for details +*/ + +//>>built +define("dojo/request/iframe",["module","require","./watch","./util","./handlers","../_base/lang","../io-query","../query","../has","../dom","../dom-construct","../_base/window"],function(_1,_2,_3,_4,_5,_6,_7,_8,_9,_a,_b,_c){var _d=_1.id.replace(/[\/\.\-]/g,"_"),_e=_d+"_onload";if(!_c.global[_e]){_c.global[_e]=function(){var _f=_10._currentDfd;if(!_f){_10._fireNextRequest();return;}var _11=_f.response,_12=_11.options,_13=_a.byId(_12.form)||_f._tmpForm;if(_13){var _14=_f._contentToClean;for(var i=0;i<_14.length;i++){var key=_14[i];for(var j=0;j<_13.childNodes.length;j++){var _15=_13.childNodes[j];if(_15.name===key){_b.destroy(_15);break;}}}_f._originalAction&&_13.setAttribute("action",_f._originalAction);if(_f._originalMethod){_13.setAttribute("method",_f._originalMethod);_13.method=_f._originalMethod;}if(_f._originalTarget){_13.setAttribute("target",_f._originalTarget);_13.target=_f._originalTarget;}}if(_f._tmpForm){_b.destroy(_f._tmpForm);delete _f._tmpForm;}_f._finished=true;};}function _16(_17,_18,uri){if(_c.global[_17]){return _c.global[_17];}if(_c.global.frames[_17]){return _c.global.frames[_17];}if(!uri){if(_9("config-useXDomain")&&!_9("config-dojoBlankHtmlUrl")){console.warn("dojo/request/iframe: When using cross-domain Dojo builds,"+" please save dojo/resources/blank.html to your domain and set dojoConfig.dojoBlankHtmlUrl"+" to the path on your domain to blank.html");}uri=(_9("config-dojoBlankHtmlUrl")||_2.toUrl("dojo/resources/blank.html"));}var _19=_b.place("<iframe id=\""+_17+"\" name=\""+_17+"\" src=\""+uri+"\" onload=\""+_18+"\" style=\"position: absolute; left: 1px; top: 1px; height: 1px; width: 1px; visibility: hidden\">",_c.body());_c.global[_17]=_19;return _19;};function _1a(_1b,src,_1c){var _1d=_c.global.frames[_1b.name];if(_1d.contentWindow){_1d=_1d.contentWindow;}try{if(!_1c){_1d.location=src;}else{_1d.location.replace(src);}}catch(e){}};function doc(_1e){if(_1e.contentDocument){return _1e.contentDocument;}var _1f=_1e.name;if(_1f){var _20=_c.doc.getElementsByTagName("iframe");if(_1e.document&&_20[_1f].contentWindow&&_20[_1f].contentWindow.document){return _20[_1f].contentWindow.document;}else{if(_c.doc.frames[_1f]&&_c.doc.frames[_1f].document){return _c.doc.frames[_1f].document;}}}return null;};function _21(){return _b.create("form",{name:_d+"_form",style:{position:"absolute",top:"-1000px",left:"-1000px"}},_c.body());};function _22(){var dfd;try{if(_10._currentDfd||!_10._dfdQueue.length){return;}do{dfd=_10._currentDfd=_10._dfdQueue.shift();}while(dfd&&(dfd.canceled||(dfd.isCanceled&&dfd.isCanceled()))&&_10._dfdQueue.length);if(!dfd||dfd.canceled||(dfd.isCanceled&&dfd.isCanceled())){_10._currentDfd=null;return;}var _23=dfd.response,_24=_23.options,c2c=dfd._contentToClean=[],_25=_a.byId(_24.form),_26=_4.notify,_27=_24.data||null,_28;if(!dfd._legacy&&_24.method==="POST"&&!_25){_25=dfd._tmpForm=_21();}else{if(_24.method==="GET"&&_25&&_23.url.indexOf("?")>-1){_28=_23.url.slice(_23.url.indexOf("?")+1);_27=_6.mixin(_7.queryToObject(_28),_27);}}if(_25){if(!dfd._legacy){var _29=_25;do{_29=_29.parentNode;}while(_29!==_c.doc.documentElement);if(!_29){_25.style.position="absolute";_25.style.left="-1000px";_25.style.top="-1000px";_c.body().appendChild(_25);}if(!_25.name){_25.name=_d+"_form";}}if(_27){var _2a=function(_2b,_2c){_b.create("input",{type:"hidden",name:_2b,value:_2c},_25);c2c.push(_2b);};for(var x in _27){var val=_27[x];if(_6.isArray(val)&&val.length>1){for(var i=0;i<val.length;i++){_2a(x,val[i]);}}else{if(!_25[x]){_2a(x,val);}else{_25[x].value=val;}}}}var _2d=_25.getAttributeNode("action"),_2e=_25.getAttributeNode("method"),_2f=_25.getAttributeNode("target");if(_23.url){dfd._originalAction=_2d?_2d.value:null;if(_2d){_2d.value=_23.url;}else{_25.setAttribute("action",_23.url);}}if(!dfd._legacy){dfd._originalMethod=_2e?_2e.value:null;if(_2e){_2e.value=_24.method;}else{_25.setAttribute("method",_24.method);}}else{if(!_2e||!_2e.value){if(mthdNode){mthdNode.value=_24.method;}else{fn.setAttribute("method",_24.method);}}}dfd._originalTarget=_2f?_2f.value:null;if(_2f){_2f.value=_10._iframeName;}else{_25.setAttribute("target",_10._iframeName);}_25.target=_10._iframeName;_26&&_26.emit("send",_23,dfd.promise.cancel);_10._notifyStart(_23);_25.submit();}else{var _30="";if(_23.options.data){_30=_23.options.data;if(typeof _30!=="string"){_30=_7.objectToQuery(_30);}}var _31=_23.url+(_23.url.indexOf("?")>-1?"&":"?")+_30;_26&&_26.emit("send",_23,dfd.promise.cancel);_10._notifyStart(_23);_10.setSrc(_10._frame,_31,true);}}catch(e){dfd.reject(e);}};function _32(_33){return !this.isFulfilled();};function _34(_35){return !!this._finished;};function _36(_37,_38){if(!_38){try{var _39=_37.options,doc=_10.doc(_10._frame),_3a=_39.handleAs;if(_3a!=="html"){if(_3a==="xml"){if(doc.documentElement.tagName.toLowerCase()==="html"){_8("a",doc.documentElement).orphan();var _3b=doc.documentElement.innerText;_3b=_3b.replace(/>\s+</g,"><");_37.text=_6.trim(_3b);}else{_37.data=doc;}}else{_37.text=doc.getElementsByTagName("textarea")[0].value;}_5(_37);}else{_37.data=doc;}}catch(e){_38=e;}}if(_38){this.reject(_38);}else{if(this._finished){this.resolve(_37);}else{this.reject(new Error("Invalid dojo/request/iframe request state"));}}};function _3c(_3d){this._callNext();};var _3e={method:"POST"};function _10(url,_3f,_40){var _41=_4.parseArgs(url,_4.deepCreate(_3e,_3f),true);url=_41.url;_3f=_41.options;if(_3f.method!=="GET"&&_3f.method!=="POST"){throw new Error(_3f.method+" not supported by dojo/request/iframe");}if(!_10._frame){_10._frame=_10.create(_10._iframeName,_e+"();");}var dfd=_4.deferred(_41,null,_32,_34,_36,_3c);dfd._callNext=function(){if(!this._calledNext){this._calledNext=true;_10._currentDfd=null;_10._fireNextRequest();}};dfd._legacy=_40;_10._dfdQueue.push(dfd);_10._fireNextRequest();_3(dfd);return _40?dfd:dfd.promise;};_10.create=_16;_10.doc=doc;_10.setSrc=_1a;_10._iframeName=_d+"_IoIframe";_10._notifyStart=function(){};_10._dfdQueue=[];_10._currentDfd=null;_10._fireNextRequest=_22;_4.addCommonMethods(_10,["GET","POST"]);return _10;});
\ No newline at end of file diff --git a/lib/dojo/request/iframe.js.uncompressed.js b/lib/dojo/request/iframe.js.uncompressed.js new file mode 100644 index 000000000..aee6b0c4d --- /dev/null +++ b/lib/dojo/request/iframe.js.uncompressed.js @@ -0,0 +1,430 @@ +define("dojo/request/iframe", [ + 'module', + 'require', + './watch', + './util', + './handlers', + '../_base/lang', + '../io-query', + '../query', + '../has', + '../dom', + '../dom-construct', + '../_base/window'/*=====, + '../request', + '../_base/declare' =====*/ +], function(module, require, watch, util, handlers, lang, ioQuery, query, has, dom, domConstruct, win/*=====, request, declare =====*/){ + var mid = module.id.replace(/[\/\.\-]/g, '_'), + onload = mid + '_onload'; + + if(!win.global[onload]){ + win.global[onload] = function(){ + var dfd = iframe._currentDfd; + if(!dfd){ + iframe._fireNextRequest(); + return; + } + + var response = dfd.response, + options = response.options, + formNode = dom.byId(options.form) || dfd._tmpForm; + + if(formNode){ + // remove all the hidden content inputs + var toClean = dfd._contentToClean; + for(var i=0; i<toClean.length; i++){ + var key = toClean[i]; + //Need to cycle over all nodes since we may have added + //an array value which means that more than one node could + //have the same .name value. + for(var j=0; j<formNode.childNodes.length; j++){ + var childNode = formNode.childNodes[j]; + if(childNode.name === key){ + domConstruct.destroy(childNode); + break; + } + } + } + + // restore original action + target + dfd._originalAction && formNode.setAttribute('action', dfd._originalAction); + if(dfd._originalMethod){ + formNode.setAttribute('method', dfd._originalMethod); + formNode.method = dfd._originalMethod; + } + if(dfd._originalTarget){ + formNode.setAttribute('target', dfd._originalTarget); + formNode.target = dfd._originalTarget; + } + } + + if(dfd._tmpForm){ + domConstruct.destroy(dfd._tmpForm); + delete dfd._tmpForm; + } + + dfd._finished = true; + }; + } + + function create(name, onloadstr, uri){ + if(win.global[name]){ + return win.global[name]; + } + + if(win.global.frames[name]){ + return win.global.frames[name]; + } + + if(!uri){ + if(has('config-useXDomain') && !has('config-dojoBlankHtmlUrl')){ + console.warn('dojo/request/iframe: When using cross-domain Dojo builds,' + + ' please save dojo/resources/blank.html to your domain and set dojoConfig.dojoBlankHtmlUrl' + + ' to the path on your domain to blank.html'); + } + uri = (has('config-dojoBlankHtmlUrl')||require.toUrl('dojo/resources/blank.html')); + } + + var frame = domConstruct.place( + '<iframe id="'+name+'" name="'+name+'" src="'+uri+'" onload="'+onloadstr+ + '" style="position: absolute; left: 1px; top: 1px; height: 1px; width: 1px; visibility: hidden">', + win.body()); + + win.global[name] = frame; + + return frame; + } + + function setSrc(_iframe, src, replace){ + var frame = win.global.frames[_iframe.name]; + + if(frame.contentWindow){ + // We have an iframe node instead of the window + frame = frame.contentWindow; + } + + try{ + if(!replace){ + frame.location = src; + }else{ + frame.location.replace(src); + } + }catch(e){ + console.log('dojo/request/iframe.setSrc: ', e); + } + } + + function doc(iframeNode){ + if(iframeNode.contentDocument){ + return iframeNode.contentDocument; + } + var name = iframeNode.name; + if(name){ + var iframes = win.doc.getElementsByTagName('iframe'); + if(iframeNode.document && iframes[name].contentWindow && iframes[name].contentWindow.document){ + return iframes[name].contentWindow.document; + }else if(win.doc.frames[name] && win.doc.frames[name].document){ + return win.doc.frames[name].document; + } + } + return null; + } + + function createForm(){ + return domConstruct.create('form', { + name: mid + '_form', + style: { + position: 'absolute', + top: '-1000px', + left: '-1000px' + } + }, win.body()); + } + + function fireNextRequest(){ + // summary: + // Internal method used to fire the next request in the queue. + var dfd; + try{ + if(iframe._currentDfd || !iframe._dfdQueue.length){ + return; + } + do{ + dfd = iframe._currentDfd = iframe._dfdQueue.shift(); + }while(dfd && (dfd.canceled || (dfd.isCanceled && dfd.isCanceled())) && iframe._dfdQueue.length); + + if(!dfd || dfd.canceled || (dfd.isCanceled && dfd.isCanceled())){ + iframe._currentDfd = null; + return; + } + + var response = dfd.response, + options = response.options, + c2c = dfd._contentToClean = [], + formNode = dom.byId(options.form), + notify = util.notify, + data = options.data || null, + queryStr; + + if(!dfd._legacy && options.method === 'POST' && !formNode){ + formNode = dfd._tmpForm = createForm(); + }else if(options.method === 'GET' && formNode && response.url.indexOf('?') > -1){ + queryStr = response.url.slice(response.url.indexOf('?') + 1); + data = lang.mixin(ioQuery.queryToObject(queryStr), data); + } + + if(formNode){ + if(!dfd._legacy){ + var parentNode = formNode; + do{ + parentNode = parentNode.parentNode; + }while(parentNode !== win.doc.documentElement); + + // Append the form node or some browsers won't work + if(!parentNode){ + formNode.style.position = 'absolute'; + formNode.style.left = '-1000px'; + formNode.style.top = '-1000px'; + win.body().appendChild(formNode); + } + + if(!formNode.name){ + formNode.name = mid + '_form'; + } + } + + // if we have things in data, we need to add them to the form + // before submission + if(data){ + var createInput = function(name, value){ + domConstruct.create('input', { + type: 'hidden', + name: name, + value: value + }, formNode); + c2c.push(name); + }; + for(var x in data){ + var val = data[x]; + if(lang.isArray(val) && val.length > 1){ + for(var i=0; i<val.length; i++){ + createInput(x, val[i]); + } + }else{ + if(!formNode[x]){ + createInput(x, val); + }else{ + formNode[x].value = val; + } + } + } + } + + //IE requires going through getAttributeNode instead of just getAttribute in some form cases, + //so use it for all. See #2844 + var actionNode = formNode.getAttributeNode('action'), + methodNode = formNode.getAttributeNode('method'), + targetNode = formNode.getAttributeNode('target'); + + if(response.url){ + dfd._originalAction = actionNode ? actionNode.value : null; + if(actionNode){ + actionNode.value = response.url; + }else{ + formNode.setAttribute('action', response.url); + } + } + + if(!dfd._legacy){ + dfd._originalMethod = methodNode ? methodNode.value : null; + if(methodNode){ + methodNode.value = options.method; + }else{ + formNode.setAttribute('method', options.method); + } + }else{ + if(!methodNode || !methodNode.value){ + if(mthdNode){ + mthdNode.value = options.method; + }else{ + fn.setAttribute("method", options.method); + } + } + } + + dfd._originalTarget = targetNode ? targetNode.value : null; + if(targetNode){ + targetNode.value = iframe._iframeName; + }else{ + formNode.setAttribute('target', iframe._iframeName); + } + formNode.target = iframe._iframeName; + + notify && notify.emit('send', response, dfd.promise.cancel); + iframe._notifyStart(response); + formNode.submit(); + }else{ + // otherwise we post a GET string by changing URL location for the + // iframe + + var extra = ''; + if(response.options.data){ + extra = response.options.data; + if(typeof extra !== 'string'){ + extra = ioQuery.objectToQuery(extra); + } + } + var tmpUrl = response.url + (response.url.indexOf('?') > -1 ? '&' : '?') + extra; + notify && notify.emit('send', response, dfd.promise.cancel); + iframe._notifyStart(response); + iframe.setSrc(iframe._frame, tmpUrl, true); + } + }catch(e){ + dfd.reject(e); + } + } + + // dojo/request/watch handlers + function isValid(response){ + return !this.isFulfilled(); + } + function isReady(response){ + return !!this._finished; + } + function handleResponse(response, error){ + if(!error){ + try{ + var options = response.options, + doc = iframe.doc(iframe._frame), + handleAs = options.handleAs; + + if(handleAs !== 'html'){ + if(handleAs === 'xml'){ + // IE6-8 have to parse the XML manually. See http://bugs.dojotoolkit.org/ticket/6334 + if(doc.documentElement.tagName.toLowerCase() === 'html'){ + query('a', doc.documentElement).orphan(); + var xmlText = doc.documentElement.innerText; + xmlText = xmlText.replace(/>\s+</g, '><'); + response.text = lang.trim(xmlText); + }else{ + response.data = doc; + } + }else{ + // 'json' and 'javascript' and 'text' + response.text = doc.getElementsByTagName('textarea')[0].value; // text + } + handlers(response); + }else{ + response.data = doc; + } + }catch(e){ + error = e; + } + } + + if(error){ + this.reject(error); + }else if(this._finished){ + this.resolve(response); + }else{ + this.reject(new Error('Invalid dojo/request/iframe request state')); + } + } + function last(response){ + this._callNext(); + } + + var defaultOptions = { + method: 'POST' + }; + function iframe(url, options, returnDeferred){ + var response = util.parseArgs(url, util.deepCreate(defaultOptions, options), true); + url = response.url; + options = response.options; + + if(options.method !== 'GET' && options.method !== 'POST'){ + throw new Error(options.method + ' not supported by dojo/request/iframe'); + } + + if(!iframe._frame){ + iframe._frame = iframe.create(iframe._iframeName, onload + '();'); + } + + var dfd = util.deferred(response, null, isValid, isReady, handleResponse, last); + dfd._callNext = function(){ + if(!this._calledNext){ + this._calledNext = true; + iframe._currentDfd = null; + iframe._fireNextRequest(); + } + }; + dfd._legacy = returnDeferred; + + iframe._dfdQueue.push(dfd); + iframe._fireNextRequest(); + + watch(dfd); + + return returnDeferred ? dfd : dfd.promise; + } + + /*===== + iframe = function(url, options){ + // summary: + // Sends a request using an iframe element with the given URL and options. + // url: String + // URL to request + // options: dojo/request/iframe.__Options? + // Options for the request. + // returns: dojo/request.__Promise + }; + iframe.__BaseOptions = declare(request.__BaseOptions, { + // form: DOMNode? + // A form node to use to submit data to the server. + // data: String|Object? + // Data to transfer. When making a GET request, this will + // be converted to key=value parameters and appended to the + // URL. + }); + iframe.__MethodOptions = declare(null, { + // method: String? + // The HTTP method to use to make the request. Must be + // uppercase. Only `"GET"` and `"POST"` are accepted. + // Default is `"POST"`. + }); + iframe.__Options = declare([iframe.__BaseOptions, iframe.__MethodOptions]); + + iframe.get = function(url, options){ + // summary: + // Send an HTTP GET request using an iframe element with the given URL and options. + // url: String + // URL to request + // options: dojo/request/iframe.__BaseOptions? + // Options for the request. + // returns: dojo/request.__Promise + }; + iframe.post = function(url, options){ + // summary: + // Send an HTTP POST request using an iframe element with the given URL and options. + // url: String + // URL to request + // options: dojo/request/iframe.__BaseOptions? + // Options for the request. + // returns: dojo/request.__Promise + }; + =====*/ + iframe.create = create; + iframe.doc = doc; + iframe.setSrc = setSrc; + + // TODO: Make these truly private in 2.0 + iframe._iframeName = mid + '_IoIframe'; + iframe._notifyStart = function(){}; + iframe._dfdQueue = []; + iframe._currentDfd = null; + iframe._fireNextRequest = fireNextRequest; + + util.addCommonMethods(iframe, ['GET', 'POST']); + + return iframe; +}); diff --git a/lib/dojo/request/node.js b/lib/dojo/request/node.js new file mode 100644 index 000000000..8ef5426fb --- /dev/null +++ b/lib/dojo/request/node.js @@ -0,0 +1,8 @@ +/* + Copyright (c) 2004-2012, The Dojo Foundation All Rights Reserved. + Available via Academic Free License >= 2.1 OR the modified BSD license. + see: http://dojotoolkit.org/license for details +*/ + +//>>built +define("dojo/request/node",["require","./util","./handlers","../errors/RequestTimeoutError","../node!http","../node!https","../node!url","../node!stream"],function(_1,_2,_3,_4,_5,_6,_7,_8){var _9=_8.Stream,_a;var _b={method:"GET",query:null,data:_a,headers:{}};function _c(_d,_e){var _f=_2.parseArgs(_d,_2.deepCreate(_b,_e),_e&&_e.data instanceof _9);_d=_f.url;_e=_f.options;var def=_2.deferred(_f,function(dfd,_10){_10.clientRequest.abort();});_d=_7.parse(_d);var _11=_f.requestOptions={hostname:_d.hostname,port:_d.port,socketPath:_e.socketPath,method:_e.method,headers:_e.headers,agent:_e.agent,pfx:_e.pfx,key:_e.key,passphrase:_e.passphrase,cert:_e.cert,ca:_e.ca,ciphers:_e.ciphers,rejectUnauthorized:_e.rejectUnauthorized===false?false:true};if(_d.path){_11.path=_d.path;}if(_e.user||_e.password){_11.auth=(_e.user||"")+":"+(_e.password||"");}var req=_f.clientRequest=(_d.protocol==="https:"?_6:_5).request(_11);if(_e.socketOptions){if("timeout" in _e.socketOptions){req.setTimeout(_e.socketOptions.timeout);}if("noDelay" in _e.socketOptions){req.setNoDelay(_e.socketOptions.noDelay);}if("keepAlive" in _e.socketOptions){var _12=_e.socketOptions.keepAlive;req.setKeepAlive(_12>=0,_12||0);}}req.on("socket",function(){_f.hasSocket=true;def.progress(_f);});req.on("response",function(_13){_f.clientResponse=_13;_f.status=_13.statusCode;_f.getHeader=function(_14){return _13.headers[_14.toLowerCase()]||null;};var _15=[];_13.on("data",function(_16){_15.push(_16);});_13.on("end",function(){if(_17){clearTimeout(_17);}_f.text=_15.join("");_3(_f);def.resolve(_f);});});req.on("error",def.reject);if(_e.data){if(typeof _e.data==="string"){req.end(_e.data);}else{_e.data.pipe(req);}}else{req.end();}if(_e.timeout){var _17=setTimeout(function(){def.cancel(new _4(_f));},_e.timeout);}return def.promise;};_2.addCommonMethods(_c);return _c;});
\ No newline at end of file diff --git a/lib/dojo/request/node.js.uncompressed.js b/lib/dojo/request/node.js.uncompressed.js new file mode 100644 index 000000000..8c44b1988 --- /dev/null +++ b/lib/dojo/request/node.js.uncompressed.js @@ -0,0 +1,191 @@ +define("dojo/request/node", [ + 'require', + './util', + './handlers', + '../errors/RequestTimeoutError', + '../node!http', + '../node!https', + '../node!url', + '../node!stream'/*=====, + '../request', + '../_base/declare' =====*/ +], function(require, util, handlers, RequestTimeoutError, http, https, URL, stream/*=====, request, declare =====*/){ + var Stream = stream.Stream, + undefined; + + var defaultOptions = { + method: 'GET', + query: null, + data: undefined, + headers: {} + }; + function node(url, options){ + var response = util.parseArgs(url, util.deepCreate(defaultOptions, options), options && options.data instanceof Stream); + url = response.url; + options = response.options; + + var def = util.deferred( + response, + function(dfd, response){ + response.clientRequest.abort(); + } + ); + + url = URL.parse(url); + + var reqOptions = response.requestOptions = { + hostname: url.hostname, + port: url.port, + socketPath: options.socketPath, + method: options.method, + headers: options.headers, + agent: options.agent, + pfx: options.pfx, + key: options.key, + passphrase: options.passphrase, + cert: options.cert, + ca: options.ca, + ciphers: options.ciphers, + rejectUnauthorized: options.rejectUnauthorized === false ? false : true + }; + if(url.path){ + reqOptions.path = url.path; + } + if(options.user || options.password){ + reqOptions.auth = (options.user||'') + ':' + (options.password||''); + } + var req = response.clientRequest = (url.protocol === 'https:' ? https : http).request(reqOptions); + + if(options.socketOptions){ + if('timeout' in options.socketOptions){ + req.setTimeout(options.socketOptions.timeout); + } + if('noDelay' in options.socketOptions){ + req.setNoDelay(options.socketOptions.noDelay); + } + if('keepAlive' in options.socketOptions){ + var initialDelay = options.socketOptions.keepAlive; + req.setKeepAlive(initialDelay >= 0, initialDelay || 0); + } + } + + req.on('socket', function(){ + response.hasSocket = true; + def.progress(response); + }); + + req.on('response', function(clientResponse){ + response.clientResponse = clientResponse; + response.status = clientResponse.statusCode; + response.getHeader = function(headerName){ + return clientResponse.headers[headerName.toLowerCase()] || null; + }; + + var body = []; + clientResponse.on('data', function(chunk){ + body.push(chunk); + + // TODO: progress updates via the deferred + }); + clientResponse.on('end', function(){ + if(timeout){ + clearTimeout(timeout); + } + response.text = body.join(''); + handlers(response); + def.resolve(response); + }); + }); + + req.on('error', def.reject); + + if(options.data){ + if(typeof options.data === "string"){ + req.end(options.data); + }else{ + options.data.pipe(req); + } + }else{ + req.end(); + } + + if(options.timeout){ + var timeout = setTimeout(function(){ + def.cancel(new RequestTimeoutError(response)); + }, options.timeout); + } + + return def.promise; + } + + /*===== + node = function(url, options){ + // summary: + // Sends a request using the included http or https interface from node.js + // with the given URL and options. + // url: String + // URL to request + // options: dojo/request/node.__Options? + // Options for the request. + // returns: dojo/request.__Promise + }; + node.__BaseOptions = declare(request.__BaseOptions, { + // data: String|Object|Stream? + // Data to transfer. This is ignored for GET and DELETE + // requests. + // headers: Object? + // Headers to use for the request. + // user: String? + // Username to use during the request. + // password: String? + // Password to use during the request. + }); + node.__MethodOptions = declare(null, { + // method: String? + // The HTTP method to use to make the request. Must be + // uppercase. Default is `"GET"`. + }); + node.__Options = declare([node.__BaseOptions, node.__MethodOptions]); + + node.get = function(url, options){ + // summary: + // Send an HTTP GET request using XMLHttpRequest with the given URL and options. + // url: String + // URL to request + // options: dojo/request/node.__BaseOptions? + // Options for the request. + // returns: dojo/request.__Promise + }; + node.post = function(url, options){ + // summary: + // Send an HTTP POST request using XMLHttpRequest with the given URL and options. + // url: String + // URL to request + // options: dojo/request/node.__BaseOptions? + // Options for the request. + // returns: dojo/request.__Promise + }; + node.put = function(url, options){ + // summary: + // Send an HTTP PUT request using XMLHttpRequest with the given URL and options. + // url: String + // URL to request + // options: dojo/request/node.__BaseOptions? + // Options for the request. + // returns: dojo/request.__Promise + }; + node.del = function(url, options){ + // summary: + // Send an HTTP DELETE request using XMLHttpRequest with the given URL and options. + // url: String + // URL to request + // options: dojo/request/node.__BaseOptions? + // Options for the request. + // returns: dojo/request.__Promise + }; + =====*/ + + util.addCommonMethods(node); + + return node; +}); diff --git a/lib/dojo/request/notify.js b/lib/dojo/request/notify.js new file mode 100644 index 000000000..b16d79d56 --- /dev/null +++ b/lib/dojo/request/notify.js @@ -0,0 +1,8 @@ +/* + Copyright (c) 2004-2012, The Dojo Foundation All Rights Reserved. + Available via Academic Free License >= 2.1 OR the modified BSD license. + see: http://dojotoolkit.org/license for details +*/ + +//>>built +define("dojo/request/notify",["../Evented","../_base/lang","./util"],function(_1,_2,_3){var _4=0,_5=[].slice;var _6=_2.mixin(new _1,{onsend:function(_7){if(!_4){this.emit("start");}_4++;},_onload:function(_8){this.emit("done",_8);},_onerror:function(_9){this.emit("done",_9);},_ondone:function(_a){if(--_4<=0){_4=0;this.emit("stop");}},emit:function(_b,_c){var _d=_1.prototype.emit.apply(this,arguments);if(this["_on"+_b]){this["_on"+_b].apply(this,_5.call(arguments,1));}return _d;}});function _e(_f,_10){return _6.on(_f,_10);};_e.emit=function(_11,_12,_13){return _6.emit(_11,_12,_13);};return _3.notify=_e;});
\ No newline at end of file diff --git a/lib/dojo/request/notify.js.uncompressed.js b/lib/dojo/request/notify.js.uncompressed.js new file mode 100644 index 000000000..2b8a2b68b --- /dev/null +++ b/lib/dojo/request/notify.js.uncompressed.js @@ -0,0 +1,74 @@ +define("dojo/request/notify", ['../Evented', '../_base/lang', './util'], function(Evented, lang, util){ + // module: + // dojo/request/notify + // summary: + // Global notification API for dojo/request. Notifications will + // only be emitted if this module is required. + // + // | require('dojo/request', 'dojo/request/notify', + // | function(request, notify){ + // | notify('load', function(response){ + // | if(response.url === 'someUrl.html'){ + // | console.log('Loaded!'); + // | } + // | }); + // | request.get('someUrl.html'); + // | } + // | ); + + var pubCount = 0, + slice = [].slice; + + var hub = lang.mixin(new Evented, { + onsend: function(data){ + if(!pubCount){ + this.emit('start'); + } + pubCount++; + }, + _onload: function(data){ + this.emit('done', data); + }, + _onerror: function(data){ + this.emit('done', data); + }, + _ondone: function(data){ + if(--pubCount <= 0){ + pubCount = 0; + this.emit('stop'); + } + }, + emit: function(type, event){ + var result = Evented.prototype.emit.apply(this, arguments); + + // After all event handlers have run, run _on* handler + if(this['_on' + type]){ + this['_on' + type].apply(this, slice.call(arguments, 1)); + } + return result; + } + }); + + function notify(type, listener){ + // summary: + // Register a listener to be notified when an event + // in dojo/request happens. + // type: String? + // The event to listen for. Events emitted: "start", "send", + // "load", "error", "done", "stop". + // listener: Function? + // A callback to be run when an event happens. + // returns: + // A signal object that can be used to cancel the listener. + // If remove() is called on this signal object, it will + // stop the listener from being executed. + return hub.on(type, listener); + } + notify.emit = function(type, event, cancel){ + return hub.emit(type, event, cancel); + }; + + // Attach notify to dojo/request/util to avoid + // try{ require('./notify'); }catch(e){} + return util.notify = notify; +}); diff --git a/lib/dojo/request/registry.js b/lib/dojo/request/registry.js new file mode 100644 index 000000000..b72d1d996 --- /dev/null +++ b/lib/dojo/request/registry.js @@ -0,0 +1,8 @@ +/* + Copyright (c) 2004-2012, The Dojo Foundation All Rights Reserved. + Available via Academic Free License >= 2.1 OR the modified BSD license. + see: http://dojotoolkit.org/license for details +*/ + +//>>built +define("dojo/request/registry",["require","../_base/array","./default!platform","./util"],function(_1,_2,_3,_4){var _5=[];function _6(_7,_8){var _9=_5.slice(0),i=0,_a;while(_a=_9[i++]){if(_a(_7,_8)){return _a.request.call(null,_7,_8);}}return _3.apply(null,arguments);};function _b(_c,_d){var _e;if(_d){if(_c.test){_e=function(_f){return _c.test(_f);};}else{if(_c.apply&&_c.call){_e=function(){return _c.apply(null,arguments);};}else{_e=function(url){return url===_c;};}}_e.request=_d;}else{_e=function(){return true;};_e.request=_c;}return _e;};_6.register=function(url,_10,_11){var _12=_b(url,_10);_5[(_11?"unshift":"push")](_12);return {remove:function(){var idx;if(~(idx=_2.indexOf(_5,_12))){_5.splice(idx,1);}}};};_6.load=function(id,_13,_14,_15){if(id){_1([id],function(_16){_3=_16;_14(_6);});}else{_14(_6);}};_4.addCommonMethods(_6);return _6;});
\ No newline at end of file diff --git a/lib/dojo/request/registry.js.uncompressed.js b/lib/dojo/request/registry.js.uncompressed.js new file mode 100644 index 000000000..b5d28f3e7 --- /dev/null +++ b/lib/dojo/request/registry.js.uncompressed.js @@ -0,0 +1,85 @@ +define("dojo/request/registry", [ + 'require', + '../_base/array', + './default!platform', + './util' +], function(require, array, fallbackProvider, util){ + var providers = []; + + function request(url, options){ + var matchers = providers.slice(0), + i = 0, + matcher; + + while(matcher=matchers[i++]){ + if(matcher(url, options)){ + return matcher.request.call(null, url, options); + } + } + + return fallbackProvider.apply(null, arguments); + } + + function createMatcher(match, provider){ + var matcher; + + if(provider){ + if(match.test){ + // RegExp + matcher = function(url){ + return match.test(url); + }; + }else if(match.apply && match.call){ + matcher = function(){ + return match.apply(null, arguments); + }; + }else{ + matcher = function(url){ + return url === match; + }; + } + + matcher.request = provider; + }else{ + // If only one argument was passed, assume it is a provider function + // to apply unconditionally to all URLs + matcher = function(){ + return true; + }; + + matcher.request = match; + } + + return matcher; + } + + request.register = function(url, provider, first){ + var matcher = createMatcher(url, provider); + providers[(first ? 'unshift' : 'push')](matcher); + + return { + remove: function(){ + var idx; + if(~(idx = array.indexOf(providers, matcher))){ + providers.splice(idx, 1); + } + } + }; + }; + + request.load = function(id, parentRequire, loaded, config){ + if(id){ + // if there's an id, load and set the fallback provider + require([id], function(fallback){ + fallbackProvider = fallback; + loaded(request); + }); + }else{ + loaded(request); + } + }; + + util.addCommonMethods(request); + + return request; +}); diff --git a/lib/dojo/request/script.js b/lib/dojo/request/script.js new file mode 100644 index 000000000..5f182dc75 --- /dev/null +++ b/lib/dojo/request/script.js @@ -0,0 +1,8 @@ +/* + Copyright (c) 2004-2012, The Dojo Foundation All Rights Reserved. + Available via Academic Free License >= 2.1 OR the modified BSD license. + see: http://dojotoolkit.org/license for details +*/ + +//>>built +define("dojo/request/script",["module","./watch","./util","../_base/array","../_base/lang","../on","../dom","../dom-construct","../has","../_base/window"],function(_1,_2,_3,_4,_5,on,_6,_7,_8,_9){_8.add("script-readystatechange",function(_a,_b){var _c=_b.createElement("script");return typeof _c["onreadystatechange"]!=="undefined"&&(typeof _a["opera"]==="undefined"||_a["opera"].toString()!=="[object Opera]");});var _d=_1.id.replace(/[\/\.\-]/g,"_"),_e=0,_f=_8("script-readystatechange")?"readystatechange":"load",_10=/complete|loaded/,_11=this[_d+"_callbacks"]={},_12=[];function _13(id,url,_14){var doc=(_14||_9.doc),_15=doc.createElement("script");_15.type="text/javascript";_15.src=url;_15.id=id;_15.async=true;_15.charset="utf-8";return doc.getElementsByTagName("head")[0].appendChild(_15);};function _16(id,_17,_18){_7.destroy(_6.byId(id,_17));if(_11[id]){if(_18){_11[id]=function(){delete _11[id];};}else{delete _11[id];}}};function _19(dfd){var _1a=dfd.response.options,_1b=_1a.ioArgs?_1a.ioArgs.frameDoc:_1a.frameDoc;_12.push({id:dfd.id,frameDoc:_1b});if(_1a.ioArgs){_1a.ioArgs.frameDoc=null;}_1a.frameDoc=null;};function _1c(dfd,_1d){if(dfd.canDelete){_1e._remove(dfd.id,_1d.options.frameDoc,true);}};function _1f(_20){if(_12&&_12.length){_4.forEach(_12,function(_21){_1e._remove(_21.id,_21.frameDoc);_21.frameDoc=null;});_12=[];}return _20.options.jsonp?!_20.data:true;};function _22(_23){return !!this.scriptLoaded;};function _24(_25){var _26=_25.options.checkString;return _26&&eval("typeof("+_26+") !== \"undefined\"");};function _27(_28,_29){if(this.canDelete){_19(this);}if(_29){this.reject(_29);}else{this.resolve(_28);}};function _1e(url,_2a,_2b){var _2c=_3.parseArgs(url,_3.deepCopy({},_2a));url=_2c.url;_2a=_2c.options;var dfd=_3.deferred(_2c,_1c,_1f,_2a.jsonp?null:(_2a.checkString?_24:_22),_27);_5.mixin(dfd,{id:_d+(_e++),canDelete:false});if(_2a.jsonp){var _2d=new RegExp("[?&]"+_2a.jsonp+"=");if(!_2d.test(url)){url+=_2d+(_2a.frameDoc?"parent.":"")+_d+"_callbacks."+dfd.id;}dfd.canDelete=true;_11[dfd.id]=function(_2e){_2c.data=_2e;dfd.handleResponse(_2c);};}if(_3.notify){_3.notify.emit("send",_2c,dfd.promise.cancel);}if(!_2a.canAttach||_2a.canAttach(dfd)){var _2f=_1e._attach(dfd.id,url,_2a.frameDoc);if(!_2a.jsonp&&!_2a.checkString){var _30=on(_2f,_f,function(evt){if(evt.type==="load"||_10.test(_2f.readyState)){_30.remove();dfd.scriptLoaded=evt;}});}}_2(dfd);return _2b?dfd:dfd.promise;};_1e.get=_1e;_1e._attach=_13;_1e._remove=_16;_1e._callbacksProperty=_d+"_callbacks";return _1e;});
\ No newline at end of file diff --git a/lib/dojo/request/script.js.uncompressed.js b/lib/dojo/request/script.js.uncompressed.js new file mode 100644 index 000000000..fcce1bd4b --- /dev/null +++ b/lib/dojo/request/script.js.uncompressed.js @@ -0,0 +1,218 @@ +define("dojo/request/script", [ + 'module', + './watch', + './util', + '../_base/array', + '../_base/lang', + '../on', + '../dom', + '../dom-construct', + '../has', + '../_base/window'/*=====, + '../request', + '../_base/declare' =====*/ +], function(module, watch, util, array, lang, on, dom, domConstruct, has, win/*=====, request, declare =====*/){ + has.add('script-readystatechange', function(global, document){ + var script = document.createElement('script'); + return typeof script['onreadystatechange'] !== 'undefined' && + (typeof global['opera'] === 'undefined' || global['opera'].toString() !== '[object Opera]'); + }); + + var mid = module.id.replace(/[\/\.\-]/g, '_'), + counter = 0, + loadEvent = has('script-readystatechange') ? 'readystatechange' : 'load', + readyRegExp = /complete|loaded/, + callbacks = this[mid + '_callbacks'] = {}, + deadScripts = []; + + function attach(id, url, frameDoc){ + var doc = (frameDoc || win.doc), + element = doc.createElement('script'); + + element.type = 'text/javascript'; + element.src = url; + element.id = id; + element.async = true; + element.charset = 'utf-8'; + + return doc.getElementsByTagName('head')[0].appendChild(element); + } + + function remove(id, frameDoc, cleanup){ + domConstruct.destroy(dom.byId(id, frameDoc)); + + if(callbacks[id]){ + if(cleanup){ + // set callback to a function that deletes itself so requests that + // are in-flight don't error out when returning and also + // clean up after themselves + callbacks[id] = function(){ + delete callbacks[id]; + }; + }else{ + delete callbacks[id]; + } + } + } + + function _addDeadScript(dfd){ + // Be sure to check ioArgs because it can dynamically change in the dojox/io plugins. + // See http://bugs.dojotoolkit.org/ticket/15890. + var options = dfd.response.options, + frameDoc = options.ioArgs ? options.ioArgs.frameDoc : options.frameDoc; + + deadScripts.push({ id: dfd.id, frameDoc: frameDoc }); + + if(options.ioArgs){ + options.ioArgs.frameDoc = null; + } + options.frameDoc = null; + } + + function canceler(dfd, response){ + if(dfd.canDelete){ + //For timeouts and cancels, remove the script element immediately to + //avoid a response from it coming back later and causing trouble. + script._remove(dfd.id, response.options.frameDoc, true); + } + } + function isValid(response){ + //Do script cleanup here. We wait for one inflight pass + //to make sure we don't get any weird things by trying to remove a script + //tag that is part of the call chain (IE 6 has been known to + //crash in that case). + if(deadScripts && deadScripts.length){ + array.forEach(deadScripts, function(_script){ + script._remove(_script.id, _script.frameDoc); + _script.frameDoc = null; + }); + deadScripts = []; + } + + return response.options.jsonp ? !response.data : true; + } + function isReadyScript(response){ + return !!this.scriptLoaded; + } + function isReadyCheckString(response){ + var checkString = response.options.checkString; + + return checkString && eval('typeof(' + checkString + ') !== "undefined"'); + } + function handleResponse(response, error){ + if(this.canDelete){ + _addDeadScript(this); + } + if(error){ + this.reject(error); + }else{ + this.resolve(response); + } + } + + function script(url, options, returnDeferred){ + var response = util.parseArgs(url, util.deepCopy({}, options)); + url = response.url; + options = response.options; + + var dfd = util.deferred( + response, + canceler, + isValid, + options.jsonp ? null : (options.checkString ? isReadyCheckString : isReadyScript), + handleResponse + ); + + lang.mixin(dfd, { + id: mid + (counter++), + canDelete: false + }); + + if(options.jsonp){ + var queryParameter = new RegExp('[?&]' + options.jsonp + '='); + if(!queryParameter.test(url)){ + url += queryParameter + + (options.frameDoc ? 'parent.' : '') + + mid + '_callbacks.' + dfd.id; + } + + dfd.canDelete = true; + callbacks[dfd.id] = function(json){ + response.data = json; + dfd.handleResponse(response); + }; + } + + if(util.notify){ + util.notify.emit('send', response, dfd.promise.cancel); + } + + if(!options.canAttach || options.canAttach(dfd)){ + var node = script._attach(dfd.id, url, options.frameDoc); + + if(!options.jsonp && !options.checkString){ + var handle = on(node, loadEvent, function(evt){ + if(evt.type === 'load' || readyRegExp.test(node.readyState)){ + handle.remove(); + dfd.scriptLoaded = evt; + } + }); + } + } + + watch(dfd); + + return returnDeferred ? dfd : dfd.promise; + } + script.get = script; + /*===== + script = function(url, options){ + // summary: + // Sends a request using a script element with the given URL and options. + // url: String + // URL to request + // options: dojo/request/script.__Options? + // Options for the request. + // returns: dojo/request.__Promise + }; + script.__BaseOptions = declare(request.__BaseOptions, { + // 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 `jsonp` instead). + // frameDoc: Document? + // The Document object of 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. + }); + script.__MethodOptions = declare(null, { + // method: String? + // This option is ignored. All requests using this transport are + // GET requests. + }); + script.__Options = declare([script.__BaseOptions, script.__MethodOptions]); + + script.get = function(url, options){ + // summary: + // Send an HTTP GET request using a script element with the given URL and options. + // url: String + // URL to request + // options: dojo/request/script.__BaseOptions? + // Options for the request. + // returns: dojo/request.__Promise + }; + =====*/ + + // TODO: Remove in 2.0 + script._attach = attach; + script._remove = remove; + script._callbacksProperty = mid + '_callbacks'; + + return script; +}); diff --git a/lib/dojo/request/util.js b/lib/dojo/request/util.js new file mode 100644 index 000000000..a1dcf8321 --- /dev/null +++ b/lib/dojo/request/util.js @@ -0,0 +1,8 @@ +/* + Copyright (c) 2004-2012, The Dojo Foundation All Rights Reserved. + Available via Academic Free License >= 2.1 OR the modified BSD license. + see: http://dojotoolkit.org/license for details +*/ + +//>>built +define("dojo/request/util",["exports","../errors/RequestError","../errors/CancelError","../Deferred","../io-query","../_base/array","../_base/lang"],function(_1,_2,_3,_4,_5,_6,_7){_1.deepCopy=function deepCopy(_8,_9){for(var _a in _9){var _b=_8[_a],_c=_9[_a];if(_b!==_c){if(_b&&typeof _b==="object"&&_c&&typeof _c==="object"){_1.deepCopy(_b,_c);}else{_8[_a]=_c;}}}return _8;};_1.deepCreate=function deepCreate(_d,_e){_e=_e||{};var _f=_7.delegate(_d),_10,_11;for(_10 in _d){_11=_d[_10];if(_11&&typeof _11==="object"){_f[_10]=_1.deepCreate(_11,_e[_10]);}}return _1.deepCopy(_f,_e);};var _12=Object.freeze||function(obj){return obj;};function _13(_14){return _12(_14);};_1.deferred=function deferred(_15,_16,_17,_18,_19,_1a){var def=new _4(function(_1b){_16&&_16(def,_15);if(!_1b||!(_1b instanceof _2)&&!(_1b instanceof _3)){return new _3("Request canceled",_15);}return _1b;});def.response=_15;def.isValid=_17;def.isReady=_18;def.handleResponse=_19;function _1c(_1d){_1d.response=_15;throw _1d;};var _1e=def.then(_13).otherwise(_1c);if(_1.notify){_1e.then(_7.hitch(_1.notify,"emit","load"),_7.hitch(_1.notify,"emit","error"));}var _1f=_1e.then(function(_20){return _20.data||_20.text;});var _21=_12(_7.delegate(_1f,{response:_1e}));if(_1a){def.then(function(_22){_1a.call(def,_22);},function(_23){_1a.call(def,_15,_23);});}def.promise=_21;def.then=_21.then;return def;};_1.addCommonMethods=function addCommonMethods(_24,_25){_6.forEach(_25||["GET","POST","PUT","DELETE"],function(_26){_24[(_26==="DELETE"?"DEL":_26).toLowerCase()]=function(url,_27){_27=_7.delegate(_27||{});_27.method=_26;return _24(url,_27);};});};_1.parseArgs=function parseArgs(url,_28,_29){var _2a=_28.data,_2b=_28.query;if(_2a&&!_29){if(typeof _2a==="object"){_28.data=_5.objectToQuery(_2a);}}if(_2b){if(typeof _2b==="object"){_2b=_5.objectToQuery(_2b);}if(_28.preventCache){_2b+=(_2b?"&":"")+"request.preventCache="+(+(new Date));}}else{if(_28.preventCache){_2b="request.preventCache="+(+(new Date));}}if(url&&_2b){url+=(~url.indexOf("?")?"&":"?")+_2b;}return {url:url,options:_28,getHeader:function(_2c){return null;}};};_1.checkStatus=function(_2d){_2d=_2d||0;return (_2d>=200&&_2d<300)||_2d===304||_2d===1223||!_2d;};});
\ No newline at end of file diff --git a/lib/dojo/request/util.js.uncompressed.js b/lib/dojo/request/util.js.uncompressed.js new file mode 100644 index 000000000..988eb6746 --- /dev/null +++ b/lib/dojo/request/util.js.uncompressed.js @@ -0,0 +1,145 @@ +define("dojo/request/util", [ + 'exports', + '../errors/RequestError', + '../errors/CancelError', + '../Deferred', + '../io-query', + '../_base/array', + '../_base/lang' +], function(exports, RequestError, CancelError, Deferred, ioQuery, array, lang){ + exports.deepCopy = function deepCopy(target, source){ + for(var name in source){ + var tval = target[name], + sval = source[name]; + if(tval !== sval){ + if(tval && typeof tval === 'object' && sval && typeof sval === 'object'){ + exports.deepCopy(tval, sval); + }else{ + target[name] = sval; + } + } + } + return target; + }; + + exports.deepCreate = function deepCreate(source, properties){ + properties = properties || {}; + var target = lang.delegate(source), + name, value; + + for(name in source){ + value = source[name]; + + if(value && typeof value === 'object'){ + target[name] = exports.deepCreate(value, properties[name]); + } + } + return exports.deepCopy(target, properties); + }; + + var freeze = Object.freeze || function(obj){ return obj; }; + function okHandler(response){ + return freeze(response); + } + + exports.deferred = function deferred(response, cancel, isValid, isReady, handleResponse, last){ + var def = new Deferred(function(reason){ + cancel && cancel(def, response); + + if(!reason || !(reason instanceof RequestError) && !(reason instanceof CancelError)){ + return new CancelError('Request canceled', response); + } + return reason; + }); + + def.response = response; + def.isValid = isValid; + def.isReady = isReady; + def.handleResponse = handleResponse; + + function errHandler(error){ + error.response = response; + throw error; + } + var responsePromise = def.then(okHandler).otherwise(errHandler); + + if(exports.notify){ + responsePromise.then( + lang.hitch(exports.notify, 'emit', 'load'), + lang.hitch(exports.notify, 'emit', 'error') + ); + } + + var dataPromise = responsePromise.then(function(response){ + return response.data || response.text; + }); + + var promise = freeze(lang.delegate(dataPromise, { + response: responsePromise + })); + + + if(last){ + def.then(function(response){ + last.call(def, response); + }, function(error){ + last.call(def, response, error); + }); + } + + def.promise = promise; + def.then = promise.then; + + return def; + }; + + exports.addCommonMethods = function addCommonMethods(provider, methods){ + array.forEach(methods||['GET', 'POST', 'PUT', 'DELETE'], function(method){ + provider[(method === 'DELETE' ? 'DEL' : method).toLowerCase()] = function(url, options){ + options = lang.delegate(options||{}); + options.method = method; + return provider(url, options); + }; + }); + }; + + exports.parseArgs = function parseArgs(url, options, skipData){ + var data = options.data, + query = options.query; + + if(data && !skipData){ + if(typeof data === 'object'){ + options.data = ioQuery.objectToQuery(data); + } + } + + if(query){ + if(typeof query === 'object'){ + query = ioQuery.objectToQuery(query); + } + if(options.preventCache){ + query += (query ? '&' : '') + 'request.preventCache=' + (+(new Date)); + } + }else if(options.preventCache){ + query = 'request.preventCache=' + (+(new Date)); + } + + if(url && query){ + url += (~url.indexOf('?') ? '&' : '?') + query; + } + + return { + url: url, + options: options, + getHeader: function(headerName){ return null; } + }; + }; + + exports.checkStatus = function(stat){ + stat = stat || 0; + return (stat >= 200 && stat < 300) || // allow any 2XX response code + stat === 304 || // or, get it out of the cache + stat === 1223 || // or, Internet Explorer mangled the status code + !stat; // or, we're Titanium/browser chrome/chrome extension requesting a local file + }; +}); diff --git a/lib/dojo/request/watch.js b/lib/dojo/request/watch.js new file mode 100644 index 000000000..b38b4a6f4 --- /dev/null +++ b/lib/dojo/request/watch.js @@ -0,0 +1,8 @@ +/* + Copyright (c) 2004-2012, The Dojo Foundation All Rights Reserved. + Available via Academic Free License >= 2.1 OR the modified BSD license. + see: http://dojotoolkit.org/license for details +*/ + +//>>built +define("dojo/request/watch",["./util","../errors/RequestTimeoutError","../errors/CancelError","../_base/array","../_base/window","../has!host-browser?dom-addeventlistener?:../on:"],function(_1,_2,_3,_4,_5,on){var _6=null,_7=[];function _8(){var _9=+(new Date);for(var i=0,_a;i<_7.length&&(_a=_7[i]);i++){var _b=_a.response,_c=_b.options;if((_a.isCanceled&&_a.isCanceled())||(_a.isValid&&!_a.isValid(_b))){_7.splice(i--,1);_d._onAction&&_d._onAction();}else{if(_a.isReady&&_a.isReady(_b)){_7.splice(i--,1);_a.handleResponse(_b);_d._onAction&&_d._onAction();}else{if(_a.startTime){if(_a.startTime+(_c.timeout||0)<_9){_7.splice(i--,1);_a.cancel(new _2("Timeout exceeded",_b));_d._onAction&&_d._onAction();}}}}}_d._onInFlight&&_d._onInFlight(_a);if(!_7.length){clearInterval(_6);_6=null;}};function _d(_e){if(_e.response.options.timeout){_e.startTime=+(new Date);}if(_e.isFulfilled()){return;}_7.push(_e);if(!_6){_6=setInterval(_8,50);}if(_e.response.options.sync){_8();}};_d.cancelAll=function cancelAll(){try{_4.forEach(_7,function(_f){try{_f.cancel(new _3("All requests canceled."));}catch(e){}});}catch(e){}};if(_5&&on&&_5.doc.attachEvent){on(_5.global,"unload",function(){_d.cancelAll();});}return _d;});
\ No newline at end of file diff --git a/lib/dojo/request/watch.js.uncompressed.js b/lib/dojo/request/watch.js.uncompressed.js new file mode 100644 index 000000000..2b7722816 --- /dev/null +++ b/lib/dojo/request/watch.js.uncompressed.js @@ -0,0 +1,109 @@ +define("dojo/request/watch", [ + './util', + '../errors/RequestTimeoutError', + '../errors/CancelError', + '../_base/array', + '../_base/window', + '../has!host-browser?dom-addeventlistener?:../on:' +], function(util, RequestTimeoutError, CancelError, array, win, on){ + // avoid setting a timer per request. It degrades performance on IE + // something fierece if we don't use unified loops. + var _inFlightIntvl = null, + _inFlight = []; + + function watchInFlight(){ + // summary: + // internal method that checks each inflight XMLHttpRequest to see + // if it has completed or if the timeout situation applies. + + var now = +(new Date); + + // we need manual loop because we often modify _inFlight (and therefore 'i') while iterating + for(var i = 0, dfd; i < _inFlight.length && (dfd = _inFlight[i]); i++){ + var response = dfd.response, + options = response.options; + if((dfd.isCanceled && dfd.isCanceled()) || (dfd.isValid && !dfd.isValid(response))){ + _inFlight.splice(i--, 1); + watch._onAction && watch._onAction(); + }else if(dfd.isReady && dfd.isReady(response)){ + _inFlight.splice(i--, 1); + dfd.handleResponse(response); + watch._onAction && watch._onAction(); + }else if(dfd.startTime){ + // did we timeout? + if(dfd.startTime + (options.timeout || 0) < now){ + _inFlight.splice(i--, 1); + // Cancel the request so the io module can do appropriate cleanup. + dfd.cancel(new RequestTimeoutError('Timeout exceeded', response)); + watch._onAction && watch._onAction(); + } + } + } + + watch._onInFlight && watch._onInFlight(dfd); + + if(!_inFlight.length){ + clearInterval(_inFlightIntvl); + _inFlightIntvl = null; + } + } + + function watch(dfd){ + // summary: + // Watches the io request represented by dfd to see if it completes. + // dfd: Deferred + // The Deferred object to watch. + // response: Object + // The object used as the value of the request promise. + // validCheck: Function + // Function used to check if the IO request is still valid. Gets the dfd + // object as its only argument. + // ioCheck: Function + // Function used to check if basic IO call worked. Gets the dfd + // object as its only argument. + // resHandle: Function + // Function used to process response. Gets the dfd + // object as its only argument. + if(dfd.response.options.timeout){ + dfd.startTime = +(new Date); + } + + if(dfd.isFulfilled()){ + // bail out if the deferred is already fulfilled + return; + } + + _inFlight.push(dfd); + if(!_inFlightIntvl){ + _inFlightIntvl = setInterval(watchInFlight, 50); + } + + // handle sync requests separately from async: + // http://bugs.dojotoolkit.org/ticket/8467 + if(dfd.response.options.sync){ + watchInFlight(); + } + } + + watch.cancelAll = function cancelAll(){ + // summary: + // Cancels all pending IO requests, regardless of IO type + try{ + array.forEach(_inFlight, function(dfd){ + try{ + dfd.cancel(new CancelError('All requests canceled.')); + }catch(e){} + }); + }catch(e){} + }; + + if(win && on && win.doc.attachEvent){ + // Automatically call cancel all io calls on unload in IE + // http://bugs.dojotoolkit.org/ticket/2357 + on(win.global, 'unload', function(){ + watch.cancelAll(); + }); + } + + return watch; +}); diff --git a/lib/dojo/request/xhr.js b/lib/dojo/request/xhr.js new file mode 100644 index 000000000..ea63b4fe6 --- /dev/null +++ b/lib/dojo/request/xhr.js @@ -0,0 +1,8 @@ +/* + Copyright (c) 2004-2012, The Dojo Foundation All Rights Reserved. + Available via Academic Free License >= 2.1 OR the modified BSD license. + see: http://dojotoolkit.org/license for details +*/ + +//>>built +define("dojo/request/xhr",["../errors/RequestError","./watch","./handlers","./util","../has"],function(_1,_2,_3,_4,_5){_5.add("native-xhr",function(){return typeof XMLHttpRequest!=="undefined";});_5.add("dojo-force-activex-xhr",function(){return _5("activex")&&!document.addEventListener&&window.location.protocol==="file:";});_5.add("native-xhr2",function(){if(!_5("native-xhr")){return;}var x=new XMLHttpRequest();return typeof x["addEventListener"]!=="undefined"&&(typeof opera==="undefined"||typeof x["upload"]!=="undefined");});_5.add("native-formdata",function(){return typeof FormData==="function";});function _6(_7,_8){var _9=_7.xhr;_7.status=_7.xhr.status;_7.text=_9.responseText;if(_7.options.handleAs==="xml"){_7.data=_9.responseXML;}if(!_8){try{_3(_7);}catch(e){_8=e;}}if(_8){this.reject(_8);}else{if(_4.checkStatus(_9.status)){this.resolve(_7);}else{_8=new _1("Unable to load "+_7.url+" status: "+_9.status,_7);this.reject(_8);}}};var _a,_b,_c,_d;if(_5("native-xhr2")){_a=function(_e){return !this.isFulfilled();};_d=function(_f,_10){_10.xhr.abort();};_c=function(_11,dfd,_12){function _13(evt){dfd.handleResponse(_12);};function _14(evt){var _15=evt.target;var _16=new _1("Unable to load "+_12.url+" status: "+_15.status,_12);dfd.handleResponse(_12,_16);};function _17(evt){if(evt.lengthComputable){_12.loaded=evt.loaded;_12.total=evt.total;dfd.progress(_12);}};_11.addEventListener("load",_13,false);_11.addEventListener("error",_14,false);_11.addEventListener("progress",_17,false);return function(){_11.removeEventListener("load",_13,false);_11.removeEventListener("error",_14,false);_11.removeEventListener("progress",_17,false);};};}else{_a=function(_18){return _18.xhr.readyState;};_b=function(_19){return 4===_19.xhr.readyState;};_d=function(dfd,_1a){var xhr=_1a.xhr;var _1b=typeof xhr.abort;if(_1b==="function"||_1b==="object"||_1b==="unknown"){xhr.abort();}};}var _1c,_1d={data:null,query:null,sync:false,method:"GET",headers:{"Content-Type":"application/x-www-form-urlencoded"}};function xhr(url,_1e,_1f){var _20=_4.parseArgs(url,_4.deepCreate(_1d,_1e),_5("native-formdata")&&_1e&&_1e.data&&_1e.data instanceof FormData);url=_20.url;_1e=_20.options;var _21,_22=function(){_21&&_21();};var dfd=_4.deferred(_20,_d,_a,_b,_6,_22);var _23=_20.xhr=xhr._create();if(!_23){dfd.cancel(new _1("XHR was not created"));return _1f?dfd:dfd.promise;}_20.getHeader=function(_24){return this.xhr.getResponseHeader(_24);};if(_c){_21=_c(_23,dfd,_20);}var _25=_1e.data,_26=!_1e.sync,_27=_1e.method;try{_23.open(_27,url,_26,_1e.user||_1c,_1e.password||_1c);if(_1e.withCredentials){_23.withCredentials=_1e.withCredentials;}var _28=_1e.headers,_29;if(_28){for(var hdr in _28){if(hdr.toLowerCase()==="content-type"){_29=_28[hdr];}else{if(_28[hdr]){_23.setRequestHeader(hdr,_28[hdr]);}}}}if(_29&&_29!==false){_23.setRequestHeader("Content-Type",_29);}if(!_28||!("X-Requested-With" in _28)){_23.setRequestHeader("X-Requested-With","XMLHttpRequest");}if(_4.notify){_4.notify.emit("send",_20,dfd.promise.cancel);}_23.send(_25);}catch(e){dfd.reject(e);}_2(dfd);_23=null;return _1f?dfd:dfd.promise;};xhr._create=function(){throw new Error("XMLHTTP not available");};if(_5("native-xhr")&&!_5("dojo-force-activex-xhr")){xhr._create=function(){return new XMLHttpRequest();};}else{if(_5("activex")){try{new ActiveXObject("Msxml2.XMLHTTP");xhr._create=function(){return new ActiveXObject("Msxml2.XMLHTTP");};}catch(e){try{new ActiveXObject("Microsoft.XMLHTTP");xhr._create=function(){return new ActiveXObject("Microsoft.XMLHTTP");};}catch(e){}}}}_4.addCommonMethods(xhr);return xhr;});
\ No newline at end of file diff --git a/lib/dojo/request/xhr.js.uncompressed.js b/lib/dojo/request/xhr.js.uncompressed.js new file mode 100644 index 000000000..620fac3b1 --- /dev/null +++ b/lib/dojo/request/xhr.js.uncompressed.js @@ -0,0 +1,316 @@ +define("dojo/request/xhr", [ + '../errors/RequestError', + './watch', + './handlers', + './util', + '../has'/*=====, + '../request', + '../_base/declare' =====*/ +], function(RequestError, watch, handlers, util, has/*=====, request, declare =====*/){ + has.add('native-xhr', function(){ + // if true, the environment has a native XHR implementation + return typeof XMLHttpRequest !== 'undefined'; + }); + has.add('dojo-force-activex-xhr', function(){ + return has('activex') && !document.addEventListener && window.location.protocol === 'file:'; + }); + + has.add('native-xhr2', function(){ + if(!has('native-xhr')){ return; } + var x = new XMLHttpRequest(); + return typeof x['addEventListener'] !== 'undefined' && + (typeof opera === 'undefined' || typeof x['upload'] !== 'undefined'); + }); + + has.add('native-formdata', function(){ + // if true, the environment has a native FormData implementation + return typeof FormData === 'function'; + }); + + function handleResponse(response, error){ + var _xhr = response.xhr; + response.status = response.xhr.status; + response.text = _xhr.responseText; + + if(response.options.handleAs === 'xml'){ + response.data = _xhr.responseXML; + } + + if(!error){ + try{ + handlers(response); + }catch(e){ + error = e; + } + } + + if(error){ + this.reject(error); + }else if(util.checkStatus(_xhr.status)){ + this.resolve(response); + }else{ + error = new RequestError('Unable to load ' + response.url + ' status: ' + _xhr.status, response); + + this.reject(error); + } + } + + var isValid, isReady, addListeners, cancel; + if(has('native-xhr2')){ + // Any platform with XHR2 will only use the watch mechanism for timeout. + + isValid = function(response){ + // summary: + // Check to see if the request should be taken out of the watch queue + return !this.isFulfilled(); + }; + cancel = function(dfd, response){ + // summary: + // Canceler for deferred + response.xhr.abort(); + }; + addListeners = function(_xhr, dfd, response){ + // summary: + // Adds event listeners to the XMLHttpRequest object + function onLoad(evt){ + dfd.handleResponse(response); + } + function onError(evt){ + var _xhr = evt.target; + var error = new RequestError('Unable to load ' + response.url + ' status: ' + _xhr.status, response); + dfd.handleResponse(response, error); + } + + function onProgress(evt){ + if(evt.lengthComputable){ + response.loaded = evt.loaded; + response.total = evt.total; + dfd.progress(response); + } + } + + _xhr.addEventListener('load', onLoad, false); + _xhr.addEventListener('error', onError, false); + _xhr.addEventListener('progress', onProgress, false); + + return function(){ + _xhr.removeEventListener('load', onLoad, false); + _xhr.removeEventListener('error', onError, false); + _xhr.removeEventListener('progress', onProgress, false); + }; + }; + }else{ + isValid = function(response){ + return response.xhr.readyState; //boolean + }; + isReady = function(response){ + return 4 === response.xhr.readyState; //boolean + }; + cancel = function(dfd, response){ + // summary: + // canceller function for util.deferred call. + var xhr = response.xhr; + var _at = typeof xhr.abort; + if(_at === 'function' || _at === 'object' || _at === 'unknown'){ + xhr.abort(); + } + }; + } + + var undefined, + defaultOptions = { + data: null, + query: null, + sync: false, + method: 'GET', + headers: { + 'Content-Type': 'application/x-www-form-urlencoded' + } + }; + function xhr(url, options, returnDeferred){ + var response = util.parseArgs( + url, + util.deepCreate(defaultOptions, options), + has('native-formdata') && options && options.data && options.data instanceof FormData + ); + url = response.url; + options = response.options; + + var remover, + last = function(){ + remover && remover(); + }; + + //Make the Deferred object for this xhr request. + var dfd = util.deferred( + response, + cancel, + isValid, + isReady, + handleResponse, + last + ); + var _xhr = response.xhr = xhr._create(); + + if(!_xhr){ + // If XHR factory somehow returns nothings, + // cancel the deferred. + dfd.cancel(new RequestError('XHR was not created')); + return returnDeferred ? dfd : dfd.promise; + } + + response.getHeader = function(headerName){ + return this.xhr.getResponseHeader(headerName); + }; + + if(addListeners){ + remover = addListeners(_xhr, dfd, response); + } + + var data = options.data, + async = !options.sync, + method = options.method; + + try{ + // IE6 won't let you call apply() on the native function. + _xhr.open(method, url, async, options.user || undefined, options.password || undefined); + + if(options.withCredentials){ + _xhr.withCredentials = options.withCredentials; + } + + var headers = options.headers, + contentType; + if(headers){ + for(var hdr in headers){ + if(hdr.toLowerCase() === 'content-type'){ + contentType = headers[hdr]; + }else if(headers[hdr]){ + //Only add header if it has a value. This allows for instance, skipping + //insertion of X-Requested-With by specifying empty value. + _xhr.setRequestHeader(hdr, headers[hdr]); + } + } + } + + if(contentType && contentType !== false){ + _xhr.setRequestHeader('Content-Type', contentType); + } + if(!headers || !('X-Requested-With' in headers)){ + _xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest'); + } + + if(util.notify){ + util.notify.emit('send', response, dfd.promise.cancel); + } + _xhr.send(data); + }catch(e){ + dfd.reject(e); + } + + watch(dfd); + _xhr = null; + + return returnDeferred ? dfd : dfd.promise; + } + + /*===== + xhr = function(url, options){ + // summary: + // Sends a request using XMLHttpRequest with the given URL and options. + // url: String + // URL to request + // options: dojo/request/xhr.__Options? + // Options for the request. + // returns: dojo/request.__Promise + }; + xhr.__BaseOptions = declare(request.__BaseOptions, { + // sync: Boolean? + // Whether to make a synchronous request or not. Default + // is `false` (asynchronous). + // data: String|Object|FormData? + // Data to transfer. This is ignored for GET and DELETE + // requests. + // headers: Object? + // Headers to use for the request. + // user: String? + // Username to use during the request. + // password: String? + // Password to use during the request. + // withCredentials: Boolean? + // For cross-site requests, whether to send credentials + // or not. + }); + xhr.__MethodOptions = declare(null, { + // method: String? + // The HTTP method to use to make the request. Must be + // uppercase. Default is `"GET"`. + }); + xhr.__Options = declare([xhr.__BaseOptions, xhr.__MethodOptions]); + + xhr.get = function(url, options){ + // summary: + // Send an HTTP GET request using XMLHttpRequest with the given URL and options. + // url: String + // URL to request + // options: dojo/request/xhr.__BaseOptions? + // Options for the request. + // returns: dojo/request.__Promise + }; + xhr.post = function(url, options){ + // summary: + // Send an HTTP POST request using XMLHttpRequest with the given URL and options. + // url: String + // URL to request + // options: dojo/request/xhr.__BaseOptions? + // Options for the request. + // returns: dojo/request.__Promise + }; + xhr.put = function(url, options){ + // summary: + // Send an HTTP PUT request using XMLHttpRequest with the given URL and options. + // url: String + // URL to request + // options: dojo/request/xhr.__BaseOptions? + // Options for the request. + // returns: dojo/request.__Promise + }; + xhr.del = function(url, options){ + // summary: + // Send an HTTP DELETE request using XMLHttpRequest with the given URL and options. + // url: String + // URL to request + // options: dojo/request/xhr.__BaseOptions? + // Options for the request. + // returns: dojo/request.__Promise + }; + =====*/ + xhr._create = function(){ + // summary: + // does the work of portably generating a new XMLHTTPRequest object. + throw new Error('XMLHTTP not available'); + }; + if(has('native-xhr') && !has('dojo-force-activex-xhr')){ + xhr._create = function(){ + return new XMLHttpRequest(); + }; + }else if(has('activex')){ + try{ + new ActiveXObject('Msxml2.XMLHTTP'); + xhr._create = function(){ + return new ActiveXObject('Msxml2.XMLHTTP'); + }; + }catch(e){ + try{ + new ActiveXObject('Microsoft.XMLHTTP'); + xhr._create = function(){ + return new ActiveXObject('Microsoft.XMLHTTP'); + }; + }catch(e){} + } + } + + util.addCommonMethods(xhr); + + return xhr; +}); |