Rillke has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/190648

Change subject: Special.upload.js: Avoid making functions within loops
......................................................................

Special.upload.js: Avoid making functions within loops

The old implementation used a dirty trick to fool JSHint; though there
is really no need to create a function for each single radio input.

Change-Id: I1e5c7c403efb26c74df39669491bc49602a9df4f
---
M resources/src/mediawiki.special/mediawiki.special.upload.js
1 file changed, 31 insertions(+), 24 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/48/190648/1

diff --git a/resources/src/mediawiki.special/mediawiki.special.upload.js 
b/resources/src/mediawiki.special/mediawiki.special.upload.js
index f405c7a..24705e3 100644
--- a/resources/src/mediawiki.special/mediawiki.special.upload.js
+++ b/resources/src/mediawiki.special/mediawiki.special.upload.js
@@ -531,32 +531,39 @@
 
        // Disable all upload source fields except the selected one
        $( function () {
-               var i, $row,
-                       $rows = $( '.mw-htmlform-field-UploadSourceField' );
+               var rowSelector = '.mw-htmlform-field-UploadSourceField',
+                       $rows = $( rowSelector ),
+                       $radios = $rows.find( 'input[type="radio"]' ),
+                       onRadioChange;
 
-               /**
-                * @param {jQuery} $currentRow
-                * @return {Function} Handler
-                * @return {jQuery.Event} return.e
-                */
-               function createHandler( $currentRow ) {
-                       return function () {
-                               $( '.mw-upload-source-error' ).remove();
-                               if ( this.checked ) {
-                                       // Disable all inputs
-                                       $rows.find( 
'input[name!="wpSourceType"]' ).prop( 'disabled', true );
-                                       // Re-enable the current one
-                                       $currentRow.find( 'input' ).prop( 
'disabled', false );
-                               }
-                       };
-               }
 
-               for ( i = $rows.length; i; i-- ) {
-                       $row = $rows.eq( i - 1 );
-                       $row
-                               .find( 'input[name="wpSourceType"]' )
-                               .change( createHandler( $row ) );
-               }
+               onRadioChange = function () {
+                       var $currentRowInputs;
+
+                       if ( !this.checked ) {
+                               return;
+                       }
+
+                       $( '.mw-upload-source-error' ).remove();
+
+                       // Enable selected upload method,
+                       // disable source inputs of alternative
+                       // upload methods
+                       $currentRowInputs = $( this )
+                               .closest( rowSelector )
+                               .find( 'input' )
+                               .prop( 'disabled', false );
+
+                       $rows
+                               .find( 'input' )
+                               .not( $radios )
+                               .not( $currentRowInputs )
+                               .prop( 'disabled', true );
+               };
+
+               $radios.on( {
+                       change: onRadioChange
+               } );
        } );
 
        $( function () {

-- 
To view, visit https://gerrit.wikimedia.org/r/190648
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I1e5c7c403efb26c74df39669491bc49602a9df4f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Rillke <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to