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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/**
    @name Edo.core.Module
    @class
    @typeName module
    @description 模块加载器.能加载指定路径的文件,如user.xml, user.html, user.jsp等.
    @extend Edo.core.UIComponent
    @example 
 
 
*/ 
Edo.core.Module = function(){
    /**
        @name Edo.core.Module#load
        @event
        @description 
    */
 
    /**
        @name Edo.core.Module#unload
        @event
        @description 
    */
 
    /**
        @name Edo.core.Module#beforeunload
        @event
        @description 
    */    
    Edo.core.Module.superclass.constructor.call(this);
};
Edo.core.Module.extend(Edo.core.UIComponent,{
    elCls: 'e-module e-div',
    /**
        @name Edo.core.Module#autoMask
        @property
        @default true
        @description 自动遮罩
    */    
    autoMask: true,
    /**
        @name Edo.core.Module#src
        @property
        @default ''
        @description 模块链接的页面地址
    */        
    src: '',
    _setSrc: function(value){
        if(this.src != value){
            this.src = value;
            this.load(value);
            this.changeProperty('src', value);
        }
    },
    _setHtml: function(){},
    
    createChildren: function(){
        Edo.core.Module.superclass.createChildren.apply(this, arguments);        
        if(this.src){            
            this.load(this.src);
        }
    },
        
    syncSize: function(){
        Edo.core.Module.superclass.syncSize.call(this);
        if(this.iframe){
            var size = Edo.util.Dom.getSize(this.el, true);
            this.iframe.style.width = size.width+'px';
            this.iframe.style.height = size.height+'px';
        }
    },
//    doCreateChildWindow: function(){
//        var cEdo = this.childWindow.Edo;
//        if(cEdo){                    
//            cEdo.create({
//                type: 'button',
//                redner: '#body'
//            });
//            this.configGet = null;
//            
//            this.fireEvent('load',{
//                type: 'load',
//                source: sf                
//            });
//        }else{
//            this.doCreateChildWindow.defer(100, this);
//        }
//    },
    doLoad: function (){   
        if(this.configGet === false) {
            doLoad.defer(50, this);
            return;
        }
        
        this.childWindow = this.iframe.contentWindow;
        
//        if(this.isConfig){               //暂时不支持此功能:以后应该是edo字符串库,直接操作滴
//            //引用js和css资源,并...从ajax得到配置xml或json
//            var html = '<html><body><style type="text/css">html,body{width:100%;height:100%;overflow:hidden;}</style></body></html>'+Edo_core_Module_res+'<script type="text/javascript"></script>';
//            var doc = this.childWindow.document;
//            doc.open();
//            doc.write(html);
//            doc.close();
//            
//            this.doCreateChildWindow.defer(100, this);            
//            return;
//        }
        
        if(this.autoMask !== false) this.unmask();
        
        this.fireEvent('load',{
            type: 'load',
            source: this,
            src: this.src,
            window: this.childWindow
        });
    },
    /**
        @name Edo.core.Module#load
        @function
        @description 加载一个指定url的文件
        @param {String} src 可以是edo的xml定义文件,也可以是任何一个静态或动态的网页
        @param {Boolean} isConfig 说明src引用的是否是配置(xml,json)
    */
    load: function(src, isConfig){
        this.src = src;
        if(!this.el) return false;
        
        if(this.unload() === false) return;
        
        if(this.autoMask !== false) this.mask();
        
        this.src = src;
        this.isConfig = isConfig;
        //        
        //debugger
        var im = this.iframe = document.createElement('iframe');
        im.frameBorder = 0;
        //im.scrolling = 'no';
        im.style.width = (this.realWidth||0)+'px';
        im.style.height = (this.realHeight||0)+'px';
        
        this.el.appendChild(im);        
        
        if(isConfig){
            this.configGet = false;
            var sf = this;
            Edo.util.Ajax.request({
                url: src,
                type: 'get',
                onSuccess: function(text){
                    sf.configGet = text;
                },
                onFail: function(){
                    throw new Error("没有获得module的配置对象资源");
                }
            });
            //1)ajax src
            //2)iframe创建
            //两者都是异步的,所以,需要一个同步
        }else{
            im.src = src;
        }
        
        function checkIFrame(){
        
            var win = this.iframe.contentWindow;
            try{
                if(win && win.document && win.document.readyState=="complete"){                
                    this.doLoad();
                }else{
                    checkIFrame.defer(20, this);    
                }
            }catch(e){            
                this.doLoad(false);
            }
        }        
        if(isGecko && !isChrome){
            var sf = this;
            im.onload = this.doLoad.bind(this);                
        }else{
            checkIFrame.defer(20, this);
        }
        
        
        //优化
        //1)xml的获取由module进行
        //2)同时生成iframe,不需要等iframe加载完毕才进行xml的获取
    },
    /**
        @name Edo.core.Module#unload
        @function
        @description 卸载一个当前加载的页面    
    */
    unload: function(){
        if(this.src && this.iframe){
            //卸载不通过,则不进行更换src操作
            if(this.fireEvent('beforeunload', {type:'beforeunload',source: this}) === false) return false;
            
            this.iframe.src = 'javascript:false;';//'abort:blank';//
            Edo.util.Dom.remove(this.iframe);
            this.childWindow = this.src = this.iframe = this.isConfig = null;            
            this.fireEvent('unload', {
                type: 'unload',
                source: this
            });
        }
    }
});
Edo.core.Module.regType('module');