MediaWiki:Gadget-IndexFormTools.js

/* * Simple JS to provide some reactivity to the index page form */

/* eslint-disable one-var, vars-on-top */

( function ( mw, $ ) {

// only in edit of Index NS	if ( mw.config.get( 'wgCanonicalNamespace' ) !== 'Index' ||			[ 'edit', 'submit' ].indexOf( mw.config.get( 'wgAction' ) ) === -1 ) { return; }

$( function {

// eslint-disable-next-line no-jquery/no-global-selector var progWidget = OO.ui.infuse( $( '#wpprpindex-Progress' ).parent );

// eslint-disable-next-line no-jquery/no-global-selector var validDateWidget = OO.ui.infuse( $( '#wpprpindex-Validation_date' ).parent );

function isValidated { return progWidget.getValue === 'T'; }

/**		 * Update the status of the validated date widget */		function updateValidDate { var canSetDate = isValidated;

validDateWidget.setDisabled( !canSetDate );

var placeholder; if ( !canSetDate ) { placeholder = 'Validation date cannot be set before the work is validated.'; } else { var now = new Date; // don't use wgMonthNames, the categories are fixed as English var months = [ 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' ]; placeholder = months[ now.getMonth ] + ' ' + now.getFullYear; }

validDateWidget.$input.attr( 'placeholder', placeholder ); }

function getCheckerUrl { var pageName = mw.config.get( 'wgPageName' ); return 'https://checker.toolforge.org/?db=enwikisource_p&title=' + pageName; }

function addLinkToFieldLabel( id, link ) { $( id ) .closest( '.oo-ui-fieldLayout-body' ) .find( 'label' ) .append( link					.css( { 'font-size': '92%', float: 'right' } )				); }

updateValidDate;

progWidget.on( 'change', function {			updateValidDate;		} );

addLinkToFieldLabel( '#wpprpindex-Transclusion', $( '' )			.attr( 'href', getCheckerUrl )			.attr( 'target', '_blank' )			.append( 'Check transclusion' )		); } );

// eslint-disable-next-line no-undef }( mediaWiki, jQuery ) );