@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,640 +0,0 @@
1
- /* base framework module */
2
- (function()
3
- {
4
- "use strict";
5
-
6
- /*
7
- DataPubSub
8
-
9
- this will create a pub sub object
10
- to allow messages to be subscribed to and
11
- publish changes that will be pushed to the
12
- subscribers.
13
-
14
- */
15
- var DataPubSub = base.Class.extend(
16
- {
17
- constructor: function()
18
- {
19
- this.callBacks = {};
20
- this.lastToken = -1;
21
- },
22
-
23
- /* this will get the subscriber array for the
24
- message or create a new subscriber array if none
25
- is setup already.
26
- @param (string) msg
27
- @return (array) subscriber array */
28
- get: function(msg)
29
- {
30
- var callBacks = this.callBacks;
31
- return (callBacks[msg] || (callBacks[msg] = []));
32
- },
33
-
34
- reset: function()
35
- {
36
- this.callBacks = {};
37
- },
38
-
39
- on: function(msg, callBack)
40
- {
41
- var token = (++this.lastToken);
42
- var list = this.get(msg);
43
- list.push({
44
- token: token,
45
- callBack: callBack
46
- });
47
- return token;
48
- },
49
-
50
- off: function(msg, token)
51
- {
52
- var list = this.callBacks[msg] || false;
53
- if(list)
54
- {
55
- var length = list.length;
56
- for (var i = 0; i < length; i++ )
57
- {
58
- var item = list[i];
59
- if(item.token === token)
60
- {
61
- list.splice(i, 1);
62
- break;
63
- }
64
- }
65
- }
66
- },
67
-
68
- remove: function(msg)
69
- {
70
- var callBacks = this.callBacks;
71
- if(callBacks[msg])
72
- {
73
- delete callBacks[msg];
74
- }
75
- },
76
-
77
- publish: function(msg)
78
- {
79
- var i, length,
80
- list = this.callBacks[msg] || false;
81
- if(list !== false)
82
- {
83
- length = list.length;
84
- for (i = 0; i < length; i++ )
85
- {
86
- list[i].callBack.apply(this, arguments);
87
- }
88
- }
89
- }
90
- });
91
-
92
- var pubSub = new DataPubSub();
93
- base.extend.DataPubSub = DataPubSub;
94
-
95
- var Source = base.Class.extend(
96
- {
97
- constructor: function()
98
- {
99
- this.msg = null;
100
- this.token = null;
101
- },
102
-
103
- setToken: function(token)
104
- {
105
- this.token = token;
106
- },
107
-
108
- callBack: null,
109
-
110
- subscribe: function(msg)
111
- {
112
- this.msg = msg;
113
- var callBack = base.bind(this, this.callBack);
114
- this.token = pubSub.on(msg, callBack);
115
- },
116
-
117
- unsubscribe: function()
118
- {
119
- pubSub.off(this.msg, this.token);
120
- }
121
- });
122
-
123
- var DataSource = Source.extend(
124
- {
125
- constructor: function(data, prop)
126
- {
127
- Source.call(this);
128
- this.data = data;
129
- this.prop = prop;
130
- },
131
-
132
- set: function(value)
133
- {
134
- this.data.set(this.prop, value);
135
- },
136
-
137
- get: function()
138
- {
139
- return this.data.get(this.prop);
140
- },
141
-
142
- callBack: function(evt, prop, value, committer)
143
- {
144
- if(this.data !== this.committer)
145
- {
146
- this.data.set(prop, value, committer);
147
- }
148
- }
149
- });
150
-
151
- var ElementSource = Source.extend(
152
- {
153
- constructor: function(element, attr, filter)
154
- {
155
- Source.call(this);
156
- this.element = element;
157
- this.attr = this.getAttrBind(attr);
158
-
159
- if(typeof filter === 'string')
160
- {
161
- filter = this.setupFilter(filter);
162
- }
163
- this.filter = filter;
164
- },
165
-
166
- getAttrBind: function(customAttr)
167
- {
168
- /* this will setup the custom attr if the prop
169
- has specified one. */
170
- if(customAttr)
171
- {
172
- return customAttr;
173
- }
174
-
175
- var attr = 'textContent';
176
- /* if no custom attr has been requested we will get the
177
- default attr of the element */
178
- var element = this.element;
179
- if(element && typeof element === 'object')
180
- {
181
- var tagName = element.tagName.toLowerCase();
182
- if (tagName === "input" || tagName === "textarea" || tagName === "select")
183
- {
184
- var type = element.type;
185
- if(type && (type === 'checkbox' || type === 'radio'))
186
- {
187
- attr = 'checked';
188
- }
189
- else
190
- {
191
- attr = 'value';
192
- }
193
- }
194
- }
195
- return attr;
196
- },
197
-
198
- setupFilter: function(filter)
199
- {
200
- var pattern = /(\[\[[^\]]+\]\])/;
201
- return function(value)
202
- {
203
- return filter.replace(pattern, value);
204
- };
205
- },
206
-
207
- /* this will set a value on an elememnt.
208
- @param (mixed) value */
209
- set: function(value)
210
- {
211
- var element = this.element;
212
- if(element && typeof element === 'object')
213
- {
214
- /* this will check to apply the option filter before
215
- settings the value */
216
- if(this.filter)
217
- {
218
- value = this.filter(value);
219
- }
220
-
221
- var attr = this.attr,
222
- type = element.type;
223
- if(type && (type === 'checkbox' || type === 'radio'))
224
- {
225
- value = (value == 1);
226
- }
227
-
228
- if(attr.substring(0, 5) === 'data-')
229
- {
230
- base.data(element, attr, value);
231
- }
232
- else
233
- {
234
- element[attr] = value;
235
- }
236
- }
237
- },
238
-
239
- /* this will get a value on an elememnt.
240
- @return (mixed) the element value */
241
- get: function()
242
- {
243
- var value = '',
244
- element = this.element;
245
- if(element && typeof element === 'object')
246
- {
247
- var attr = this.attr;
248
- if(attr.substring(0, 5) === 'data-')
249
- {
250
- value = base.data(element, attr);
251
- }
252
- else
253
- {
254
- value = element[attr];
255
- }
256
- }
257
- return value;
258
- },
259
-
260
- callBack: function(evt, prop, value, committer)
261
- {
262
- if(committer !== this.element)
263
- {
264
- this.set(value);
265
- }
266
- }
267
- });
268
-
269
- var Connection = base.Class.extend(
270
- {
271
- constructor: function()
272
- {
273
- this.element = null;
274
- this.data = null;
275
- },
276
-
277
- addElement: function(element, attr, filter)
278
- {
279
- return (this.element = new ElementSource(element, attr, filter));
280
- },
281
-
282
- addData: function(data, prop)
283
- {
284
- return (this.data = new DataSource(data, prop));
285
- },
286
-
287
- unsubscribeSource: function(source)
288
- {
289
- if(source)
290
- {
291
- source.unsubscribe();
292
- }
293
- },
294
-
295
- unsubscribe: function()
296
- {
297
- this.unsubscribeSource(this.element);
298
- this.unsubscribeSource(this.data);
299
-
300
- this.element = null;
301
- this.data = null;
302
- }
303
- });
304
-
305
- var ConnectionTracker = base.Class.extend(
306
- {
307
- constructor: function()
308
- {
309
- this.connections = {};
310
- },
311
-
312
- add: function(id, connection)
313
- {
314
- var connections = this.connections;
315
- return (connections[id] = connection);
316
- },
317
-
318
- get: function(id)
319
- {
320
- return (this.connections[id] || false);
321
- },
322
-
323
- remove: function(id)
324
- {
325
- var connection = this.connections[id];
326
- if(connection)
327
- {
328
- connection.unsubscribe();
329
- delete this.connections[id];
330
- }
331
- }
332
- });
333
-
334
- var WatcherTracker = base.Class.extend(
335
- {
336
- constructor: function()
337
- {
338
- this.watchers = {};
339
- },
340
-
341
- find: function(id)
342
- {
343
- var watchers = this.watchers;
344
- return (watchers[id] || (watchers[id] = []));
345
- },
346
-
347
- add: function(id, data, prop, callBack)
348
- {
349
- var subscriptions = this.find(id);
350
- subscriptions.push({
351
- data: data,
352
- msg: prop,
353
- token: this.getSubscription(data, prop, callBack)
354
- });
355
- },
356
-
357
- getSubscription: function(data, prop, callBack)
358
- {
359
- return data.on(prop, callBack);
360
- },
361
-
362
- get: function(id)
363
- {
364
- return (this.watchers[id] || false);
365
- },
366
-
367
- remove: function(id)
368
- {
369
- var subscriptions = this.watchers[id];
370
- if(subscriptions)
371
- {
372
- for(var i = 0, length = subscriptions.length; i < length; i++)
373
- {
374
- var subscription = subscriptions[i];
375
- if(subscription)
376
- {
377
- subscription.data.off(subscription.msg, subscription.token);
378
- }
379
- }
380
- delete this.watchers[id];
381
- }
382
- }
383
- });
384
-
385
- /*
386
- DataBinder
387
-
388
- this create a data bind module to add
389
- two way data binding to base models.
390
- */
391
- var DataBinder = base.Class.extend(
392
- {
393
- constructor: function()
394
- {
395
- this.version = "1.0.1";
396
- this.attr = 'data-bind';
397
-
398
- this.connections = new ConnectionTracker();
399
- this.watchers = new WatcherTracker();
400
-
401
- this.idCount = 0;
402
- this.setup();
403
- },
404
-
405
- setup: function()
406
- {
407
- this.setupEvents();
408
- },
409
-
410
- /* this will add the data bind attr on an
411
- element for a model property.
412
- @param (object) element
413
- @param (object) data
414
- @param (string) prop
415
- @return (object) the instance of the data binder */
416
- bind: function(element, data, prop, filter)
417
- {
418
- var bindSettings = this.getPropSettings(prop);
419
- prop = bindSettings.prop;
420
-
421
- /* this will setup the model bind attr to the
422
- element and assign a bind id attr to support
423
- two way binding */
424
- var connection = this.setupConnection(element, data, prop, bindSettings.attr, filter);
425
-
426
- /* we want to get the starting value of the
427
- data and set it on our element */
428
- var connectionElement = connection.element,
429
- value = data.get(prop);
430
- if(typeof value !== 'undefined')
431
- {
432
- connectionElement.set(value);
433
- }
434
- else
435
- {
436
- /* this will set the element value
437
- as the prop value */
438
- value = connectionElement.get();
439
- if(value !== '')
440
- {
441
- connection.data.set(value);
442
- }
443
- }
444
- return this;
445
- },
446
-
447
- setupConnection: function(element, data, prop, customAttr, filter)
448
- {
449
- var connection = new Connection();
450
-
451
- var id = this.getBindId(element);
452
- var dataSource = connection.addData(data, prop);
453
- dataSource.subscribe(id);
454
-
455
- /* this will add the data binding
456
- attr to out element so it will subscribe to
457
- the two data changes */
458
- var dataId = data.getDataId(),
459
- msg = dataId + ':' + prop;
460
-
461
- var elementSource = connection.addElement(element, customAttr, filter);
462
- elementSource.subscribe(msg);
463
-
464
- this.addConnection(id, connection);
465
-
466
- return connection;
467
- },
468
-
469
- addConnection: function(id, connection)
470
- {
471
- this.connections.add(id, connection);
472
- },
473
-
474
- setBindId: function(element)
475
- {
476
- var id = 'bs-db-' + this.idCount++;
477
- base.attr(element, this.attr + '-id', id);
478
- return id;
479
- },
480
-
481
- getBindId: function(element)
482
- {
483
- var id = base.attr(element, this.attr + '-id');
484
- if(!id)
485
- {
486
- id = this.setBindId(element);
487
- }
488
- return id;
489
- },
490
-
491
- getPropSettings: function(prop)
492
- {
493
- var bindProp = prop,
494
- bindAttr = null;
495
-
496
- /* this will setup the custom attr if the prop
497
- has specified one. */
498
- var parts = prop.split(':');
499
- if(parts.length > 1)
500
- {
501
- bindProp = parts[1];
502
- bindAttr = parts[0];
503
- }
504
-
505
- return {
506
- prop: bindProp,
507
- attr: bindAttr
508
- };
509
- },
510
-
511
- /* this will remove an element from the data binder
512
- @param (object) element
513
- @return (object) the instance of the data binder*/
514
- unbind: function(element)
515
- {
516
- var id = base.data(element, this.attr + '-id');
517
- if(id)
518
- {
519
- this.connections.remove(id);
520
- this.watchers.remove(id);
521
- }
522
- return this;
523
- },
524
-
525
- watch: function(element, data, prop, callBack)
526
- {
527
- if(!element || typeof element !== 'object')
528
- {
529
- return false;
530
- }
531
-
532
- var id = this.getBindId(element);
533
- this.watchers.add(id, data, prop, callBack);
534
- },
535
-
536
- unwatch: function(element)
537
- {
538
- if(!element || typeof element !== 'object')
539
- {
540
- return false;
541
- }
542
-
543
- var id = base.attr(element, this.attr + '-id');
544
- if(id)
545
- {
546
- this.watchers.remove(element);
547
- }
548
- },
549
-
550
- /* this will publish a change to the data binder.
551
- @param (string) message e.g id:change
552
- @param (string) attrName = the model prop name
553
- @param (mixed) the prop value
554
- @param (object) the object committing the change */
555
- publish: function(msg, attr, value, committer)
556
- {
557
- pubSub.publish(msg, attr, value, committer);
558
- return this;
559
- },
560
-
561
- isDataBound: function(element)
562
- {
563
- if(element)
564
- {
565
- var dataAttr = this.attr;
566
- var id = base.data(element, dataAttr + '-id');
567
- if(id)
568
- {
569
- return id;
570
- }
571
- }
572
- return false;
573
- },
574
-
575
- blockedKeys: [
576
- 17, //ctrl
577
- 9, //tab
578
- 16, //shift
579
- 18, //alt
580
- 20, //caps lock
581
- 37, //arrows
582
- 38,
583
- 39,
584
- 40
585
- ],
586
-
587
- bindHandler: function(evt)
588
- {
589
- if(evt.type === 'keyup')
590
- {
591
- /* this will check to block ctrl, shift or alt +
592
- buttons */
593
- if(evt.ctrlKey !== false || evt.shiftKey !== false || evt.altKey !== false || base.inArray(this.blockedKeys, evt.keyCode) !== -1)
594
- {
595
- return true;
596
- }
597
- }
598
-
599
- var target = evt.target || evt.srcElement;
600
- var id = this.isDataBound(target);
601
- if(id)
602
- {
603
- var connection = this.connections.get(id);
604
- if(connection)
605
- {
606
- var value = connection.element.get();
607
- /* this will publish to the ui and to the
608
- model that subscribes to the element */
609
- pubSub.publish(id, connection.data.prop, value, target);
610
- }
611
- }
612
- evt.stopPropagation();
613
- },
614
-
615
- /* this will setup the on change handler and
616
- add the events. this needs to be setup before adding
617
- the events. */
618
- changeHandler: null,
619
- setupEvents: function()
620
- {
621
- this.changeHandler = base.bind(this, this.bindHandler);
622
-
623
- this.addEvents();
624
- },
625
-
626
- /* this will add the binder events */
627
- addEvents: function()
628
- {
629
- base.on(["change", "keyup"], document, this.changeHandler, false);
630
- },
631
-
632
- /* this will remove the binder events */
633
- removeEvents: function()
634
- {
635
- base.off(["change", "keyup"], document, this.changeHandler, false);
636
- }
637
- });
638
-
639
- base.extend.DataBinder = new DataBinder();
640
- })();