@base-framework/base 2.6.0 → 2.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (190) hide show
  1. package/base.min.js +1 -0
  2. package/es5/base.js +2968 -0
  3. package/es5/modules/ajax.js +663 -0
  4. package/es5/modules/animation.js +188 -0
  5. package/es5/modules/animations.js +1080 -0
  6. package/es5/modules/atom.js +65 -0
  7. package/es5/modules/component.js +1310 -0
  8. package/es5/modules/data-binder.js +1131 -0
  9. package/es5/modules/data.js +1808 -0
  10. package/es5/modules/date.js +525 -0
  11. package/es5/modules/form-validator.js +324 -0
  12. package/es5/modules/history.js +126 -0
  13. package/es5/modules/html-builder.js +461 -0
  14. package/es5/modules/layout.js +1679 -0
  15. package/es5/modules/mouse.js +124 -0
  16. package/es5/modules/nav-link.js +123 -0
  17. package/es5/modules/olderversions/animations-ease.js +1095 -0
  18. package/es5/modules/olderversions/animations-update.js +1048 -0
  19. package/es5/modules/olderversions/base-animations.js +636 -0
  20. package/es5/modules/olderversions/base-component-class.js +100 -0
  21. package/es5/modules/olderversions/base-data-binder-1.js +407 -0
  22. package/es5/modules/olderversions/base-data-binder-class.js +358 -0
  23. package/es5/modules/olderversions/base-layout-parser-class.js +172 -0
  24. package/es5/modules/olderversions/base-mode-1.js +777 -0
  25. package/es5/modules/olderversions/base-model-class.js +585 -0
  26. package/es5/modules/olderversions/data-binder/element-binding/base-data-binder-class.js +358 -0
  27. package/es5/modules/olderversions/data-binder/element-binding/base-model-class.js +585 -0
  28. package/es5/modules/olderversions/data-binder/model-binding/base-data-binder-class.js +353 -0
  29. package/es5/modules/olderversions/data-binder/model-binding/base-model-class.js +604 -0
  30. package/es5/modules/olderversions/data-binder-update-watcher.js +640 -0
  31. package/es5/modules/olderversions/data-tracker.js +187 -0
  32. package/es5/modules/olderversions/event-update.js +666 -0
  33. package/es5/modules/olderversions/nav-link.js +119 -0
  34. package/es5/modules/olderversions/router-with-templates-1.js +785 -0
  35. package/es5/modules/olderversions/router-with-templates.js +701 -0
  36. package/es5/modules/prototypes/ajax.js +657 -0
  37. package/es5/modules/prototypes/atom.js +65 -0
  38. package/es5/modules/prototypes/component.js +972 -0
  39. package/es5/modules/prototypes/data-binder.js +1089 -0
  40. package/es5/modules/prototypes/data.js +1290 -0
  41. package/es5/modules/prototypes/html-builder.js +414 -0
  42. package/es5/modules/prototypes/layout.js +879 -0
  43. package/es5/modules/router.js +1680 -0
  44. package/es5/modules/state.js +274 -0
  45. package/es6/.jshintrc +3 -0
  46. package/es6/base.js +41 -0
  47. package/es6/core.js +1 -0
  48. package/es6/data-tracker.js +351 -0
  49. package/es6/events.js +602 -0
  50. package/es6/legacy/es5/base.js +2968 -0
  51. package/es6/legacy/es5/modules/ajax.js +663 -0
  52. package/es6/legacy/es5/modules/animation.js +188 -0
  53. package/es6/legacy/es5/modules/animations.js +1080 -0
  54. package/es6/legacy/es5/modules/atom.js +65 -0
  55. package/es6/legacy/es5/modules/component.js +1310 -0
  56. package/es6/legacy/es5/modules/data-binder.js +1131 -0
  57. package/es6/legacy/es5/modules/data.js +1808 -0
  58. package/es6/legacy/es5/modules/date.js +525 -0
  59. package/es6/legacy/es5/modules/form-validator.js +324 -0
  60. package/es6/legacy/es5/modules/history.js +126 -0
  61. package/es6/legacy/es5/modules/html-builder.js +461 -0
  62. package/es6/legacy/es5/modules/layout.js +1679 -0
  63. package/es6/legacy/es5/modules/mouse.js +124 -0
  64. package/es6/legacy/es5/modules/nav-link.js +123 -0
  65. package/es6/legacy/es5/modules/olderversions/animations-ease.js +1095 -0
  66. package/es6/legacy/es5/modules/olderversions/animations-update.js +1048 -0
  67. package/es6/legacy/es5/modules/olderversions/base-animations.js +636 -0
  68. package/es6/legacy/es5/modules/olderversions/base-component-class.js +100 -0
  69. package/es6/legacy/es5/modules/olderversions/base-data-binder-1.js +407 -0
  70. package/es6/legacy/es5/modules/olderversions/base-data-binder-class.js +358 -0
  71. package/es6/legacy/es5/modules/olderversions/base-layout-parser-class.js +172 -0
  72. package/es6/legacy/es5/modules/olderversions/base-mode-1.js +777 -0
  73. package/es6/legacy/es5/modules/olderversions/base-model-class.js +585 -0
  74. package/es6/legacy/es5/modules/olderversions/data-binder/element-binding/base-data-binder-class.js +358 -0
  75. package/es6/legacy/es5/modules/olderversions/data-binder/element-binding/base-model-class.js +585 -0
  76. package/es6/legacy/es5/modules/olderversions/data-binder/model-binding/base-data-binder-class.js +353 -0
  77. package/es6/legacy/es5/modules/olderversions/data-binder/model-binding/base-model-class.js +604 -0
  78. package/es6/legacy/es5/modules/olderversions/data-binder-update-watcher.js +640 -0
  79. package/es6/legacy/es5/modules/olderversions/data-tracker.js +187 -0
  80. package/es6/legacy/es5/modules/olderversions/event-update.js +666 -0
  81. package/es6/legacy/es5/modules/olderversions/nav-link.js +119 -0
  82. package/es6/legacy/es5/modules/olderversions/router-with-templates-1.js +785 -0
  83. package/es6/legacy/es5/modules/olderversions/router-with-templates.js +701 -0
  84. package/es6/legacy/es5/modules/prototypes/ajax.js +657 -0
  85. package/es6/legacy/es5/modules/prototypes/atom.js +65 -0
  86. package/es6/legacy/es5/modules/prototypes/component.js +972 -0
  87. package/es6/legacy/es5/modules/prototypes/data-binder.js +1089 -0
  88. package/es6/legacy/es5/modules/prototypes/data.js +1290 -0
  89. package/es6/legacy/es5/modules/prototypes/html-builder.js +414 -0
  90. package/es6/legacy/es5/modules/prototypes/layout.js +879 -0
  91. package/es6/legacy/es5/modules/router.js +1680 -0
  92. package/es6/legacy/es5/modules/state.js +274 -0
  93. package/es6/main.js +1331 -0
  94. package/es6/modules/ajax/ajax.js +514 -0
  95. package/es6/modules/animation/animation.js +236 -0
  96. package/es6/modules/animations/animation-controller.js +231 -0
  97. package/es6/modules/animations/animation.js +64 -0
  98. package/es6/modules/animations/attr-movement.js +66 -0
  99. package/es6/modules/animations/css-movement.js +170 -0
  100. package/es6/modules/animations/movement.js +131 -0
  101. package/es6/modules/animations/value.js +187 -0
  102. package/es6/modules/atom/atom.js +54 -0
  103. package/es6/modules/component/component.js +230 -0
  104. package/es6/modules/component/event-helper.js +119 -0
  105. package/es6/modules/component/jot.js +144 -0
  106. package/es6/modules/component/state-helper.js +262 -0
  107. package/es6/modules/component/unit.js +551 -0
  108. package/es6/modules/data/attrs.js +40 -0
  109. package/es6/modules/data/basic-data.js +500 -0
  110. package/es6/modules/data/data-utils.js +29 -0
  111. package/es6/modules/data/data.js +3 -0
  112. package/es6/modules/data/deep-data.js +541 -0
  113. package/es6/modules/data/model-service.js +528 -0
  114. package/es6/modules/data/model.js +133 -0
  115. package/es6/modules/data/simple-data.js +33 -0
  116. package/es6/modules/data-binder/connection-tracker.js +113 -0
  117. package/es6/modules/data-binder/connection.js +16 -0
  118. package/es6/modules/data-binder/data-binder.js +352 -0
  119. package/es6/modules/data-binder/data-pub-sub.js +141 -0
  120. package/es6/modules/data-binder/data-source.js +56 -0
  121. package/es6/modules/data-binder/element-source.js +219 -0
  122. package/es6/modules/data-binder/one-way-connection.js +46 -0
  123. package/es6/modules/data-binder/one-way-source.js +43 -0
  124. package/es6/modules/data-binder/source.js +36 -0
  125. package/es6/modules/data-binder/two-way-connection.js +75 -0
  126. package/es6/modules/data-binder/two-way-source.js +41 -0
  127. package/es6/modules/date/date.js +544 -0
  128. package/es6/modules/history/history.js +89 -0
  129. package/es6/modules/html-builder/html-builder.js +434 -0
  130. package/es6/modules/import/import.js +390 -0
  131. package/es6/modules/layout/layout-builder.js +1269 -0
  132. package/es6/modules/layout/layout-parser.js +134 -0
  133. package/es6/modules/layout/watcher-helper.js +282 -0
  134. package/es6/modules/mouse/mouse.js +114 -0
  135. package/es6/modules/router/component-helper.js +163 -0
  136. package/es6/modules/router/history-controller.js +216 -0
  137. package/es6/modules/router/nav-link.js +124 -0
  138. package/es6/modules/router/route.js +401 -0
  139. package/es6/modules/router/router.js +789 -0
  140. package/es6/modules/router/utils.js +31 -0
  141. package/es6/modules/state/state-target.js +91 -0
  142. package/es6/modules/state/state.js +171 -0
  143. package/es6/package-lock.json +13 -0
  144. package/es6/package.json +28 -0
  145. package/es6/shared/objects.js +99 -0
  146. package/legacy/es5/base.js +2968 -0
  147. package/legacy/es5/modules/ajax.js +663 -0
  148. package/legacy/es5/modules/animation.js +188 -0
  149. package/legacy/es5/modules/animations.js +1080 -0
  150. package/legacy/es5/modules/atom.js +65 -0
  151. package/legacy/es5/modules/component.js +1310 -0
  152. package/legacy/es5/modules/data-binder.js +1131 -0
  153. package/legacy/es5/modules/data.js +1808 -0
  154. package/legacy/es5/modules/date.js +525 -0
  155. package/legacy/es5/modules/form-validator.js +324 -0
  156. package/legacy/es5/modules/history.js +126 -0
  157. package/legacy/es5/modules/html-builder.js +461 -0
  158. package/legacy/es5/modules/layout.js +1679 -0
  159. package/legacy/es5/modules/mouse.js +124 -0
  160. package/legacy/es5/modules/nav-link.js +123 -0
  161. package/legacy/es5/modules/olderversions/animations-ease.js +1095 -0
  162. package/legacy/es5/modules/olderversions/animations-update.js +1048 -0
  163. package/legacy/es5/modules/olderversions/base-animations.js +636 -0
  164. package/legacy/es5/modules/olderversions/base-component-class.js +100 -0
  165. package/legacy/es5/modules/olderversions/base-data-binder-1.js +407 -0
  166. package/legacy/es5/modules/olderversions/base-data-binder-class.js +358 -0
  167. package/legacy/es5/modules/olderversions/base-layout-parser-class.js +172 -0
  168. package/legacy/es5/modules/olderversions/base-mode-1.js +777 -0
  169. package/legacy/es5/modules/olderversions/base-model-class.js +585 -0
  170. package/legacy/es5/modules/olderversions/data-binder/element-binding/base-data-binder-class.js +358 -0
  171. package/legacy/es5/modules/olderversions/data-binder/element-binding/base-model-class.js +585 -0
  172. package/legacy/es5/modules/olderversions/data-binder/model-binding/base-data-binder-class.js +353 -0
  173. package/legacy/es5/modules/olderversions/data-binder/model-binding/base-model-class.js +604 -0
  174. package/legacy/es5/modules/olderversions/data-binder-update-watcher.js +640 -0
  175. package/legacy/es5/modules/olderversions/data-tracker.js +187 -0
  176. package/legacy/es5/modules/olderversions/event-update.js +666 -0
  177. package/legacy/es5/modules/olderversions/nav-link.js +119 -0
  178. package/legacy/es5/modules/olderversions/router-with-templates-1.js +785 -0
  179. package/legacy/es5/modules/olderversions/router-with-templates.js +701 -0
  180. package/legacy/es5/modules/prototypes/ajax.js +657 -0
  181. package/legacy/es5/modules/prototypes/atom.js +65 -0
  182. package/legacy/es5/modules/prototypes/component.js +972 -0
  183. package/legacy/es5/modules/prototypes/data-binder.js +1089 -0
  184. package/legacy/es5/modules/prototypes/data.js +1290 -0
  185. package/legacy/es5/modules/prototypes/html-builder.js +414 -0
  186. package/legacy/es5/modules/prototypes/layout.js +879 -0
  187. package/legacy/es5/modules/router.js +1680 -0
  188. package/legacy/es5/modules/state.js +274 -0
  189. package/package.json +8 -3
  190. package/update +16 -0
