mw.special.recentchanges fixes:
authorKrinkle <krinkle@users.mediawiki.org>
Tue, 28 Jun 2011 17:56:56 +0000 (17:56 +0000)
committerKrinkle <krinkle@users.mediawiki.org>
Tue, 28 Jun 2011 17:56:56 +0000 (17:56 +0000)
- 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

resources/Resources.php
resources/mediawiki.special/mediawiki.special.recentchanges.js
tests/qunit/suites/resources/mediawiki.special/mediawiki.special.recentchanges.js

index 12e178d..877d9c4 100644 (file)
@@ -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
index 294417c..4854ff4 100644 (file)
@@ -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
                 */
                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 );
index 5f13e29..b25a62f 100644 (file)
@@ -33,31 +33,35 @@ test( 'foobar', function() {
        ;
 
        var $env = $( '<div>' ).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' );