11/*******************************************************************************
22
33 uBlock Origin - a browser extension to block requests.
4- Copyright (C) 2014-2016 Raymond Hill
4+ Copyright (C) 2014-2017 Raymond Hill
55
66 This program is free software: you can redistribute it and/or modify
77 it under the terms of the GNU General Public License as published by
@@ -1092,7 +1092,14 @@ var filterChoiceFromEvent = function(ev) {
10921092/******************************************************************************/
10931093
10941094var onDialogClicked = function ( ev ) {
1095- if ( ev . target === null ) {
1095+
1096+ // If the dialog is hidden, clicking on it force it to become visible.
1097+ if ( dialog . classList . contains ( 'hide' ) ) {
1098+ dialog . classList . add ( 'show' ) ;
1099+ dialog . classList . remove ( 'hide' ) ;
1100+ }
1101+
1102+ else if ( ev . target === null ) {
10961103 /* do nothing */
10971104 }
10981105
@@ -1161,6 +1168,11 @@ var showDialog = function(options) {
11611168
11621169 options = options || { } ;
11631170
1171+ // Typically the dialog will be forced to be visible when using a
1172+ // touch-aware device.
1173+ dialog . classList . toggle ( 'show' , options . show === true ) ;
1174+ dialog . classList . remove ( 'hide' ) ;
1175+
11641176 // Create lists of candidate filters
11651177 var populate = function ( src , des ) {
11661178 var root = dialog . querySelector ( des ) ;
@@ -1262,7 +1274,17 @@ var onSvgHovered = (function() {
12621274 } ;
12631275} ) ( ) ;
12641276
1265- /******************************************************************************/
1277+ /*******************************************************************************
1278+
1279+ Swipe right:
1280+ If picker not paused: quit picker
1281+ If picker paused and dialog visible: hide dialog
1282+ If picker paused and dialog not visible: quit picker
1283+
1284+ Swipe left:
1285+ If picker paused and dialog not visible: show dialog
1286+
1287+ */
12661288
12671289var onSvgTouchStartStop = ( function ( ) {
12681290 var startX ,
@@ -1277,22 +1299,43 @@ var onSvgTouchStartStop = (function() {
12771299 if ( startX === undefined ) { return ; }
12781300 var stopX = ev . changedTouches [ 0 ] . pageX ,
12791301 stopY = ev . changedTouches [ 0 ] . pageY ,
1302+ angle = Math . abs ( Math . atan2 ( stopY - startY , stopX - startX ) ) ,
12801303 distance = Math . sqrt (
12811304 Math . pow ( stopX - startX , 2 ) ,
12821305 Math . pow ( stopY - startY , 2 )
12831306 ) ;
1284- // Swipe = exit element zapper/picker.
1285- if ( distance > 32 ) {
1286- stopPicker ( ) ;
1307+ var angleUpperBound = Math . PI * 0.25 * 0.5 ,
1308+ swipeRight = angle < angleUpperBound ,
1309+ swipeInvalid = swipeRight === false &&
1310+ angle < Math . PI - angleUpperBound ;
1311+ // Interpret touch events as a click events if swipe is not valid.
1312+ if ( distance < 64 || swipeInvalid ) {
1313+ onSvgClicked ( {
1314+ type : 'touch' ,
1315+ target : ev . target ,
1316+ clientX : startX ,
1317+ clientY : startY
1318+ } ) ;
12871319 return ;
12881320 }
1289- // Interpret touch event as a click.
1290- onSvgClicked ( {
1291- type : 'click' ,
1292- target : ev . target ,
1293- clientX : startX ,
1294- clientY : startY
1295- } ) ;
1321+ // Swipe left.
1322+ if ( swipeRight === false ) {
1323+ if ( pickerBody . classList . contains ( 'paused' ) ) {
1324+ dialog . classList . remove ( 'hide' ) ;
1325+ dialog . classList . add ( 'show' ) ;
1326+ }
1327+ return ;
1328+ }
1329+ // Swipe right.
1330+ if (
1331+ pickerBody . classList . contains ( 'paused' ) &&
1332+ dialog . classList . contains ( 'show' )
1333+ ) {
1334+ dialog . classList . remove ( 'show' ) ;
1335+ dialog . classList . add ( 'hide' ) ;
1336+ return ;
1337+ }
1338+ stopPicker ( ) ;
12961339 } ;
12971340} ) ( ) ;
12981341
@@ -1329,7 +1372,7 @@ var onSvgClicked = function(ev) {
13291372 if ( filtersFrom ( ev . clientX , ev . clientY ) === 0 ) {
13301373 return ;
13311374 }
1332- showDialog ( ) ;
1375+ showDialog ( { show : ev . type === 'touch' } ) ;
13331376} ;
13341377
13351378/******************************************************************************/
0 commit comments