Skip to content

Commit 2bdd7c1

Browse files
committed
Ensure default delay, fix "pattern" error, create callback for options to use
1 parent 6b961de commit 2bdd7c1

File tree

7 files changed

+61
-41
lines changed

7 files changed

+61
-41
lines changed

src/Velocity/tweens.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ export function findPattern(parts: ReadonlyArray<string>, propertyName: string):
219219
change = num[1] ? num[1][0] + unit : undefined,
220220
changeOrUnit = change || unit;
221221

222-
if (!units.includes(changeOrUnit)) {
222+
if (digits && !units.includes(changeOrUnit)) {
223223
// Will be an empty string at the least.
224224
units.push(changeOrUnit);
225225
}

src/velocityFn.ts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,6 @@ export function Velocity(this: VelocityElements | void, ...argsList: any[]): Vel
125125
* element's animations needs to be to the currently-running ones.
126126
*/
127127
animations: AnimationCall[],
128-
/**
129-
* Stagger delays the start of sequential elements in an animation.
130-
*/
131-
hasStagger: number | VelocityOptionFn<number> = 0,
132128
/**
133129
* The promise that is returned.
134130
*/
@@ -321,10 +317,10 @@ export function Velocity(this: VelocityElements | void, ...argsList: any[]): Vel
321317
options.mobileHA = true;
322318
}
323319
if (optionsMap.drag === true) {
324-
options.drag = optionsMap.drag;
320+
options.drag = true;
325321
}
326322
if (isNumber(optionsMap.stagger) || isFunction(optionsMap.stagger)) {
327-
hasStagger = options.stagger = optionsMap.stagger;
323+
options.stagger = optionsMap.stagger;
328324
}
329325
if (!isReverse) {
330326
if (optionsMap["display"] != null) {
@@ -379,6 +375,7 @@ export function Velocity(this: VelocityElements | void, ...argsList: any[]): Vel
379375
if (complete !== undefined) {
380376
options.complete = complete;
381377
}
378+
options.delay = defaults.delay;
382379
options.loop = defaults.loop;
383380
options.repeat = options.repeatAgain = defaults.repeat;
384381
}
@@ -433,15 +430,15 @@ export function Velocity(this: VelocityElements | void, ...argsList: any[]): Vel
433430

434431
options._total++;
435432
animations.push(animation);
436-
if (hasStagger) {
437-
if (isFunction(hasStagger)) {
438-
const num = hasStagger.call(element, index, elements.length, elements, "stagger");
433+
if (options.stagger) {
434+
if (isFunction(options.stagger)) {
435+
const num = optionCallback(options.stagger, element, index, elements.length, elements, "stagger");
439436

440437
if (isNumber(num)) {
441-
animation.delay = getValue(options.delay, defaults.delay) + num;
438+
animation.delay = options.delay + num;
442439
}
443440
} else {
444-
animation.delay = getValue(options.delay, defaults.delay) + (hasStagger * index);
441+
animation.delay = options.delay + (options.stagger * index);
445442
}
446443
}
447444
if (options.drag) {
@@ -476,3 +473,14 @@ export function Velocity(this: VelocityElements | void, ...argsList: any[]): Vel
476473
/* Return the elements back to the call chain, with wrapped elements taking precedence in case Velocity was called via the $.fn. extension. */
477474
return elements || promise as any;
478475
}
476+
477+
/**
478+
* Call an option callback in a try/catch block and report an error if needed.
479+
*/
480+
function optionCallback<T>(fn: VelocityOptionFn<T>, element: HTMLorSVGElement, index: number, length: number, elements: HTMLorSVGElement[], option: string): T {
481+
try {
482+
return fn.call(element, index, length, elements, option);
483+
} catch (e) {
484+
console.error(`VelocityJS: Exception when calling '${option}' callback:`, e);
485+
}
486+
}

velocity.es5.js

Lines changed: 19 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

velocity.es5.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

velocity.js

Lines changed: 19 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

velocity.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

velocity.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)