root / trunk / web / dojo / dojox / io / xhrPlugins.js @ 12
History | View | Annotate | Download (2.73 KB)
1 | 9 | andrej.cim | /*
|
---|---|---|---|
2 | Copyright (c) 2004-2010, 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 | |||
8 | if(!dojo._hasResource["dojox.io.xhrPlugins"]){ |
||
9 | dojo._hasResource["dojox.io.xhrPlugins"]=true; |
||
10 | dojo.provide("dojox.io.xhrPlugins");
|
||
11 | dojo.require("dojo.AdapterRegistry");
|
||
12 | dojo.require("dojo._base.xhr");
|
||
13 | (function(){
|
||
14 | var _1;
|
||
15 | var _2;
|
||
16 | function _3(){ |
||
17 | return _2=dojox.io.xhrPlugins.plainXhr=_2||dojo._defaultXhr||dojo.xhr;
|
||
18 | }; |
||
19 | dojox.io.xhrPlugins.register=function(){ |
||
20 | var _4=_3();
|
||
21 | if(!_1){
|
||
22 | _1=new dojo.AdapterRegistry();
|
||
23 | dojo[dojo._defaultXhr?"_defaultXhr":"xhr"]=function(_5,_6,_7){ |
||
24 | return _1.match.apply(_1,arguments); |
||
25 | }; |
||
26 | _1.register("xhr",function(_8,_9){ |
||
27 | if(!_9.url.match(/^\w*:\/\//)){ |
||
28 | return true; |
||
29 | } |
||
30 | var _a=window.location.href.match(/^.*?\/\/.*?\//)[0]; |
||
31 | return _9.url.substring(0,_a.length)==_a; |
||
32 | },_4); |
||
33 | } |
||
34 | return _1.register.apply(_1,arguments); |
||
35 | }; |
||
36 | dojox.io.xhrPlugins.addProxy=function(_b){ |
||
37 | var _c=_3();
|
||
38 | dojox.io.xhrPlugins.register("proxy",function(_d,_e){ |
||
39 | return true; |
||
40 | },function(_f,_10,_11){
|
||
41 | _10.url=_b+encodeURIComponent(_10.url); |
||
42 | return _c.call(dojo,_f,_10,_11);
|
||
43 | }); |
||
44 | }; |
||
45 | var _12;
|
||
46 | dojox.io.xhrPlugins.addCrossSiteXhr=function(url,_13){ |
||
47 | var _14=_3();
|
||
48 | if(_12===undefined&&window.XMLHttpRequest){ |
||
49 | try{
|
||
50 | var xhr=new XMLHttpRequest(); |
||
51 | xhr.open("GET","http://testing-cross-domain-capability.com",true); |
||
52 | _12=true;
|
||
53 | dojo.config.noRequestedWithHeaders=true;
|
||
54 | } |
||
55 | catch(e){
|
||
56 | _12=false;
|
||
57 | } |
||
58 | } |
||
59 | dojox.io.xhrPlugins.register("cs-xhr",function(_15,_16){ |
||
60 | return (_12||(window.XDomainRequest&&_16.sync!==true&&(_15=="GET"||_15=="POST"||_13)))&&(_16.url.substring(0,url.length)==url); |
||
61 | },_12?_14:function(){ |
||
62 | var _17=dojo._xhrObj;
|
||
63 | dojo._xhrObj=function(){ |
||
64 | var xdr=new XDomainRequest(); |
||
65 | xdr.readyState=1;
|
||
66 | xdr.setRequestHeader=function(){ |
||
67 | }; |
||
68 | xdr.getResponseHeader=function(_18){ |
||
69 | return _18=="Content-Type"?xdr.contentType:null; |
||
70 | }; |
||
71 | function _19(_1a,_1b){ |
||
72 | return function(){ |
||
73 | xdr.readyState=_1b; |
||
74 | xdr.status=_1a; |
||
75 | }; |
||
76 | }; |
||
77 | xdr.onload=_19(200,4); |
||
78 | xdr.onprogress=_19(200,3); |
||
79 | xdr.onerror=_19(404,4); |
||
80 | return xdr;
|
||
81 | }; |
||
82 | var dfd=(_13?_13(_3()):_3()).apply(dojo,arguments); |
||
83 | dojo._xhrObj=_17; |
||
84 | return dfd;
|
||
85 | }); |
||
86 | }; |
||
87 | dojox.io.xhrPlugins.fullHttpAdapter=function(_1c,_1d){ |
||
88 | return function(_1e,_1f,_20){ |
||
89 | var _21={};
|
||
90 | var _22={};
|
||
91 | if(_1e!="GET"){ |
||
92 | _22["http-method"]=_1e;
|
||
93 | if(_1f.putData&&_1d){
|
||
94 | _21["http-content"]=_1f.putData;
|
||
95 | delete _1f.putData;
|
||
96 | _20=false;
|
||
97 | } |
||
98 | if(_1f.postData&&_1d){
|
||
99 | _21["http-content"]=_1f.postData;
|
||
100 | delete _1f.postData;
|
||
101 | _20=false;
|
||
102 | } |
||
103 | _1e="POST";
|
||
104 | } |
||
105 | for(var i in _1f.headers){ |
||
106 | var _23=i.match(/^X-/)?i.substring(2).replace(/-/g,"_").toLowerCase():("http-"+i); |
||
107 | _22[_23]=_1f.headers[i]; |
||
108 | } |
||
109 | _1f.query=dojo.objectToQuery(_22); |
||
110 | dojo._ioAddQueryToUrl(_1f); |
||
111 | _1f.content=dojo.mixin(_1f.content||{},_21); |
||
112 | return _1c.call(dojo,_1e,_1f,_20);
|
||
113 | }; |
||
114 | }; |
||
115 | })(); |
||
116 | } |