Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add Actor.hasKeyframeAt method. #19

Merged
merged 4 commits into from

2 participants

@sork

I was not sure if this commit had to be part of #18, so I created a separate Pull Request for it.

Besides the method itself, I also updated Underscore.js to version 1.3.3 and included some unit tests in test.keyframes.html.

@sork

Sorry about the //debugger; lines I had to remove in the last commit.

@jeremyckahn jeremyckahn merged commit 8a776bb into jeremyckahn:master
@jeremyckahn
Owner

Beautiful! Simple and functional. I love it, thanks for the feature!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 80 additions and 2 deletions.
  1. +1 −1  lib/underscore
  2. +24 −1 src/rekapi.actor.js
  3. +55 −0 tests/test.keyframe.html
2  lib/underscore
@@ -1 +1 @@
-Subproject commit bfa4fe8a4fc178b252d11c56d7851b105763b720
+Subproject commit 599d31101b7a7b896ff73e338d26ae698833f878
View
25 src/rekapi.actor.js
@@ -426,6 +426,30 @@ var rekapiActor = function (context, _, Tweenable) {
};
+ /*
+ * Determines if an actor has a keyframe set at a given millisecond.
+ * Can optionally look for an existing keyframe on a single property track.
+ *
+ * @param {number} when Millisecond
+ * @param {string} opt_trackName Optional name of a property track
+ * @return {boolean}
+ */
+ Actor.prototype.hasKeyframeAt = function(when, opt_trackName) {
+ var tracks = this._propertyTracks;
+
+ if (opt_trackName) {
+ if (!_.has(tracks, opt_trackName)) {
+ return false;
+ }
+ tracks = _.pick(tracks, opt_trackName);
+ }
+
+ return _.find(tracks, function (propertyTrack, trackName) {
+ return findPropertyAtMillisecondInTrack(this, trackName, when) !== undefined;
+ }, this) !== undefined;
+ };
+
+
/**
* @param {number} when
* @param {Object} stateModification
@@ -448,7 +472,6 @@ var rekapiActor = function (context, _, Tweenable) {
}
}, this);
-
return this;
};
View
55 tests/test.keyframe.html
@@ -398,6 +398,61 @@
});
+ module('Keyframe presence');
+
+ test('Actor can determine if it has a keyframe at a given millisecond' , function () {
+ var testKapi
+ ,testActor;
+
+ testKapi = setupTestKapi();
+ testActor = setupTestActor(testKapi);
+
+ testActor
+ .keyframe(0, {
+ 'x': 0
+ }, {
+ 'x': 'elastic'
+ }).keyframe(1000, {
+ 'x': 100
+ }, {
+ 'x': 'elastic'
+ });
+
+ equals(testActor.hasKeyframeAt(500), false,
+ 'Keyframe does not exist at 500ms');
+ equals(testActor.hasKeyframeAt(2000), false,
+ 'Keyframe does not exist at 2000ms');
+ equals(testActor.hasKeyframeAt(1000), true,
+ 'Keyframe exists at 1000ms');
+ });
+
+ test('Actor can determine if it has a keyframe on a given property track' , function () {
+ var testKapi
+ ,testActor;
+
+ testKapi = setupTestKapi();
+ testActor = setupTestActor(testKapi);
+
+ testActor
+ .keyframe(0, {
+ 'x': 0
+ }, {
+ 'x': 'elastic'
+ }).keyframe(1000, {
+ 'x': 100
+ }, {
+ 'x': 'elastic'
+ });
+
+ equals(testActor.hasKeyframeAt(0, 'y'), false,
+ 'Keyframe does not exist at 0ms on an unknown track');
+ equals(testActor.hasKeyframeAt(1200, 'x'), false,
+ 'Keyframe does not exist at 1200ms on the x track');
+ equals(testActor.hasKeyframeAt(1000, 'x'), true,
+ 'Keyframe exists at 1000ms on the x track');
+ });
+
+
module('Waits');
test('Can copy keyframes (one initial keyframe)', function () {
Something went wrong with that request. Please try again.