@@ -0,0 +1,879 @@
1
+ /* base framework module */
2
+ /*
3
+ this will create a layout builder object
4
+ and shortcut functions.
5
+ */
6
+ (function()
7
+ {
8
+ "use strict";
9
+
10
+ /**
11
+ * LayoutParser
12
+ *
13
+ * This will parse JSON layouts.
14
+ * @class
15
+ */
16
+ var LayoutParser = base.Class.extend(
17
+ {
18
+ /**
19
+ * @member {array} _reserved
20
+ * @protected
21
+ */
22
+ _reserved: [
23
+ 'tag',
24
+ 'bind',
25
+ 'onCreated',
26
+ 'route',
27
+ 'switch',
28
+ 'onSet',
29
+ 'onState',
30
+ 'watch',
31
+ 'cache'
32
+ ],
33
+
34
+ /**
35
+ * This will get the tag name of an element.
36
+ *
37
+ * @param {object} obj
38
+ * @return {string}
39
+ */
40
+ getElementTag: function(obj)
41
+ {
42
+ var type = 'div',
43
+ node = obj.tag || obj.t;
44
+ if (typeof node !== 'undefined')
45
+ {
46
+ type = obj.tag = node;
47
+ }
48
+
49
+ return type;
50
+ },
51
+
52
+ /**
53
+ * This will parse a layout element.
54
+ *
55
+ * @param {object} obj
56
+ * @return {object}
57
+ */
58
+ parseElement: function(obj)
59
+ {
60
+ var attr = {},
61
+ children = [];
62
+
63
+ var tag = this.getElementTag(obj);
64
+ if(tag === 'button')
65
+ {
66
+ attr.type = attr.type || 'button';
67
+ }
68
+
69
+ if(typeof obj.children === 'undefined')
70
+ {
71
+ obj.children = null;
72
+ }
73
+
74
+ if(typeof obj.text !== 'undefined')
75
+ {
76
+ obj.textContent = obj.text;
77
+ }
78
+
79
+ var reserved = this._reserved;
80
+
81
+ for (var key in obj)
82
+ {
83
+ if (obj.hasOwnProperty(key))
84
+ {
85
+ var value = obj[key];
86
+ if (value === null || base.inArray(reserved, key) !== -1)
87
+ {
88
+ continue;
89
+ }
90
+
91
+ /* we need to filter the children from the attr
92
+ settings. the children need to keep their order. */
93
+ if (typeof value !== 'object')
94
+ {
95
+ attr[key] = value;
96
+ }
97
+ else
98
+ {
99
+ if (key === 'children')
100
+ {
101
+ children = children.concat(value);
102
+ }
103
+ else
104
+ {
105
+ children.push(value);
106
+ }
107
+ }
108
+ }
109
+ }
110
+
111
+ return {
112
+ tag: tag,
113
+ attr: attr,
114
+ children: children
115
+ };
116
+ }
117
+ });
118
+
119
+ /**
120
+ * WatcherHelper
121
+ *
122
+ * This helper creates watcher callBacks, parses watcher strings
123
+ * and sets up watchers.
124
+ */
125
+ var WatcherHelper =
126
+ {
127
+ /**
128
+ * This will get the property names to be watched.
129
+ *
130
+ * @protected
131
+ * @param {string} string
132
+ * @return {(array|null)}
133
+ */
134
+ _getWatcherProps: function(string)
135
+ {
136
+ var pattern = /\[\[(.*?)\]\]/g,
137
+ matches = string.match(pattern);
138
+ if(matches)
139
+ {
140
+ pattern = /(\[\[|\]\])/g;
141
+ for(var i = 0, length = matches.length; i < length; i++)
142
+ {
143
+ matches[i] = matches[i].replace(pattern, '');
144
+ }
145
+ }
146
+ return matches;
147
+ },
148
+
149
+ /**
150
+ * This will update an element attribute.
151
+ *
152
+ * @protected
153
+ * @param {object} ele
154
+ * @param {string} attr
155
+ * @param {string} value
156
+ */
157
+ updateAttr: function(ele, attr, value)
158
+ {
159
+ if(attr === 'text' || attr === 'textContent')
160
+ {
161
+ ele.textContent = value;
162
+ }
163
+ else if(attr === 'innerHTML')
164
+ {
165
+ ele.innerHTML = value;
166
+ }
167
+ else
168
+ {
169
+ base.setAttr(ele, attr, value);
170
+ }
171
+ },
172
+
173
+ /**
174
+ * This will get a watcher callBack.
175
+ *
176
+ * @protected
177
+ * @param {object} ele
178
+ * @param {(string|array)} data
179
+ * @param {string} string
180
+ * @param {string} attr
181
+ * @param {boolean} isArray
182
+ * @return {function}
183
+ */
184
+ _getWatcherCallBack: function(ele, data, string, attr, isArray)
185
+ {
186
+ var self = this;
187
+ return function()
188
+ {
189
+ var count = 0,
190
+ pattern = /(\[\[(.*?)\]\])/g,
191
+ value = string.replace(pattern, function()
192
+ {
193
+ var watcherData = (isArray)? data[count] : data;
194
+ count++;
195
+ var result = watcherData.get(arguments[2]);
196
+ return (typeof result !== 'undefined'? result : '');
197
+ });
198
+ self.updateAttr(ele, attr, value);
199
+ };
200
+ },
201
+
202
+ /**
203
+ * This will get a watcher value.
204
+ *
205
+ * @private
206
+ * @param {(string|object)} settings
207
+ * @param {object} parent
208
+ * @return {array}
209
+ */
210
+ getValue: function(settings, parent)
211
+ {
212
+ if(typeof settings === 'string')
213
+ {
214
+ settings =
215
+ {
216
+ value: settings
217
+ };
218
+ }
219
+
220
+ var value = settings.value;
221
+ if(base.isArray(value) === false)
222
+ {
223
+ value = [value, (parent.data || parent.state)];
224
+ }
225
+ return value;
226
+ },
227
+
228
+ /**
229
+ * This will get the watcher callBack.
230
+ *
231
+ * @param {object} settings
232
+ * @param {object} ele
233
+ * @param {object} data
234
+ * @param {string} string
235
+ * @param {bool} isDataArray
236
+ * @return {function}
237
+ */
238
+ getCallBack: function(settings, ele, data, string, isDataArray)
239
+ {
240
+ var callBack,
241
+ overrideCallBack = settings.callBack;
242
+ if(typeof overrideCallBack === 'function')
243
+ {
244
+ callBack = function(value, committer)
245
+ {
246
+ overrideCallBack(ele, value, committer);
247
+ };
248
+ }
249
+ else
250
+ {
251
+ var attr = settings.attr || 'textContent';
252
+ callBack = this._getWatcherCallBack(ele, data, string, attr, isDataArray);
253
+ }
254
+ return callBack;
255
+ },
256
+
257
+ /**
258
+ * This will add a data watcher.
259
+ *
260
+ * @private
261
+ * @param {object} ele
262
+ * @param {(string|object)} settings
263
+ * @param {object} parent
264
+ */
265
+ addDataWatcher: function(ele, settings, parent)
266
+ {
267
+ var value = this.getValue(settings, parent),
268
+ data = value[1];
269
+ if(!data)
270
+ {
271
+ return false;
272
+ }
273
+
274
+ var string = value[0],
275
+ isDataArray = base.isArray(data);
276
+
277
+ var callBack = this.getCallBack(settings, ele, data, string, isDataArray);
278
+ var props = this._getWatcherProps(string);
279
+ for(var i = 0, length = props.length; i < length; i++)
280
+ {
281
+ var watcherData = (isDataArray)? data[i] : data;
282
+ this.addWatcher(ele, watcherData, props[i], callBack);
283
+ }
284
+ },
285
+
286
+ /**
287
+ * This will setup a data watcher.
288
+ *
289
+ * @param {object} ele
290
+ * @param {(string|object)} settings
291
+ * @param {object} parent
292
+ */
293
+ setup: function(ele, settings, parent)
294
+ {
295
+ if(!settings)
296
+ {
297
+ return false;
298
+ }
299
+
300
+ this.addDataWatcher(ele, settings, parent);
301
+ },
302
+
303
+ /**
304
+ * This will add a watcher.
305
+ *
306
+ * @private
307
+ * @param {object} ele
308
+ * @param {object} data
309
+ * @param {string} prop
310
+ * @param {function} callBack
311
+ */
312
+ addWatcher: function(ele, data, prop, callBack)
313
+ {
314
+ base.DataBinder.watch(ele, data, prop, callBack);
315
+ }
316
+ };
317
+
318
+ var parser = new LayoutParser();
319
+
320
+ /**
321
+ * LayoutBuilder
322
+ *
323
+ * This will build JSON layouts.
324
+ *
325
+ * @class
326
+ * @augments base.htmlBuilder
327
+ */
328
+ var LayoutBuilder = base.htmlBuilder.extend(
329
+ {
330
+ /**
331
+ * This will create a new element.
332
+ *
333
+ * @override
334
+ * @param {string} nodeName The node name.
335
+ * @param {object} attrObject The node attributes.
336
+ * @param {object} container The node container.
337
+ * @param {boolean} [prepend=false] Add to the begining of the container.
338
+ * @return {object} The new element.
339
+ */
340
+ create: function(nodeName, attrObject, container, prepend)
341
+ {
342
+ var obj = document.createElement(nodeName);
343
+ this._addElementAttrs(obj, attrObject);
344
+ this.append(container, obj);
345
+ return obj;
346
+ },
347
+
348
+ /**
349
+ * This will build a JSON layout.
350
+ *
351
+ * @param {object} obj The JSON layout.
352
+ * @param {object} [container] The parent receiving the layout.
353
+ * @param {object} [parent] The component adding the layout.
354
+ * @return {object} The doc Frag element.
355
+ */
356
+ build: function(obj, container, parent)
357
+ {
358
+ var fragment = this.createDocFragment();
359
+
360
+ if (obj.constructor === Array)
361
+ {
362
+ var item;
363
+ for (var i = 0, length = obj.length; i < length; i++)
364
+ {
365
+ item = obj[i];
366
+ this.buildElement(item, fragment, parent);
367
+ }
368
+ }
369
+ else
370
+ {
371
+ this.buildElement(obj, fragment, parent);
372
+ }
373
+
374
+ if(container && typeof container === 'object')
375
+ {
376
+ container.appendChild(fragment);
377
+ }
378
+ return fragment;
379
+ },
380
+
381
+ /**
382
+ * This will build an element or component.
383
+ *
384
+ * @param {object} obj
385
+ * @param {object} container
386
+ * @param {object} [parent] The component adding the layout.
387
+ */
388
+ buildElement: function(obj, container, parent)
389
+ {
390
+ if(obj.component || obj.isUnit === true)
391
+ {
392
+ this.createComponent(obj, container, parent);
393
+ }
394
+ else
395
+ {
396
+ this.createElement(obj, container, parent);
397
+ }
398
+ },
399
+
400
+ /**
401
+ * This will append a child element to a parent.
402
+ *
403
+ * @override
404
+ * @param {object} parent
405
+ * @param {object} child
406
+ */
407
+ append: function(parent, child)
408
+ {
409
+ parent.appendChild(child);
410
+ },
411
+
412
+ /**
413
+ * This will create an element.
414
+ *
415
+ * @protected
416
+ * @param {object} obj
417
+ * @param {object} container
418
+ * @param {object} [parent] The component adding the layout.
419
+ */
420
+ createElement: function(obj, container, parent)
421
+ {
422
+ var settings = parser.parseElement(obj);
423
+ var ele = this.createNode(settings, container);
424
+
425
+ var propName = obj.cache;
426
+ if(parent && propName)
427
+ {
428
+ parent[propName] = ele;
429
+ }
430
+
431
+ if(typeof obj.onCreated === 'function')
432
+ {
433
+ obj.onCreated(ele);
434
+ }
435
+
436
+ /* this will check to bind the element to
437
+ the prop of a data */
438
+ var bind = obj.bind;
439
+ if(bind)
440
+ {
441
+ this.bindElement(ele, bind, parent);
442
+ }
443
+
444
+ if(obj.route)
445
+ {
446
+ this.addRoute(ele, obj.route);
447
+ }
448
+
449
+ if(obj.switch)
450
+ {
451
+ this.addSwitch(ele, obj.switch);
452
+ }
453
+
454
+ if(parent)
455
+ {
456
+ var onState = obj.onState;
457
+ if(onState && onState.length)
458
+ {
459
+ this.onState(ele, onState, parent);
460
+ }
461
+
462
+ var onSet = obj.onSet;
463
+ if(onSet && onSet.length)
464
+ {
465
+ this.onSet(ele, onSet, parent);
466
+ }
467
+ }
468
+
469
+ if(obj.watch)
470
+ {
471
+ this.watch(ele, obj.watch, parent);
472
+ }
473
+
474
+ /* we want to recursively add the children to
475
+ the new element */
476
+ var children = settings.children;
477
+ if (children.length > 0)
478
+ {
479
+ var child;
480
+ for (var i = 0, length = children.length; i < length; i++)
481
+ {
482
+ child = children[i];
483
+ if(child === null)
484
+ {
485
+ continue;
486
+ }
487
+
488
+ this.buildElement(child, ele, parent);
489
+ }
490
+ }
491
+ },
492
+
493
+ /**
494
+ * This will get the data source from the parent component.
495
+ *
496
+ * @protected
497
+ * @param {object} [parent]
498
+ * @return {(object|boolean)}
499
+ */
500
+ _getDataSource: function(parent)
501
+ {
502
+ if(!parent)
503
+ {
504
+ return false;
505
+ }
506
+
507
+ var data = (parent.data || parent.state);
508
+ return data || false;
509
+ },
510
+
511
+ /**
512
+ * This will bind an element to data.
513
+ *
514
+ * @protected
515
+ * @param {object} ele
516
+ * @param {(string|array)} bind
517
+ * @param {*} parent
518
+ */
519
+ bindElement: function(ele, bind, parent)
520
+ {
521
+ var data, prop, filter;
522
+
523
+ if(typeof bind === 'string')
524
+ {
525
+ data = this._getDataSource(parent);
526
+ if(!data)
527
+ {
528
+ return false;
529
+ }
530
+
531
+ prop = bind;
532
+ }
533
+ else if(bind.constructor === Array)
534
+ {
535
+ if((typeof bind[0] !== 'object'))
536
+ {
537
+ var dataSource = this._getDataSource(parent);
538
+ if(!dataSource)
539
+ {
540
+ return false;
541
+ }
542
+ else
543
+ {
544
+ bind.unshift(dataSource);
545
+ }
546
+ }
547
+
548
+ data = bind[0];
549
+ prop = bind[1];
550
+ filter = bind[2];
551
+ }
552
+
553
+ base.DataBinder.bind(ele, data, prop, filter);
554
+ },
555
+
556
+ /**
557
+ * This will add a route.
558
+ *
559
+ * @protected
560
+ * @param {object} ele
561
+ * @param {(object|array)} route
562
+ */
563
+ addRoute: function(ele, route)
564
+ {
565
+ if(!route)
566
+ {
567
+ return false;
568
+ }
569
+
570
+ if(route.constructor === Array)
571
+ {
572
+ for(var i = 0, length = route.length; i < length; i++)
573
+ {
574
+ this.setupRoute(ele, route[i]);
575
+ }
576
+ }
577
+ else
578
+ {
579
+ this.setupRoute(ele, route);
580
+ }
581
+ },
582
+
583
+ /**
584
+ * This will setup a route.
585
+ *
586
+ * @protected
587
+ * @param {object} ele
588
+ * @param {object} route
589
+ */
590
+ setupRoute: function(ele, route)
591
+ {
592
+ route.container = ele;
593
+ var newRoute = base.router.add(route);
594
+
595
+ base.DataTracker.add(ele, 'routes',
596
+ {
597
+ route: newRoute
598
+ });
599
+ },
600
+
601
+ /**
602
+ * This will add a switch.
603
+ *
604
+ * @protected
605
+ * @param {object} ele
606
+ * @param {array} group
607
+ */
608
+ addSwitch: function(ele, group)
609
+ {
610
+ for(var i = 0, length = group.length; i < length; i++)
611
+ {
612
+ var route = group[i];
613
+ route.container = ele;
614
+ }
615
+
616
+ var id = base.router.addSwitch(group);
617
+ base.DataTracker.add(ele, 'switch',
618
+ {
619
+ id: id
620
+ });
621
+ },
622
+
623
+ /**
624
+ * This will add a watcher.
625
+ *
626
+ * @protected
627
+ * @param {object} ele
628
+ * @param {(array|object)} watcher
629
+ * @param {object} [parent]
630
+ */
631
+ watch: function(ele, watcher, parent)
632
+ {
633
+ if(!watcher)
634
+ {
635
+ return false;
636
+ }
637
+
638
+ if(base.isArray(watcher))
639
+ {
640
+ for(var i = 0, length = watcher.length; i < length; i++)
641
+ {
642
+ WatcherHelper.setup(ele, watcher[i], parent);
643
+ }
644
+ }
645
+ else
646
+ {
647
+ WatcherHelper.setup(ele, watcher, parent);
648
+ }
649
+ },
650
+
651
+ /**
652
+ * This will add an onState watcher.
653
+ *
654
+ * @param {object} ele
655
+ * @param {array} onState
656
+ * @param {object} parent
657
+ */
658
+ onState: function(ele, onState, parent)
659
+ {
660
+ this.onUpdate(ele, parent.state, onState, parent);
661
+ },
662
+
663
+ /**
664
+ * This will add an onSet watcher.
665
+ *
666
+ * @param {object} ele
667
+ * @param {array} onSet
668
+ * @param {object} parent
669
+ */
670
+ onSet: function(ele, onSet, parent)
671
+ {
672
+ this.onUpdate(ele, parent.data, onSet, parent);
673
+ },
674
+
675
+ /**
676
+ * This will setup a data watcher.
677
+ *
678
+ * @param {object} ele
679
+ * @param {object} data
680
+ * @param {string} prop
681
+ * @param {(function|object)} callBack
682
+ * @param {string} parent
683
+ */
684
+ onUpdate: function(ele, data, settings, parent)
685
+ {
686
+ var prop,
687
+ self = this,
688
+ callBack, update;
689
+
690
+ if(base.isArray(settings[0]))
691
+ {
692
+ for(var i = 0, maxLength = settings.length; i < maxLength; i++)
693
+ {
694
+ var itemSettings = settings[i];
695
+ if(!itemSettings)
696
+ {
697
+ continue;
698
+ }
699
+
700
+ this.onUpdate(ele, data, itemSettings, parent);
701
+ }
702
+ return;
703
+ }
704
+
705
+ if(settings.length < 3)
706
+ {
707
+ prop = settings[0];
708
+ callBack = settings[1];
709
+ }
710
+ else
711
+ {
712
+ data = settings[0];
713
+ prop = settings[1];
714
+ callBack = settings[2];
715
+ }
716
+
717
+ if(!data || !prop)
718
+ {
719
+ return false;
720
+ }
721
+
722
+ switch(typeof callBack)
723
+ {
724
+ case 'object':
725
+ update = function(value)
726
+ {
727
+ self.addClass(ele, callBack, value);
728
+ };
729
+ break;
730
+ case 'function':
731
+ update = function(value)
732
+ {
733
+ self.updateElement(ele, callBack, prop, value, parent);
734
+ };
735
+ break;
736
+ }
737
+
738
+ base.DataBinder.watch(ele, data, prop, update);
739
+ },
740
+
741
+ /**
742
+ * This will setup a data watcher.
743
+ *
744
+ * @private
745
+ * @param {object} ele
746
+ * @param {function} callBack
747
+ * @param {string} value
748
+ * @param {string} parent
749
+ */
750
+ updateElement: function(ele, callBack, prop, value, parent)
751
+ {
752
+ var result = callBack(ele, value);
753
+ switch(typeof result)
754
+ {
755
+ case 'object':
756
+ if(parent && parent.persist === true && parent.state)
757
+ {
758
+ var key = prop + ':' + value,
759
+ state = parent.state,
760
+ previousResult = state.get(key);
761
+ if(typeof previousResult !== 'undefined')
762
+ {
763
+ result = previousResult;
764
+ }
765
+
766
+ state.set(key, result);
767
+ }
768
+ this.rebuild(ele, result, parent);
769
+ break;
770
+ case 'string':
771
+ this.addHtml(ele, result);
772
+ break;
773
+ }
774
+ },
775
+
776
+ /**
777
+ * This will add or remove a class from an element.
778
+ *
779
+ * @param {object} ele
780
+ * @param {object} stateStyles
781
+ * @param {*} newValue
782
+ */
783
+ addClass: function(ele, stateStyles, newValue)
784
+ {
785
+ for(var prop in stateStyles)
786
+ {
787
+ if(!stateStyles.hasOwnProperty(prop) || !prop)
788
+ {
789
+ continue;
790
+ }
791
+
792
+ if(stateStyles[prop] === newValue)
793
+ {
794
+ base.addClass(ele, prop);
795
+ }
796
+ else
797
+ {
798
+ base.removeClass(ele, prop);
799
+ }
800
+ }
801
+ },
802
+
803
+ /**
804
+ * This will reset an element innerHTML and rebuild.
805
+ *
806
+ * @private
807
+ * @param {object} ele
808
+ * @param {object} layout
809
+ * @param {object} parent
810
+ */
811
+ rebuild: function(ele, layout, parent)
812
+ {
813
+ this.removeAll(ele);
814
+ this.build(layout, ele, parent);
815
+ },
816
+
817
+ /**
818
+ * This will create a component.
819
+ *
820
+ * @protected
821
+ * @param {object} obj
822
+ * @param {object} container
823
+ * @param {object} parent
824
+ */
825
+ createComponent: function(obj, container, parent)
826
+ {
827
+ // this will allow both cached components or native components
828
+ var component = obj.component || obj;
829
+ component.parent = parent;
830
+
831
+ if(parent && parent.persist === true)
832
+ {
833
+ component.persist = true;
834
+ }
835
+
836
+ component.setup(container);
837
+
838
+ if(obj.component && typeof obj.onCreated === 'function')
839
+ {
840
+ obj.onCreated(component);
841
+ }
842
+ },
843
+
844
+ /**
845
+ * This will create a node.
846
+ *
847
+ * @param {object} settings
848
+ * @param {object} container
849
+ * @return {object}
850
+ */
851
+ createNode: function(settings, container)
852
+ {
853
+ var tag = settings.tag;
854
+ if(tag !== 'text')
855
+ {
856
+ return this.create(tag, settings.attr, container);
857
+ }
858
+
859
+ var attr = settings.attr;
860
+ var text = attr.textContent || attr.text;
861
+ return this.createTextNode(text, container);
862
+ }
863
+ });
864
+
865
+ var builder = base.extend.builder = new LayoutBuilder();
866
+
867
+ /**
868
+ * This will build a JSON layout.
869
+ *
870
+ * @param {object} obj
871
+ * @param {object} [container]
872
+ * @param {object} [parent]
873
+ * @return {object}
874
+ */
875
+ base.extend.buildLayout = function(obj, container, parent)
876
+ {
877
+ builder.build(obj, container, parent);
878
+ };
879
+ })();