Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes froala-labs/froala-editor-js-2#2143 #125

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 51 additions & 1 deletion src/vue-froala.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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) {
Expand Down