Jdlrobson has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/108725


Change subject: Minerva: Make preferences on Minerva consistent with desktop
......................................................................

Minerva: Make preferences on Minerva consistent with desktop

* Use the same id's for buttons
* Maintain the open appearance tab when switching the skin to Minerva
* Ensure when saving the current tab is kept enabled

Change-Id: I45070544303bb1f9df46acfb5865b134b9e5a30b
---
M javascripts/specials/preferences.js
1 file changed, 27 insertions(+), 6 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend 
refs/changes/25/108725/1

diff --git a/javascripts/specials/preferences.js 
b/javascripts/specials/preferences.js
index 94ff477..597124a 100644
--- a/javascripts/specials/preferences.js
+++ b/javascripts/specials/preferences.js
@@ -1,23 +1,34 @@
 jQuery( function( $ ) {
-var $header, $tabHeadings, $tabs, hash = window.location.hash, $activeBtn;
+var $header, $tabHeadings, $tabs, $activeBtn, val,
+       $form = $( '#mw-prefs-form' ),
+       action = $form.attr( 'action' ),
+       // Load from user preference if available
+       hash = window.location.hash;
 
 $header = $( '<div class="header">' ).insertBefore( '#content' );
 $tabHeadings = $( '<ul class="button-bar">' ).appendTo( $header );
 $tabs = $( '#preferences > fieldset' );
 
-function handler() {
-       var $this = $( this );
+function handler( ev ) {
+       var $this = $( this ),
+               hash = $this.attr( 'href' );
+       // Ensure that the browser does not jump to the section in the DOM
+       ev.preventDefault();
+       // However make sure the address bar changes
+       window.location.hash = hash;
        $tabs.hide();
        $tabHeadings.find( '.active' ).removeClass( 'active' );
        $this.parent().addClass( 'active' );
        $this.data( 'tab' ).show();
+       // Ensure on a save the hash is passed.
+       $form.attr( 'action', action + hash );
 }
 
-$tabs.each( function( i ) {
+$tabs.each( function() {
        var $this = $( this ),
                legend = $this.find( 'legend' ).eq( 0 ),
                $li = $( '<li>' ).appendTo( $tabHeadings ),
-               id = 'pref' + i;
+               id = $this.attr( 'id' );
 
        $( '<a class="button">' ).attr( 'href', '#' + id ).
                data( 'tab', $this ).text( legend.text() ).
@@ -25,9 +36,19 @@
 } );
 $tabs.hide();
 
+// Preserve active tab when switching from another skin to Minerva
+// FIXME: [Core] this is a terrible abuse of the web.
+if ( !hash && window.sessionStorage ) {
+       val = window.sessionStorage.getItem( 'mediawikiPreferencesTab' );
+       if ( val ) {
+               hash = '#mw-prefsection-' + val;
+       }
+}
+
 $activeBtn = $tabHeadings.find( '[href="' + hash + '"]' );
 if ( $activeBtn.length === 0 ) {
-       $tabHeadings.find( '[href="#pref0"]' ).trigger( 'click' );
+       // click the first tab button
+       $tabHeadings.find( '.button' ).eq( 0 ).trigger( 'click' );
 } else {
        $activeBtn.trigger( 'click' );
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/108725
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I45070544303bb1f9df46acfb5865b134b9e5a30b
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to