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){
10 kernel.deprecated("dojo/io/iframe", "Use dojo/request/iframe.", "2.0");
13 var __ioArgs = declare(kernel.__IoArgs, {
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
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.
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().
43 return kernel.io.iframe = {
45 // Deprecated, use dojo/request/iframe instead.
46 // Sends an Ajax I/O call using and Iframe (for instance, to upload files)
48 create: function(fname, onloadstr, uri){
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().
54 // The name of the iframe. Used for the name attribute on the
57 // A string of JavaScript that will be executed when the content
58 // in the iframe loads.
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
64 setSrc: function(iframe, src, replace){
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.
70 doc: function(iframeNode){
72 // Returns the document object associated with the iframe DOM Node argument.
78 var mid = _iframe._iframeName;
79 mid = mid.substring(0, mid.lastIndexOf('_'));
81 var iframe = lang.delegate(_iframe, {
83 // Deprecated, use dojo/request/iframe instead.
84 // Sends an Ajax I/O call using and Iframe (for instance, to upload files)
87 return iframe._frame = _iframe.create.apply(_iframe, arguments);
90 // cover up delegated methods
94 send: function(/*__ioArgs*/args){
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.
101 //Set up the deferred.
102 var dfd = xhr._ioSetArgs(args,
103 function(/*Deferred*/dfd){
105 // canceller function for xhr._ioSetArgs call.
106 rDfd && rDfd.cancel();
108 function(/*Deferred*/dfd){
110 // okHandler function for xhr._ioSetArgs call.
114 var handleAs = ioArgs.handleAs;
116 //Assign correct value based on handleAs value.
117 if(handleAs === "xml" || handleAs === "html"){
118 value = rDfd.response.data;
120 value = rDfd.response.text;
121 if(handleAs === "json"){
122 value = json.fromJson(value);
123 }else if(handleAs === "javascript"){
124 value = kernel.eval(value);
132 function(/*Error*/error, /*Deferred*/dfd){
134 // errHandler function for xhr._ioSetArgs call.
135 dfd.ioArgs._hasError = true;
140 var ioArgs = dfd.ioArgs;
143 form = dom.byId(args.form);
144 if(args.method && args.method.toUpperCase() === "POST" && form){
150 handleAs: args.handleAs === "json" || args.handleAs === "javascript" ? "text" : args.handleAs,
152 query: form ? null : args.content,
153 data: form ? args.content : null,
154 timeout: args.timeout,
159 options.method = options.method.toUpperCase();
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){
166 xhr._ioNotifyStart(dfd);
170 rDfd = _iframe(ioArgs.url, options, true);
172 ioArgs._callNext = rDfd._callNext;
174 rDfd.then(function(){
176 }).otherwise(function(error){
177 dfd.ioArgs.error = error;
184 _iframeOnload: win.global[mid + '_onload']
187 lang.setObject("dojo.io.iframe", iframe);