Skip to content

Commit

Permalink
fix stop swiping until animating
Browse files Browse the repository at this point in the history
  • Loading branch information
snake-345 committed Apr 25, 2018
1 parent 7ccde08 commit 8b39e23
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "jcarouselSwipe",
"main": "./dist/jquery.jcarousel-swipe.js",
"version": "0.3.6",
"version": "0.3.7",
"authors": [
"Evgeniy Pelmenev <[email protected]>"
],
Expand Down
19 changes: 11 additions & 8 deletions dist/jquery.jcarousel-swipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
var startTouch = {};
var currentTouch = {};
var started = false;
var animated = false;
var xKey = !this._instance.vertical ? 'x' : 'y';
var yKey = !this._instance.vertical ? 'y' : 'x';
var edgeLT, lastItem;
Expand All @@ -49,7 +48,7 @@
startTouch = getTouches(event);
startTarget = event.target || event.srcElement;

if (self._options.draggable) {
if (self._options.draggable && !self._instance.animating) {
$(document).on('touchmove.jcarouselSwipe mousemove.jcarouselSwipe', dragMove);
}
$(document).on('touchend.jcarouselSwipe touchcancel.jcarouselSwipe mouseup.jcarouselSwipe', dragEnd);
Expand All @@ -59,17 +58,19 @@
var delta, newLT, itemsOption;
event = event.originalEvent || event || window.event;
currentTouch = getTouches(event);
var xDiff = Math.abs(startTouch[xKey] - currentTouch[xKey]);
var yDiff = Math.abs(startTouch[yKey] - currentTouch[yKey]);

if (started) {
event.preventDefault();
}

if (Math.abs(startTouch[yKey] - currentTouch[yKey]) > 10 && !started) {
if (yDiff > 10 && yDiff > xDiff && !started) {
$(document).off('touchmove.jcarouselSwipe mousemove.jcarouselSwipe');
return;
}

if (!animated && Math.abs(startTouch[xKey] - currentTouch[xKey]) > 10) {
if (!self._instance.animating && xDiff > 10 || started) {
delta = startTouch[xKey] - currentTouch[xKey];

if (!started) {
Expand Down Expand Up @@ -99,7 +100,10 @@
function dragEnd(event) {
event = event.originalEvent || event || window.event;
currentTouch = getTouches(event);
if (started || (!self._options.draggable && Math.abs(startTouch[xKey] - currentTouch[xKey]) > 10)) {
var xDiff = Math.abs(startTouch[xKey] - currentTouch[xKey]);
var yDiff = Math.abs(startTouch[yKey] - currentTouch[yKey]);

if (started || (!self._options.draggable && xDiff > 10 && xDiff > yDiff)) {
var newTarget = self._getNewTarget(startTouch[xKey] - currentTouch[xKey] > 0);
newTarget = self._instance._options.wrap === 'circular' ? newTarget.relative : newTarget.static;

Expand All @@ -116,10 +120,9 @@
self._removeClones();
self._instance._items = null;
}
animated = true;

started = false;
self._instance[self._options.method](newTarget, function() {
started = false;
animated = false;
if (self._instance._options.wrap !== 'circular') {
self._removeClones();
self._instance._items = null;
Expand Down
2 changes: 1 addition & 1 deletion dist/jquery.jcarousel-swipe.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jcarouselSwipe",
"version": "0.3.6",
"version": "0.3.7",
"description": "Adds comfortable swipe gestures to jcarousel",
"author": "Evgeniy Pelmenev <[email protected]>",
"license": "MIT",
Expand Down
10 changes: 4 additions & 6 deletions src/jquery.jcarousel-swipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
var startTouch = {};
var currentTouch = {};
var started = false;
var animated = false;
var xKey = !this._instance.vertical ? 'x' : 'y';
var yKey = !this._instance.vertical ? 'y' : 'x';
var edgeLT, lastItem;
Expand All @@ -49,7 +48,7 @@
startTouch = getTouches(event);
startTarget = event.target || event.srcElement;

if (self._options.draggable) {
if (self._options.draggable && !self._instance.animating) {
$(document).on('touchmove.jcarouselSwipe mousemove.jcarouselSwipe', dragMove);
}
$(document).on('touchend.jcarouselSwipe touchcancel.jcarouselSwipe mouseup.jcarouselSwipe', dragEnd);
Expand All @@ -71,7 +70,7 @@
return;
}

if (!animated && xDiff > 10 || started) {
if (!self._instance.animating && xDiff > 10 || started) {
delta = startTouch[xKey] - currentTouch[xKey];

if (!started) {
Expand Down Expand Up @@ -121,10 +120,9 @@
self._removeClones();
self._instance._items = null;
}
animated = true;

started = false;
self._instance[self._options.method](newTarget, function() {
started = false;
animated = false;
if (self._instance._options.wrap !== 'circular') {
self._removeClones();
self._instance._items = null;
Expand Down

0 comments on commit 8b39e23

Please sign in to comment.