Permalink
Browse files

Adding the ability to scroll vertically on touch devices

  • Loading branch information...
1 parent 6dce1ff commit b0bdb13a38d15f062b3831bbf7989cca86ba3cc8 @amcguier amcguier committed with ChrisMcKee Feb 14, 2012
Showing with 31 additions and 15 deletions.
  1. +27 −12 src/lib/code.util-1.0.6/src/touchelement.class.js
  2. +2 −2 src/photoswipe.class.js
  3. +2 −1 src/uilayer.class.js
@@ -69,7 +69,8 @@
move: false,
gesture: false,
doubleTap: false,
- preventDefaultTouchEvents: true
+ preventDefaultTouchEvents: true,
+ allowVerticalScroll:false
};
Util.extend(this.captureSettings, captureSettings);
@@ -288,7 +289,7 @@
*/
onTouchStart: function(e){
- if (this.captureSettings.preventDefaultTouchEvents){
+ if (this.captureSettings.preventDefaultTouchEvents && !this.captureSettings.allowVerticalScroll){
e.preventDefault();
}
@@ -327,9 +328,7 @@
*/
onTouchMove: function(e){
- if (this.captureSettings.preventDefaultTouchEvents){
- e.preventDefault();
- }
+
if (this.isGesture && this.captureSettings.gesture){
return;
@@ -339,11 +338,21 @@
touchEvent = Util.Events.getTouchEvent(e),
touches = touchEvent.touches;
+ var point = this.getTouchPoint(touches);
+
+ if(this.captureSettings.allowVerticalScroll && Math.abs(this.touchStartPoint.x - point.x) < Math.abs(this.touchStartPoint.y - point.y)){
++ return;
++ }
+
+ if (this.captureSettings.preventDefaultTouchEvents){
+ e.preventDefault();
+ }
+
Util.Events.fire(this, {
type: Util.TouchElement.EventTypes.onTouch,
target: this,
action: Util.TouchElement.ActionTypes.touchMove,
- point: this.getTouchPoint(touches),
+ point: point,
targetEl: e.target,
currentTargetEl: e.currentTarget
});
@@ -360,11 +369,7 @@
if (this.isGesture && this.captureSettings.gesture){
return;
}
-
- if (this.captureSettings.preventDefaultTouchEvents){
- e.preventDefault();
- }
-
+
// http://backtothecode.blogspot.com/2009/10/javascript-touch-and-gesture-events.html
// iOS removed the current touch from e.touches on "touchend"
// Need to look into e.changedTouches
@@ -373,8 +378,18 @@
touchEvent = Util.Events.getTouchEvent(e),
touches = (!Util.isNothing(touchEvent.changedTouches)) ? touchEvent.changedTouches : touchEvent.touches;
+
+
this.touchEndPoint = this.getTouchPoint(touches);
+ if(this.captureSettings.allowVerticalScroll && Math.abs(this.touchStartPoint.x - this.touchEndPoint.x) < Math.abs(this.touchStartPoint.y - this.touchEndPoint.y)){
++ return;
++ }
+
+ if (this.captureSettings.preventDefaultTouchEvents){
+ e.preventDefault();
+ }
+
Util.Events.fire(this, {
type: Util.TouchElement.EventTypes.onTouch,
target: this,
@@ -592,4 +607,4 @@
window,
window.klass,
window.Code.Util
-));
+));
View
@@ -159,7 +159,7 @@
uiWebViewResetPositionDelay: 500,
target: window,
preventDefaultTouchEvents: true,
-
+ allowVerticalScroll:false,
// Carousel
loop: true,
@@ -1297,4 +1297,4 @@
window.Code.PhotoSwipe.Toolbar,
window.Code.PhotoSwipe.UILayer,
window.Code.PhotoSwipe.ZoomPanRotate
-));
+));
View
@@ -77,7 +77,8 @@
move: true,
gesture: Util.Browser.iOS,
doubleTap: true,
- preventDefaultTouchEvents: this.settings.preventDefaultTouchEvents
+ preventDefaultTouchEvents: this.settings.preventDefaultTouchEvents,
+ allowVerticalScroll: this.settings.allowVerticalScroll
});
},

0 comments on commit b0bdb13

Please sign in to comment.