File tree Expand file tree Collapse file tree 1 file changed +22
-1
lines changed Expand file tree Collapse file tree 1 file changed +22
-1
lines changed Original file line number Diff line number Diff line change 91
91
}
92
92
93
93
/**
94
- * Mobile burger menu button for toggling sidebar
94
+ * Mobile burger menu button and gesture for toggling sidebar
95
95
*/
96
96
97
97
function initMobileMenu ( ) {
108
108
sidebar . classList . remove ( 'open' )
109
109
}
110
110
} )
111
+
112
+ // Toggle sidebar on swipe
113
+ var start = { } , end = { }
114
+
115
+ document . body . addEventListener ( 'touchstart' , function ( e ) {
116
+ start . x = e . changedTouches [ 0 ] . clientX
117
+ start . y = e . changedTouches [ 0 ] . clientY
118
+ } )
119
+
120
+ document . body . addEventListener ( 'touchend' , function ( e ) {
121
+ end . y = e . changedTouches [ 0 ] . clientY
122
+ end . x = e . changedTouches [ 0 ] . clientX
123
+
124
+ var xDiff = end . x - start . x
125
+ var yDiff = end . y - start . y
126
+
127
+ if ( Math . abs ( xDiff ) > Math . abs ( yDiff ) ) {
128
+ if ( xDiff > 0 ) sidebar . classList . add ( 'open' )
129
+ else sidebar . classList . remove ( 'open' )
130
+ }
131
+ } )
111
132
}
112
133
113
134
/**
You can’t perform that action at this time.
0 commit comments