gpt4 book ai didi

extjs4 - 将tinyMCE 4集成到extJS 4中

转载 作者:行者123 更新时间:2023-12-02 04:21:15 24 4
gpt4 key购买 nike

由于tinyMCE 4与之前的版本相比有很大的变化,是否有人尝试将extjs 4.*集成到新版本的tinyMCE中?

最佳答案

基本集成的实现非常简单:

Ext.define('TinyMceField', {
extend: 'Ext.form.field.TextArea'
,alias: 'widget.tinymce'

/**
* TinyMCE editor configuration.
*
* @cfg {Object}
*/
,editorConfig: undefined

,afterRender: function() {
this.callParent(arguments);

var me = this,
id = this.inputEl.id;

var editor = tinymce.createEditor(id, Ext.apply({
selector: '#' + id
,resize: false
,height: this.height
,width: this.width
,menubar: false
}, this.editorConfig));

this.editor = editor;

// set initial value when the editor has been rendered
editor.on('init', function() {
editor.setContent(me.value || '');
});

// render
editor.render();

// --- Relay events to Ext

editor.on('focus', function() {
me.previousContent = editor.getContent();
me.fireEvent('focus', me);
});

editor.on('blur', function() {
me.fireEvent('blur', me);
});

editor.on('change', function(e) {
var content = editor.getContent(),
previousContent = me.previousContent;
if (content !== previousContent) {
me.previousContent = content;
me.fireEvent('change', me, content, previousContent);
}
});
}

,getRawValue: function() {
var editor = this.editor,
value = editor && editor.initialized ? editor.getContent() : Ext.value(this.rawValue, '');
this.rawValue = value;
return value;
}

,setRawValue: function(value) {
this.callParent(arguments);

var editor = this.editor;
if (editor && editor.initialized) {
editor.setContent(value);
}

return this;
}
});

用法示例( see fiddle ):

Ext.widget('window', {
width: 400
,height: 350
,layout: 'form'
,items: [{
xtype: 'textfield'
,fieldLabel: 'Foo'
}, {
xtype: 'tinymce'
,id: 'tinyEditor'
,fieldLabel: 'Bar'
,value: '<p>Foo</p><p><strong>Bar</strong></p>'
,listeners: {
change: function(me, newValue, oldValue) {
console.log('content changed: ' + oldValue + ' => ' + newValue);
}
,blur: function() { console.log('editor blurred'); }
,focus: function() { console.log('editor focused'); }
}
}]
,bbar: [{
text: 'Get value'
,handler: function() {
var e = Ext.getCmp('tinyEditor');
alert(e.getValue());
}
}]
});

关于extjs4 - 将tinyMCE 4集成到extJS 4中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16765827/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com