@base-framework/base 2.6.1 → 2.6.3

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 (248) hide show
  1. package/README.md +1 -0
  2. package/dist/base.js +1 -0
  3. package/package.json +30 -26
  4. package/.jshintrc +0 -3
  5. package/base.js +0 -41
  6. package/base.min.js +0 -1
  7. package/core.js +0 -1
  8. package/data-tracker.js +0 -351
  9. package/es5/base.js +0 -2968
  10. package/es5/modules/ajax.js +0 -663
  11. package/es5/modules/animation.js +0 -188
  12. package/es5/modules/animations.js +0 -1080
  13. package/es5/modules/atom.js +0 -65
  14. package/es5/modules/component.js +0 -1310
  15. package/es5/modules/data-binder.js +0 -1131
  16. package/es5/modules/data.js +0 -1808
  17. package/es5/modules/date.js +0 -525
  18. package/es5/modules/form-validator.js +0 -324
  19. package/es5/modules/history.js +0 -126
  20. package/es5/modules/html-builder.js +0 -461
  21. package/es5/modules/layout.js +0 -1679
  22. package/es5/modules/mouse.js +0 -124
  23. package/es5/modules/nav-link.js +0 -123
  24. package/es5/modules/olderversions/animations-ease.js +0 -1095
  25. package/es5/modules/olderversions/animations-update.js +0 -1048
  26. package/es5/modules/olderversions/base-animations.js +0 -636
  27. package/es5/modules/olderversions/base-component-class.js +0 -100
  28. package/es5/modules/olderversions/base-data-binder-1.js +0 -407
  29. package/es5/modules/olderversions/base-data-binder-class.js +0 -358
  30. package/es5/modules/olderversions/base-layout-parser-class.js +0 -172
  31. package/es5/modules/olderversions/base-mode-1.js +0 -777
  32. package/es5/modules/olderversions/base-model-class.js +0 -585
  33. package/es5/modules/olderversions/data-binder/element-binding/base-data-binder-class.js +0 -358
  34. package/es5/modules/olderversions/data-binder/element-binding/base-model-class.js +0 -585
  35. package/es5/modules/olderversions/data-binder/model-binding/base-data-binder-class.js +0 -353
  36. package/es5/modules/olderversions/data-binder/model-binding/base-model-class.js +0 -604
  37. package/es5/modules/olderversions/data-binder-update-watcher.js +0 -640
  38. package/es5/modules/olderversions/data-tracker.js +0 -187
  39. package/es5/modules/olderversions/event-update.js +0 -666
  40. package/es5/modules/olderversions/nav-link.js +0 -119
  41. package/es5/modules/olderversions/router-with-templates-1.js +0 -785
  42. package/es5/modules/olderversions/router-with-templates.js +0 -701
  43. package/es5/modules/prototypes/ajax.js +0 -657
  44. package/es5/modules/prototypes/atom.js +0 -65
  45. package/es5/modules/prototypes/component.js +0 -972
  46. package/es5/modules/prototypes/data-binder.js +0 -1089
  47. package/es5/modules/prototypes/data.js +0 -1290
  48. package/es5/modules/prototypes/html-builder.js +0 -414
  49. package/es5/modules/prototypes/layout.js +0 -879
  50. package/es5/modules/router.js +0 -1680
  51. package/es5/modules/state.js +0 -274
  52. package/es6/.jshintrc +0 -3
  53. package/es6/base.js +0 -41
  54. package/es6/core.js +0 -1
  55. package/es6/data-tracker.js +0 -351
  56. package/es6/events.js +0 -602
  57. package/es6/legacy/es5/base.js +0 -2968
  58. package/es6/legacy/es5/modules/ajax.js +0 -663
  59. package/es6/legacy/es5/modules/animation.js +0 -188
  60. package/es6/legacy/es5/modules/animations.js +0 -1080
  61. package/es6/legacy/es5/modules/atom.js +0 -65
  62. package/es6/legacy/es5/modules/component.js +0 -1310
  63. package/es6/legacy/es5/modules/data-binder.js +0 -1131
  64. package/es6/legacy/es5/modules/data.js +0 -1808
  65. package/es6/legacy/es5/modules/date.js +0 -525
  66. package/es6/legacy/es5/modules/form-validator.js +0 -324
  67. package/es6/legacy/es5/modules/history.js +0 -126
  68. package/es6/legacy/es5/modules/html-builder.js +0 -461
  69. package/es6/legacy/es5/modules/layout.js +0 -1679
  70. package/es6/legacy/es5/modules/mouse.js +0 -124
  71. package/es6/legacy/es5/modules/nav-link.js +0 -123
  72. package/es6/legacy/es5/modules/olderversions/animations-ease.js +0 -1095
  73. package/es6/legacy/es5/modules/olderversions/animations-update.js +0 -1048
  74. package/es6/legacy/es5/modules/olderversions/base-animations.js +0 -636
  75. package/es6/legacy/es5/modules/olderversions/base-component-class.js +0 -100
  76. package/es6/legacy/es5/modules/olderversions/base-data-binder-1.js +0 -407
  77. package/es6/legacy/es5/modules/olderversions/base-data-binder-class.js +0 -358
  78. package/es6/legacy/es5/modules/olderversions/base-layout-parser-class.js +0 -172
  79. package/es6/legacy/es5/modules/olderversions/base-mode-1.js +0 -777
  80. package/es6/legacy/es5/modules/olderversions/base-model-class.js +0 -585
  81. package/es6/legacy/es5/modules/olderversions/data-binder/element-binding/base-data-binder-class.js +0 -358
  82. package/es6/legacy/es5/modules/olderversions/data-binder/element-binding/base-model-class.js +0 -585
  83. package/es6/legacy/es5/modules/olderversions/data-binder/model-binding/base-data-binder-class.js +0 -353
  84. package/es6/legacy/es5/modules/olderversions/data-binder/model-binding/base-model-class.js +0 -604
  85. package/es6/legacy/es5/modules/olderversions/data-binder-update-watcher.js +0 -640
  86. package/es6/legacy/es5/modules/olderversions/data-tracker.js +0 -187
  87. package/es6/legacy/es5/modules/olderversions/event-update.js +0 -666
  88. package/es6/legacy/es5/modules/olderversions/nav-link.js +0 -119
  89. package/es6/legacy/es5/modules/olderversions/router-with-templates-1.js +0 -785
  90. package/es6/legacy/es5/modules/olderversions/router-with-templates.js +0 -701
  91. package/es6/legacy/es5/modules/prototypes/ajax.js +0 -657
  92. package/es6/legacy/es5/modules/prototypes/atom.js +0 -65
  93. package/es6/legacy/es5/modules/prototypes/component.js +0 -972
  94. package/es6/legacy/es5/modules/prototypes/data-binder.js +0 -1089
  95. package/es6/legacy/es5/modules/prototypes/data.js +0 -1290
  96. package/es6/legacy/es5/modules/prototypes/html-builder.js +0 -414
  97. package/es6/legacy/es5/modules/prototypes/layout.js +0 -879
  98. package/es6/legacy/es5/modules/router.js +0 -1680
  99. package/es6/legacy/es5/modules/state.js +0 -274
  100. package/es6/main.js +0 -1331
  101. package/es6/modules/ajax/ajax.js +0 -514
  102. package/es6/modules/animation/animation.js +0 -236
  103. package/es6/modules/animations/animation-controller.js +0 -231
  104. package/es6/modules/animations/animation.js +0 -64
  105. package/es6/modules/animations/attr-movement.js +0 -66
  106. package/es6/modules/animations/css-movement.js +0 -170
  107. package/es6/modules/animations/movement.js +0 -131
  108. package/es6/modules/animations/value.js +0 -187
  109. package/es6/modules/atom/atom.js +0 -54
  110. package/es6/modules/component/component.js +0 -230
  111. package/es6/modules/component/event-helper.js +0 -119
  112. package/es6/modules/component/jot.js +0 -144
  113. package/es6/modules/component/state-helper.js +0 -262
  114. package/es6/modules/component/unit.js +0 -551
  115. package/es6/modules/data/attrs.js +0 -40
  116. package/es6/modules/data/basic-data.js +0 -500
  117. package/es6/modules/data/data-utils.js +0 -29
  118. package/es6/modules/data/data.js +0 -3
  119. package/es6/modules/data/deep-data.js +0 -541
  120. package/es6/modules/data/model-service.js +0 -528
  121. package/es6/modules/data/model.js +0 -133
  122. package/es6/modules/data/simple-data.js +0 -33
  123. package/es6/modules/data-binder/connection-tracker.js +0 -113
  124. package/es6/modules/data-binder/connection.js +0 -16
  125. package/es6/modules/data-binder/data-binder.js +0 -352
  126. package/es6/modules/data-binder/data-pub-sub.js +0 -141
  127. package/es6/modules/data-binder/data-source.js +0 -56
  128. package/es6/modules/data-binder/element-source.js +0 -219
  129. package/es6/modules/data-binder/one-way-connection.js +0 -46
  130. package/es6/modules/data-binder/one-way-source.js +0 -43
  131. package/es6/modules/data-binder/source.js +0 -36
  132. package/es6/modules/data-binder/two-way-connection.js +0 -75
  133. package/es6/modules/data-binder/two-way-source.js +0 -41
  134. package/es6/modules/date/date.js +0 -544
  135. package/es6/modules/history/history.js +0 -89
  136. package/es6/modules/html-builder/html-builder.js +0 -434
  137. package/es6/modules/import/import.js +0 -390
  138. package/es6/modules/layout/layout-builder.js +0 -1269
  139. package/es6/modules/layout/layout-parser.js +0 -134
  140. package/es6/modules/layout/watcher-helper.js +0 -282
  141. package/es6/modules/mouse/mouse.js +0 -114
  142. package/es6/modules/router/component-helper.js +0 -163
  143. package/es6/modules/router/history-controller.js +0 -216
  144. package/es6/modules/router/nav-link.js +0 -124
  145. package/es6/modules/router/route.js +0 -401
  146. package/es6/modules/router/router.js +0 -789
  147. package/es6/modules/router/utils.js +0 -31
  148. package/es6/modules/state/state-target.js +0 -91
  149. package/es6/modules/state/state.js +0 -171
  150. package/es6/package-lock.json +0 -13
  151. package/es6/package.json +0 -28
  152. package/es6/shared/objects.js +0 -99
  153. package/events.js +0 -602
  154. package/legacy/es5/base.js +0 -2968
  155. package/legacy/es5/modules/ajax.js +0 -663
  156. package/legacy/es5/modules/animation.js +0 -188
  157. package/legacy/es5/modules/animations.js +0 -1080
  158. package/legacy/es5/modules/atom.js +0 -65
  159. package/legacy/es5/modules/component.js +0 -1310
  160. package/legacy/es5/modules/data-binder.js +0 -1131
  161. package/legacy/es5/modules/data.js +0 -1808
  162. package/legacy/es5/modules/date.js +0 -525
  163. package/legacy/es5/modules/form-validator.js +0 -324
  164. package/legacy/es5/modules/history.js +0 -126
  165. package/legacy/es5/modules/html-builder.js +0 -461
  166. package/legacy/es5/modules/layout.js +0 -1679
  167. package/legacy/es5/modules/mouse.js +0 -124
  168. package/legacy/es5/modules/nav-link.js +0 -123
  169. package/legacy/es5/modules/olderversions/animations-ease.js +0 -1095
  170. package/legacy/es5/modules/olderversions/animations-update.js +0 -1048
  171. package/legacy/es5/modules/olderversions/base-animations.js +0 -636
  172. package/legacy/es5/modules/olderversions/base-component-class.js +0 -100
  173. package/legacy/es5/modules/olderversions/base-data-binder-1.js +0 -407
  174. package/legacy/es5/modules/olderversions/base-data-binder-class.js +0 -358
  175. package/legacy/es5/modules/olderversions/base-layout-parser-class.js +0 -172
  176. package/legacy/es5/modules/olderversions/base-mode-1.js +0 -777
  177. package/legacy/es5/modules/olderversions/base-model-class.js +0 -585
  178. package/legacy/es5/modules/olderversions/data-binder/element-binding/base-data-binder-class.js +0 -358
  179. package/legacy/es5/modules/olderversions/data-binder/element-binding/base-model-class.js +0 -585
  180. package/legacy/es5/modules/olderversions/data-binder/model-binding/base-data-binder-class.js +0 -353
  181. package/legacy/es5/modules/olderversions/data-binder/model-binding/base-model-class.js +0 -604
  182. package/legacy/es5/modules/olderversions/data-binder-update-watcher.js +0 -640
  183. package/legacy/es5/modules/olderversions/data-tracker.js +0 -187
  184. package/legacy/es5/modules/olderversions/event-update.js +0 -666
  185. package/legacy/es5/modules/olderversions/nav-link.js +0 -119
  186. package/legacy/es5/modules/olderversions/router-with-templates-1.js +0 -785
  187. package/legacy/es5/modules/olderversions/router-with-templates.js +0 -701
  188. package/legacy/es5/modules/prototypes/ajax.js +0 -657
  189. package/legacy/es5/modules/prototypes/atom.js +0 -65
  190. package/legacy/es5/modules/prototypes/component.js +0 -972
  191. package/legacy/es5/modules/prototypes/data-binder.js +0 -1089
  192. package/legacy/es5/modules/prototypes/data.js +0 -1290
  193. package/legacy/es5/modules/prototypes/html-builder.js +0 -414
  194. package/legacy/es5/modules/prototypes/layout.js +0 -879
  195. package/legacy/es5/modules/router.js +0 -1680
  196. package/legacy/es5/modules/state.js +0 -274
  197. package/main.js +0 -1331
  198. package/modules/ajax/ajax.js +0 -514
  199. package/modules/animation/animation.js +0 -236
  200. package/modules/animations/animation-controller.js +0 -231
  201. package/modules/animations/animation.js +0 -64
  202. package/modules/animations/attr-movement.js +0 -66
  203. package/modules/animations/css-movement.js +0 -170
  204. package/modules/animations/movement.js +0 -131
  205. package/modules/animations/value.js +0 -187
  206. package/modules/atom/atom.js +0 -54
  207. package/modules/component/component.js +0 -230
  208. package/modules/component/event-helper.js +0 -119
  209. package/modules/component/jot.js +0 -144
  210. package/modules/component/state-helper.js +0 -262
  211. package/modules/component/unit.js +0 -551
  212. package/modules/data/attrs.js +0 -40
  213. package/modules/data/basic-data.js +0 -500
  214. package/modules/data/data-utils.js +0 -29
  215. package/modules/data/data.js +0 -3
  216. package/modules/data/deep-data.js +0 -541
  217. package/modules/data/model-service.js +0 -528
  218. package/modules/data/model.js +0 -133
  219. package/modules/data/simple-data.js +0 -33
  220. package/modules/data-binder/connection-tracker.js +0 -113
  221. package/modules/data-binder/connection.js +0 -16
  222. package/modules/data-binder/data-binder.js +0 -352
  223. package/modules/data-binder/data-pub-sub.js +0 -141
  224. package/modules/data-binder/data-source.js +0 -56
  225. package/modules/data-binder/element-source.js +0 -219
  226. package/modules/data-binder/one-way-connection.js +0 -46
  227. package/modules/data-binder/one-way-source.js +0 -43
  228. package/modules/data-binder/source.js +0 -36
  229. package/modules/data-binder/two-way-connection.js +0 -75
  230. package/modules/data-binder/two-way-source.js +0 -41
  231. package/modules/date/date.js +0 -544
  232. package/modules/history/history.js +0 -89
  233. package/modules/html-builder/html-builder.js +0 -434
  234. package/modules/import/import.js +0 -390
  235. package/modules/layout/layout-builder.js +0 -1269
  236. package/modules/layout/layout-parser.js +0 -134
  237. package/modules/layout/watcher-helper.js +0 -282
  238. package/modules/mouse/mouse.js +0 -114
  239. package/modules/router/component-helper.js +0 -163
  240. package/modules/router/history-controller.js +0 -216
  241. package/modules/router/nav-link.js +0 -124
  242. package/modules/router/route.js +0 -401
  243. package/modules/router/router.js +0 -789
  244. package/modules/router/utils.js +0 -31
  245. package/modules/state/state-target.js +0 -91
  246. package/modules/state/state.js +0 -171
  247. package/shared/objects.js +0 -99
  248. package/update +0 -16
@@ -1,879 +0,0 @@
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
- })();