mirror of https://github.com/gorhill/uBlock.git
code review: allow free scrolling in element picker mode
This commit is contained in:
parent
6cecd2192e
commit
3044590fa6
|
@ -1290,34 +1290,38 @@ var onSvgTouchStartStop = (function() {
|
||||||
var startX,
|
var startX,
|
||||||
startY;
|
startY;
|
||||||
return function onTouch(ev) {
|
return function onTouch(ev) {
|
||||||
ev.preventDefault();
|
|
||||||
if ( ev.type === 'touchstart' ) {
|
if ( ev.type === 'touchstart' ) {
|
||||||
startX = ev.touches[0].pageX;
|
startX = ev.touches[0].screenX;
|
||||||
startY = ev.touches[0].pageY;
|
startY = ev.touches[0].screenY;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ( startX === undefined ) { return; }
|
if ( startX === undefined ) { return; }
|
||||||
var stopX = ev.changedTouches[0].pageX,
|
if ( ev.cancelable === false ) { return; }
|
||||||
stopY = ev.changedTouches[0].pageY,
|
var stopX = ev.changedTouches[0].screenX,
|
||||||
|
stopY = ev.changedTouches[0].screenY,
|
||||||
angle = Math.abs(Math.atan2(stopY - startY, stopX - startX)),
|
angle = Math.abs(Math.atan2(stopY - startY, stopX - startX)),
|
||||||
distance = Math.sqrt(
|
distance = Math.sqrt(
|
||||||
Math.pow(stopX - startX, 2),
|
Math.pow(stopX - startX, 2),
|
||||||
Math.pow(stopY - startY, 2)
|
Math.pow(stopY - startY, 2)
|
||||||
);
|
);
|
||||||
var angleUpperBound = Math.PI * 0.25 * 0.5,
|
|
||||||
swipeRight = angle < angleUpperBound,
|
|
||||||
swipeInvalid = swipeRight === false &&
|
|
||||||
angle < Math.PI - angleUpperBound;
|
|
||||||
// Interpret touch events as a click events if swipe is not valid.
|
// Interpret touch events as a click events if swipe is not valid.
|
||||||
if ( distance < 64 || swipeInvalid ) {
|
if ( distance < 32 ) {
|
||||||
onSvgClicked({
|
onSvgClicked({
|
||||||
type: 'touch',
|
type: 'touch',
|
||||||
target: ev.target,
|
target: ev.target,
|
||||||
clientX: startX,
|
clientX: ev.changedTouches[0].pageX,
|
||||||
clientY: startY
|
clientY: ev.changedTouches[0].pageY
|
||||||
});
|
});
|
||||||
|
ev.preventDefault();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if ( distance < 64 ) { return; }
|
||||||
|
var angleUpperBound = Math.PI * 0.25 * 0.5,
|
||||||
|
swipeRight = angle < angleUpperBound;
|
||||||
|
if ( swipeRight === false && angle < Math.PI - angleUpperBound ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ev.preventDefault();
|
||||||
// Swipe left.
|
// Swipe left.
|
||||||
if ( swipeRight === false ) {
|
if ( swipeRight === false ) {
|
||||||
if ( pickerBody.classList.contains('paused') ) {
|
if ( pickerBody.classList.contains('paused') ) {
|
||||||
|
|
Loading…
Reference in New Issue