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
152
153
154
155
156
157
158
 
/*
    实现下拉框逻辑,trigger图标
        1.combobox: grid
        2.date:     datepicker
        3.lov:      弹出url,弹出窗体 popupWindow
        4.tree
        
    实现autoComplete功能:
    popupCt:是一个box容器.
*/
/**
    @name Edo.controls.Trigger
    @class
    @typeName trigger
    @description 下拉弹出框
    @extend Edo.controls.TextInput
*/
Edo.controls.Trigger = function(){    
    /**
        @name Edo.controls.Trigger#beforetrigger
        @event
        @domevent
        @description trigger图标点击前事件
    */
    
    /**
        @name Edo.controls.Trigger#trigger
        @event
        @domevent
        @description trigger图标点击事件
    */
 
    Edo.controls.Trigger.superclass.constructor.call(this);
};
Edo.controls.Trigger.extend(Edo.controls.TextInput,{    
    enableResizePopup: true,
    /**
        @name Edo.controls.Trigger#maxHeight
        @property        
        @default 500
    */
    maxHeight: 500,    
    /**        
        @name Edo.controls.Trigger#triggerPopup
        @property
        @type Boolean
        @default false
        @description 为true在按trigger图片的时候,自动显示
    */      
    triggerPopup: false,
 
    triggerCls: 'e-trigger',
    triggerOverCls: 'e-trigger-over',
    triggerPressedCls: 'e-trigger-pressed', 
    
    triggerVisible: true,    
    
    initEvents: function(){             
        Edo.controls.Trigger.superclass.initEvents.call(this);            
        
        if(!this.design){
            Edo.util.Dom.on(this.el, 'mousedown', this._onTriggerMousedown, this);
            var el = this.trigger;
            Edo.util.Dom.addClassOnClick(el, this.triggerPressedCls);
            Edo.util.Dom.addClassOnOver(el, this.triggerOverCls);
        }
    },
    _onTriggerMousedown: function(e){
        if(this.readOnly || e.within(this.trigger)){
            this._onTrigger.defer(1, this, [e]);
        }
    },
    _onTrigger: function(e){
        e.stopDefault();
        if(!this.isEnable()) return;        
        if(e.button != Edo.util.MouseButton.left) return;
        
        e.type = 'beforetrigger';
        e.source = this;
        
        if(this.fireEvent('beforetrigger', e) === false) return;
                
        
        if(this.triggerPopup){
            if(this.popupDisplayed){
                this.hidePopup();
            }else{
                this.showPopup();
            }        
        }
        //this.focus();
        this.focus.defer(50, this);//这行代码真恶心..
        //this.field.focus();
//        var sf = this;
//        setTimeout(function(){
//            sf.field.focus();
//        }, 100);
        e.type = 'trigger';
        this.fireEvent('trigger', {
            type: 'trigger',
            source: this
        });
    },
//    setEnable: function(value){
//        Edo.controls.Trigger.superclass.setEnable.call(this, value);
//        if(this.trigger){
//            if(this.isEnable()){
//                Edo.util.Dom.removeClass(this.trigger, "e-disabled");
//            }else{        
//                Edo.util.Dom.addClass(this.trigger, "e-disabled");
//            }
//        }
//    },
    getTriggerHtml: function(){
        return '<div class="e-trigger-icon"></div>';
    },
    getInnerHtml: function(sb){
        Edo.controls.Trigger.superclass.getInnerHtml.call(this, sb);
        
        sb[sb.length] = '<div class="';
        
        sb[sb.length] = this.triggerCls;
        sb[sb.length] = '" style="display:';
        sb[sb.length] = this.triggerVisible ? 'block' : 'none';
        sb[sb.length] = ';height:';
        sb[sb.length] = this.realHeight-1;
        sb[sb.length] = 'px;">';
        sb[sb.length] = this.getTriggerHtml();
        sb[sb.length] = '</div>';     
    },   
    createChildren: function(el){
        Edo.controls.Trigger.superclass.createChildren.call(this, el);
        this.trigger = this.field.nextSibling;
    },
    syncSize: function(){    //设置组件尺寸,并设置容器子元素的所有尺寸!
        Edo.controls.Trigger.superclass.syncSize.call(this);
        
        if(this.triggerVisible){
            this.trigger.style.display = 'block';
            Edo.util.Dom.setHeight(this.trigger, this.realHeight - 4);
        }else{
            this.trigger.style.display = 'none';
        }
    },
    triggerWidth: 19,
    getFieldWidth: function(){
        return this.realWidth - (this.triggerVisible ? this.triggerWidth : 0);
    },
    destroy : function(){   
        Edo.util.Dom.clearEvent(this.trigger);            
        Edo.util.Dom.remove(this.trigger);
        this.trigger = null;
        Edo.controls.Trigger.superclass.destroy.call(this);                 
    }
});
 
Edo.controls.Trigger.regType('trigger');