Created
May 14, 2019 20:17
-
-
Save sjurgis/7a648811af2a99f4657b3158e43667a7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
({ | |
afterRender: function (component, helper) { | |
this.superAfterRender(); | |
var targetEl = component.find("main").getElement(); | |
var preventPullToRefreshCheckbox = true; | |
var preventOverscrollGlowCheckbox = false; | |
var preventScrollCheckbox = false; | |
var maybePreventPullToRefresh = false; | |
var lastTouchY = 0; | |
var touchstartHandler = function (e) { | |
if (e.touches.length !== 1) return; | |
lastTouchY = e.touches[0].clientY; | |
maybePreventPullToRefresh = | |
preventPullToRefreshCheckbox.checked && | |
window.pageYOffset === 0; | |
}; | |
var touchmoveHandler = function (e) { | |
// alert('yeeet') | |
var touchY = e.touches[0].clientY; | |
var touchYDelta = touchY - lastTouchY; | |
lastTouchY = touchY; | |
if (maybePreventPullToRefresh) { | |
maybePreventPullToRefresh = false; | |
if (touchYDelta > 0) { | |
e.preventDefault(); | |
return; | |
} | |
} | |
if (preventScrollCheckbox.checked) { | |
e.preventDefault(); | |
return; | |
} | |
if (preventOverscrollGlowCheckbox.checked) { | |
if (window.pageYOffset === 0 && touchYDelta > 0) { | |
e.preventDefault(); | |
return; | |
} | |
} | |
}; | |
targetEl.addEventListener('touchstart', touchstartHandler, {passive: false}); | |
targetEl.addEventListener('touchmove', touchmoveHandler, {passive: false}); | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment