From 5569b64c5389bd2272591a1be6fbf73adbb18f3b Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Sat, 13 Jan 2018 01:43:02 +0100 Subject: [PATCH] Stop using `dragContent` --- src/block_manager/view/BlockView.js | 12 +++++++----- src/utils/Droppable.js | 10 +++++----- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/block_manager/view/BlockView.js b/src/block_manager/view/BlockView.js index 99fd15bb4..bae9e572a 100644 --- a/src/block_manager/view/BlockView.js +++ b/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); }, /** diff --git a/src/utils/Droppable.js b/src/utils/Droppable.js index 3276a87b0..5edf4d607 100644 --- a/src/utils/Droppable.js +++ b/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 && `
${content}
`; } - const result = { content, dragContent }; + const result = { content }; em.trigger('canvas:dragdata', dataTransfer, result); return result;