Skip to content

Commit

Permalink
Fix #88
Browse files Browse the repository at this point in the history
Big thanks to @jsimnz
Fix old tests
Fix lint errors
  • Loading branch information
maxwellito committed Oct 24, 2016
1 parent 76c534a commit 04e182f
Show file tree
Hide file tree
Showing 7 changed files with 161 additions and 123 deletions.
9 changes: 7 additions & 2 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ gulp.task('distrib', function () {
*
*/
gulp.task('lint', function () {
return gulp.src(['src/pathformer.js', 'src/vivus.js'])
return gulp.src(['src/vivus.js', 'src/pathformer.js', 'test/**/*.spec.js'])
.pipe(jshint())
.pipe(jshint.reporter('default'));
});
Expand All @@ -52,7 +52,12 @@ gulp.task('lint', function () {
*/
gulp.task('test', function () {
// Be sure to return the stream
return gulp.src(['src/pathformer.js', 'src/vivus.js', 'test/unit/**.js'])
return gulp.src([
'test/unit.setup.js',
'src/pathformer.js',
'src/vivus.js',
'test/unit/**.js'
])
.pipe(karma({
configFile: 'test/karma.conf.js',
action: 'run'
Expand Down
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -320,5 +320,6 @@ Thanks to all contributors! Also users who pushed me to improve the library by p
- [@flyingfisch](https://github.com/flyingfisch) for general helping with issues
- [@morgangiraud](https://github.com/morgangiraud) on the ignore invisible paths
- [@Nerdissimo](https://github.com/Nerdissimo) for inserting SVG without `object` wrapper
- [@jsimnz](https://github.com/jsimnz) for adding callbacks to play method

and many others...
36 changes: 19 additions & 17 deletions src/vivus.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ Vivus.prototype.setOptions = function (options) {
this.reverseStack = !!options.reverseStack;
this.selfDestroy = !!options.selfDestroy;
this.onReady = options.onReady;
this.map = new Array();
this.map = [];
this.frameLength = this.currentFrame = this.delayUnit = this.speed = this.handle = null;

this.ignoreInvisible = options.hasOwnProperty('ignoreInvisible') ? !!options.ignoreInvisible : false;
Expand Down Expand Up @@ -364,28 +364,25 @@ Vivus.prototype.drawer = function () {
if (this.currentFrame <= 0) {
this.stop();
this.reset();
this.callback(this);
if (this.instance_callback) {
this.instance_callback(this)
this.instance_callback = null
}
} else if (this.currentFrame >= this.frameLength) {
this.stop();
this.currentFrame = this.frameLength;
this.trace();
if (this.selfDestroy) {
this.destroy();
}
this.callback(this);
if (this.instance_callback) {
this.instance_callback(this)
this.instance_callback = null;
}
} else {
this.trace();
this.handle = requestAnimFrame(function () {
self.drawer();
});
return;
}

this.callback(this);
if (this.instanceCallback) {
this.instanceCallback(this);
this.instanceCallback = null;
}
};

Expand Down Expand Up @@ -557,15 +554,20 @@ Vivus.prototype.setFrameProgress = function (progress) {
* @param {number} speed Animation speed [optional]
*/
Vivus.prototype.play = function (speed, callback) {
if (speed && typeof speed === "function") {
this.instance_callback = speed // first parameter is actually the callback function
speed = null
} else if (speed && typeof speed !== 'number') {
this.instanceCallback = null;

if (speed && typeof speed === 'function') {
this.instanceCallback = speed; // first parameter is actually the callback function
speed = null;
}
else if (speed && typeof speed !== 'number') {
throw new Error('Vivus [play]: invalid speed');
}
// if the first parameter wasn't the callback, check if the seconds was
if (callback && typeof(callback) === "function" && !this.instance_callback)
this.instance_callback = callback;
if (callback && typeof(callback) === 'function' && !this.instanceCallback) {
this.instanceCallback = callback;
}


this.speed = speed || 1;
if (!this.handle) {
Expand Down
1 change: 1 addition & 0 deletions test/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module.exports = function(config) {

// list of files / patterns to load in the browser
files: [
'test/unit.setup.js',
'src/pathformer.js',
'src/vivus.js',
'test/unit/**.js'
Expand Down
14 changes: 14 additions & 0 deletions test/unit.setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* Here is a cheap and bad implementation
* of requestAnimationFrame and
* cancelAnimationFrame mock.
* But it's more than enough
* for our tests.
*/
window.requestAnimFrameStack = [];
window.requestAnimationFrame = function (callback) {
window.requestAnimFrameStack.push(callback);
return true;
};
window.cancelAnimationFrame = function () {
window.requestAnimFrameStack = [];
};
2 changes: 1 addition & 1 deletion test/unit/pathformer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ describe('Pathformer', function () {
rx: 3,
r: 1
};
})
});

it('should return an object with a `d` attribute', function () {
var output = Pathformer.prototype.circleToPath(circle);
Expand Down
Loading

0 comments on commit 04e182f

Please sign in to comment.