refactor(ionicTouch): factor ngClick logic out to reusable service

Addresses #802
This commit is contained in:
Andy Joslin
2014-03-15 09:24:05 -06:00
parent baa04cde4d
commit 90f360c827

View File

@@ -1,10 +1,9 @@
// Similar to Angular's ngTouch, however it uses Ionic's tap detection
// and click simulation. ngClick
// and click simulation. ngClick
(function(angular, ionic) {'use strict';
angular.module('ionic.ui.touch', [])
.config(['$provide', function($provide) {
@@ -15,17 +14,16 @@ angular.module('ionic.ui.touch', [])
}]);
}])
.directive('ngClick', ['$parse', function($parse) {
/**
* @private
*/
.factory('$ionicNgClick', ['$parse', function($parse) {
function onTap(e) {
// wire this up to Ionic's tap/click simulation
ionic.tapElement(e.target, e);
}
// Actual linking function.
return function(scope, element, attr) {
var clickHandler = $parse(attr.ngClick);
return function(scope, element, clickExpr) {
var clickHandler = $parse(clickExpr);
element.on('click', function(event) {
scope.$apply(function() {
@@ -42,9 +40,13 @@ angular.module('ionic.ui.touch', [])
scope.$on('$destroy', function () {
ionic.off('tap', onTap, element[0]);
});
};
}])
.directive('ngClick', ['$ionicNgClick', function($ionicNgClick) {
return function(scope, element, attr) {
$ionicNgClick(scope, element, attr.ngClick);
};
}])
.directive('ionStopEvent', function () {