@base-framework/base 2.6.0 → 2.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (190) hide show
  1. package/base.min.js +1 -0
  2. package/es5/base.js +2968 -0
  3. package/es5/modules/ajax.js +663 -0
  4. package/es5/modules/animation.js +188 -0
  5. package/es5/modules/animations.js +1080 -0
  6. package/es5/modules/atom.js +65 -0
  7. package/es5/modules/component.js +1310 -0
  8. package/es5/modules/data-binder.js +1131 -0
  9. package/es5/modules/data.js +1808 -0
  10. package/es5/modules/date.js +525 -0
  11. package/es5/modules/form-validator.js +324 -0
  12. package/es5/modules/history.js +126 -0
  13. package/es5/modules/html-builder.js +461 -0
  14. package/es5/modules/layout.js +1679 -0
  15. package/es5/modules/mouse.js +124 -0
  16. package/es5/modules/nav-link.js +123 -0
  17. package/es5/modules/olderversions/animations-ease.js +1095 -0
  18. package/es5/modules/olderversions/animations-update.js +1048 -0
  19. package/es5/modules/olderversions/base-animations.js +636 -0
  20. package/es5/modules/olderversions/base-component-class.js +100 -0
  21. package/es5/modules/olderversions/base-data-binder-1.js +407 -0
  22. package/es5/modules/olderversions/base-data-binder-class.js +358 -0
  23. package/es5/modules/olderversions/base-layout-parser-class.js +172 -0
  24. package/es5/modules/olderversions/base-mode-1.js +777 -0
  25. package/es5/modules/olderversions/base-model-class.js +585 -0
  26. package/es5/modules/olderversions/data-binder/element-binding/base-data-binder-class.js +358 -0
  27. package/es5/modules/olderversions/data-binder/element-binding/base-model-class.js +585 -0
  28. package/es5/modules/olderversions/data-binder/model-binding/base-data-binder-class.js +353 -0
  29. package/es5/modules/olderversions/data-binder/model-binding/base-model-class.js +604 -0
  30. package/es5/modules/olderversions/data-binder-update-watcher.js +640 -0
  31. package/es5/modules/olderversions/data-tracker.js +187 -0
  32. package/es5/modules/olderversions/event-update.js +666 -0
  33. package/es5/modules/olderversions/nav-link.js +119 -0
  34. package/es5/modules/olderversions/router-with-templates-1.js +785 -0
  35. package/es5/modules/olderversions/router-with-templates.js +701 -0
  36. package/es5/modules/prototypes/ajax.js +657 -0
  37. package/es5/modules/prototypes/atom.js +65 -0
  38. package/es5/modules/prototypes/component.js +972 -0
  39. package/es5/modules/prototypes/data-binder.js +1089 -0
  40. package/es5/modules/prototypes/data.js +1290 -0
  41. package/es5/modules/prototypes/html-builder.js +414 -0
  42. package/es5/modules/prototypes/layout.js +879 -0
  43. package/es5/modules/router.js +1680 -0
  44. package/es5/modules/state.js +274 -0
  45. package/es6/.jshintrc +3 -0
  46. package/es6/base.js +41 -0
  47. package/es6/core.js +1 -0
  48. package/es6/data-tracker.js +351 -0
  49. package/es6/events.js +602 -0
  50. package/es6/legacy/es5/base.js +2968 -0
  51. package/es6/legacy/es5/modules/ajax.js +663 -0
  52. package/es6/legacy/es5/modules/animation.js +188 -0
  53. package/es6/legacy/es5/modules/animations.js +1080 -0
  54. package/es6/legacy/es5/modules/atom.js +65 -0
  55. package/es6/legacy/es5/modules/component.js +1310 -0
  56. package/es6/legacy/es5/modules/data-binder.js +1131 -0
  57. package/es6/legacy/es5/modules/data.js +1808 -0
  58. package/es6/legacy/es5/modules/date.js +525 -0
  59. package/es6/legacy/es5/modules/form-validator.js +324 -0
  60. package/es6/legacy/es5/modules/history.js +126 -0
  61. package/es6/legacy/es5/modules/html-builder.js +461 -0
  62. package/es6/legacy/es5/modules/layout.js +1679 -0
  63. package/es6/legacy/es5/modules/mouse.js +124 -0
  64. package/es6/legacy/es5/modules/nav-link.js +123 -0
  65. package/es6/legacy/es5/modules/olderversions/animations-ease.js +1095 -0
  66. package/es6/legacy/es5/modules/olderversions/animations-update.js +1048 -0
  67. package/es6/legacy/es5/modules/olderversions/base-animations.js +636 -0
  68. package/es6/legacy/es5/modules/olderversions/base-component-class.js +100 -0
  69. package/es6/legacy/es5/modules/olderversions/base-data-binder-1.js +407 -0
  70. package/es6/legacy/es5/modules/olderversions/base-data-binder-class.js +358 -0
  71. package/es6/legacy/es5/modules/olderversions/base-layout-parser-class.js +172 -0
  72. package/es6/legacy/es5/modules/olderversions/base-mode-1.js +777 -0
  73. package/es6/legacy/es5/modules/olderversions/base-model-class.js +585 -0
  74. package/es6/legacy/es5/modules/olderversions/data-binder/element-binding/base-data-binder-class.js +358 -0
  75. package/es6/legacy/es5/modules/olderversions/data-binder/element-binding/base-model-class.js +585 -0
  76. package/es6/legacy/es5/modules/olderversions/data-binder/model-binding/base-data-binder-class.js +353 -0
  77. package/es6/legacy/es5/modules/olderversions/data-binder/model-binding/base-model-class.js +604 -0
  78. package/es6/legacy/es5/modules/olderversions/data-binder-update-watcher.js +640 -0
  79. package/es6/legacy/es5/modules/olderversions/data-tracker.js +187 -0
  80. package/es6/legacy/es5/modules/olderversions/event-update.js +666 -0
  81. package/es6/legacy/es5/modules/olderversions/nav-link.js +119 -0
  82. package/es6/legacy/es5/modules/olderversions/router-with-templates-1.js +785 -0
  83. package/es6/legacy/es5/modules/olderversions/router-with-templates.js +701 -0
  84. package/es6/legacy/es5/modules/prototypes/ajax.js +657 -0
  85. package/es6/legacy/es5/modules/prototypes/atom.js +65 -0
  86. package/es6/legacy/es5/modules/prototypes/component.js +972 -0
  87. package/es6/legacy/es5/modules/prototypes/data-binder.js +1089 -0
  88. package/es6/legacy/es5/modules/prototypes/data.js +1290 -0
  89. package/es6/legacy/es5/modules/prototypes/html-builder.js +414 -0
  90. package/es6/legacy/es5/modules/prototypes/layout.js +879 -0
  91. package/es6/legacy/es5/modules/router.js +1680 -0
  92. package/es6/legacy/es5/modules/state.js +274 -0
  93. package/es6/main.js +1331 -0
  94. package/es6/modules/ajax/ajax.js +514 -0
  95. package/es6/modules/animation/animation.js +236 -0
  96. package/es6/modules/animations/animation-controller.js +231 -0
  97. package/es6/modules/animations/animation.js +64 -0
  98. package/es6/modules/animations/attr-movement.js +66 -0
  99. package/es6/modules/animations/css-movement.js +170 -0
  100. package/es6/modules/animations/movement.js +131 -0
  101. package/es6/modules/animations/value.js +187 -0
  102. package/es6/modules/atom/atom.js +54 -0
  103. package/es6/modules/component/component.js +230 -0
  104. package/es6/modules/component/event-helper.js +119 -0
  105. package/es6/modules/component/jot.js +144 -0
  106. package/es6/modules/component/state-helper.js +262 -0
  107. package/es6/modules/component/unit.js +551 -0
  108. package/es6/modules/data/attrs.js +40 -0
  109. package/es6/modules/data/basic-data.js +500 -0
  110. package/es6/modules/data/data-utils.js +29 -0
  111. package/es6/modules/data/data.js +3 -0
  112. package/es6/modules/data/deep-data.js +541 -0
  113. package/es6/modules/data/model-service.js +528 -0
  114. package/es6/modules/data/model.js +133 -0
  115. package/es6/modules/data/simple-data.js +33 -0
  116. package/es6/modules/data-binder/connection-tracker.js +113 -0
  117. package/es6/modules/data-binder/connection.js +16 -0
  118. package/es6/modules/data-binder/data-binder.js +352 -0
  119. package/es6/modules/data-binder/data-pub-sub.js +141 -0
  120. package/es6/modules/data-binder/data-source.js +56 -0
  121. package/es6/modules/data-binder/element-source.js +219 -0
  122. package/es6/modules/data-binder/one-way-connection.js +46 -0
  123. package/es6/modules/data-binder/one-way-source.js +43 -0
  124. package/es6/modules/data-binder/source.js +36 -0
  125. package/es6/modules/data-binder/two-way-connection.js +75 -0
  126. package/es6/modules/data-binder/two-way-source.js +41 -0
  127. package/es6/modules/date/date.js +544 -0
  128. package/es6/modules/history/history.js +89 -0
  129. package/es6/modules/html-builder/html-builder.js +434 -0
  130. package/es6/modules/import/import.js +390 -0
  131. package/es6/modules/layout/layout-builder.js +1269 -0
  132. package/es6/modules/layout/layout-parser.js +134 -0
  133. package/es6/modules/layout/watcher-helper.js +282 -0
  134. package/es6/modules/mouse/mouse.js +114 -0
  135. package/es6/modules/router/component-helper.js +163 -0
  136. package/es6/modules/router/history-controller.js +216 -0
  137. package/es6/modules/router/nav-link.js +124 -0
  138. package/es6/modules/router/route.js +401 -0
  139. package/es6/modules/router/router.js +789 -0
  140. package/es6/modules/router/utils.js +31 -0
  141. package/es6/modules/state/state-target.js +91 -0
  142. package/es6/modules/state/state.js +171 -0
  143. package/es6/package-lock.json +13 -0
  144. package/es6/package.json +28 -0
  145. package/es6/shared/objects.js +99 -0
  146. package/legacy/es5/base.js +2968 -0
  147. package/legacy/es5/modules/ajax.js +663 -0
  148. package/legacy/es5/modules/animation.js +188 -0
  149. package/legacy/es5/modules/animations.js +1080 -0
  150. package/legacy/es5/modules/atom.js +65 -0
  151. package/legacy/es5/modules/component.js +1310 -0
  152. package/legacy/es5/modules/data-binder.js +1131 -0
  153. package/legacy/es5/modules/data.js +1808 -0
  154. package/legacy/es5/modules/date.js +525 -0
  155. package/legacy/es5/modules/form-validator.js +324 -0
  156. package/legacy/es5/modules/history.js +126 -0
  157. package/legacy/es5/modules/html-builder.js +461 -0
  158. package/legacy/es5/modules/layout.js +1679 -0
  159. package/legacy/es5/modules/mouse.js +124 -0
  160. package/legacy/es5/modules/nav-link.js +123 -0
  161. package/legacy/es5/modules/olderversions/animations-ease.js +1095 -0
  162. package/legacy/es5/modules/olderversions/animations-update.js +1048 -0
  163. package/legacy/es5/modules/olderversions/base-animations.js +636 -0
  164. package/legacy/es5/modules/olderversions/base-component-class.js +100 -0
  165. package/legacy/es5/modules/olderversions/base-data-binder-1.js +407 -0
  166. package/legacy/es5/modules/olderversions/base-data-binder-class.js +358 -0
  167. package/legacy/es5/modules/olderversions/base-layout-parser-class.js +172 -0
  168. package/legacy/es5/modules/olderversions/base-mode-1.js +777 -0
  169. package/legacy/es5/modules/olderversions/base-model-class.js +585 -0
  170. package/legacy/es5/modules/olderversions/data-binder/element-binding/base-data-binder-class.js +358 -0
  171. package/legacy/es5/modules/olderversions/data-binder/element-binding/base-model-class.js +585 -0
  172. package/legacy/es5/modules/olderversions/data-binder/model-binding/base-data-binder-class.js +353 -0
  173. package/legacy/es5/modules/olderversions/data-binder/model-binding/base-model-class.js +604 -0
  174. package/legacy/es5/modules/olderversions/data-binder-update-watcher.js +640 -0
  175. package/legacy/es5/modules/olderversions/data-tracker.js +187 -0
  176. package/legacy/es5/modules/olderversions/event-update.js +666 -0
  177. package/legacy/es5/modules/olderversions/nav-link.js +119 -0
  178. package/legacy/es5/modules/olderversions/router-with-templates-1.js +785 -0
  179. package/legacy/es5/modules/olderversions/router-with-templates.js +701 -0
  180. package/legacy/es5/modules/prototypes/ajax.js +657 -0
  181. package/legacy/es5/modules/prototypes/atom.js +65 -0
  182. package/legacy/es5/modules/prototypes/component.js +972 -0
  183. package/legacy/es5/modules/prototypes/data-binder.js +1089 -0
  184. package/legacy/es5/modules/prototypes/data.js +1290 -0
  185. package/legacy/es5/modules/prototypes/html-builder.js +414 -0
  186. package/legacy/es5/modules/prototypes/layout.js +879 -0
  187. package/legacy/es5/modules/router.js +1680 -0
  188. package/legacy/es5/modules/state.js +274 -0
  189. package/package.json +8 -3
  190. package/update +16 -0
