Skip to content

Instantly share code, notes, and snippets.

@RichardStyles
Last active October 7, 2025 22:42
Show Gist options
  • Save RichardStyles/aa9026be2bb3220b2ae1 to your computer and use it in GitHub Desktop.
Save RichardStyles/aa9026be2bb3220b2ae1 to your computer and use it in GitHub Desktop.
ExtJS 5 component to hold CKEditor (web text editor) from http://ckeditor.com/
Ext.define('Ext.ux.CKeditor', {
extend: 'Ext.form.field.TextArea',
alias: 'widget.ckeditor',
defaultListenerScope: true,
listeners: {
instanceReady: 'instanceReady',
resize: 'resize',
boxready : 'onBoxReady'
},
editorId: null,
editor:null,
CKConfig: {},
constructor: function () {
this.callParent(arguments);
},
initComponent: function () {
this.callParent(arguments);
this.on("afterrender", function () {
Ext.apply(this.CKConfig, {
height: this.getHeight(),
width: this.getWidth()
});
this.editor = CKEDITOR.replace(this.inputEl.id, this.CKConfig);
this.editorId = this.inputEl.id;
this.editor.name = this.name;
this.editor.on("instanceReady", function (ev) {
this.fireEvent(
"instanceReady",
this,
this.editor
);
}, this);
}, this);
},
instanceReady : function (ev) {
// Set read only to false to avoid issue when created into or as a child of a disabled component.
ev.editor.setReadOnly(false);
},
onRender: function (ct, position) {
if (!this.el) {
this.defaultAutoCreate = {
tag: 'textarea',
autocomplete: 'off'
};
}
this.callParent(arguments)
},
setValue: function (value) {
this.callParent(arguments);
if (this.editor) {
this.editor.setData(value);
}
},
getValue: function () {
if (this.editor) {
return this.editor.getData();
}
else {
return ''
}
},
destroy: function(){
// delete instance
if(!Ext.isEmpty(CKEDITOR.instances[this.editorId])){
delete CKEDITOR.instances[this.editorId];
}
},
resize: function(win,width, height,opt) {
var eid = this.editorId,
editor = CKEDITOR.instances[this.editorId];
if (!Ext.isEmpty(CKEDITOR.instances[this.editorId])){
CKEDITOR.instances[this.editorId].resize(width, height);
}
},
onBoxReady : function(win, width, height, eOpts){
// used to hook into the resize method
}
});
@eemsong
Copy link

eemsong commented Oct 7, 2025

I am trying to upgrade the ckeditor4 to Ckeditor5. Is this code working under the new CKEditor5?

@RichardStyles
Copy link
Author

Sorry @eemsong i’ve not used ExtJS now for several years. It’s not something I’d recommend.

Provided ExtJS hasn’t had a major rewrite since (no idea) it should be possible to modify this gist for it, I don’t see why not.

If I remember all this did was wrap the setup and scope/api of the ckeditor object, it’s likely the observer (load/destroy etc) functions may have changed either in ExtJS or ckeditor, ie any specific setup processes if this isn’t working.

I don’t have the ability to test this myself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment