diff --git a/js/angular/directive/gesture.js b/js/angular/directive/gesture.js index 638fdb4be2..0e0e05c6f9 100644 --- a/js/angular/directive/gesture.js +++ b/js/angular/directive/gesture.js @@ -239,26 +239,22 @@ function gestureDirective(directiveName) { return ['$ionicGesture', '$parse', function($ionicGesture, $parse) { var eventType = directiveName.substr(2).toLowerCase(); - return { - restrict: 'A', - compile: function($element, attr) { - var fn = $parse( attr[directiveName] ); + return function(scope, element, attr) { + var fn = $parse( attr[directiveName] ); - return function(scope, element, attr) { - - var listener = function(ev) { - scope.$apply(function() { - fn(scope, {$event:event}); - }); - }; - - var gesture = $ionicGesture.on(eventType, listener, $element); - - scope.$on('$destroy', function() { - $ionicGesture.off(gesture, eventType, listener); + var listener = function(ev) { + scope.$apply(function() { + fn(scope, { + $event: ev }); - }; - } + }); + }; + + var gesture = $ionicGesture.on(eventType, listener, element); + + scope.$on('$destroy', function() { + $ionicGesture.off(gesture, eventType, listener); + }); }; }]; } diff --git a/test/unit/angular/directive/gesture.unit.js b/test/unit/angular/directive/gesture.unit.js new file mode 100644 index 0000000000..7d266dfb44 --- /dev/null +++ b/test/unit/angular/directive/gesture.unit.js @@ -0,0 +1,36 @@ +describe('gesture directive', function() { + beforeEach(module('ionic')); + + 'onHold onTap onTouch onRelease onDrag onDragUp onDragRight onDragDown onDragLeft onSwipe onSwipeUp onSwipeRight onSwipeBottom onSwipeLeft' + .split(' ') + .map(function(directiveName) { + return { + gestureName: directiveName.substr(2).toLowerCase(), + directiveName: directiveName, + htmlName: directiveName.replace(/[A-Z]/g, function(match, i) { + return '-' + match.toLowerCase(); + }) + }; + }) + .forEach(function(directive){ + it('should compile', inject(function($compile, $rootScope, $ionicGesture) { + var fakeGesture = {}; + spyOn($ionicGesture, 'on').andCallFake(function(eventType, listener, el) { + callback = listener; + return fakeGesture; + }); + spyOn($ionicGesture, 'off'); + var el = $compile('
')($rootScope.$new()); + $rootScope.$apply(); + + el.scope().foo = jasmine.createSpy('foo'); + + expect($ionicGesture.on.mostRecentCall.args[0]).toBe(directive.gestureName); + var event = {}; + callback(event); + expect(el.scope().foo).toHaveBeenCalledWith(1, event); + el.scope().$destroy(); + expect($ionicGesture.off).toHaveBeenCalledWith(fakeGesture, directive.gestureName, callback); + })); + }); +}); diff --git a/test/unit/angular/directive/gestures.js b/test/unit/angular/directive/gestures.js deleted file mode 100644 index e69de29bb2..0000000000