From: Krinkle Date: Sun, 6 Feb 2011 03:31:32 +0000 (+0000) Subject: Three small fixes to mediawiki.specials.preferences.js X-Git-Tag: 1.31.0-rc.0~32170 X-Git-Url: https://git.cyclocoop.org/%27.WWW_URL.%27admin/?a=commitdiff_plain;h=786a25f8043b5782d21dd124f94de449576b8f01;p=lhc%2Fweb%2Fwiklou.git Three small fixes to mediawiki.specials.preferences.js * Moving class-adder from mousedown() to click(). Mousedown also fires when opening the contextmenu (right-click). If I right-clicked, say, preftab-4 to open in a new tab, it would work (thanks to r81573), but it would also trigger the 'selected'-class on that tab (which is wrong and out-of-sync since click() did not and should not fire). This behaviour was the case in Safari 5/Firefox 3 (Mac) and Chrome (Windows). Moving it to click() should not have any affect on the behaviour in other browsers. Test it at: http://api.jquery.com/mousedown/ * Wrapping the hash-jump in a document.ready function. This module is enclosed in a self-executing anonymous function to enforce private scope passing mediaWiki and jQuery. Although that, ((function($,mw){ /* ... */ })(jQuery,mediaWiki);) may look like a shortcut for jQuery(document).ready(), it is not. (Because both ; and jQuery(function{ /* ... */ }); look alike and are shortcuts). Anyway, wrapping it now to avoid it jumping too early. * Using second argument of .each(), which is a reference to 'this' By using that (named) variable instead there's no confusion with the other 'this' inside the click event binder – which refers to the then-clicked element (the anchor tag) rather than the legend-element. --- diff --git a/resources/mediawiki.special/mediawiki.special.preferences.js b/resources/mediawiki.special/mediawiki.special.preferences.js index a6988bcd28..7fbd6d5901 100644 --- a/resources/mediawiki.special/mediawiki.special.preferences.js +++ b/resources/mediawiki.special/mediawiki.special.preferences.js @@ -12,24 +12,22 @@ $( '#preferences' ) .addClass( 'prefsection' ) .children( 'legend' ) .addClass( 'mainLegend' ) - .each( function( i ) { - $(this).parent().attr( 'id', 'prefsection-' + i ); + .each( function( i, legend ) { + $(legend).parent().attr( 'id', 'prefsection-' + i ); if ( i === 0 ) { - $(this).parent().show(); + $(legend).parent().show(); } $( '#preftoc' ).append( $( '
  • ' ) .addClass( i === 0 ? 'selected' : null ) .append( $( '') - .text( $(this).text() ) + .text( $(legend).text() ) .attr( 'id', 'preftab-' + i + '-tab' ) .attr( 'href', '#preftab-' + i ) // Use #preftab-N instead of #prefsection-N to avoid jumping on click - .mousedown( function( e ) { + .click( function() { $(this).parent().parent().find( 'li' ).removeClass( 'selected' ); - $(this).parent().addClass( 'selected' ); - } ) - .click( function( e ) { + $(this).parent().addClass( 'selected' ) $( '#preferences > fieldset' ).hide(); $( '#prefsection-' + i ).show(); } ) @@ -40,11 +38,14 @@ $( '#preferences' ) // If we've reloaded the page or followed an open-in-new-window, // make the selected tab visible. -var hash = window.location.hash; -if( hash.match( /^#preftab-[\d]+$/ ) ) { - var tab = $( hash + '-tab' ); - tab.mousedown().click(); -} +// On document ready: +$( function() { + var hash = window.location.hash; + if( hash.match( /^#preftab-[\d]+$/ ) ) { + var $tab = $( hash + '-tab' ); + $tab.click(); + } +} ); /** * Given an email validity status (true, false, null) update the label CSS class