diff options
| author | Braden Shepherdson | 2013-07-25 15:23:10 -0700 | 
|---|---|---|
| committer | Braden Shepherdson | 2013-07-25 16:36:11 -0700 | 
| commit | ab189142988043d0513bb796c3b54ca7d07f242d (patch) | |
| tree | 65b349dc7c0a4e6b387ba339376ef52d1f3a0cfa | |
| parent | f9ea69f6567c22ff328fd1f7b07847883757bfa6 (diff) | |
| download | angular.js-ab189142988043d0513bb796c3b54ca7d07f242d.tar.bz2 | |
feat(ngMobile): emit 'swipeleft' and 'swiperight' events
Similar to ngMobile clicks, these events were not capturable by other
directives. Now they emit 'swipeleft' and 'swiperight' events that can
be follow with element.on('swipeleft', ...).
| -rw-r--r-- | src/ngMobile/directive/ngSwipe.js | 7 | ||||
| -rw-r--r-- | test/ngMobile/directive/ngSwipeSpec.js | 32 | 
2 files changed, 36 insertions, 3 deletions
| diff --git a/src/ngMobile/directive/ngSwipe.js b/src/ngMobile/directive/ngSwipe.js index e68e45da..42389542 100644 --- a/src/ngMobile/directive/ngSwipe.js +++ b/src/ngMobile/directive/ngSwipe.js @@ -54,7 +54,7 @@      </doc:example>   */ -function makeSwipeDirective(directiveName, direction) { +function makeSwipeDirective(directiveName, direction, eventName) {    ngMobile.directive(directiveName, ['$parse', '$swipe', function($parse, $swipe) {      // The maximum vertical delta for a swipe should be less than 75px.      var MAX_VERTICAL_DISTANCE = 75; @@ -98,6 +98,7 @@ function makeSwipeDirective(directiveName, direction) {          'end': function(coords) {            if (validSwipe(coords)) {              scope.$apply(function() { +              element.triggerHandler(eventName);                swipeHandler(scope);              });            } @@ -108,6 +109,6 @@ function makeSwipeDirective(directiveName, direction) {  }  // Left is negative X-coordinate, right is positive. -makeSwipeDirective('ngSwipeLeft', -1); -makeSwipeDirective('ngSwipeRight', 1); +makeSwipeDirective('ngSwipeLeft', -1, 'swipeleft'); +makeSwipeDirective('ngSwipeRight', 1, 'swiperight'); diff --git a/test/ngMobile/directive/ngSwipeSpec.js b/test/ngMobile/directive/ngSwipeSpec.js index 6bc7d300..f51556c6 100644 --- a/test/ngMobile/directive/ngSwipeSpec.js +++ b/test/ngMobile/directive/ngSwipeSpec.js @@ -102,6 +102,38 @@ var swipeTests = function(description, restrictBrowsers, startEvent, moveEvent,        expect($rootScope.swiped).toBeUndefined();      })); + +    it('should emit "swipeleft" events for left swipes', inject(function($rootScope, $compile, $rootElement) { +      element = $compile('<div ng-swipe-left="swiped = true"></div>')($rootScope); +      $rootElement.append(element); +      $rootScope.$digest(); + +      expect($rootScope.swiped).toBeUndefined(); +      var eventFired = false; +      element.on('swipeleft', function() { +        eventFired = true; +      }); + +      browserTrigger(element, startEvent, [], 100, 20); +      browserTrigger(element, endEvent, [], 20, 20); +      expect(eventFired).toEqual(true); +    })); + +    it('should emit "swiperight" events for right swipes', inject(function($rootScope, $compile, $rootElement) { +      element = $compile('<div ng-swipe-right="swiped = true"></div>')($rootScope); +      $rootElement.append(element); +      $rootScope.$digest(); + +      expect($rootScope.swiped).toBeUndefined(); +      var eventFired = false; +      element.on('swiperight', function() { +        eventFired = true; +      }); + +      browserTrigger(element, startEvent, [], 20, 20); +      browserTrigger(element, endEvent, [], 100, 20); +      expect(eventFired).toEqual(true); +    }));    });  } | 
