|
77 | 77 | * - added option method to update init options at runtime
|
78 | 78 | *
|
79 | 79 | * $version 1.6.3 - added doubletap, longtap events and longTapThreshold, doubleTapThreshold property
|
| 80 | +* $Date: 2013-04-04 (Thurs, 04 April 2013) $ |
| 81 | +* $version 1.6.4 - Fixed bug with cancelThreshold introduced in 1.6.3, where swipe status no longer fired start event, and stopped once swiping back. |
80 | 82 | */
|
81 | 83 |
|
82 | 84 | /**
|
|
143 | 145 | * @namespace
|
144 | 146 | * @property {int} [fingers=1] The number of fingers to detect in a swipe. Any swipes that do not meet this requirement will NOT trigger swipe handlers.
|
145 | 147 | * @property {int} [threshold=75] The number of pixels that the user must move their finger by before it is considered a swipe.
|
146 |
| - * @property {int} [cancelThreshold=25] The number of pixels that the user must move their finger back from the original swipe direction to cancel the gesture. |
| 148 | + * @property {int} [cancelThreshold=null] The number of pixels that the user must move their finger back from the original swipe direction to cancel the gesture. |
147 | 149 | * @property {int} [pinchThreshold=20] The number of pixels that the user must pinch their finger by before it is considered a pinch.
|
148 | 150 | * @property {int} [maxTimeThreshold=null] Time, in milliseconds, between touchStart and touchEnd must NOT exceed in order to be considered a swipe.
|
149 | 151 | * @property {int} [fingerReleaseThreshold=250] Time in milliseconds between releasing multiple fingers. If 2 fingers are down, and are released one after the other, if they are within this threshold, it counts as a simultaneous release.
|
|
175 | 177 | var defaults = {
|
176 | 178 | fingers: 1,
|
177 | 179 | threshold: 75,
|
178 |
| - cancelThreshold:25, |
| 180 | + cancelThreshold:null, |
179 | 181 | pinchThreshold:20,
|
180 | 182 | maxTimeThreshold: null,
|
181 | 183 | fingerReleaseThreshold:250,
|
|
722 | 724 | duration = calculateDuration();
|
723 | 725 |
|
724 | 726 | //If we trigger handlers at end of swipe OR, we trigger during, but they didnt trigger and we are still in the move phase
|
725 |
| - if (options.triggerOnTouchEnd || (options.triggerOnTouchEnd == false && phase === PHASE_MOVE)) { |
| 727 | + if(didSwipeBackToCancel()) { |
| 728 | + phase = PHASE_CANCEL; |
| 729 | + triggerHandler(event, phase); |
| 730 | + } else if (options.triggerOnTouchEnd || (options.triggerOnTouchEnd == false && phase === PHASE_MOVE)) { |
726 | 731 | phase = PHASE_END;
|
727 | 732 | triggerHandler(event, phase);
|
728 | 733 | }
|
|
810 | 815 | // Ensure we have valid swipe (under time and over distance and check if we are out of bound...)
|
811 | 816 | var validTime = validateSwipeTime();
|
812 | 817 | var validDistance = validateSwipeDistance();
|
813 |
| - |
| 818 | + var didCancel = didSwipeBackToCancel(); |
814 | 819 |
|
815 | 820 | //If we have exceeded our time, then cancel
|
816 |
| - if(!validTime) { |
| 821 | + if(!validTime || didCancel) { |
817 | 822 | nextPhase = PHASE_CANCEL;
|
818 | 823 | }
|
819 | 824 | //Else if we are moving, and have reached distance then end
|
|
825 | 830 | nextPhase = PHASE_CANCEL;
|
826 | 831 | }
|
827 | 832 |
|
828 |
| - |
829 | 833 | return nextPhase;
|
830 | 834 | }
|
831 | 835 |
|
|
842 | 846 | var ret = undefined;
|
843 | 847 |
|
844 | 848 | // SWIPE GESTURES
|
845 |
| - if(didSwipe()) { |
| 849 | + if(didSwipe() || hasSwipes()) { //hasSwipes as status needs to fire even if swipe is invalid |
846 | 850 | //Trigger the swipe events...
|
847 | 851 | ret = triggerHandlerForGesture(event, phase, SWIPE);
|
848 |
| - } |
| 852 | + } |
849 | 853 |
|
850 | 854 | // PINCH GESTURES (if the above didnt cancel)
|
851 |
| - else if(didPinch() && ret!==false) { |
| 855 | + else if((didPinch() || hasPinches()) && ret!==false) { |
852 | 856 | //Trigger the pinch events...
|
853 | 857 | ret = triggerHandlerForGesture(event, phase, PINCH);
|
854 | 858 | }
|
|
1121 | 1125 | valid = distance >= options.threshold;
|
1122 | 1126 | }
|
1123 | 1127 |
|
1124 |
| - //And we didn't swipe back to cancel... |
1125 |
| - if(valid && options.cancelThreshold !== null) { |
1126 |
| - valid = (getMaxDistance( direction ) - distance) < options.cancelThreshold; |
| 1128 | + return valid; |
| 1129 | + } |
| 1130 | + |
| 1131 | + /** |
| 1132 | + * Checks the user has swiped back to cancel. |
| 1133 | + * @return Boolean if <code>cancelThreshold</code> has been set, return true if the cancelThreshold was met, else false. |
| 1134 | + * If no cancelThreshold was set, then we return true. |
| 1135 | + * @inner |
| 1136 | + */ |
| 1137 | + function didSwipeBackToCancel() { |
| 1138 | + var cancelled = false; |
| 1139 | + if(options.cancelThreshold !== null && direction !==null) { |
| 1140 | + cancelled = (getMaxDistance( direction ) - distance) >= options.cancelThreshold; |
1127 | 1141 | }
|
1128 | 1142 |
|
1129 |
| - return valid; |
| 1143 | + return cancelled; |
1130 | 1144 | }
|
1131 | 1145 |
|
1132 | 1146 | /**
|
|
1256 | 1270 | function validateSwipe() {
|
1257 | 1271 | //Check validity of swipe
|
1258 | 1272 | var hasValidTime = validateSwipeTime();
|
1259 |
| - var hasValidDistance = validateSwipeDistance(); |
1260 |
| - var hasCorrectFingerCount = validateFingers(); |
| 1273 | + var hasValidDistance = validateSwipeDistance(); |
| 1274 | + var hasCorrectFingerCount = validateFingers(); |
1261 | 1275 | var hasEndPoint = validateEndPoint();
|
| 1276 | + var didCancel = didSwipeBackToCancel(); |
1262 | 1277 |
|
1263 | 1278 | // if the user swiped more than the minimum length, perform the appropriate action
|
1264 | 1279 | // hasValidDistance is null when no distance is set
|
1265 |
| - var valid = hasEndPoint && hasCorrectFingerCount && hasValidDistance && hasValidTime; |
| 1280 | + var valid = !didCancel && hasEndPoint && hasCorrectFingerCount && hasValidDistance && hasValidTime; |
1266 | 1281 |
|
1267 | 1282 | return valid;
|
1268 | 1283 | }
|
|
0 commit comments