diff --git a/src/block_manager/view/BlockView.js b/src/block_manager/view/BlockView.js index 7cb134dd4..9a2da769e 100644 --- a/src/block_manager/view/BlockView.js +++ b/src/block_manager/view/BlockView.js @@ -6,6 +6,7 @@ module.exports = Backbone.View.extend({ events: { mousedown: 'startDrag', dragstart: 'handleDragStart', + drag: 'handleDrag', dragend: 'handleDragEnd' }, @@ -34,7 +35,8 @@ module.exports = Backbone.View.extend({ }, handleDragStart(ev) { - const content = this.model.get('content'); + const { em, model } = this; + const content = model.get('content'); const isObj = isObject(content); const type = isObj ? 'text/json' : 'text'; const data = isObj ? JSON.stringify(content) : content; @@ -43,7 +45,12 @@ module.exports = Backbone.View.extend({ // but will use dragContent as I need it for the Sorter context // IE11 supports only 'text' data type ev.dataTransfer.setData('text', data); - this.em.set('dragContent', content); + em.set('dragContent', content); + em.trigger('block:drag:start', model, ev); + }, + + handleDrag(ev) { + this.em.trigger('block:drag', this.model, ev); }, handleDragEnd() { @@ -72,6 +79,8 @@ module.exports = Backbone.View.extend({ dragResult: null, dragContent: null }); + + em.trigger('block:drag:stop', result, model); }, /** diff --git a/src/editor/index.js b/src/editor/index.js index c1f94a21f..6e31238cb 100644 --- a/src/editor/index.js +++ b/src/editor/index.js @@ -22,8 +22,9 @@ * ## Blocks * * `block:add` - New block added * * `block:remove` - Block removed - * * `block:drag:start` - Started dragging new block, Event object is passed as an argument - * * `block:drag:stop` - Block dropped inside canvas, the new model is passed as an argument to the callback + * * `block:drag:start` - Started dragging block, model of the block is passed as an argument + * * `block:drag` - Dragging block, the block's model and the drag event are passed as arguments + * * `block:drag:stop` - Dragging of the block is stopped. As agruments for the callback you get, the dropped component model (if dropped successfully) and the model of the block * ## Assets * * `asset:add` - New asset added * * `asset:remove` - Asset removed