r74282 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r74281‎ | r74282 | r74283 >
Date:22:16, 4 October 2010
Author:tparscal
Status:ok (Comments)
Tags:
Comment:
Moved some of the functionality from mediawiki.legacy.prefs into mediawiki.specials.preferences.
Modified paths:
  • /trunk/phase3/includes/specials/SpecialPreferences.php (modified) (history)
  • /trunk/phase3/resources/Resources.php (modified) (history)
  • /trunk/phase3/resources/mediawiki/mediawiki.specials.preferences.js (added) (history)
  • /trunk/phase3/skins/common/prefs.js (modified) (history)

Diff [purge]

Index: trunk/phase3/skins/common/prefs.js
@@ -1,81 +1,3 @@
2 -// generate toc from prefs form, fold sections
3 -// XXX: needs testing on IE/Mac and safari
4 -// more comments to follow
5 -window.tabbedprefs = function() {
6 - var prefform = document.getElementById( 'preferences' );
7 - if ( !prefform || !document.createElement ) {
8 - return;
9 - }
10 - if ( prefform.nodeName.toLowerCase() == 'a' ) {
11 - return; // Occasional IE problem
12 - }
13 - prefform.className = prefform.className + 'jsprefs';
14 - var sections = [];
15 - var children = prefform.childNodes;
16 - var seci = 0;
17 - for ( var i = 0; i < children.length; i++ ) {
18 - if ( children[i].nodeName.toLowerCase() == 'fieldset' ) {
19 - children[i].id = 'prefsection-' + seci;
20 - children[i].className = 'prefsection';
21 - if ( is_opera ) {
22 - children[i].className = 'prefsection operaprefsection';
23 - }
24 - var legends = children[i].getElementsByTagName('legend');
25 - sections[seci] = {};
26 - if ( legends[0] ) {
27 - legends[0].className = 'mainLegend';
28 - }
29 - if ( legends[0] && legends[0].firstChild.nodeValue ) {
30 - sections[seci].text = legends[0].firstChild.nodeValue;
31 - } else {
32 - sections[seci].text = '# ' + seci;
33 - }
34 - sections[seci].secid = children[i].id;
35 - seci++;
36 - if ( sections.length != 1 ) {
37 - children[i].style.display = 'none';
38 - } else {
39 - var selectedid = children[i].id;
40 - }
41 - }
42 - }
43 - var toc = document.createElement( 'ul' );
44 - toc.id = 'preftoc';
45 - toc.selectedid = selectedid;
46 - for ( i = 0; i < sections.length; i++ ) {
47 - var li = document.createElement( 'li' );
48 - if ( i === 0 ) {
49 - li.className = 'selected';
50 - }
51 - var a = document.createElement( 'a' );
52 - a.href = '#' + sections[i].secid;
53 - a.onmousedown = a.onclick = uncoversection;
54 - a.appendChild( document.createTextNode( sections[i].text ) );
55 - a.secid = sections[i].secid;
56 - li.appendChild( a );
57 - toc.appendChild( li );
58 - }
59 - prefform.parentNode.insertBefore( toc, prefform.parentNode.childNodes[0] );
60 - document.getElementById( 'prefsubmit' ).id = 'prefcontrol';
61 -}
62 -
63 -window.uncoversection = function() {
64 - var oldsecid = this.parentNode.parentNode.selectedid;
65 - var newsec = document.getElementById( this.secid );
66 - if ( oldsecid != this.secid ) {
67 - var ul = document.getElementById( 'preftoc' );
68 - document.getElementById( oldsecid ).style.display = 'none';
69 - newsec.style.display = 'block';
70 - ul.selectedid = this.secid;
71 - var lis = ul.getElementsByTagName( 'li' );
72 - for ( var i = 0; i< lis.length; i++ ) {
73 - lis[i].className = '';
74 - }
75 - this.parentNode.className = 'selected';
76 - }
77 - return false;
78 -}
79 -
802 // Timezone stuff
813 // tz in format [+-]HHMM
824 window.checkTimezone = function( tz, msg ) {
@@ -214,4 +136,3 @@
215137 }
216138
217139 addOnloadHook( timezoneSetup );
218 -addOnloadHook( tabbedprefs );
Index: trunk/phase3/includes/specials/SpecialPreferences.php
@@ -51,8 +51,9 @@
5252 $this->showResetForm();
5353 return;
5454 }
55 -
 55+
