Last active
August 29, 2015 13:55
-
-
Save JanSuchanek/8710857 to your computer and use it in GitHub Desktop.
Revisions
-
JanSuchanek revised this gist
Jan 30, 2014 . 1 changed file with 5 additions and 8 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -26,19 +26,16 @@ $.nette.ext('fileUpload', { }, { onChangeFiles: function(event){ that.formFiles = this; }, onUploadSubmit: function(event){ event.stopPropagation(); event.preventDefault(); that.uploadForm = this; that.getProgress().show().addClass("progress-striped").addClass("active"); that.getBar().addClass("bar-success"); if(event.currentTarget.length > 0){ var formData = new FormData(this); @@ -47,11 +44,11 @@ $.nette.ext('fileUpload', { $.nette.ajax({ url: this.action, type: 'POST', data: formData, dataType: 'json', cache: false, processData: false, contentType: false, }); } } -
JanSuchanek revised this gist
Jan 30, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -14,7 +14,7 @@ $.nette.ext('fileUpload', { xhr.upload.onload = function(){ that.setPercent(100); }; return xhr; }, success: function(payload){ setTimeout(function(){ -
JanSuchanek revised this gist
Jan 30, 2014 . 1 changed file with 0 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -16,9 +16,6 @@ $.nette.ext('fileUpload', { }; return xhr; }, success: function(payload){ setTimeout(function(){ that.getProgress().hide(); -
JanSuchanek created this gist
Jan 30, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,76 @@ $.nette.ext('fileUpload', { init: function(rh){ that = this; $("form.fileUpload input[type=file]").on("change", this.onChangeFiles); $("form.fileUpload").on("submit", this.onUploadSubmit); }, before: function(jqXHR, settings){ var xhr = $.ajaxSettings.xhr(); xhr.upload.onprogress = function(e){ if(e.lengthComputable){ that.setPercent(Math.round(e.loaded/e.total*100)); } }; xhr.upload.onload = function(){ that.setPercent(100); }; return xhr; }, start: function(jqXHR, settings){ return false; }, success: function(payload){ setTimeout(function(){ that.getProgress().hide(); that.selector("input[type=file]").val(''); that.setPercent(0); }, 2000); } }, { onChangeFiles: function(event){ that.formFiles = this; console.info(this.files.length) }, onUploadSubmit: function(event){ event.stopPropagation(); event.preventDefault(); that.uploadForm = this; that.getProgress().show().addClass("progress-striped").addClass("active"); that.getBar().addClass("bar-success"); console.info(this.files); if(event.currentTarget.length > 0){ var formData = new FormData(this); if(formData){ $.nette.ajax({ url: this.action, type: 'POST', data: formData, dataType: 'json', cache: false, processData: false, // Don't process the files contentType: false, // Set content type to false as jQuery will tell the server its a query string request }); } } }, selector: function(s){ return $(that.uploadForm).find(s) }, getProgress: function(){ return that.selector('.progress'); }, getBar: function(){ return that.selector('.progress .progress-bar'); }, setPercent: function(p){ that.getBar().attr("aria-valuenow",p).width(p+'%').html(p+'% Complete'); }, formFiles: null, uploadform: null });