Clean up: Consistently use "$" instead of "$( document ).ready"
[lhc/web/wiklou.git] / resources / mediawiki.special / mediawiki.special.recentchanges.js
index 1006a9d..79d793a 100644 (file)
@@ -1,38 +1,34 @@
-/* JavaScript for Special:RecentChanges */
-( function( $, mw ) {
+/**
+ * JavaScript for Special:RecentChanges
+ */
+( function ( mw, $ ) {
+       var rc, $checkboxes, $select;
 
-mw.special.recentchanges = {
-       // -- Variables
-       'select' : false,
-       'checkboxes' : [ 'nsassociated', 'nsinvert' ],
+       rc = {
+               /**
+                * Handler to disable/enable the namespace selector checkboxes when the
+                * special 'all' namespace is selected/unselected respectively.
+                */
+               updateCheckboxes: function () {
+                       // The option element for the 'all' namespace has an empty value
+                       var isAllNS = $select.val() === '';
 
-       // -- Methods
-       'init' : function() {
-               this.select = $( 'select#namespace' );
+                       // Iterates over checkboxes and propagate the selected option
+                       $checkboxes.prop( 'disabled', isAllNS );
+               },
 
-               // 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();
-       },
-       
-       /**
-        * 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' );
+               init: function () {
+                       $select = $( '#namespace' );
+                       $checkboxes = $( '#nsassociated, #nsinvert' );
 
-               // Iterates over checkboxes and propagate the selected option
-               $.map( this.checkboxes, function(id) {
-                       $( 'input#'+id ).attr( 'disabled', isAllNS );
-               });
-       },
-};
+                       // Bind to change event, and trigger once to set the initial state of the checkboxes.
+                       rc.updateCheckboxes();
+                       $select.change( rc.updateCheckboxes );
+               }
+       };
 
-mw.special.recentchanges.init();
+       $( rc.init );
 
-}(jQuery, mediaWiki ) );
+       mw.special.recentchanges = rc;
+
+}( mediaWiki, jQuery ) );