From 3534b5836ebb85f6751af5d9e3e62bb3b6145aed Mon Sep 17 00:00:00 2001 From: llj Date: Fri, 25 Nov 2016 16:59:21 +0800 Subject: [PATCH] [fileupload] fix for Firefox 50 --- seahub/templates/view_shared_upload_link.html | 29 +++++++++++-------- static/scripts/app/views/dir.js | 9 +++--- static/scripts/app/views/fileupload.js | 15 ++++++---- 3 files changed, 31 insertions(+), 22 deletions(-) diff --git a/seahub/templates/view_shared_upload_link.html b/seahub/templates/view_shared_upload_link.html index 18ad6391ba..6c00730fad 100644 --- a/seahub/templates/view_shared_upload_link.html +++ b/seahub/templates/view_shared_upload_link.html @@ -124,11 +124,16 @@ form.fileupload({ data.files.shift(); return; } - if (file.webkitRelativePath) { // for 'upload folder' - file.relative_path = file.webkitRelativePath; - } - if (file.relativePath) { // for 'folder drag & drop' - file.relative_path = file.relativePath + file.name; + + // set 'file.relative_path' when upload a folder + if (data.fileInput) { // clicking + if (file.webkitRelativePath) { + file.relative_path = file.webkitRelativePath; + } + } else { // drag & drop + if (file.relativePath) { + file.relative_path = file.relativePath + file.name; + } } }) .bind('fileuploadsubmit', function(e, data) { @@ -221,13 +226,13 @@ form.fileupload({ {% if enable_upload_folder %} if ('webkitdirectory' in $('input[type="file"]', $('#add-file'))[0]) { $('#add-folder').show(); - $('#add-file, #add-folder').click(function() { - form.fileupload( - 'option', - 'fileInput', - $('input[type="file"]', $(this)) - ); - }); + form.fileupload( + 'option', { + fileInput: $('input[type="file"]', $('#add-file, #add-folder')), + // set 'replaceFileInput: false' for Firefox(v50) + replaceFileInput: navigator.userAgent.indexOf('Firefox') == -1 ? true : false + } + ); } {% endif %} diff --git a/static/scripts/app/views/dir.js b/static/scripts/app/views/dir.js index 9e7cd858bc..ee502d046b 100644 --- a/static/scripts/app/views/dir.js +++ b/static/scripts/app/views/dir.js @@ -216,16 +216,17 @@ define([ if (app.pageOptions.enable_upload_folder) { if ('webkitdirectory' in $('#basic-upload-input')[0]) { - // if enable_upload_folder and is chrome this.$("#basic-upload").remove(); this.$("#advanced-upload").show(); this.upload_dropdown = new DropdownView({ el: this.$("#advanced-upload") }); $popup.fileupload( - 'option', - 'fileInput', - this.$('#advanced-upload input[type="file"]')); + 'option', { + fileInput: this.$('#advanced-upload input[type="file"]'), + // set 'replaceFileInput: false' for Firefox(v50) + replaceFileInput: navigator.userAgent.indexOf('Firefox') == -1 ? true : false + }); } else { this.$("#advanced-upload").remove(); $popup.fileupload( diff --git a/static/scripts/app/views/fileupload.js b/static/scripts/app/views/fileupload.js index ec1d737c5d..aca29ebcc1 100644 --- a/static/scripts/app/views/fileupload.js +++ b/static/scripts/app/views/fileupload.js @@ -108,13 +108,16 @@ define([ data.files.shift(); return; } - if (file.webkitRelativePath) { - file.relative_path = file.webkitRelativePath; - } - // add folder by drag & drop - if (file.relativePath) { - file.relative_path = file.relativePath + file.name; + // set 'file.relative_path' when upload a folder + if (data.fileInput) { // clicking + if (file.webkitRelativePath) { + file.relative_path = file.webkitRelativePath; + } + } else { // drag & drop + if (file.relativePath) { + file.relative_path = file.relativePath + file.name; + } } }) .bind('fileuploadstart', function() {