[go: up one dir, main page]

Skip to content

Commit

Permalink
Ensure default delay, fix "pattern" error, create callback for option…
Browse files Browse the repository at this point in the history
…s to use
  • Loading branch information
Rycochet committed Jun 10, 2018
1 parent 6b961de commit 2bdd7c1
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 41 deletions.
2 changes: 1 addition & 1 deletion src/Velocity/tweens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ export function findPattern(parts: ReadonlyArray<string>, propertyName: string):
change = num[1] ? num[1][0] + unit : undefined,
changeOrUnit = change || unit;

if (!units.includes(changeOrUnit)) {
if (digits && !units.includes(changeOrUnit)) {
// Will be an empty string at the least.
units.push(changeOrUnit);
}
Expand Down
30 changes: 19 additions & 11 deletions src/velocityFn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,6 @@ export function Velocity(this: VelocityElements | void, ...argsList: any[]): Vel
* element's animations needs to be to the currently-running ones.
*/
animations: AnimationCall[],
/**
* Stagger delays the start of sequential elements in an animation.
*/
hasStagger: number | VelocityOptionFn<number> = 0,
/**
* The promise that is returned.
*/
Expand Down Expand Up @@ -321,10 +317,10 @@ export function Velocity(this: VelocityElements | void, ...argsList: any[]): Vel
options.mobileHA = true;
}
if (optionsMap.drag === true) {
options.drag = optionsMap.drag;
options.drag = true;
}
if (isNumber(optionsMap.stagger) || isFunction(optionsMap.stagger)) {
hasStagger = options.stagger = optionsMap.stagger;
options.stagger = optionsMap.stagger;
}
if (!isReverse) {
if (optionsMap["display"] != null) {
Expand Down Expand Up @@ -379,6 +375,7 @@ export function Velocity(this: VelocityElements | void, ...argsList: any[]): Vel
if (complete !== undefined) {
options.complete = complete;
}
options.delay = defaults.delay;
options.loop = defaults.loop;
options.repeat = options.repeatAgain = defaults.repeat;
}
Expand Down Expand Up @@ -433,15 +430,15 @@ export function Velocity(this: VelocityElements | void, ...argsList: any[]): Vel

options._total++;
animations.push(animation);
if (hasStagger) {
if (isFunction(hasStagger)) {
const num = hasStagger.call(element, index, elements.length, elements, "stagger");
if (options.stagger) {
if (isFunction(options.stagger)) {
const num = optionCallback(options.stagger, element, index, elements.length, elements, "stagger");

if (isNumber(num)) {
animation.delay = getValue(options.delay, defaults.delay) + num;
animation.delay = options.delay + num;
}
} else {
animation.delay = getValue(options.delay, defaults.delay) + (hasStagger * index);
animation.delay = options.delay + (options.stagger * index);
}
}
if (options.drag) {
Expand Down Expand Up @@ -476,3 +473,14 @@ export function Velocity(this: VelocityElements | void, ...argsList: any[]): Vel
/* Return the elements back to the call chain, with wrapped elements taking precedence in case Velocity was called via the $.fn. extension. */
return elements || promise as any;
}

/**
* Call an option callback in a try/catch block and report an error if needed.
*/
function optionCallback<T>(fn: VelocityOptionFn<T>, element: HTMLorSVGElement, index: number, length: number, elements: HTMLorSVGElement[], option: string): T {
try {
return fn.call(element, index, length, elements, option);
} catch (e) {
console.error(`VelocityJS: Exception when calling '${option}' callback:`, e);
}
}
32 changes: 19 additions & 13 deletions velocity.es5.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion velocity.es5.js.map

Large diffs are not rendered by default.

32 changes: 19 additions & 13 deletions velocity.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion velocity.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion velocity.min.js

Large diffs are not rendered by default.

0 comments on commit 2bdd7c1

Please sign in to comment.