@base-framework/base 2.6.1 → 2.6.3

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