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

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

index 80c0fec..3526cef 100644 (file)
@@ -1,5 +1 @@
-( function( $, mw ) {
-
-       mw.special = {};
-
-} )( jQuery, mediaWiki );
+mw.special = {};
index 1006a9d..294417c 100644 (file)
@@ -1,38 +1,40 @@
 /* JavaScript for Special:RecentChanges */
-( function( $, mw ) {
-
-mw.special.recentchanges = {
-       // -- Variables
-       'select' : false,
-       'checkboxes' : [ 'nsassociated', 'nsinvert' ],
-
-       // -- Methods
-       'init' : function() {
-               this.select = $( 'select#namespace' );
-
-               // Register an onChange trigger for the <select> element
-               this.select.change( function() {
-                       mw.special.recentchanges.updateCheckboxes();
-               });
-               // on load, trigger the event to eventually update checkboxes statuses
-               this.select.change();
-       },
+( function( $ ) {
+
+       var checkboxes = [ 'nsassociated', 'nsinvert' ];
+
+       mw.special.recentchanges = {
+
+               /**
+                * @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();
+               },
        
-       /**
-        * handler to disable/enable the namespace selector checkboxes when the
-        * special 'all' namespace is selected/unselected respectively.
-        */
-       'updateCheckboxes' : function() {
-               // The 'all' namespace is the FIRST in the list.
-               var isAllNS = this.select.find( 'option' ).first().is( ':selected' );
-
-               // Iterates over checkboxes and propagate the selected option
-               $.map( this.checkboxes, function(id) {
-                       $( 'input#'+id ).attr( 'disabled', isAllNS );
-               });
-       },
-};
-
-mw.special.recentchanges.init();
-
-}(jQuery, mediaWiki ) );
+               /**
+                * Handler to disable/enable the namespace selector checkboxes when the
+                * special 'all' namespace is selected/unselected respectively.
+                */
+               updateCheckboxes: function() {
+                       // The 'all' namespace is the FIRST in the list.
+                       var isAllNS = mw.special.recentchanges.$select.find( 'option' ).first().is( ':selected' );
+
+                       // Iterates over checkboxes and propagate the selected option
+                       $.map( checkboxes, function( id ) {
+                               $( '#'+id ).attr( 'disabled', isAllNS );
+                       });
+               },
+       };
+
+       mw.special.recentchanges.init();
+
+})( jQuery );
index 7175121..5f13e29 100644 (file)
@@ -1,12 +1,12 @@
-module( 'mediawiki.special.preferences.js' );
+module( 'mw.special.recentchanges.js' );
 
 test( '-- Initial check', function() {
        expect( 2 );
-       ok( mediaWiki.special.recentchanges.init,
-          'mediaWiki.special.recentchanges.init defined'
+       ok( mw.special.recentchanges.init,
+          'mw.special.recentchanges.init defined'
          );
-       ok( mediaWiki.special.recentchanges.updateCheckboxes,
-          'mediaWiki.special.recentchanges.updateCheckboxes defined'
+       ok( mw.special.recentchanges.updateCheckboxes,
+          'mw.special.recentchanges.updateCheckboxes defined'
          );
        // TODO: verify checkboxes == [ 'nsassociated', 'nsinvert' ]
 });
@@ -38,29 +38,29 @@ test( 'foobar', function() {
        // TODO abstract the double strictEquals
 
        // At first checkboxes are enabled
-       strictEqual( $('input#nsinvert').attr('disabled'), enabled);
-       strictEqual( $('input#nsassociated').attr('disabled'), enabled);
+       strictEqual( $( '#nsinvert' ).attr( 'disabled' ), enabled );
+       strictEqual( $( '#nsassociated' ).attr( 'disabled' ), enabled );
 
        // load our magic code to disable them
-       mediaWiki.special.recentchanges.init();
-       strictEqual( $('#nsinvert').attr('disabled'), 'disabled');
-       strictEqual( $('#nsassociated').attr('disabled'), 'disabled' );
+       mw.special.recentchanges.init();
+       strictEqual( $( '#nsinvert' ).attr( 'disabled' ), 'disabled' );
+       strictEqual( $( '#nsassociated' ).attr( 'disabled' ), 'disabled' );
 
        // select second option...
-       $('select#namespace option:nth-child(1)').removeAttr( 'selected' );
-       $('select#namespace option:nth-child(2)').attr( 'selected', 'selected' );
-       $('select#namespace').change();
+       $( '#namespace option:nth-child(1)' ).removeAttr( 'selected' );
+       $( '#namespace option:nth-child(2)' ).attr( 'selected', 'selected' );
+       $( '#namespace' ).change();
        // ... and checkboxes should be enabled again
-       strictEqual( $('input#nsinvert').attr('disabled'), enabled);
-       strictEqual( $('input#nsassociated').attr('disabled'), enabled);
+       strictEqual( $( '#nsinvert' ).attr( 'disabled' ), enabled );
+       strictEqual( $( '#nsassociated' ).attr( 'disabled' ), enabled );
 
-       // select first option ('all' namespace)...
-       $('select#namespace option:nth-child(1)').attr( 'selected', 'selected' );
-       $('select#namespace option:nth-child(2)').removeAttr( 'selected' );
-       $('select#namespace').change();
+       // select first option ( 'all' namespace)...
+       $( '#namespace option:nth-child(1)' ).attr( 'selected', 'selected' );
+       $( '#namespace option:nth-child(2)' ).removeAttr( 'selected' );
+       $( '#namespace' ).change();
        // ... and checkboxes should now be disabled
-       strictEqual( $('#nsinvert').attr('disabled'), 'disabled');
-       strictEqual( $('#nsassociated').attr('disabled'), 'disabled' );
+       strictEqual( $( '#nsinvert' ).attr( 'disabled' ), 'disabled' );
+       strictEqual( $( '#nsassociated' ).attr( 'disabled' ), 'disabled' );
 
        // DOM cleanup
        $env.remove();