From 1721a342b21efe617f16ab47762cae0181216997 Mon Sep 17 00:00:00 2001 From: GovardhanCel Date: Fri, 6 Dec 2019 17:41:54 +0530 Subject: [PATCH] Error with vue-froala and multiple / dynamic instance --- src/vue-froala.js | 52 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/src/vue-froala.js b/src/vue-froala.js index b5ca8d0..e04cd2b 100644 --- a/src/vue-froala.js +++ b/src/vue-froala.js @@ -88,7 +88,8 @@ export default (Vue, Options = {}) => { return; } - this.currentConfig = this.config || this.defaultConfig; + // To remove object reference of previous editor https://github.com/froala-labs/froala-editor-js-2/issues/2143 + this.currentConfig = this.clone(this.config || this.defaultConfig); this.setContent(true); @@ -102,6 +103,55 @@ export default (Vue, Options = {}) => { }, + // TODO: replace clone method with better possible alternate + clone: function(item){ + const me = this; + if (!item) { return item; } // null, undefined values check + + let types = [ Number, String, Boolean ], + result; + + // normalizing primitives if someone did new String('aaa'), or new Number('444'); + types.forEach(function(type) { + if (item instanceof type) { + result = type( item ); + } + }); + + if (typeof result == "undefined") { + if (Object.prototype.toString.call( item ) === "[object Array]") { + result = []; + item.forEach(function(child, index, array) { + result[index] = me.clone( child ); + }); + } else if (typeof item == "object") { + // testing that this is DOM + if (item.nodeType && typeof item.cloneNode == "function") { + result = item.cloneNode( true ); + } else if (!item.prototype) { // check that this is a literal + if (item instanceof Date) { + result = new Date(item); + } else { + // it is an object literal + result = {}; + for (var i in item) { + result[i] = me.clone( item[i] ); + } + } + } else { + if (false && item.constructor) { + result = new item.constructor(); + } else { + result = item; + } + } + } else { + result = item; + } + } + + return result; + }, setContent: function (firstTime) { if (!this.editorInitialized && !firstTime) {