-/*
+/**
* JavaScript for Special:Preferences
*/
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
// <a href="#.."> will naturally set the hash, handled by onhashchange.
// But other things that change the hash will also be catched (e.g. using
// the Back and Forward browser navigation).
- if ( 'onhashchange' in window ) {
+ // Note the special check for IE "compatibility" mode.
+ if ( 'onhashchange' in window &&
+ ( document.documentMode === undefined || document.documentMode >= 8 )
+ ) {
$(window).on( 'hashchange' , function () {
var hash = window.location.hash;
if ( hash.match( /^#mw-prefsection-[\w\-]+/ ) ) {
$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 );
+ } );
+ }
} );