Skip to content
This repository has been archived by the owner on Mar 26, 2023. It is now read-only.

Commit

Permalink
touch passive listeners
Browse files Browse the repository at this point in the history
  • Loading branch information
rnosov committed Feb 17, 2018
1 parent 8b3f932 commit d3165bf
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/lib/swipedetect.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
// credit: http://www.javascriptkit.com/javatutors/touchevents2.shtml
var supportsPassive = false;
try {
var opts = Object.defineProperty({}, 'passive', {
get: function() {
supportsPassive = true;
}
});
window.addEventListener("testPassive", null, opts);
window.removeEventListener("testPassive", null, opts);
} catch (e) {}
export default function swipedetect(el, callback){

var touchsurface = el,
Expand All @@ -14,6 +24,11 @@ export default function swipedetect(el, callback){
startTime,
handleswipe = callback || function(swipedir){}



// Use our detect's results. passive applied if supported, capture will be false either way.
//elem.addEventListener('touchstart', fn, supportsPassive ? { passive: true } : false);

touchsurface.addEventListener('touchstart', function(e){
var touchobj = e.changedTouches[0];
swipedir = 'none';
Expand All @@ -22,7 +37,7 @@ export default function swipedetect(el, callback){
startY = touchobj.pageY;
startTime = new Date().getTime(); // record time when finger first makes contact with surface
//e.preventDefault();
}, false)
}, supportsPassive ? { passive: true } : false)

//touchsurface.addEventListener('touchmove', function(e){
// e.preventDefault() // prevent scrolling when inside DIV
Expand All @@ -43,5 +58,5 @@ export default function swipedetect(el, callback){
}
handleswipe(swipedir)
//e.preventDefault()
}, false)
}, supportsPassive ? { passive: true } : false)
}

0 comments on commit d3165bf

Please sign in to comment.