Browse Source

Fix block d&d with `dragContent`

pull/758/head
Artur Arseniev 8 years ago
parent
commit
593247c8bd
  1. 12
      src/block_manager/view/BlockView.js
  2. 7
      src/utils/Droppable.js

12
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', '');
},
/**

7
src/utils/Droppable.js

@ -82,8 +82,11 @@ export default class Droppable {
},
document: canvas.getFrameEl().contentDocument
});
const content = this.getContentByData(dt).content || '<br>';
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') || '<br>';
this.sorter.setDropContent(content);
this.sorter.startSort(this.el);
em.trigger('canvas:dragenter', dt, content);
}

Loading…
Cancel
Save