Permalink
Browse files

add counting steps

  • Loading branch information...
1 parent 52b0326 commit 294204afe02c4d8c45802329d055a54ca6bbdd13 @arunoda committed Sep 21, 2011
Showing with 55 additions and 4 deletions.
  1. +18 −3 lib/qbox.js
  2. +1 −1 package.json
  3. +36 −0 tests/qbox.js
View
@@ -9,8 +9,15 @@ function QBox(steps) {
var startingCallback;
var ticks;
-
- addTicks(); //copy steps into ticks
+ var countingSteps = null;
+
+ if(typeof(steps) == 'number') {
+ //used for steps in a number
+ countingSteps = steps;
+ } else {
+ //used for steps as an array
+ addTicks(); //copy steps into ticks
+ }
this.ready = function(callback) {
if(isReady && !isStop) {
@@ -45,7 +52,12 @@ function QBox(steps) {
this.tick = function(step) {
- if(ticks && ticks instanceof Array) {
+ if(countingSteps != null) {
+ countingSteps--;
+ if(countingSteps == 0) {
+ this.start();
+ }
+ } else if(ticks && ticks instanceof Array) {
var index = ticks.indexOf(step);
if(index >= 0) {
@@ -90,6 +102,9 @@ function QBox(steps) {
isReady = false;
isStop = false;
addTicks();
+ if(countingSteps != null) {
+ countingSteps = steps;
+ }
};
function addTicks() {
View
@@ -1,6 +1,6 @@
{
"name": "qbox",
- "version": "0.1.6",
+ "version": "0.1.7",
"directories": {
"lib": "./lib"
},
View
@@ -149,4 +149,40 @@ exports.testOnStart = function(test) {
$.tick(2);
test.done();
+};
+
+exports.testCountingSteps = function(test) {
+
+ test.expect(1);
+ var $ = qbox.create(4);
+ $.ready(function() {
+ test.ok(true);
+ });
+
+ [1,2,3,4].forEach(function(step) {
+ $.tick();
+ });
+ test.done();
+};
+
+exports.testCountingStepsWithReset = function(test) {
+
+ test.expect(2);
+ var $ = qbox.create(4);
+ $.ready(function() {
+ test.ok(true);
+ });
+
+ [1,2,3,4].forEach(function(step) {
+ $.tick();
+ });
+ $.reset();
+ $.ready(function() {
+ test.ok(true);
+ });
+ [1,2,3,4].forEach(function(step) {
+ $.tick();
+ });
+
+ test.done();
};

0 comments on commit 294204a

Please sign in to comment.