@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.
- package/base.min.js +1 -0
- package/es5/base.js +2968 -0
- package/es5/modules/ajax.js +663 -0
- package/es5/modules/animation.js +188 -0
- package/es5/modules/animations.js +1080 -0
- package/es5/modules/atom.js +65 -0
- package/es5/modules/component.js +1310 -0
- package/es5/modules/data-binder.js +1131 -0
- package/es5/modules/data.js +1808 -0
- package/es5/modules/date.js +525 -0
- package/es5/modules/form-validator.js +324 -0
- package/es5/modules/history.js +126 -0
- package/es5/modules/html-builder.js +461 -0
- package/es5/modules/layout.js +1679 -0
- package/es5/modules/mouse.js +124 -0
- package/es5/modules/nav-link.js +123 -0
- package/es5/modules/olderversions/animations-ease.js +1095 -0
- package/es5/modules/olderversions/animations-update.js +1048 -0
- package/es5/modules/olderversions/base-animations.js +636 -0
- package/es5/modules/olderversions/base-component-class.js +100 -0
- package/es5/modules/olderversions/base-data-binder-1.js +407 -0
- package/es5/modules/olderversions/base-data-binder-class.js +358 -0
- package/es5/modules/olderversions/base-layout-parser-class.js +172 -0
- package/es5/modules/olderversions/base-mode-1.js +777 -0
- package/es5/modules/olderversions/base-model-class.js +585 -0
- package/es5/modules/olderversions/data-binder/element-binding/base-data-binder-class.js +358 -0
- package/es5/modules/olderversions/data-binder/element-binding/base-model-class.js +585 -0
- package/es5/modules/olderversions/data-binder/model-binding/base-data-binder-class.js +353 -0
- package/es5/modules/olderversions/data-binder/model-binding/base-model-class.js +604 -0
- package/es5/modules/olderversions/data-binder-update-watcher.js +640 -0
- package/es5/modules/olderversions/data-tracker.js +187 -0
- package/es5/modules/olderversions/event-update.js +666 -0
- package/es5/modules/olderversions/nav-link.js +119 -0
- package/es5/modules/olderversions/router-with-templates-1.js +785 -0
- package/es5/modules/olderversions/router-with-templates.js +701 -0
- package/es5/modules/prototypes/ajax.js +657 -0
- package/es5/modules/prototypes/atom.js +65 -0
- package/es5/modules/prototypes/component.js +972 -0
- package/es5/modules/prototypes/data-binder.js +1089 -0
- package/es5/modules/prototypes/data.js +1290 -0
- package/es5/modules/prototypes/html-builder.js +414 -0
- package/es5/modules/prototypes/layout.js +879 -0
- package/es5/modules/router.js +1680 -0
- package/es5/modules/state.js +274 -0
- package/es6/.jshintrc +3 -0
- package/es6/base.js +41 -0
- package/es6/core.js +1 -0
- package/es6/data-tracker.js +351 -0
- package/es6/events.js +602 -0
- package/es6/legacy/es5/base.js +2968 -0
- package/es6/legacy/es5/modules/ajax.js +663 -0
- package/es6/legacy/es5/modules/animation.js +188 -0
- package/es6/legacy/es5/modules/animations.js +1080 -0
- package/es6/legacy/es5/modules/atom.js +65 -0
- package/es6/legacy/es5/modules/component.js +1310 -0
- package/es6/legacy/es5/modules/data-binder.js +1131 -0
- package/es6/legacy/es5/modules/data.js +1808 -0
- package/es6/legacy/es5/modules/date.js +525 -0
- package/es6/legacy/es5/modules/form-validator.js +324 -0
- package/es6/legacy/es5/modules/history.js +126 -0
- package/es6/legacy/es5/modules/html-builder.js +461 -0
- package/es6/legacy/es5/modules/layout.js +1679 -0
- package/es6/legacy/es5/modules/mouse.js +124 -0
- package/es6/legacy/es5/modules/nav-link.js +123 -0
- package/es6/legacy/es5/modules/olderversions/animations-ease.js +1095 -0
- package/es6/legacy/es5/modules/olderversions/animations-update.js +1048 -0
- package/es6/legacy/es5/modules/olderversions/base-animations.js +636 -0
- package/es6/legacy/es5/modules/olderversions/base-component-class.js +100 -0
- package/es6/legacy/es5/modules/olderversions/base-data-binder-1.js +407 -0
- package/es6/legacy/es5/modules/olderversions/base-data-binder-class.js +358 -0
- package/es6/legacy/es5/modules/olderversions/base-layout-parser-class.js +172 -0
- package/es6/legacy/es5/modules/olderversions/base-mode-1.js +777 -0
- package/es6/legacy/es5/modules/olderversions/base-model-class.js +585 -0
- package/es6/legacy/es5/modules/olderversions/data-binder/element-binding/base-data-binder-class.js +358 -0
- package/es6/legacy/es5/modules/olderversions/data-binder/element-binding/base-model-class.js +585 -0
- package/es6/legacy/es5/modules/olderversions/data-binder/model-binding/base-data-binder-class.js +353 -0
- package/es6/legacy/es5/modules/olderversions/data-binder/model-binding/base-model-class.js +604 -0
- package/es6/legacy/es5/modules/olderversions/data-binder-update-watcher.js +640 -0
- package/es6/legacy/es5/modules/olderversions/data-tracker.js +187 -0
- package/es6/legacy/es5/modules/olderversions/event-update.js +666 -0
- package/es6/legacy/es5/modules/olderversions/nav-link.js +119 -0
- package/es6/legacy/es5/modules/olderversions/router-with-templates-1.js +785 -0
- package/es6/legacy/es5/modules/olderversions/router-with-templates.js +701 -0
- package/es6/legacy/es5/modules/prototypes/ajax.js +657 -0
- package/es6/legacy/es5/modules/prototypes/atom.js +65 -0
- package/es6/legacy/es5/modules/prototypes/component.js +972 -0
- package/es6/legacy/es5/modules/prototypes/data-binder.js +1089 -0
- package/es6/legacy/es5/modules/prototypes/data.js +1290 -0
- package/es6/legacy/es5/modules/prototypes/html-builder.js +414 -0
- package/es6/legacy/es5/modules/prototypes/layout.js +879 -0
- package/es6/legacy/es5/modules/router.js +1680 -0
- package/es6/legacy/es5/modules/state.js +274 -0
- package/es6/main.js +1331 -0
- package/es6/modules/ajax/ajax.js +514 -0
- package/es6/modules/animation/animation.js +236 -0
- package/es6/modules/animations/animation-controller.js +231 -0
- package/es6/modules/animations/animation.js +64 -0
- package/es6/modules/animations/attr-movement.js +66 -0
- package/es6/modules/animations/css-movement.js +170 -0
- package/es6/modules/animations/movement.js +131 -0
- package/es6/modules/animations/value.js +187 -0
- package/es6/modules/atom/atom.js +54 -0
- package/es6/modules/component/component.js +230 -0
- package/es6/modules/component/event-helper.js +119 -0
- package/es6/modules/component/jot.js +144 -0
- package/es6/modules/component/state-helper.js +262 -0
- package/es6/modules/component/unit.js +551 -0
- package/es6/modules/data/attrs.js +40 -0
- package/es6/modules/data/basic-data.js +500 -0
- package/es6/modules/data/data-utils.js +29 -0
- package/es6/modules/data/data.js +3 -0
- package/es6/modules/data/deep-data.js +541 -0
- package/es6/modules/data/model-service.js +528 -0
- package/es6/modules/data/model.js +133 -0
- package/es6/modules/data/simple-data.js +33 -0
- package/es6/modules/data-binder/connection-tracker.js +113 -0
- package/es6/modules/data-binder/connection.js +16 -0
- package/es6/modules/data-binder/data-binder.js +352 -0
- package/es6/modules/data-binder/data-pub-sub.js +141 -0
- package/es6/modules/data-binder/data-source.js +56 -0
- package/es6/modules/data-binder/element-source.js +219 -0
- package/es6/modules/data-binder/one-way-connection.js +46 -0
- package/es6/modules/data-binder/one-way-source.js +43 -0
- package/es6/modules/data-binder/source.js +36 -0
- package/es6/modules/data-binder/two-way-connection.js +75 -0
- package/es6/modules/data-binder/two-way-source.js +41 -0
- package/es6/modules/date/date.js +544 -0
- package/es6/modules/history/history.js +89 -0
- package/es6/modules/html-builder/html-builder.js +434 -0
- package/es6/modules/import/import.js +390 -0
- package/es6/modules/layout/layout-builder.js +1269 -0
- package/es6/modules/layout/layout-parser.js +134 -0
- package/es6/modules/layout/watcher-helper.js +282 -0
- package/es6/modules/mouse/mouse.js +114 -0
- package/es6/modules/router/component-helper.js +163 -0
- package/es6/modules/router/history-controller.js +216 -0
- package/es6/modules/router/nav-link.js +124 -0
- package/es6/modules/router/route.js +401 -0
- package/es6/modules/router/router.js +789 -0
- package/es6/modules/router/utils.js +31 -0
- package/es6/modules/state/state-target.js +91 -0
- package/es6/modules/state/state.js +171 -0
- package/es6/package-lock.json +13 -0
- package/es6/package.json +28 -0
- package/es6/shared/objects.js +99 -0
- package/legacy/es5/base.js +2968 -0
- package/legacy/es5/modules/ajax.js +663 -0
- package/legacy/es5/modules/animation.js +188 -0
- package/legacy/es5/modules/animations.js +1080 -0
- package/legacy/es5/modules/atom.js +65 -0
- package/legacy/es5/modules/component.js +1310 -0
- package/legacy/es5/modules/data-binder.js +1131 -0
- package/legacy/es5/modules/data.js +1808 -0
- package/legacy/es5/modules/date.js +525 -0
- package/legacy/es5/modules/form-validator.js +324 -0
- package/legacy/es5/modules/history.js +126 -0
- package/legacy/es5/modules/html-builder.js +461 -0
- package/legacy/es5/modules/layout.js +1679 -0
- package/legacy/es5/modules/mouse.js +124 -0
- package/legacy/es5/modules/nav-link.js +123 -0
- package/legacy/es5/modules/olderversions/animations-ease.js +1095 -0
- package/legacy/es5/modules/olderversions/animations-update.js +1048 -0
- package/legacy/es5/modules/olderversions/base-animations.js +636 -0
- package/legacy/es5/modules/olderversions/base-component-class.js +100 -0
- package/legacy/es5/modules/olderversions/base-data-binder-1.js +407 -0
- package/legacy/es5/modules/olderversions/base-data-binder-class.js +358 -0
- package/legacy/es5/modules/olderversions/base-layout-parser-class.js +172 -0
- package/legacy/es5/modules/olderversions/base-mode-1.js +777 -0
- package/legacy/es5/modules/olderversions/base-model-class.js +585 -0
- package/legacy/es5/modules/olderversions/data-binder/element-binding/base-data-binder-class.js +358 -0
- package/legacy/es5/modules/olderversions/data-binder/element-binding/base-model-class.js +585 -0
- package/legacy/es5/modules/olderversions/data-binder/model-binding/base-data-binder-class.js +353 -0
- package/legacy/es5/modules/olderversions/data-binder/model-binding/base-model-class.js +604 -0
- package/legacy/es5/modules/olderversions/data-binder-update-watcher.js +640 -0
- package/legacy/es5/modules/olderversions/data-tracker.js +187 -0
- package/legacy/es5/modules/olderversions/event-update.js +666 -0
- package/legacy/es5/modules/olderversions/nav-link.js +119 -0
- package/legacy/es5/modules/olderversions/router-with-templates-1.js +785 -0
- package/legacy/es5/modules/olderversions/router-with-templates.js +701 -0
- package/legacy/es5/modules/prototypes/ajax.js +657 -0
- package/legacy/es5/modules/prototypes/atom.js +65 -0
- package/legacy/es5/modules/prototypes/component.js +972 -0
- package/legacy/es5/modules/prototypes/data-binder.js +1089 -0
- package/legacy/es5/modules/prototypes/data.js +1290 -0
- package/legacy/es5/modules/prototypes/html-builder.js +414 -0
- package/legacy/es5/modules/prototypes/layout.js +879 -0
- package/legacy/es5/modules/router.js +1680 -0
- package/legacy/es5/modules/state.js +274 -0
- package/package.json +8 -3
- package/update +16 -0
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import {base} from '../../core.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* This will remove a class and hide an element.
|
|
5
|
+
*
|
|
6
|
+
* @param {object} obj
|
|
7
|
+
* @param {string} animationClass
|
|
8
|
+
* @param {function} callBack
|
|
9
|
+
*/
|
|
10
|
+
const removeClassAndHide = (obj, animationClass, callBack) =>
|
|
11
|
+
{
|
|
12
|
+
obj.style.display = 'none';
|
|
13
|
+
removeAnimationClass(obj, animationClass, callBack);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* This will remove a class when the animation is finished.
|
|
18
|
+
*
|
|
19
|
+
* @param {object} obj
|
|
20
|
+
* @param {string} animationClass
|
|
21
|
+
* @param {function} callBack
|
|
22
|
+
*/
|
|
23
|
+
const removeAnimationClass = (obj, animationClass, callBack) =>
|
|
24
|
+
{
|
|
25
|
+
if(typeof callBack === 'function')
|
|
26
|
+
{
|
|
27
|
+
callBack.call();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
base.removeClass(obj, animationClass);
|
|
31
|
+
animate.animating.remove(obj);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const getElement = (element) =>
|
|
35
|
+
{
|
|
36
|
+
return (typeof element === 'string')? document.getElementById(element) : element;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/* this will add and remove css animations */
|
|
40
|
+
export const animate =
|
|
41
|
+
{
|
|
42
|
+
/* this class tracks all objects being animated and can
|
|
43
|
+
add and remove them when completed */
|
|
44
|
+
animating:
|
|
45
|
+
{
|
|
46
|
+
/**
|
|
47
|
+
* @param array objects
|
|
48
|
+
*/
|
|
49
|
+
objects: [],
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* This will add an animation.
|
|
53
|
+
*
|
|
54
|
+
* @param {object} object
|
|
55
|
+
* @param {string} className
|
|
56
|
+
* @param {int} timer
|
|
57
|
+
*/
|
|
58
|
+
add(object, className, timer)
|
|
59
|
+
{
|
|
60
|
+
if(!object)
|
|
61
|
+
{
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
this.stopPreviousAnimations(object);
|
|
66
|
+
this.objects.push({
|
|
67
|
+
object,
|
|
68
|
+
className,
|
|
69
|
+
timer
|
|
70
|
+
});
|
|
71
|
+
},
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* This will remove an animation from an element.
|
|
75
|
+
*
|
|
76
|
+
* @param {object} object
|
|
77
|
+
* @param {string} removeClass
|
|
78
|
+
*/
|
|
79
|
+
remove(object, removeClass)
|
|
80
|
+
{
|
|
81
|
+
if(!object)
|
|
82
|
+
{
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
let animations = this.checkAnimating(object);
|
|
87
|
+
if(animations === false)
|
|
88
|
+
{
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
let animation, indexNumber,
|
|
93
|
+
objects = this.objects;
|
|
94
|
+
for(var i = 0, maxLength = animations.length; i < maxLength; i++)
|
|
95
|
+
{
|
|
96
|
+
animation = animations[i];
|
|
97
|
+
/* we want to stop the timer */
|
|
98
|
+
this.stopTimer(animation);
|
|
99
|
+
|
|
100
|
+
if(removeClass)
|
|
101
|
+
{
|
|
102
|
+
/* we want to remove the className */
|
|
103
|
+
base.removeClass(animation.object, animation.className);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/* we want to remove the animation fron the object array */
|
|
107
|
+
//var indexNumber = this.objects.indexOf(animation);
|
|
108
|
+
indexNumber = objects.indexOf(animation);
|
|
109
|
+
if(indexNumber > -1)
|
|
110
|
+
{
|
|
111
|
+
objects.splice(indexNumber, 1);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* This will stop an animation timer.
|
|
118
|
+
* @param {object} animation
|
|
119
|
+
*/
|
|
120
|
+
stopTimer(animation)
|
|
121
|
+
{
|
|
122
|
+
if(animation)
|
|
123
|
+
{
|
|
124
|
+
let timer = animation.timer;
|
|
125
|
+
window.clearTimeout(timer);
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* This will check if the element is animating.
|
|
131
|
+
* @param {object} obj
|
|
132
|
+
* @return {(array|bool)}
|
|
133
|
+
*/
|
|
134
|
+
checkAnimating(obj)
|
|
135
|
+
{
|
|
136
|
+
let animation,
|
|
137
|
+
animationArray = [];
|
|
138
|
+
|
|
139
|
+
/* we want to get any timers set for our object */
|
|
140
|
+
let objects = this.objects;
|
|
141
|
+
for(var i = 0, maxLength = objects.length; i < maxLength; i++)
|
|
142
|
+
{
|
|
143
|
+
animation = objects[i];
|
|
144
|
+
if(animation.object === obj)
|
|
145
|
+
{
|
|
146
|
+
animationArray.push(animation);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return (animationArray.length > 0)? animationArray : false;
|
|
151
|
+
},
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* This will stop previous animations still animating.
|
|
155
|
+
* @param {object} obj
|
|
156
|
+
*/
|
|
157
|
+
stopPreviousAnimations(obj)
|
|
158
|
+
{
|
|
159
|
+
this.remove(obj, 1);
|
|
160
|
+
},
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* This will reset the objects.
|
|
164
|
+
*/
|
|
165
|
+
reset()
|
|
166
|
+
{
|
|
167
|
+
this.objects = [];
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* This will create an animation.
|
|
173
|
+
*
|
|
174
|
+
* @param {object} obj
|
|
175
|
+
* @param {string} animationClass
|
|
176
|
+
* @param {int} duration
|
|
177
|
+
* @param {function} callBack
|
|
178
|
+
* @param {funtion} endCallBack
|
|
179
|
+
*/
|
|
180
|
+
create(obj, animationClass, duration, callBack, endCallBack)
|
|
181
|
+
{
|
|
182
|
+
let animationCallBack = base.createCallBack(null, callBack, [obj, animationClass, endCallBack]);
|
|
183
|
+
|
|
184
|
+
let timer = window.setTimeout(animationCallBack, duration);
|
|
185
|
+
this.animating.add(obj, animationClass, timer);
|
|
186
|
+
},
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* This will add an animation then hide the element.
|
|
190
|
+
*
|
|
191
|
+
* @param {object} object
|
|
192
|
+
* @param {string} animationClass
|
|
193
|
+
* @param {int} duration
|
|
194
|
+
* @param {function} endCallBack
|
|
195
|
+
*/
|
|
196
|
+
hide(object, animationClass, duration, endCallBack)
|
|
197
|
+
{
|
|
198
|
+
let obj = getElement(object);
|
|
199
|
+
base.addClass(obj, animationClass);
|
|
200
|
+
|
|
201
|
+
this.create(obj, animationClass, duration, removeClassAndHide, endCallBack);
|
|
202
|
+
},
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* This will add an animation then show the element.
|
|
206
|
+
*
|
|
207
|
+
* @param {object} object
|
|
208
|
+
* @param {string} animationClass
|
|
209
|
+
* @param {int} duration
|
|
210
|
+
* @param {function} endCallBack
|
|
211
|
+
*/
|
|
212
|
+
show(object, animationClass, duration, endCallBack)
|
|
213
|
+
{
|
|
214
|
+
let obj = getElement(object);
|
|
215
|
+
base.addClass(obj, animationClass);
|
|
216
|
+
obj.style.display = 'block';
|
|
217
|
+
|
|
218
|
+
this.create(obj, animationClass, duration, removeAnimationClass, endCallBack);
|
|
219
|
+
},
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* This will add an animation to the element.
|
|
223
|
+
*
|
|
224
|
+
* @param {object} object
|
|
225
|
+
* @param {string} animationClass
|
|
226
|
+
* @param {int} duration
|
|
227
|
+
* @param {function} endCallBack
|
|
228
|
+
*/
|
|
229
|
+
set(object, animationClass, duration, endCallBack)
|
|
230
|
+
{
|
|
231
|
+
let obj = getElement(object);
|
|
232
|
+
base.addClass(obj, animationClass);
|
|
233
|
+
|
|
234
|
+
this.create(obj, animationClass, duration, removeAnimationClass, endCallBack);
|
|
235
|
+
}
|
|
236
|
+
};
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import {Animation} from './animation.js';
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
AnimationController
|
|
5
|
+
|
|
6
|
+
this will create an animation controller object
|
|
7
|
+
that will animate a target property or properties
|
|
8
|
+
on an element over a duration.
|
|
9
|
+
|
|
10
|
+
@param (object) settings = the animation settings
|
|
11
|
+
@param [(function)] callBack = the function to call back
|
|
12
|
+
when the animation is done
|
|
13
|
+
*/
|
|
14
|
+
export class AnimationController
|
|
15
|
+
{
|
|
16
|
+
constructor(settings, callBack)
|
|
17
|
+
{
|
|
18
|
+
/* this is the delay of the animation in milliseconds */
|
|
19
|
+
this.delay = settings.delay || 0;
|
|
20
|
+
this.delayTimer = null;
|
|
21
|
+
this.startTime = null;
|
|
22
|
+
|
|
23
|
+
/* this is the animation duration in milliseconds */
|
|
24
|
+
this.duration = settings.duration || 0;
|
|
25
|
+
|
|
26
|
+
this.element = this.getElement(settings.element);
|
|
27
|
+
this.status = 'stopped';
|
|
28
|
+
this.animation = null;
|
|
29
|
+
|
|
30
|
+
/* this will be the call back function to return
|
|
31
|
+
when the animation is complete or errors */
|
|
32
|
+
this.callBack = callBack;
|
|
33
|
+
|
|
34
|
+
/* this will setup the fps */
|
|
35
|
+
this.fps = settings.fps || 60;
|
|
36
|
+
|
|
37
|
+
/* this will setup the new animation object and start
|
|
38
|
+
the animation if all is correct or stop and return an
|
|
39
|
+
error */
|
|
40
|
+
this.setup(settings);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
setup(settings)
|
|
44
|
+
{
|
|
45
|
+
this.animationCallBack = this.animate.bind(this);
|
|
46
|
+
|
|
47
|
+
let element = this.element;
|
|
48
|
+
if(typeof element === 'object')
|
|
49
|
+
{
|
|
50
|
+
/* we want to start the animation by the animation
|
|
51
|
+
delay settings */
|
|
52
|
+
let callBack = this.setupAnimation.bind(this, element, settings);
|
|
53
|
+
this.delayTimer = window.setTimeout(callBack, this.delay);
|
|
54
|
+
}
|
|
55
|
+
else
|
|
56
|
+
{
|
|
57
|
+
/* we do not have an element or property to
|
|
58
|
+
animate so we wantto return an error */
|
|
59
|
+
this.updateStatus('error');
|
|
60
|
+
}
|
|
61
|
+
return this;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
setupAnimation(element, settings)
|
|
65
|
+
{
|
|
66
|
+
this.animation = new Animation(element, settings);
|
|
67
|
+
this.start(settings);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/* this will start the animation by getting the start time
|
|
71
|
+
and starting the animation timer */
|
|
72
|
+
start()
|
|
73
|
+
{
|
|
74
|
+
/* this will track the time passed and the progress
|
|
75
|
+
of the animation */
|
|
76
|
+
this.startTime = new Date();
|
|
77
|
+
this.timePassed = 0;
|
|
78
|
+
this.progress = 0;
|
|
79
|
+
this.timer = null;
|
|
80
|
+
|
|
81
|
+
this.startTimer();
|
|
82
|
+
return this;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
stop()
|
|
86
|
+
{
|
|
87
|
+
this.stopTimer();
|
|
88
|
+
return this;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/* this will get the element that is being used.
|
|
92
|
+
@param (mixed) element = the element selector or object
|
|
93
|
+
@return (object) the element */
|
|
94
|
+
getElement(element)
|
|
95
|
+
{
|
|
96
|
+
return (typeof element === 'string')? document.querySelector(element) : element;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/* this will get the delta to be used with the animation.
|
|
100
|
+
@return (number) the current delta */
|
|
101
|
+
delta(t)
|
|
102
|
+
{
|
|
103
|
+
let delta = 0;
|
|
104
|
+
|
|
105
|
+
switch(this.ease)
|
|
106
|
+
{
|
|
107
|
+
case 'easeInOut':
|
|
108
|
+
case 'easeInOutQuad':
|
|
109
|
+
delta = t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t;
|
|
110
|
+
break;
|
|
111
|
+
case 'easeIn':
|
|
112
|
+
case 'easeInQuad':
|
|
113
|
+
delta = (t * t);
|
|
114
|
+
break;
|
|
115
|
+
case 'easeInCubic':
|
|
116
|
+
delta = (t * t * t);
|
|
117
|
+
break;
|
|
118
|
+
case 'easeInQuart':
|
|
119
|
+
delta = (t * t * t * t);
|
|
120
|
+
break;
|
|
121
|
+
case 'easeInCirc':
|
|
122
|
+
delta = (1 - Math.sin(Math.acos(t)));
|
|
123
|
+
break;
|
|
124
|
+
case 'easeOut':
|
|
125
|
+
case 'easeOutQuad':
|
|
126
|
+
delta = (t * (2 - t));
|
|
127
|
+
break;
|
|
128
|
+
case 'easeOutCubic':
|
|
129
|
+
delta = ((--t) * t * t + 1);
|
|
130
|
+
break;
|
|
131
|
+
case 'easeOutQuart':
|
|
132
|
+
delta = (1 - (--t) * t * t * t);
|
|
133
|
+
break;
|
|
134
|
+
case 'linear':
|
|
135
|
+
delta = t;
|
|
136
|
+
break;
|
|
137
|
+
default:
|
|
138
|
+
delta = t;
|
|
139
|
+
}
|
|
140
|
+
return delta;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/* this will perform the animation on the element by
|
|
144
|
+
incrementally updating the element object property
|
|
145
|
+
by the timed progress. */
|
|
146
|
+
animate()
|
|
147
|
+
{
|
|
148
|
+
this.timePassed = new Date() - this.startTime;
|
|
149
|
+
|
|
150
|
+
let percent = this.timePassed / this.duration,
|
|
151
|
+
progress = this.progress = (percent > 1)? 1 : percent;
|
|
152
|
+
|
|
153
|
+
let delta = this.delta(progress);
|
|
154
|
+
this.animation.step(delta);
|
|
155
|
+
|
|
156
|
+
/* if the progress is 1 the animation is complete */
|
|
157
|
+
if(progress >= 1)
|
|
158
|
+
{
|
|
159
|
+
this.stopTimer();
|
|
160
|
+
this.updateStatus('completed');
|
|
161
|
+
}
|
|
162
|
+
else
|
|
163
|
+
{
|
|
164
|
+
this.timer = window.requestAnimationFrame(this.animationCallBack);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
updateStatus(status)
|
|
169
|
+
{
|
|
170
|
+
let action = () =>
|
|
171
|
+
{
|
|
172
|
+
switch(status)
|
|
173
|
+
{
|
|
174
|
+
case 'started':
|
|
175
|
+
break;
|
|
176
|
+
case 'stopped':
|
|
177
|
+
break;
|
|
178
|
+
case 'completed':
|
|
179
|
+
case 'error':
|
|
180
|
+
this.checkCallBack();
|
|
181
|
+
break;
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
/* we want to save the status and call the
|
|
186
|
+
action function */
|
|
187
|
+
this.status = status;
|
|
188
|
+
action();
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
checkCallBack()
|
|
192
|
+
{
|
|
193
|
+
let callBack = this.callBack;
|
|
194
|
+
if(typeof callBack === 'function')
|
|
195
|
+
{
|
|
196
|
+
callBack(this.status);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/* this will start the animation by setting up the
|
|
201
|
+
animation timer. */
|
|
202
|
+
startTimer()
|
|
203
|
+
{
|
|
204
|
+
/* this will check to stop any previous timer before
|
|
205
|
+
creating a new timer */
|
|
206
|
+
this.stopTimer();
|
|
207
|
+
|
|
208
|
+
/* we want to call the animation first to not show a
|
|
209
|
+
delay in the animation before the callback is called */
|
|
210
|
+
this.updateStatus('started');
|
|
211
|
+
this.animate();
|
|
212
|
+
return this;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/* this will stop the animation timer if still setup */
|
|
216
|
+
stopTimer()
|
|
217
|
+
{
|
|
218
|
+
var w = window;
|
|
219
|
+
if(this.timer)
|
|
220
|
+
{
|
|
221
|
+
w.cancelAnimationFrame(this.timer);
|
|
222
|
+
this.updateStatus('stopped');
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
if(this.delayTimer)
|
|
226
|
+
{
|
|
227
|
+
w.clearTimeout(this.delayTimer);
|
|
228
|
+
}
|
|
229
|
+
return this;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import {Movement} from './movement.js';
|
|
2
|
+
|
|
3
|
+
export class Animation
|
|
4
|
+
{
|
|
5
|
+
constructor(element, settings)
|
|
6
|
+
{
|
|
7
|
+
this.element = element;
|
|
8
|
+
|
|
9
|
+
/* this will track the animation properties being
|
|
10
|
+
animated */
|
|
11
|
+
this.movements = [];
|
|
12
|
+
this.setupMovements(settings);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
setup()
|
|
16
|
+
{
|
|
17
|
+
this.setupMovements(settings);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
addMovement(property)
|
|
21
|
+
{
|
|
22
|
+
this.movements.push(property);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
setupMovements(settings)
|
|
26
|
+
{
|
|
27
|
+
let movement,
|
|
28
|
+
element = this.element;
|
|
29
|
+
|
|
30
|
+
const addMovement = (movementSettings) =>
|
|
31
|
+
{
|
|
32
|
+
movement = Movement.create(element, movementSettings);
|
|
33
|
+
this.addMovement(movement);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/* this will check if we have multiple properties to
|
|
37
|
+
add or only one property */
|
|
38
|
+
let property = settings.property;
|
|
39
|
+
if(Array.isArray(property))
|
|
40
|
+
{
|
|
41
|
+
for(var i = 0, length = property.length; i < length; i++)
|
|
42
|
+
{
|
|
43
|
+
addMovement(property[i]);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
else
|
|
47
|
+
{
|
|
48
|
+
addMovement(settings);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/* this will step the animation movements by the
|
|
53
|
+
delta.
|
|
54
|
+
@param (number) delta */
|
|
55
|
+
step(delta)
|
|
56
|
+
{
|
|
57
|
+
let movements = this.movements,
|
|
58
|
+
length = movements.length;
|
|
59
|
+
for(var i = 0; i < length; i++)
|
|
60
|
+
{
|
|
61
|
+
movements[i].step(delta);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import {Movement} from './movement.js';
|
|
2
|
+
import {base} from '../../core.js';
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
AttrMovement class
|
|
6
|
+
|
|
7
|
+
this will create an attr movement object that can
|
|
8
|
+
update the property when animated.
|
|
9
|
+
|
|
10
|
+
@param (object) element
|
|
11
|
+
@param (object) settings
|
|
12
|
+
*/
|
|
13
|
+
export class AttrMovement extends Movement
|
|
14
|
+
{
|
|
15
|
+
constructor(element, settings)
|
|
16
|
+
{
|
|
17
|
+
super(element, settings);
|
|
18
|
+
this.filter = settings.filter;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/* this will get start value of the property being animated.
|
|
22
|
+
@param (string) value = the value being modified
|
|
23
|
+
@return (string) the type of units */
|
|
24
|
+
getStartValue(value, end)
|
|
25
|
+
{
|
|
26
|
+
let start = 0;
|
|
27
|
+
if(typeof value === 'undefined')
|
|
28
|
+
{
|
|
29
|
+
start = this.element[this.property];
|
|
30
|
+
}
|
|
31
|
+
else
|
|
32
|
+
{
|
|
33
|
+
start = this.getValue(value);
|
|
34
|
+
}
|
|
35
|
+
return start;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
filterValue(value)
|
|
39
|
+
{
|
|
40
|
+
let filter,
|
|
41
|
+
|
|
42
|
+
callBack = this.filter;
|
|
43
|
+
if(typeof callBack === 'function')
|
|
44
|
+
{
|
|
45
|
+
/* this will add the step to the value */
|
|
46
|
+
filter = function(value)
|
|
47
|
+
{
|
|
48
|
+
return callBack(value);
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
else
|
|
52
|
+
{
|
|
53
|
+
filter = function(value)
|
|
54
|
+
{
|
|
55
|
+
return value;
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
return (this.filterValue = filter).apply(this, base.listToArray(arguments));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
update(value)
|
|
62
|
+
{
|
|
63
|
+
value = this.filterValue(value);
|
|
64
|
+
this.element[this.property] = value;
|
|
65
|
+
}
|
|
66
|
+
}
|