protect.js: Simplify by using jQuery
authorFomafix <fomafix@googlemail.com>
Wed, 3 Apr 2019 04:23:34 +0000 (06:23 +0200)
committerFomafix <fomafix@googlemail.com>
Wed, 3 Apr 2019 04:32:52 +0000 (06:32 +0200)
Also remove useless boolean return.

Change-Id: I5a1ee977c2e7548bab98f8a7b6731262d175db51

resources/src/mediawiki.legacy/protect.js

index 01d6a65..9a3e050 100644 (file)
         * @param {number} index Protection level
         */
        function setAllSelectors( index ) {
-               getLevelSelectors().each( function () {
-                       this.selectedIndex = index;
-               } );
+               getLevelSelectors().prop( 'selectedIndex', index );
        }
 
        /**
         *
         * @param {Event} event Expiry input that changed
         */
-
        function updateExpiry( event ) {
                if ( !isUnchained() ) {
-                       getExpiryInputs().each( function () {
-                               this.value = event.target.value;
-                       } );
+                       getExpiryInputs().val( event.target.value );
                }
                if ( isUnchained() ) {
                        $( '#' + event.target.id.replace( /^mwProtect-(\w+)-expires$/, 'mwProtectExpirySelection-$1' ) ).val( 'othertime' );
                } else {
-                       getExpirySelectors().each( function () {
-                               this.value = 'othertime';
-                       } );
+                       getExpirySelectors().val( 'othertime' );
                }
        }
 
         */
        function updateExpiryList( event ) {
                if ( !isUnchained() ) {
-                       getExpirySelectors().each( function () {
-                               this.value = event.target.value;
-                       } );
-                       getExpiryInputs().each( function () {
-                               this.value = '';
-                       } );
+                       getExpirySelectors().val( event.target.value );
+                       getExpiryInputs().val( '' );
                }
        }
 
        /**
         * Set up the protection chaining interface (i.e. "unlock move permissions" checkbox)
         * on the protection form
-        *
-        * @return {boolean}
         */
        function init() {
                var $cell = $( '<td>' ),
                        $row = $( '<tr>' ).append( $cell );
 
                if ( !$( '#mwProtectSet' ).length ) {
-                       return false;
+                       return;
                }
 
                $( 'form#mw-Protect-Form' ).on( 'submit', toggleUnchainedInputs.bind( this, true ) );
-               getExpirySelectors().each( function () {
-                       $( this ).on( 'change', updateExpiryList );
-               } );
-               getExpiryInputs().each( function () {
-                       $( this ).on( 'keyup change', updateExpiry );
-               } );
-               getLevelSelectors().each( function () {
-                       $( this ).on( 'change', updateLevels );
-               } );
+               getExpirySelectors().on( 'change', updateExpiryList );
+               getExpiryInputs().on( 'keyup change', updateExpiry );
+               getLevelSelectors().on( 'change', updateLevels );
 
                $( '#mwProtectSet > tbody > tr:first' ).after( $row );
 
                }
 
                updateCascadeCheckbox();
-               return true;
        }
 
        $( init );