diff --git a/js/angular/directive/gesture.js b/js/angular/directive/gesture.js index b7eadf0d3d..b30e326a1b 100644 --- a/js/angular/directive/gesture.js +++ b/js/angular/directive/gesture.js @@ -1,6 +1,11 @@ +forEach( + 'onHold onTap onTouch onRelease onDrag onDragUp onDragRight onDragDown onDragLeft onSwipe onSwipeUp onSwipeRight onSwipeBottom onSwipeLeft'.split(' '), + function(name) { + IonicModule.directive(name, gestureDirective(name)); + } +); -IonicModule /** * @ngdoc directive @@ -16,7 +21,6 @@ IonicModule * * ``` */ - .directive('onHold', gestureDirective('onHold')) /** @@ -34,7 +38,6 @@ IonicModule * * ``` */ - .directive('onTap', gestureDirective('onTap')) /** @@ -52,7 +55,6 @@ IonicModule * * ``` */ - .directive('onTouch', gestureDirective('onTouch')) /** @@ -69,7 +71,6 @@ IonicModule * * ``` */ - .directive('onRelease', gestureDirective('onRelease')) /** @@ -88,7 +89,6 @@ IonicModule * * ``` */ - .directive('onDrag', gestureDirective('onDrag')) /** @@ -105,7 +105,6 @@ IonicModule * * ``` */ - .directive('onDragUp', gestureDirective('onDragUp')) /** @@ -122,7 +121,6 @@ IonicModule * * ``` */ - .directive('onDragRight', gestureDirective('onDragRight')) /** @@ -139,7 +137,6 @@ IonicModule * * ``` */ - .directive('onDragDown', gestureDirective('onDragDown')) /** @@ -156,7 +153,6 @@ IonicModule * * ``` */ - .directive('onDragLeft', gestureDirective('onDragLeft')) /** @@ -173,7 +169,6 @@ IonicModule * * ``` */ - .directive('onSwipe', gestureDirective('onSwipe')) /** @@ -190,7 +185,6 @@ IonicModule * * ``` */ - .directive('onSwipeUp', gestureDirective('onSwipeUp')) /** @@ -207,7 +201,6 @@ IonicModule * * ``` */ - .directive('onSwipeRight', gestureDirective('onSwipeRight')) /** @@ -224,7 +217,6 @@ IonicModule * * ``` */ - .directive('onSwipeDown', gestureDirective('onSwipeDown')) /** @@ -241,27 +233,30 @@ IonicModule * * ``` */ - .directive('onSwipeLeft', gestureDirective('onSwipeLeft')); - -function gestureDirective(attrName) { - return ['$ionicGesture', function($ionicGesture) { +function gestureDirective(directiveName) { + return ['$ionicGesture', '$parse', function($ionicGesture, $parse) { return { restrict: 'A', - link: function($scope, $element, $attr) { - var eventType = attrName.substr(2).toLowerCase(); + compile: function($element, attr) { + var fn = $parse( attr[directiveName] ); + var eventType = directiveName.substr(2).toLowerCase(); - var listener = function(ev) { - $scope.$apply( $attr[attrName] ); + 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 gesture = $ionicGesture.on(eventType, listener, $element); - - $scope.$on('$destroy', function() { - $ionicGesture.off(gesture, eventType, listener); - }); - } }; }]; diff --git a/test/html/gesture.html b/test/html/gesture.html index 7cf926f6d6..ac5ab4f798 100644 --- a/test/html/gesture.html +++ b/test/html/gesture.html @@ -36,48 +36,48 @@

- - - - - -

-
+
Swipe (any direction)
-
+
Swipe Left
-
+
Swipe Right
-
+
Swipe Down
-
+
Swipe Up
@@ -90,8 +90,8 @@ .controller('AppCtrl', function($scope) { - $scope.gestureTest = function(data) { - o('gesture directive test', [data]) + $scope.gestureTest = function($event, data) { + o('gesture directive test', [$event.type, data]) }; })