|
1217 | 1217 |
|
1218 | 1218 | function link($scope, element, attrs) { |
1219 | 1219 | var swipeDirection; |
1220 | | - var hammerElem; |
1221 | | - if (typeof(Hammer)!=='undefined') { |
1222 | | - hammerElem = new Hammer(element[0]); |
1223 | | - // set the options for swipe (to make them a bit more forgiving in detection) |
1224 | | - hammerElem.get('swipe').set({ |
1225 | | - direction: Hammer.DIRECTION_ALL, |
1226 | | - threshold: 5, // this is how far the swipe has to travel |
1227 | | - velocity: 0.5 // and this is how fast the swipe must travel |
1228 | | - }); |
1229 | | - } |
| 1220 | + var hammerElem, hammerDirection; |
| 1221 | + |
1230 | 1222 | // detect what direction the directive is pointing |
1231 | 1223 | switch (attrs.baSwipeClose) { |
1232 | 1224 | case 'right': |
1233 | 1225 | swipeDirection = 'swiperight'; |
| 1226 | + hammerDirection = Hammer.DIRECTION_RIGHT; |
1234 | 1227 | break; |
1235 | 1228 | case 'left': |
1236 | 1229 | swipeDirection = 'swipeleft'; |
| 1230 | + hammerDirection = Hammer.DIRECTION_LEFT; |
1237 | 1231 | break; |
1238 | 1232 | case 'up': |
1239 | 1233 | swipeDirection = 'swipeup'; |
| 1234 | + hammerDirection = Hammer.DIRECTION_UP; |
1240 | 1235 | break; |
1241 | 1236 | case 'down': |
1242 | 1237 | swipeDirection = 'swipedown'; |
| 1238 | + hammerDirection = Hammer.DIRECTION_DOWN; |
1243 | 1239 | break; |
1244 | 1240 | default: |
1245 | 1241 | swipeDirection = 'swipe'; |
| 1242 | + hammerDirection = Hammer.DIRECTION_ALL; |
1246 | 1243 | } |
1247 | | - if(typeof(hammerElem) !== 'undefined'){ |
| 1244 | + |
| 1245 | + if (typeof(Hammer)!=='undefined') { |
| 1246 | + hammerElem = new Hammer(element[0]); |
| 1247 | + // set the options for swipe (to make them a bit more forgiving in detection) |
| 1248 | + hammerElem.get('swipe').set({ |
| 1249 | + direction: hammerDirection, |
| 1250 | + threshold: 5, // this is how far the swipe has to travel |
| 1251 | + velocity: 0.5 // and this is how fast the swipe must travel |
| 1252 | + }); |
1248 | 1253 | hammerElem.on(swipeDirection, function() { |
1249 | 1254 | BaseAppsApi.publish(attrs.id, 'close'); |
1250 | 1255 | }); |
|
0 commit comments