Added threshold before starting drag. Added default of 10px
This commit is contained in:
Max Lynch
2013-10-08 18:15:59 -05:00
parent 942b8b1c35
commit a175b9ce71
2 changed files with 44 additions and 34 deletions

39
dist/ionic.js vendored
View File

@ -2444,6 +2444,7 @@ ionic.controllers.NavController.prototype = {
this.left = options.left;
this.right = options.right;
this.content = options.content;
this.dragThresholdX = options.dragThresholdX || 10;
this._rightShowing = false;
this._leftShowing = false;
@ -2661,33 +2662,37 @@ ionic.controllers.NavController.prototype = {
// End a drag with the given event
_endDrag: function(e) {
this.snapToRest(e);
this._startX = null;
this._lastX = null;
this._offsetX = null;
},
// Initialize a drag with the given event
_initDrag: function(e) {
this.content.disableAnimation();
this._isDragging = true;
this._startX = 0;
this._offsetX = 0;
this._lastX = 0;
},
// Handle a drag event
_handleDrag: function(e) {
if(!this._isDragging) {
this._initDrag(e);
// If we don't have start coords, grab and store them
if(!this._startX) {
this._startX = e.gesture.touches[0].pageX;
this._lastX = this._startX;
} else {
// Grab the current tap coords
this._lastX = e.gesture.touches[0].pageX;
}
// Calculate difference from the tap points
if(Math.abs(this._lastX - this._startX) > this.dragThresholdX) {
// if the difference is greater than threshold, start dragging using the current
// point as the starting point
this._startX = this._lastX
this._isDragging = true;
// Initialize dragging
this.content.disableAnimation();
this._offsetX = this.getOpenAmount();
}
var newX = this._offsetX + (this._lastX - this._startX);
this.openAmount(newX);
this._lastX = e.gesture.touches[0].pageX;
if(this._isDragging) {
this.openAmount(this._offsetX + (this._lastX - this._startX));
}
}
};

View File

@ -12,6 +12,7 @@
this.left = options.left;
this.right = options.right;
this.content = options.content;
this.dragThresholdX = options.dragThresholdX || 10;
this._rightShowing = false;
this._leftShowing = false;
@ -229,33 +230,37 @@
// End a drag with the given event
_endDrag: function(e) {
this.snapToRest(e);
this._startX = null;
this._lastX = null;
this._offsetX = null;
},
// Initialize a drag with the given event
_initDrag: function(e) {
this.content.disableAnimation();
this._isDragging = true;
this._startX = 0;
this._offsetX = 0;
this._lastX = 0;
},
// Handle a drag event
_handleDrag: function(e) {
if(!this._isDragging) {
this._initDrag(e);
// If we don't have start coords, grab and store them
if(!this._startX) {
this._startX = e.gesture.touches[0].pageX;
this._lastX = this._startX;
} else {
// Grab the current tap coords
this._lastX = e.gesture.touches[0].pageX;
}
// Calculate difference from the tap points
if(Math.abs(this._lastX - this._startX) > this.dragThresholdX) {
// if the difference is greater than threshold, start dragging using the current
// point as the starting point
this._startX = this._lastX
this._isDragging = true;
// Initialize dragging
this.content.disableAnimation();
this._offsetX = this.getOpenAmount();
}
var newX = this._offsetX + (this._lastX - this._startX);
this.openAmount(newX);
this._lastX = e.gesture.touches[0].pageX;
if(this._isDragging) {
this.openAmount(this._offsetX + (this._lastX - this._startX));
}
}
};