From 273076e69776c7cdd0aaab08cec559bd79601a14 Mon Sep 17 00:00:00 2001 From: Moriel Schottlender Date: Thu, 20 Apr 2017 17:19:47 -0700 Subject: [PATCH] Fix preference tab switching so it doesn't fight prevTab v url hash 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 --- .../src/mediawiki.special/mediawiki.special.preferences.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/resources/src/mediawiki.special/mediawiki.special.preferences.js b/resources/src/mediawiki.special/mediawiki.special.preferences.js index 0fa661041c..84a9a96509 100644 --- a/resources/src/mediawiki.special/mediawiki.special.preferences.js +++ b/resources/src/mediawiki.special/mediawiki.special.preferences.js @@ -108,11 +108,13 @@ 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(); @@ -240,7 +242,7 @@ 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 () { -- 2.20.1