Permalink
Browse files

Fixes a bug with multiple touches.

  • Loading branch information...
1 parent 8e028f2 commit 772b7793003a63594f3cbe52728039a681a78089 @paulstraw committed Sep 7, 2011
Showing with 16 additions and 11 deletions.
  1. +8 −6 ender.poke.js
  2. +7 −4 example.html
  3. +1 −1 package.json
View
@@ -1,6 +1,6 @@
/*!
* Poke, an Ender module for handling swipe gestures on mobile devices
- * Version 0.0.1
+ * Version 0.1.1
* (c) 2011 Paul Straw (@pausltraw)
* Lots of code from Zepto's touch module: https://github.com/madrobby/zepto
* Released under the MIT License
@@ -13,7 +13,8 @@
var t = $(el),
gestures,
touch = {},
- lastSwipe;
+ lastSwipe,
+ lastTouch;
function swipeDirection(x1, x2, y1, y2){
var xDelta = Math.abs(x1 - x2), yDelta = Math.abs(y1 - y2);
@@ -29,13 +30,14 @@
//reset stuff
gestures = [];
lastSwipe = '';
+ lastTouch = e.touches.length - 1;
- touch.x1 = e.touches[0].pageX;
- touch.y1 = e.touches[0].pageY;
+ touch.x1 = e.touches[lastTouch].pageX;
+ touch.y1 = e.touches[lastTouch].pageY;
},
touchmove: function(e) {
- touch.x2 = e.touches[0].pageX;
- touch.y2 = e.touches[0].pageY;
+ touch.x2 = e.touches[lastTouch].pageX;
+ touch.y2 = e.touches[lastTouch].pageY;
if (Math.abs(touch.x1 - touch.x2) > 60 || Math.abs(touch.y1 - touch.y2) > 60) {
var currentSwipe = swipeDirection(touch.x1, touch.x2, touch.y1, touch.y2);
View
@@ -30,8 +30,9 @@
font-weight: bold;
font-size: 36px;
width: 100%;
- height: 100%;
- padding-top: 40%;
+ height: 50px;
+ margin-top: 40%;
+ background: rgba(255, 255, 0, 0.3);
}
</style>
@@ -40,15 +41,17 @@
</head>
<body>
- <p>swipe anywhere (N-E, S-W-N, or E)</p>
+ <p>swipe, starting on the stripe (N-E, S-W-N, or E)</p>
<div id="hello"></div>
<script>
!function(){
var h = $('#hello')[0];
$(document).bind('touchmove', function(e) {
e.preventDefault();
- }).poke({
+ });
+
+ $('#hello').poke({
'N-E': function() {
h.innerHTML = 'N-E';
},
View
@@ -1,7 +1,7 @@
{
"name": "ender-poke",
"description": "An Ender module for handling swipe gestures on mobile devices",
- "version": "0.0.1",
+ "version": "0.1.1",
"homepage": "https://github.com/paulstraw/ender-poke",
"authors": ["Paul Straw (@paulstraw)"],
"repository": {

0 comments on commit 772b779

Please sign in to comment.