mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
This change makes the DelegateService available on the ionic namespace. It is useful so external directives can follow the delegate pattern set by the framework itself.
120 lines
3.2 KiB
JavaScript
120 lines
3.2 KiB
JavaScript
|
|
/**
|
|
* @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();
|
|
};
|
|
}]);
|