미디어위키:Gadget-Edittools.js
창팝위키
다른 명령
참고: 설정을 저장한 후에 바뀐 점을 확인하기 위해서는 브라우저의 캐시를 새로 고쳐야 합니다.
- 파이어폭스 / 사파리: Shift 키를 누르면서 새로 고침을 클릭하거나, Ctrl-F5 또는 Ctrl-R을 입력 (Mac에서는 ⌘-R)
- 구글 크롬: Ctrl-Shift-R키를 입력 (Mac에서는 ⌘-Shift-R)
- 엣지: Ctrl 키를 누르면서 새로 고침을 클릭하거나, Ctrl-F5를 입력.
/*
* 원본: https://www.mediawiki.org/wiki/MediaWiki:Gadget-Edittools.js
*/
console.log('EditTools 스크립트 시작');
(function (mw) {
"use strict";
var conf, editTools, sections;
conf = {
initialSubset: window.EditTools_initial_subset === undefined ? window.EditTools_initial_subset : 0
};
editTools = {
/**
* Creates the selector
*/
setup: function () {
var container, select, initial;
container = document.getElementById('mw-edittools-charinsert');
if (!container) {
return;
}
sections = container.querySelectorAll('.mw-edittools-section');
if (sections.length <= 1) {
// Only care if there is more than one
return;
}
// 감싸는 div 생성
var selectWrapper = document.createElement('div');
selectWrapper.classList.add('oo-ui-widget', 'oo-ui-widget-enabled', 'oo-ui-inputWidget', 'oo-ui-dropdownInputWidget');
select = document.createElement('select');
select.style.display = 'inline';
select.classList.add('oo-ui-inputWidget-input', 'oo-ui-indicator-down');
initial = conf.initialSubset;
if (isNaN(initial) || initial < 0 || initial >= sections.length) {
initial = 0;
}
sections.forEach(function (section, i) {
var sectionTitle, option;
sectionTitle = section.dataset.sectionTitle;
option = document.createElement('option');
option.textContent = sectionTitle;
option.value = i.toString();
option.selected = (i === initial);
select.appendChild(option);
});
select.addEventListener('change', editTools.handleOnchange);
// select 요소를 감싸는 div에 추가
selectWrapper.appendChild(select);
// 감싸는 div를 container에 prepend
container.prepend(selectWrapper);
editTools.chooseSection(initial);
},
/**
* Handle onchange event of the <select>
*
* @param {Event} e
*/
handleOnchange: function (e) {
editTools.chooseSection(Number(e.target.value));
return true;
},
/**
* Toggle the currently visible section
*
* @param {Number} sectionNum
*/
chooseSection: function (sectionNum) {
var choice = sections[sectionNum];
if (!choice) {
return;
}
choice.style.display = 'inline';
sections.forEach(function (section) {
if (section !== choice) {
section.style.display = 'none';
}
});
}
};
$(function() {
editTools.setup();
});
}(mediaWiki));