mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
refactor(ionicTouch): factor ngClick logic out to reusable service
Addresses #802
This commit is contained in:
22
js/ext/angular/src/directive/ionicTouch.js
vendored
22
js/ext/angular/src/directive/ionicTouch.js
vendored
@@ -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 () {
|
||||
|
||||
Reference in New Issue
Block a user