@@ -264,34 +264,39 @@ if (downloadNote.length >= 1) {
264264
265265//This code handles the Expand/Hide toggle for the Docs/Tutorials left nav items
266266
267- $ ( "#pytorch-left-menu p.caption" ) . each ( function ( ) {
268- var collapsedSections = [ 'Notes' ] ;
269- var menuName = this . innerText . replace ( / [ ^ \w \s ] / gi, '' ) . trim ( ) ;
270- if ( collapsedSections . includes ( menuName ) == true && $ ( this ) . children ( ) . not ( ".expand-menu" ) ) {
271- $ ( this ) . children ( "span" ) . after ( "<span class='expand-menu'>[ + ]</span>" ) ;
272- $ ( this ) . children ( "span" ) . after ( "<span class='hide-menu collapse'>[ - ]</span>" ) ;
273- $ ( this ) . next ( "ul" ) . hide ( ) ;
274- } else {
275- $ ( this ) . children ( "span" ) . after ( "<span class='hide-menu'>[ - ]</span>" ) ;
276- $ ( this ) . children ( "span" ) . after ( "<span class='expand-menu collapse'>[ + ]</span>" ) ;
277- }
278- } )
267+ $ ( document ) . ready ( function ( ) {
268+ var caption = "#pytorch-left-menu p.caption" ;
269+ var collapseAdded = $ ( this ) . not ( 'checked' ) ;
270+
271+ $ ( caption ) . each ( function ( ) {
272+ var menuName = this . innerText . replace ( / [ ^ \w \s ] / gi, '' ) . trim ( ) ;
273+ $ ( this ) . find ( "span" ) . addClass ( 'checked' ) ;
274+ if ( collapsedSections . includes ( menuName ) == true && collapseAdded ) {
275+ $ ( this . firstChild ) . after ( "<span class='expand-menu'>[ + ]</span>" ) ;
276+ $ ( this . firstChild ) . after ( "<span class='hide-menu collapse'>[ - ]</span>" ) ;
277+ $ ( this ) . next ( "ul" ) . hide ( ) ;
278+ } else if ( collapsedSections . includes ( menuName ) == false && collapseAdded ) {
279+ $ ( this . firstChild ) . after ( "<span class='expand-menu collapse'>[ + ]</span>" ) ;
280+ $ ( this . firstChild ) . after ( "<span class='hide-menu'>[ - ]</span>" ) ;
281+ }
282+ } )
279283
280- $ ( ".expand-menu" ) . on ( "click" , function ( ) {
281- $ ( this ) . next ( ".hide-menu" ) . toggle ( ) ;
282- $ ( this ) . parent ( ) . next ( "ul" ) . toggle ( ) ;
283- toggleList ( this ) ;
284- } ) ;
284+ $ ( ".expand-menu" ) . on ( "click" , function ( ) {
285+ $ ( this ) . prev ( ".hide-menu" ) . toggle ( ) ;
286+ $ ( this ) . parent ( ) . next ( "ul" ) . toggle ( ) ;
287+ toggleList ( this ) ;
288+ } ) ;
285289
286- $ ( ".hide-menu" ) . on ( "click" , function ( ) {
287- $ ( this ) . prev ( ".expand-menu" ) . toggle ( ) ;
288- $ ( this ) . parent ( ) . next ( "ul" ) . toggle ( ) ;
289- toggleList ( this ) ;
290- } ) ;
290+ $ ( ".hide-menu" ) . on ( "click" , function ( ) {
291+ $ ( this ) . next ( ".expand-menu" ) . toggle ( ) ;
292+ $ ( this ) . parent ( ) . next ( "ul" ) . toggle ( ) ;
293+ toggleList ( this ) ;
294+ } ) ;
291295
292- function toggleList ( menuCommand ) {
293- $ ( menuCommand ) . toggle ( ) ;
294- }
296+ function toggleList ( menuCommand ) {
297+ $ ( menuCommand ) . toggle ( ) ;
298+ }
299+ } ) ;
295300
296301// Get the card link from the card's link attribute
297302
0 commit comments