-
Notifications
You must be signed in to change notification settings - Fork 13
/
AtomUIComponent.js
199 lines (169 loc) · 5.23 KB
/
AtomUIComponent.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
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
/// <reference path="atomcomponent.js" />
(function (base) {
return classCreator("WebAtoms.AtomUIComponent", base,
function () {
},
{
get_owner: function () {
return this;
},
get_appScope: function () {
return appScope;
},
get_scope: function () {
if (this._scope === undefined) {
var ap = this.get_atomParent(this._element._logicalParent || this._element.parentNode);
if (ap) {
return ap._localScope || ap.get_scope();
}
else {
return appScope;
}
}
return this._scope;
},
get_localScope: function () {
if (this._localScope === undefined) {
var ap = this.get_atomParent(this._element._logicalParent || this._element.parentNode);
if (ap) {
return ap.get_localScope();
} else {
throw new Error("Local Scope does not exist");
}
}
return this._localScope;
},
set_scope: function (s) {
var scope = this._localScope || this.get_scope();
for (var k in s) {
if (/^(application|owner|app|parent)$/gi.test(k))
throw new Error("Invalid name for the scope property");
// if value is already set...
var v = s[k];
if (scope == window.appScope && !window.atomApplication._ready) {
if ((k.indexOf('_') != 0)
&& (v !== undefined && v !== null)
&& (/string|number|boolean/i.test(typeof (v)))){
atomApplication._defaultScope[k] = v;
}
}
if (scope[k] !== undefined)
continue;
scope[k] = v;
}
},
get_name: function () {
return this._name;
},
getTemplate: function (k) {
var t = this["_" + k];
if (t !== undefined && t !== null)
return t;
// resolve...
t = Templates.get(this.constructor, k);
if (!t) {
return null;
}
this["_" + k] = t;
return t;
}
},
{
next: null,
value: undefined
});
})(WebAtoms.AtomComponent.prototype);
Templates.compiled = {
};
Templates.compileElement = function (e) {
var ae = new AtomEnumerator(e);
ae.next();
var a = ae.current();
var e1 = document.createElement(a);
if (!ae.next())
return e1;
a = ae.current();
if (a) {
for (var k in a) {
e1.setAttribute(k, a[k]);
}
}
while (ae.next()) {
a = ae.current();
if (!a)
break;
if (a.constructor == String) {
e1.appendChild(document.createTextNode(a));
} else {
e1.appendChild(Templates.compileElement(a));
}
}
return e1;
};
Templates.compileJsonML = function (j) {
if (j.length == 1)
return Templates.compileElement(j[0]);
var r = [];
var ae = new AtomEnumerator(j);
while (ae.next()) {
r.push(Templates.compileElement(ae.current()));
}
return r;
};
Templates.compile = function (type, name, t) {
var div = document.createElement("div");
div.innerHTML = t;
if ($(div).children().length == 1) {
t = AtomUI.cloneNode((div.firstElementChild || div.children[0]));
}
return t;
};
Templates.get = function (type, k) {
//var x = this.compileType(type);
//return x[k];
var name = type.__typeName + "." + k;
var x = this.compiled[name];
if (x)
return x;
x = Templates.jsonML[name];
if (!x) {
if (type.__baseType) {
x = Templates.get(type.__baseType, k);
}
} else {
x = Templates.compileJsonML(x);
}
if (!x)
return null;
this.compiled[name] = x;
return x;
};
Templates.compileType = function (type) {
var name = type.__typeName;
var shortName = name.split(".");
shortName = shortName[shortName.length - 1];
var x = this.compiled[name];
if (x)
return x;
x = {
};
var tl = this[name] || this[shortName];
if (tl) {
for (var t in tl) {
x[t] = this.compile(type, t, tl[t]);
}
}
if (type.__baseType) {
var y = this.compileType(type.__baseType);
for (var yt in y) {
if (!x[yt]) {
x[yt] = y[yt];
}
}
}
this.compiled[name] = x;
var t = this;
delete t[name];
delete t[shortName];
return x;
};