Extjs7 classic 自定义panel折叠图标

版本

7.4.0 classic

效果

  • 展开
    在这里插入图片描述
  • 折叠
  • 在这里插入图片描述

源码

  1. 覆盖panel组件updateCollapseTool方法修改折叠按钮图标
updateCollapseTool: function () {
    this.callParent();
    var me = this, collapseTool = me.collapseTool;
    if (collapseTool) {
        if (me.collapsed && !me.isPlaceHolderCollapse()) {
            collapseTool.setIconCls('x-fa fa-indent')
        } else {
            collapseTool.setIconCls('x-fa fa-outdent')
        }
    }
}
  1. 覆盖panel组件createReExpander方法修改展开按钮图标
createReExpander: function (direction, defaults) {
    var result = this.callParent([direction, defaults]);
    result.expandTool.setIconCls('x-fa fa-indent');
    return result;
}

EXT源码

  • ext-classic/src/panel/Panel.js
// 更新折叠按钮图标
updateCollapseTool: function() {
    var me = this,
        collapseTool = me.collapseTool,
        toolCfg;

    if (!collapseTool && me.collapsible) {
        me.collapseDirection = me.collapseDirection || me.getHeaderPosition() || 'top';

        toolCfg = {
            xtype: 'tool',
            handler: me.toggleCollapse,
            scope: me
        };

        // In accordion layout panels are collapsible/expandable with keyboard
        // via the panel title that is focusable. There is no need to have a separate
        // collapse/expand tool for keyboard interaction but we still have to react
        // to mouse clicks, and historically accordion panels had coolapse tools
        // so we leave the tool but make it unfocusable and keyboard inactive.
        // Note that we do the same thing for the automatically added close tool
        // but NOT for the other tools.
        if (me.isAccordionPanel) {
            toolCfg.focusable = false;
            toolCfg.ariaRole = 'presentation';
        }

        me.collapseTool = me.expandTool = collapseTool = Ext.widget(toolCfg);
    }

    if (collapseTool) {
        if (me.collapsed && !me.isPlaceHolderCollapse()) {
            collapseTool.setType('expand-' + me.getOppositeDirection(me.collapseDirection));
            collapseTool.setTooltip(me.expandToolText);
        }
        else {
            collapseTool.setType('collapse-' + me.collapseDirection);
            collapseTool.setTooltip(me.collapseToolText);
        }
    }
},
// 创建展开按钮
createReExpander: function(direction, defaults) {
    var me = this,
        isLeft = direction === 'left',
        isRight = direction === 'right',
        isVertical = isLeft || isRight,
        ownerCt = me.ownerCt,
        header = me.header,
        result = Ext.apply({
            hideMode: 'offsets',
            title: me.getTitle(),
            titleAlign: me.getTitleAlign(),
            titlePosition: me.getTitlePosition(),
            vertical: isVertical,
            textCls: me.headerTextCls,
            icon: me.getIcon(),
            iconCls: me.getIconCls(),
            iconAlign: me.getIconAlign(),
            glyph: me.getGlyph(),
            baseCls: me.self.prototype.baseCls + '-header',
            ui: me.ui,
            frame: me.frame && me.frameHeader,
            ignoreParentFrame: me.frame || me.overlapHeader,
            ignoreBorderManagement: me.frame || me.ignoreHeaderBorderManagement,
            indicateDrag: me.draggable,
            collapseImmune: true,
            ariaRole: me.ariaRole,
            preventRefocus: true,
            ownerCt: (ownerCt && me.collapseMode === 'placeholder') ? ownerCt : me,
            ownerLayout: me.componentLayout,
            forceOrientation: true,
            margin: me.margin,
            // When placeholder is focused, focus the expander tool.
            // TODO: When https://sencha.jira.com/browse/EXTJS-19718 is
            // fixed, this should not be needed.
            // placeholder is a FocusableContainer
            defaultFocus: 'tool[isDefaultExpandTool]'
        }, defaults);

    // If we're in mini mode, set the placeholder size to only 1px since
    // we don't need it to show up.
    if (me.collapseMode === 'mini') {
        if (isVertical) {
            result.width = 1;
        }
        else {
            result.height = 1;
        }
    }

    if (header) {
        Ext.apply(result, {
            focusableContainer: header.focusableContainer,
            activeChildTabIndex: header.activeChildTabIndex,
            inactiveChildTabIndex: header.inactiveChildTabIndex,
            allowFocusingDisabledChildren: header.allowFocusingDisabledChildren
        });
    }

    // Create the re expand tool
    // For UI consistency reasons, collapse:left reExpanders, and region: 'west' placeHolders
    // have the re expand tool at the *top* with a bit of space.
    if (!me.hideCollapseTool) {
        if (!me.maintainTitlePosition && (isLeft || (isRight && me.isPlaceHolderCollapse()))) {
            // adjust the title position if the collapse tool needs to be at the
            // top of a vertical header
            result.titlePosition = 1;
        }

        result.tools = [{
            xtype: 'tool',
            type: 'expand-' + me.getOppositeDirection(direction),
            isDefaultExpandTool: true,
            uiCls: ['top'],
            handler: me.toggleCollapse,
            scope: me,
            tooltip: me.expandToolText
        }];
    }

    result = new Ext.panel.Header(result);
    result.addClsWithUI(me.getHeaderCollapsedClasses(result));

    result.expandTool = result.down('tool[isDefaultExpandTool=true]');

    return result;
},
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
ExtJS 中自定义一个 textarea 组件并显示行号,可以通过下面两种方式实现: 1. 使用 Ext.ux.form.field.CodeMirror 组件 使用 Ext.ux.form.field.CodeMirror 组件可以非常方便地实现 textarea 组件显示行号的功能。该组件基于 CodeMirror 编辑器实现,支持语法高亮、自动补全等功能。 示例代码: ``` Ext.define('MyApp.view.MyTextArea', { extend: 'Ext.ux.form.field.CodeMirror', alias: 'widget.mytextarea', initComponent: function() { this.callParent(); this.editor.setOption('lineNumbers', true); } }); ``` 在组件的 `initComponent` 方法中,设置 `lineNumbers` 选项为 `true` 即可显示行号。 2. 使用 Ext.form.field.TextArea 组件 如果不想使用 CodeMirror 编辑器,也可以通过自定义渲染函数来实现 textarea 组件显示行号的功能。具体实现方式如下: 示例代码: ``` Ext.define('MyApp.view.MyTextArea', { extend: 'Ext.form.field.TextArea', alias: 'widget.mytextarea', afterRender: function() { this.callParent(); this.mon(this.inputEl, 'scroll', this.onScroll, this); this.mon(this.inputEl, 'resize', this.onResize, this); this.mon(this.inputEl, 'keydown', this.onKeyDown, this); this.mon(this.inputEl, 'keyup', this.onKeyUp, this); this.mon(this.inputEl, 'mousedown', this.onMouseDown, this); this.mon(this.inputEl, 'mouseup', this.onMouseUp, this); this.mon(this.inputEl, 'dblclick', this.onDblClick, this); this.mon(this.inputEl, 'contextmenu', this.onContextMenu, this); this.updateLineNumber(); }, onScroll: function() { this.updateLineNumber(); }, onResize: function() { this.updateLineNumber(); }, onKeyDown: function() { this.updateLineNumber(); }, onKeyUp: function() { this.updateLineNumber(); }, onMouseDown: function() { this.updateLineNumber(); }, onMouseUp: function() { this.updateLineNumber(); }, onDblClick: function() { this.updateLineNumber(); }, onContextMenu: function() { this.updateLineNumber(); }, updateLineNumber: function() { var text = this.getValue(); var lineNumber = text.split(/\r?\n/).length; var lineNumberHtml = ''; for (var i = 1; i <= lineNumber; i++) { lineNumberHtml += i + '<br/>'; } this.getEl().down('.line-number').update(lineNumberHtml); }, getSubTplMarkup: function(values) { return this.callParent([Ext.apply({}, values, { inputCls: 'x-form-textarea', value: values.value && Ext.util.Format.htmlEncode(values.value), lineNumber: true })]); }, getSubTplData: function(fieldData) { var data = this.callParent([fieldData]); if (fieldData.lineNumber) { data.inputWrapCls = (data.inputWrapCls || '') + ' x-form-textarea-with-number'; data.afterInputEl = '<div class="line-number"></div>'; } return data; } }); ``` 在组件的 `afterRender` 方法中,绑定 `scroll`、`resize`、`keydown`、`keyup`、`mousedown`、`mouseup`、`dblclick` 和 `contextmenu` 事件,当组件内容发生变化时更新行号。在 `updateLineNumber` 方法中,计算组件内容的行数,并生成对应的 HTML 代码插入到组件 DOM 中。在 `getSubTplData` 和 `getSubTplMarkup` 方法中,通过添加 CSS 类和 HTML 代码实现行号的显示。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

路过君_P

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值