//>>built
define("dojox/form/uploader/plugins/HTML5",["dojo/_base/declare","dojo/_base/lang","dojo/_base/array","dojo"],function(g,d,h,e){g=g("dojox.form.uploader.plugins.HTML5",[],{errMsg:"Error uploading files. Try checking permissions",uploadType:"html5",postCreate:function(){this.connectForm();this.inherited(arguments);this.uploadOnSelect&&this.connect(this,"onChange",function(a){this.upload(a[0])})},_drop:function(a){e.stopEvent(a);this._files=a.dataTransfer.files;this.onChange(this.getFileList())},upload:function(a){this.onBegin(this.getFileList());
this.supports("FormData")?this.uploadWithFormData(a):this.supports("sendAsBinary")&&this.sendAsBinary(a)},addDropTarget:function(a,c){c||(this.connect(a,"dragenter",e.stopEvent),this.connect(a,"dragover",e.stopEvent),this.connect(a,"dragleave",e.stopEvent));this.connect(a,"drop","_drop")},sendAsBinary:function(a){if(this.getUrl()){var c="---------------------------"+(new Date).getTime(),b=this.createXhr();b.setRequestHeader("Content-Type","multipart/form-data; boundary="+c);if(a=this._buildRequestBody(a,
c))b.sendAsBinary(a);else this.onError(this.errMsg)}},uploadWithFormData:function(a){if(this.getUrl()){var c=new FormData,b=this._getFileFieldName();h.forEach(this._files,function(a){c.append(b,a)},this);if(a)for(var f in a)c.append(f,a[f]);this.createXhr().send(c)}},_xhrProgress:function(a){if(a.lengthComputable){var c={bytesLoaded:a.loaded,bytesTotal:a.total,type:a.type,timeStamp:a.timeStamp};"load"==a.type?(c.percent="100%",c.decimal=1):(c.decimal=a.loaded/a.total,c.percent=Math.ceil(100*(a.loaded/
a.total))+"%");this.onProgress(c)}},createXhr:function(){var a=new XMLHttpRequest,c;a.upload.addEventListener("progress",d.hitch(this,"_xhrProgress"),!1);a.addEventListener("load",d.hitch(this,"_xhrProgress"),!1);a.addEventListener("error",d.hitch(this,function(a){this.onError(a);clearInterval(c)}),!1);a.addEventListener("abort",d.hitch(this,function(a){this.onAbort(a);clearInterval(c)}),!1);a.onreadystatechange=d.hitch(this,function(){if(4===a.readyState){clearInterval(c);try{this.onComplete(JSON.parse(a.responseText.replace(/^\{\}&&/,
"")))}catch(b){this.onError("Error parsing server result:",b)}}});a.open("POST",this.getUrl());c=setInterval(d.hitch(this,function(){}),250);return a},_buildRequestBody:function(a,c){var b="",c="--"+c,f=[],d=this._files,g=this._getFileFieldName();h.forEach(d,function(a,d){var e=a.fileName,h;try{h=a.getAsBinary()+"\r\n",b+=c+"\r\n",b+="Content-Disposition: form-data; ",b+='name="'+g+'"; ',b+='filename="'+e+'"\r\n',b+="Content-Type: "+this.getMimeType()+"\r\n\r\n",b+=h}catch(i){f.push({index:d,name:e})}},
this);f.length&&f.length>=d.length&&(this.onError({message:this.errMsg,filesInError:f}),b=!1);if(!b)return!1;if(a)for(var e in a)b+=c+"\r\n",b+="Content-Disposition: form-data; ",b+='name="'+e+'"\r\n\r\n',b+=a[e]+"\r\n";return b+=c+"--\r\n"}});dojox.form.addUploaderPlugin(g);return g});