Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #95 from joaodubas/zepto
--- Enabled vertical swipe, by defining which movement was greater (vertical or horizontal). Also added support to pinch gesture, via gesture events (only available on iOS). Tests where also generated, on touch.html and gesture.html.
- Loading branch information
Showing
6 changed files
with
99 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
(function($){ | ||
if ($.os.ios) { | ||
var gesture = {}, gestureTimeout; | ||
|
||
function parentIfText(node){ | ||
return 'tagName' in node ? node : node.parentNode; | ||
} | ||
|
||
$(document).ready(function(){ | ||
$(document.body).bind('gesturestart', function(e){ | ||
var now = Date.now(), delta = now - (gesture.last || now); | ||
gesture.target = parentIfText(e.target); | ||
gestureTimeout && clearTimeout(gestureTimeout); | ||
gesture.e1 = e.scale; | ||
gesture.last = now; | ||
}).bind('gesturechange', function(e){ | ||
gesture.e2 = e.scale; | ||
}).bind('gestureend', function(e){ | ||
if (gesture.e2 > 0) { | ||
Math.abs(gesture.e1 - gesture.e2) != 0 && $(gesture.target).trigger('pinch') && | ||
$(gesture.target).trigger('pinch' + (gesture.e1 - gesture.e2 > 0 ? 'In' : 'Out')); | ||
gesture.e1 = gesture.e2 = gesture.last = 0; | ||
} else if ('last' in gesture) { | ||
gesture = {}; | ||
} | ||
}); | ||
}); | ||
|
||
['pinch', 'pinchIn', 'pinchOut'].forEach(function(m){ | ||
$.fn[m] = function(callback){ return this.bind(m, callback) } | ||
}); | ||
} | ||
})(Zepto); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Zepto gesture functional test</title> | ||
<meta name="viewport" content="maximum-scale=1,initial-scale=1,user-scalable=0"> | ||
<script src="../src/zepto.js"></script> | ||
<script src="../src/event.js"></script> | ||
<script src="../src/detect.js"></script> | ||
<script src="../src/gesture.js"></script> | ||
</head> | ||
<body> | ||
<h1>Zepto gestures functional test</h1> | ||
|
||
<div id="gesture_test" style="width: 200px; height: 200px; background: #ddd"> | ||
gesture events test | ||
</div> | ||
|
||
<script> | ||
$('#gesture_test') | ||
.pinch(function(){ | ||
$(this).append(' | pinch!'); | ||
}) | ||
.pinchIn(function(){ | ||
$(this).append(' | pinch in!'); | ||
}) | ||
.pinchOut(function(){ | ||
$(this).append(' | pinch out!'); | ||
}); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters