From 62e35069b8ef60a60ab5a8d1443108163a7bd958 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Sat, 5 Feb 2011 21:54:56 +0000 Subject: [PATCH] Preserve Special:Preferences tab state across reload, open in new tab/window. * 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 --- .../mediawiki.special.preferences.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/resources/mediawiki.special/mediawiki.special.preferences.js b/resources/mediawiki.special/mediawiki.special.preferences.js index 1775bec450..a6988bcd28 100644 --- a/resources/mediawiki.special/mediawiki.special.preferences.js +++ b/resources/mediawiki.special/mediawiki.special.preferences.js @@ -23,24 +23,29 @@ $( '#preferences' ) .append( $( '') .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 */ -- 2.20.1