@base-framework/base 2.6.1 → 2.6.2

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 +9 -4
  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,1089 +0,0 @@
1
- /* base framework module */
2
- (function()
3
- {
4
- "use strict";
5
-
6
- /**
7
- * DataPubSub
8
- *
9
- * This is a pub sub class to allow subscribers to
10
- * listen for updates when published by publishers.
11
- * @class
12
- */
13
- var DataPubSub = base.Class.extend(
14
- {
15
- /**
16
- * @constructor
17
- */
18
- constructor: function()
19
- {
20
- /**
21
- * @member {object} callBacks
22
- * @protected
23
- */
24
- this.callBacks = {};
25
-
26
- /**
27
- * @member {int} lastToken
28
- * @protected
29
- */
30
- this.lastToken = -1;
31
- },
32
-
33
- /**
34
- * This will get a subscriber array.
35
- *
36
- * @param {string} msg
37
- * @return {array}
38
- */
39
- get: function(msg)
40
- {
41
- var callBacks = this.callBacks;
42
- return (callBacks[msg] || (callBacks[msg] = []));
43
- },
44
-
45
- /**
46
- * This will reset pub sub.
47
- */
48
- reset: function()
49
- {
50
- this.callBacks = {};
51
- this.lastToken = -1;
52
- },
53
-
54
- /**
55
- * This will add a subscriber.
56
- *
57
- * @param {string} msg
58
- * @param {function} callBack
59
- * @return {string} The subscriber token.
60
- */
61
- on: function(msg, callBack)
62
- {
63
- var token = (++this.lastToken);
64
- var list = this.get(msg);
65
- list.push({
66
- token: token,
67
- callBack: callBack
68
- });
69
- return token;
70
- },
71
-
72
- /**
73
- * This will remove a subscriber.
74
- *
75
- * @param {string} msg
76
- * @param {string} token
77
- */
78
- off: function(msg, token)
79
- {
80
- var list = this.callBacks[msg] || false;
81
- if(list === false)
82
- {
83
- return false;
84
- }
85
-
86
- var length = list.length;
87
- for (var i = 0; i < length; i++ )
88
- {
89
- var item = list[i];
90
- if(item.token === token)
91
- {
92
- list.splice(i, 1);
93
- break;
94
- }
95
- }
96
- },
97
-
98
- /**
99
- * This will delete a message.
100
- *
101
- * @param {string} msg
102
- */
103
- remove: function(msg)
104
- {
105
- var callBacks = this.callBacks;
106
- if(callBacks[msg])
107
- {
108
- delete callBacks[msg];
109
- }
110
- },
111
-
112
- /**
113
- * This will publish a message.
114
- *
115
- * @param {string} msg
116
- * @param {string} value
117
- * @param {object} committer
118
- */
119
- publish: function(msg)
120
- {
121
- var i, length,
122
- list = this.callBacks[msg] || false;
123
- if(list === false)
124
- {
125
- return false;
126
- }
127
-
128
- var args = Array.prototype.slice.call(arguments, 1);
129
-
130
- length = list.length;
131
- for (i = 0; i < length; i++)
132
- {
133
- var item = list[i];
134
- if(!item)
135
- {
136
- continue;
137
- }
138
- item.callBack.apply(this, args);
139
- }
140
- }
141
- });
142
-
143
- var pubSub = new DataPubSub();
144
- base.extend.DataPubSub = DataPubSub;
145
-
146
- /**
147
- * Source
148
- *
149
- * This will create a new source to use with
150
- * a connection.
151
- * @class
152
- */
153
- var Source = base.Class.extend(
154
- {
155
- /**
156
- * @constructor
157
- */
158
- constructor: function()
159
- {
160
- /**
161
- * @member {string} msg
162
- * @protected
163
- */
164
- this.msg = null;
165
-
166
- /**
167
- * @member {string} token
168
- */
169
- this.token = null;
170
- },
171
-
172
- /**
173
- * This will set the token.
174
- *
175
- * @param {string} token
176
- */
177
- setToken: function(token)
178
- {
179
- this.token = token;
180
- }
181
- });
182
-
183
- /**
184
- * OneWaySource
185
- *
186
- * This will create a one way source to use with
187
- * a connection.
188
- * @class
189
- * @augments Source
190
- */
191
- var OneWaySource = Source.extend(
192
- {
193
- /**
194
- * This will setup the data source.
195
- *
196
- * @param {object} data
197
- */
198
- constructor: function(data)
199
- {
200
- Source.call(this);
201
- this.data = data;
202
- },
203
-
204
- /**
205
- * This will subscribe to a message.
206
- *
207
- * @param {string} msg
208
- * @param {function} callBack
209
- */
210
- subscribe: function(msg, callBack)
211
- {
212
- this.msg = msg;
213
- this.token = this.data.on(msg, callBack);
214
- },
215
-
216
- /**
217
- * This will unsubscribe from the message.
218
- */
219
- unsubscribe: function()
220
- {
221
- this.data.off(this.msg, this.token);
222
- }
223
- });
224
-
225
- /**
226
- * TwoWaySource
227
- *
228
- * This will create a two way source to use with
229
- * a connection.
230
- * @class
231
- * @augments Source
232
- */
233
- var TwoWaySource = Source.extend(
234
- {
235
- /**
236
- * @member {function} callBack
237
- */
238
- callBack: null,
239
-
240
- /**
241
- * This will subscribe to a message.
242
- *
243
- * @param {string} msg
244
- */
245
- subscribe: function(msg)
246
- {
247
- this.msg = msg;
248
- var callBack = base.bind(this, this.callBack);
249
- this.token = pubSub.on(msg, callBack);
250
- },
251
-
252
- /**
253
- * This will unsubscribe from a message.
254
- */
255
- unsubscribe: function()
256
- {
257
- pubSub.off(this.msg, this.token);
258
- }
259
- });
260
-
261
- /**
262
- * DataSource
263
- *
264
- * This will create a data source to use with
265
- * a connection.
266
- * @class
267
- * @augments TwoWaySource
268
- */
269
- var DataSource = TwoWaySource.extend(
270
- {
271
- /**
272
- * @constructor
273
- * @param {object} data
274
- * @param {string} prop
275
- */
276
- constructor: function(data, prop)
277
- {
278
- TwoWaySource.call(this);
279
- this.data = data;
280
- this.prop = prop;
281
- },
282
-
283
- /**
284
- * This will set the data value.
285
- *
286
- * @param {*} value
287
- */
288
- set: function(value)
289
- {
290
- this.data.set(this.prop, value);
291
- },
292
-
293
- /**
294
- * This will get the data value.
295
- */
296
- get: function()
297
- {
298
- return this.data.get(this.prop);
299
- },
300
-
301
- /**
302
- * The callBack when updated.
303
- *
304
- * @param {*} value
305
- * @param {object} committer
306
- */
307
- callBack: function(value, committer)
308
- {
309
- if(this.data !== committer)
310
- {
311
- this.data.set(this.prop, value, committer);
312
- }
313
- }
314
- });
315
-
316
- /**
317
- * ElementSource
318
- *
319
- * This will create an element source to use with
320
- * a connection.
321
- * @class
322
- * @augments TwoWaySource
323
- */
324
- var ElementSource = TwoWaySource.extend(
325
- {
326
- /**
327
- * @constructor
328
- * @param {object} element
329
- * @param {string} attr
330
- * @param {(string|function)} [filter]
331
- */
332
- constructor: function(element, attr, filter)
333
- {
334
- TwoWaySource.call(this);
335
- this.element = element;
336
- this.attr = this.getAttrBind(attr);
337
-
338
- if(typeof filter === 'string')
339
- {
340
- filter = this.setupFilter(filter);
341
- }
342
- this.filter = filter;
343
- },
344
-
345
- /**
346
- * This will get the bind attribute.
347
- *
348
- * @param {string} [customAttr]
349
- * @return {string}
350
- */
351
- getAttrBind: function(customAttr)
352
- {
353
- /* this will setup the custom attr if the prop
354
- has specified one. */
355
- if(customAttr)
356
- {
357
- return customAttr;
358
- }
359
-
360
- var attr = 'textContent';
361
- /* if no custom attr has been requested we will get the
362
- default attr of the element */
363
- var element = this.element;
364
- if(!(element && typeof element === 'object'))
365
- {
366
- return attr;
367
- }
368
-
369
- var tagName = element.tagName.toLowerCase();
370
- if (tagName === "input" || tagName === "textarea" || tagName === "select")
371
- {
372
- var type = element.type;
373
- if(type)
374
- {
375
- switch(type)
376
- {
377
- case 'checkbox':
378
- attr = 'checked';
379
- break;
380
- case 'file':
381
- attr = 'files';
382
- break;
383
- default:
384
- attr = 'value';
385
- }
386
- }
387
- else
388
- {
389
- attr = 'value';
390
- }
391
- }
392
- return attr;
393
- },
394
-
395
- /**
396
- * This will setup a filter callBack.
397
- *
398
- * @param {string} filter
399
- * @return {function}
400
- */
401
- setupFilter: function(filter)
402
- {
403
- var pattern = /(\[\[[^\]]+\]\])/;
404
- return function(value)
405
- {
406
- return filter.replace(pattern, value);
407
- };
408
- },
409
-
410
- /**
411
- * This will set a value on an element.
412
- *
413
- * @param {*} value
414
- */
415
- set: function(value)
416
- {
417
- var element = this.element;
418
- if(!element || typeof element !== 'object')
419
- {
420
- return false;
421
- }
422
-
423
- /* this will check to apply the option filter before
424
- setting the value */
425
- if(this.filter)
426
- {
427
- value = this.filter(value);
428
- }
429
-
430
- var attr = this.attr,
431
- type = element.type;
432
- if(type)
433
- {
434
- switch(type)
435
- {
436
- case 'checkbox':
437
- value = (value == 1);
438
- break;
439
- case 'radio':
440
- element.checked = (element.value === value);
441
- return true;
442
- }
443
- }
444
-
445
- if(attr.substring(4, 1) === '-')
446
- {
447
- base.setAttr(element, attr, value);
448
- }
449
- else
450
- {
451
- element[attr] = value;
452
- }
453
- },
454
-
455
- /**
456
- * This will get the value from an element.
457
- */
458
- get: function()
459
- {
460
- var element = this.element;
461
- if(!element || typeof element !== 'object')
462
- {
463
- return '';
464
- }
465
-
466
- var attr = this.attr;
467
- return (attr.substring(4, 1) === '-')? base.getAttr(element, attr) : element[attr];
468
- },
469
-
470
- /**
471
- * The callBack when updated.
472
- *
473
- * @param {*} value
474
- * @param {object} committer
475
- */
476
- callBack: function(value, committer)
477
- {
478
- if(committer !== this.element)
479
- {
480
- this.set(value);
481
- }
482
- }
483
- });
484
-
485
- /**
486
- * Connection
487
- *
488
- * This will create a connection.
489
- * @class
490
- */
491
- var Connection = base.Class.extend(
492
- {
493
- /**
494
- * This will be used to unsubscribe.
495
- */
496
- unsubscribe: function()
497
- {
498
-
499
- }
500
- });
501
-
502
- /**
503
- * OneWayConnection
504
- *
505
- * This will create a one way connection.
506
- * @class
507
- * @augments Connection
508
- */
509
- var OneWayConnection = Connection.extend(
510
- {
511
- /**
512
- * @constructor
513
- */
514
- constructor: function()
515
- {
516
- /**
517
- * @member {object} source
518
- */
519
- this.source = null;
520
- },
521
-
522
- /**
523
- * This will setup the connection source.
524
- *
525
- * @param {object} data
526
- * @return {object}
527
- */
528
- addSource: function(data)
529
- {
530
- return (this.source = new OneWaySource(data));
531
- },
532
-
533
- /**
534
- * This will be used to unsubscribe.
535
- * @override
536
- */
537
- unsubscribe: function()
538
- {
539
- this.source.unsubscribe();
540
- this.source = null;
541
- }
542
- });
543
-
544
- /**
545
- * TwoWayConnection
546
- *
547
- * This will setup a two way connection.
548
- * @class
549
- * @augments Connection
550
- */
551
- var TwoWayConnection = Connection.extend(
552
- {
553
- /**
554
- * @constructor
555
- */
556
- constructor: function()
557
- {
558
- this.element = null;
559
- this.data = null;
560
- },
561
-
562
- /**
563
- * This will add the element source.
564
- *
565
- * @param {object} element
566
- * @param {string} attr
567
- * @param {(string|function)} filter
568
- * @return {object}
569
- */
570
- addElement: function(element, attr, filter)
571
- {
572
- return (this.element = new ElementSource(element, attr, filter));
573
- },
574
-
575
- /**
576
- * This will add the data source.
577
- *
578
- * @param {object} data
579
- * @param {string} prop
580
- * @return {object}
581
- */
582
- addData: function(data, prop)
583
- {
584
- return (this.data = new DataSource(data, prop));
585
- },
586
-
587
- /**
588
- * This will unsubscribe from a source.
589
- *
590
- * @param {object} source
591
- */
592
- unsubscribeSource: function(source)
593
- {
594
- if(source)
595
- {
596
- source.unsubscribe();
597
- }
598
- },
599
-
600
- /**
601
- * This will be used to unsubscribe.
602
- * @override
603
- */
604
- unsubscribe: function()
605
- {
606
- this.unsubscribeSource(this.element);
607
- this.unsubscribeSource(this.data);
608
-
609
- this.element = null;
610
- this.data = null;
611
- }
612
- });
613
-
614
- /**
615
- * ConnectionTracker
616
- *
617
- * This will create a new connection tracker to track active
618
- * connections in the data binder.
619
- * @class
620
- */
621
- var ConnectionTracker = base.Class.extend(
622
- {
623
- /**
624
- * @constructor
625
- */
626
- constructor: function()
627
- {
628
- /**
629
- * @member {object} connections
630
- */
631
- this.connections = {};
632
- },
633
-
634
- /**
635
- * This will add a new connection to be tracked.
636
- *
637
- * @param {string} id
638
- * @param {string} attr
639
- * @param {object} connection
640
- * @return {object}
641
- */
642
- add: function(id, attr, connection)
643
- {
644
- var connections = this.find(id);
645
- return (connections[attr] = connection);
646
- },
647
-
648
- /**
649
- * This will get a connection.
650
- *
651
- * @param {string} id
652
- * @param {string} attr
653
- * @return {(object|bool)}
654
- */
655
- get: function(id, attr)
656
- {
657
- var connections = this.connections[id];
658
- if(connections)
659
- {
660
- return (connections[attr] || false);
661
- }
662
- return false;
663
- },
664
-
665
- /**
666
- * This will find a connection.
667
- *
668
- * @param {string} id
669
- * @return {object}
670
- */
671
- find: function(id)
672
- {
673
- var connections = this.connections;
674
- return (connections[id] || (connections[id] = {}));
675
- },
676
-
677
- /**
678
- * This will remove a connection or all connections by id.
679
- * @param {string} id
680
- * @param {string} [attr]
681
- */
682
- remove: function(id, attr)
683
- {
684
- var connections = this.connections[id];
685
- if(!connections)
686
- {
687
- return false;
688
- }
689
-
690
- var connection;
691
- if(attr)
692
- {
693
- connection = connections[attr];
694
- if(connection)
695
- {
696
- connection.unsubscribe();
697
- delete connections[attr];
698
- }
699
-
700
- /* this will remove the msg from the elements
701
- if no elements are listed under the msg */
702
- if(base.isEmpty(connections))
703
- {
704
- delete this.connections[id];
705
- }
706
- }
707
- else
708
- {
709
- for(var prop in connections)
710
- {
711
- if(connections.hasOwnProperty(prop))
712
- {
713
- connection = connections[prop];
714
- if(connection)
715
- {
716
- connection.unsubscribe();
717
- }
718
- }
719
- }
720
-
721
- delete this.connections[id];
722
- }
723
- }
724
- });
725
-
726
- /**
727
- * DataBinder
728
- *
729
- * This will create a data binder object that can
730
- * create one way and two way data bindings.
731
- * @class
732
- */
733
- var DataBinder = base.Class.extend(
734
- {
735
- /**
736
- * @constructor
737
- */
738
- constructor: function()
739
- {
740
- this.version = "1.0.1";
741
- this.attr = 'dataBindId';
742
-
743
- this.connections = new ConnectionTracker();
744
-
745
- this.idCount = 0;
746
- this.setup();
747
- },
748
-
749
- /**
750
- * This will setup the events.
751
- * @protected
752
- */
753
- setup: function()
754
- {
755
- this.setupEvents();
756
- },
757
-
758
- /**
759
- * This will bind an element to a data property.
760
- *
761
- * @param {object} element
762
- * @param {object} data
763
- * @param {string} prop
764
- * @param {(string|function)} [filter]
765
- * @return {object} an instance of the databinder.
766
- */
767
- bind: function(element, data, prop, filter)
768
- {
769
- var bindSettings = this.getPropSettings(prop);
770
- prop = bindSettings.prop;
771
-
772
- /* this will setup the model bind attr to the
773
- element and assign a bind id attr to support
774
- two way binding */
775
- var connection = this.setupConnection(element, data, prop, bindSettings.attr, filter);
776
-
777
- /* we want to get the starting value of the
778
- data and set it on our element */
779
- var connectionElement = connection.element,
780
- value = data.get(prop);
781
- if(typeof value !== 'undefined')
782
- {
783
- connectionElement.set(value);
784
- }
785
- else
786
- {
787
- /* this will set the element value
788
- as the prop value */
789
- value = connectionElement.get();
790
- if(value !== '')
791
- {
792
- connection.data.set(value);
793
- }
794
- }
795
- return this;
796
- },
797
-
798
- /**
799
- * This will bind an element to a data property.
800
- *
801
- * @protected
802
- * @param {object} element
803
- * @param {object} data
804
- * @param {string} prop
805
- * @param {string} customAttr
806
- * @param {(string|function)} [filter]
807
- * @return {object} The new connection.
808
- */
809
- setupConnection: function(element, data, prop, customAttr, filter)
810
- {
811
- var id = this.getBindId(element);
812
- var connection = new TwoWayConnection();
813
-
814
- // this will create the data source
815
- var dataSource = connection.addData(data, prop);
816
- // this will subscribe the data to the element
817
- dataSource.subscribe(id);
818
-
819
- /* this will add the data binding
820
- attr to our element so it will subscribe to
821
- the two data changes */
822
- var dataId = data.getDataId(),
823
- msg = dataId + ':' + prop;
824
-
825
- // this will create the element source
826
- var elementSource = connection.addElement(element, customAttr, filter);
827
- // this will subscribe the element to the data
828
- elementSource.subscribe(msg);
829
-
830
- this.addConnection(id, 'bind', connection);
831
-
832
- return connection;
833
- },
834
-
835
- /**
836
- * This will add a new connection to the
837
- * connection tracker.
838
- *
839
- * @protected
840
- * @param {string} id
841
- * @param {string} attr
842
- * @param {object} connection
843
- */
844
- addConnection: function(id, attr, connection)
845
- {
846
- this.connections.add(id, attr, connection);
847
- },
848
-
849
- /**
850
- * This will set the bind id.
851
- *
852
- * @param {object} element
853
- */
854
- setBindId: function(element)
855
- {
856
- var id = 'db-' + this.idCount++;
857
- element[this.attr] = id;
858
- return id;
859
- },
860
-
861
- /**
862
- * This will get the bind id.
863
- *
864
- * @param {object} element
865
- * @return {string}
866
- */
867
- getBindId: function(element)
868
- {
869
- return element[this.attr] || this.setBindId(element);
870
- },
871
-
872
- /**
873
- * This will parse the prop to get the settings.
874
- *
875
- * @param {string} prop
876
- * @return {object}
877
- */
878
- getPropSettings: function(prop)
879
- {
880
- var bindProp = prop,
881
- bindAttr = null;
882
-
883
- /* this will setup the custom attr if the prop
884
- has specified one. */
885
- if(prop.indexOf(':') !== -1)
886
- {
887
- var parts = prop.split(':');
888
- bindProp = parts[1];
889
- bindAttr = parts[0];
890
- }
891
-
892
- return {
893
- prop: bindProp,
894
- attr: bindAttr
895
- };
896
- },
897
-
898
- /**
899
- * This will unbind the element.
900
- *
901
- * @param {object} element
902
- * @return {object} an instance of the data binder.
903
- */
904
- unbind: function(element)
905
- {
906
- var id = element[this.attr];
907
- if(id)
908
- {
909
- this.connections.remove(id);
910
- }
911
- return this;
912
- },
913
-
914
- /**
915
- * This will setup a watcher for an element.
916
- *
917
- * @param {object} element
918
- * @param {object} data
919
- * @param {string} prop
920
- * @param {function} callBack
921
- */
922
- watch: function(element, data, prop, callBack)
923
- {
924
- if(!element || typeof element !== 'object')
925
- {
926
- return false;
927
- }
928
-
929
- var connection = new OneWayConnection();
930
-
931
- // this will create the one way source
932
- var source = connection.addSource(data);
933
- source.subscribe(prop, callBack);
934
-
935
- // this will add the new connection to the connection tracker
936
- var id = this.getBindId(element);
937
- var attr = data.getDataId() + ':' + prop;
938
- this.addConnection(id, attr, connection);
939
-
940
- var value = data.get(prop);
941
- if(typeof value !== 'undefined')
942
- {
943
- callBack(value);
944
- }
945
- },
946
-
947
- /**
948
- * This will remove a watcher from an element.
949
- *
950
- * @param {object} element
951
- * @param {object} data
952
- * @param {string} prop
953
- */
954
- unwatch: function(element, data, prop)
955
- {
956
- if(!element || typeof element !== 'object')
957
- {
958
- return false;
959
- }
960
-
961
- var id = element[this.attr];
962
- if(id)
963
- {
964
- var attr = data.getDataId() + ':' + prop;
965
- this.connections.remove(id, attr);
966
- }
967
- },
968
-
969
- /**
970
- * This will publish to the pub sub.
971
- *
972
- * @param {string} msg
973
- * @param {*} value
974
- * @param {object} committer
975
- * @return {object} an instance of the data binder.
976
- */
977
- publish: function(msg, value, committer)
978
- {
979
- pubSub.publish(msg, value, committer);
980
- return this;
981
- },
982
-
983
- /**
984
- * This will check if an element is bound.
985
- *
986
- * @protected
987
- * @param {object} element
988
- * @return {boolean}
989
- */
990
- isDataBound: function(element)
991
- {
992
- if(element)
993
- {
994
- var id = element[this.attr];
995
- if(id)
996
- {
997
- return id;
998
- }
999
- }
1000
- return false;
1001
- },
1002
-
1003
- /**
1004
- * @member {array} blockedKeys
1005
- * @protected
1006
- */
1007
- blockedKeys: [
1008
- 9, //tab
1009
- 18, //alt
1010
- 20, //caps lock
1011
- 37, //arrows
1012
- 38,
1013
- 39,
1014
- 40
1015
- ],
1016
-
1017
- isBlocked: function(evt)
1018
- {
1019
- if(evt.type !== 'keyup')
1020
- {
1021
- return false;
1022
- }
1023
-
1024
- return (evt.altKey !== false || base.inArray(this.blockedKeys, evt.keyCode) !== -1);
1025
- },
1026
-
1027
- /**
1028
- * This is the callBack for the chnage event.
1029
- *
1030
- * @param {object} evt
1031
- */
1032
- bindHandler: function(evt)
1033
- {
1034
- if(this.isBlocked(evt))
1035
- {
1036
- return true;
1037
- }
1038
-
1039
- var target = evt.target || evt.srcElement;
1040
- var id = this.isDataBound(target);
1041
- if(id)
1042
- {
1043
- var connection = this.connections.get(id, 'bind');
1044
- if(connection)
1045
- {
1046
- var value = connection.element.get();
1047
- /* this will publish to the ui and to the
1048
- model that subscribes to the element */
1049
- pubSub.publish(id, value, target);
1050
- }
1051
- }
1052
- evt.stopPropagation();
1053
- },
1054
-
1055
- /* this will setup the on change handler and
1056
- add the events. this needs to be setup before adding
1057
- the events. */
1058
- changeHandler: null,
1059
-
1060
- /**
1061
- * This wil setup the events.
1062
- * @protected
1063
- */
1064
- setupEvents: function()
1065
- {
1066
- this.changeHandler = base.bind(this, this.bindHandler);
1067
-
1068
- this.addEvents();
1069
- },
1070
-
1071
- /**
1072
- * This will add the events.
1073
- */
1074
- addEvents: function()
1075
- {
1076
- base.on(["change", "keyup"], document, this.changeHandler, false);
1077
- },
1078
-
1079
- /**
1080
- * This will remove the events.
1081
- */
1082
- removeEvents: function()
1083
- {
1084
- base.off(["change", "keyup"], document, this.changeHandler, false);
1085
- }
1086
- });
1087
-
1088
- base.extend.DataBinder = new DataBinder();
1089
- })();