@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,972 @@
1
+ /* base framework module */
2
+ (function()
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 create a state object.
163
+ *
164
+ * @param {string} action
165
+ * @param {*} state
166
+ * @param {function} callBack
167
+ * @param {string} [targetId]
168
+ * @return {object}
169
+ */
170
+ createState: function(action, state, callBack, targetId)
171
+ {
172
+ return {
173
+ action: action,
174
+ state: state,
175
+ callBack: callBack,
176
+ targetId: targetId,
177
+ token: null
178
+ };
179
+ },
180
+
181
+ /**
182
+ * This will convert an action object to a state array.
183
+ *
184
+ * @protected
185
+ * @param {object} action
186
+ * @return {array}
187
+ */
188
+ convertStates: function(action)
189
+ {
190
+ var actions = [];
191
+ for(var prop in action)
192
+ {
193
+ if(action.hasOwnProperty(prop) === false)
194
+ {
195
+ continue;
196
+ }
197
+ else if(prop === 'remotes')
198
+ {
199
+ this.setupRemoteStates(action[prop], actions);
200
+ continue;
201
+ }
202
+
203
+ var targetId = null,
204
+ callBack = null,
205
+ state = action[prop];
206
+ if(state && typeof state === 'object')
207
+ {
208
+ callBack = state.callBack;
209
+ targetId = state.id || state.targetId;
210
+ state = state.state;
211
+ }
212
+
213
+ actions.push(this.createState(
214
+ prop,
215
+ state,
216
+ callBack,
217
+ targetId
218
+ ));
219
+ }
220
+ return actions;
221
+ },
222
+
223
+ setupRemoteStates: function(remotes, actions)
224
+ {
225
+ var remote;
226
+ for(var i = 0, length = remotes.length; i < length; i++)
227
+ {
228
+ remote = remotes[i];
229
+ if(!remote)
230
+ {
231
+ continue;
232
+ }
233
+
234
+ for(var prop in remote)
235
+ {
236
+ if(remote.hasOwnProperty(prop) === false || prop === 'id')
237
+ {
238
+ continue;
239
+ }
240
+
241
+ var callBack = null,
242
+ value = remote[prop],
243
+ state = (value !== null)? value : undefined;
244
+ if(state && typeof state === 'object')
245
+ {
246
+ callBack = state.callBack;
247
+ state = state.state;
248
+ }
249
+
250
+ actions.push(this.createState(
251
+ prop,
252
+ state,
253
+ callBack,
254
+ remote.id
255
+ ));
256
+ }
257
+ }
258
+ },
259
+
260
+ /**
261
+ * This will remove remote states.
262
+ */
263
+ removeRemoteStates: function()
264
+ {
265
+ var remoteStates = this.remoteStates;
266
+ if(remoteStates)
267
+ {
268
+ this.removeActions(remoteStates);
269
+ }
270
+ },
271
+
272
+ /**
273
+ * This will remove the actions.
274
+ *
275
+ * @param {array} actions
276
+ */
277
+ removeActions: function(actions)
278
+ {
279
+ if(actions.length < 1)
280
+ {
281
+ return false;
282
+ }
283
+
284
+ var states = base.state;
285
+ for(var i = 0, length = actions.length; i < length; i++)
286
+ {
287
+ var action = actions[i];
288
+ states.remove(action.targetId, action.action, action.token);
289
+ }
290
+ },
291
+
292
+ /**
293
+ * This will restore a state.
294
+ *
295
+ * @param {object} state
296
+ */
297
+ restore: function(state)
298
+ {
299
+ state.restore();
300
+
301
+ var remotes = this.remoteStates;
302
+ if(!remotes)
303
+ {
304
+ return;
305
+ }
306
+
307
+ for(var i = 0, length = remotes.length; i < length; i++)
308
+ {
309
+ var action = remotes[i];
310
+ action.token = this.bindRemoteState(state, action.action, action.targetId);
311
+ }
312
+ },
313
+
314
+ /**
315
+ * This will setup a two way bind to a remote state.
316
+ *
317
+ * @param {object} target
318
+ * @param {string} actionEvent
319
+ * @param {string} remoteTargetId
320
+ * @return {string}
321
+ */
322
+ bindRemoteState: function(target, actionEvent, remoteTargetId)
323
+ {
324
+ var token,
325
+ remoteTarget = base.state.getTarget(remoteTargetId);
326
+
327
+ var value = remoteTarget.get(actionEvent);
328
+ if(typeof value !== 'undefined')
329
+ {
330
+ target.set(actionEvent, value);
331
+ }
332
+
333
+ token = remoteTarget.on(actionEvent, function(state, prevState, committer)
334
+ {
335
+ if(committer === target)
336
+ {
337
+ return false;
338
+ }
339
+
340
+ target.set(actionEvent, state, remoteTarget);
341
+ });
342
+
343
+ target.on(actionEvent, function(state, prevState, committer)
344
+ {
345
+ if(committer === remoteTarget)
346
+ {
347
+ return false;
348
+ }
349
+
350
+ remoteTarget.set(actionEvent, state, target);
351
+ });
352
+
353
+ return token;
354
+ },
355
+
356
+ /**
357
+ * This will add the states to the target.
358
+ *
359
+ * @protected
360
+ * @param {object} state
361
+ * @param {array} actions
362
+ */
363
+ addStatesToTarget: function(state, actions)
364
+ {
365
+ var remotes = this.remoteStates;
366
+
367
+ for(var i = 0, length = actions.length; i < length; i++)
368
+ {
369
+ var action = actions[i],
370
+ token = this.addAction(state, action);
371
+
372
+ if(action.targetId)
373
+ {
374
+ action.token = token;
375
+ remotes.push(action);
376
+ }
377
+ }
378
+
379
+ if(remotes.length < 1)
380
+ {
381
+ this.remoteStates = null;
382
+ }
383
+ },
384
+
385
+ /**
386
+ * This will add an action.
387
+ *
388
+ * @param {object} target
389
+ * @param {object} action
390
+ */
391
+ addAction: function(target, action)
392
+ {
393
+ var token,
394
+ actionEvent = action.action;
395
+
396
+ /* this will check to select the remote target if set */
397
+ var targetId = action.targetId;
398
+ if(targetId)
399
+ {
400
+ token = this.bindRemoteState(target, actionEvent, targetId);
401
+ }
402
+
403
+ if(typeof action.state !== 'undefined')
404
+ {
405
+ target.addAction(actionEvent, action.state);
406
+ }
407
+
408
+ var callBack = action.callBack;
409
+ if(typeof callBack === 'function')
410
+ {
411
+ target.on(actionEvent, callBack);
412
+ }
413
+
414
+ return token;
415
+ }
416
+ });
417
+
418
+ var builder = base.builder;
419
+
420
+ /**
421
+ * Component
422
+ *
423
+ * @class
424
+ *
425
+ * This will allow components to be extended
426
+ * from a single factory.
427
+ *
428
+ * @example
429
+ * var QuickFlashPanel = base.Component.extend(
430
+ * {
431
+ * constructor: function(props)
432
+ * {
433
+ * // this will setup the component id
434
+ * base.Component.call(this, props);
435
+ * },
436
+ *
437
+ * render: function()
438
+ * {
439
+ * return {
440
+ *
441
+ * };
442
+ * }
443
+ * });
444
+ */
445
+ var Component = base.Class.extend(
446
+ {
447
+ /**
448
+ * @constructor
449
+ * @param {object} [props]
450
+ */
451
+ constructor: function(props)
452
+ {
453
+ this.init();
454
+ this.setupProps(props);
455
+ this.onCreated();
456
+
457
+ this.rendered = false;
458
+ this.container = null;
459
+ },
460
+
461
+ /**
462
+ * @param {bool} isComponent
463
+ */
464
+ isComponent: true,
465
+
466
+ /**
467
+ * This will setup the component number and unique
468
+ * instance id for the component elements.
469
+ * @protected
470
+ */
471
+ init: function()
472
+ {
473
+ var constructor = this.constructor;
474
+ this.number = (typeof constructor.number === 'undefined')? constructor.number = 0 : (++constructor.number);
475
+
476
+ var name = this.overrideTypeId || this.componentTypeId;
477
+ this.id = name + this.number;
478
+ },
479
+
480
+ /**
481
+ * This will setup the component props.
482
+ *
483
+ * @param {object} [props]
484
+ */
485
+ setupProps: function(props)
486
+ {
487
+ if(!props || typeof props !== 'object')
488
+ {
489
+ return false;
490
+ }
491
+
492
+ for(var prop in props)
493
+ {
494
+ if(props.hasOwnProperty(prop))
495
+ {
496
+ this[prop] = props[prop];
497
+ }
498
+ }
499
+ },
500
+
501
+ /**
502
+ * override this to do something when created.
503
+ */
504
+ onCreated: function()
505
+ {
506
+
507
+ },
508
+
509
+ /**
510
+ * This will render the component.
511
+ *
512
+ * @return {object}
513
+ */
514
+ render: function()
515
+ {
516
+ return {
517
+
518
+ };
519
+ },
520
+
521
+ /**
522
+ * This will cache the layout panel and set the main id.
523
+ * @param {object} layout
524
+ * @return {object}
525
+ */
526
+ _cacheRoot: function(layout)
527
+ {
528
+ if(!layout)
529
+ {
530
+ return layout;
531
+ }
532
+
533
+ if(!layout.id)
534
+ {
535
+ layout.id = this.getId();
536
+ }
537
+
538
+ layout.cache = 'panel';
539
+ return layout;
540
+ },
541
+
542
+ /**
543
+ * This will create the component layout.
544
+ * @protected
545
+ * @return {object}
546
+ */
547
+ _createLayout: function()
548
+ {
549
+ if(this.persist)
550
+ {
551
+ return this._layout || (this._layout = this.render());
552
+ }
553
+
554
+ return this.render();
555
+ },
556
+
557
+ /**
558
+ * This will prepare the layout.
559
+ *
560
+ * @protected
561
+ * @return {object}
562
+ */
563
+ prepareLayout: function()
564
+ {
565
+ var layout = this._createLayout();
566
+ return this._cacheRoot(layout);
567
+ },
568
+
569
+ /**
570
+ * This will build the layout.
571
+ * @protected
572
+ */
573
+ buildLayout: function()
574
+ {
575
+ var layout = this.prepareLayout();
576
+ this.build(layout, this.container);
577
+
578
+ base.DataTracker.add(this.panel, 'components',
579
+ {
580
+ component: this
581
+ });
582
+
583
+ this.rendered = true;
584
+ },
585
+
586
+ /**
587
+ * This will build a layout.
588
+ *
589
+ * @param {object} layout
590
+ * @param {object} container
591
+ * @return {object}
592
+ */
593
+ build: function(layout, container)
594
+ {
595
+ return builder.build(layout, container, this);
596
+ },
597
+
598
+ /**
599
+ * This will rebuild a layout.
600
+ *
601
+ * @param {object} layout
602
+ * @param {object} container
603
+ * @return {object}
604
+ */
605
+ rebuild: function(layout, container)
606
+ {
607
+ return builder.rebuild(container, layout, this);
608
+ },
609
+
610
+ /**
611
+ * This will remove children from an element.
612
+ *
613
+ * @param {object} layout
614
+ * @param {object} container
615
+ * @return {object}
616
+ */
617
+ removeAll: function(ele)
618
+ {
619
+ return builder.removeAll(ele);
620
+ },
621
+
622
+ /**
623
+ * This will cache an element when its created by
624
+ * saving a reference to it as a property on the
625
+ * component.
626
+ *
627
+ * @param {string} propName The name to use as
628
+ * the reference.
629
+ * @param {object} layout
630
+ * @param {function} [callBack]
631
+ * @return {object}
632
+ */
633
+ cache: function(propName, layout, callBack)
634
+ {
635
+ if(!layout || typeof layout !== 'object')
636
+ {
637
+ return false;
638
+ }
639
+
640
+ if(layout.isUnit === true)
641
+ {
642
+ layout =
643
+ {
644
+ component: layout
645
+ };
646
+ }
647
+
648
+ var self = this;
649
+ layout.onCreated = function(element)
650
+ {
651
+ self[propName] = element;
652
+
653
+ if(typeof callBack === 'function')
654
+ {
655
+ callBack(element);
656
+ }
657
+ };
658
+ return layout;
659
+ },
660
+
661
+ /**
662
+ * This will get an id of the component or the full
663
+ * id that has the component id prepended to the
664
+ * requested id.
665
+ *
666
+ * @param {string} [id]
667
+ * @return {string}
668
+ */
669
+ getId: function(id)
670
+ {
671
+ var mainId = this.id;
672
+ if(typeof id === 'string')
673
+ {
674
+ mainId += '-' + id;
675
+ }
676
+ return mainId;
677
+ },
678
+
679
+ /**
680
+ * This will initialize the component.
681
+ * @protected
682
+ */
683
+ initialize: function()
684
+ {
685
+ this.beforeSetup();
686
+ this.addStates();
687
+ this.buildLayout();
688
+ this.addEvents();
689
+ this.afterSetup();
690
+ },
691
+
692
+ /**
693
+ * override this to do something before setup.
694
+ */
695
+ beforeSetup: function()
696
+ {
697
+
698
+ },
699
+
700
+ /**
701
+ * override this to do something after setup.
702
+ */
703
+ afterSetup: function()
704
+ {
705
+
706
+ },
707
+
708
+ /**
709
+ * This will setup and render the component.
710
+ * @param {object} container
711
+ */
712
+ setup: function(container)
713
+ {
714
+ this.container = container;
715
+ this.initialize();
716
+ },
717
+
718
+ /* this will allow the component to override the
719
+ state target id to add a custom id */
720
+ /**
721
+ * @member {string} [stateTargetId] // optional override of state id
722
+ */
723
+ stateTargetId: null,
724
+
725
+ /**
726
+ * This will setup the state target.
727
+ *
728
+ * @protected
729
+ * @param {string} [id]
730
+ */
731
+ setupStateTarget: function(id)
732
+ {
733
+ var targetId = id || this.stateTargetId || this.id;
734
+ this.state = base.state.getTarget(targetId);
735
+ },
736
+
737
+ /**
738
+ * Override this to setup the component states.
739
+ * @return {object}
740
+ */
741
+ setupStates: function()
742
+ {
743
+ /*
744
+ return {
745
+ action: 'state'
746
+ };
747
+
748
+ or
749
+
750
+ return {
751
+ action:
752
+ {
753
+ state: 'state',
754
+ callBack: function(state, prevState)
755
+ {
756
+
757
+ }
758
+ }
759
+ };*/
760
+
761
+ return {
762
+
763
+ };
764
+ },
765
+
766
+ /**
767
+ * This will add the states.
768
+ * @protected
769
+ */
770
+ addStates: function()
771
+ {
772
+ /* this will check to restore previous a previous state if the
773
+ component has been preserved. */
774
+ var state = this.state;
775
+ if(state)
776
+ {
777
+ this.stateHelper.restore(state);
778
+ return;
779
+ }
780
+
781
+ /* this will only setupa state manager if
782
+ we have states */
783
+ var states = this.setupStates();
784
+ if(base.isEmpty(states))
785
+ {
786
+ return;
787
+ }
788
+
789
+ this.setupStateTarget();
790
+ this.stateHelper = new StateHelper(this.state, states);
791
+ },
792
+
793
+ /**
794
+ * This will remove the states.
795
+ * @protected
796
+ */
797
+ removeStates: function()
798
+ {
799
+ var state = this.state;
800
+ if(!state)
801
+ {
802
+ return false;
803
+ }
804
+
805
+ this.stateHelper.removeRemoteStates();
806
+ state.remove();
807
+ },
808
+
809
+ /**
810
+ * This will setup the event helper.
811
+ *
812
+ * @protected
813
+ */
814
+ setupEventHelper: function()
815
+ {
816
+ if(!this.events)
817
+ {
818
+ this.events = new EventHelper();
819
+ }
820
+ },
821
+
822
+ /**
823
+ * This will setup the events.
824
+ *
825
+ * @protected
826
+ * @return {array}
827
+ */
828
+ setupEvents: function()
829
+ {
830
+ return [
831
+ //['action', element, function(e){}, false]
832
+ ];
833
+ },
834
+
835
+ /**
836
+ * This will add the events.
837
+ *
838
+ * @protected
839
+ */
840
+ addEvents: function()
841
+ {
842
+ var events = this.setupEvents();
843
+ if(events.length < 1)
844
+ {
845
+ return false;
846
+ }
847
+
848
+ this.setupEventHelper();
849
+ this.events.addEvents(events);
850
+ },
851
+
852
+ /**
853
+ * This will remove the events.
854
+ * @protected
855
+ */
856
+ removeEvents: function()
857
+ {
858
+ var events = this.events;
859
+ if(events)
860
+ {
861
+ events.reset();
862
+ }
863
+ },
864
+
865
+ /**
866
+ * This will remove the component.
867
+ * @protected
868
+ */
869
+ remove: function()
870
+ {
871
+ this.prepareDestroy();
872
+
873
+ var panel = this.panel || this.id;
874
+ builder.removeElement(panel);
875
+ },
876
+
877
+ /**
878
+ * This will prepare the component to be destroyed.
879
+ */
880
+ prepareDestroy: function()
881
+ {
882
+ this.rendered = false;
883
+ this.beforeDestroy();
884
+ this.removeEvents();
885
+ this.removeStates();
886
+ },
887
+
888
+ /**
889
+ * Override this to do something before destroy.
890
+ */
891
+ beforeDestroy: function()
892
+ {
893
+
894
+ },
895
+
896
+ /**
897
+ * This will destroy the component.
898
+ */
899
+ destroy: function()
900
+ {
901
+ this.remove();
902
+ },
903
+
904
+ /**
905
+ * This will bind and element to data.
906
+ *
907
+ * @param {object} element
908
+ * @param {object} data
909
+ * @param {string} prop
910
+ * @param {function} filter
911
+ */
912
+ bindElement: function(element, data, prop, filter)
913
+ {
914
+ if(element)
915
+ {
916
+ base.DataBinder.bind(element, data, prop, filter);
917
+ }
918
+ }
919
+ });
920
+
921
+ var componentTypeNumber = 0;
922
+
923
+ /**
924
+ * This will extend the parent component to a child
925
+ * component.
926
+ *
927
+ * @static
928
+ * @param {object} child
929
+ * @return {function}
930
+ */
931
+ Component.extend = function(child)
932
+ {
933
+ if(!child)
934
+ {
935
+ return false;
936
+ }
937
+
938
+ var parent = this.prototype;
939
+
940
+ /* the child constructor must be set to set
941
+ the parent static methods on the child */
942
+ var constructor = child && child.constructor? child.constructor : false;
943
+ if(child.hasOwnProperty('constructor') === false)
944
+ {
945
+ constructor = function()
946
+ {
947
+ var args = base.listToArray(arguments);
948
+ parent.constructor.apply(this, args);
949
+ };
950
+ }
951
+
952
+ /* this will add the parent class to the
953
+ child class */
954
+ constructor.prototype = base.extendClass(parent, child);
955
+
956
+ /* this will assign a unique id to the type of
957
+ component */
958
+ constructor.prototype.componentTypeId = 'bs-cp-' + (componentTypeNumber++) + '-';
959
+
960
+ /* this will add the static methods from the parent to
961
+ the child constructor. could use assign but ie doesn't
962
+ support it */
963
+ //Object.assign(constructor, this);
964
+ base.extendObject(this, constructor);
965
+ return constructor;
966
+ };
967
+
968
+ /* this will add a reference to the component
969
+ object */
970
+ base.extend.Component = Component;
971
+
972
+ })();