[FIX] web_editor: drop an image in the editable area

Issue: can't drop a image if the editor is not focused or if the editor is
empty
This commit is contained in:
Gorash
2019-05-06 10:29:23 +00:00
parent b2df3c7f30
commit eaeff40236
2 changed files with 21 additions and 1 deletions
@@ -19,6 +19,7 @@ var DropzonePlugin = Plugins.dropzone.extend({
attachDragAndDropEvent: function () {
this._super.apply(this, arguments);
this.$dropzone.off('drop');
this.$dropzone.on('dragenter', this._onDragenter.bind(this));
this.$dropzone.on('drop', this._onDrop.bind(this));
},
@@ -71,7 +72,7 @@ var DropzonePlugin = Plugins.dropzone.extend({
if (range.so >= dom.nodeLength(range.sc)) {
$(range.sc).append(spinner);
} else {
$(range.sc).before(range.sc.childNodes[range.so]);
$(range.sc.childNodes[range.so]).before(spinner);
}
} else {
range.sc.splitText(range.so);
@@ -155,6 +156,21 @@ var DropzonePlugin = Plugins.dropzone.extend({
},
});
},
/**
* @private
* @param {JQueryEvent} e
*/
_onDragenter: function (e) {
var range = this.context.invoke('editor.createRange');
if (!this.editable.contains(range.sc)) {
var node = this.editable;
if (node && node.firstChild) {
node = node.firstChild;
}
range = this.context.invoke('editor.setRange', node, 0, node, 0);
range.select();
}
},
/**
* @private
* @param {JQueryEvent} e
@@ -162,6 +178,8 @@ var DropzonePlugin = Plugins.dropzone.extend({
_onDrop: function (e) {
e.preventDefault();
this.$editor.removeClass('dragover');
if (this.options.disableDragAndDrop) {
return;
}
@@ -43,6 +43,8 @@ var MediaPlugin = AbstractPlugin.extend({
'dblclick .note-editable': '_onDblclick',
},
mousePosition: {},
//--------------------------------------------------------------------------
// Public
//--------------------------------------------------------------------------