From: Krinkle Date: Tue, 28 Jun 2011 17:56:56 +0000 (+0000) Subject: mw.special.recentchanges fixes: X-Git-Tag: 1.31.0-rc.0~29220 X-Git-Url: http://git.cyclocoop.org/%22.%24image2.%22?a=commitdiff_plain;h=ab52899b1d0c3d145a659dff673b80b345bb6058;p=lhc%2Fweb%2Fwiklou.git 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 --- diff --git a/resources/Resources.php b/resources/Resources.php index 12e178dd61..877d9c4523 100644 --- a/resources/Resources.php +++ b/resources/Resources.php @@ -538,6 +538,7 @@ return array( 'mediawiki.special.recentchanges' => array( 'scripts' => 'resources/mediawiki.special/mediawiki.special.recentchanges.js', 'dependencies' => array( 'mediawiki.special' ), + 'position' => 'top', ), 'mediawiki.special.upload' => array( // @TODO: merge in remainder of mediawiki.legacy.upload diff --git a/resources/mediawiki.special/mediawiki.special.recentchanges.js b/resources/mediawiki.special/mediawiki.special.recentchanges.js index 294417ce1f..4854ff4abf 100644 --- a/resources/mediawiki.special/mediawiki.special.recentchanges.js +++ b/resources/mediawiki.special/mediawiki.special.recentchanges.js @@ -3,22 +3,12 @@ var checkboxes = [ 'nsassociated', 'nsinvert' ]; - mw.special.recentchanges = { + /** + * @var select {jQuery} + */ + var $select = null; - /** - * @var select {jQuery} - */ - $select: null, - - init: function() { - var rc = this; - - rc.$select = - $( 'select#namespace' ) - .change( rc.updateCheckboxes ) - // Trigger once set the initial statuses of the checkboxes. - .change(); - }, + var rc = mw.special.recentchanges = { /** * Handler to disable/enable the namespace selector checkboxes when the @@ -26,15 +16,24 @@ */ updateCheckboxes: function() { // The 'all' namespace is the FIRST in the list. - var isAllNS = mw.special.recentchanges.$select.find( 'option' ).first().is( ':selected' ); + var isAllNS = $select.find( 'option' ).first().is( ':selected' ); // Iterates over checkboxes and propagate the selected option - $.map( checkboxes, function( id ) { - $( '#'+id ).attr( 'disabled', isAllNS ); + $.each( checkboxes, function( i, id ) { + $( '#' + id ).attr( 'disabled', isAllNS ); }); }, + + init: function() { + // Populate & bind + $select = $( '#namespace' ).change( rc.updateCheckboxes ); + + // Trigger once set the initial statuses of the checkboxes. + $select.change(); + } }; - mw.special.recentchanges.init(); + // Run when document is ready + $( rc.init ); })( jQuery ); diff --git a/tests/qunit/suites/resources/mediawiki.special/mediawiki.special.recentchanges.js b/tests/qunit/suites/resources/mediawiki.special/mediawiki.special.recentchanges.js index 5f13e298b2..b25a62f55b 100644 --- a/tests/qunit/suites/resources/mediawiki.special/mediawiki.special.recentchanges.js +++ b/tests/qunit/suites/resources/mediawiki.special/mediawiki.special.recentchanges.js @@ -33,31 +33,35 @@ test( 'foobar', function() { ; var $env = $( '
' ).html( select ).appendTo( 'body' ); - var enabled = undefined; // TODO abstract the double strictEquals // At first checkboxes are enabled - strictEqual( $( '#nsinvert' ).attr( 'disabled' ), enabled ); - strictEqual( $( '#nsassociated' ).attr( 'disabled' ), enabled ); + strictEqual( $( '#nsinvert' ).attr( 'disabled' ), undefined ); + strictEqual( $( '#nsassociated' ).attr( 'disabled' ), undefined ); - // load our magic code to disable them + // Initiate the recentchanges module mw.special.recentchanges.init(); + + // By default strictEqual( $( '#nsinvert' ).attr( 'disabled' ), 'disabled' ); strictEqual( $( '#nsassociated' ).attr( 'disabled' ), 'disabled' ); // select second option... - $( '#namespace option:nth-child(1)' ).removeAttr( 'selected' ); - $( '#namespace option:nth-child(2)' ).attr( 'selected', 'selected' ); + var $options = $( '#namespace' ).find( 'option' ); + $options.eq(0).removeAttr( 'selected' ); + $options.eq(1).attr( 'selected', 'selected' ); $( '#namespace' ).change(); + // ... and checkboxes should be enabled again - strictEqual( $( '#nsinvert' ).attr( 'disabled' ), enabled ); - strictEqual( $( '#nsassociated' ).attr( 'disabled' ), enabled ); + strictEqual( $( '#nsinvert' ).attr( 'disabled' ), undefined ); + strictEqual( $( '#nsassociated' ).attr( 'disabled' ), undefined ); // select first option ( 'all' namespace)... - $( '#namespace option:nth-child(1)' ).attr( 'selected', 'selected' ); - $( '#namespace option:nth-child(2)' ).removeAttr( 'selected' ); + $options.eq(1).removeAttr( 'selected' ); + $options.eq(0).attr( 'selected', 'selected' );; $( '#namespace' ).change(); + // ... and checkboxes should now be disabled strictEqual( $( '#nsinvert' ).attr( 'disabled' ), 'disabled' ); strictEqual( $( '#nsassociated' ).attr( 'disabled' ), 'disabled' );