5656 $wgOut->addModules( 'mediawiki.legacy.prefs' );
 57+ $wgOut->addModuleScripts( 'mediawiki.specials.preferences' );
5758
5859 if ( $wgRequest->getCheck( 'success' ) ) {
5960 $wgOut->wrapWikiMsg(
Index: trunk/phase3/resources/Resources.php
@@ -304,6 +304,9 @@
305305 'scripts' => 'resources/mediawiki/mediawiki.js',
306306 'debugScripts' => 'resources/mediawiki/mediawiki.log.js',
307307 ) ),
 308+ 'mediawiki.specials.preferences' => new ResourceLoaderFileModule( array(
 309+ 'scripts' => 'resources/mediawiki/mediawiki.specials.preferences.js',
 310+ ) ),
308311
309312 /* MediaWiki Legacy */
310313
Index: trunk/phase3/resources/mediawiki/mediawiki.specials.preferences.js
@@ -0,0 +1,40 @@
 2+/*
 3+ * JavaScript for Special:Preferences
 4+ */
 5+
 6+$( '#prefsubmit' ).attr( 'id', 'prefcontrol' ).end()
 7+$( '#preferences' )
 8+ .addClass( 'jsprefs' )
 9+ .before( $( '<ul id="preftoc"></ul>' ) )
 10+ .find( '> fieldset' )
 11+ .hide()
 12+ .addClass( 'prefsection' )
 13+ .find( '> legend' )
 14+ .addClass( 'mainLegend' )
 15+ .each( function( i ) {
 16+ $(this).parent().attr( 'id', 'prefsection-' + i );
 17+ if ( i === 0 ) {
 18+ $(this).parent().show();
 19+ }
 20+ $( '#preftoc' ).append(
 21+ $( '<li></li>' )
 22+ .addClass( i === 0 ? 'selected' : null )
 23+ .append(
 24+ $( '<a></a>')
 25+ .text( $(this).text() )
 26+ .attr( 'href', '#prefsection-' + i )
 27+ .mousedown( function( e ) {
 28+ $(this).parent().parent().find( 'li' ).removeClass( 'selected' );
 29+ $(this).parent().addClass( 'selected' );
 30+ e.preventDefault();
 31+ return false;
 32+ } )
 33+ .click( function( e ) {
 34+ $( '#preferences > fieldset' ).hide();
 35+ $( '#prefsection-' + i ).show();
 36+ e.preventDefault();
 37+ return false;
 38+ } )
 39+ )
 40+ );
 41+ } );
Property changes on: trunk/phase3/resources/mediawiki/mediawiki.specials.preferences.js
___________________________________________________________________
Added: svn:eol-style
142 + native

Follow-up revisions

RevisionCommit summaryAuthorDate
r74380Improved on r74282 and r74333 in response to CR comments.tparscal19:05, 6 October 2010

Comments

#Comment by Brion VIBBER (talk | contribs)   15:21, 5 October 2010

mmmm delicious jquery code

#Comment by Catrope (talk | contribs)   18:08, 6 October 2010
+$( '#prefsubmit' ).attr( 'id', 'prefcontrol' ).end()

Using .end() here is useless. Also, why is it changing the ID?

+	.before( $( '<ul id="preftoc"></ul>' ) )

No need to jQuery-wrap that.

+	.find( '> fieldset' )

AKA .children( 'fieldset' ) . Another occurrence just below.

#Comment by Trevor Parscal (WMF) (talk | contribs)   19:06, 6 October 2010
  • The .end() and needless wrapping was a remnant of shuffling things around.
  • Good point with the .children - using that now.

All fixed in r74380

#Comment by Catrope (talk | contribs)   13:02, 7 October 2010

One remaining unanswered question: why are you changing the ID of prefsubmit to prefcontrol?

#Comment by Trevor Parscal (WMF) (talk | contribs)   15:59, 7 October 2010

I was just keeping up the original behavior - I do not know.

Status & tagging log