En plus de @proton grande réponse ci-dessus, il y a une autre façon de insérer boutons à la barre d'outils, différents de les ajouter à la fin. Dans ma réponse, je vais écrire comme un nouveau contrôle nommé « RichTextBox » (et non pas comme un plug-in), mais cela peut être fait de toute autre manière:
Ext.define('Ext.ux.form.RichTextBox', {
extend: 'Ext.form.field.HtmlEditor',
xtype: 'richtextbox',
enableSourceEdit: false, // i choose to hide the option that shows html
initComponent: function() {
this.on('render', this.onRender, this);
this.callParent();
},
/**
* Insert buttons listed below to the html-editor at specific position.
* handler is implemented using 'execCommand':
* https://developer.mozilla.org/en-US/docs/Web/API/Document/execCommand
*/
onRender: function() {
var me = this;
var tb = me.getToolbar();
var btns = {
StrikeThrough: {
//xtype: 'button', // button is default item for this toolbar
itemId: 'btnStrikeThrough',
iconCls: 'x-toolbar-strikethrough ', //choose icon with css class
enableOnSelection: true,
overflowText: 'StrikeThrough',
tooltip: {
title: 'StrikeThrough',
text: 'Toggles strikethrough on/off for the selection or at the insertion point'
},
handler: function() {
this.getDoc().execCommand('strikeThrough', false, null);
},
scope: this,
},
/** Seperator */
sep: "-"
};
tb.insert(5, btns.StrikeThrough); // insert button to the toolbar
//tb.insert(10, btns.sep); // add seperator
//tb.remove(26); // remove button, seperator, etc.
this.callParent(); //important: call regular 'onRender' here or at the start of the foo
}
});
.addButton ([{..}]) - ne fonctionne pas - à la place, vous devez utiliser: this.cmp.getToolbar(). add ({/ * boutons définitions * /}) – snir
@snir Merci! 'add' est nécessaire depuis ExtJS v4 ([sample v4] (http://jsfiddle.net/protron/DCGRg/186/)). 'addButton' fonctionne correctement dans ExtJS v3 ([sample v3] (http://jsfiddle.net/protron/DCGRg/187/)). –