Skip to content

Instantly share code, notes, and snippets.

@RichardStyles
Last active April 19, 2018 09:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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
}
});
@jjab2020
Copy link

hello any version to use in extjs 6 any help thank you very much :)

@RichardStyles
Copy link
Author

I have a couple of projects which I need to upgrade for ExtJS 6 so will let you know.

@RichardStyles
Copy link
Author

@jjab2020 Current work in progress building the component as a package, with promising results. https://github.com/RichardStyles/ExtJSCKEditor

@roohitgandhi
Copy link

hello, when I click "Templates" button and chose "Image and Title", then from general tab browse the image. It shows image there. But after save when I reload it is showing blank space instead. Am I missing any config setting? or anything?
I have noticed that the html it creates for image has src as blank.

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