@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,1310 @@
1
+ /* base framework module */
2
+ (function(global)
3
+ {
4
+ "use strict";
5
+
6
+ /**
7
+ * EventHelper
8
+ *
9
+ * This will create an event object to make
10
+ * adding and removing events easier.
11
+ * @class
12
+ */
13
+ var EventHelper = base.Class.extend(
14
+ {
15
+ /**
16
+ * @constructor
17
+ */
18
+ constructor: function()
19
+ {
20
+ this.events = [];
21
+ },
22
+
23
+ /**
24
+ * This will add an array of events.
25
+ *
26
+ * @param {array} events
27
+ */
28
+ addEvents: function(events)
29
+ {
30
+ if(events.length < 1)
31
+ {
32
+ return false;
33
+ }
34
+
35
+ for(var i = 0, length = events.length; i < length; i++)
36
+ {
37
+ var event = events[i];
38
+ this.on(event[0], event[1], event[2], event[3]);
39
+ }
40
+ },
41
+
42
+ /**
43
+ * This will add an event.
44
+ *
45
+ * @param {string} event
46
+ * @param {object} obj
47
+ * @param {function} callBack
48
+ * @param {boolean} capture
49
+ */
50
+ on: function(event, obj, callBack, capture)
51
+ {
52
+ base.on(event, obj, callBack, capture);
53
+
54
+ this.events.push({
55
+ event: event,
56
+ obj: obj,
57
+ callBack: callBack,
58
+ capture: capture
59
+ });
60
+ },
61
+
62
+ /**
63
+ * This will remove an event.
64
+ *
65
+ * @param {string} event
66
+ * @param {object} obj
67
+ * @param {function} callBack
68
+ * @param {boolean} capture
69
+ */
70
+ off: function(event, obj, callBack, capture)
71
+ {
72
+ base.off(event, obj, callBack, capture);
73
+
74
+ var option,
75
+ events = this.events;
76
+ for(var i = 0, length = events.length; i < length; i++)
77
+ {
78
+ option = events[i];
79
+ if(option.event === event && option.obj === obj)
80
+ {
81
+ events.splice(i, 1);
82
+ break;
83
+ }
84
+ }
85
+ },
86
+
87
+ /**
88
+ * This will set all events.
89
+ */
90
+ set: function()
91
+ {
92
+ var event,
93
+ events = this.events;
94
+ for(var i = 0, length = events.length; i < length; i++)
95
+ {
96
+ event = events[i];
97
+ base.on(event.event, event.obj, event.callBack, event.capture);
98
+ }
99
+ },
100
+
101
+ unset: function()
102
+ {
103
+ var event,
104
+ events = this.events;
105
+ for(var i = 0, length = events.length; i < length; i++)
106
+ {
107
+ event = events[i];
108
+ base.off(event.event, event.obj, event.callBack, event.capture);
109
+ }
110
+ },
111
+
112
+ /**
113
+ * This will reset the events.
114
+ */
115
+ reset: function()
116
+ {
117
+ this.unset();
118
+ this.events = [];
119
+ }
120
+ });
121
+
122
+ base.extend.EventHelper = EventHelper;
123
+
124
+ /* this will register the component system to the
125
+ data tracker to remove components that have been
126
+ nested in layouts. */
127
+ base.DataTracker.addType('components', function(data)
128
+ {
129
+ if(!data)
130
+ {
131
+ return false;
132
+ }
133
+
134
+ var component = data.component;
135
+ if(component && component.rendered === true)
136
+ {
137
+ component.prepareDestroy();
138
+ }
139
+ });
140
+
141
+ /**
142
+ * StateHelper
143
+ *
144
+ * This is a helper to manage component states.
145
+ */
146
+ var StateHelper = base.Class.extend(
147
+ {
148
+ /**
149
+ * @constructor
150
+ * @param {object} state
151
+ * @param {object} states
152
+ */
153
+ constructor: function(state, states)
154
+ {
155
+ this.remoteStates = [];
156
+
157
+ var actions = this.convertStates(states);
158
+ this.addStatesToTarget(state, actions);
159
+ },
160
+
161
+ /**
162
+ * This will add states to a state.
163
+ *
164
+ * @param {object} state
165
+ * @param {object} states
166
+ */
167
+ addStates: function(state, states)
168
+ {
169
+ var actions = this.convertStates(states);
170
+ this.addStatesToTarget(state, actions);
171
+ },
172
+
173
+ /**
174
+ * This will create a state object.
175
+ *
176
+ * @param {string} action
177
+ * @param {*} state
178
+ * @param {function} callBack
179
+ * @param {string} [targetId]
180
+ * @return {object}
181
+ */
182
+ createState: function(action, state, callBack, targetId)
183
+ {
184
+ return {
185
+ action: action,
186
+ state: state,
187
+ callBack: callBack,
188
+ targetId: targetId,
189
+ token: null
190
+ };
191
+ },
192
+
193
+ /**
194
+ * This will convert an action object to a state array.
195
+ *
196
+ * @protected
197
+ * @param {object} action
198
+ * @return {array}
199
+ */
200
+ convertStates: function(action)
201
+ {
202
+ var actions = [];
203
+ for(var prop in action)
204
+ {
205
+ if(action.hasOwnProperty(prop) === false)
206
+ {
207
+ continue;
208
+ }
209
+ else if(prop === 'remotes')
210
+ {
211
+ this.setupRemoteStates(action[prop], actions);
212
+ continue;
213
+ }
214
+
215
+ var targetId = null,
216
+ callBack = null,
217
+ state = action[prop];
218
+ if(state && typeof state === 'object')
219
+ {
220
+ callBack = state.callBack;
221
+ targetId = state.id || state.targetId;
222
+ state = state.state;
223
+ }
224
+
225
+ actions.push(this.createState(
226
+ prop,
227
+ state,
228
+ callBack,
229
+ targetId
230
+ ));
231
+ }
232
+ return actions;
233
+ },
234
+
235
+ setupRemoteStates: function(remotes, actions)
236
+ {
237
+ var remote;
238
+ for(var i = 0, length = remotes.length; i < length; i++)
239
+ {
240
+ remote = remotes[i];
241
+ if(!remote)
242
+ {
243
+ continue;
244
+ }
245
+
246
+ for(var prop in remote)
247
+ {
248
+ if(remote.hasOwnProperty(prop) === false || prop === 'id')
249
+ {
250
+ continue;
251
+ }
252
+
253
+ var callBack = null,
254
+ value = remote[prop],
255
+ state = (value !== null)? value : undefined;
256
+ if(state && typeof state === 'object')
257
+ {
258
+ callBack = state.callBack;
259
+ state = state.state;
260
+ }
261
+
262
+ actions.push(this.createState(
263
+ prop,
264
+ state,
265
+ callBack,
266
+ remote.id
267
+ ));
268
+ }
269
+ }
270
+ },
271
+
272
+ /**
273
+ * This will remove remote states.
274
+ */
275
+ removeRemoteStates: function()
276
+ {
277
+ var remoteStates = this.remoteStates;
278
+ if(remoteStates)
279
+ {
280
+ this.removeActions(remoteStates);
281
+ }
282
+ },
283
+
284
+ /**
285
+ * This will remove the actions.
286
+ *
287
+ * @param {array} actions
288
+ */
289
+ removeActions: function(actions)
290
+ {
291
+ if(actions.length < 1)
292
+ {
293
+ return false;
294
+ }
295
+
296
+ var states = base.state;
297
+ for(var i = 0, length = actions.length; i < length; i++)
298
+ {
299
+ var action = actions[i];
300
+ states.remove(action.targetId, action.action, action.token);
301
+ }
302
+ },
303
+
304
+ /**
305
+ * This will restore a state.
306
+ *
307
+ * @param {object} state
308
+ */
309
+ restore: function(state)
310
+ {
311
+ state.restore();
312
+
313
+ var remotes = this.remoteStates;
314
+ if(!remotes)
315
+ {
316
+ return;
317
+ }
318
+
319
+ for(var i = 0, length = remotes.length; i < length; i++)
320
+ {
321
+ var action = remotes[i];
322
+ action.token = this.bindRemoteState(state, action.action, action.targetId);
323
+ }
324
+ },
325
+
326
+ /**
327
+ * This will setup a two way bind to a remote state.
328
+ *
329
+ * @param {object} target
330
+ * @param {string} actionEvent
331
+ * @param {string} remoteTargetId
332
+ * @return {string}
333
+ */
334
+ bindRemoteState: function(target, actionEvent, remoteTargetId)
335
+ {
336
+ var remoteTarget = base.state.getTarget(remoteTargetId);
337
+
338
+ return target.link(remoteTarget, actionEvent);
339
+ },
340
+
341
+ /**
342
+ * This will add the states to the target.
343
+ *
344
+ * @protected
345
+ * @param {object} state
346
+ * @param {array} actions
347
+ */
348
+ addStatesToTarget: function(state, actions)
349
+ {
350
+ var remotes = this.remoteStates;
351
+
352
+ for(var i = 0, length = actions.length; i < length; i++)
353
+ {
354
+ var action = actions[i],
355
+ token = this.addAction(state, action);
356
+
357
+ if(action.targetId)
358
+ {
359
+ action.token = token;
360
+ remotes.push(action);
361
+ }
362
+ }
363
+
364
+ if(remotes.length < 1)
365
+ {
366
+ this.remoteStates = null;
367
+ }
368
+ },
369
+
370
+ /**
371
+ * This will add an action.
372
+ *
373
+ * @param {object} target
374
+ * @param {object} action
375
+ */
376
+ addAction: function(target, action)
377
+ {
378
+ var token,
379
+ actionEvent = action.action;
380
+
381
+ /* this will check to select the remote target if set */
382
+ var targetId = action.targetId;
383
+ if(targetId)
384
+ {
385
+ token = this.bindRemoteState(target, actionEvent, targetId);
386
+ }
387
+
388
+ if(typeof action.state !== 'undefined')
389
+ {
390
+ target.addAction(actionEvent, action.state);
391
+ }
392
+
393
+ var callBack = action.callBack;
394
+ if(typeof callBack === 'function')
395
+ {
396
+ target.on(actionEvent, callBack);
397
+ }
398
+
399
+ return token;
400
+ }
401
+ });
402
+
403
+ var builder = base.builder;
404
+
405
+ /**
406
+ * Unit
407
+ *
408
+ * @class
409
+ *
410
+ * This will allow units to be extended
411
+ * from a single factory.
412
+ *
413
+ * @example
414
+ * var Alert = base.Unit.extend(
415
+ * {
416
+ * constructor: function(props)
417
+ * {
418
+ * // this will setup the component id
419
+ * base.Component.call(this, props);
420
+ * },
421
+ *
422
+ * render: function()
423
+ * {
424
+ * return {
425
+ *
426
+ * };
427
+ * }
428
+ * });
429
+ */
430
+ var Unit = base.Class.extend(
431
+ {
432
+ /**
433
+ * @constructor
434
+ * @param {object} [props]
435
+ */
436
+ constructor: function(props)
437
+ {
438
+ this.init();
439
+ this.setupProps(props);
440
+ this.onCreated();
441
+
442
+ this.rendered = false;
443
+ this.container = null;
444
+ },
445
+
446
+ /**
447
+ * @param {bool} isUnit
448
+ */
449
+ isUnit: true,
450
+
451
+ /**
452
+ * This will setup the unit number and unique
453
+ * instance id for the unit elements.
454
+ * @protected
455
+ */
456
+ init: function()
457
+ {
458
+ var constructor = this.constructor;
459
+ this.number = (typeof constructor.number === 'undefined')? constructor.number = 0 : (++constructor.number);
460
+
461
+ var name = this.overrideTypeId || this._typeId;
462
+ this.id = name + this.number;
463
+ },
464
+
465
+ /**
466
+ * This will setup the unit props.
467
+ *
468
+ * @param {object} [props]
469
+ */
470
+ setupProps: function(props)
471
+ {
472
+ if(!props || typeof props !== 'object')
473
+ {
474
+ return false;
475
+ }
476
+
477
+ for(var prop in props)
478
+ {
479
+ if(props.hasOwnProperty(prop))
480
+ {
481
+ this[prop] = props[prop];
482
+ }
483
+ }
484
+ },
485
+
486
+ /**
487
+ * This will get the parent context.
488
+ *
489
+ * @returns {object|null}
490
+ */
491
+ getParentContext: function()
492
+ {
493
+ if(!this.parent)
494
+ {
495
+ return null;
496
+ }
497
+
498
+ return this.parent.getContext();
499
+ },
500
+
501
+ /**
502
+ * This will set up the context.
503
+ *
504
+ * @returns {void}
505
+ */
506
+ setupContext: function()
507
+ {
508
+ var parentContext = this.getParentContext();
509
+ var context = this.setContext(parentContext);
510
+ if(context)
511
+ {
512
+ this.context = context;
513
+ return;
514
+ }
515
+
516
+ this.context = parentContext;
517
+ this.setupAddingContext();
518
+ },
519
+
520
+ /**
521
+ * This will set up the adding context.
522
+ *
523
+ * @returns {void}
524
+ */
525
+ setupAddingContext: function()
526
+ {
527
+ var parentContext = this.context;
528
+ var context = this.addContext(parentContext);
529
+ if(!context)
530
+ {
531
+ return;
532
+ }
533
+
534
+ var branchName = context[0];
535
+ if(!branchName)
536
+ {
537
+ return;
538
+ }
539
+
540
+ this.addingContext = true;
541
+ this.contextBranchName = branchName;
542
+ this.addContextBranch(branchName, context[1]);
543
+ },
544
+
545
+ /**
546
+ * This will add a branch to the context.
547
+ *
548
+ * @param {string} branchName
549
+ * @param {mixed} value
550
+ */
551
+ addContextBranch: function(branchName, value)
552
+ {
553
+ this.context = this.context || {};
554
+ this.context[branchName] = value;
555
+ },
556
+
557
+ /**
558
+ * This will set the component context.
559
+ *
560
+ * @param {object|null} context
561
+ * @returns {object|null}
562
+ */
563
+ setContext: function(context)
564
+ {
565
+ return null;
566
+ },
567
+
568
+ /**
569
+ * This will add context to the parent context.
570
+ *
571
+ * @param {object|null} context
572
+ * @return {array|null}
573
+ */
574
+ addContext: function(context)
575
+ {
576
+ return null;
577
+ },
578
+
579
+ /**
580
+ * This will remove the added context from the parent.
581
+ *
582
+ * @returns {void}
583
+ */
584
+ removeContext: function()
585
+ {
586
+ if(!this.addingContext)
587
+ {
588
+ return;
589
+ }
590
+
591
+ this.removeContextBranch(this.contextBranchName);
592
+ },
593
+
594
+ /**
595
+ * This will remove a context branch.
596
+ *
597
+ * @param {string} branch
598
+ * @returns {void}
599
+ */
600
+ removeContextBranch: function(branch)
601
+ {
602
+ if(!branch)
603
+ {
604
+ return;
605
+ }
606
+
607
+ delete this.context[branch];
608
+ },
609
+
610
+ /**
611
+ * This will get the context.
612
+ *
613
+ * @returns {object|null}
614
+ */
615
+ getContext: function()
616
+ {
617
+ return this.context;
618
+ },
619
+
620
+ /**
621
+ * override this to do something when created.
622
+ */
623
+ onCreated: function()
624
+ {
625
+
626
+ },
627
+
628
+ /**
629
+ * This will render the unit.
630
+ *
631
+ * @return {object}
632
+ */
633
+ render: function()
634
+ {
635
+ return {
636
+
637
+ };
638
+ },
639
+
640
+ /**
641
+ * This will cache the layout panel and set the main id.
642
+ * @param {object} layout
643
+ * @return {object}
644
+ */
645
+ _cacheRoot: function(layout)
646
+ {
647
+ if(!layout)
648
+ {
649
+ return layout;
650
+ }
651
+
652
+ if(!layout.id)
653
+ {
654
+ layout.id = this.getId();
655
+ }
656
+
657
+ layout.cache = 'panel';
658
+ return layout;
659
+ },
660
+
661
+ /**
662
+ * This will create the unit layout.
663
+ * @protected
664
+ * @return {object}
665
+ */
666
+ _createLayout: function()
667
+ {
668
+ if(this.persist)
669
+ {
670
+ return this._layout || (this._layout = this.render());
671
+ }
672
+
673
+ return this.render();
674
+ },
675
+
676
+ /**
677
+ * This will prepare the layout.
678
+ *
679
+ * @protected
680
+ * @return {object}
681
+ */
682
+ prepareLayout: function()
683
+ {
684
+ var layout = this._createLayout();
685
+ return this._cacheRoot(layout);
686
+ },
687
+
688
+ /**
689
+ * This will build the layout.
690
+ * @protected
691
+ */
692
+ buildLayout: function()
693
+ {
694
+ var layout = this.prepareLayout();
695
+ this.build(layout, this.container);
696
+
697
+ base.DataTracker.add(this.panel, 'components',
698
+ {
699
+ component: this
700
+ });
701
+
702
+ this.rendered = true;
703
+ },
704
+
705
+ /**
706
+ * This will build a layout.
707
+ *
708
+ * @param {object} layout
709
+ * @param {object} container
710
+ * @return {object}
711
+ */
712
+ build: function(layout, container)
713
+ {
714
+ return builder.build(layout, container, this);
715
+ },
716
+
717
+ /**
718
+ * This will prepend layout to a container.
719
+ *
720
+ * @param {object} layout
721
+ * @param {object} container
722
+ * @param {object} [optionalNode]
723
+ */
724
+ prepend: function(layout, container, optionalNode)
725
+ {
726
+ var frag = this.build(layout, null);
727
+ builder.prepend(container, frag, optionalNode);
728
+ },
729
+
730
+ /**
731
+ * This will rebuild a layout.
732
+ *
733
+ * @param {object} layout
734
+ * @param {object} container
735
+ * @return {object}
736
+ */
737
+ rebuild: function(layout, container)
738
+ {
739
+ return builder.rebuild(container, layout, this);
740
+ },
741
+
742
+ /**
743
+ * This will render the content on condition of a property.
744
+ *
745
+ * @param {mixed} prop
746
+ * @param {mixed} content
747
+ * @returns {object}
748
+ */
749
+ if: function(prop, content)
750
+ {
751
+ return (!prop)? null : (content || prop);
752
+ },
753
+
754
+ /**
755
+ * This will map an array to children elements.
756
+ *
757
+ * @param {array} items
758
+ * @param {function} callBack
759
+ * @returns {array}
760
+ */
761
+ map: function(items, callBack)
762
+ {
763
+ var children = [];
764
+ if(!items || items.length < 1)
765
+ {
766
+ return children;
767
+ }
768
+
769
+ for(var i = 0, length = items.length; i < length; i++)
770
+ {
771
+ var item = callBack(items[i], i);
772
+ children.push(item);
773
+ }
774
+ return children;
775
+ },
776
+
777
+ /**
778
+ * This will remove children from an element.
779
+ *
780
+ * @param {object} layout
781
+ * @param {object} container
782
+ * @return {object}
783
+ */
784
+ removeAll: function(ele)
785
+ {
786
+ return builder.removeAll(ele);
787
+ },
788
+
789
+ /**
790
+ * This will cache an element when its created by
791
+ * saving a reference to it as a property on the
792
+ * unit.
793
+ *
794
+ * @param {string} propName The name to use as
795
+ * the reference.
796
+ * @param {object} layout
797
+ * @param {function} [callBack]
798
+ * @return {object}
799
+ */
800
+ cache: function(propName, layout, callBack)
801
+ {
802
+ if(!layout || typeof layout !== 'object')
803
+ {
804
+ return false;
805
+ }
806
+
807
+ if(layout.isUnit === true)
808
+ {
809
+ layout =
810
+ {
811
+ component: layout
812
+ };
813
+ }
814
+
815
+ var self = this;
816
+ layout.onCreated = function(element)
817
+ {
818
+ self[propName] = element;
819
+
820
+ if(typeof callBack === 'function')
821
+ {
822
+ callBack(element);
823
+ }
824
+ };
825
+ return layout;
826
+ },
827
+
828
+ /**
829
+ * This will get an id of the unit or the full
830
+ * id that has the unit id prepended to the
831
+ * requested id.
832
+ *
833
+ * @param {string} [id]
834
+ * @return {string}
835
+ */
836
+ getId: function(id)
837
+ {
838
+ var mainId = this.id;
839
+ if(typeof id === 'string')
840
+ {
841
+ mainId += '-' + id;
842
+ }
843
+ return mainId;
844
+ },
845
+
846
+ /**
847
+ * This will initialize the unit.
848
+ * @protected
849
+ */
850
+ initialize: function()
851
+ {
852
+ this.setupContext();
853
+ this.beforeSetup();
854
+ this.buildLayout();
855
+ this.afterSetup();
856
+ },
857
+
858
+ /**
859
+ * override this to do something before setup.
860
+ */
861
+ beforeSetup: function()
862
+ {
863
+
864
+ },
865
+
866
+ /**
867
+ * override this to do something after setup.
868
+ */
869
+ afterSetup: function()
870
+ {
871
+
872
+ },
873
+
874
+ /**
875
+ * This will setup and render the unit.
876
+ * @param {object} container
877
+ */
878
+ setup: function(container)
879
+ {
880
+ this.container = container;
881
+ this.initialize();
882
+ },
883
+
884
+ /**
885
+ * This will remove the unit.
886
+ * @protected
887
+ */
888
+ remove: function()
889
+ {
890
+ this.prepareDestroy();
891
+ this.removeContext();
892
+
893
+ var panel = this.panel || this.id;
894
+ builder.removeElement(panel);
895
+ },
896
+
897
+ /**
898
+ * This will prepare the unit to be destroyed.
899
+ */
900
+ prepareDestroy: function()
901
+ {
902
+ this.rendered = false;
903
+ this.beforeDestroy();
904
+ },
905
+
906
+ /**
907
+ * Override this to do something before destroy.
908
+ */
909
+ beforeDestroy: function()
910
+ {
911
+
912
+ },
913
+
914
+ /**
915
+ * This will destroy the unit.
916
+ */
917
+ destroy: function()
918
+ {
919
+ this.remove();
920
+ },
921
+
922
+ /**
923
+ * This will bind and element to data.
924
+ *
925
+ * @param {object} element
926
+ * @param {object} data
927
+ * @param {string} prop
928
+ * @param {function} filter
929
+ */
930
+ bindElement: function(element, data, prop, filter)
931
+ {
932
+ if(element)
933
+ {
934
+ base.DataBinder.bind(element, data, prop, filter);
935
+ }
936
+ }
937
+ });
938
+
939
+ var typeNumber = 0;
940
+
941
+ /**
942
+ * This will extend the parent unit to a child
943
+ * unit.
944
+ *
945
+ * @static
946
+ * @param {object} child
947
+ * @return {function}
948
+ */
949
+ Unit.extend = function(child)
950
+ {
951
+ if(!child)
952
+ {
953
+ return false;
954
+ }
955
+
956
+ var parent = this.prototype;
957
+
958
+ /* the child constructor must be set to set
959
+ the parent static methods on the child */
960
+ var constructor = child && child.constructor? child.constructor : false;
961
+ if(child.hasOwnProperty('constructor') === false)
962
+ {
963
+ constructor = function()
964
+ {
965
+ var args = base.listToArray(arguments);
966
+ parent.constructor.apply(this, args);
967
+ };
968
+ }
969
+
970
+ /* this will add the parent class to the
971
+ child class */
972
+ constructor.prototype = base.extendClass(parent, child);
973
+
974
+ /* this will assign a unique id to the type of
975
+ unit */
976
+ constructor.prototype._typeId = 'cp-' + (typeNumber++) + '-';
977
+
978
+ /* this will add the static methods from the parent to
979
+ the child constructor. could use assign but ie doesn't
980
+ support it */
981
+ //Object.assign(constructor, this);
982
+ base.extendObject(this, constructor);
983
+ return constructor;
984
+ };
985
+
986
+ /**
987
+ * Component
988
+ *
989
+ * @class
990
+ *
991
+ * This will allow components to be extended
992
+ * from a single factory.
993
+ *
994
+ * @example
995
+ * var QuickFlashPanel = base.Component.extend(
996
+ * {
997
+ * constructor: function(props)
998
+ * {
999
+ * // this will setup the component id
1000
+ * base.Component.call(this, props);
1001
+ * },
1002
+ *
1003
+ * render: function()
1004
+ * {
1005
+ * return {
1006
+ *
1007
+ * };
1008
+ * }
1009
+ * });
1010
+ */
1011
+ var Component = Unit.extend(
1012
+ {
1013
+ /**
1014
+ * @param {bool} isComponent
1015
+ */
1016
+ isComponent: true,
1017
+
1018
+ /**
1019
+ * This will initialize the component.
1020
+ * @protected
1021
+ */
1022
+ initialize: function()
1023
+ {
1024
+ this.setupContext();
1025
+ this.beforeSetup();
1026
+ this.addStates();
1027
+ this.buildLayout();
1028
+ this.addEvents();
1029
+ this.afterSetup();
1030
+ },
1031
+
1032
+ /* this will allow the component to override the
1033
+ state target id to add a custom id */
1034
+ /**
1035
+ * @member {string} [stateTargetId] // optional override of state id
1036
+ */
1037
+ stateTargetId: null,
1038
+
1039
+ /**
1040
+ * This will setup the state target.
1041
+ *
1042
+ * @protected
1043
+ * @param {string} [id]
1044
+ */
1045
+ setupStateTarget: function(id)
1046
+ {
1047
+ var targetId = id || this.stateTargetId || this.id;
1048
+ this.state = base.state.getTarget(targetId);
1049
+ },
1050
+
1051
+ /**
1052
+ * Override this to setup the component states.
1053
+ * @return {object}
1054
+ */
1055
+ setupStates: function()
1056
+ {
1057
+ /*
1058
+ return {
1059
+ action: 'state'
1060
+ };
1061
+
1062
+ or
1063
+
1064
+ return {
1065
+ action:
1066
+ {
1067
+ state: 'state',
1068
+ callBack: function(state, prevState)
1069
+ {
1070
+
1071
+ }
1072
+ }
1073
+ };*/
1074
+
1075
+ return {
1076
+
1077
+ };
1078
+ },
1079
+
1080
+ /**
1081
+ * This will add the states.
1082
+ * @protected
1083
+ */
1084
+ addStates: function()
1085
+ {
1086
+ /* this will check to restore previous a previous state if the
1087
+ component has been preserved. */
1088
+ var state = this.state;
1089
+ if(state)
1090
+ {
1091
+ this.stateHelper.restore(state);
1092
+ return;
1093
+ }
1094
+
1095
+ /* this will only setupa state manager if
1096
+ we have states */
1097
+ var states = this.setupStates();
1098
+ if(base.isEmpty(states))
1099
+ {
1100
+ return;
1101
+ }
1102
+
1103
+ this.setupStateTarget();
1104
+ this.stateHelper = new StateHelper(this.state, states);
1105
+ },
1106
+
1107
+ /**
1108
+ * This will remove the states.
1109
+ * @protected
1110
+ */
1111
+ removeStates: function()
1112
+ {
1113
+ var state = this.state;
1114
+ if(!state)
1115
+ {
1116
+ return false;
1117
+ }
1118
+
1119
+ this.stateHelper.removeRemoteStates();
1120
+ state.remove();
1121
+ },
1122
+
1123
+ /**
1124
+ * This will setup the event helper.
1125
+ *
1126
+ * @protected
1127
+ */
1128
+ setupEventHelper: function()
1129
+ {
1130
+ if(!this.events)
1131
+ {
1132
+ this.events = new EventHelper();
1133
+ }
1134
+ },
1135
+
1136
+ /**
1137
+ * This will setup the events.
1138
+ *
1139
+ * @protected
1140
+ * @return {array}
1141
+ */
1142
+ setupEvents: function()
1143
+ {
1144
+ return [
1145
+ //['action', element, function(e){}, false]
1146
+ ];
1147
+ },
1148
+
1149
+ /**
1150
+ * This will add the events.
1151
+ *
1152
+ * @protected
1153
+ */
1154
+ addEvents: function()
1155
+ {
1156
+ var events = this.setupEvents();
1157
+ if(events.length < 1)
1158
+ {
1159
+ return false;
1160
+ }
1161
+
1162
+ this.setupEventHelper();
1163
+ this.events.addEvents(events);
1164
+ },
1165
+
1166
+ /**
1167
+ * This will remove the events.
1168
+ * @protected
1169
+ */
1170
+ removeEvents: function()
1171
+ {
1172
+ var events = this.events;
1173
+ if(events)
1174
+ {
1175
+ events.reset();
1176
+ }
1177
+ },
1178
+
1179
+ /**
1180
+ * This will prepare the component to be destroyed.
1181
+ */
1182
+ prepareDestroy: function()
1183
+ {
1184
+ this.rendered = false;
1185
+ this.beforeDestroy();
1186
+ this.removeEvents();
1187
+ this.removeStates();
1188
+ this.removeContext();
1189
+
1190
+ if(this.data && this.persist === false)
1191
+ {
1192
+ this.data.unlink();
1193
+ }
1194
+ }
1195
+ });
1196
+
1197
+ /**
1198
+ * This will store the jot shorthand method alaises.
1199
+ */
1200
+ var JOT_SHORTHAND_METHODS =
1201
+ {
1202
+ created: 'onCreated',
1203
+ state: 'setupStates',
1204
+ events: 'setupEevents',
1205
+ before: 'beforeSetup',
1206
+ render: 'render',
1207
+ after: 'afterSetup',
1208
+ destroy: 'beforeDestroy'
1209
+ };
1210
+
1211
+ /**
1212
+ * This will get the jot method by value. If the method is an
1213
+ * object, it will be nested in a function.
1214
+ *
1215
+ * @param {object|function} value
1216
+ * @returns {function}
1217
+ */
1218
+ var getJotShorthandMethod = function(value)
1219
+ {
1220
+ var valueType = (typeof value);
1221
+ return (valueType === 'function')? value : function()
1222
+ {
1223
+ return value;
1224
+ };
1225
+ };
1226
+
1227
+ /**
1228
+ * This will create a jot component object that will be used
1229
+ * to create the jot component.
1230
+ *
1231
+ * @param {object} settings
1232
+ * @returns {object}
1233
+ */
1234
+ var JotComponent = function(settings)
1235
+ {
1236
+ var component = {};
1237
+ if(!settings)
1238
+ {
1239
+ return component;
1240
+ }
1241
+
1242
+ for(var prop in settings)
1243
+ {
1244
+ if(settings.hasOwnProperty(prop) === false)
1245
+ {
1246
+ continue;
1247
+ }
1248
+
1249
+ var value = settings[prop];
1250
+ var alias = JOT_SHORTHAND_METHODS[prop];
1251
+ if(alias)
1252
+ {
1253
+ component[alias] = getJotShorthandMethod(value);
1254
+ continue;
1255
+ }
1256
+
1257
+ component[prop] = value;
1258
+ }
1259
+
1260
+ return component;
1261
+ };
1262
+
1263
+ /**
1264
+ * This will create a shorthand component.
1265
+ *
1266
+ * @param {object|function} layout
1267
+ * @returns {function}
1268
+ */
1269
+ global.Jot = function(layout)
1270
+ {
1271
+ if(!layout)
1272
+ {
1273
+ return null;
1274
+ }
1275
+
1276
+ switch(typeof layout)
1277
+ {
1278
+ case 'object':
1279
+ var settings;
1280
+ if(layout.render)
1281
+ {
1282
+ settings = JotComponent(layout);
1283
+ return base.Component.extend(settings);
1284
+ }
1285
+
1286
+ settings = {
1287
+ render: function()
1288
+ {
1289
+ return layout;
1290
+ }
1291
+ };
1292
+
1293
+ // this will create a stateless and dataless unit
1294
+ return base.Unit.extend(settings);
1295
+ case 'function':
1296
+ settings = {
1297
+ render: layout
1298
+ };
1299
+
1300
+ // this will create a stateless and dataless unit
1301
+ return base.Unit.extend(settings);
1302
+ }
1303
+ };
1304
+
1305
+ /* this will add a reference to the component
1306
+ object */
1307
+ base.extend.Unit = Unit;
1308
+ base.extend.Component = Component;
1309
+
1310
+ })(this);