@@ -10,43 +10,62 @@ document.addEventListener('DOMContentLoaded', () => {
1010 window . dispatchEvent ( new Event ( 'resize' ) ) ;
1111 }
1212
13+ // Mouse and touch events
1314 sidebarResizer . addEventListener ( 'mousedown' , initResize ) ;
15+ sidebarResizer . addEventListener ( 'touchstart' , initResize , { passive : false } ) ;
1416 document . addEventListener ( 'mousemove' , resize ) ;
17+ document . addEventListener ( 'touchmove' , resize , { passive : false } ) ;
1518 document . addEventListener ( 'mouseup' , stopResize ) ;
19+ document . addEventListener ( 'touchend' , stopResize ) ;
1620
1721 sidebarResizer . addEventListener ( 'click' , e => {
1822 if ( didMove ) {
1923 e . stopPropagation ( ) ;
2024 e . preventDefault ( ) ;
2125 return ;
2226 }
23- vehicleContainer . style . width = '0px' ;
24- localStorage . setItem ( 'vehicle-container-width' , '0px' ) ;
27+ let newWidth = '0px' ;
28+ if ( parseInt ( vehicleContainer . style . width ) < 10 || ! vehicleContainer . style . width ) {
29+ newWidth = '200px' ;
30+ }
31+ vehicleContainer . style . width = newWidth ;
32+ localStorage . setItem ( 'vehicle-container-width' , newWidth ) ;
2533 window . dispatchEvent ( new Event ( 'resize' ) ) ;
2634 } ) ;
2735
36+ function getClientX ( e ) {
37+ return e . touches ? e . touches [ 0 ] . clientX : e . clientX ;
38+ }
39+
2840 function initResize ( e ) {
41+ if ( e . touches && e . touches . length !== 1 ) return ;
2942 isResizing = true ;
3043 didMove = false ;
31- dragStartX = e . clientX ;
44+ dragStartX = getClientX ( e ) ;
3245 document . body . style . cursor = 'col-resize' ;
3346 e . preventDefault ( ) ;
3447 }
3548
3649 function resize ( e ) {
3750 if ( ! isResizing ) return ;
51+ if ( e . touches && e . touches . length !== 1 ) return ;
3852
39- if ( Math . abs ( e . clientX - dragStartX ) > 3 ) {
53+ const clientX = getClientX ( e ) ;
54+ if ( Math . abs ( clientX - dragStartX ) > 3 ) {
4055 didMove = true ;
4156 }
4257
4358 const containerRect = sidebarResizer . parentElement . getBoundingClientRect ( ) ;
44- const newWidth = e . clientX - containerRect . left - sidebarResizer . getBoundingClientRect ( ) . width / 2 ;
59+ let newWidth = clientX - containerRect . left - sidebarResizer . getBoundingClientRect ( ) . width / 2 ;
60+ newWidth = Math . max ( 0 , newWidth )
61+
4562
4663 vehicleContainer . style . width = `${ newWidth } px` ;
4764 simContainer . style . flexGrow = 1 ;
4865 window . dispatchEvent ( new Event ( 'resize' ) ) ;
4966 localStorage . setItem ( 'vehicle-container-width' , newWidth ) ;
67+
68+ e . preventDefault ( ) ;
5069 }
5170
5271 function stopResize ( ) {
0 commit comments