มีเดียวิกิ:Gadget-IndexFormTools.js

หมายเหตุ: หลังเผยแพร่ คุณอาจต้องล้างแคชเว็บเบราว์เซอร์ของคุณเพื่อดูการเปลี่ยนแปลง

  • ไฟร์ฟอกซ์ / ซาฟารี: กด Shift ค้างขณะคลิก Reload หรือกด Ctrl-F5 หรือ Ctrl-R (⌘-R บนแมค)
  • กูเกิล โครม: กด Ctrl-Shift-R (⌘-Shift-R บนแมค)
  • อินเทอร์เน็ตเอกซ์พลอเรอร์ และ Edge: กด Ctrl ค้างขณะคลิก Refresh หรือกด Ctrl-F5
  • โอเปร่า: กด Ctrl-F5
/*
 * Simple JS to provide some reactivity to the index page form
 *
 * Gadget originally from [[s:en:MediaWiki:Gadget-IndexFormTools.js]]
 */

/* 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-ความคืบหน้า' ).parent() );

		// eslint-disable-next-line no-jquery/no-global-selector
		var validDateWidget = OO.ui.infuse( $( '#wpprpindex-วันที่ตรวจสอบเนื้อหาเสร็จสมบูรณ์' ).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 = 'ไม่สามารถใส่วันที่ตรวจสอบเนื้อหาเสร็จก่อนการตรวจสอบเนื้อหาเสร็จสิ้น';
			} else {
				var now = new Date();
				// don't use wgMonthNames, the categories are fixed as Thai and uses Buddhist Era year
				var months = [ 'มกราคม', 'กุมภาพันธ์', 'มีนาคม', 'เมษายน', 'พฤษภาคม', 'มิถุนายน', 'กรกฎาคม', 'สิงหาคม', 'กันยายน', 'ตุลาคม', 'พฤศจิกายน', 'ธันวาคม' ];
				var BEyear = now.getFullYear() + 543;
				placeholder = months[ now.getMonth() ] + ' ' + BEyear;
			}

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

		function getCheckerUrl() {
			var pageName = mw.config.get( 'wgPageName' );
			return 'https://checker.toolforge.org/?db=thwikisource_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-การผสานหน้า', $( '<a>' )
			.attr( 'href', getCheckerUrl() )
			.attr( 'target', '_blank' )
			.append( 'ตรวจสอบการผสานหน้า' )
		);
	} );

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