r90982 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r90981‎ | r90982 | r90983 >
Date:17:40, 28 June 2011
Author:krinkle
Status:ok (Comments)
Tags:
Comment:
mw.special.recentchanges fixes:
- using mw globally directly
- ID-selectors
- JS Effeciency in mw.special.rc.init (chaining instead of re-getting from this.select)
- passing function by reference instead of calling inside a new anonymous function
- marking checkboxes a private/local variable
- whitespace conventions



Follows up: r90943 r90960 r90968 r90980
Modified paths:
  • /trunk/phase3/resources/mediawiki.special/mediawiki.special.js (modified) (history)
  • /trunk/phase3/resources/mediawiki.special/mediawiki.special.recentchanges.js (modified) (history)
  • /trunk/phase3/tests/qunit/suites/resources/mediawiki.special/mediawiki.special.recentchanges.js (modified) (history)

Diff [purge]

Index: trunk/phase3/tests/qunit/suites/resources/mediawiki.special/mediawiki.special.recentchanges.js
@@ -1,12 +1,12 @@
2 -module( 'mediawiki.special.preferences.js' );
 2+module( 'mw.special.recentchanges.js' );
33
44 test( '-- Initial check', function() {
55 expect( 2 );
6 - ok( mediaWiki.special.recentchanges.init,
7 - 'mediaWiki.special.recentchanges.init defined'
 6+ ok( mw.special.recentchanges.init,
 7+ 'mw.special.recentchanges.init defined'
88 );
9 - ok( mediaWiki.special.recentchanges.updateCheckboxes,
10 - 'mediaWiki.special.recentchanges.updateCheckboxes defined'
 9+ ok( mw.special.recentchanges.updateCheckboxes,
 10+ 'mw.special.recentchanges.updateCheckboxes defined'
1111 );
1212 // TODO: verify checkboxes == [ 'nsassociated', 'nsinvert' ]
1313 });
@@ -38,29 +38,29 @@
3939 // TODO abstract the double strictEquals
4040
4141 // At first checkboxes are enabled
42 - strictEqual( $('input#nsinvert').attr('disabled'), enabled);
43 - strictEqual( $('input#nsassociated').attr('disabled'), enabled);
 42+ strictEqual( $( '#nsinvert' ).attr( 'disabled' ), enabled );
 43+ strictEqual( $( '#nsassociated' ).attr( 'disabled' ), enabled );
4444
4545 // load our magic code to disable them
46 - mediaWiki.special.recentchanges.init();
47 - strictEqual( $('#nsinvert').attr('disabled'), 'disabled');
48 - strictEqual( $('#nsassociated').attr('disabled'), 'disabled' );
 46+ mw.special.recentchanges.init();
 47+ strictEqual( $( '#nsinvert' ).attr( 'disabled' ), 'disabled' );
 48+ strictEqual( $( '#nsassociated' ).attr( 'disabled' ), 'disabled' );
4949
5050 // select second option...
51 - $('select#namespace option:nth-child(1)').removeAttr( 'selected' );
52 - $('select#namespace option:nth-child(2)').attr( 'selected', 'selected' );
53 - $('select#namespace').change();
 51+ $( '#namespace option:nth-child(1)' ).removeAttr( 'selected' );
 52+ $( '#namespace option:nth-child(2)' ).attr( 'selected', 'selected' );
 53+ $( '#namespace' ).change();
5454 // ... and checkboxes should be enabled again
55 - strictEqual( $('input#nsinvert').attr('disabled'), enabled);
56 - strictEqual( $('input#nsassociated').attr('disabled'), enabled);
 55+ strictEqual( $( '#nsinvert' ).attr( 'disabled' ), enabled );
 56+ strictEqual( $( '#nsassociated' ).attr( 'disabled' ), enabled );
5757
58 - // select first option ('all' namespace)...
59 - $('select#namespace option:nth-child(1)').attr( 'selected', 'selected' );
60 - $('select#namespace option:nth-child(2)').removeAttr( 'selected' );
61 - $('select#namespace').change();
 58+ // select first option ( 'all' namespace)...
 59+ $( '#namespace option:nth-child(1)' ).attr( 'selected', 'selected' );
 60+ $( '#namespace option:nth-child(2)' ).removeAttr( 'selected' );
 61+ $( '#namespace' ).change();
6262 // ... and checkboxes should now be disabled
63 - strictEqual( $('#nsinvert').attr('disabled'), 'disabled');
64 - strictEqual( $('#nsassociated').attr('disabled'), 'disabled' );
 63+ strictEqual( $( '#nsinvert' ).attr( 'disabled' ), 'disabled' );
 64+ strictEqual( $( '#nsassociated' ).attr( 'disabled' ), 'disabled' );
6565
6666 // DOM cleanup
6767 $env.remove();
Index: trunk/phase3/resources/mediawiki.special/mediawiki.special.recentchanges.js
@@ -1,38 +1,40 @@
22 /* JavaScript for Special:RecentChanges */
3 -( function( $, mw ) {
 3+( function( $ ) {
44
5 -mw.special.recentchanges = {
6 - // -- Variables
7 - 'select' : false,
8 - 'checkboxes' : [ 'nsassociated', 'nsinvert' ],
 5+ var checkboxes = [ 'nsassociated', 'nsinvert' ];
96
10 - // -- Methods
11 - 'init' : function() {
12 - this.select = $( 'select#namespace' );
 7+ mw.special.recentchanges = {
138
14 - // Register an onChange trigger for the <select> element
15 - this.select.change( function() {
16 - mw.special.recentchanges.updateCheckboxes();
17 - });
18 - // on load, trigger the event to eventually update checkboxes statuses
19 - this.select.change();
20 - },
 9+ /**
 10+ * @var select {jQuery}
 11+ */
 12+ $select: null,
 13+
 14+ init: function() {
 15+ var rc = this;
 16+
 17+ rc.$select =
 18+ $( 'select#namespace' )
 19+ .change( rc.updateCheckboxes )
 20+ // Trigger once set the initial statuses of the checkboxes.
 21+ .change();
 22+ },
2123
22 - /**
23 - * handler to disable/enable the namespace selector checkboxes when the
24 - * special 'all' namespace is selected/unselected respectively.
25 - */
26 - 'updateCheckboxes' : function() {
27 - // The 'all' namespace is the FIRST in the list.
28 - var isAllNS = this.select.find( 'option' ).first().is( ':selected' );
 24+ /**
 25+ * Handler to disable/enable the namespace selector checkboxes when the
 26+ * special 'all' namespace is selected/unselected respectively.
 27+ */
 28+ updateCheckboxes: function() {
 29+ // The 'all' namespace is the FIRST in the list.
 30+ var isAllNS = mw.special.recentchanges.$select.find( 'option' ).first().is( ':selected' );
2931
30 - // Iterates over checkboxes and propagate the selected option
31 - $.map( this.checkboxes, function(id) {
32 - $( 'input#'+id ).attr( 'disabled', isAllNS );
33 - });
34 - },
35 -};
 32+ // Iterates over checkboxes and propagate the selected option
 33+ $.map( checkboxes, function( id ) {
 34+ $( '#'+id ).attr( 'disabled', isAllNS );
 35+ });
 36+ },
 37+ };
3638
37 -mw.special.recentchanges.init();
 39+ mw.special.recentchanges.init();
3840
39 -}(jQuery, mediaWiki ) );
 41+})( jQuery );
Index: trunk/phase3/resources/mediawiki.special/mediawiki.special.js
@@ -1,5 +1 @@
2 -( function( $, mw ) {
3 -
4 - mw.special = {};
5 -
6 -} )( jQuery, mediaWiki );
 2+mw.special = {};

Follow-up revisions

RevisionCommit summaryAuthorDate
r90984mw.special.recentchanges fixes:...krinkle17:56, 28 June 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r90943Disable ns selector checkboxes when 'all' namespace is selected...hashar06:40, 28 June 2011
r90960Fix r90943: redefined mediawiki.special module that had already been added in...catrope14:28, 28 June 2011
r90968Move mediawiki.special.js to the correct directory. Followup r90941, r90960catrope15:24, 28 June 2011
r90980Update qunit test runner includes for mediawiki.special.js move in r90968brion17:17, 28 June 2011

Comments

#Comment by Brion VIBBER (talk | contribs)   17:55, 28 June 2011

Cleanup seems ok.

Status & tagging log