HTML モードに切り替える必要はありません。insertAtCursor
HTML テンプレートで関数を使用するだけです。
<hr>
水平定規(タグ)を挿入するボタンを追加する方法のこの簡単な例を作成しました:
Ext.ns('Ext.ux.form.HtmlEditor');
Ext.ux.form.HtmlEditor.HR = Ext.extend(Ext.util.Observable, {
init: function(cmp){
this.cmp = cmp;
this.cmp.on('render', this.onRender, this);
},
onRender: function(){
this.cmp.getToolbar().addButton([{
iconCls: 'x-edit-bold', //your iconCls here
handler: function(){
this.cmp.insertAtCursor('<hr>');
},
scope: this,
tooltip: 'horizontal ruler',
overflowText: 'horizontal ruler'
}]);
}
});
Ext.preg('ux-htmleditor-hr', Ext.ux.form.HtmlEditor.HR);
Ext.QuickTips.init();
new Ext.Viewport({
layout: 'fit',
items: [{
xtype: 'htmleditor',
plugins: [new Ext.ux.form.HtmlEditor.HR()]
}]
});
jsfiddle.net/protron/DCGRg/183/で実行されていることがわかります。
しかし、HtmlEditor.Plugins (またはExtJS 4 の場合は ateodorescu/mzExt ) を確認することを強くお勧めします。そこでは、カスタム ボタンの追加について、たとえば、何かが選択されたときにボタンを有効/無効にする方法、セパレーターを配置する方法など、さらに多くの情報を見つけることができます。