@@ -74,6 +74,33 @@ $( document ).ready(function() {
74
74
sidebar . scrollTop ( activeSection . offset ( ) . top ) ;
75
75
}
76
76
77
+ var firstContact = null ;
78
+
79
+ $ ( this ) . on ( 'touchstart' , function ( e ) {
80
+ firstContact = {
81
+ x : e . originalEvent . touches [ 0 ] . clientX ,
82
+ time : Date . now ( )
83
+ } ;
84
+ } ) ;
85
+
86
+ $ ( this ) . on ( 'touchmove' , function ( e ) {
87
+ if ( ! firstContact )
88
+ return ;
89
+
90
+ var curX = e . originalEvent . touches [ 0 ] . clientX ;
91
+ var xDiff = curX - firstContact . x ,
92
+ tDiff = Date . now ( ) - firstContact . time ;
93
+
94
+ if ( tDiff < 250 && Math . abs ( xDiff ) >= 150 ) {
95
+ if ( xDiff >= 0 && firstContact . x < Math . min ( document . body . clientWidth * 0.25 , 300 ) )
96
+ showSidebar ( ) ;
97
+ else if ( xDiff < 0 && curX < 300 )
98
+ hideSidebar ( ) ;
99
+
100
+ firstContact = null ;
101
+ }
102
+ } ) ;
103
+
77
104
78
105
// Theme button
79
106
$ ( "#theme-toggle" ) . click ( function ( ) {
@@ -343,23 +370,29 @@ function showTooltip(elem, msg) {
343
370
344
371
function sidebarToggle ( ) {
345
372
var html = $ ( "html" ) ;
346
- if ( html . hasClass ( "sidebar-hidden" ) ) {
347
- html . removeClass ( "sidebar-hidden" ) . addClass ( "sidebar-visible" ) ;
348
- store . set ( 'mdbook-sidebar' , 'visible' ) ;
349
- } else if ( html . hasClass ( "sidebar-visible" ) ) {
350
- html . removeClass ( "sidebar-visible" ) . addClass ( "sidebar-hidden" ) ;
351
- store . set ( 'mdbook-sidebar' , 'hidden' ) ;
373
+ if ( html . hasClass ( "sidebar-hidden" ) ) {
374
+ showSidebar ( ) ;
375
+ } else if ( html . hasClass ( "sidebar-visible" ) ) {
376
+ hideSidebar ( ) ;
352
377
} else {
353
- if ( $ ( "#sidebar" ) . position ( ) . left === 0 ) {
354
- html . addClass ( "sidebar-hidden" ) ;
355
- store . set ( 'mdbook-sidebar' , 'hidden' ) ;
378
+ if ( $ ( "#sidebar" ) . position ( ) . left === 0 ) {
379
+ hideSidebar ( ) ;
356
380
} else {
357
- html . addClass ( "sidebar-visible" ) ;
358
- store . set ( 'mdbook-sidebar' , 'visible' ) ;
381
+ showSidebar ( ) ;
359
382
}
360
383
}
361
384
}
362
385
386
+ function showSidebar ( ) {
387
+ $ ( 'html' ) . removeClass ( 'sidebar-hidden' ) . addClass ( 'sidebar-visible' ) ;
388
+ store . set ( 'mdbook-sidebar' , 'visible' ) ;
389
+ }
390
+
391
+ function hideSidebar ( ) {
392
+ $ ( 'html' ) . removeClass ( 'sidebar-visible' ) . addClass ( 'sidebar-hidden' ) ;
393
+ store . set ( 'mdbook-sidebar' , 'hidden' ) ;
394
+ }
395
+
363
396
function run_rust_code ( code_block ) {
364
397
var result_block = code_block . find ( ".result" ) ;
365
398
if ( result_block . length === 0 ) {
0 commit comments