]> git.wh0rd.org - tt-rss.git/blob - lib/dojo/io/iframe.js.uncompressed.js
upgrade dojo to 1.8.3 (refs #570)
[tt-rss.git] / lib / dojo / io / iframe.js.uncompressed.js
1 define("dojo/io/iframe", [
2 "../_base/config", "../_base/json", "../_base/kernel", /*===== "../_base/declare", =====*/ "../_base/lang",
3 "../_base/xhr", "../sniff", "../_base/window",
4 "../dom", "../dom-construct", "../query", "require", "../aspect", "../request/iframe"
5 ], function(config, json, kernel, /*===== declare, =====*/ lang, xhr, has, win, dom, domConstruct, query, require, aspect, _iframe){
6
7 // module:
8 // dojo/io/iframe
9
10 kernel.deprecated("dojo/io/iframe", "Use dojo/request/iframe.", "2.0");
11
12 /*=====
13 var __ioArgs = declare(kernel.__IoArgs, {
14 // method: String?
15 // The HTTP method to use. "GET" or "POST" are the only supported
16 // values. It will try to read the value from the form node's
17 // method, then try this argument. If neither one exists, then it
18 // defaults to POST.
19 // handleAs: String?
20 // Specifies what format the result data should be given to the
21 // load/handle callback. Valid values are: text, html, xml, json,
22 // javascript. IMPORTANT: For all values EXCEPT html and xml, The
23 // server response should be an HTML file with a textarea element.
24 // The response data should be inside the textarea element. Using an
25 // HTML document the only reliable, cross-browser way this
26 // transport can know when the response has loaded. For the html
27 // handleAs value, just return a normal HTML document. NOTE: xml
28 // is now supported with this transport (as of 1.1+); a known issue
29 // is if the XML document in question is malformed, Internet Explorer
30 // will throw an uncatchable error.
31 // content: Object?
32 // If "form" is one of the other args properties, then the content
33 // object properties become hidden form form elements. For
34 // instance, a content object of {name1 : "value1"} is converted
35 // to a hidden form element with a name of "name1" and a value of
36 // "value1". If there is not a "form" property, then the content
37 // object is converted into a name=value&name=value string, by
38 // using xhr.objectToQuery().
39 });
40 =====*/
41
42 /*=====
43 return kernel.io.iframe = {
44 // summary:
45 // Deprecated, use dojo/request/iframe instead.
46 // Sends an Ajax I/O call using and Iframe (for instance, to upload files)
47
48 create: function(fname, onloadstr, uri){
49 // summary:
50 // Creates a hidden iframe in the page. Used mostly for IO
51 // transports. You do not need to call this to start a
52 // dojo/io/iframe request. Just call send().
53 // fname: String
54 // The name of the iframe. Used for the name attribute on the
55 // iframe.
56 // onloadstr: String
57 // A string of JavaScript that will be executed when the content
58 // in the iframe loads.
59 // uri: String
60 // The value of the src attribute on the iframe element. If a
61 // value is not given, then dojo/resources/blank.html will be
62 // used.
63 },
64 setSrc: function(iframe, src, replace){
65 // summary:
66 // Sets the URL that is loaded in an IFrame. The replace parameter
67 // indicates whether location.replace() should be used when
68 // changing the location of the iframe.
69 },
70 doc: function(iframeNode){
71 // summary:
72 // Returns the document object associated with the iframe DOM Node argument.
73 }
74 };
75 =====*/
76
77
78 var mid = _iframe._iframeName;
79 mid = mid.substring(0, mid.lastIndexOf('_'));
80
81 var iframe = lang.delegate(_iframe, {
82 // summary:
83 // Deprecated, use dojo/request/iframe instead.
84 // Sends an Ajax I/O call using and Iframe (for instance, to upload files)
85
86 create: function(){
87 return iframe._frame = _iframe.create.apply(_iframe, arguments);
88 },
89
90 // cover up delegated methods
91 get: null,
92 post: null,
93
94 send: function(/*__ioArgs*/args){
95 // summary:
96 // Function that sends the request to the server.
97 // This transport can only process one send() request at a time, so if send() is called
98 // multiple times, it will queue up the calls and only process one at a time.
99 var rDfd;
100
101 //Set up the deferred.
102 var dfd = xhr._ioSetArgs(args,
103 function(/*Deferred*/dfd){
104 // summary:
105 // canceller function for xhr._ioSetArgs call.
106 rDfd && rDfd.cancel();
107 },
108 function(/*Deferred*/dfd){
109 // summary:
110 // okHandler function for xhr._ioSetArgs call.
111 var value = null,
112 ioArgs = dfd.ioArgs;
113 try{
114 var handleAs = ioArgs.handleAs;
115
116 //Assign correct value based on handleAs value.
117 if(handleAs === "xml" || handleAs === "html"){
118 value = rDfd.response.data;
119 }else{
120 value = rDfd.response.text;
121 if(handleAs === "json"){
122 value = json.fromJson(value);
123 }else if(handleAs === "javascript"){
124 value = kernel.eval(value);
125 }
126 }
127 }catch(e){
128 value = e;
129 }
130 return value;
131 },
132 function(/*Error*/error, /*Deferred*/dfd){
133 // summary:
134 // errHandler function for xhr._ioSetArgs call.
135 dfd.ioArgs._hasError = true;
136 return error;
137 }
138 );
139
140 var ioArgs = dfd.ioArgs;
141
142 var method = "GET",
143 form = dom.byId(args.form);
144 if(args.method && args.method.toUpperCase() === "POST" && form){
145 method = "POST";
146 }
147
148 var options = {
149 method: method,
150 handleAs: args.handleAs === "json" || args.handleAs === "javascript" ? "text" : args.handleAs,
151 form: args.form,
152 query: form ? null : args.content,
153 data: form ? args.content : null,
154 timeout: args.timeout,
155 ioArgs: ioArgs
156 };
157
158 if(options.method){
159 options.method = options.method.toUpperCase();
160 }
161
162 if(config.ioPublish && kernel.publish && ioArgs.args.ioPublish !== false){
163 var start = aspect.after(_iframe, "_notifyStart", function(data){
164 if(data.options.ioArgs === ioArgs){
165 start.remove();
166 xhr._ioNotifyStart(dfd);
167 }
168 }, true);
169 }
170 rDfd = _iframe(ioArgs.url, options, true);
171
172 ioArgs._callNext = rDfd._callNext;
173
174 rDfd.then(function(){
175 dfd.resolve(dfd);
176 }).otherwise(function(error){
177 dfd.ioArgs.error = error;
178 dfd.reject(error);
179 });
180
181 return dfd;
182 },
183
184 _iframeOnload: win.global[mid + '_onload']
185 });
186
187 lang.setObject("dojo.io.iframe", iframe);
188
189 return iframe;
190 });