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 );
;
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' );