@@ -930,6 +930,10 @@ async function clickedOnFileHTML(fileEl, event) {
930930
931931 if ( isMobile ) { // if on mobile device
932932
933+ // close sidebar
934+ toggleSidebar ( false ) ;
935+ saveSidebarStateLS ( ) ;
936+
933937 // update bottom float
934938 updateFloat ( ) ;
935939
@@ -1349,7 +1353,7 @@ async function loadFileInHTML(fileEl, fileSha) {
13491353
13501354 // if previous file selection exists in HTML
13511355 if ( prevSelFileEl ) {
1352-
1356+
13531357 // load previous selected file
13541358 loadFileInHTML ( prevSelFileEl , selectedFile . sha ) ;
13551359
@@ -1430,6 +1434,10 @@ async function loadFileInHTML(fileEl, fileSha) {
14301434 onNextFrame ( ( ) => {
14311435
14321436 liveView . classList . remove ( 'notransition' ) ;
1437+
1438+ // close sidebar
1439+ toggleSidebar ( false ) ;
1440+ saveSidebarStateLS ( ) ;
14331441
14341442 // update bottom float
14351443 bottomFloat . classList . add ( 'file-open' ) ;
@@ -1482,8 +1490,16 @@ async function loadFileInHTML(fileEl, fileSha) {
14821490 // change codeit lang
14831491 cd . lang = selectedFile . lang ;
14841492
1485- // update bottom float
1486- if ( isMobile ) updateFloat ( ) ;
1493+ if ( isMobile ) {
1494+
1495+ // close sidebar
1496+ toggleSidebar ( false ) ;
1497+ saveSidebarStateLS ( ) ;
1498+
1499+ // update bottom float
1500+ updateFloat ( ) ;
1501+
1502+ }
14871503
14881504 } catch ( e ) { // if file is binary
14891505
@@ -1572,6 +1588,11 @@ function loadBinaryFileHTML(file, toggled) {
15721588
15731589 liveView . classList . remove ( 'notransition' ) ;
15741590
1591+ // close sidebar
1592+ toggleSidebar ( false ) ;
1593+ saveSidebarStateLS ( ) ;
1594+
1595+ // update bottom float
15751596 updateFloat ( ) ;
15761597
15771598 } )
@@ -2625,6 +2646,10 @@ function createNewFileInHTML() {
26252646 // then open new file
26262647 window . setTimeout ( ( ) => {
26272648
2649+ // close sidebar
2650+ toggleSidebar ( false ) ;
2651+ saveSidebarStateLS ( ) ;
2652+
26282653 // update bottom float
26292654 updateFloat ( ) ;
26302655
@@ -2993,10 +3018,20 @@ async function deleteModFileInHTML(fileEl) {
29933018 fileEl . classList . remove ( 'modified' ) ;
29943019
29953020 if ( fileEl . classList . contains ( 'selected' ) ) {
3021+
3022+ const sidebarOpen = body . classList . contains ( 'expanded' ) ;
29963023
29973024 const scrollPos = selectedFile . scrollPos ;
29983025
29993026 await loadFileInHTML ( fileEl , fileSha ) ;
3027+
3028+ if ( ! sidebarOpen ) {
3029+
3030+ // close sidebar
3031+ toggleSidebar ( false ) ;
3032+ saveSidebarStateLS ( ) ;
3033+
3034+ }
30003035
30013036 // prevent bottom float disappearing on mobile
30023037 if ( isMobile ) lastScrollTop = scrollPos [ 1 ] ;
@@ -3127,11 +3162,21 @@ async function protectUnsavedCode() {
31273162 // if new version of selected file exists
31283163 if ( selectedElName !== null ) {
31293164
3165+ const sidebarOpen = body . classList . contains ( 'expanded' ) ;
3166+
31303167 const scrollPos = selectedFile . scrollPos ;
31313168
31323169 // load file
31333170 await loadFileInHTML ( selectedElName , getAttr ( selectedElName , 'sha' ) ) ;
31343171
3172+ if ( ! sidebarOpen ) {
3173+
3174+ // close sidebar
3175+ toggleSidebar ( false ) ;
3176+ saveSidebarStateLS ( ) ;
3177+
3178+ }
3179+
31353180 // prevent bottom float disappearing on mobile
31363181 if ( isMobile ) lastScrollTop = scrollPos [ 1 ] ;
31373182
@@ -3145,9 +3190,19 @@ async function protectUnsavedCode() {
31453190 // if selected file isn't loaded
31463191 if ( selectedFile . sha !== getAttr ( selectedElSha , 'sha' ) ) {
31473192
3193+ const sidebarOpen = body . classList . contains ( 'expanded' ) ;
3194+
31483195 // load file
31493196 loadFileInHTML ( selectedElSha , getAttr ( selectedElSha , 'sha' ) ) ;
31503197
3198+ if ( ! sidebarOpen ) {
3199+
3200+ // close sidebar
3201+ toggleSidebar ( false ) ;
3202+ saveSidebarStateLS ( ) ;
3203+
3204+ }
3205+
31513206 }
31523207
31533208 }
@@ -3488,13 +3543,14 @@ function setupSidebar() {
34883543 // render sidebar
34893544 renderSidebarHTML ( ) ;
34903545
3491- // if sidebar is open
3546+ // if sidebar is open in local storage
34923547 if ( getStorage ( 'sidebar' ) == 'true'
34933548 && ! isEmbed ) {
34943549
34953550 // don't transition
34963551 body . classList . add ( 'notransition' ) ;
34973552
3553+ // open sidebar
34983554 toggleSidebar ( true ) ;
34993555
35003556 onNextFrame ( ( ) => {
@@ -3505,6 +3561,9 @@ function setupSidebar() {
35053561
35063562 } else if ( isMobile ) {
35073563
3564+ // close sidebar
3565+ toggleSidebar ( false ) ;
3566+
35083567 // update bottom float
35093568 updateFloat ( ) ;
35103569
0 commit comments