forked from ionic-team/ionic-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlistController.js
117 lines (111 loc) · 3.23 KB
/
listController.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/**
* @ngdoc service
* @name $ionicListDelegate
* @module ionic
*
* @description
* Delegate for controlling the {@link ionic.directive:ionList} directive.
*
* Methods called directly on the $ionicListDelegate service will control all lists.
* Use the {@link ionic.service:$ionicListDelegate#$getByHandle $getByHandle}
* method to control specific ionList instances.
*
* @usage
*
* ````html
* <ion-content ng-controller="MyCtrl">
* <button class="button" ng-click="showDeleteButtons()"></button>
* <ion-list>
* <ion-item ng-repeat="i in items">
* {% raw %}Hello, {{i}}!{% endraw %}
* <ion-delete-button class="ion-minus-circled"></ion-delete-button>
* </ion-item>
* </ion-list>
* </ion-content>
* ```
* ```js
* function MyCtrl($scope, $ionicListDelegate) {
* $scope.showDeleteButtons = function() {
* $ionicListDelegate.showDelete(true);
* };
* }
* ```
*/
IonicModule.service('$ionicListDelegate', ionic.DelegateService([
/**
* @ngdoc method
* @name $ionicListDelegate#showReorder
* @param {boolean=} showReorder Set whether or not this list is showing its reorder buttons.
* @returns {boolean} Whether the reorder buttons are shown.
*/
'showReorder',
/**
* @ngdoc method
* @name $ionicListDelegate#showDelete
* @param {boolean=} showDelete Set whether or not this list is showing its delete buttons.
* @returns {boolean} Whether the delete buttons are shown.
*/
'showDelete',
/**
* @ngdoc method
* @name $ionicListDelegate#canSwipeItems
* @param {boolean=} canSwipeItems Set whether or not this list is able to swipe to show
* option buttons.
* @returns {boolean} Whether the list is able to swipe to show option buttons.
*/
'canSwipeItems',
/**
* @ngdoc method
* @name $ionicListDelegate#closeOptionButtons
* @description Closes any option buttons on the list that are swiped open.
*/
'closeOptionButtons'
/**
* @ngdoc method
* @name $ionicListDelegate#$getByHandle
* @param {string} handle
* @returns `delegateInstance` A delegate instance that controls only the
* {@link ionic.directive:ionList} directives with `delegate-handle` matching
* the given handle.
*
* Example: `$ionicListDelegate.$getByHandle('my-handle').showReorder(true);`
*/
]))
.controller('$ionicList', [
'$scope',
'$attrs',
'$ionicListDelegate',
'$ionicHistory',
function($scope, $attrs, $ionicListDelegate, $ionicHistory) {
var self = this;
var isSwipeable = true;
var isReorderShown = false;
var isDeleteShown = false;
var deregisterInstance = $ionicListDelegate._registerInstance(
self, $attrs.delegateHandle, function() {
return $ionicHistory.isActiveScope($scope);
}
);
$scope.$on('$destroy', deregisterInstance);
self.showReorder = function(show) {
if (arguments.length) {
isReorderShown = !!show;
}
return isReorderShown;
};
self.showDelete = function(show) {
if (arguments.length) {
isDeleteShown = !!show;
}
return isDeleteShown;
};
self.canSwipeItems = function(can) {
if (arguments.length) {
isSwipeable = !!can;
}
return isSwipeable;
};
self.closeOptionButtons = function() {
self.listView && self.listView.clearDragEffects();
};
}]);