diff options
| -rw-r--r-- | src/ngMobile/directive/ngClick.js | 13 | ||||
| -rw-r--r-- | test/ngMobile/directive/ngClickSpec.js | 16 | 
2 files changed, 23 insertions, 6 deletions
| diff --git a/src/ngMobile/directive/ngClick.js b/src/ngMobile/directive/ngClick.js index 358a1af9..51e201c2 100644 --- a/src/ngMobile/directive/ngClick.js +++ b/src/ngMobile/directive/ngClick.js @@ -233,9 +233,7 @@ ngMobile.directive('ngClick', ['$parse', '$timeout', '$rootElement',          }          if (!angular.isDefined(attr.disabled) || attr.disabled === false) { -          scope.$apply(function() { -            clickHandler(scope, {$event: event}); -          }); +          element.triggerHandler('click', event);          }        } @@ -246,9 +244,12 @@ ngMobile.directive('ngClick', ['$parse', '$timeout', '$rootElement',      // something else nearby.      element.onclick = function(event) { }; -    // Fallback click handler. -    // Busted clicks don't get this far, and adding this handler allows ng-tap to be used on -    // desktop as well, to allow more portable sites. +    // Actual click handler. +    // There are three different kinds of clicks, only two of which reach this point. +    // - On desktop browsers without touch events, their clicks will always come here. +    // - On mobile browsers, the simulated "fast" click will call this. +    // - But the browser's follow-up slow click will be "busted" before it reaches this handler. +    // Therefore it's safe to use this directive on both mobile and desktop.      element.on('click', function(event) {        scope.$apply(function() {          clickHandler(scope, {$event: event}); diff --git a/test/ngMobile/directive/ngClickSpec.js b/test/ngMobile/directive/ngClickSpec.js index 1147f0a2..9038514c 100644 --- a/test/ngMobile/directive/ngClickSpec.js +++ b/test/ngMobile/directive/ngClickSpec.js @@ -358,4 +358,20 @@ describe('ngClick (mobile)', function() {    }); +  describe('the normal click event', function() { +    it('should be capturable by other handlers', inject(function($rootScope, $compile) { +      var called = false; + +      element = $compile('<div ng-click="event = $event" ></div>')($rootScope); + +      element.on('click', function() { +        called = true; +      }); + +      browserTrigger(element, 'touchstart', [], 10, 10); +      browserTrigger(element, 'touchend', [], 10, 10); + +      expect(called).toEqual(true); +    })); +  });  }); | 
