diff --git a/src/block_manager/view/BlockView.js b/src/block_manager/view/BlockView.js index 41510b404..bbcbcab26 100644 --- a/src/block_manager/view/BlockView.js +++ b/src/block_manager/view/BlockView.js @@ -4,7 +4,8 @@ import { on, off, hasDnd } from 'utils/mixins'; module.exports = Backbone.View.extend({ events: { mousedown: 'startDrag', - dragstart: 'handleDragStart' + dragstart: 'handleDragStart', + dragend: 'handleDragEnd' }, initialize(o, config = {}) { @@ -36,8 +37,15 @@ module.exports = Backbone.View.extend({ const isObj = isObject(content); const type = isObj ? 'text/json' : 'text'; const data = isObj ? JSON.stringify(content) : content; - // Note: data are not available on dragenter for security reason + + // Note: data are not available on dragenter for security reason, + // but will use dragContent as I need it for the Sorter context ev.dataTransfer.setData(type, data); + this.em.set('dragContent', content); + }, + + handleDragEnd() { + this.em.set('dragContent', ''); }, /** diff --git a/src/utils/Droppable.js b/src/utils/Droppable.js index ddc2922a0..c533963bc 100644 --- a/src/utils/Droppable.js +++ b/src/utils/Droppable.js @@ -82,8 +82,11 @@ export default class Droppable { }, document: canvas.getFrameEl().contentDocument }); - const content = this.getContentByData(dt).content || '
'; - this.sorter.setDropContent(content); // should not be empty + // For security reason I can't read the drag data on dragenter, but + // as I need it for the Sorter context I will use `dragContent` or just + // any not empty element + const content = em.get('dragContent') || '
'; + this.sorter.setDropContent(content); this.sorter.startSort(this.el); em.trigger('canvas:dragenter', dt, content); }