forked from AlloyTeam/Abstract.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloadmodel.js
85 lines (64 loc) · 2.24 KB
/
loadmodel.js
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
;(function(){
var $ = Model.$;
// 生命周期只有一次
// rock之后即脱离父元素
// 被真正的model替代
var LoadModel = Model.Class("BaseModel", {
type: "LoadModel",
// url name
constructor: function(opt){
this.callSuper();
this.moduleName = opt.moduleName;
this.name = opt.name;
},
// 预先加载的逻辑
load: function(callback){
var name = this.name;
// 先寻找是否有外放的tab
var key = "recieveModel" + name;
var realizeKey = "realizeModel" + name;
var _this = this;
var recieveFunc = function(name, model, onswitch) {
if (name && model) {
// 替换自己
_this.parent && _this.parent.replaceChild(_this, model);
_this.dispatchEvent(Model.createEvent({
type: "completed",
target: _this,
name: "anonymouse"
}), model, onswitch);
window[key] = null;
delete window[key];
callback && callback(model);
}
};
if (window[realizeKey]) {
window[realizeKey](recieveFunc);
} else {
window[key] = recieveFunc;
// 加载模快
Model.load(this.moduleName, function(e){
});
}
},
active: function(e){
var parent = this.parent;
var _this = this;
this.load(function(model){
model.rock();
// 检查父亲元素进行预先加载
if(parent){
for(var i = 0; i < parent.children.length; i ++){
var item = parent.children[i];
if(item !== _this && item.type === "LoadModel"){
item.load();
}
}
}
});
},
unactive: function(e){
}
});
Model.external("LoadModel", LoadModel);
})();