(Bug 27559) Preserve tab selection after submit in [[Special:Preferences]]
authorPavel Selitskas <p.selitskas@gmail.com>
Sat, 12 Jan 2013 01:20:04 +0000 (04:20 +0300)
committerPavel Selitskas <p.selitskas@gmail.com>
Wed, 16 Jan 2013 22:53:20 +0000 (01:53 +0300)
Firstly it was planned to be implemented via cookies, but they behave terribly.
So, for now it's a HTML5-only solution (via sessionStorage).

Change-Id: I7b7f14a6dca580a4498bda1ada48d1a3ba7c69c3

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

index 46384a8..6eaec6a 100644 (file)
@@ -180,4 +180,20 @@ jQuery( document ).ready( function ( $ ) {
                $tzTextbox.blur( updateTimezoneSelection );
                updateTimezoneSelection();
        }
+
+       // Preserve the tab after saving the preferences
+       // Not using cookies, because their deletion results are inconsistent.
+       // Not using jStorage due to its enormous size (for this feature)
+       if ( window.sessionStorage ) {
+               if ( sessionStorage.getItem( 'mediawikiPreferencesTab' ) !== null ) {
+                       switchPrefTab( sessionStorage.getItem( 'mediawikiPreferencesTab' ), 'noHash' );
+               }
+               // Deleting the key, the tab states should be reset until we press Save
+               sessionStorage.removeItem( 'mediawikiPreferencesTab' );
+
+               $( '#mw-prefs-form' ).submit( function () {
+                       var storageData = $( $preftoc ).find( 'li.selected a' ).attr( 'id' ).replace( 'preftab-', '' );
+                       sessionStorage.setItem( 'mediawikiPreferencesTab', storageData );
+               } );
+       }
 } );