Skip to content

Commit

Permalink
more code :-)
Browse files Browse the repository at this point in the history
  • Loading branch information
jtangelder committed May 26, 2014
1 parent fb2c521 commit a185c47
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
30 changes: 20 additions & 10 deletions src/recognizers/tap.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ function TapRecognizer() {
this.prevTime = false;
this.prevCenter = false;

this.tapCount = 0;
this.counter = 0;
}

inherit(TapRecognizer, Recognizer, {
Expand Down Expand Up @@ -32,25 +32,35 @@ inherit(TapRecognizer, Recognizer, {
var validTapTime = input.deltaTime < options.time;
var validMovement = !this.prevCenter || getDistance(this.prevCenter, input.center) < options.movementBetweenTaps;

this.tapCount = (!validPointers || !validInterval || !validTapTime || !validMovement) ? 0 : this.tapCount += 1;

var validTapCount = (this.tapCount !== 0 || options.taps === 1) && this.tapCount % options.taps === 0;

this.prevTime = input.timeStamp;
this.prevCenter = input.center;

if(validTapCount && validTapTime) {
if(this.tapCount === 0) {
this.tapCount = 1;
}
if(!validPointers || !validTapTime || !validMovement) {
this.counter = 0;
return STATE_FAILED;
}

if(validInterval) {
this.counter += 1;
} else {
this.counter = 1;
}

var validTapCount = (this.counter % options.taps === 0);

if(validTapCount && validTapTime && validPointers && validMovement) {
return STATE_RECOGNIZED;
}
}
return STATE_FAILED;
},

handler: function(input) {
input.tapCount = this.tapCount;
input.tapCount = this.counter;
this.inst.trigger(this.options.event, input);
},

reset: function() {
return Recognizer.prototype.reset.apply(this, arguments);
}
});
9 changes: 5 additions & 4 deletions tests/manual/log.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<title></title>
</head>
<body>
<pre style="background: silver; width: 100%; height: 400px; overflow: hidden" id="hit"></pre>
<pre style="background: silver; width: 100%; height: 400px; overflow: hidden; -webkit-user-select: none;" id="hit"></pre>

<p>In the console is a log of all triggered events</p>

Expand All @@ -28,19 +28,20 @@


var el = document.querySelector("#hit");

var mc = new Hammer.Instance(el, {
touchAction: 'none'
});


mc.addRecognizer(new Hammer.RecognizerSet([
new Hammer.PanRecognizer({event: 'multipan', pointers: 3 }),
new Hammer.PinchRecognizer({event: 'multipinch', pointers: 3 }),
new Hammer.PanRecognizer({event: 'triplepan', pointers: 3 }),
new Hammer.PinchRecognizer({event: 'triplepinch', pointers: 3 }),
]));

mc.addRecognizer(new Hammer.PanRecognizer());
mc.addRecognizer(new Hammer.RotationRecognizer());
mc.addRecognizer(new Hammer.PinchRecognizer());

mc.addRecognizer(new Hammer.TapRecognizer());
mc.addRecognizer(new Hammer.TapRecognizer({ event: 'doubletap', taps: 2 }));

Expand Down

0 comments on commit a185c47

Please sign in to comment.