Skip to content

Commit

Permalink
Infinite looping
Browse files Browse the repository at this point in the history
Infinite looping. Closes #175. See http://VelocityJS.org/#loop.

Ability to chain RegisterUI calls on the UI pack. Closes #207.

Fixed bug where promises wouldn’t be returned with the fade and slide
commands.

The `display` and `visibility` options now fire upon the completion of
a non-infinite `loop`.
  • Loading branch information
julianshapiro committed Jul 30, 2014
1 parent f9be38d commit 956c6d2
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 26 deletions.
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,5 @@ node_modules
test
min
README.md
Gruntfile.js
velocity.js
velocity.min.js
Gruntfile.js.bak
velocity.jquery-shim.js
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "velocity",
"version": "0.9.0",
"version": "0.10.0",
"homepage": "http://velocityjs.org",
"authors": [
{ "name" : "Julian Shapiro",
Expand Down
2 changes: 1 addition & 1 deletion component.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "velocity",
"repository": "julianshapiro/velocity",
"version": "0.9.0",
"version": "0.10.0",
"description": "Accelerated JavaScript animation.",
"keywords": [
"animation",
Expand Down
60 changes: 45 additions & 15 deletions jquery.velocity.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/*!
* Velocity.js: Accelerated JavaScript animation.
* @version 0.9.0
* @version 0.10.0
* @docs http://velocityjs.org
* @license Copyright 2014 Julian Shapiro. MIT License: http://en.wikipedia.org/wiki/MIT_License
*/
Expand All @@ -25,8 +25,6 @@ Velocity's structure:
- completeCall(): Handles the cleanup process for each Velocity call.
*/

/* NOTICE: Despite the ensuing code indicating that Velocity works *without* jQuery and *with* Zepto, this support has not yet landed. */

/******************
Velocity.js
******************/
Expand Down Expand Up @@ -134,6 +132,16 @@ Velocity's structure:

isSVG: function (variable) {
return window.SVGElement && (variable instanceof SVGElement);
},

isEmptyObject: function (variable) {
var name;

for (name in variable) {
return false;
}

return true;
}
};

Expand Down Expand Up @@ -188,7 +196,7 @@ Velocity's structure:
DOM elements and stand alone for targeting raw DOM elements. */
/* Note: The global object also doubles as a publicly-accessible data store for the purposes of unit testing. */
/* Note: Alias the lowercase and uppercase variants of "velocity" to minimize user confusion due to the lowercase nature of the $.fn extension. */
var Velocity = global.Velocity = global.velocity = {
var Velocity = global.Velocity = global.velocity = $.extend({
/* Container for page-wide Velocity state data. */
State: {
/* Detect mobile devices to determine if mobileHA should be turned on. */
Expand Down Expand Up @@ -244,10 +252,10 @@ Velocity's structure:
animate: function () { /* Defined below. */ },
/* 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: 9, patch: 0 },
version: { major: 0, minor: 10, patch: 0 },
/* Set to 1 or 2 (most verbose) to output debug info to console. */
debug: false
};
}, window.Velocity);

/* Retrieve the appropriate scroll anchor and property name for the browser: https://developer.mozilla.org/en-US/docs/Web/API/Window.scrollY */
if (window.pageYOffset !== undefined) {
Expand Down Expand Up @@ -1676,7 +1684,7 @@ Velocity's structure:
regardless of the element's current queue state. */
$.each(Velocity.State.calls, function(i, activeCall) {
/* Inactive calls are set to false by the logic inside completeCall(). Skip them. */
if (activeCall !== false) {
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) {
Expand Down Expand Up @@ -1732,7 +1740,7 @@ Velocity's structure:

default:
/* Treat a non-empty plain object as a literal properties map. */
if ($.isPlainObject(propertiesMap) && !$.isEmptyObject(propertiesMap)) {
if ($.isPlainObject(propertiesMap) && !Type.isEmptyObject(propertiesMap)) {
action = "start";

/****************
Expand Down Expand Up @@ -2141,7 +2149,7 @@ Velocity's structure:
/* Easing is the only option that embeds into the individual tween data (since it can be defined on a per-property basis).
Accordingly, every property's easing value must be updated when an options object is passed in with a reverse call.
The side effect of this extensibility is that all per-property easing values are forcefully reset to the new value. */
if (!$.isEmptyObject(options)) {
if (!Type.isEmptyObject(options)) {
lastTweensContainer[lastTween].easing = opts.easing;
}

Expand Down Expand Up @@ -2849,7 +2857,9 @@ Velocity's structure:

/* If a complete callback was passed into this call, transfer it to the loop sequence's final "reverse" call
so that it's triggered when the entire sequence is complete (and not when the very first animation is complete). */
if (opts.complete && (x === reverseCallsCount - 1)) {
if (x === reverseCallsCount - 1) {
reverseOptions.display = opts.display;
reverseOptions.visibility = opts.visibility;
reverseOptions.complete = opts.complete;
}

Expand Down Expand Up @@ -3116,7 +3126,7 @@ Velocity's structure:

/* If the user set display to "none" (intending to hide the element), set it now that the animation has completed. */
/* Note: display:none isn't set when calls are manually stopped (via Velocity.animate("stop"). */
/* Note: Display is ignored with "reverse" calls, which is what loops are composed of, since this behavior would be undesirable. */
/* Note: Display gets ignored with "reverse" calls and infinite loops, since this behavior would be undesirable. */
if (!isStopped && !opts.loop) {
if (opts.display === "none") {
CSS.setPropertyValue(element, "display", opts.display);
Expand Down Expand Up @@ -3173,7 +3183,6 @@ Velocity's structure:

/* Complete is fired once per call (not once per element) and is passed the full raw DOM element set as both its context and its first argument. */
/* Note: Callbacks aren't fired when calls are manually stopped (via Velocity.animate("stop"). */
/* Note: If this is a loop, complete callback firing is only triggered on the loop's final reverse call. */
if (!isStopped && opts.complete && !opts.loop && (i === callLength - 1)) {
/* We throw callbacks in a setTimeout so that thrown errors don't halt the execution of Velocity itself. */
try {
Expand All @@ -3189,10 +3198,19 @@ Velocity's structure:
Promise Resolving
**********************/

if (resolver) {
/* Note: Infinite loops don't return promises. */
if (resolver && opts.loop !== true) {
resolver(elements);
}

/****************************
Option: Loop (Infinite)
****************************/

if (opts.loop === true && !isStopped) {
Velocity.animate(element, "reverse", { loop: true, delay: opts.delay });
}

/***************
Dequeueing
***************/
Expand Down Expand Up @@ -3262,7 +3280,7 @@ Velocity's structure:

/* slideUp, slideDown */
$.each([ "Down", "Up" ], function(i, direction) {
Velocity.Sequences["slide" + direction] = function (element, options) {
Velocity.Sequences["slide" + direction] = function (element, options, elementsIndex, elementsSize, elements, promiseData) {
var opts = $.extend({}, options),
originalValues = {
height: null,
Expand Down Expand Up @@ -3384,6 +3402,8 @@ Velocity's structure:
if (complete) {
complete.call(element, element);
}

promiseData && promiseData.resolver(elements || element);
};

/* Animation triggering. */
Expand All @@ -3393,7 +3413,7 @@ Velocity's structure:

/* fadeIn, fadeOut */
$.each([ "In", "Out" ], function(i, direction) {
Velocity.Sequences["fade" + direction] = function (element, options, elementsIndex, elementsSize) {
Velocity.Sequences["fade" + direction] = function (element, options, elementsIndex, elementsSize, elements, promiseData) {
var opts = $.extend({}, options),
propertiesMap = {
opacity: (direction === "In") ? 1 : 0
Expand All @@ -3403,6 +3423,16 @@ Velocity's structure:
callbacks by firing them only when the final element has been reached. */
if (elementsIndex !== elementsSize - 1) {
opts.complete = opts.begin = null;
} else {
var originalComplete = opts.complete;

opts.complete = function() {
if (originalComplete) {
originalComplete.call(element, element);
}

promiseData && promiseData.resolver(elements || element);
}
}

/* If a display was passed in, use it. Otherwise, default to "none" for fadeOut or the element-specific default for fadeIn. */
Expand Down
4 changes: 2 additions & 2 deletions jquery.velocity.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "velocity-animate",
"version": "0.9.0",
"version": "0.10.0",
"description": "Accelerated JavaScript animation.",
"keywords": [
"velocity",
Expand Down
5 changes: 4 additions & 1 deletion velocity.ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/*!
* velocity.ui.js: UI effects pack for Velocity. Load this file after jquery.velocity.js.
* @version 4.0.6
* @version 4.1.0
* @docs http://velocityjs.org/#uiPack
* @support <=IE8: Callouts will have no effect, and transitions will simply fade in/out. IE9/Android 2.3: Most effects are fully supported, the rest fade in/out. All other browsers: Full support.
* @license Copyright Julian Shapiro. MIT License: http://en.wikipedia.org/wiki/MIT_License
Expand Down Expand Up @@ -170,6 +170,9 @@
Container.Velocity.animate(element, propertyMap, opts);
}
};

/* Return the Velocity object so that RegisterUI calls can be chained. */
return Container.Velocity;
};

/*********************
Expand Down
Loading

0 comments on commit 956c6d2

Please sign in to comment.