ExtJS: add button to htmleditor

后端 未结 3 1034
一向
一向 2021-02-06 06:04

I am using ExtJS and I have a htmleditor in my form. I would like to add a custom button to that element (for example after all other buttons like alignments, font weights, ...)

3条回答
  •  南方客
    南方客 (楼主)
    2021-02-06 06:11

    You don't need to switch to HTML mode. Just use the insertAtCursor function with the HTML template.

    I made this easy example of how to add button which inserts a horizontal ruler (


    tag):

    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('
    '); }, 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()] }] });

    You can see it running at: jsfiddle.net/protron/DCGRg/183/

    But I really recommend you to check out HtmlEditor.Plugins (or ateodorescu/mzExt for ExtJS 4). There you can find a lot more about adding custom buttons, for instance, how to enable/disable the buttons when something is selected, put separators, etc.

提交回复
热议问题