@@ -0,0 +1,1080 @@
1
+ /* base framework module */
2
+ /*
3
+ javascript animation add and remove with full object
4
+ animation tracking
5
+ */
6
+ (function()
7
+ {
8
+ "use strict";
9
+
10
+ var math =
11
+ {
12
+ round: function(number)
13
+ {
14
+ return ~~ (0.5 + number);
15
+ },
16
+
17
+ floor: function(number)
18
+ {
19
+ return ~~number;
20
+ }
21
+ };
22
+
23
+ /* this will add and remove animations */
24
+ base.extend.animations =
25
+ {
26
+ version: '1.0.1',
27
+
28
+ /* this class tracks all objects being animated and can
29
+ add and remove them when completed */
30
+ animating:
31
+ {
32
+ objects: [],
33
+
34
+ /* this will create a new animation obj form the params obj
35
+ and add it to the objects array to be tracked.
36
+ @param (object) obj = the animation params
37
+ @return (object) the animation object */
38
+ add: function(obj)
39
+ {
40
+ var animation = null,
41
+ self = this;
42
+
43
+ /* we want to setup the animation to remove itself when
44
+ finished */
45
+ var removeAnimation = function(status)
46
+ {
47
+ self.remove(animation);
48
+ /* this will check to return the animation call back
49
+ and return the status */
50
+ var callBack = obj.callBack;
51
+ if(typeof callBack === 'function')
52
+ {
53
+ callBack(status);
54
+ }
55
+ };
56
+
57
+ /* this will create a new animation object and we
58
+ want to add it to the objects array */
59
+ animation = new AnimationController(obj, removeAnimation);
60
+ this.objects.push(animation);
61
+ return animation;
62
+ },
63
+
64
+ /* this will stop and remove an animation obj form the
65
+ params obj and remove it from being tracked.
66
+ @param (object) obj = the animation obj
67
+ @return (object) an instance of the animating object */
68
+ remove: function(obj)
69
+ {
70
+ this.stopAnimation(obj);
71
+
72
+ var objects = this.objects;
73
+ var indexNumber = base.inArray(objects, obj);
74
+ if(indexNumber > -1)
75
+ {
76
+ objects.splice(indexNumber, 1);
77
+ }
78
+ return this;
79
+ },
80
+
81
+ /* this will remove and stop any animation still active
82
+ on an element.
83
+ @param (object) element
84
+ @return (object) an instance of the animating object */
85
+ removeByElement: function(element)
86
+ {
87
+ if(!element)
88
+ {
89
+ return this;
90
+ }
91
+
92
+ var animations = this.checkAnimating(element);
93
+ if(animations !== false)
94
+ {
95
+ for(var i = 0, maxLength = animations.length; i < maxLength; i++)
96
+ {
97
+ /* we want to remove the animation fron the object array */
98
+ this.remove(animations[i]);
99
+ }
100
+ }
101
+ return this;
102
+ },
103
+
104
+ /* this will stop an animation if its still active.
105
+ @param (object) animation = the animation object
106
+ @return (object) an instance of the animating object */
107
+ stopAnimation: function(animation)
108
+ {
109
+ if(!animation || typeof animation !== 'object')
110
+ {
111
+ return this;
112
+ }
113
+
114
+ if(animation.status !== 'stopped')
115
+ {
116
+ /* we want to stop the animation */
117
+ animation.stop();
118
+ }
119
+ return this;
120
+ },
121
+
122
+ /* this will get all active aniamtion objects for an element.
123
+ @param (object) element
124
+ @return (array) an array of animation objects */
125
+ checkAnimating: function(element)
126
+ {
127
+ var animationArray = [];
128
+
129
+ if(element && typeof element === 'object')
130
+ {
131
+ /* we want to get any timers set for our object */
132
+ var objects = this.objects;
133
+ for(var i = 0, maxLength = objects.length; i < maxLength; i++)
134
+ {
135
+ var animation = objects[i];
136
+ if(animation.element === element)
137
+ {
138
+ animationArray.push(animation);
139
+ }
140
+ }
141
+ }
142
+ return (animationArray.length >= 1)? animationArray : false;
143
+ },
144
+
145
+ /* this will stop all previous aniamtions on an element.
146
+ @param (object) element = the element
147
+ @return (object) an instance of the animating object */
148
+ stopPreviousAnimations: function(element)
149
+ {
150
+ /* we want to remove the timers and class names
151
+ from the object */
152
+ this.removeByElement(element);
153
+ return this;
154
+ },
155
+
156
+ reset: function()
157
+ {
158
+ this.objects = [];
159
+ return this;
160
+ }
161
+ },
162
+
163
+ add: function(obj)
164
+ {
165
+ return this.animating.add(obj);
166
+ },
167
+
168
+ remove: function(obj)
169
+ {
170
+ this.animating.remove(obj);
171
+ },
172
+
173
+ /* this will setup the request animation frame to
174
+ allow backwards compat. */
175
+ setupAnimationFrame: function()
176
+ {
177
+ var w = window;
178
+ /* setup request for prefix or setTimeout if
179
+ not supported */
180
+ w.requestAnimationFrame = (
181
+ w.requestAnimationFrame ||
182
+ w.mozRequestAnimationFrame ||
183
+ w.webkitRequestAnimationFrame ||
184
+ w.msRequestAnimationFrame ||
185
+ function(callBack)
186
+ {
187
+ return w.setTimeout(callBack, 1000 / 60);
188
+ }
189
+ );
190
+
191
+ /* setup cancel for prefix or setTimeout if
192
+ not supported */
193
+ w.cancelAnimationFrame = (
194
+ w.cancelAnimationFrame ||
195
+ w.mozCancelAnimationFrame ||
196
+ function(requestID)
197
+ {
198
+ w.clearTimeout(requestID);
199
+ }
200
+ );
201
+ },
202
+
203
+ stop: function(element)
204
+ {
205
+ this.animating.stopPreviousAnimations(element);
206
+ }
207
+ };
208
+
209
+ /* we want to setup the animation frame to support
210
+ all browsers */
211
+ base.animations.setupAnimationFrame();
212
+
213
+ /*
214
+ Animation class
215
+
216
+ this will create a new animation object to animate
217
+ attr, css, or css method properties.
218
+
219
+ animations can update multiple properties in one
220
+ aniamtion.
221
+ @param (object) element
222
+ @param (object) settings
223
+ */
224
+ var Animation = base.Class.extend(
225
+ {
226
+ constructor: function(element, settings)
227
+ {
228
+ this.element = element;
229
+
230
+ /* this will track the animation properties being
231
+ animated */
232
+ this.movements = [];
233
+ this.setupMovements(settings);
234
+ },
235
+
236
+ setup: function()
237
+ {
238
+ this.setupMovements(settings);
239
+ },
240
+
241
+ addMovement: function(property)
242
+ {
243
+ this.movements.push(property);
244
+ },
245
+
246
+ setupMovements: function(settings)
247
+ {
248
+ var movement,
249
+ element = this.element,
250
+ self = this;
251
+
252
+ var addMovement = function(movementSettings)
253
+ {
254
+ movement = Movement.create(element, movementSettings);
255
+ self.addMovement(movement);
256
+ };
257
+
258
+ /* this will check if we have multiple properties to
259
+ add or only one property */
260
+ var property = settings.property;
261
+ if(base.isArray(property))
262
+ {
263
+ for(var i = 0, length = property.length; i < length; i++)
264
+ {
265
+ addMovement(property[i]);
266
+ }
267
+ }
268
+ else
269
+ {
270
+ addMovement(settings);
271
+ }
272
+ },
273
+
274
+ /* this will step the animation movements by the
275
+ delta.
276
+ @param (number) delta */
277
+ step: function(delta)
278
+ {
279
+ var movements = this.movements,
280
+ length = movements.length;
281
+ for(var i = 0; i < length; i++)
282
+ {
283
+ movements[i].step(delta);
284
+ }
285
+ }
286
+ });
287
+
288
+ /*
289
+ Value class
290
+
291
+ this will create a movement property value that can
292
+ update the property value when animated.
293
+
294
+ this will automatically get the units of the value
295
+ and check for value combining to inherit the start
296
+ value and add or remove the end value from the
297
+ start.
298
+
299
+ @param (object) settings
300
+ */
301
+ var Value = base.Class.extend(
302
+ {
303
+ constructor: function(settings)
304
+ {
305
+ this.value = null;
306
+ this.setup(settings);
307
+ },
308
+
309
+ setup: function(settings)
310
+ {
311
+ var value = this.value = this.createValue(settings);
312
+ /* we want to check if we are increasing or
313
+ decreasing the target */
314
+ value.increasing = this.isIncreasing(settings.end);
315
+ },
316
+
317
+ createValue: function(settings)
318
+ {
319
+ /* we need to get the end value with any extra data
320
+ to check for combining and to get the units */
321
+ var endValue = settings.end,
322
+ startValue = this.getValue(settings.start),
323
+ value = this.getValue(endValue);
324
+
325
+ return {
326
+ combining: this.checkCombind(endValue),
327
+ start: startValue,
328
+ end: value,
329
+ units: this.getUnits(endValue),
330
+ difference: (Math.abs(startValue - value))
331
+ };
332
+ },
333
+
334
+ /* this will get the units of the property being animated.
335
+ @param (string) text = the value being modified
336
+ @return (string) the type of units */
337
+ getUnits: function(text)
338
+ {
339
+ if(typeof text !== 'undefined')
340
+ {
341
+ text = this.getString(text);
342
+
343
+ /* we need to remove the numbers or plus or minus equals
344
+ to get the units */
345
+ var pattern = /([0-9.\-\+=])/g;
346
+ return text.replace(pattern, '');
347
+ }
348
+ return '';
349
+ },
350
+
351
+ checkCombind: function(end)
352
+ {
353
+ if(typeof end !== 'undefined')
354
+ {
355
+ end = this.getString(end);
356
+ /* we want to check if we have a plus or minus equals to
357
+ show that we are using the current position as the start */
358
+ var pattern = /(\+=|-=)/g,
359
+ matches = end.match(pattern);
360
+ if(matches)
361
+ {
362
+ return true;
363
+ }
364
+ }
365
+ return false;
366
+ },
367
+
368
+ /* this will convert any type to a string
369
+ @param (mixed) value = the value to convert
370
+ @return (string) the value string */
371
+ getString: function(value)
372
+ {
373
+ return (typeof value !== 'string')? value.toString() : value;
374
+ },
375
+
376
+ /* this will get the number from an value and remove
377
+ any other marks including chars.
378
+ @param (mixed) text = the text to get the value from
379
+ @return (number) the number value */
380
+ getValue: function(text)
381
+ {
382
+ if(typeof text !== 'undefined')
383
+ {
384
+ /* we need to remove any non numeric data from the value
385
+ and convert to number after */
386
+ var pattern = /(\+=|-=|[^0-9.-])/g;
387
+ text = this.getString(text);
388
+ return (text.replace(pattern, '') * 1);
389
+ }
390
+ return 0;
391
+ },
392
+
393
+ /* this will check if the element is increasing or decreasing the
394
+ target.
395
+ @return (bool) true or false */
396
+ isIncreasing: function(endValue)
397
+ {
398
+ /* we want to check if we are adding to the start or
399
+ just modifying the value */
400
+ var value = this.value;
401
+ var endTotal = value.end;
402
+ var startValue = value.start;
403
+ if(value.combining === true)
404
+ {
405
+ endTotal = (this.getString(endValue).indexOf("-") === -1)? (startValue + endTotal) : startValue - endTotal;
406
+ }
407
+ return (endTotal >= startValue)? true : false;
408
+ },
409
+
410
+ combindValue: function(delta)
411
+ {
412
+ return (this.value.end * delta);
413
+ },
414
+
415
+ calcValue: function(delta)
416
+ {
417
+ return (this.value.difference * delta);
418
+ },
419
+
420
+ /* this will setup theproper method to step the
421
+ value by checking for combining and currying
422
+ theproper function to step the value.
423
+ @param (number) delta
424
+ @return (number) the value step */
425
+ step: function(delta)
426
+ {
427
+ var step;
428
+ var value = this.value;
429
+ if(value.combining === true)
430
+ {
431
+ step = this.combindValue;
432
+ }
433
+ else
434
+ {
435
+ step = this.calcValue;
436
+ }
437
+ return (this.step = step).apply(this, base.listToArray(arguments));
438
+ },
439
+
440
+ update: function(delta)
441
+ {
442
+ var step = this.step(delta);
443
+ var value = this.value;
444
+
445
+ /* we want to check to add or subtract the step
446
+ by the increase prop */
447
+ return this.applyStep(value, step);
448
+ },
449
+
450
+ increaseValue: function(value, step)
451
+ {
452
+ var start = value.start;
453
+ return (start + step) + value.units;
454
+ },
455
+
456
+ decreaseValue: function(value, step)
457
+ {
458
+ var start = value.start;
459
+ return (start - step) + value.units;
460
+ },
461
+
462
+ /* this will setup the proper method to apply the
463
+ step by checking for increasing and currying
464
+ the proper function to applyu the step value.
465
+ @param (object) value
466
+ @return (number) the value step */
467
+ applyStep: function(value, step)
468
+ {
469
+ var applyStep = (value.increasing === true)? this.increaseValue : this.decreaseValue;
470
+ return (this.applyStep = applyStep).apply(this, base.listToArray(arguments));
471
+ }
472
+ });
473
+
474
+ /*
475
+ Movement class
476
+
477
+ this will create a movement object that can
478
+ update the property when animated. this is an abstract
479
+ class and should be extended to use.
480
+
481
+ @param (object) element
482
+ @param (object) settings
483
+ */
484
+ var Movement = base.Class.extend(
485
+ {
486
+ constructor: function(element, settings)
487
+ {
488
+ this.element = element;
489
+ this.property = null;
490
+ this.value = null;
491
+
492
+ this.setup(settings);
493
+ },
494
+
495
+ setup: function(settings)
496
+ {
497
+ this.setupProperty(settings);
498
+ },
499
+
500
+ /* this will return a new movement object by the
501
+ property type.
502
+ @param (object) element
503
+ @param (object) settings
504
+ @return (object) the new movement */
505
+ setupMovementType: function(element, settings)
506
+ {
507
+ var movement,
508
+ type = this.getType(element, settings);
509
+ switch(type)
510
+ {
511
+ case 'css':
512
+ movement = new CssMovement(element, settings);
513
+ break;
514
+ case 'attr':
515
+ movement = new AttrMovement(element, settings);
516
+ break;
517
+ }
518
+ return movement;
519
+ },
520
+
521
+ getType: function(element, settings)
522
+ {
523
+ return (element.style && settings.property in element.style)? 'css' : 'attr';
524
+ },
525
+
526
+ /* this will create a new value object for the
527
+ property value to be updated.
528
+ @param (object) settings
529
+ @return (object) the value object */
530
+ createValue: function(settings)
531
+ {
532
+ var values = this.getValue(settings);
533
+ return new Value(values);
534
+ },
535
+
536
+ /* this will get the start and end values of the
537
+ movement to be used to create a new value object.
538
+ @param (object) settings
539
+ @return (object) the start and end values */
540
+ getValue: function(settings)
541
+ {
542
+ var endValue = this.getEndValue(settings.endValue),
543
+ startValue = this.getStartValue(settings.startValue, endValue);
544
+
545
+ return {
546
+ start: startValue,
547
+ end: endValue
548
+ };
549
+ },
550
+
551
+ /* this will get start value of the property being animated.
552
+ @param (string) value = the value being modified
553
+ @return (string) the type of units */
554
+ getStartValue: function(value, end)
555
+ {
556
+ return value;
557
+ },
558
+
559
+ getEndValue: function(text)
560
+ {
561
+ return text;
562
+ },
563
+
564
+ setupProperty: function(settings)
565
+ {
566
+ this.property = settings.property;
567
+ this.value = this.createValue(settings);
568
+ },
569
+
570
+ /* this will update the value object
571
+ @param (number) delta
572
+ return (mixed) the proprety value */
573
+ updateValue: function(delta)
574
+ {
575
+ return this.value.update(delta);
576
+ },
577
+
578
+ step: function(delta)
579
+ {
580
+ var value = this.updateValue(delta);
581
+ this.update(value);
582
+ },
583
+
584
+ /* this should be overridden by the update
585
+ property type being animated.
586
+ @param (mixed) value */
587
+ update: function(value)
588
+ {
589
+
590
+ }
591
+ });
592
+
593
+ /* this is a static moethod that can create
594
+ anewinstance of amovement by thepreopty type.
595
+ @param (object) element
596
+ @param (object) settings
597
+ @return (object) the new movement */
598
+ Movement.create = function(element, settings)
599
+ {
600
+ return this.prototype.setupMovementType(element, settings);
601
+ };
602
+
603
+ /*
604
+ AttrMovement class
605
+
606
+ this will create an attr movement object that can
607
+ update the property when animated.
608
+
609
+ @param (object) element
610
+ @param (object) settings
611
+ */
612
+ var AttrMovement = Movement.extend(
613
+ {
614
+ constructor: function(element, settings)
615
+ {
616
+ Movement.call(this, element, settings);
617
+ this.filter = settings.filter;
618
+ },
619
+
620
+ /* this will get start value of the property being animated.
621
+ @param (string) value = the value being modified
622
+ @return (string) the type of units */
623
+ getStartValue: function(value, end)
624
+ {
625
+ var start = 0;
626
+ if(typeof value === 'undefined')
627
+ {
628
+ start = this.element[this.property];
629
+ }
630
+ else
631
+ {
632
+ start = this.getValue(value);
633
+ }
634
+ return start;
635
+ },
636
+
637
+ filterValue: function(value)
638
+ {
639
+ var filter;
640
+
641
+ var callBack = this.filter;
642
+ if(typeof callBack === 'function')
643
+ {
644
+ /* this will add the step to the value */
645
+ filter = function(value)
646
+ {
647
+ return callBack(value);
648
+ };
649
+ }
650
+ else
651
+ {
652
+ filter = function(value)
653
+ {
654
+ return value;
655
+ };
656
+ }
657
+ return (this.filterValue = filter).apply(this, base.listToArray(arguments));
658
+ },
659
+
660
+ update: function(value)
661
+ {
662
+ value = this.filterValue(value);
663
+ this.element[this.property] = value;
664
+ }
665
+ });
666
+
667
+ var CssMovement = Movement.extend(
668
+ {
669
+ constructor: function(element, settings)
670
+ {
671
+ this.style = element.style;
672
+ Movement.call(this, element, settings);
673
+ },
674
+
675
+ /* this will get start value of the property being animated.
676
+ @param (string) value = the value being modified
677
+ @return (string) the type of units */
678
+ getStartValue: function(value, end)
679
+ {
680
+ var start = 0;
681
+ if(typeof value === 'undefined')
682
+ {
683
+ var element = this.element,
684
+ property = this.property,
685
+ method = this.method;
686
+ if(method)
687
+ {
688
+ var values = base.css(element, property);
689
+ if(values !== 'none')
690
+ {
691
+ var cssPattern = new RegExp('(?:' + method + '\((.+)\))', 'g');
692
+ values.replace(cssPattern, function(fullMatch, params)
693
+ {
694
+ start = (typeof params === 'string')? params.split(',') : null;
695
+ });
696
+ }
697
+ else
698
+ {
699
+ var unit;
700
+ var pattern = /\d+/g;
701
+ var length = end.length;
702
+ start = [];
703
+ for(var i = 0; i < length; i++)
704
+ {
705
+ /* we want to ensure that we add the same units */
706
+ unit = end[i].replace(pattern, '');
707
+ start.push(0 + unit);
708
+ }
709
+ }
710
+ }
711
+ else
712
+ {
713
+ var params = base.css(element, property);
714
+ start = (typeof params === 'string')? params.split(' ') : null;
715
+ }
716
+ }
717
+ else
718
+ {
719
+ start = this.getCssValue(value);
720
+ }
721
+ return start;
722
+ },
723
+
724
+ getEndValue: function(text)
725
+ {
726
+ return this.getCssValue(text);
727
+ },
728
+
729
+ /* this will get the number from an value and remove
730
+ any other marks including chars.
731
+ @param (mixed) text = the text to get the value from
732
+ @return (number) the number value */
733
+ getCssValue: function(text)
734
+ {
735
+ var textType = typeof text;
736
+ if(textType !== 'undefined')
737
+ {
738
+ var value,
739
+ self = this;
740
+
741
+ if(textType === 'string')
742
+ {
743
+ /* this will check to setup the css value by
744
+ checking if we are using a css method
745
+ e.g. transform: translate3d() */
746
+ var cssPattern = /(?:(\w+\s*)\((.+)\))/g;
747
+ text.replace(cssPattern, function(fullMatch, method, params)
748
+ {
749
+ value = (typeof params === 'string')? params.split(',') : null;
750
+ self.setMethod(method);
751
+ });
752
+
753
+ if(value === undefined)
754
+ {
755
+ /* this will check to split by space to allow
756
+ short hand */
757
+ value = text.split(' ');
758
+ }
759
+ return value;
760
+ }
761
+ else
762
+ {
763
+ return text;
764
+ }
765
+ }
766
+ return 0;
767
+ },
768
+
769
+ /* this will create a new value object array for the
770
+ property values to be updated.
771
+ @param (object) settings
772
+ @return (array) the values array */
773
+ createValue: function(settings)
774
+ {
775
+ var valueArray = [];
776
+ var values = this.getValue(settings);
777
+ if(values)
778
+ {
779
+ if(base.isArray(values.end))
780
+ {
781
+ var start = values.start,
782
+ end = values.end;
783
+ for(var i = 0, length = end.length; i < length; i++)
784
+ {
785
+ valueArray.push(new Value({
786
+ start: start[i],
787
+ end: end[i]
788
+ }));
789
+ }
790
+ }
791
+ else
792
+ {
793
+ valueArray.push(new Value(values));
794
+ }
795
+ }
796
+ return valueArray;
797
+ },
798
+
799
+ setMethod: function(method)
800
+ {
801
+ if(typeof this.method !== 'string')
802
+ {
803
+ this.method = method;
804
+ }
805
+ },
806
+
807
+ updateValue: function(delta)
808
+ {
809
+ var valueArray = [];
810
+ var values = this.value;
811
+ if(values.length)
812
+ {
813
+ for(var i = 0, length = values.length; i < length; i++)
814
+ {
815
+ valueArray.push(values[i].update(delta));
816
+ }
817
+ }
818
+ return valueArray;
819
+ },
820
+
821
+ update: function(value)
822
+ {
823
+ var method = this.method;
824
+ if(method)
825
+ {
826
+ value = method + '(' + value.join(', ') + ')';
827
+ }
828
+ else
829
+ {
830
+ value = value.join(' ');
831
+ }
832
+ this.style[this.property] = value;
833
+ }
834
+ });
835
+
836
+ /*
837
+ AnimationController
838
+
839
+ this will create an animation controller object
840
+ that will animate a target property or properties
841
+ on an element over a duration.
842
+
843
+ @param (object) settings = the animation settings
844
+ @param [(function)] callBack = the function to call back
845
+ when the animation is done
846
+ */
847
+ var AnimationController = base.Class.extend(
848
+ {
849
+ constructor: function(settings, callBack)
850
+ {
851
+ /* this is the delay of the animation in milliseconds */
852
+ this.delay = settings.delay || 0;
853
+ this.delayTimer = null;
854
+ this.startTime = null;
855
+
856
+ /* this is the animation duration in milliseconds */
857
+ this.duration = settings.duration || 0;
858
+
859
+ this.element = this.getElement(settings.element);
860
+ this.status = 'stopped';
861
+ this.animation = null;
862
+
863
+ /* this will be the call back function to return
864
+ when the animation is complete or errors */
865
+ this.callBack = callBack;
866
+
867
+ /* this will setup the fps */
868
+ this.fps = settings.fps || 60;
869
+
870
+ /* this will setup the new animation object and start
871
+ the animation if all is correct or stop and return an
872
+ error */
873
+ this.setup(settings);
874
+ },
875
+
876
+ setup: function(settings)
877
+ {
878
+ this.animationCallBack = this.animate.bind(this);
879
+
880
+ var element = this.element;
881
+ if(typeof element === 'object')
882
+ {
883
+ /* we want to start the animation by the animation
884
+ delay settings */
885
+ var callBack = base.createCallBack(this, this.setupAnimation, [element, settings]);
886
+ this.delayTimer = window.setTimeout(callBack, this.delay);
887
+ }
888
+ else
889
+ {
890
+ /* we do not have an element or property to
891
+ animate so we wantto return an error */
892
+ this.updateStatus('error');
893
+ }
894
+ return this;
895
+ },
896
+
897
+ setupAnimation: function(element, settings)
898
+ {
899
+ this.animation = new Animation(element, settings);
900
+ this.start(settings);
901
+ },
902
+
903
+ /* this will start the animation by getting the start time
904
+ and starting the animation timer */
905
+ start: function()
906
+ {
907
+ /* this will track the time passed and the progress
908
+ of the animation */
909
+ this.startTime = new Date();
910
+ this.timePassed = 0;
911
+ this.progress = 0;
912
+ this.timer = null;
913
+
914
+ this.startTimer();
915
+ return this;
916
+ },
917
+
918
+ stop: function()
919
+ {
920
+ this.stopTimer();
921
+ return this;
922
+ },
923
+
924
+ /* this will get the element that is being used.
925
+ @param (mixed) element = the element selector or object
926
+ @return (object) the element */
927
+ getElement: function(element)
928
+ {
929
+ return (typeof element === 'string')? document.querySelector(element) : element;
930
+ },
931
+
932
+ /* this will get the delta to be used with the animation.
933
+ @return (number) the current delta */
934
+ delta: function(t)
935
+ {
936
+ var delta = 0;
937
+
938
+ switch(this.ease)
939
+ {
940
+ case 'easeInOut':
941
+ case 'easeInOutQuad':
942
+ delta = t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t;
943
+ break;
944
+ case 'easeIn':
945
+ case 'easeInQuad':
946
+ delta = (t * t);
947
+ break;
948
+ case 'easeInCubic':
949
+ delta = (t * t * t);
950
+ break;
951
+ case 'easeInQuart':
952
+ delta = (t * t * t * t);
953
+ break;
954
+ case 'easeInCirc':
955
+ delta = (1 - Math.sin(Math.acos(t)));
956
+ break;
957
+ case 'easeOut':
958
+ case 'easeOutQuad':
959
+ delta = (t * (2 - t));
960
+ break;
961
+ case 'easeOutCubic':
962
+ delta = ((--t) * t * t + 1);
963
+ break;
964
+ case 'easeOutQuart':
965
+ delta = (1 - (--t) * t * t * t);
966
+ break;
967
+ case 'linear':
968
+ delta = t;
969
+ break;
970
+ default:
971
+ delta = t;
972
+ }
973
+ return delta;
974
+ },
975
+
976
+ /* this will perform the animation on the element by
977
+ incrementally updating the element object property
978
+ by the timed progress. */
979
+ animate: function()
980
+ {
981
+ this.timePassed = new Date() - this.startTime;
982
+ var percent = this.timePassed / this.duration;
983
+ var progress = this.progress = (percent > 1)? 1 : percent;
984
+
985
+ var delta = this.delta(progress);
986
+ this.animation.step(delta);
987
+
988
+ /* if the progress is 1 the animation is complete */
989
+ if(progress >= 1)
990
+ {
991
+ this.stopTimer();
992
+ this.updateStatus('completed');
993
+ }
994
+ else
995
+ {
996
+ this.timer = window.requestAnimationFrame(this.animationCallBack);
997
+ }
998
+ },
999
+
1000
+ updateStatus: function(status)
1001
+ {
1002
+ var self = this;
1003
+ var action = function()
1004
+ {
1005
+ switch(status)
1006
+ {
1007
+ case 'started':
1008
+ break;
1009
+ case 'stopped':
1010
+ break;
1011
+ case 'completed':
1012
+ case 'error':
1013
+ self.checkCallBack();
1014
+ break;
1015
+ }
1016
+ };
1017
+
1018
+ /* we want to save the status and call the
1019
+ action function */
1020
+ this.status = status;
1021
+ action();
1022
+ },
1023
+
1024
+ checkCallBack: function()
1025
+ {
1026
+ var callBack = this.callBack;
1027
+ if(typeof callBack === 'function')
1028
+ {
1029
+ callBack.call(null, this.status);
1030
+ }
1031
+ },
1032
+
1033
+ /* this will start the animation by setting up the
1034
+ animation timer. */
1035
+ startTimer: function()
1036
+ {
1037
+ /* this will check to stop any previous timer before
1038
+ creating a new timer */
1039
+ this.stopTimer();
1040
+
1041
+ /* we want to call the animation first to not show a
1042
+ delay in the animation before the callback is called */
1043
+ this.updateStatus('started');
1044
+ this.animate();
1045
+ return this;
1046
+ },
1047
+
1048
+ /* this will stop the animation timer if still setup */
1049
+ stopTimer: function()
1050
+ {
1051
+ var w = window;
1052
+ if(this.timer)
1053
+ {
1054
+ w.cancelAnimationFrame(this.timer);
1055
+ this.updateStatus('stopped');
1056
+ }
1057
+
1058
+ if(this.delayTimer)
1059
+ {
1060
+ w.clearTimeout(this.delayTimer);
1061
+ }
1062
+ return this;
1063
+ }
1064
+ });
1065
+
1066
+ /* this will add an animation to an element.
1067
+ @param (object) paramsObj = the animation params
1068
+ @return (object) the animation object */
1069
+ base.extend.addAnimation = function(paramsObj)
1070
+ {
1071
+ return base.animations.add(paramsObj);
1072
+ };
1073
+
1074
+ /* this will stop all animations on an element.
1075
+ @param (object) element = the element */
1076
+ base.extend.stopAnimations = function(element)
1077
+ {
1078
+ base.animations.stop(element);
1079
+ };
1080
+ })();