Skip to content

Commit 634b397

Browse files
committed
fix(ionList): disable tap on element being edited
Addresses #1202
1 parent 8e3a3d0 commit 634b397

File tree

3 files changed

+27
-13
lines changed

3 files changed

+27
-13
lines changed

js/angular/directive/list.js

+15-2
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ function($animate, $timeout) {
137137

138138
$element.children().toggleClass('list-left-editing', isShown);
139139
toggleNgHide('.item-delete.item-left-edit', isShown);
140+
toggleTapDisabled('.item-content', isShown);
140141
});
141142
$scope.$watch(function() {
142143
return listCtrl.showReorder();
@@ -149,14 +150,26 @@ function($animate, $timeout) {
149150

150151
$element.children().toggleClass('list-right-editing', isShown);
151152
toggleNgHide('.item-reorder.item-right-edit', isShown);
153+
toggleTapDisabled('.item-content', isShown);
152154
});
153155

154156
function toggleNgHide(selector, shouldShow) {
155157
angular.forEach($element[0].querySelectorAll(selector), function(node) {
156-
if (shouldShow) $animate.removeClass(angular.element(node), 'ng-hide');
157-
else $animate.addClass(angular.element(node), 'ng-hide');
158+
if (shouldShow) {
159+
$animate.removeClass(angular.element(node), 'ng-hide');
160+
} else {
161+
$animate.addClass(angular.element(node), 'ng-hide');
162+
}
158163
});
159164
}
165+
function toggleTapDisabled(selector, shouldDisable) {
166+
var el = angular.element($element[0].querySelectorAll(selector));
167+
if (shouldDisable) {
168+
el.attr('data-tap-disabled', 'true');
169+
} else {
170+
el.removeAttr('data-tap-disabled');
171+
}
172+
}
160173
}
161174

162175
};

test/html/list.html

+12-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<html ng-app="ionicApp">
22
<head>
3+
34
<meta charset="utf-8">
45
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
56
<title>Ionic List Directive</title>
@@ -51,7 +52,7 @@ <h1 class="title">Ionic Delete/Option Buttons</h1>
5152
Type 1
5253
</div>
5354
<ion-item ng-repeat="item in items"
54-
href="#{{item.id}}"
55+
ng-click="alert(item.id)"
5556
class="item item-avatar-left item-icon-right"
5657
type="item-avatar" >
5758
<img src="{{item.image}}">
@@ -69,7 +70,7 @@ <h2>Item {{ item.id }}</h2>
6970
ng-click="share(item)">
7071
Share
7172
</ion-option-button>
72-
<ion-reorder-button class="ion-navicon" on-reoder="moveItem(item, fromIndex, toIndex)"></ion-reorder-button>
73+
<ion-reorder-button class="ion-navicon" on-reorder="moveItem(item, $fromIndex, $toIndex)"></ion-reorder-button>
7374
</ion-item>
7475

7576
</ion-list>
@@ -85,18 +86,22 @@ <h2>Item {{ item.id }}</h2>
8586
showDelete: false
8687
};
8788

89+
$scope.moveItem = function(item, from, to) {
90+
console.log('beforeReorder', item, from, to, $scope.items.slice(0,5));
91+
$scope.items.splice(from, 1);
92+
$scope.items.splice(to, 0, item);
93+
console.log('afterReorder', $scope.items.slice(0,5));
94+
};
95+
96+
$scope.alert = window.alert.bind(window);
97+
8898
$scope.edit = function(item) {
8999
alert('Edit Item: ' + item.id);
90100
};
91101
$scope.share = function(item) {
92102
alert('Share Item: ' + item.id);
93103
};
94104

95-
$scope.moveItem = function(item, fromIndex, toIndex) {
96-
$scope.items.splice(fromIndex, 1);
97-
$scope.items.splice(toIndex, 0, item);
98-
};
99-
100105
$scope.onItemDelete = function(item) {
101106
$scope.items.splice($scope.items.indexOf(item), 1);
102107
};

test/unit/angular/directive/list.unit.js

-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
describe('',function(){
2-
31
describe('$ionicList controller', function() {
42
beforeEach(module('ionic'));
53
function setup(attrs) {
@@ -332,5 +330,3 @@ describe('ionOptionButton directive', function() {
332330
expect(optionContainer.children().hasClass('button')).toBe(true);
333331
}));
334332
});
335-
336-
});

0 commit comments

Comments
 (0)