/*
	Copyright (c) 2004-2016, The JS 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 ../NodeList-dom ../NodeList-manipulate".split(" "),function(F,G,H,p,I,y,B,C,z,D,q,g){function J(a){return!this.isFulfilled()}function K(a){return!!this._finished}function L(a,b){if(!b)try{var d=a.options,f=c.doc(c._frame),e=d.handleAs;if("html"!==e){if("xml"===e)if("html"===f.documentElement.tagName.toLowerCase()){C("a",f.documentElement).orphan();
var h=f.documentElement.innerText||f.documentElement.textContent;h=h.replace(/>\s+</g,"\x3e\x3c");a.text=y.trim(h)}else a.data=f;else a.text=f.getElementsByTagName("textarea")[0].value;I(a)}else a.data=f}catch(k){b=k}b?this.reject(b):this._finished?this.resolve(a):this.reject(Error("Invalid dojo/request/iframe request state"))}function M(a){this._callNext()}function c(a,b,d){var f=p.parseArgs(a,p.deepCreate(N,b),!0);a=f.url;b=f.options;if("GET"!==b.method&&"POST"!==b.method)throw Error(b.method+" not supported by dojo/request/iframe");
c._frame||(c._frame=c.create(c._iframeName,A+"();"));a=p.deferred(f,null,J,K,L,M);a._callNext=function(){this._calledNext||(this._calledNext=!0,c._currentDfd=null,c._fireNextRequest())};a._legacy=d;c._dfdQueue.push(a);c._fireNextRequest();H(a);return d?a:a.promise}var t=F.id.replace(/[\/\.\-]/g,"_"),A=t+"_onload";g.global[A]||(g.global[A]=function(){var a=c._currentDfd;if(a){var b=D.byId(a.response.options.form)||a._tmpForm;if(b){for(var d=a._contentToClean,f=0;f<d.length;f++)for(var e=d[f],h=0;h<
b.childNodes.length;h++){var k=b.childNodes[h];if(k.name===e){q.destroy(k);break}}a._originalAction&&b.setAttribute("action",a._originalAction);a._originalMethod&&(b.setAttribute("method",a._originalMethod),b.method=a._originalMethod);a._originalTarget&&(b.setAttribute("target",a._originalTarget),b.target=a._originalTarget)}a._tmpForm&&(q.destroy(a._tmpForm),delete a._tmpForm);a._finished=!0}else c._fireNextRequest()});var N={method:"POST"};c.create=function(a,b,d){if(g.global[a])return g.global[a];
if(g.global.frames[a])return g.global.frames[a];d||(z("config-useXDomain")&&z("config-dojoBlankHtmlUrl"),d=z("config-dojoBlankHtmlUrl")||G.toUrl("dojo/resources/blank.html"));b=q.place('\x3ciframe id\x3d"'+a+'" name\x3d"'+a+'" src\x3d"'+d+'" onload\x3d"'+b+'" style\x3d"position: absolute; left: 1px; top: 1px; height: 1px; width: 1px; visibility: hidden"\x3e',g.body());return g.global[a]=b};c.doc=function(a){if(a.contentDocument)return a.contentDocument;var b=a.name;if(b){var d=g.doc.getElementsByTagName("iframe");
if(a.document&&d[b].contentWindow&&d[b].contentWindow.document)return d[b].contentWindow.document;if(g.doc.frames[b]&&g.doc.frames[b].document)return g.doc.frames[b].document}return null};c.setSrc=function(a,b,d){a=g.global.frames[a.name];a.contentWindow&&(a=a.contentWindow);try{d?a.location.replace(b):a.location=b}catch(f){}};c._iframeName=t+"_IoIframe";c._notifyStart=function(){};c._dfdQueue=[];c._currentDfd=null;c._fireNextRequest=function(){try{if(!c._currentDfd&&c._dfdQueue.length){do var a=
c._currentDfd=c._dfdQueue.shift();while(a&&(a.canceled||a.isCanceled&&a.isCanceled())&&c._dfdQueue.length);if(!a||a.canceled||a.isCanceled&&a.isCanceled())c._currentDfd=null;else{var b=a.response,d=b.options,f=a._contentToClean=[],e=D.byId(d.form),h=p.notify,k=d.data||null;if(!a._legacy&&"POST"===d.method&&!e)e=a._tmpForm=q.create("form",{name:t+"_form",style:{position:"absolute",top:"-1000px",left:"-1000px"}},g.body());else if("GET"===d.method&&e&&-1<b.url.indexOf("?")){var r=b.url.slice(b.url.indexOf("?")+
1);k=y.mixin(B.queryToObject(r),k)}if(e){if(!a._legacy){var l=e;do l=l.parentNode;while(l&&l!==g.doc.documentElement);l||(e.style.position="absolute",e.style.left="-1000px",e.style.top="-1000px",g.body().appendChild(e));e.name||(e.name=t+"_form")}if(k){l=function(u,O){q.create("input",{type:"hidden",name:u,value:O},e);f.push(u)};for(var v in k){var n=k[v];if(y.isArray(n)&&1<n.length)for(r=0;r<n.length;r++)l(v,n[r]);else{var E=C("input[name\x3d'"+v+"']",e);-1==E.indexOf()?l(v,n):E.val(n)}}}var w=e.getAttributeNode("action"),
m=e.getAttributeNode("method"),x=e.getAttributeNode("target");b.url&&(a._originalAction=w?w.value:null,w?w.value=b.url:e.setAttribute("action",b.url));a._legacy?m&&m.value||(m?m.value=d.method:e.setAttribute("method",d.method)):(a._originalMethod=m?m.value:null,m?m.value=d.method:e.setAttribute("method",d.method));a._originalTarget=x?x.value:null;x?x.value=c._iframeName:e.setAttribute("target",c._iframeName);e.target=c._iframeName;h&&h.emit("send",b,a.promise.cancel);c._notifyStart(b);e.submit()}else d=
"",b.options.data&&(d=b.options.data,"string"!==typeof d&&(d=B.objectToQuery(d))),l=b.url+(-1<b.url.indexOf("?")?"\x26":"?")+d,h&&h.emit("send",b,a.promise.cancel),c._notifyStart(b),c.setSrc(c._frame,l,!0)}}}catch(u){a.reject(u)}};p.addCommonMethods(c,["GET","POST"]);return c});