편집 전 과거 문서의 위키텍스트 (old_wikitext) | 'class EditToolsBox {
/**
*
* @param {{}} data
*/
constructor(data) {
/** @type {Array<HTMLDivElement>} */
const SubsetBoxes = [];
data = window.charinsert = Object.assign(data, window.charinsertCustom);
const specialchars_box = $('<div id="editpage-specialchars" class="nopopups"></div>');
specialchars_box[0].title = '편집 창에 입력할 글자 혹은 태그를 클릭하세요';
// 문자셋 드랍다운 메뉴를 만듭니다.
const options = [];
for (const i in data) {
options.push(new OO.ui.MenuOptionWidget({ label: i, data: data[i] }));
}
/**
* @type {OO.ui.DropdownWidget}
*/
const DropdownWidget = new OO.ui.DropdownWidget();
DropdownWidget.setLabel('Choose character subset');
const DropdownMenu = DropdownWidget.getMenu();
DropdownMenu.addItems(options)
DropdownMenu.on('choose', (seletedItem) => {
let seletedIndex = DropdownMenu.getItemIndex(seletedItem);
if (SubsetBoxes.length === 0 || !SubsetBoxes[seletedIndex]) {
const box = this.makeSubsetBox(seletedItem.getData());
if (box != null) {
specialchars_box.append(box.$element)
SubsetBoxes[seletedIndex] = box.$element[0];
}
}
SubsetBoxes.forEach(e => { e.style.display = 'none' })
SubsetBoxes[seletedIndex].style.display = 'inline';
});
DropdownMenu.chooseItem(options[0]);
// Find the element that is focused
this.$currentFocused = $('#wpTextbox1');
// Apply to dynamically created textboxes as well as normal ones
$(document).on('focus', 'textarea, input:text', () => this.$currentFocused = $(this));
$(".wikiEditor-ui").append(specialchars_box);
specialchars_box.before(DropdownWidget.$element);
}
/**
*
* @param {String} token
* @returns {OO.ui.ButtonWidget}}
*/
makeButton(token) {
const Button = new OO.ui.ButtonWidget({
useInputTag: true,
framed: false,
label: token
})
Button.$element.on('click', { toInsert: token }, this.InsertOnClick);
return Button;
}
InsertOnClick(e) {
e.preventDefault();
if (this.$currentFocused && this.$currentFocused.length && !this.$currentFocused.prop('readonly')) {
let splitterIndex;
if ((splitterIndex = e.data.toInsert.indexOf("+")) > 0) {
this.$currentFocused.textSelection(
'encapsulateSelection', {
pre: e.data.toInsert.substr(0, splitterIndex),
post: e.data.toInsert.substr(splitterIndex + 1)
});
} else {
this.$currentFocused.textSelection(
'encapsulateSelection', {
pre: e.data.toInsert
}
)
}
}
}
makeSubsetBox(curSubset) {
const tokens = []
if (typeof curSubset == "undefined") {
return null
}
else if (Array.isArray(curSubset)) {
for (const token of curSubset) {
tokens.push(this.makeButton(token));
}
} else {
for (const tokenKey in curSubset) {
const tokenArray = curSubset[tokenKey];
tokens.push(new OO.ui.LabelWidget({ label: `${tokenKey} ` }));
for (const token of tokenArray) {
tokens.push(this.makeButton(token));
}
}
}
return new OO.ui.ButtonGroupWidget({ items: tokens });
}
}
mw.loader.using(['oojs-ui']).then(() => {
mw.hook('wikiEditor.toolbarReady').add(() => new EditToolsBox(data));
});' |
편집 후 새 문서의 위키텍스트 (new_wikitext) | 'window.charinsert = {
기본: {
괄호: [
"(+)",
"[+]",
"{+}",
"〔+〕",
"〈+〉",
"【+】"
],
위키텍스트: [
"{{크기||+}}",
"[[+]]",
"[[#+]]",
"{{+}}",
"<!--+-->",
" /*+*/",
"[[분류:+]]",
"[[분류:+|_]]",
"[[파일:+]]",
" ",
"<del>+</del>",
"<br/>",
"<hr/>",
"----",
"{{-}}",
"{{각주}}",
"<ref>+</ref>",
"<ref.name='+' />",
"{{URL|+}}",
"__TOC__",
"<span.id='+'/>"
],
틀: [
"{{색||+}}",
"{{lang||+}}",
"{{llang||+}}",
"{{|+}}",
"{{문서이름}}",
"{{전체문서이름}}",
"{{삭제|+}}",
"{{특정판.삭제|+}}",
"{{유튜브|+}}",
"{{퍼온문서|문서=+|판=_|퍼온곳=_}}",
"{{번역된.문서|en|+||}}",
"{{string|+}}",
"{{배지|+}}",
"{{PD-author}}"
]
},
"틀 작성": [
"{{{+}}}",
"{{{+|}}}",
"<onlyinclude>+</onlyinclude>",
"<includeonly>+</includeonly>",
"<noinclude>+</noinclude>",
"{{풀기:+}}",
"<templatestyles.src='+/styles.css'/>"
],
"파서함수": [
"{{#expr:+}}",
"{{#if:+}}",
"{{#ifeq:+}}",
"{{#iferror:+}}",
"{{#ifexist:+}}",
"{{#switch:+}}",
"{{#time:+}}",
"{{#titlepart:+}}",
"{{#invoke:|}}"
],
"HTML": [
"<p>+</p>",
"<div>+</div>",
"<div.style=''>+</div>",
"<div.class=''.style=''>+</div>",
"<span>+</span>",
"<span.style=''>+</span>",
"<span.class=''.style=''>+</span>",
"<code>+</code>",
"<code><nowiki>+</nowiki></code>",
"<pre>+</pre>",
"<syntaxhighlight.lang='+'>\n\n</syntaxhighlight>"
],
"파일 저작권": [
"{{PD-self}}",
"{{PD-old}}",
"{{PD-author}}",
"{{CC-BY-3.0}}",
"{{CC-BY-SA-3.0}}"
]
};
class EditToolsBox {
constructor() {
/** @type {Array<HTMLDivElement>} */
const SubsetBoxes = [];
const data = Object.assign(window.charinsert, window.charinsertCustom);
const specialchars_box = $('<div id="editpage-specialchars" class="nopopups"></div>');
specialchars_box[0].title = '편집 창에 입력할 글자 혹은 태그를 클릭하세요';
// 문자셋 드랍다운 메뉴를 만듭니다.
const options = [];
for (const i in data) {
options.push(new OO.ui.MenuOptionWidget({ label: i, data: data[i] }));
}
/**
* @type {OO.ui.DropdownWidget}
*/
const DropdownWidget = new OO.ui.DropdownWidget();
DropdownWidget.setLabel('Choose character subset');
const DropdownMenu = DropdownWidget.getMenu();
DropdownMenu.addItems(options);
DropdownMenu.on('choose', (seletedItem) => {
let seletedIndex = DropdownMenu.getItemIndex(seletedItem);
if (SubsetBoxes.length === 0 || !SubsetBoxes[seletedIndex]) {
const box = this.makeSubsetBox(seletedItem.getData());
if (box != null) {
specialchars_box.append(box.$element);
SubsetBoxes[seletedIndex] = box.$element[0];
}
}
SubsetBoxes.forEach(e => { e.style.display = 'none' })
SubsetBoxes[seletedIndex].style.display = 'inline';
});
DropdownMenu.chooseItem(options[0]);
// Find the element that is focused
this.$currentFocused = $('#wpTextbox1');
// Apply to dynamically created textboxes as well as normal ones
$(document).on('focus', 'textarea, input:text', () => this.$currentFocused = $(this));
$(".wikiEditor-ui").append(specialchars_box);
specialchars_box.before(DropdownWidget.$element);
}
/**
*
* @param {String} token
* @returns {OO.ui.ButtonWidget}}
*/
makeButton(token) {
const Button = new OO.ui.ButtonWidget({
useInputTag: true,
framed: false,
label: token
});
Button.$element.on('click', { toInsert: token }, this.InsertOnClick);
return Button;
}
InsertOnClick(e) {
e.preventDefault();
if (this.$currentFocused && this.$currentFocused.length && !this.$currentFocused.prop('readonly')) {
let splitterIndex;
if ((splitterIndex = e.data.toInsert.indexOf("+")) > 0) {
this.$currentFocused.textSelection(
'encapsulateSelection', {
pre: e.data.toInsert.substr(0, splitterIndex),
post: e.data.toInsert.substr(splitterIndex + 1)
});
} else {
this.$currentFocused.textSelection(
'encapsulateSelection', {
pre: e.data.toInsert
}
);
}
}
}
makeSubsetBox(curSubset) {
const tokens = []
if (typeof curSubset == "undefined") {
return null;
}
else if (Array.isArray(curSubset)) {
for (const token of curSubset) {
tokens.push(this.makeButton(token));
}
} else {
for (const tokenKey in curSubset) {
const tokenArray = curSubset[tokenKey];
tokens.push(new OO.ui.LabelWidget({ label: `${tokenKey} ` }));
for (const token of tokenArray) {
tokens.push(this.makeButton(token));
}
}
}
return new OO.ui.ButtonGroupWidget({ items: tokens });
}
}
mw.loader.using(['oojs-ui']).then(() => {
mw.hook('wikiEditor.toolbarReady').add(() => new EditToolsBox(data));
mw.loader.load('//librewiki.net/index.php?title=User:하늘/EditTools.css&action=raw&ctype=text/css', 'text/css');
});' |
편집 전후의 차이 (edit_diff) | '@@ -1,13 +1,101 @@
+window.charinsert = {
+ 기본: {
+ 괄호: [
+ "(+)",
+ "[+]",
+ "{+}",
+ "〔+〕",
+ "〈+〉",
+ "【+】"
+ ],
+ 위키텍스트: [
+ "{{크기||+}}",
+ "[[+]]",
+ "[[#+]]",
+ "{{+}}",
+ "<!--+-->",
+ " /*+*/",
+ "[[분류:+]]",
+ "[[분류:+|_]]",
+ "[[파일:+]]",
+ " ",
+ "<del>+</del>",
+ "<br/>",
+ "<hr/>",
+ "----",
+ "{{-}}",
+ "{{각주}}",
+ "<ref>+</ref>",
+ "<ref.name='+' />",
+ "{{URL|+}}",
+ "__TOC__",
+ "<span.id='+'/>"
+ ],
+ 틀: [
+ "{{색||+}}",
+ "{{lang||+}}",
+ "{{llang||+}}",
+ "{{|+}}",
+ "{{문서이름}}",
+ "{{전체문서이름}}",
+ "{{삭제|+}}",
+ "{{특정판.삭제|+}}",
+ "{{유튜브|+}}",
+ "{{퍼온문서|문서=+|판=_|퍼온곳=_}}",
+ "{{번역된.문서|en|+||}}",
+ "{{string|+}}",
+ "{{배지|+}}",
+ "{{PD-author}}"
+ ]
+ },
+ "틀 작성": [
+ "{{{+}}}",
+ "{{{+|}}}",
+ "<onlyinclude>+</onlyinclude>",
+ "<includeonly>+</includeonly>",
+ "<noinclude>+</noinclude>",
+ "{{풀기:+}}",
+ "<templatestyles.src='+/styles.css'/>"
+ ],
+ "파서함수": [
+ "{{#expr:+}}",
+ "{{#if:+}}",
+ "{{#ifeq:+}}",
+ "{{#iferror:+}}",
+ "{{#ifexist:+}}",
+ "{{#switch:+}}",
+ "{{#time:+}}",
+ "{{#titlepart:+}}",
+ "{{#invoke:|}}"
+ ],
+ "HTML": [
+ "<p>+</p>",
+ "<div>+</div>",
+ "<div.style=''>+</div>",
+ "<div.class=''.style=''>+</div>",
+ "<span>+</span>",
+ "<span.style=''>+</span>",
+ "<span.class=''.style=''>+</span>",
+ "<code>+</code>",
+ "<code><nowiki>+</nowiki></code>",
+ "<pre>+</pre>",
+ "<syntaxhighlight.lang='+'>\n\n</syntaxhighlight>"
+ ],
+ "파일 저작권": [
+ "{{PD-self}}",
+ "{{PD-old}}",
+ "{{PD-author}}",
+ "{{CC-BY-3.0}}",
+ "{{CC-BY-SA-3.0}}"
+ ]
+};
+
class EditToolsBox {
- /**
- *
- * @param {{}} data
- */
- constructor(data) {
+ constructor() {
/** @type {Array<HTMLDivElement>} */
const SubsetBoxes = [];
- data = window.charinsert = Object.assign(data, window.charinsertCustom);
+ const data = Object.assign(window.charinsert, window.charinsertCustom);
const specialchars_box = $('<div id="editpage-specialchars" class="nopopups"></div>');
@@ -28,5 +116,5 @@
const DropdownMenu = DropdownWidget.getMenu();
- DropdownMenu.addItems(options)
+ DropdownMenu.addItems(options);
DropdownMenu.on('choose', (seletedItem) => {
@@ -36,5 +124,5 @@
const box = this.makeSubsetBox(seletedItem.getData());
if (box != null) {
- specialchars_box.append(box.$element)
+ specialchars_box.append(box.$element);
SubsetBoxes[seletedIndex] = box.$element[0];
}
@@ -66,5 +154,5 @@
framed: false,
label: token
- })
+ });
Button.$element.on('click', { toInsert: token }, this.InsertOnClick);
return Button;
@@ -88,5 +176,5 @@
pre: e.data.toInsert
}
- )
+ );
}
}
@@ -97,5 +185,5 @@
if (typeof curSubset == "undefined") {
- return null
+ return null;
}
else if (Array.isArray(curSubset)) {
@@ -119,3 +207,4 @@
mw.loader.using(['oojs-ui']).then(() => {
mw.hook('wikiEditor.toolbarReady').add(() => new EditToolsBox(data));
+ mw.loader.load('//librewiki.net/index.php?title=User:하늘/EditTools.css&action=raw&ctype=text/css', 'text/css');
});
' |
편집 중 추가된 줄 (added_lines) | [
0 => 'window.charinsert = {',
1 => ' 기본: {',
2 => ' 괄호: [',
3 => ' "(+)",',
4 => ' "[+]",',
5 => ' "{+}",',
6 => ' "〔+〕",',
7 => ' "〈+〉",',
8 => ' "【+】"',
9 => ' ],',
10 => ' 위키텍스트: [',
11 => ' "{{크기||+}}",',
12 => ' "[[+]]",',
13 => ' "[[#+]]",',
14 => ' "{{+}}",',
15 => ' "<!--+-->",',
16 => ' " /*+*/",',
17 => ' "[[분류:+]]",',
18 => ' "[[분류:+|_]]",',
19 => ' "[[파일:+]]",',
20 => ' " ",',
21 => ' "<del>+</del>",',
22 => ' "<br/>",',
23 => ' "<hr/>",',
24 => ' "----",',
25 => ' "{{-}}",',
26 => ' "{{각주}}",',
27 => ' "<ref>+</ref>",',
28 => ' "<ref.name='+' />",',
29 => ' "{{URL|+}}",',
30 => ' "__TOC__",',
31 => ' "<span.id='+'/>"',
32 => ' ],',
33 => ' 틀: [',
34 => ' "{{색||+}}",',
35 => ' "{{lang||+}}",',
36 => ' "{{llang||+}}",',
37 => ' "{{|+}}",',
38 => ' "{{문서이름}}",',
39 => ' "{{전체문서이름}}",',
40 => ' "{{삭제|+}}",',
41 => ' "{{특정판.삭제|+}}",',
42 => ' "{{유튜브|+}}",',
43 => ' "{{퍼온문서|문서=+|판=_|퍼온곳=_}}",',
44 => ' "{{번역된.문서|en|+||}}",',
45 => ' "{{string|+}}",',
46 => ' "{{배지|+}}",',
47 => ' "{{PD-author}}"',
48 => ' ]',
49 => ' },',
50 => ' "틀 작성": [',
51 => ' "{{{+}}}",',
52 => ' "{{{+|}}}",',
53 => ' "<onlyinclude>+</onlyinclude>",',
54 => ' "<includeonly>+</includeonly>",',
55 => ' "<noinclude>+</noinclude>",',
56 => ' "{{풀기:+}}",',
57 => ' "<templatestyles.src='+/styles.css'/>"',
58 => ' ],',
59 => ' "파서함수": [',
60 => ' "{{#expr:+}}",',
61 => ' "{{#if:+}}",',
62 => ' "{{#ifeq:+}}",',
63 => ' "{{#iferror:+}}",',
64 => ' "{{#ifexist:+}}",',
65 => ' "{{#switch:+}}",',
66 => ' "{{#time:+}}",',
67 => ' "{{#titlepart:+}}",',
68 => ' "{{#invoke:|}}"',
69 => ' ],',
70 => ' "HTML": [',
71 => ' "<p>+</p>",',
72 => ' "<div>+</div>",',
73 => ' "<div.style=''>+</div>",',
74 => ' "<div.class=''.style=''>+</div>",',
75 => ' "<span>+</span>",',
76 => ' "<span.style=''>+</span>",',
77 => ' "<span.class=''.style=''>+</span>",',
78 => ' "<code>+</code>",',
79 => ' "<code><nowiki>+</nowiki></code>",',
80 => ' "<pre>+</pre>",',
81 => ' "<syntaxhighlight.lang='+'>\n\n</syntaxhighlight>"',
82 => ' ],',
83 => ' "파일 저작권": [',
84 => ' "{{PD-self}}",',
85 => ' "{{PD-old}}",',
86 => ' "{{PD-author}}",',
87 => ' "{{CC-BY-3.0}}",',
88 => ' "{{CC-BY-SA-3.0}}"',
89 => ' ]',
90 => '};',
91 => '',
92 => ' constructor() {',
93 => ' const data = Object.assign(window.charinsert, window.charinsertCustom);',
94 => ' DropdownMenu.addItems(options);',
95 => ' specialchars_box.append(box.$element);',
96 => ' });',
97 => ' );',
98 => ' return null;',
99 => ' mw.loader.load('//librewiki.net/index.php?title=User:하늘/EditTools.css&action=raw&ctype=text/css', 'text/css');'
] |