사용자:Wikiwater2020/defaultsummaries.js

위키백과, 우리 모두의 백과사전.

참고: 설정을 저장한 후에 바뀐 점을 확인하기 위해서는 브라우저의 캐시를 새로 고쳐야 합니다. 구글 크롬, 파이어폭스, 마이크로소프트 엣지, 사파리: ⇧ Shift 키를 누른 채 "새로 고침" 버튼을 클릭하십시오. 더 자세한 정보를 보려면 위키백과:캐시 무시하기 항목을 참고하십시오.

/*  _____________________________________________________________________________
 * |                                                                             |
 * |                    === WARNING: GLOBAL GADGET FILE ===                      |
 * |                  Changes to this page affect many users.                    |
 * | Please discuss changes on the talk page or on [[WT:Gadget]] before editing. |
 * |_____________________________________________________________________________|
 *
 * 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 mw, ve */

/* eslint-disable no-jquery/no-global-selector */

( function () { // Wrap with anonymous function
	var $summaryBox = $( '#wpSummary' ),
		minorSummaries = [
			'철자/문법/오타 수정',
			'스타일/레이아웃 오류 수정',
			'[[위키백과:문서 훼손|문서 훼손]] 또는 시험 편집을 [[도움말:되돌리기|되돌림]]',
			'설명되지 않은 내용 제거를 [[도움말:되돌리기|되돌림]]',
			'교열 (사소함)'
		],
		articleSummaries = [
			'내용 확장',
			'각주 추가/개선',
			'위키링크 추가/제거',
			'교열/정리',
			'분류 추가/제거',
			'외부 링크 추가/제거',
			'출처 없는 내용 삭제'
		],
		nonArticleSummaries = [
			'답장',
			'댓글',
			'의견'
		],
		talkPageSummaries = [
			'[[위키백과:위키프로젝트|위키프로젝트]] 태그',
			'[[위키백과:위키프로젝트|위키프로젝트]] 평가'
		];

	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 getSummaryDropdowns() {
		// 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: '일반적인 편집 요약 – 클릭해서 사용'
			} ),
			minorDropdown = new OO.ui.DropdownWidget( {
				label: '일반적인 사소한 편집 요약 – 클릭해서 사용'
			} );

		dropdown.menu.on( 'select', onSummarySelect );
		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 );
			}
		}
		return dropdown.$element.add( minorDropdown.$element );
	}
	// VisualEditor
	mw.hook( 've.saveDialog.stateChanged' ).add( function () {
		var target, $saveOptions, $dropdowns;
		// .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;
		}
		$dropdowns = getSummaryDropdowns();
		$saveOptions.before( $dropdowns );
	} );
	// WikiEditor
	$.when( mw.loader.using( 'oojs-ui-core' ), $.ready ).then( function () {
		var $dropdowns,
			$editCheckboxes = $( '.editCheckboxes' );

		// If we failed to find the editCheckboxes class
		if ( !$editCheckboxes.length ) {
			return;
		}
		$dropdowns = getSummaryDropdowns();
		$dropdowns.css( {
			width: '48%',
			'padding-bottom': '1em'
		} );
		$editCheckboxes.before( $dropdowns );
	} );
}() );