Browse Source

Stop using `dragContent`

pull/758/head
Artur Arseniev 9 years ago
parent
commit
5569b64c53
  1. 12
      src/block_manager/view/BlockView.js
  2. 10
      src/utils/Droppable.js

12
src/block_manager/view/BlockView.js

@ -1,3 +1,4 @@
import { isObject } from 'underscore';
import { on, off, hasDnd } from 'utils/mixins';
module.exports = Backbone.View.extend({
@ -32,11 +33,12 @@ module.exports = Backbone.View.extend({
handleDragStart(ev) {
const content = this.model.get('content');
// Firefox requires setData
ev.dataTransfer.setData('text', null);
// Can't put the content in dataTransfer as it will not be available
// on `dragenter` event for security reason
this.config.em.set('dragContent', content);
const isObj = isObject(content);
const type = isObj ? 'text/json' : 'text';
const data = isObj ? JSON.stringify(content) : content;
console.log('handleDragStart', data);
// Note: data are not available on dragenter for security reason
ev.dataTransfer.setData(type, data);
},
/**

10
src/utils/Droppable.js

@ -36,7 +36,7 @@ export default class Droppable {
// force out like in BlockView
const sorter = this.sorter;
cancel && (sorter.moved = 0);
em.set('dragContent', '');
//em.set('dragContent', '');
sorter.endMove();
em.trigger('canvas:dragend', ev);
}
@ -109,7 +109,6 @@ export default class Droppable {
const em = this.em;
const types = dataTransfer.types;
const files = dataTransfer.files;
const dragContent = em.get('dragContent'); // Used by blocks
let content = dataTransfer.getData('text');
if (files.length) {
@ -136,13 +135,14 @@ export default class Droppable {
attributes: { href: content },
content: content
};
} else if (dragContent) {
content = dragContent;
} else if (types.indexOf('text/json') >= 0) {
const json = dataTransfer.getData('text/json');
json && (content = JSON.parse(json));
} else {
content = content && `<div>${content}</div>`;
}
const result = { content, dragContent };
const result = { content };
em.trigger('canvas:dragdata', dataTransfer, result);
return result;

Loading…
Cancel
Save