@@ -39,22 +39,25 @@ $(function() {
3939 }
4040
4141 // expand/collapse module
42- function slide_module ( module , action ) {
42+ function slide_module ( module , action , fast ) {
43+ if ( ! module . attr ( 'id' ) )
44+ return ;
4345 var latch = module . find ( '.module-latch' ) ;
4446 var spinner = $ ( latch . children ( '.module-spinner' ) [ 0 ] ) ;
4547 var content = $ ( module . children ( '.module-content' ) [ 0 ] ) ;
48+ var duration = fast ? 0 : 200 ;
4649
4750 function slide_done ( ) {
4851 spinner . html ( content . is ( ':visible' ) ? '▾' : '▸' ) ;
4952 }
5053 if ( action == 'show' ) {
51- content . slideDown ( 200 , 'swing' , slide_done ) ;
54+ content . slideDown ( duration , 'swing' , slide_done ) ;
5255 }
5356 else if ( action == 'hide' ) {
54- content . slideUp ( 200 , 'swing' , slide_done ) ;
57+ content . slideUp ( duration , 'swing' , slide_done ) ;
5558 }
5659 else {
57- content . slideToggle ( 200 , 'swing' , slide_done ) ;
60+ content . slideToggle ( duration , 'swing' , slide_done ) ;
5861 }
5962 }
6063
@@ -289,12 +292,9 @@ $(function() {
289292 $ ( '.edit-hide' ) . hide ( ) ;
290293 $ ( '.edit-show' ) . show ( ) ;
291294
292- // expand specific modules
293- $ ( '#module-details .module-header' ) . each ( function ( ) {
294- if ( $ ( this . parentNode ) . find ( '.module-content:visible' ) . length === 0 ) {
295- $ ( this ) . click ( ) ;
296- }
297- } ) ;
295+ // expand specific modules during the initial edit
296+ if ( ! $ ( '#editing' ) . val ( ) )
297+ slide_module ( $ ( '#module-details' ) , 'show' ) ;
298298
299299 // if there's no current user-story, it's a better experience if it's editable by default
300300 if ( $ ( '#cf_user_story' ) . val ( ) === '' ) {
@@ -384,6 +384,15 @@ $(function() {
384384 return ;
385385 $ ( '.save-btn' ) . attr ( 'disabled' , true ) ;
386386 this . form . submit ( ) ;
387+
388+ // remember expanded modules
389+ $ ( '#editing' ) . val (
390+ $ ( '.module .module-content:visible' )
391+ . parent ( )
392+ . map ( function ( el ) { return $ ( this ) . attr ( 'id' ) ; } )
393+ . toArray ( )
394+ . join ( ' ' )
395+ ) ;
387396 } )
388397 . attr ( 'disabled' , false ) ;
389398
@@ -639,8 +648,11 @@ $(function() {
639648 event . preventDefault ( ) ;
640649 $ ( '#user-story' ) . hide ( ) ;
641650 $ ( '#user-story-edit-btn' ) . hide ( ) ;
642- $ ( '#cf_user_story' ) . show ( ) . focus ( ) . select ( ) ;
643651 $ ( '#top-save-btn' ) . show ( ) ;
652+ $ ( '#cf_user_story' ) . show ( ) ;
653+ // don't focus the user-story field when restoring edit mode after navigation
654+ if ( $ ( '#editing' ) . val ( ) === '' )
655+ $ ( '#cf_user_story' ) . focus ( ) . select ( ) ;
644656 } ) ;
645657 $ ( '#user-story-reply-btn' )
646658 . click ( function ( event ) {
@@ -1006,6 +1018,20 @@ $(function() {
10061018 dirty . val ( that . val ( ) === that . data ( 'preselected' ) [ 0 ] ? '' : '1' ) ;
10071019 }
10081020 } ) ;
1021+
1022+ // finally switch to edit mode if we navigate back to a page that was editing
1023+ if ( $ ( '#editing' ) . val ( ) ) {
1024+ $ ( '.module' )
1025+ . each ( function ( ) {
1026+ slide_module ( $ ( this ) , 'hide' , true ) ;
1027+ } ) ;
1028+ $ ( $ ( '#editing' ) . val ( ) . split ( ' ' ) )
1029+ . each ( function ( ) {
1030+ slide_module ( $ ( '#' + this ) , 'show' , true ) ;
1031+ } ) ;
1032+ $ ( '#mode-btn' ) . click ( ) ;
1033+ $ ( '#editing' ) . val ( '' ) ;
1034+ }
10091035} ) ;
10101036
10111037function confirmUnsafeURL ( url ) {
0 commit comments