Commit 142aed4c authored by Jonas Schürmann's avatar Jonas Schürmann

Simplify and fix content property synchronisation

parent 3897b0bb
......@@ -13,25 +13,14 @@ var proto = Object.create(HTMLElement.prototype, {
},
content: {
get: function () {
if (this._editor !== null) {
return this._editor.getData();
} else {
return this._content;
}
return this._content;
},
set: function (content) {
if (this._editor !== null) {
if (this._contentUpdate === null) {
setTimeout(function () {
if (this._contentUpdate !== this._editor.getData()) {
this._editor.setData(this._contentUpdate);
this._contentUpdate = null;
}
}, 0);
}
this._contentUpdate = content;
} else {
if (content !== this._content) {
this._content = content;
if (this._editor !== null) {
this._editor.setData(this._content);
}
}
}
},
......@@ -47,22 +36,22 @@ var proto = Object.create(HTMLElement.prototype, {
value: function () {
this._editor = CKEDITOR.appendTo(
this, this._config, this._content);
this._content = null;
var base = this;
base._editor.on('change', function (e) {
var content = base._editor.getData();
base._content = content;
var event = new CustomEvent(
'ckeditorchange',
{ detail: base._editor.getData() });
{detail: content});
base.dispatchEvent(event);
});
}
},
detachedCallback: {
value: function () {
this._content = this._editor.getData();
this._editor.destroy();
this._editor = null;
}
}
});
document.registerElement('x-ckeditor', { prototype: proto });
document.registerElement('x-ckeditor', {prototype: proto});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment