Preserve Special:Preferences tab state across reload, open in new tab/window.
authorBrion Vibber <brion@users.mediawiki.org>
Sat, 5 Feb 2011 21:54:56 +0000 (21:54 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Sat, 5 Feb 2011 21:54:56 +0000 (21:54 +0000)
* removed the preventDefault()s from handlers on the tab links, so the document hash gets updated (and thus preserved on reload)
* switched from #prefsection-N to #preftab-N on the generated links, so they don't cause the doc to jump down to the top of the tab sections on click now that the preventDefault is gone
* added a check for the hash after tab setup; if we have a #preftab-N then we invoke the tab-switch straight off.

This should keep devs from going insane when doing work on any preferences panel other than the first one

resources/mediawiki.special/mediawiki.special.preferences.js

index 1775bec..a6988bc 100644 (file)
@@ -23,24 +23,29 @@ $( '#preferences' )
                                                        .append(
                                                                $( '<a></a>')
                                                                        .text( $(this).text() )
-                                                                       .attr( 'href', '#prefsection-' + i )
+                                                                       .attr( 'id', 'preftab-' + i + '-tab' )
+                                                                       .attr( 'href', '#preftab-' + i ) // Use #preftab-N instead of #prefsection-N to avoid jumping on click
                                                                        .mousedown( function( e ) {
                                                                                $(this).parent().parent().find( 'li' ).removeClass( 'selected' );
                                                                                $(this).parent().addClass( 'selected' );
-                                                                               e.preventDefault();
-                                                                               return false;
                                                                        } )
                                                                        .click( function( e ) {
                                                                                $( '#preferences > fieldset' ).hide();
                                                                                $( '#prefsection-' + i ).show();
-                                                                               e.preventDefault();
-                                                                               return false;
                                                                        } )
                                                        )
                                        );
                                }
                        );
 
+// If we've reloaded the page or followed an open-in-new-window,
+// make the selected tab visible.
+var hash = window.location.hash;
+if( hash.match( /^#preftab-[\d]+$/ ) ) {
+       var tab = $( hash + '-tab' );
+       tab.mousedown().click();
+}
+
 /**
  * Given an email validity status (true, false, null) update the label CSS class
  */