사용자:Wikisaft/common.js: 두 판 사이의 차이

편집 요약 없음
편집 요약 없음
1번째 줄: 1번째 줄:
/* 한국어 위키백과 미디어위키:Gadget-editsummary.js 호출 */
/***
* 편집요약 상용구
*
* 설명:
*  편집 요약 입력란 아래에, 클릭하면 요약에 정해진 문구를 입력하는 버튼을 추가
*
* 환경설정용 변수:
* window.esSummaries: object, 추가될 버튼 혹은 텍스트
***/


// 주 함수: 페이지 로드 완료 시 버튼 생성
function esEditSummary() {
function esEditSummary() {
if (typeof esEditSummaries === 'undefined') return;
var editform = document.getElementById('editform');
var wgAction = mw.config.get('wgAction');
if (wgAction == 'edit' || wgAction == 'submit') {
// 편집 화면(미리보기 포함)이면서 새 주제 덧붙이기가 아닌 경우
var wpSummary = document.getElementById('wpSummary');
// (#wpSummary가 제목으로 사용되는 경우)에만 동작
if (!wpSummary || (wpSummary.form.wpSection && wpSummary.form.wpSection.value == 'new')) return;
// 요약창이 없는 경우에는 미동작
wpSummaryButtons = document.createElement('span');
if (($.inArray( mw.config.get('wgAction'), ['edit', 'submit']) !== -1 && editform && editform.wpSection) &&
wpSummaryButtons.id = 'esSummaryButtons';
editform.wpSection.value !== 'new' && $('#wpSummary').length !== 0) {
wpSummary.parentNode.insertBefore(wpSummaryButtons, wpSummary.nextSibling);
// esCanBeMinor: esInsSummary 함수에서 사용
for (var i = 0; i < esEditSummaries.length; i++) esAppendButton(i);
window.esCanBeMinor = 1;
// 레거시
if (typeof window.esSummaries === 'undefined' && typeof esEditSummaries === 'object') {
window.esSummaries = esEditSummaries;
}
// 컨테이너
$('#wpSummaryLabel').after($('<div></div>').attr('id', 'esBtns'));
// 레이블 추가
var label = $('<span></span>');
label.addClass('esLabel');
label.text('편집요약 상용구: ');
$("#esBtns").prepend(label);
$("#esBtns").append($('<br>'));
// 요약 비우기 버튼 추가
var clrBtn = $("<span></span>").attr('title', '편집 요약 비우기');
clrBtn.addClass('esClrBtn');
clrBtn.text('');
clrBtn.click(function () {
$('#wpMinoredit').prop('checked', mw.user.options.get('minordefault'));
$('#wpSummary')[0].value = '';
window.esCanBeMinor = 1;
});
$("#esBtns").append(clrBtn);
// 설정 배열의 각 요소에 대해 버튼 추가 함수 실행
for (var id in window.esSummaries) {
esAppendBtn(id);
}
}
}
}
}


function esAppendButton(id) { // 버튼 추가하는 함수
// 버튼 추가 함수
var btn = document.createElement('esSummaryButton');
function esAppendBtn(id) {
btn.appendChild(document.createTextNode(esEditSummaries[id][0]));
if (typeof window.esSummaries[id] === 'object') {
btn.title = esEditSummaries[id][2];
var btn = $("<span></span>").attr({
        btn.style.fontSize = "1em" // 스타일 지정
'class': 'esBtn',
btn.onclick = function() {esInsertSummary(esEditSummaries[id][1], esEditSummaries[id][3], esEditSummaries[id][4])};
'title': window.esSummaries[id][2]});
wpSummaryButtons.appendChild(btn);
btn.text(window.esSummaries[id][0]);
btn.click(function () {esInsSummary(window.esSummaries[id][1],
window.esSummaries[id][3], window.esSummaries[id][4])});
$("#esBtns").append(btn);
}
// 줄바꿈 및 소제목
else if (typeof window.esSummaries[id] === 'string') {
if (window.esSummaries[id] === 'br') {
$('#esBtns').append($('<br>'));
}
else {
var sTitle = $("<span></span>").attr({
'class': 'esSTitle'});
sTitle.text(window.esSummaries[id]);
$('#esBtns').append(sTitle);
}
}
}
}


function esInsertSummary(text, isMinor, clear) {
// 편집 요약 수정 함수: 버튼이 눌리면 동작
var wpSummary = document.getElementById('wpSummary');
function esInsSummary(text, isMinor, clear) {
if (isMinor !== undefined) { $('#wpMinoredit').prop('checked', isMinor, clear); }
var wpSummary = $('#wpSummary')[0];
if (clear == 1) {
// 사소한 편집 여부 체크박스 조작
wpSummary.value = text;
if (typeof isMinor !== 'undefined') {
return;
// 사소한 편집이 명시적으로 아닌 요약이 한 번이라도 추가되면
// 다른 요약 버튼에 의해 사소한 편집이 체크되지 않음
if (isMinor === 0 ) window.esCanBeMinor = 0;
$('#wpMinoredit').prop('checked', (window.esCanBeMinor && isMinor));
}
if (typeof clear === 'undefined') clear = 0;
// 요약 비우기
if (clear) wpSummary.value = text;
// 요약 덧붙이기
else if (wpSummary.value.indexOf(text) === -1) {
if (wpSummary.value.match(/[^,; \/]$/)) wpSummary.value += ', ';
wpSummary.value = wpSummary.value.replace(/\s+$/, " ") + text;
}
}
if (wpSummary.value.indexOf(text) != -1) return ;
if (wpSummary.value.match(/[^,; \/]$/)) wpSummary.value += ',';
if (wpSummary.value.match(/[^ ]$/)) wpSummary.value += ' ';
wpSummary.value += text;
}
}



