Merge "(Bug 44192) Do not attempt to send a real e-mail in ApiAccountCreationTest"
[lhc/web/wiklou.git] / resources / mediawiki.special / mediawiki.special.preferences.js
index d8d092b..6eaec6a 100644 (file)
@@ -1,4 +1,4 @@
-/*
+/**
  * JavaScript for Special:Preferences
  */
 jQuery( document ).ready( function ( $ ) {
@@ -8,20 +8,19 @@ jQuery( document ).ready( function ( $ ) {
 
        $( '#prefsubmit' ).attr( 'id', 'prefcontrol' );
 
-               $preftoc = $('<ul id="preftoc"></ul>'),
-               $preferences = $( '#preferences' )
-                       .addClass( 'jsprefs' )
-                       .before( $preftoc ),
-               $fieldsets = $preferences.children( 'fieldset' )
-                       .hide()
-                       .addClass( 'prefsection' ),
-               $legends = $fieldsets
-                       .children( 'legend' )
-                       .addClass( 'mainLegend' );
+       $preftoc = $('<ul id="preftoc"></ul>');
+       $preferences = $( '#preferences' )
+               .addClass( 'jsprefs' )
+               .before( $preftoc );
+       $fieldsets = $preferences.children( 'fieldset' )
+               .hide()
+               .addClass( 'prefsection' );
+       $legends = $fieldsets
+               .children( 'legend' )
+               .addClass( 'mainLegend' );
 
        /**
-        * It uses document.getElementById for security reasons (html injections in
-        * jQuery()).
+        * It uses document.getElementById for security reasons (HTML injections in $()).
         *
         * @param String name: the name of a tab without the prefix ("mw-prefsection-")
         * @param String mode: [optional] A hash will be set according to the current
@@ -181,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 );
+               } );
+       }
 } );