From 0638619f81fa10e2efb1b362ad408e7e3ef4640b Mon Sep 17 00:00:00 2001 From: Hank Grabowski Date: Sun, 7 Oct 2018 20:10:52 -0400 Subject: [PATCH 1/2] 7878 directly pasting images into edit box and broader drag and drop areas --- .../app/views/publisher/uploader_view.js | 2 +- .../javascripts/app/views/publisher_view.js | 1 + .../helpers/post_photo_uploader.es6 | 19 ++++++++++++++++++- app/assets/javascripts/jasmine-load-all.js | 2 +- app/assets/javascripts/main.js | 2 +- app/assets/javascripts/mobile/mobile.js | 2 +- .../mobile/mobile_file_uploader.js | 3 ++- 7 files changed, 25 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/app/views/publisher/uploader_view.js b/app/assets/javascripts/app/views/publisher/uploader_view.js index 538946fbcb0..824d9219cce 100644 --- a/app/assets/javascripts/app/views/publisher/uploader_view.js +++ b/app/assets/javascripts/app/views/publisher/uploader_view.js @@ -10,7 +10,7 @@ app.views.PublisherUploader = Backbone.View.extend({ this.publisher.photozoneEl.on("click", ".x", _.bind(this._removePhoto, this)); // Initialize the PostPhotoUploader and subscribe its events - this.uploader = new Diaspora.PostPhotoUploader(this.el); + this.uploader = new Diaspora.PostPhotoUploader(this.el, opts.dropZoneElementIds); this.uploader.onUploadStarted = _.bind(this.uploadStartedHandler, this); this.uploader.onProgress = _.bind(this.progressHandler, this); this.uploader.onUploadCompleted = _.bind(this.uploadCompleteHandler, this); diff --git a/app/assets/javascripts/app/views/publisher_view.js b/app/assets/javascripts/app/views/publisher_view.js index 2549692ab2f..ce5501ce2ca 100644 --- a/app/assets/javascripts/app/views/publisher_view.js +++ b/app/assets/javascripts/app/views/publisher_view.js @@ -113,6 +113,7 @@ app.views.Publisher = Backbone.View.extend({ this.viewUploader = new app.views.PublisherUploader({ el: this.$("#file-upload"), + dropZoneElementIds: ["publisher-textarea-wrapper"], publisher: this }); this.viewUploader.on("change", this.checkSubmitAvailability, this); diff --git a/app/assets/javascripts/helpers/post_photo_uploader.es6 b/app/assets/javascripts/helpers/post_photo_uploader.es6 index 581a41f31ac..ba94ec5ed6b 100644 --- a/app/assets/javascripts/helpers/post_photo_uploader.es6 +++ b/app/assets/javascripts/helpers/post_photo_uploader.es6 @@ -5,8 +5,9 @@ Diaspora.PostPhotoUploader = class { * Initializes a new instance of PostPhotoUploader * This class handles uploading photos and provides client side scaling */ - constructor(el, aspectIds) { + constructor(el, dropZoneElementIds, aspectIds) { this.element = el; + this.dropZoneElementIds = dropZoneElementIds; this.sizeLimit = 4194304; this.aspectIds = aspectIds; @@ -53,6 +54,10 @@ Diaspora.PostPhotoUploader = class { /* eslint-enable camelcase */ } }, + paste: { + targetElement: document.getElementById("status_message_text"), + promptForName: true + }, validation: { acceptFiles: "image/png, image/jpeg, image/gif", allowedExtensions: ["jpg", "jpeg", "png", "gif"], @@ -72,6 +77,18 @@ Diaspora.PostPhotoUploader = class { onError: (id, name, errorReason) => this.showMessage("error", errorReason) } }); + + if (this.dropZoneElementIds instanceof Array) { + var dropZoneElements = this.dropZoneElementIds.map(id => document.getElementById(id)).filter(el => el); + if (dropZoneElements.length > 0) { + this.dragAndDropModule = new qq.DragAndDrop({ + dropZoneElements: dropZoneElements, + callbacks: { + processingDroppedFilesComplete: (files) => this.fineUploader.addFiles(files) + } + }); + } + } } /** diff --git a/app/assets/javascripts/jasmine-load-all.js b/app/assets/javascripts/jasmine-load-all.js index fe771027cb4..3cf73aa3bf2 100644 --- a/app/assets/javascripts/jasmine-load-all.js +++ b/app/assets/javascripts/jasmine-load-all.js @@ -1,7 +1,7 @@ //= require jquery3 //= require handlebars.runtime //= require main -//= require fine-uploader/fine-uploader.core +//= require fine-uploader/fine-uploader //= require mobile/mobile //= require jquery.autoSuggest.custom //= require contact-list diff --git a/app/assets/javascripts/main.js b/app/assets/javascripts/main.js index 76d020cd7c8..c0a2a66ebea 100644 --- a/app/assets/javascripts/main.js +++ b/app/assets/javascripts/main.js @@ -16,7 +16,7 @@ //= require jquery-ui/sortable //= require keycodes //= require jquery.autoSuggest.custom -//= require fine-uploader/fine-uploader.core +//= require fine-uploader/fine-uploader //= require handlebars.runtime //= require_tree ../templates //= require posix-bracket-expressions diff --git a/app/assets/javascripts/mobile/mobile.js b/app/assets/javascripts/mobile/mobile.js index 3d12c4281ca..a3bd568ec75 100644 --- a/app/assets/javascripts/mobile/mobile.js +++ b/app/assets/javascripts/mobile/mobile.js @@ -10,7 +10,7 @@ //= require autosize //= require keycodes //= require jquery.autoSuggest.custom -//= require fine-uploader/fine-uploader.core +//= require fine-uploader/fine-uploader //= require jquery.timeago //= require underscore //= require bootstrap diff --git a/app/assets/javascripts/mobile/mobile_file_uploader.js b/app/assets/javascripts/mobile/mobile_file_uploader.js index af8c20732a9..fb6198e48a9 100644 --- a/app/assets/javascripts/mobile/mobile_file_uploader.js +++ b/app/assets/javascripts/mobile/mobile_file_uploader.js @@ -6,7 +6,8 @@ function createUploader(){ var fileInfo = $("#fileInfo-publisher"); // Initialize the PostPhotoUploader and subscribe its events - this.uploader = new Diaspora.PostPhotoUploader(document.getElementById("file-upload-publisher"), aspectIds); + this.uploader = new Diaspora.PostPhotoUploader(document.getElementById("file-upload-publisher"), + ["publisher-textarea-wrapper", "status_message_text", "file-upload-publisher"]); this.uploader.onUploadStarted = _.bind(uploadStartedHandler, this); this.uploader.onProgress = _.bind(progressHandler, this); From 6c3269c6d5a6da0eda1c36787edad2f20e1e73c5 Mon Sep 17 00:00:00 2001 From: Thorsten Claus Date: Wed, 14 Apr 2021 08:27:06 +0200 Subject: [PATCH 2/2] Expand publisher on drag&drop --- app/assets/javascripts/app/views/publisher_view.js | 1 + 1 file changed, 1 insertion(+) diff --git a/app/assets/javascripts/app/views/publisher_view.js b/app/assets/javascripts/app/views/publisher_view.js index ce5501ce2ca..741ea271e42 100644 --- a/app/assets/javascripts/app/views/publisher_view.js +++ b/app/assets/javascripts/app/views/publisher_view.js @@ -447,6 +447,7 @@ app.views.Publisher = Backbone.View.extend({ checkSubmitAvailability: function() { if (this._submittable()) { + this.open(); this.setButtonsEnabled(true); } else { this.setButtonsEnabled(false);