Skip to content

Commit

Permalink
Utility function w/ sequences fix
Browse files Browse the repository at this point in the history
Fixes sequences with raw DOM elements and utility function. Closes
#247. Closes #249. Thanks, @fattenap.

Prepare Velocity for the upcoming jQuery shim. Closes #208.
  • Loading branch information
julianshapiro authored and Rycochet committed Aug 2, 2020
1 parent 1fab0a2 commit 2320e6e
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 20 deletions.
2 changes: 1 addition & 1 deletion packages/velocity/bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "velocity",
"version": "0.11.5",
"version": "0.11.6",
"homepage": "http://velocityjs.org",
"authors": [
{ "name" : "Julian Shapiro",
Expand Down
2 changes: 1 addition & 1 deletion packages/velocity/component.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "velocity",
"repository": "julianshapiro/velocity",
"version": "0.11.5",
"version": "0.11.6",
"description": "Accelerated JavaScript animation.",
"keywords": [
"animation",
Expand Down
24 changes: 14 additions & 10 deletions packages/velocity/jquery.velocity.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Velocity.js
******************/

/*! VelocityJS.org (0.11.5). (C) 2014 Julian Shapiro. MIT @license: en.wikipedia.org/wiki/MIT_License */
/*! VelocityJS.org (0.11.6). (C) 2014 Julian Shapiro. MIT @license: en.wikipedia.org/wiki/MIT_License */

/*
Structure:
Expand Down Expand Up @@ -103,6 +103,11 @@ return function (global, window, document, undefined) {
return result;
}

/* Wrap single elements in an array so that $.each() can iterate with the element instead of its node's children. */
function createElementsArray (elements) {
return Type.isNode(elements) ? [ elements ] : elements;
}

var Type = {
isString: function (variable) {
return (typeof variable === "string");
Expand Down Expand Up @@ -160,7 +165,6 @@ return function (global, window, document, undefined) {
if (jQuery && jQuery.fn !== undefined) {
$ = jQuery;
} else if (window.Velocity && window.Velocity.Utilities) {

$ = window.Velocity.Utilities;
}

Expand Down Expand Up @@ -286,7 +290,7 @@ return function (global, window, document, undefined) {
elements = [].slice.call(elements);
}

$.each(Type.isNode(elements) ? [ elements ] : elements, function(i, element) {
$.each(createElementsArray(elements), function(i, element) {
/* Initialize Velocity's per-element data cache if this element hasn't previously been animated. */
if (Data(element) === undefined) {
Velocity.init(element);
Expand Down Expand Up @@ -315,7 +319,7 @@ return function (global, window, document, undefined) {
},
/* Set to true to force a duration of 1ms for all animations so that UI testing can be performed without waiting on animations to complete. */
mock: false,
version: { major: 0, minor: 11, patch: 5 },
version: { major: 0, minor: 11, patch: 6 },
/* Set to 1 or 2 (most verbose) to output debug info to console. */
debug: false
};
Expand Down Expand Up @@ -1696,7 +1700,7 @@ return function (global, window, document, undefined) {
*******************/

/* Clear the currently-active delay on each targeted element. */
$.each(Type.isNode(elements) ? [ elements ] : elements, function(i, element) {
$.each(createElementsArray(elements), function(i, element) {
if (Data(element) && Data(element).delayTimer) {
/* Stop the timer from triggering its cached next() function. */
clearTimeout(Data(element).delayTimer.setTimeout);
Expand Down Expand Up @@ -1724,8 +1728,8 @@ return function (global, window, document, undefined) {
/* Inactive calls are set to false by the logic inside completeCall(). Skip them. */
if (activeCall) {
/* If we're operating on a single element, wrap it in an array so that $.each() can iterate over it. */
$.each(Type.isNode(activeCall[1]) ? [ activeCall[1] ] : activeCall[1], function(k, activeElement) {
$.each(Type.isNode(elements) ? [ elements ] : elements, function(l, element) {
$.each(createElementsArray(activeCall[1]), function(k, activeElement) {
$.each(createElementsArray(elements), function(l, element) {
/* Check that this call was applied to the target element. */
if (element === activeElement) {
if (Data(element)) {
Expand All @@ -1743,7 +1747,7 @@ return function (global, window, document, undefined) {

/* Iterate through the items in the element's queue. */
$.each($.queue(element, queueName), function(i, item) {
/* The queue array can contain an "inprogress" sentinal, which we skip. */
/* The queue array can contain an "inprogress" string, which we skip. */
if (Type.isFunction(item)) {
/* Pass the item's callback a flag indicating that we want to abort from the queue call.
(Specifically, the queue will resolve the call's associated promise then abort.) */
Expand Down Expand Up @@ -1796,7 +1800,7 @@ return function (global, window, document, undefined) {
}

/* Individually trigger the sequence for each element in the set to prevent users from having to handle iteration logic in their sequence. */
$.each(elements, function(elementIndex, element) {
$.each(createElementsArray(elements), function(elementIndex, element) {
/* If the stagger option was passed in, successively delay each element by the stagger value (in ms). Retain the original delay value. */
if (parseFloat(options.stagger)) {
options.delay = delayOriginal + (parseFloat(options.stagger) * elementIndex);
Expand Down Expand Up @@ -2753,7 +2757,7 @@ return function (global, window, document, undefined) {

/* If the "nodeType" property exists on the elements variable, we're animating a single element.
Place it in an array so that $.each() can iterate over it. */
$.each(Type.isNode(elements) ? [ elements ] : elements, function(i, element) {
$.each(createElementsArray(elements), function(i, element) {
/* Ensure each element in a set has a nodeType (is a real element) to avoid throwing errors. */
if (Type.isNode(element)) {
processElement.call(element);
Expand Down
4 changes: 2 additions & 2 deletions packages/velocity/jquery.velocity.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/velocity/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "velocity-animate",
"version": "0.11.5",
"version": "0.11.6",
"description": "Accelerated JavaScript animation.",
"keywords": [
"velocity",
Expand Down
6 changes: 3 additions & 3 deletions packages/velocity/velocity.ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Velocity UI Pack
**********************/

/* VelocityJS.org UI Pack (4.1.1). (C) 2014 Julian Shapiro. MIT @license: en.wikipedia.org/wiki/MIT_License. Portions copyright Daniel Eden, Christian Pucci. */
/* VelocityJS.org UI Pack (4.1.2). (C) 2014 Julian Shapiro. MIT @license: en.wikipedia.org/wiki/MIT_License. Portions copyright Daniel Eden, Christian Pucci. */

(function() {

Expand Down Expand Up @@ -36,7 +36,7 @@
parentNode;

/* Sum the total height (including padding and margin) of all targeted elements. */
Container.Velocity.Utilities.each(elements, function(i, element) {
Container.Velocity.Utilities.each(elements.nodeType ? [ elements ] : elements, function(i, element) {
if (stagger) {
/* Increase the totalDuration by the successive delay amounts produced by the stagger option. */
totalDuration += i * stagger;
Expand Down Expand Up @@ -116,7 +116,7 @@
/* Append promise resolving onto the user's sequence callback. */
function injectFinalCallbacks () {
if ((sequenceOptions.display === undefined || sequenceOptions.display === "none") && /Out$/.test(effectName)) {
Container.Velocity.Utilities.each(elements, function(i, element) {
Container.Velocity.Utilities.each(elements.nodeType ? [ elements ] : elements, function(i, element) {
Container.Velocity.CSS.setPropertyValue(element, "display", "none");
});
}
Expand Down
Loading

0 comments on commit 2320e6e

Please sign in to comment.