From ca71722c1eaa5c2aa4597bef38ca812c15294359 Mon Sep 17 00:00:00 2001 From: shpuld Date: Tue, 21 Feb 2017 15:13:19 +0200 Subject: Files dropped into post_status_form text box get sent to media_upload for attachment upload, media_upload reorganized a bit to allow reuse of existing code. --- src/components/media_upload/media_upload.js | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'src/components/media_upload/media_upload.js') diff --git a/src/components/media_upload/media_upload.js b/src/components/media_upload/media_upload.js index 3f2e3964..3f6fec5b 100644 --- a/src/components/media_upload/media_upload.js +++ b/src/components/media_upload/media_upload.js @@ -3,12 +3,22 @@ import statusPosterService from '../../services/status_poster/status_poster.serv const mediaUpload = { mounted () { - const store = this.$store const input = this.$el.querySelector('input') - const self = this input.addEventListener('change', ({target}) => { const file = target.files[0] + this.uploadFile(file) + }) + }, + data () { + return { + uploading: false + } + }, + methods: { + uploadFile(file) { + const self = this + const store = this.$store const formData = new FormData() formData.append('media', file) @@ -23,11 +33,15 @@ const mediaUpload = { self.$emit('upload-failed') self.uploading = false }) - }) + } }, - data () { - return { - uploading: false + props: [ + 'dropFiles' + ], + watch: { + 'dropFiles': function (fileInfos) { + if (!this.uploading) + this.uploadFile(fileInfos[0]) } } } -- cgit v1.2.3-70-g09d2 From 892b826df59203a920bfebbd2ac37ef62dcf411b Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Tue, 21 Feb 2017 21:48:48 +0100 Subject: Small style adjustment, add meta-enter posting. --- src/components/media_upload/media_upload.js | 5 +++-- src/components/post_status_form/post_status_form.js | 2 +- src/components/post_status_form/post_status_form.vue | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) (limited to 'src/components/media_upload/media_upload.js') diff --git a/src/components/media_upload/media_upload.js b/src/components/media_upload/media_upload.js index 3f6fec5b..746970aa 100644 --- a/src/components/media_upload/media_upload.js +++ b/src/components/media_upload/media_upload.js @@ -16,7 +16,7 @@ const mediaUpload = { } }, methods: { - uploadFile(file) { + uploadFile (file) { const self = this const store = this.$store const formData = new FormData() @@ -40,8 +40,9 @@ const mediaUpload = { ], watch: { 'dropFiles': function (fileInfos) { - if (!this.uploading) + if (!this.uploading) { this.uploadFile(fileInfos[0]) + } } } } diff --git a/src/components/post_status_form/post_status_form.js b/src/components/post_status_form/post_status_form.js index e798b196..d55525bb 100644 --- a/src/components/post_status_form/post_status_form.js +++ b/src/components/post_status_form/post_status_form.js @@ -144,7 +144,7 @@ const PostStatusForm = { return fileTypeService.fileType(fileInfo.mimetype) }, fileDrop (e) { - if(e.dataTransfer.files.length > 0) { + if (e.dataTransfer.files.length > 0) { e.preventDefault() // allow dropping text like before this.dropFiles = e.dataTransfer.files } diff --git a/src/components/post_status_form/post_status_form.vue b/src/components/post_status_form/post_status_form.vue index d9138109..eceef4a2 100644 --- a/src/components/post_status_form/post_status_form.vue +++ b/src/components/post_status_form/post_status_form.vue @@ -2,7 +2,7 @@
- +
-- cgit v1.2.3-70-g09d2 From 6c385ae80aaf763db7f973b5dc1e3bd21367a2a7 Mon Sep 17 00:00:00 2001 From: shpuld Date: Wed, 22 Feb 2017 14:53:05 +0200 Subject: Make drag&drop work on more browsers/platforms, make the Upload button accept drops as well. --- src/components/media_upload/media_upload.js | 14 ++++++++++++++ src/components/media_upload/media_upload.vue | 2 +- src/components/post_status_form/post_status_form.js | 3 +++ src/components/post_status_form/post_status_form.vue | 2 +- 4 files changed, 19 insertions(+), 2 deletions(-) (limited to 'src/components/media_upload/media_upload.js') diff --git a/src/components/media_upload/media_upload.js b/src/components/media_upload/media_upload.js index 3f6fec5b..2f312ec9 100644 --- a/src/components/media_upload/media_upload.js +++ b/src/components/media_upload/media_upload.js @@ -33,6 +33,20 @@ const mediaUpload = { self.$emit('upload-failed') self.uploading = false }) + }, + fileDrop (e) { + if(e.dataTransfer.files.length > 0) { + e.preventDefault() // allow dropping text like before + this.uploadFile(e.dataTransfer.files[0]) + } + }, + fileDrag (e) { + let types = e.dataTransfer.types + if(types.contains('Files')) { + e.dataTransfer.dropEffect = 'copy' + } else { + e.dataTransfer.dropEffect = 'none' + } } }, props: [ diff --git a/src/components/media_upload/media_upload.vue b/src/components/media_upload/media_upload.vue index 3302db37..b839067b 100644 --- a/src/components/media_upload/media_upload.vue +++ b/src/components/media_upload/media_upload.vue @@ -1,5 +1,5 @@