Index: trunk/phase3/includes/HTMLForm.php |
— | — | @@ -701,7 +701,7 @@ |
702 | 702 | } |
703 | 703 | $attributes = array(); |
704 | 704 | if ( $displayTitle ) { |
705 | | - $attributes["title"] = Sanitizer::escapeId( $key ); |
| 705 | + $attributes["id"] = 'prefsection-' . Sanitizer::escapeId( $key, 'noninitial' ); |
706 | 706 | } |
707 | 707 | $subsectionHtml .= Xml::fieldset( $legend, $section, $attributes ) . "\n"; |
708 | 708 | } |
Index: trunk/phase3/resources/mediawiki.special/mediawiki.special.preferences.js |
— | — | @@ -2,48 +2,58 @@ |
3 | 3 | * JavaScript for Special:Preferences |
4 | 4 | */ |
5 | 5 | ( function( $, mw ) { |
6 | | - |
7 | 6 | $( '#prefsubmit' ).attr( 'id', 'prefcontrol' ); |
8 | | -$( '#preferences' ) |
| 7 | +var $preftoc = $('<ul id="preftoc"></ul>'); |
| 8 | +var $preferences = $( '#preferences' ) |
9 | 9 | .addClass( 'jsprefs' ) |
10 | | - .before( $( '<ul id="preftoc"></ul>' ) ) |
11 | | - .children( 'fieldset' ) |
12 | | - .hide() |
13 | | - .addClass( 'prefsection' ) |
14 | | - .children( 'legend' ) |
15 | | - .addClass( 'mainLegend' ) |
16 | | - .each( function( i, legend ) { |
17 | | - $(legend).parent().attr( 'id', 'prefsection-' + i ); |
18 | | - if ( i === 0 ) { |
19 | | - $(legend).parent().show(); |
20 | | - } |
21 | | - var ident = $(legend).parent().attr( 'title' ); |
22 | | - $( '#preftoc' ).append( |
23 | | - $( '<li></li>' ) |
24 | | - .addClass( i === 0 ? 'selected' : null ) |
25 | | - .append( |
26 | | - $( '<a></a>') |
27 | | - .text( $(legend).text() ) |
28 | | - .attr( 'id', 'preftab-' + ident + '-tab' ) |
29 | | - .attr( 'href', '#preftab-' + ident ) // Use #preftab-N instead of #prefsection-N to avoid jumping on click |
30 | | - .click( function() { |
31 | | - $(this).parent().parent().find( 'li' ).removeClass( 'selected' ); |
32 | | - $(this).parent().addClass( 'selected' ); |
33 | | - $( '#preferences > fieldset' ).hide(); |
34 | | - $( '#prefsection-' + i ).show(); |
35 | | - } ) |
36 | | - ) |
37 | | - ); |
38 | | - } |
39 | | - ); |
| 10 | + .before( $preftoc ); |
40 | 11 | |
| 12 | +var $fieldsets = $preferences.children( 'fieldset' ) |
| 13 | + .hide() |
| 14 | + .addClass( 'prefsection' ); |
| 15 | + |
| 16 | +var $legends = $fieldsets.children( 'legend' ) |
| 17 | + .addClass( 'mainLegend' ); |
| 18 | + |
| 19 | +// Populate the prefToc |
| 20 | +$legends.each( function( i, legend ) { |
| 21 | + var $legend = $(legend); |
| 22 | + if ( i === 0 ) { |
| 23 | + $legend.parent().show(); |
| 24 | + } |
| 25 | + var ident = $legend.parent().attr( 'id' ); |
| 26 | + |
| 27 | + var $li = $( '<li/>', { |
| 28 | + 'class' : ( i === 0 ) ? 'selected' : null |
| 29 | + }); |
| 30 | + var $a = $( '<a/>', { |
| 31 | + text : $legend.text(), |
| 32 | + id : ident.replace('prefsection', 'preftab'), |
| 33 | + href : '#' + ident |
| 34 | + }).click( function( e ) { |
| 35 | + e.preventDefault(); |
| 36 | + // Handle hash manually to prevent jumping |
| 37 | + // Therefore save and restore scrollTop to prevent jumping |
| 38 | + var scrollTop = $(window).scrollTop(); |
| 39 | + window.location.hash = $(this).attr('href'); |
| 40 | + $(window).scrollTop(scrollTop); |
| 41 | + |
| 42 | + $preftoc.find( 'li' ).removeClass( 'selected' ); |
| 43 | + $(this).parent().addClass( 'selected' ); |
| 44 | + $( '#preferences > fieldset' ).hide(); |
| 45 | + $( '#' + ident ).show(); |
| 46 | + }); |
| 47 | + $li.append( $a ); |
| 48 | + $preftoc.append( $li ); |
| 49 | +} ); |
| 50 | + |
41 | 51 | // If we've reloaded the page or followed an open-in-new-window, |
42 | 52 | // make the selected tab visible. |
43 | 53 | // On document ready: |
44 | 54 | $( function() { |
45 | 55 | var hash = window.location.hash; |
46 | | - if( hash.match( /^#preftab-[\w-]+/ ) ) { |
47 | | - var $tab = $( hash + '-tab' ); |
| 56 | + if( hash.match( /^#prefsection-[\w-]+/ ) ) { |
| 57 | + var $tab = $( hash.replace('prefsection', 'preftab') ); |
48 | 58 | $tab.click(); |
49 | 59 | } |
50 | 60 | } ); |