feat(ionSideMenu): add edge-drag-threshold, delegate edgeDragThreshold()

Closes #1570
This commit is contained in:
MGMsystems
2014-06-04 13:41:56 +02:00
committed by Andrew
parent ba1859b308
commit ba56bb983f
5 changed files with 59 additions and 5 deletions

View File

@@ -9,6 +9,7 @@ function($scope, $attrs, $ionicSideMenuDelegate, $ionicPlatform) {
extend(this, ionic.controllers.SideMenuController.prototype);
this.$scope = $scope;
this.dragThreshold = 25;
ionic.controllers.SideMenuController.call(this, {
left: { width: 275 },
@@ -22,6 +23,19 @@ function($scope, $attrs, $ionicSideMenuDelegate, $ionicPlatform) {
return $scope.dragContent;
};
this.dragThreshold = 25;
this.edgeDragThreshold = function(value) {
if (arguments.length) {
if (angular.isNumber(value) && value > 0) {
this.dragThreshold = value;
this.dragOnlyEdge = true;
} else {
this.dragOnlyEdge = !!value;
}
}
return this.dragOnlyEdge;
};
this.isDraggableTarget = function(e) {
return $scope.dragContent &&
(!e.gesture.srcEvent.defaultPrevented &&

View File

@@ -12,6 +12,7 @@
* @usage
* ```html
* <ion-side-menu-content
* edge-drag-threshold="true"
* drag-content="true">
* </ion-side-menu-content>
* ```
@@ -19,6 +20,10 @@
* {@link ionic.directive:ionSideMenus} documentation.
*
* @param {boolean=} drag-content Whether the content can be dragged. Default true.
* @param {boolean|number=} edge-drag-threshold Whether the content drag can only start if it is below a certain threshold distance from the edge of the screen. Default false. Accepts three types of values:
* - If a non-zero number is given, that many pixels is used as the maximum allowed distance from the edge that starts dragging the side menu.
* - If true is given, the default number of pixels (25) is used as the maximum allowed distance.
* - If false or 0 is given, the edge drag threshold is disabled, and dragging from anywhere on the content is allowed.
*
*/
IonicModule
@@ -37,7 +42,7 @@ function($timeout, $ionicGesture) {
$element.addClass('menu-content pane');
if (angular.isDefined(attr.dragContent)) {
if (isDefined(attr.dragContent)) {
$scope.$watch(attr.dragContent, function(value) {
sideMenuCtrl.canDragContent(value);
});
@@ -45,6 +50,12 @@ function($timeout, $ionicGesture) {
sideMenuCtrl.canDragContent(true);
}
if (isDefined(attr.edgeDragThreshold)) {
$scope.$watch(attr.edgeDragThreshold, function(value) {
sideMenuCtrl.edgeDragThreshold(value);
});
}
var defaultPrevented = false;
var isDragging = false;
@@ -87,6 +98,7 @@ function($timeout, $ionicGesture) {
var releaseGesture = $ionicGesture.on('release', dragReleaseFn, $element);
sideMenuCtrl.setContent({
element: element[0],
onDrag: function(e) {},
endDrag: function(e) {},
getTranslateX: function() {

View File

@@ -89,7 +89,17 @@ IonicModule
* side menus.
* @returns {boolean} Whether the content can be dragged to open side menus.
*/
'canDragContent'
'canDragContent',
/**
* @ngdoc method
* @name $ionicSideMenuDelegate#edgeDragThreshold
* @param {boolean|number=} value Set whether the content drag can only start if it is below a certain threshold distance from the edge of the screen. Accepts three different values:
* - If a non-zero number is given, that many pixels is used as the maximum allowed distance from the edge that starts dragging the side menu.
* - If true is given, the default number of pixels (25) is used as the maximum allowed distance.
* - If false or 0 is given, the edge drag threshold is disabled, and dragging from anywhere on the content is allowed.
* @returns {boolean} Whether the drag can start only from within the edge of screen threshold.
*/
'edgeDragThreshold',
/**
* @ngdoc method
* @name $ionicSideMenuDelegate#$getByHandle