From c32a6f4c5051b16b248c94279dc87578f6d35f28 Mon Sep 17 00:00:00 2001 From: Jeff Date: Tue, 11 Jul 2017 12:00:02 +0800 Subject: [PATCH 1/2] Little trick enabling sidebar closing through swiping Detecting touch trace to trigger sidebar toggle --- source/js/src/motion.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/source/js/src/motion.js b/source/js/src/motion.js index bf6e473e9..39676ed93 100644 --- a/source/js/src/motion.js +++ b/source/js/src/motion.js @@ -79,6 +79,7 @@ $(document).ready(function () { var SIDEBAR_WIDTH = '320px'; var SIDEBAR_DISPLAY_DURATION = 200; + var xPos, yPos; var sidebarToggleMotion = { toggleEl: $('.sidebar-toggle'), @@ -90,6 +91,9 @@ $(document).ready(function () { this.dimmerEl.on('click', this.clickHandler.bind(this)); this.toggleEl.on('mouseenter', this.mouseEnterHandler.bind(this)); this.toggleEl.on('mouseleave', this.mouseLeaveHandler.bind(this)); + this.sidebarEl.on('touchstart', this.touchstartHandler.bind(this)); + this.sidebarEl.on('touchend', this.touchendHandler.bind(this)); + this.sidebarEl.on('touchmove', function(e){e.preventDefault();}); $(document) .on('sidebar.isShowing', function () { @@ -117,6 +121,17 @@ $(document).ready(function () { } sidebarToggleLines.init(); }, + touchstartHandler: function(e) { + xPos = e.originalEvent.touches[0].clientX; + yPos = e.originalEvent.touches[0].clientY; + }, + touchendHandler: function(e) { + var _xPos = e.originalEvent.changedTouches[0].clientX; + var _yPos = e.originalEvent.changedTouches[0].clientY; + if (_xPos-xPos > 30 && _yPos-yPos < 20) { + this.hideSidebar(); + } + }, showSidebar: function () { var self = this; From 1abb54642c5ecd3251287bcb84651ab8a461a71a Mon Sep 17 00:00:00 2001 From: Jeff Date: Tue, 11 Jul 2017 12:38:39 +0800 Subject: [PATCH 2/2] bug fix make it more reasonable --- source/js/src/motion.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/js/src/motion.js b/source/js/src/motion.js index 39676ed93..a73df2bee 100644 --- a/source/js/src/motion.js +++ b/source/js/src/motion.js @@ -128,8 +128,8 @@ $(document).ready(function () { touchendHandler: function(e) { var _xPos = e.originalEvent.changedTouches[0].clientX; var _yPos = e.originalEvent.changedTouches[0].clientY; - if (_xPos-xPos > 30 && _yPos-yPos < 20) { - this.hideSidebar(); + if (_xPos-xPos > 30 && Math.abs(_yPos-yPos) < 20) { + this.clickHandler(); } }, showSidebar: function () {