Skip to content

Commit

Permalink
Animation status fix
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitryBaranovskiy committed Aug 16, 2011
1 parent 951f8fb commit e1fb048
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 28 deletions.
2 changes: 1 addition & 1 deletion raphael-min.js

Large diffs are not rendered by default.

41 changes: 26 additions & 15 deletions raphael.core.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@
commaSpaces = /\s*,\s*/,
hsrg = {hs: 1, rg: 1},
p2s = /,?([achlmqrstvxz]),?/gi,
pathCommand = /([achlmqstvz])[\s,]*((-?\d*\.?\d*(?:e[\-+]?\d+)?\s*,?\s*)+)/ig,
pathCommand = /([achlmrqstvz])[\s,]*((-?\d*\.?\d*(?:e[\-+]?\d+)?\s*,?\s*)+)/ig,
tCommand = /([rstm])[\s,]*((-?\d*\.?\d*(?:e[\-+]?\d+)?\s*,?\s*)+)/ig,
pathValues = /(-?\d*\.?\d*(?:e[\-+]?\d+)?)\s*,?\s*/ig,
radial_gradient = R._radial_gradient = /^r(?:\(([^,]+?)\s*,\s*([^\)]+?)\))?/,
Expand Down Expand Up @@ -1005,7 +1005,7 @@
if (!pathString) {
return null;
}
var paramCounts = {a: 7, c: 6, h: 1, l: 2, m: 2, q: 4, s: 4, t: 2, v: 1, z: 0},
var paramCounts = {a: 7, c: 6, h: 1, l: 2, m: 2, r: 4, q: 4, s: 4, t: 2, v: 1, z: 0},
data = [];
if (R.is(pathString, array) && R.is(pathString[0], array)) { // rough assumption
data = pathClone(pathString);
Expand Down Expand Up @@ -3499,22 +3499,24 @@
**
> Parameters
**
- params (object) final attributes for the element, see also @Element.attr
- ms (number) number of milliseconds for animation to run
- element (object) element to sync with
- anim (object) animation to sync with
- params (object) #optional final attributes for the element, see also @Element.attr
- ms (number) #optional number of milliseconds for animation to run
- easing (string) #optional easing type. Accept on of @Raphael.easing_formulas or CSS format: `cubic‐bezier(XX, XX, XX, XX)`
- callback (function) #optional callback function. Will be called at the end of animation.
* or
- animation (object) animation object, see @Raphael.animation
- element (object) element to sync with
- anim (object) animation to sync with
- animation (object) #optional animation object, see @Raphael.animation
**
= (object) original element
\*/
elproto.animateWith = function (element, params, ms, easing, callback) {
// var a = R.animation(params, ms, easing, callback);
// status = element.status(anim);
// this.animate(a);
// this.status(a, status);
this.animate(params, ms, easing, callback);
return this;
elproto.animateWith = function (element, anim, params, ms, easing, callback) {
var a = params ? R.animation(params, ms, easing, callback) : anim;
status = element.status(anim);
this.animate(a);
return this.status(a, status * anim.ms / a.ms);
};
function CubicBezierAtTime(t, p1x, p1y, p2x, p2y, duration) {
var cx = 3 * p1x,
Expand Down Expand Up @@ -3811,13 +3813,16 @@
totalOrigin: totalOrigin
};
animationElements.push(e);
if (status && !isInAnim) {
if (status && !isInAnim && !isInAnimSet) {
e.stop = true;
e.start = new Date - ms * status;
if (animationElements.length == 1) {
return animation();
}
}
if (isInAnimSet) {
e.start = new Date - e.ms * status;
}
animationElements.length == 1 && requestAnimFrame(animation);
} else {
isInAnim.initstatus = status;
Expand All @@ -3842,6 +3847,9 @@
= (object) @Animation
\*/
R.animation = function (params, ms, easing, callback) {
if (params instanceof Animation) {
return params;
}
if (R.is(easing, "function") || !easing) {
callback = callback || easing || null;
easing = null;
Expand Down Expand Up @@ -3949,7 +3957,10 @@
if (anim) {
return e.status;
}
out.push({anim: e.anim, status: e.status});
out.push({
anim: e.anim,
status: e.status
});
}
}
if (anim) {
Expand Down Expand Up @@ -4200,7 +4211,7 @@
!--len && callback.call(set);
});
easing = R.is(easing, string) ? easing : collector;
var anim = params instanceof Animation ? params : R.animation(params, ms, easing, collector);
var anim = R.animation(params, ms, easing, collector);
item = this.items[--i].animate(anim);
while (i--) {
this.items[i] && !this.items[i].removed && this.items[i].animateWith(item, anim);
Expand Down
31 changes: 19 additions & 12 deletions raphael.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@
commaSpaces = /\s*,\s*/,
hsrg = {hs: 1, rg: 1},
p2s = /,?([achlmqrstvxz]),?/gi,
pathCommand = /([achlmqstvz])[\s,]*((-?\d*\.?\d*(?:e[\-+]?\d+)?\s*,?\s*)+)/ig,
pathCommand = /([achlmrqstvz])[\s,]*((-?\d*\.?\d*(?:e[\-+]?\d+)?\s*,?\s*)+)/ig,
tCommand = /([rstm])[\s,]*((-?\d*\.?\d*(?:e[\-+]?\d+)?\s*,?\s*)+)/ig,
pathValues = /(-?\d*\.?\d*(?:e[\-+]?\d+)?)\s*,?\s*/ig,
radial_gradient = R._radial_gradient = /^r(?:\(([^,]+?)\s*,\s*([^\)]+?)\))?/,
Expand Down Expand Up @@ -884,7 +884,7 @@
if (!pathString) {
return null;
}
var paramCounts = {a: 7, c: 6, h: 1, l: 2, m: 2, q: 4, s: 4, t: 2, v: 1, z: 0},
var paramCounts = {a: 7, c: 6, h: 1, l: 2, m: 2, r: 4, q: 4, s: 4, t: 2, v: 1, z: 0},
data = [];
if (R.is(pathString, array) && R.is(pathString[0], array)) { // rough assumption
data = pathClone(pathString);
Expand Down Expand Up @@ -2559,13 +2559,11 @@
return color > 255 ? 255 : color < 0 ? 0 : color;
};

elproto.animateWith = function (element, params, ms, easing, callback) {
// var a = R.animation(params, ms, easing, callback);
// status = element.status(anim);
// this.animate(a);
// this.status(a, status);
this.animate(params, ms, easing, callback);
return this;
elproto.animateWith = function (element, anim, params, ms, easing, callback) {
var a = params ? R.animation(params, ms, easing, callback) : anim;
status = element.status(anim);
this.animate(a);
return this.status(a, status * anim.ms / a.ms);
};
function CubicBezierAtTime(t, p1x, p1y, p2x, p2y, duration) {
var cx = 3 * p1x,
Expand Down Expand Up @@ -2840,13 +2838,16 @@
totalOrigin: totalOrigin
};
animationElements.push(e);
if (status && !isInAnim) {
if (status && !isInAnim && !isInAnimSet) {
e.stop = true;
e.start = new Date - ms * status;
if (animationElements.length == 1) {
return animation();
}
}
if (isInAnimSet) {
e.start = new Date - e.ms * status;
}
animationElements.length == 1 && requestAnimFrame(animation);
} else {
isInAnim.initstatus = status;
Expand All @@ -2856,6 +2857,9 @@
}

R.animation = function (params, ms, easing, callback) {
if (params instanceof Animation) {
return params;
}
if (R.is(easing, "function") || !easing) {
callback = callback || easing || null;
easing = null;
Expand Down Expand Up @@ -2912,7 +2916,10 @@
if (anim) {
return e.status;
}
out.push({anim: e.anim, status: e.status});
out.push({
anim: e.anim,
status: e.status
});
}
}
if (anim) {
Expand Down Expand Up @@ -3078,7 +3085,7 @@
!--len && callback.call(set);
});
easing = R.is(easing, string) ? easing : collector;
var anim = params instanceof Animation ? params : R.animation(params, ms, easing, collector);
var anim = R.animation(params, ms, easing, collector);
item = this.items[--i].animate(anim);
while (i--) {
this.items[i] && !this.items[i].removed && this.items[i].animateWith(item, anim);
Expand Down

0 comments on commit e1fb048

Please sign in to comment.