Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
Fix #444: multiple CKEditor instances
Browse files Browse the repository at this point in the history
  • Loading branch information
cdujeu committed Feb 4, 2014
1 parent 89e5316 commit 08487d9
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions core/src/plugins/editor.ckeditor/class.AjxpCkEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
*/
Class.create("AjxpCkEditor", TextEditor, {

editorInstanceId:null,

initialize: function($super, oFormObject, options)
{
$super(oFormObject, options);
Expand Down Expand Up @@ -78,30 +80,32 @@ Class.create("AjxpCkEditor", TextEditor, {
this.inputNode = node;
var fileName = node.getPath();
var textarea;
this.editorInstanceId = slugString(node.getPath());

this.textareaContainer = new Element('div');
this.textarea = new Element('textarea');
this.textarea.name = this.textarea.id = 'content';
this.textarea.name = this.textarea.id = this.editorInstanceId;
this.contentMainContainer = this.textareaContainer;
this.textarea.setStyle({width:'100%'});
this.textarea.setAttribute('wrap', 'off');
this.element.insert(this.textareaContainer);
this.textareaContainer.appendChild(this.textarea);
fitHeightToBottom(this.textareaContainer, $(modal.elementName));
this.reloadEditor('content');
//fitHeightToBottom(this.textareaContainer, $(modal.elementName));
this.reloadEditor(this.editorInstanceId);
this.element.observe("editor:close", function(){
CKEDITOR.instances.content.destroy();
});
CKEDITOR.instances[this.editorInstanceId].destroy();
}.bind(this));
this.element.observe("editor:resize", function(event){
this.resizeEditor();
}.bind(this));
var destroy = function(){
if(CKEDITOR.instances.content){
this.textarea.value = CKEDITOR.instances.content.getData();
CKEDITOR.instances.content.destroy();
if(CKEDITOR.instances[this.editorInstanceId]){
this.textarea.value = CKEDITOR.instances[this.editorInstanceId].getData();
CKEDITOR.instances[this.editorInstanceId].destroy();
}
};
var reInit = function(){
CKEDITOR.replace('content', this.editorConfig);
CKEDITOR.replace(this.editorInstanceId, this.editorConfig);
window.setTimeout(function(){
this.resizeEditor();
this.bindCkEditorEvents();
Expand All @@ -126,7 +130,7 @@ Class.create("AjxpCkEditor", TextEditor, {
if(this.isModified) return;// useless

window.setTimeout(function(){
var editor = CKEDITOR.instances.content;
var editor = CKEDITOR.instances[this.editorInstanceId];
if(!editor) {
return;
}
Expand Down Expand Up @@ -168,24 +172,24 @@ Class.create("AjxpCkEditor", TextEditor, {
},

resizeEditor : function(){
var width = this.contentMainContainer.getWidth()-(Prototype.Browser.IE?0:12);
var height = this.contentMainContainer.getHeight();
if(CKEDITOR.instances.content){
CKEDITOR.instances.content.resize(width,height);
if(CKEDITOR.instances[this.editorInstanceId] && CKEDITOR.instances[this.editorInstanceId].container){
var width = this.contentMainContainer.getWidth();
var height = this.contentMainContainer.getHeight();
CKEDITOR.instances[this.editorInstanceId].resize(width,height);
}
},

saveFile : function(){
var connexion = this.prepareSaveConnexion();
var value = CKEDITOR.instances.content.getData();
var value = CKEDITOR.instances[this.editorInstanceId].getData();
this.textarea.value = value;
connexion.addParameter('content', value);
connexion.sendAsync();
},

parseTxt : function(transport){
this.textarea.value = transport.responseText;
CKEDITOR.instances.content.setData(transport.responseText);
CKEDITOR.instances[this.editorInstanceId].setData(transport.responseText);
this.removeOnLoad(this.textareaContainer);
this.setModified(false);
}
Expand Down

0 comments on commit 08487d9

Please sign in to comment.