Fix preference tab switching so it doesn't fight prevTab v url hash
authorMoriel Schottlender <moriel@gmail.com>
Fri, 21 Apr 2017 00:19:47 +0000 (17:19 -0700)
committerMoriel Schottlender <moriel@gmail.com>
Fri, 21 Apr 2017 00:19:47 +0000 (17:19 -0700)
There was a bug where, when loading the Preferences page, the tab
was initially set by the URL hash (correct behavior) but then later
the system asked for the 'previous tab' in session storage, and changed
it to that -- which overrode the URL hash placement. In most cases,
the previous tab and url hash seemed to have been correct because
the user would go to the Preferences section and expect whatever
was the most recent tab they saw to open - but in the case of
specifically hitting "Beta" link (or clicking a direct link with
a specific hash to one of the preferences tabs) the previous tab
and hash had a fight, where the url-hash was the loser.

This commit fixes that by deleting the 'previousTab' from session
when the hash is set. Also, as a bonus, made sure that when the
previousTab removes itself from session, it actually removes the
correct key (and not tries to remove the value, which it did up
until now, and would've resulted in the previousTab value never
actually being removed)

Bug: T162938
Change-Id: I95c809f41dec7d7120c73dffa4a107346d049f70

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

index 0fa6610..84a9a96 100644 (file)
                        var hash = location.hash,
                                matchedElement, parentSection;
                        if ( hash.match( /^#mw-prefsection-[\w\-]+/ ) ) {
+                               mw.storage.session.remove( 'mwpreferences-prevTab' );
                                switchPrefTab( hash.replace( '#mw-prefsection-', '' ) );
                        } else if ( hash.match( /^#mw-[\w\-]+/ ) ) {
                                matchedElement = document.getElementById( hash.slice( 1 ) );
                                parentSection = $( matchedElement ).closest( '.prefsection' );
                                if ( parentSection.length ) {
+                                       mw.storage.session.remove( 'mwpreferences-prevTab' );
                                        // Switch to proper tab and scroll to selected item.
                                        switchPrefTab( parentSection.attr( 'id' ).replace( 'mw-prefsection-', '' ), 'noHash' );
                                        matchedElement.scrollIntoView();
                if ( previousTab ) {
                        switchPrefTab( previousTab, 'noHash' );
                        // Deleting the key, the tab states should be reset until we press Save
-                       mw.storage.session.remove( previousTab );
+                       mw.storage.session.remove( 'mwpreferences-prevTab' );
                }
 
                $( '#mw-prefs-form' ).on( 'submit', function () {