How to close modal window extjs when clicking on mask?

前端 未结 4 1333
遇见更好的自我
遇见更好的自我 2021-02-05 16:19

If I create a modal window:

Ext.define(\'myWindow\', {
    extend: \'Ext.Container\',
    alias: \'widget.myWindow\',
    floating: true,
    modal: true,
    li         


        
4条回答
  •  没有蜡笔的小新
    2021-02-05 16:44

    You can listen all click events, then check if click position is out of the window

    Ext.define('myWindow', {
        extend: 'Ext.Container',
        alias: 'widget.myWindow',
        floating: true,
        modal: true,
    
        initComponent: function () {
            this.initEvents();
            this.callParent();
        },
    
        initEvents: function () {
            //make sure your window is rendered and have sizes and position
            if(!this.rendered) {
                this.on('afterrender', this.initEvents, this, {single: true});
                return;
            }
    
            this.mon(Ext.getBody(), 'click', this._checkCloseClick, this);
        }
    
        _checkCloseClick: function (event) {
            var cx = event.getX(), cy = event.getY(),
                box = this.getBox();
    
            if (cx < box.x || cx > box.x + box.width || cy < box.y || cy > box.y + box.height) {
                //clean up listener listener
                this.mun(Ext.getBody(), 'click', this._checkCloseClick, this);
                this.close();
            }
        }
    }
    

提交回复
热议问题