2022년 7월 21일 (목) 16:35 판

/***
 * 편집요약 상용구
 * 
 * 설명:
 *  편집 요약 입력란 아래에, 클릭하면 요약에 정해진 문구를 입력하는 버튼을 추가
 * 
 * 환경설정용 변수:
 *	window.esSummaries: object, 추가될 버튼 혹은 텍스트
 ***/

// 주 함수: 페이지 로드 완료 시 버튼 생성 
function esEditSummary() {
	var editform = document.getElementById('editform');
	
	// 편집 화면(미리보기 포함)이면서 새 주제 덧붙이기가 아닌 경우
	// (#wpSummary가 제목으로 사용되는 경우)에만 동작
	// 요약창이 없는 경우에는 미동작
	if (($.inArray( mw.config.get('wgAction'), ['edit', 'submit']) !== -1 && editform && editform.wpSection) &&
		editform.wpSection.value !== 'new' && $('#wpSummary').length !== 0) {
		// esCanBeMinor: esInsSummary 함수에서 사용
		window.esCanBeMinor = 1;
		
		// 레거시
		if (typeof window.esSummaries === 'undefined' && typeof esEditSummaries === 'object') {
			window.esSummaries = esEditSummaries;
		}
		
		// 컨테이너
		$('#wpSummaryLabel').after($('<div></div>').attr('id', 'esBtns'));
		
		// 레이블 추가
		var label = $('<span></span>');
		label.addClass('esLabel');
		label.text('편집요약 상용구: ');
		$("#esBtns").prepend(label);
		$("#esBtns").append($('<br>'));
		
		// 요약 비우기 버튼 추가
		var clrBtn = $("<span></span>").attr('title', '편집 요약 비우기');
		clrBtn.addClass('esClrBtn');
		clrBtn.text('❌');
		clrBtn.click(function () {
			$('#wpMinoredit').prop('checked', mw.user.options.get('minordefault'));
			$('#wpSummary')[0].value = '';
			window.esCanBeMinor = 1;
		});
		$("#esBtns").append(clrBtn);
		
		// 설정 배열의 각 요소에 대해 버튼 추가 함수 실행
		for (var id in window.esSummaries) {
			esAppendBtn(id);
		}
	}
}

// 버튼 추가 함수
function esAppendBtn(id) {
	if (typeof window.esSummaries[id] === 'object') {
		var btn = $("<span></span>").attr({
			'class': 'esBtn',
			'title': window.esSummaries[id][2]});
		btn.text(window.esSummaries[id][0]);
		btn.click(function () {esInsSummary(window.esSummaries[id][1],
			 window.esSummaries[id][3], window.esSummaries[id][4])});
		$("#esBtns").append(btn);
	}
	// 줄바꿈 및 소제목
	else if (typeof window.esSummaries[id] === 'string') {
		if (window.esSummaries[id] === 'br') {
			$('#esBtns').append($('<br>'));
		}
		else {
		var sTitle = $("<span></span>").attr({
			'class': 'esSTitle'});
		sTitle.text(window.esSummaries[id]);
		$('#esBtns').append(sTitle);
		}
	}
}

// 편집 요약 수정 함수: 버튼이 눌리면 동작
function esInsSummary(text, isMinor, clear) {
	var wpSummary = $('#wpSummary')[0];
	// 사소한 편집 여부 체크박스 조작
	if (typeof isMinor !== 'undefined') {
		// 사소한 편집이 명시적으로 아닌 요약이 한 번이라도 추가되면
		// 다른 요약 버튼에 의해 사소한 편집이 체크되지 않음
		if (isMinor === 0 ) window.esCanBeMinor = 0;
		$('#wpMinoredit').prop('checked', (window.esCanBeMinor && isMinor));
	}
	
	if (typeof clear === 'undefined') clear = 0;
	
	// 요약 비우기
	if (clear) wpSummary.value = text;
	// 요약 덧붙이기
	else if (wpSummary.value.indexOf(text) === -1) {
		if (wpSummary.value.match(/[^,; \/]$/)) wpSummary.value += ', ';
		wpSummary.value = wpSummary.value.replace(/\s+$/, " ") + text;
	}
}

jQuery( document ).ready(esEditSummary);

esEditSummaries = new Array(

/*
['버튼 이름', '입력될 편집 요약', '툴팁으로 뜨는 설명(생략 가능)', '사소한 편집 여부(0/1 혹은 true/false, 생략 가능)', '상용구 넣기 전에 요약 지우기(0/1 혹은 true/false, 생략 가능)']
위와 같은 형식으로 새로운 버튼을 추가할 수 있습니다.
마지막 줄을 제외한 줄 끝에 쉼표가 들어가 있는지 확인해 주세요.
*/
    ['갱신', '문서 정보를 새로 고침', '오래된 문서 정보를 갱신함', 0, 1],
    ['넘겨주기', '넘겨주기 생성', '넘겨주기 생성', 1, 1],
    ['동음', '동음이의어 문서 작성', '동음이의 문서를 작성', 0, 1],
    ['분류', '문서 분류 재조정', '분류 추가 삭제 및 정리', 1, 1],
    ['삭제신청', '문서 삭제 신청', '삭제 신청 틀을 담', 1, 1],
    ['오타','문서 내의 오타 수정','문서에서 오타를 정정함', 1, 1],
    ['답변', '의견에 답변함', '질문이나 의견에 답변을 함', 1,0],
    ['분할', '문단을 새 문서로 분할 - ', '다른 문서와의 병합을 제안하거나 실행함', 0, 1],
    ['내용추가', '문서의 내용 추가', '다른 문서에서 내용 추가', 0, 1 ]
);