protect.js: Reorder function declararion to avoid forward reference
authorFomafix <fomafix@googlemail.com>
Tue, 2 Apr 2019 12:47:58 +0000 (14:47 +0200)
committerFomafix <fomafix@googlemail.com>
Tue, 2 Apr 2019 12:47:58 +0000 (14:47 +0200)
The ESLint rule exception no-use-before-define can removed.

Change-Id: Ib730102ae33f37ff95b001d689666f729885cd2d

resources/src/mediawiki.legacy/protect.js

index 18f1c38..01d6a65 100644 (file)
-/* eslint-disable no-use-before-define */
 ( function () {
        var config = require( './config.json' ),
                reasonCodePointLimit = mw.config.get( 'wgCommentCodePointLimit' ),
                reasonByteLimit = mw.config.get( 'wgCommentByteLimit' );
 
        /**
-        * Set up the protection chaining interface (i.e. "unlock move permissions" checkbox)
-        * on the protection form
+        * Get a list of all protection selectors on the page
         *
-        * @return {boolean}
-        */
-       function init() {
-               var $cell = $( '<td>' ),
-                       $row = $( '<tr>' ).append( $cell );
-
-               if ( !$( '#mwProtectSet' ).length ) {
-                       return false;
-               }
-
-               $( '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 );
-               } );
-
-               $( '#mwProtectSet > tbody > tr:first' ).after( $row );
-
-               // If there is only one protection type, there is nothing to chain
-               if ( $( '[id ^= mw-protect-table-]' ).length > 1 ) {
-                       $cell.append(
-                               $( '<input>' )
-                                       .attr( { id: 'mwProtectUnchained', type: 'checkbox' } )
-                                       .on( 'click', onChainClick )
-                                       .prop( 'checked', !areAllTypesMatching() ),
-                               document.createTextNode( ' ' ),
-                               $( '<label>' )
-                                       .attr( 'for', 'mwProtectUnchained' )
-                                       .text( mw.msg( 'protect-unchain-permissions' ) )
-                       );
-
-                       toggleUnchainedInputs( !areAllTypesMatching() );
-               }
-
-               // Arbitrary 75 to leave some space for the autogenerated null edit's summary
-               if ( reasonCodePointLimit ) {
-                       $( '#mwProtect-reason' ).codePointLimit( reasonCodePointLimit - 75 );
-               } else if ( reasonByteLimit ) {
-                       $( '#mwProtect-reason' ).byteLimit( reasonByteLimit - 75 );
-               }
-
-               updateCascadeCheckbox();
-               return true;
-       }
-
-       /**
-        * Sets the disabled attribute on the cascade checkbox depending on the current selected levels
+        * @return {jQuery}
         */
-       function updateCascadeCheckbox() {
-               getLevelSelectors().each( function () {
-                       if ( !isCascadeableLevel( $( this ).val() ) ) {
-                               $( '#mwProtect-cascade' ).prop( { checked: false, disabled: true } );
-                               return false;
-                       } else {
-                               $( '#mwProtect-cascade' ).prop( 'disabled', false );
-                       }
-               } );
+       function getLevelSelectors() {
+               return $( 'select[id ^= mwProtect-level-]' );
        }
 
        /**
-        * Checks if a certain protection level is cascadeable.
+        * Get a list of all expiry inputs on the page
         *
-        * @param {string} level
-        * @return {boolean}
+        * @return {jQuery}
         */
-       function isCascadeableLevel( level ) {
-               return config.CascadingRestrictionLevels.indexOf( level ) !== -1;
+       function getExpiryInputs() {
+               return $( 'input[id ^= mwProtect-][id $= -expires]' );
        }
 
        /**
-        * When protection levels are locked together, update the rest
-        * when one action's level changes
+        * Get a list of all expiry selector lists on the page
         *
-        * @param {Event} event Level selector that changed
+        * @return {jQuery}
         */
-       function updateLevels( event ) {
-               if ( !isUnchained() ) {
-                       setAllSelectors( event.target.selectedIndex );
-               }
-               updateCascadeCheckbox();
+       function getExpirySelectors() {
+               return $( 'select[id ^= mwProtectExpirySelection-]' );
        }
 
        /**
-        * When protection levels are locked together, update the
-        * expiries when one changes
+        * Enable/disable protection selectors and expiry inputs
         *
-        * @param {Event} event Expiry input that changed
+        * @param {boolean} val Enable?
         */
-
-       function updateExpiry( event ) {
-               if ( !isUnchained() ) {
-                       getExpiryInputs().each( function () {
-                               this.value = event.target.value;
-                       } );
-               }
-               if ( isUnchained() ) {
-                       $( '#' + event.target.id.replace( /^mwProtect-(\w+)-expires$/, 'mwProtectExpirySelection-$1' ) ).val( 'othertime' );
-               } else {
-                       getExpirySelectors().each( function () {
-                               this.value = 'othertime';
-                       } );
-               }
+       function toggleUnchainedInputs( val ) {
+               var setDisabled = function () {
+                       this.disabled = !val;
+               };
+               getLevelSelectors().slice( 1 ).each( setDisabled );
+               getExpiryInputs().slice( 1 ).each( setDisabled );
+               getExpirySelectors().slice( 1 ).each( setDisabled );
        }
 
        /**
-        * When protection levels are locked together, update the
-        * expiry lists when one changes and clear the custom inputs
+        * Checks if a certain protection level is cascadeable.
         *
-        * @param {Event} event Expiry selector that changed
+        * @param {string} level
+        * @return {boolean}
         */
-       function updateExpiryList( event ) {
-               if ( !isUnchained() ) {
-                       getExpirySelectors().each( function () {
-                               this.value = event.target.value;
-                       } );
-                       getExpiryInputs().each( function () {
-                               this.value = '';
-                       } );
-               }
+       function isCascadeableLevel( level ) {
+               return config.CascadingRestrictionLevels.indexOf( level ) !== -1;
        }
 
        /**
-        * Update chain status and enable/disable various bits of the UI
-        * when the user changes the "unlock move permissions" checkbox
+        * Sets the disabled attribute on the cascade checkbox depending on the current selected levels
         */
-       function onChainClick() {
-               toggleUnchainedInputs( isUnchained() );
-               if ( !isUnchained() ) {
-                       setAllSelectors( getMaxLevel() );
-               }
-               updateCascadeCheckbox();
+       function updateCascadeCheckbox() {
+               getLevelSelectors().each( function () {
+                       if ( !isCascadeableLevel( $( this ).val() ) ) {
+                               $( '#mwProtect-cascade' ).prop( { checked: false, disabled: true } );
+                               return false;
+                       } else {
+                               $( '#mwProtect-cascade' ).prop( 'disabled', false );
+                       }
+               } );
        }
 
        /**
        }
 
        /**
-        * Get a list of all protection selectors on the page
+        * When protection levels are locked together, update the rest
+        * when one action's level changes
         *
-        * @return {jQuery}
+        * @param {Event} event Level selector that changed
         */
-       function getLevelSelectors() {
-               return $( 'select[id ^= mwProtect-level-]' );
+       function updateLevels( event ) {
+               if ( !isUnchained() ) {
+                       setAllSelectors( event.target.selectedIndex );
+               }
+               updateCascadeCheckbox();
        }
 
        /**
-        * Get a list of all expiry inputs on the page
+        * When protection levels are locked together, update the
+        * expiries when one changes
         *
-        * @return {jQuery}
+        * @param {Event} event Expiry input that changed
         */
-       function getExpiryInputs() {
-               return $( 'input[id ^= mwProtect-][id $= -expires]' );
+
+       function updateExpiry( event ) {
+               if ( !isUnchained() ) {
+                       getExpiryInputs().each( function () {
+                               this.value = event.target.value;
+                       } );
+               }
+               if ( isUnchained() ) {
+                       $( '#' + event.target.id.replace( /^mwProtect-(\w+)-expires$/, 'mwProtectExpirySelection-$1' ) ).val( 'othertime' );
+               } else {
+                       getExpirySelectors().each( function () {
+                               this.value = 'othertime';
+                       } );
+               }
        }
 
        /**
-        * Get a list of all expiry selector lists on the page
+        * When protection levels are locked together, update the
+        * expiry lists when one changes and clear the custom inputs
         *
-        * @return {jQuery}
+        * @param {Event} event Expiry selector that changed
         */
-       function getExpirySelectors() {
-               return $( 'select[id ^= mwProtectExpirySelection-]' );
+       function updateExpiryList( event ) {
+               if ( !isUnchained() ) {
+                       getExpirySelectors().each( function () {
+                               this.value = event.target.value;
+                       } );
+                       getExpiryInputs().each( function () {
+                               this.value = '';
+                       } );
+               }
        }
 
        /**
-        * Enable/disable protection selectors and expiry inputs
+        * Update chain status and enable/disable various bits of the UI
+        * when the user changes the "unlock move permissions" checkbox
+        */
+       function onChainClick() {
+               toggleUnchainedInputs( isUnchained() );
+               if ( !isUnchained() ) {
+                       setAllSelectors( getMaxLevel() );
+               }
+               updateCascadeCheckbox();
+       }
+
+       /**
+        * Set up the protection chaining interface (i.e. "unlock move permissions" checkbox)
+        * on the protection form
         *
-        * @param {boolean} val Enable?
+        * @return {boolean}
         */
-       function toggleUnchainedInputs( val ) {
-               var setDisabled = function () {
-                       this.disabled = !val;
-               };
-               getLevelSelectors().slice( 1 ).each( setDisabled );
-               getExpiryInputs().slice( 1 ).each( setDisabled );
-               getExpirySelectors().slice( 1 ).each( setDisabled );
+       function init() {
+               var $cell = $( '<td>' ),
+                       $row = $( '<tr>' ).append( $cell );
+
+               if ( !$( '#mwProtectSet' ).length ) {
+                       return false;
+               }
+
+               $( '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 );
+               } );
+
+               $( '#mwProtectSet > tbody > tr:first' ).after( $row );
+
+               // If there is only one protection type, there is nothing to chain
+               if ( $( '[id ^= mw-protect-table-]' ).length > 1 ) {
+                       $cell.append(
+                               $( '<input>' )
+                                       .attr( { id: 'mwProtectUnchained', type: 'checkbox' } )
+                                       .on( 'click', onChainClick )
+                                       .prop( 'checked', !areAllTypesMatching() ),
+                               document.createTextNode( ' ' ),
+                               $( '<label>' )
+                                       .attr( 'for', 'mwProtectUnchained' )
+                                       .text( mw.msg( 'protect-unchain-permissions' ) )
+                       );
+
+                       toggleUnchainedInputs( !areAllTypesMatching() );
+               }
+
+               // Arbitrary 75 to leave some space for the autogenerated null edit's summary
+               if ( reasonCodePointLimit ) {
+                       $( '#mwProtect-reason' ).codePointLimit( reasonCodePointLimit - 75 );
+               } else if ( reasonByteLimit ) {
+                       $( '#mwProtect-reason' ).byteLimit( reasonByteLimit - 75 );
+               }
+
+               updateCascadeCheckbox();
+               return true;
        }
 
        $( init );