Upload files on drag-and-drop.

Fixes #1188.
This commit is contained in:
Emmanuel Gil Peyrot 2018-11-02 04:43:43 +01:00 committed by JC Brand
parent 37bd332897
commit 0d4603d80d
2 changed files with 33 additions and 2 deletions

17
dist/converse.js vendored
View File

@ -59022,7 +59022,9 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_5__["default"].plugins
'click .toggle-smiley': 'toggleEmojiMenu', 'click .toggle-smiley': 'toggleEmojiMenu',
'click .upload-file': 'toggleFileUpload', 'click .upload-file': 'toggleFileUpload',
'input .chat-textarea': 'inputChanged', 'input .chat-textarea': 'inputChanged',
'keydown .chat-textarea': 'keyPressed' 'keydown .chat-textarea': 'keyPressed',
'dragover .chat-textarea': 'onDragOver',
'drop .chat-textarea': 'onDrop'
}, },
initialize() { initialize() {
@ -59128,6 +59130,19 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_5__["default"].plugins
this.model.sendFiles(evt.target.files); this.model.sendFiles(evt.target.files);
}, },
onDragOver(evt) {
evt.preventDefault();
},
onDrop(evt) {
/* There are no files to be dropped, this isnt a file transfer
* operation.
*/
if (evt.dataTransfer.files.length == 0) return;
evt.preventDefault();
this.model.sendFiles(evt.dataTransfer.files);
},
async addFileUploadButton(options) { async addFileUploadButton(options) {
const result = await _converse.api.disco.supports(Strophe.NS.HTTPUPLOAD, _converse.domain); const result = await _converse.api.disco.supports(Strophe.NS.HTTPUPLOAD, _converse.domain);

View File

@ -296,7 +296,9 @@ converse.plugins.add('converse-chatview', {
'click .toggle-smiley': 'toggleEmojiMenu', 'click .toggle-smiley': 'toggleEmojiMenu',
'click .upload-file': 'toggleFileUpload', 'click .upload-file': 'toggleFileUpload',
'input .chat-textarea': 'inputChanged', 'input .chat-textarea': 'inputChanged',
'keydown .chat-textarea': 'keyPressed' 'keydown .chat-textarea': 'keyPressed',
'dragover .chat-textarea': 'onDragOver',
'drop .chat-textarea': 'onDrop',
}, },
initialize () { initialize () {
@ -398,6 +400,20 @@ converse.plugins.add('converse-chatview', {
this.model.sendFiles(evt.target.files); this.model.sendFiles(evt.target.files);
}, },
onDragOver (evt) {
evt.preventDefault();
},
onDrop (evt) {
/* There are no files to be dropped, this isnt a file transfer
* operation.
*/
if (evt.dataTransfer.files.length == 0)
return;
evt.preventDefault();
this.model.sendFiles(evt.dataTransfer.files);
},
async addFileUploadButton (options) { async addFileUploadButton (options) {
const result = await _converse.api.disco.supports(Strophe.NS.HTTPUPLOAD, _converse.domain); const result = await _converse.api.disco.supports(Strophe.NS.HTTPUPLOAD, _converse.domain);
if (result.length) { if (result.length) {