Skip to content

Commit

Permalink
Fixes woocommerce#958. Declare onTouchStart, onTouchEnd, onTouchMove …
Browse files Browse the repository at this point in the history
…as function expressions.

This way they get hoisted properly and we don't rely on undefined
behavior (which doesn't work in some browsers).
  • Loading branch information
Mike Taylor committed Apr 28, 2015
1 parent 6df2881 commit 887f6ff
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions jquery.flexslider.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,15 +390,16 @@
cwidth,
dx,
startT,
onTouchStart,
onTouchMove,
onTouchEnd,
scrolling = false,
localX = 0,
localY = 0,
accDx = 0;

if(!msGesture){
el.addEventListener('touchstart', onTouchStart, false);

function onTouchStart(e) {
onTouchStart = function(e) {
if (slider.animating) {
e.preventDefault();
} else if ( ( window.navigator.msPointerEnabled ) || e.touches.length === 1 ) {
Expand All @@ -423,9 +424,9 @@
el.addEventListener('touchmove', onTouchMove, false);
el.addEventListener('touchend', onTouchEnd, false);
}
}
};

function onTouchMove(e) {
onTouchMove = function(e) {
// Local vars for X and Y points.

localX = e.touches[0].pageX;
Expand All @@ -445,9 +446,9 @@
slider.setProps(offset + dx, "setTouch");
}
}
}
};

function onTouchEnd(e) {
onTouchEnd = function(e) {
// finish the touch by undoing the touch session
el.removeEventListener('touchmove', onTouchMove, false);

Expand All @@ -467,7 +468,9 @@
startY = null;
dx = null;
offset = null;
}
};

el.addEventListener('touchstart', onTouchStart, false);
}else{
el.style.msTouchAction = "none";
el._gesture = new MSGesture();
Expand Down

0 comments on commit 887f6ff

Please sign in to comment.