zhuguifei
2026-03-10 2c1fd10c6fbabb8e9f0e9f07fe66fb36c008e883
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/**
    @name Edo.managers.PopupManager
    @class 
    @single
    @description 弹出定位管理器   
    @example 
 
 
*/    
Edo.managers.PopupManager = {
    zindex: 9100,
    popups: {},
    /**        
        @name Edo.managers.PopupManager#createPopup
        @function 
        @description 弹出显示组件
        @param {Object} config 弹出显示的配置对象
<pre>        
{
    target: 需要弹出的组件对象
    x:  坐标
    y:
    modal:  是否遮罩背景
}                    
</pre>                
    */        
    createPopup: function(cfg){
        var cmp = cfg.target;
        if(!cmp) return false;
        var bd = Edo.getBody();
        
        Edo.applyIf(cfg, {
            x: 'center',
            y: 'middle',
            //shadow: true,
            modal: false,
            modalCt: bd,
            onout: Edo.emptyFn,
            onin: Edo.emptyFn,
            onmousedown: Edo.emptyFn
        });                    
        
        var x = cfg.x, y = cfg.y, modalCt = cfg.modalCt;
 
        if(Edo.isValue(cfg.width)) cmp._setWidth(cfg.width);
        if(Edo.isValue(cfg.height)) cmp._setHeight(cfg.height);
        
        var zIndex = this.zindex++;
        cmp._setStyle('z-index:'+zIndex+';position:absolute;');
        cfg.zIndex = zIndex;
                
        var boxCt = Edo.util.Dom.getBox(modalCt);
        var sizeCt = Edo.util.Dom.getViewSize(document);
        boxCt.width = sizeCt.width;
        boxCt.height = sizeCt.height;
        
        if(!cmp.layouted){
            cmp.doLayout();
        }
        var boxCmp = cmp._getBox();
        
        if((!x && x !== 0) || x == 'center'){           
            x = (boxCt.x + boxCt.width/2) - boxCmp.width/2
        }
        if((!y && y !== 0) || y == 'middle'){
            y = (boxCt.y + boxCt.height/2) - boxCmp.height/2
        }
        //调节下坐标定位(如果是边缘等)
        cmp.set('visible', true);
        cmp._setXY([x, y]);
        
        cmp.left = parseInt(cmp.el.style.left);
        cmp.top = parseInt(cmp.el.style.top);
        
        if(isOpera) cmp._setXY(x, y);
        
        if(cfg.modal){
            Edo.util.Dom.mask(modalCt);
            if(modalCt._mask) modalCt._mask.style.zIndex = zIndex-1;
        }else{
            this.unmask(cmp, modalCt);
        }
        
        //cmp._setStyle('z-index:'+(parseInt(modalCt._mask.style.zIndex)+1)+';');
        
        this.popups[cmp.id] = cfg;
        
        if(cfg.focus){
            cmp.focus.defer(30, cmp);
        }                        
        
        setTimeout(function(){
        Edo.util.Dom.repaint(cmp.el);   
        }, 10);
        
        //对tab键的特殊控制处理                
    },
    /**        
        @name Edo.managers.PopupManager#removePopup
        @function 
        @description 隐藏弹出显示组件
        @param {UIComponent} 组件对象                
    */      
    removePopup: function(cmp){
    
        var o = this.popups[cmp.id];
        if(!o) return;
        cmp._setX(-3000);
        cmp.blur();
        //cmp.set('visible', false);
        
        //cmp.set.defer(1, cmp, ['visible', false]);
        if(o.modal) {
            //遍历popups,判断是否有一样的modalCt,如果有,则不unmask
            //unmask.defer(100, null, [cmp, cmp.modalCt]);
            this.unmask(cmp, o.modalCt);
        }
        delete cmp.modalCt;
        delete this.popups[cmp.id];
    },
    unmask: function(cmp, mct){
        var repeat = false;
        var zindex = -1;
        for(var id in this.popups){
            if(id == cmp.id) continue;
            var pop = this.popups[id];
            if(pop.modalCt === mct && pop.modal){
                repeat = true;
                zindex = pop.zIndex;
                break;
            }
        }
        if(repeat){
            if(mct._mask) mct._mask.style.zIndex = zindex-1;
        }
        else Edo.util.Dom.unmask(mct);
    }
};
Edo.util.Dom.on(document, 'mousedown', function(e){
    var popups = Edo.managers.PopupManager.popups;
    
    for(var id in popups){
        var popup = popups[id];               
        popup.onmousedown(e);
        if(!popup.target.within(e)){
            popup.onout(e);
        }else{
            popup.onin(e);
        }
    }
});