MediaWiki:Gadget-defaultsummaries.js

/* Imported as of 09/06/2011 from [[User:ErrantX/defaultsummaries.js]]
 * Edited version from [[User:MC10/defaultsummaries.js]]
 * Implements default edit summary dropdown boxes
 */

/* global mediaWiki, ve */

( function ( $, mw ) { // Wrap with anonymous function
	var $summaryBox = $( '#wpSummary' ),
		minorSummaries = [
			'Sửa chính tả/ngữ pháp',
			'Sửa lỗi trình bày/bố cục',
			'[[Wikipedia:Hồi sửa|Lùi lại]] các sửa đổi [[Wikipedia:Phá hoại|phá hoại]] hoặc thử nghiệm',
			'[[Wikipedia:Hồi sửa|Phục hồi]] nội dung bị loại bỏ không giải thích lý do',
			'Biên tập trang (nhỏ)'
		],
		articleSummaries = [
			'Mở rộng bài viết',
			'Thêm/cải thiện nguồn tham khảo',
			'Thêm/bỏ thể loại',
			'Thêm/bỏ liên kết ngoài',
			'Thêm/bỏ liên kết (trong) wiki',
			'Bỏ nội dung không nguồn gốc',
			'Bỏ [[WP:SPAM|liên kết spam]] theo [[WP:LKN]]',
			'Dọn dẹp',
			'Biên tập trang (lớn)'
		],
		nonArticleSummaries = [
			'Phản hồi',
			'Bình luận',
			'Đề xuất'
		],
		talkPageSummaries = [
			'Thêm thẻ [[Wikipedia:Dự án|dự án Wikipedia]]',
			'Đánh giá [[Wikipedia:Dự án|dự án Wikipedia]]'
		];

	function addOptionsToDropdown( dropdown, optionTexts ) {
		dropdown.menu.addItems( optionTexts.map( function ( optionText ) {
			return new OO.ui.MenuOptionWidget( { label: optionText } );
		} ) );
	}

	function onSummarySelect( option ) {
		// Save the original value of the edit summary field
		var editsummOriginalSummary = $summaryBox.val(),
			canned = option.getLabel(),
			newSummary = editsummOriginalSummary;

		// Append old edit summary with space, if exists,
		// and last character != space
		if ( newSummary.length !== 0 && newSummary.charAt( newSummary.length - 1 ) !== ' ' ) {
			newSummary += ' ';
		}
		newSummary += canned;
		$summaryBox.val( newSummary ).trigger( 'change' );
	}

	function insertSummaryOptions( $insertBeforeThis, dropdownWidth ) {
		// For convenience, add a dropdown box with some canned edit
		// summaries to the form.
		var namespace = mw.config.get( 'wgNamespaceNumber' ),
			dropdown = new OO.ui.DropdownWidget( {
				label: 'Tóm lược sửa đổi chung – nhấp để dùng'
			} ),
			minorDropdown = new OO.ui.DropdownWidget( {
				label: 'Tóm lược sửa đổi nhỏ chung – nhấp để dùng'
			} );

		dropdown.$element.css( 'width', dropdownWidth );
		dropdown.menu.on( 'select', onSummarySelect );

		minorDropdown.$element.css( 'width', dropdownWidth );
		minorDropdown.menu.on( 'select', onSummarySelect );

		addOptionsToDropdown( minorDropdown, minorSummaries );

		if ( namespace === 0 ) {
			addOptionsToDropdown( dropdown, articleSummaries );
		} else {
			addOptionsToDropdown( dropdown, nonArticleSummaries );
			if ( namespace % 2 !== 0 && namespace !== 3 ) {
				addOptionsToDropdown( dropdown, talkPageSummaries );
			}
		}

		$insertBeforeThis.before( dropdown.$element );
		$insertBeforeThis.before( minorDropdown.$element );
	}
	// VisualEditor
	mw.hook( 've.saveDialog.stateChanged' ).add( function () {
		var target, $saveOptions;
		// .ve-init-mw-viewPageTarget-saveDialog-checkboxes
		if ( $( 'body' ).data( 'wppresent' ) ) { return; }
		$( 'body' ).data( 'wppresent', 'true' );

		target = ve.init.target;
		$saveOptions = target.saveDialog.$saveOptions;
		$summaryBox = target.saveDialog.editSummaryInput.$input;
		if ( !$saveOptions.length ) {
			return;
		}
		insertSummaryOptions( $saveOptions );
	} );
	// WikiEditor
	$.when( mw.loader.using( 'oojs-ui-core' ), $.ready ).then( function () {
		var $editCheckboxes = $( '.editCheckboxes' );

		// If we failed to find the editCheckboxes class
		if ( !$editCheckboxes.length ) {
			return;
		}
		insertSummaryOptions( $editCheckboxes, '48%' );
	} );
}( jQuery, mediaWiki ) ); // End wrap with anonymous function
Chúng tôi bán
Bài viết liên quan
Rối loạn nhân cách ranh giới (Borderline Personality Disorder)
Rối loạn nhân cách ranh giới (Borderline Personality Disorder)
BPD là một loại rối loạn nhân cách về cảm xúc và hành vi mà ở đó, chủ thể có sự cực đoan về cảm xúc, thường xuyên sợ hãi với những nỗi sợ của sự cô đơn, phản bội
[Preview] Koigoku No Toshi – Thành phố chúng ta đang sống là giả?
[Preview] Koigoku No Toshi – Thành phố chúng ta đang sống là giả?
Makoto, một thanh niên đã crush Ai- cô bạn thời thơ ấu của mình tận 10 năm trời, bám theo cô lên tận đại học mà vẫn chưa có cơ hội tỏ tình
Nhân vật CZ2128 Delta - Overlord
Nhân vật CZ2128 Delta - Overlord
CZ2128 Delta (シ ー ゼ ッ ト ニ イ チ ニ ハ チ ・ デ ル タ / CZ2128 ・ Δ) AKA "CZ" là một người hầu chiến đấu tự động và là thành viên của "Pleiades Six Stars", đội chiến hầu của Great Tomb of Nazarick. Cô ấy được tạo ra bởi Garnet.
Haruka Hasebe - Classroom of the Elite
Haruka Hasebe - Classroom of the Elite
Haruka Hasebe (長は谷せ部べ 波は瑠る加か, Hasebe Haruka) là một trong những học sinh của Lớp 1-D.