Skip to content

Commit df41f68

Browse files
author
Chris Hawes
committed
Only configure hammer swipe options for direction specified in ba-swipe-close attribute. Fixes issue with touch scrolling failing when using ba-swipe-close=left or right
1 parent 7223813 commit df41f68

1 file changed

Lines changed: 17 additions & 10 deletions

File tree

js/angular/components/common/common.js

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -129,32 +129,39 @@
129129

130130
function link($scope, element, attrs) {
131131
var swipeDirection;
132-
var hammerElem;
133-
if (typeof(Hammer)!=='undefined') {
134-
hammerElem = new Hammer(element[0]);
135-
// set the options for swipe (to make them a bit more forgiving in detection)
136-
hammerElem.get('swipe').set({
137-
direction: Hammer.DIRECTION_ALL,
138-
threshold: 5, // this is how far the swipe has to travel
139-
velocity: 0.5 // and this is how fast the swipe must travel
140-
});
141-
}
132+
var hammerElem, hammerDirection;
133+
142134
// detect what direction the directive is pointing
143135
switch (attrs.baSwipeClose) {
144136
case 'right':
145137
swipeDirection = 'swiperight';
138+
hammerDirection = Hammer.DIRECTION_RIGHT;
146139
break;
147140
case 'left':
148141
swipeDirection = 'swipeleft';
142+
hammerDirection = Hammer.DIRECTION_LEFT;
149143
break;
150144
case 'up':
151145
swipeDirection = 'swipeup';
146+
hammerDirection = Hammer.DIRECTION_UP;
152147
break;
153148
case 'down':
154149
swipeDirection = 'swipedown';
150+
hammerDirection = Hammer.DIRECTION_DOWN;
155151
break;
156152
default:
157153
swipeDirection = 'swipe';
154+
hammerDirection = Hammer.DIRECTION_ALL;
155+
}
156+
157+
if (typeof(Hammer)!=='undefined') {
158+
hammerElem = new Hammer(element[0]);
159+
// set the options for swipe (to make them a bit more forgiving in detection)
160+
hammerElem.get('swipe').set({
161+
direction: hammerDirection,
162+
threshold: 5, // this is how far the swipe has to travel
163+
velocity: 0.5 // and this is how fast the swipe must travel
164+
});
158165
}
159166
if(typeof(hammerElem) !== 'undefined'){
160167
hammerElem.on(swipeDirection, function() {

0 commit comments

Comments
 (0)