diff options
author | Thibaud Lepretre <thibaud.lepretre@gmail.com> | 2021-08-10 15:49:57 +0300 |
---|---|---|
committer | Thibaud Lepretre <thibaud.lepretre@gmail.com> | 2021-08-11 15:04:00 +0300 |
commit | de2f94b4b48c9e32bc0f684014d6c95444c0f291 (patch) | |
tree | bb93d3f1e7bf00ca34f2fc1b72aeffc2504cd516 /src | |
parent | 0791201693fd0c12a1a9027609d8b7e449fadb30 (diff) |
Add support for touch swipe left to close sidebar
Diffstat (limited to 'src')
-rwxr-xr-x | src/js/sidebar.js | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/js/sidebar.js b/src/js/sidebar.js index 1661f88..5d7f13c 100755 --- a/src/js/sidebar.js +++ b/src/js/sidebar.js @@ -48,6 +48,37 @@ self.closeSidebar(); } }); + + var xDown = null; + var yDown = null; + + $(document).on('touchstart', function(e) { + if (self.$sidebar.hasClass('pushed')) { + var firstTouch = (e.touches || e.originalEvent.touches)[0]; + xDown = firstTouch.clientX; + yDown = firstTouch.clientY; + } + }).on('touchmove', function(e) { + if ((!xDown || !yDown) || !self.$sidebar.hasClass('pushed')) { + return; + } + + var xUp = e.touches[0].clientX; + var yUp = e.touches[0].clientY; + + var xDiff = xDown - xUp; + var yDiff = yDown - yUp; + + if (Math.abs(xDiff) > Math.abs(yDiff)) { + if (xDiff > 0) { + self.closeSidebar(); + } + } + + xDown = null; + yDown = null; + }); + // Detect resize of the windows $(window).resize(function() { // Check if the window is larger than the minimal medium screen value |