How to close modal window extjs when clicking on mask?

前端 未结 4 1176
遇见更好的自我
遇见更好的自我 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:36

    Tramway's case (sort of) works on modal or non modal windows. But not in case child components like the boundlist of a combobox float outside the windows boundaries.

    However if you use modal windows anyway you can listen for a click event on the mask like this.

    Ext.define('myWindow', {
        extend: 'Ext.window.Window',
        alias: 'widget.myWindow',
        floating: true,
        modal: true,
    
        initComponent: function () {
            var me = this;
            me.callParent(arguments);
            me.mon(Ext.getBody(), 'click', function(el, e){
                me.close(me.closeAction);
            }, me, { delegate: '.x-mask' });
        }
    });
    
    0 讨论(0)
  • 2021-02-05 16:37

    You can try this also:

    Ext.getBody().on('click', function(e, t){
        var el = win.getEl();
    
        if (!(el.dom === t || el.contains(t))) {
            win.close();
        }
    });
    
    0 讨论(0)
  • 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();
            }
        }
    }
    
    0 讨论(0)
  • 2021-02-05 16:51

    I found adding a listener to the body and checking css classes felt a little hackey to me. You can actually override the private method _onMaskClick of Ext.ZIndexManager (see, completely not hackey). Which allows you to add your own configuration parameter (and even event) to all windows.

    Ext.define('MyApp.ux.ZIndexManager_maskClick', {
      override: 'Ext.ZIndexManager',
    
      _onMaskClick: function ()
      {
        if (this.front)
        {
          var allowed = this.front.fireEvent('maskclick', this.front, this.mask);
    
          if (allowed !== false && this.front.closeOnMaskClick)
            this.front.close();
        }
        return this.callParent(arguments);
      },
    });
    
    0 讨论(0)
提交回复
热议问题