From c587a8a5969371944e202eb6080ca67711e35885 Mon Sep 17 00:00:00 2001 From: Raffi Date: Thu, 7 Mar 2019 09:53:59 +0000 Subject: [PATCH] Replace DOMNodeInserted with MutationObserver --- src/block.js | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/block.js b/src/block.js index 4264f8e5f..0b942c1a8 100644 --- a/src/block.js +++ b/src/block.js @@ -371,10 +371,12 @@ Object.assign(Block.prototype, SimpleBlock.fn, require('./block-validations'), { }, _initTextBlocks: function() { + var observer = new MutationObserver(this.clearInsertedStyles); + Array.prototype.forEach.call(this.getTextBlock(), (el) => { el.addEventListener('keyup', this.getSelectionForFormatter); el.addEventListener('mousedown', this.addMouseupListener.bind(this)); - el.addEventListener('DOMNodeInserted', this.clearInsertedStyles); + observer.observe(el, { childList: true }); }); var textBlock = this.getTextBlock()[0]; @@ -407,12 +409,16 @@ Object.assign(Block.prototype, SimpleBlock.fn, require('./block-validations'), { }, 1); }, - clearInsertedStyles: function(e) { - var target = e.target; - if (_.isUndefined(target.tagName)) { - target = target.parentNode; - } - target.removeAttribute('style'); // Hacky fix for Chrome. + clearInsertedStyles: function(mutations) { + mutations.forEach(function(mutation) { + for (var i = 0; i < mutation.addedNodes.length; i++) { + var target = mutation.addedNodes[i]; + if (_.isUndefined(target.tagName)) { + target = target.parentNode; + } + target.removeAttribute('style'); // Hacky fix for Chrome. + } + }); }, hasTextBlock: function() {