Skip to content
This repository has been archived by the owner on Mar 1, 2023. It is now read-only.

Commit

Permalink
adding longpress
Browse files Browse the repository at this point in the history
  • Loading branch information
paularmstrong committed Oct 29, 2011
1 parent fe358c9 commit ea3c3a3
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
37 changes: 37 additions & 0 deletions lib/gestures/longpress.js
@@ -0,0 +1,37 @@
CreateRecognizer('longpress', {
minduration: 1000,
maxMove: 3,
timer: null,
start: function (e) {
if (e.touches.length === 1) {
this.shouldFire = true;
} else {
this.shouldFire = false;
}

this.target.style.webkitUserSelect = 'none';
var self = this;

this.startPos = { x: e.touches[0].pageX, y: e.touches[0].pageY };

this.timer = setTimeout(function () {
self.fire(e);
}, this.minduration);
},
move: function (e) {
var touch = e.changedTouches[0];

if (touch.pageX - this.startPos.x < this.maxMove && touch.pageY - this.startPos.y < this.maxMove) {
return;
}

this.shouldFire = false;
clearTimeout(this.timer);
this.timer = null;
},
end: function (e) {
this.shouldFire = false;
clearTimeout(this.timer);
this.timer = null;
}
});
2 changes: 2 additions & 0 deletions lib/index.html
Expand Up @@ -12,6 +12,7 @@
<script src="gestures/swipe.js"></script>
<script src="gestures/pinch.js"></script>
<script src="gestures/rotate.js"></script>
<script src="gestures/longpress.js"></script>

<style>
html, body {
Expand Down Expand Up @@ -58,6 +59,7 @@
}

area.addEventListener('tap', logEvent, false);
area.addEventListener('longpress', logEvent, false);
area.addEventListener('doubletap', logEvent, false);
area.addEventListener('swipe', logEvent, false);
area.addEventListener('pinch', logEvent, false);
Expand Down

0 comments on commit ea3c3a3

Please sign in to comment.