@@ -93,6 +93,9 @@ function updateRevisionMarkers(env_id) {
9393 } ) ;
9494 $ ( "#revision" ) . html ( options ) ;
9595 $ ( "#revision" ) . val ( current ) ;
96+ if ( ! $ ( "#revision" ) . val ( ) ) {
97+ $ ( "#revision" ) . prop ( 'selectedIndex' , 0 ) ;
98+ }
9699}
97100
98101function refreshContent ( ) {
@@ -123,8 +126,19 @@ function changeRevisions() {
123126 selected_project = projectmatrix [ executable ] ;
124127
125128 if ( selected_project !== currentproject ) {
129+ var oldRevs = revisiondata [ currentproject ] || [ ] ;
130+ var oldEntry = oldRevs . find ( function ( r ) { return r [ 1 ] === $ ( "#revision" ) . val ( ) ; } ) ;
131+ var oldDate = oldEntry ? new Date ( oldEntry [ 0 ] . slice ( 0 , 19 ) ) : null ;
126132 currentproject = selected_project ;
127133 updateRevisionMarkers ( $ ( "input[name='environment']:checked" ) . val ( ) ) ;
134+ if ( oldDate ) {
135+ var newRevs = revisiondata [ currentproject ] || [ ] ;
136+ var best = newRevs . reduce ( function ( bi , r , i ) {
137+ return Math . abs ( new Date ( r [ 0 ] . slice ( 0 , 19 ) ) - oldDate ) <
138+ Math . abs ( new Date ( newRevs [ bi ] [ 0 ] . slice ( 0 , 19 ) ) - oldDate ) ? i : bi ;
139+ } , 0 ) ;
140+ $ ( "#revision" ) . prop ( 'selectedIndex' , best ) ;
141+ }
128142
129143 //Give visual cue that the select box has changed
130144 var bgc = $ ( "#revision" ) . parent ( ) . parent ( ) . css ( "backgroundColor" ) ;
0 commit comments