Skip to content

Commit

Permalink
Fix sidebar
Browse files Browse the repository at this point in the history
  • Loading branch information
qwtel committed Sep 16, 2016
1 parent 99ea12e commit 436c19d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 30 deletions.
64 changes: 35 additions & 29 deletions public/js/hydejack.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@
var startTranslateX = 0;
var translateX = 0;
var animationFrameRequested = false;
var touching = false;

var animationStartTime;
var animationStartX;
Expand Down Expand Up @@ -254,42 +255,44 @@
}

function onTouchMove(e) {
var touch = getNearestTouch(e.touches);
pageX = touch.pageX;
pageY = touch.pageY;

if (typeof isScrolling === 'undefined' && startedMoving) {
isScrolling = Math.abs(startY - pageY) > Math.abs(startX - pageX);
if (!isScrolling) {
state = START_TOUCHING;
requestAnimationLoop();
if (touching) {
var touch = getNearestTouch(e.touches);
pageX = touch.pageX;
pageY = touch.pageY;

if (typeof isScrolling === 'undefined' && startedMoving) {
isScrolling = Math.abs(startY - pageY) > Math.abs(startX - pageX);
if (!isScrolling) {
state = START_TOUCHING;
requestAnimationLoop();
}
}
}

if (isScrolling && !menuOpen) return;
if (isScrolling && !menuOpen) return;

e.preventDefault();
e.preventDefault();

startedMoving = true;
startedMoving = true;
}
}

function onTouchEnd(e) {
if (isScrolling || e.touches.length > 0) {
return;
}

if (startedMoving) {
menuOpen = velocity > VELOCITY_THRESHOLD ? 1 :
velocity < -VELOCITY_THRESHOLD ? 0 :
translateX >= sliderWidth / 2 ? 1 :
0;
}
if (touching) {
if (isScrolling || e.touches.length > 0) {
return;
}

state = START_ANIMATING;
startedMoving = false;
if (startedMoving) {
menuOpen = velocity > VELOCITY_THRESHOLD ? 1 :
velocity < -VELOCITY_THRESHOLD ? 0 :
translateX >= sliderWidth / 2 ? 1 :
0;
}

document.removeEventListener('touchmove', onTouchMove);
document.removeEventListener('touchend', onTouchEnd);
touching = false;
state = START_ANIMATING;
startedMoving = false;
}
}

function onTouchStart(e) {
Expand All @@ -316,8 +319,7 @@
startY = pageY = lastPageY = touch.pageY;

if (menuOpen || (!menuOpen && pageX < window.innerWidth / 3/* && !isCodeBlock(e.path)*/)) {
document.addEventListener('touchmove', onTouchMove);
document.addEventListener('touchend', onTouchEnd);
touching = true;
}
}
}
Expand Down Expand Up @@ -431,6 +433,8 @@
function enableSlider() {
document.body.classList.add('drawer');
document.addEventListener('touchstart', onTouchStart);
document.addEventListener('touchmove', onTouchMove);
document.addEventListener('touchend', onTouchEnd);
menu.addEventListener('click', onMenuClick);
backdrop.addEventListener('click', onBackdropClick);
animateTo(menuOpen);
Expand All @@ -439,6 +443,8 @@
function disableSlider() {
document.body.classList.remove('drawer')
document.removeEventListener('touchstart', onTouchStart);
document.removeEventListener('touchmove', onTouchMove);
document.removeEventListener('touchend', onTouchEnd);
menu.removeEventListener('click', onMenuClick);
backdrop.removeEventListener('click', onBackdropClick);
}
Expand Down
2 changes: 1 addition & 1 deletion public/js/hydejack.min.js

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

0 comments on commit 436c19d

Please sign in to comment.