r90984 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r90983‎ | r90984 | r90985 >
Date:17:56, 28 June 2011
Author:krinkle
Status:ok (Comments)
Tags:
Comment:
mw.special.recentchanges fixes:
- Partial self-revert of r90982 (binding and triggering must not be chained, as the calling function refers to the variable we're setting)
- The Qunit tests pass now :)



Follows up: r90943 r90960 r90968 r90980 r90982
Modified paths:
  • /trunk/phase3/resources/Resources.php (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
@@ -33,31 +33,35 @@
3434 ;
3535
3636 var $env = $( '<div>' ).html( select ).appendTo( 'body' );
37 - var enabled = undefined;
3837
3938 // TODO abstract the double strictEquals
4039
4140 // At first checkboxes are enabled
42 - strictEqual( $( '#nsinvert' ).attr( 'disabled' ), enabled );
43 - strictEqual( $( '#nsassociated' ).attr( 'disabled' ), enabled );
 41+ strictEqual( $( '#nsinvert' ).attr( 'disabled' ), undefined );
 42+ strictEqual( $( '#nsassociated' ).attr( 'disabled' ), undefined );
4443
45 - // load our magic code to disable them
 44+ // Initiate the recentchanges module
4645 mw.special.recentchanges.init();
 46+
 47+ // By default
4748 strictEqual( $( '#nsinvert' ).attr( 'disabled' ), 'disabled' );
4849 strictEqual( $( '#nsassociated' ).attr( 'disabled' ), 'disabled' );
4950
5051 // select second option...
51 - $( '#namespace option:nth-child(1)' ).removeAttr( 'selected' );
52 - $( '#namespace option:nth-child(2)' ).attr( 'selected', 'selected' );
 52+ var $options = $( '#namespace' ).find( 'option' );
 53+ $options.eq(0).removeAttr( 'selected' );
 54+ $options.eq(1).attr( 'selected', 'selected' );
5355 $( '#namespace' ).change();
 56+
5457 // ... and checkboxes should be enabled again
55 - strictEqual( $( '#nsinvert' ).attr( 'disabled' ), enabled );
56 - strictEqual( $( '#nsassociated' ).attr( 'disabled' ), enabled );
 58+ strictEqual( $( '#nsinvert' ).attr( 'disabled' ), undefined );
 59+ strictEqual( $( '#nsassociated' ).attr( 'disabled' ), undefined );
5760
5861 // select first option ( 'all' namespace)...
59 - $( '#namespace option:nth-child(1)' ).attr( 'selected', 'selected' );
60 - $( '#namespace option:nth-child(2)' ).removeAttr( 'selected' );
 62+ $options.eq(1).removeAttr( 'selected' );
 63+ $options.eq(0).attr( 'selected', 'selected' );;
6164 $( '#namespace' ).change();
 65+
6266 // ... and checkboxes should now be disabled
6367 strictEqual( $( '#nsinvert' ).attr( 'disabled' ), 'disabled' );
6468 strictEqual( $( '#nsassociated' ).attr( 'disabled' ), 'disabled' );
Index: trunk/phase3/resources/Resources.php
@@ -538,6 +538,7 @@
539539 'mediawiki.special.recentchanges' => array(
540540 'scripts' => 'resources/mediawiki.special/mediawiki.special.recentchanges.js',
541541 'dependencies' => array( 'mediawiki.special' ),
 542+ 'position' => 'top',
542543 ),
543544 'mediawiki.special.upload' => array(
544545 // @TODO: merge in remainder of mediawiki.legacy.upload
Index: trunk/phase3/resources/mediawiki.special/mediawiki.special.recentchanges.js
@@ -3,22 +3,12 @@
44
55 var checkboxes = [ 'nsassociated', 'nsinvert' ];
66
7 - mw.special.recentchanges = {
 7+ /**
 8+ * @var select {jQuery}
 9+ */
 10+ var $select = null;
811
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 - },
 12+ var rc = mw.special.recentchanges = {
2313
2414 /**
2515 * Handler to disable/enable the namespace selector checkboxes when the
@@ -26,15 +16,24 @@
2717 */
2818 updateCheckboxes: function() {
2919 // The 'all' namespace is the FIRST in the list.
30 - var isAllNS = mw.special.recentchanges.$select.find( 'option' ).first().is( ':selected' );
 20+ var isAllNS = $select.find( 'option' ).first().is( ':selected' );
3121
3222 // Iterates over checkboxes and propagate the selected option
33 - $.map( checkboxes, function( id ) {
34 - $( '#'+id ).attr( 'disabled', isAllNS );
 23+ $.each( checkboxes, function( i, id ) {
 24+ $( '#' + id ).attr( 'disabled', isAllNS );
3525 });
3626 },
 27+
 28+ init: function() {
 29+ // Populate & bind
 30+ $select = $( '#namespace' ).change( rc.updateCheckboxes );
 31+
 32+ // Trigger once set the initial statuses of the checkboxes.
 33+ $select.change();
 34+ }
3735 };
3836
39 - mw.special.recentchanges.init();
 37+ // Run when document is ready
 38+ $( rc.init );
4039
4140 })( jQuery );

Follow-up revisions

RevisionCommit summaryAuthorDate
r90986per r90984 CR, cleaner this waykrinkle18:17, 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
r90982mw.special.recentchanges fixes:...krinkle17:40, 28 June 2011

Comments

#Comment by Brion VIBBER (talk | contribs)   18:07, 28 June 2011

To clarify -- there is no problem with both binding and triggering something in a chained manner. The problem was failing to set rc.$select until after triggering the event, which could cause the handler to be called and attempt to reference rc.$select.

#Comment by Brion VIBBER (talk | contribs)   18:14, 28 June 2011

This commit also moves the RC special page info setup to the top to force it to load sooner; seems ok.

Status & tagging log