From d27819c3eb405e7b6d4ec1db3f68449b27fddeb8 Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Thu, 22 Mar 2018 00:43:11 +0100 Subject: [PATCH] Fix some issues in IE11 #768 --- src/block_manager/view/BlockView.js | 3 ++- src/canvas/view/CanvasView.js | 8 +++++++- src/rich_text_editor/model/RichTextEditor.js | 2 +- src/utils/Droppable.js | 8 ++++---- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/block_manager/view/BlockView.js b/src/block_manager/view/BlockView.js index 9ad8fcb45..79eff5512 100644 --- a/src/block_manager/view/BlockView.js +++ b/src/block_manager/view/BlockView.js @@ -40,7 +40,8 @@ module.exports = Backbone.View.extend({ // 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); + // IE11 supports only 'text' data type + ev.dataTransfer.setData('text', data); this.em.set('dragContent', content); }, diff --git a/src/canvas/view/CanvasView.js b/src/canvas/view/CanvasView.js index 86ebd7845..0aedb93ac 100644 --- a/src/canvas/view/CanvasView.js +++ b/src/canvas/view/CanvasView.js @@ -208,7 +208,13 @@ module.exports = Backbone.View.extend({ // property keymaster (and many others) still use it... using `defineProperty` // hack seems the only way const createCustomEvent = (e, cls) => { - var oEvent = new window[cls](e.type, e); + let oEvent; + try { + oEvent = new window[cls](e.type, e); + } catch (e) { + oEvent = document.createEvent(cls); + oEvent.initEvent(e.type, true, true); + } oEvent.keyCodeVal = e.keyCode; ['keyCode', 'which'].forEach(prop => { Object.defineProperty(oEvent, prop, { diff --git a/src/rich_text_editor/model/RichTextEditor.js b/src/rich_text_editor/model/RichTextEditor.js index 40cdad27f..c87738f40 100644 --- a/src/rich_text_editor/model/RichTextEditor.js +++ b/src/rich_text_editor/model/RichTextEditor.js @@ -113,7 +113,7 @@ export default class RichTextEditor { btn.className = btn.className.replace(active, '').trim(); // doc.queryCommandValue(name) != 'false' - if (doc.queryCommandState(name)) { + if (doc.queryCommandSupported(name) && doc.queryCommandState(name)) { btn.className += ` ${active}`; } diff --git a/src/utils/Droppable.js b/src/utils/Droppable.js index c74489dc8..8622c7972 100644 --- a/src/utils/Droppable.js +++ b/src/utils/Droppable.js @@ -3,7 +3,7 @@ */ import { on } from 'utils/mixins'; -import { bindAll } from 'underscore'; +import { bindAll, indexOf } from 'underscore'; export default class Droppable { constructor(em) { @@ -138,17 +138,17 @@ export default class Droppable { } } else if (dragContent) { content = dragContent; - } else if (types.indexOf('text/html') >= 0) { + } else if (indexOf(types, 'text/html') >= 0) { content = dataTransfer .getData('text/html') .replace(/<\/?meta[^>]*>/g, ''); - } else if (types.indexOf('text/uri-list') >= 0) { + } else if (indexOf(types, 'text/uri-list') >= 0) { content = { type: 'link', attributes: { href: content }, content: content }; - } else if (types.indexOf('text/json') >= 0) { + } else if (indexOf(types, 'text/json') >= 0) { const json = dataTransfer.getData('text/json'); json && (content = JSON.parse(json)); }