diff --git a/AjaxControlToolkit/AjaxFileUpload/AjaxFileUpload.cs b/AjaxControlToolkit/AjaxFileUpload/AjaxFileUpload.cs
index 052582c15..9c24ca371 100644
--- a/AjaxControlToolkit/AjaxFileUpload/AjaxFileUpload.cs
+++ b/AjaxControlToolkit/AjaxFileUpload/AjaxFileUpload.cs
@@ -139,6 +139,18 @@ public AjaxFileUpload()
set { ViewState["Mode"] = value.ToString(); }
}
+ ///
+ /// Whether or not automatically start upload files after drag/drop or select in file dialog. The default is false
+ ///
+ [ExtenderControlProperty]
+ [DefaultValue(false)]
+ [ClientPropertyName("autoStartUpload")]
+ public bool AutoStartUpload
+ {
+ get { return bool.Parse((string)ViewState["AutoStartUpload"] ?? "false"); }
+ set { ViewState["AutoStartUpload"] = value.ToString(); }
+ }
+
///
/// An event raised when the file upload starts.
///
diff --git a/AjaxControlToolkit/Scripts/AjaxFileUpload.js b/AjaxControlToolkit/Scripts/AjaxFileUpload.js
index 865cbcbfe..818f767a5 100644
--- a/AjaxControlToolkit/Scripts/AjaxFileUpload.js
+++ b/AjaxControlToolkit/Scripts/AjaxFileUpload.js
@@ -584,6 +584,11 @@ Sys.Extended.UI.AjaxFileUpload.ProcessorHtml5 = function(control, elements) {
e.stopPropagation();
e.preventDefault();
this.addFilesToQueue(e.dataTransfer.files);
+
+ if (control.get_autoStartUpload()) {
+ control.startUpload();
+ }
+
};
this.onFileDragOverHandler = function(e) {
@@ -594,6 +599,10 @@ Sys.Extended.UI.AjaxFileUpload.ProcessorHtml5 = function(control, elements) {
this.onFileSelectedHandler = function(e) {
this.addFilesToQueue(e.target.files);
this.createInputFileElement();
+
+ if (control.get_autoStartUpload()) {
+ control.startUpload();
+ }
};
this.createInputFileElement = function() {
@@ -633,10 +642,10 @@ Sys.Extended.UI.AjaxFileUpload.ProcessorHtml5 = function(control, elements) {
// #endregion
- this.addFilesToQueue = function(files) {
- // Validate and generate file item from HTML5 files.
+ this.addFilesToQueue = function (files) {
- for(var i = 0; i < files.length; i++) {
+ // Validate and generate file item from HTML5 files.
+ for (var i = 0; i < files.length; i++) {
var blob = files[i],
slices = 0;
@@ -953,6 +962,14 @@ Sys.Extended.UI.AjaxFileUpload.Control = function(element) {
///
this._mode = 0;
+ ///
+ /// Whether or not automatically start upload files after drag/drop or select in file dialog. The default is false
+ ///
+ /// get_autoStartUpload
+ /// set_autoStartUpload
+ ///
+ this._autoStartUpload = false;
+
///
/// Whether or not AjaxFileUpload supports server polling.
///
@@ -1182,6 +1199,18 @@ Sys.Extended.UI.AjaxFileUpload.Control.prototype = {
}
},
+ ///
+ /// Manually starts upload process
+ ///
+ startUpload: function () {
+ if (this._isUploading || !this._filesInQueue.length) {
+ return;
+ }
+
+ this._onUploadOrCancelButtonClickedHandler();
+ },
+
+
///
/// If set to true, it will set the control state to enabled (ready to upload),
/// otherwise the control will be disabled and the button state turns to the Cancel button.
@@ -1530,6 +1559,13 @@ Sys.Extended.UI.AjaxFileUpload.Control.prototype = {
this._mode = value;
},
+ get_autoStartUpload: function () {
+ return this._autoStartUpload;
+ },
+ set_autoStartUpload: function (value) {
+ this._autoStartUpload = value;
+ },
+
get_serverPollingSupport: function() {
return this._serverPollingSupport;
},
diff --git a/AjaxControlToolkit/Scripts/AjaxFileUpload.min.js b/AjaxControlToolkit/Scripts/AjaxFileUpload.min.js
index 169a51e33..2dcf3824b 100644
--- a/AjaxControlToolkit/Scripts/AjaxFileUpload.min.js
+++ b/AjaxControlToolkit/Scripts/AjaxFileUpload.min.js
@@ -1 +1 @@
-Type.registerNamespace("Sys.Extended.UI.AjaxFileUpload");Sys.Extended.UI.AjaxFileUpload.Utils=function(){this.generateGuid=function(){for(var i,t="",n=0;n<32;n++)(n==8||n==12||n==16||n==20)&&(t=t+"-"),i=Math.floor(Math.random()*16).toString(16).toUpperCase(),t=t+i;return t};this.getFileName=function(n){var i="",r,t;if(!n)return"";if(!n.value&&n.name)i=n.name;else{if(!n.value&&typeof n!="string")throw"Invalid parameter. fullPath parameter must be a string of full path or file element.";n.value&&(n=n.value);n&&(r=n.indexOf("\\")>=0?n.lastIndexOf("\\"):n.lastIndexOf("/"),t=n.substring(r),(t.indexOf("\\")===0||t.indexOf("/")===0)&&(t=t.substring(1)),i=t)}return encodeURIComponent(i)};this.getFileType=function(n){if(!n)throw"file must defined or not null";if(!n.value&&n.name)return n.name.substring(n.name.lastIndexOf(".")+1);if(n.value&&(n=n.value),typeof n!="string")throw"can't resolve file type.";return n.substring(n.lastIndexOf(".")+1)};this.sizeToString=function(n){if(!n||n<=0)return"0 Kb";var t=Math.floor(Math.log(n)/Math.log(1024));return(n/Math.pow(1024,Math.floor(t))).toFixed(2)+" "+["bytes","kb","MB","GB","TB","PB"][t]};this.checkHtml5BrowserSupport=function(){return window.File&&window.FileReader&&window.FileList&&window.Blob&&(new XMLHttpRequest).upload}};Sys.Extended.UI.AjaxFileUpload.Item=function(n,t,i){this._deleteButton=null;this._parentId=n;this._inputElementValue=t.value;this._id=t.id;this._slices=t.slices;this._sliceIndex=0;this._fileInfoContainer=null;this._fileStatusText=null;this._isUploaded=!1;this._isUploading=!1;this._fileSize=0;this._fileName="";this._fileType="";this._bytesUploaded=0;this._ui=this.initUI(i)};Sys.Extended.UI.AjaxFileUpload.Item.prototype={initUI:function(n){var l=this,t=this._inputElementValue,e=new Sys.Extended.UI.AjaxFileUpload.Utils,a=e.checkHtml5BrowserSupport(),i=this._id,r=$common.createElementFromTemplate({nodeName:"div",properties:{id:this._parentId+"_FileItemContainer_"+i},cssClasses:["ajax__fileupload_fileItemInfo"]}),u=$common.createElementFromTemplate({nodeName:"div",properties:{id:this._parentId+"_FileInfoContainer_"+i,style:{display:"inline-block"}}}),o=$common.createElementFromTemplate({nodeName:"span",properties:{id:this._parentId+"_FileItemInfo_"+i},cssClasses:["ajax__fileupload_fileItemInfo"]}),h=$common.createElementFromTemplate({nodeName:"span",properties:{id:this._parentId+"_FileItemStatus_"+i},cssClasses:["uploadstatus"]}),f=$common.createElementFromTemplate({nodeName:"div",properties:{id:this._parentId+"_FileItemDeleteButton_"+i},cssClasses:["removeButton"]}),s,c;return this._fileName=e.getFileName(t),s=decodeURIComponent(this._fileName),a?(this._fileSize=t.size,c=t.type?'('+t.type+")<\/span>":"",o.innerHTML=''+s+"<\/span> "+c+' - '+e.sizeToString(t.size)+"<\/span> ",this._fileType=t.type):(o.innerHTML=''+s+"<\/span>",this._fileType=e.getFileType(t)),u.appendChild(o),u.appendChild(h),$common.setText(f,Sys.Extended.UI.Resources.AjaxFileUpload_Remove),$addHandlers(f,{click:Function.createDelegate(this,function(){n(l)})}),Sys.Browser.agent==Sys.Browser.InternetExplorer&&Sys.Browser.version<=8?(r.appendChild(f),r.appendChild(u)):(r.appendChild(u),r.appendChild(f)),this._fileInfoContainer=u,this._deleteButton=f,this._fileStatusText=h,r},setStatus:function(n,t){$common.setText(this._fileStatusText," ("+t+")");this._fileInfoContainer.setAttribute("class",n+"State")},disabled:function(n){this._deleteButton.disabled=n?"disabled":""},hide:function(){this._deleteButton.style.visibility="hidden"},destroy:function(){$common.removeElement(this._inputElementValue);$common.removeElement(this._deleteButton);$common.removeElement(this._ui)},get_inputElementValue:function(){return this._inputElementValue},appendNodeTo:function(n){n.appendChild(this._ui)},removeNodeFrom:function(n){n.removeChild(this._ui)}};Sys.Extended.UI.AjaxFileUpload.Processor=function(n,t){var r=new Sys.Extended.UI.AjaxFileUpload.Utils,i=new XMLHttpRequest;this._iframe=null;this._iframeName=n.get_id()+"_uploadIframe";this._form=null;this.initialize=function(){this.attachEvents();this.createIFrame();this.createForm()};this.attachEvents=function(){this.onFileSelected$delegate=Function.createDelegate(this,this.onFileSelectedHandler);this.attachFileInputEvents(t.inputFile,!0);var r=this;i.onreadystatechange=function(){if(i.readyState==4&&i.status==200){var t=i.responseText;t&&(t=parseFloat(t).toFixed(2),n.setPercent(t));t<100&&setTimeout(function(){r.pollingServerProgress(!0)},500)}}};this.attachFileInputEvents=function(n,t){t?$addHandlers(n,{change:this.onFileSelected$delegate}):$common.removeHandlers(n,{change:this.onFileSelected$delegate})};this.onFileSelectedHandler=function(){var i={id:r.generateGuid(),value:t.inputFile,type:r.getFileType(t.inputFile.value)};if(!n.fileTypeIsValid(i.type)){n.confirmFileIsInvalid(i);return}if(n.fileSizeExceeded(i.value.size)){n.confirmFileIsTooLarge(i);return}n.addFileToQueue(i);this.createInputFileElement()};this.createInputFileElement=function(){var i=t.inputFile,f,u;i.style.zIndex=-999;$common.setLocation(i,{x:-99999,y:-99999});this.attachFileInputEvents(i,!1);f=n.get_id()+"_file_"+r.generateGuid();u=$common.createElementFromTemplate({nodeName:"input",properties:{id:f,name:"act-file-data",type:"file",style:{zIndex:0,cursor:"pointer",position:"absolute"}}},i.parentNode);$common.setElementOpacity(u,0);this.attachFileInputEvents(u,!0);t.inputFile=u};this.startUpload=function(){var t=this._form,i=n.getNextFile(),r;if(!i){n._currentFileId=null;this.setThrobber(!1);n.done();return}for(n.setAsUploading(i),r=i.get_inputElementValue(),n._currentFileId=i._id,this.setThrobber(!0);t.firstChild;)t.removeChild(t.firstChild);r.name="act-file-data";t.appendChild(r);t.setAttribute("action",n._uploadUrl+"?contextKey="+n.get_contextKey()+"&controlID="+n.get_id()+"&fileId="+n._currentFileId+"&fileName="+i._fileName+"&usePoll="+(n.get_serverPollingSupport()?"true":"false"));t.submit()};this.cancelUpload=function(){var t=new XMLHttpRequest,r=this;i&&i.abort();t.open("POST","?contextKey="+n.get_contextKey()+"&controlID="+n.get_id()+"&cancel=1&guid="+n._currentFileId+r.getQueryString(),!0);t.onreadystatechange=function(){if(r.setThrobber(!1),t.readyState==4)if(t.status==200)n.cancelUpload();else{r.raiseUploadError(t);throw"Failed to cancel upload.";}};t.send(null)};this.getQueryString=function(){return"&"+window.location.search.replace("?","")};this.createIFrame=function(){var t=this._iframeName,n=document.createElement("IFRAME");n.width="0";n.height="0";n.style.display="none";n.src="about:blank";n.id=t;n.name=t;n.security="restricted";document.body.appendChild(n);n.contentWindow.name=t;$addHandlers(n,{load:Function.createDelegate(this,this.onIFrameLoadedHandler)});this._iframe=n};this.onIFrameLoadedHandler=function(t){if(n._currentFileId)try{var i=this._iframe,r=null;if(i.contentDocument?r=i.contentDocument:i.contentWindow?r=i.contentWindow.document:i.document&&(r=i.document),r==null)throw"Document not initialized";n.doneAndUploadNextFile(n.getCurrentFileItem())}catch(t){if(!n._canceled||!(t.message&&(t.message.indexOf("Access is denied")>-1||t.message.indexOf("Permission denied")>-1))){this.raiseUploadError(t);throw t;}}};this.setThrobber=function(i){if(n.get_serverPollingSupport()){n.setPercent(0);$common.setVisible(t.progressBar,i?!0:!1);$common.setVisible(t.progressBarContainer,i?!0:!1);this.pollingServerProgress(i);return}n.get_throbber()!=null&&(n.get_throbber().style.display=i?"":"none")};this.pollingServerProgress=function(t){t&&n._currentFileId&&(i.open("GET","?contextKey="+n.get_contextKey()+"&controlID="+n.get_id()+"&poll=1&guid="+n._currentFileId,!0),i.send(null))};this.createForm=function(){var t,i="___postForm"+n.get_id();try{t=document.createElement('