applying code conventions and cleanup in mediawiki.special.*
authorMatmaRex <matma.rex@gmail.com>
Sun, 16 Dec 2012 14:15:49 +0000 (15:15 +0100)
committerMatmaRex <matma.rex@gmail.com>
Sun, 16 Dec 2012 14:15:49 +0000 (15:15 +0100)
Using standard closures per [[CC/JS]], typos in comments, indentation
inconsistencies, some other minor changes.

Change-Id: I53eef75006d87c8b55d6780d36165317066d1368

resources/mediawiki.special/mediawiki.special.block.js
resources/mediawiki.special/mediawiki.special.changeemail.js
resources/mediawiki.special/mediawiki.special.movePage.js
resources/mediawiki.special/mediawiki.special.preferences.js
resources/mediawiki.special/mediawiki.special.recentchanges.js
resources/mediawiki.special/mediawiki.special.search.js
resources/mediawiki.special/mediawiki.special.undelete.js
resources/mediawiki.special/mediawiki.special.upload.js

index 077adcd..2a158df 100644 (file)
@@ -2,8 +2,7 @@
  * JavaScript for Special:Block
  */
 ( function ( mw, $ ) {
-       $( function ( $ ) {
-
+       $( document ).ready( function () {
                var $blockTarget = $( '#mw-bi-target' ),
                        $anonOnlyRow = $( '#mw-input-wpHardBlock' ).closest( 'tr' ),
                        $enableAutoblockRow = $( '#mw-input-wpAutoBlock' ).closest( 'tr' ),
                        $watchUser = $( '#mw-input-wpWatch' ).closest( 'tr' );
 
                function updateBlockOptions( instant ) {
-                       if ( !$blockTarget.length ) {
-                               return;
-                       }
-
                        var blocktarget = $.trim( $blockTarget.val() ),
                                isEmpty = blocktarget === '',
                                isIp = mw.util.isIPv4Address( blocktarget, true ) || mw.util.isIPv6Address( blocktarget, true ),
                        }
                }
 
-               // Bind functions so they're checked whenever stuff changes
-               $blockTarget.keyup( updateBlockOptions );
+               if ( $blockTarget.length ) {
+                       // Bind functions so they're checked whenever stuff changes
+                       $blockTarget.keyup( updateBlockOptions );
 
-               // Call them now to set initial state (ie. Special:Block/Foobar?wpBlockExpiry=2+hours)
-               updateBlockOptions( /* instant= */ true );
+                       // Call them now to set initial state (ie. Special:Block/Foobar?wpBlockExpiry=2+hours)
+                       updateBlockOptions( /* instant= */ true );
+               }
        } );
 }( mediaWiki, jQuery ) );
 
index cab0bbd..14c2f03 100644 (file)
@@ -1,42 +1,42 @@
-/*
+/**
  * JavaScript for Special:ChangeEmail
  */
 ( function ( mw, $ ) {
+       /**
+        * Given an email validity status (true, false, null) update the label CSS class
+        */
+       function updateMailValidityLabel( mail ) {
+               var isValid = mw.util.validateEmail( mail ),
+                       $label = $( '#mw-emailaddress-validity' );
 
-/**
- * Given an email validity status (true, false, null) update the label CSS class
- */
-function updateMailValidityLabel( mail ) {
-       var     isValid = mw.util.validateEmail( mail ),
-               $label = $( '#mw-emailaddress-validity' );
-
-       // We allow empty address
-       if( isValid === null ) {
-               $label.text( '' ).removeClass( 'valid invalid' );
+               // We allow empty address
+               if ( isValid === null ) {
+                       $label.text( '' ).removeClass( 'valid invalid' );
 
-       // Valid
-       } else if ( isValid ) {
-               $label.text( mw.msg( 'email-address-validity-valid' ) ).addClass( 'valid' ).removeClass( 'invalid' );
+               // Valid
+               } else if ( isValid ) {
+                       $label.text( mw.msg( 'email-address-validity-valid' ) ).addClass( 'valid' ).removeClass( 'invalid' );
 
-       // Not valid
-       } else {
-               $label.text( mw.msg( 'email-address-validity-invalid' ) ).addClass( 'invalid' ).removeClass( 'valid' );
+               // Not valid
+               } else {
+                       $label.text( mw.msg( 'email-address-validity-invalid' ) ).addClass( 'invalid' ).removeClass( 'valid' );
+               }
        }
-}
 
-$( document ).ready( function () {
-       // Lame tip to let user know if its email is valid. See bug 22449
-       // Only bind once for 'blur' so that the user can fill it in without errors
-       // After that look at every keypress for direct feedback if it was invalid onblur
-       $( '#wpNewEmail' ).one( 'blur', function () {
-               if ( $( '#mw-emailaddress-validity' ).length === 0 ) {
-                       $(this).after( '<label for="wpNewEmail" id="mw-emailaddress-validity"></label>' );
-               }
-               updateMailValidityLabel( $(this).val() );
-               $(this).keyup( function () {
-                       updateMailValidityLabel( $(this).val() );
+       $( document ).ready( function () {
+               // Lame tip to let user know if its email is valid. See bug 22449.
+               // Only bind once for 'blur' so that the user can fill it in without errors;
+               // after that, look at every keypress for immediate feedback.
+               $( '#wpNewEmail' ).one( 'blur', function () {
+                       var $this = $( this );
+                       if ( $( '#mw-emailaddress-validity' ).length === 0 ) {
+                               $this.after( '<label for="wpNewEmail" id="mw-emailaddress-validity"></label>' );
+                       }
+
+                       updateMailValidityLabel( $this.val() );
+                       $this.keyup( function () {
+                               updateMailValidityLabel( $this.val() );
+                       } );
                } );
        } );
-} );
-
 }( mediaWiki, jQuery ) );
index 7a55806..f719d07 100644 (file)
@@ -1,7 +1,6 @@
 /**
  * JavaScript for Special:MovePage
  */
-
-jQuery( function( $ ) {
+jQuery( document ).ready( function ( $ ) {
        $( '#wpReason, #wpNewTitleMain' ).byteLimit();
 } );
index d8d092b..46384a8 100644 (file)
@@ -1,4 +1,4 @@
-/*
+/**
  * JavaScript for Special:Preferences
  */
 jQuery( document ).ready( function ( $ ) {
@@ -8,20 +8,19 @@ jQuery( document ).ready( function ( $ ) {
 
        $( '#prefsubmit' ).attr( 'id', 'prefcontrol' );
 
-               $preftoc = $('<ul id="preftoc"></ul>'),
-               $preferences = $( '#preferences' )
-                       .addClass( 'jsprefs' )
-                       .before( $preftoc ),
-               $fieldsets = $preferences.children( 'fieldset' )
-                       .hide()
-                       .addClass( 'prefsection' ),
-               $legends = $fieldsets
-                       .children( 'legend' )
-                       .addClass( 'mainLegend' );
+       $preftoc = $('<ul id="preftoc"></ul>');
+       $preferences = $( '#preferences' )
+               .addClass( 'jsprefs' )
+               .before( $preftoc );
+       $fieldsets = $preferences.children( 'fieldset' )
+               .hide()
+               .addClass( 'prefsection' );
+       $legends = $fieldsets
+               .children( 'legend' )
+               .addClass( 'mainLegend' );
 
        /**
-        * It uses document.getElementById for security reasons (html injections in
-        * jQuery()).
+        * It uses document.getElementById for security reasons (HTML injections in $()).
         *
         * @param String name: the name of a tab without the prefix ("mw-prefsection-")
         * @param String mode: [optional] A hash will be set according to the current
index 3cba9d3..d1c1354 100644 (file)
@@ -2,19 +2,16 @@
  * JavaScript for Special:RecentChanges
  */
 ( function ( mw, $ ) {
-       var rc,
-               $checkboxes,
-               $select;
+       var rc, $checkboxes, $select;
 
        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.find( 'option:selected' ).val() === '';
+                       var isAllNS = $select.val() === '';
 
                        // Iterates over checkboxes and propagate the selected option
                        $checkboxes.prop( 'disabled', isAllNS );
@@ -30,7 +27,7 @@
                }
        };
 
-       $( rc.init );
+       $( document ).ready( rc.init );
 
        mw.special.recentchanges = rc;
 
index 0cca26d..2dab302 100644 (file)
@@ -1,8 +1,8 @@
-/*
+/**
  * JavaScript for Special:Search
  */
-( function ( $, mw ) {
-       $( function () {
+( function ( mw, $ ) {
+       $( document ).ready( function () {
                var $checkboxes, $headerLinks;
 
                // Emulate HTML5 autofocus behavior in non HTML5 compliant browsers
@@ -50,4 +50,4 @@
 
        } );
 
-}( jQuery, mediaWiki ) );
+}( mediaWiki, jQuery ) );
index c6e5d61..d20aab5 100644 (file)
@@ -1,11 +1,11 @@
-/*
- * JavaScript for Specical:Undelete
+/**
+ * JavaScript for Special:Undelete
  */
 jQuery( document ).ready( function ( $ ) {
        $( '#mw-undelete-invert' ).click( function ( e ) {
-               e.preventDefault();
                $( '#undelete input[type="checkbox"]' ).prop( 'checked', function ( i, val ) {
                        return !val;
                } );
+               e.preventDefault();
        } );
 } );
index b05fd71..75532f1 100644 (file)
@@ -6,7 +6,7 @@
        /**
         * Add a preview to the upload form
         */
-       $( function ( $ ) {
+       $( document ).ready( function () {
                /**
                 * Is the FileAPI available with sufficient functionality?
                 */
@@ -25,7 +25,7 @@
                 * @return boolean
                 */
                function fileIsPreviewable( file ) {
-                       var     known = ['image/png', 'image/gif', 'image/jpeg', 'image/svg+xml'],
+                       var known = ['image/png', 'image/gif', 'image/jpeg', 'image/svg+xml'],
                                tooHuge = 10 * 1024 * 1024;
                        return ( $.inArray( file.type, known ) !== -1 ) && file.size > 0 && file.size < tooHuge;
                }
@@ -62,7 +62,7 @@
                        $( '#mw-htmlform-source' ).parent().prepend( thumb );
 
                        fetchPreview( file, function ( dataURL ) {
-                               var     img = new Image(),
+                               var img = new Image(),
                                        rotation = 0;
 
                                if ( meta && meta.tiff && meta.tiff.Orientation ) {
        /**
         * Disable all upload source fields except the selected one
         */
-       $( function ( $ ) {
+       $( document ).ready( function () {
                var i, $row,
                        $rows = $( '.mw-htmlform-field-UploadSourceField' );