User:Mike Dillon/Scripts/edittools.js
/* <pre><nowiki> */
// XXX: This should be in a regular CSS file
(function () {
var head = document.getElementsByTagName("head")[0];
if (head) {
var style = document.createElement("style");
style.setAttribute("type", "text/css")
style.appendChild(document.createTextNode(
"div#edittools_main {" +
" font-size: inherit;" +
" border-bottom: 1px solid #aaa;" +
"}" +
"div.edittools-group {" +
" font-size: smaller;" +
"}"
));
head.appendChild(style);
}
})();
function EdittoolsGroup(name, label) {
this.label = label || name;
this.elements = [];
function addElement(group, type, e) {
group.elements[group.elements.length] = [ type, e ];
return group;
}
this.addLabel = function (label) {
var b = document.createElement("b");
b.appendChild(document.createTextNode(label));
return addElement(this, "label", b);
};
this.addInsert = function (open, close, sample) {
if (!open) open = '';
if (!close) close = '';
if (!sample) sample = '';
var display = open + close;
if (display.match(/^[\u0300-\u036F\u1DC0-\u1DFF\u20D0-\u20FF\uFE20-\uFE2F]/)) {
display = "\u034F" + display;
}
var a = document.createElement("a");
a.setAttribute("href", "#");
a.setAttribute("title", "Insert text: " + display);
a.appendChild(document.createTextNode(display));
a.onclick = function () {
insertTags(open, close, sample);
return false;
};
return addElement(this, "insert", a);
};
this.addInsertList = function (chars) {
if (!chars) return;
var list = chars.split(/\s+/);
for (var n in list) {
if (list[n] != '') this.addInsert(list[n]);
}
return this;
};
this.addGap = function () {
return addElement(this, "gap", document.createTextNode("\xA0"));
};
this.addBullet = function () {
return addElement(this, "bullet", document.createTextNode("\xA0•\xA0"));
};
this.addWikiLink = function (page, label) {
var parts = page.split(/#/, 2);
var url = wgArticlePath.replace(/\$1/, encodeURIComponent(parts[0]));
if (parts[1]) {
url += "#" + encodeURIComponent(parts[1]).replace(/%/g, ".");
}
var a = document.createElement("a");
a.setAttribute("href", url);
a.setAttribute("title", page.replace(/_/g, " "));
a.appendChild(document.createTextNode(label || page));
var span = document.createElement("span");
span.appendChild(document.createTextNode("("));
span.appendChild(a);
span.appendChild(document.createTextNode(")"));
return addElement(this, "link", span);
};
}
var Edittools = new function () {
this.style = "full";
this.clear = true;
this.groups = {};
this.createGroup = function (name, label) {
if (!this.groups[name]) {
this.groups[name] = new EdittoolsGroup(name, label);
}
return this.groups[name];
};
this.getGroup = function (name) {
return this.groups[name];
};
this.removeGroup = function (name) {
delete this.groups[name];
};
this.removeAllGroups = function () {
this.groups = {};
};
this.install = function (container) {
if (container && container.nodeType == null) {
container = document.getElementById(container);
}
if (!container) return;
if (this.clear) {
while (container.firstChild) container.removeChild(container.firstChild);
}
var groupEls = {};
if (this.style == 'compact') {
var select = document.createElement("select");
select.onchange = function () {
var sel = this.options[this.selectedIndex].value;
for (var name in groupEls) {
groupEls[name].style.display = (name == sel) ? "inline" : "none";
}
};
container.appendChild(select);
container.appendChild(document.createTextNode(" "));
}
var first = true;
var elType = (this.style == 'compact') ? "span" : "div";
for (var name in this.groups) {
var group = this.groups[name];
if (this.style == 'compact') {
var opt = document.createElement("option");
opt.setAttribute("value", name);
opt.appendChild(document.createTextNode(group.label));
select.appendChild(opt);
}
var groupEl = document.createElement(elType);
groupEl.setAttribute("id", "edittools_" + name);
groupEl.setAttribute("class", "edittools-group");
if (!first && this.style == 'compact') {
groupEl.setAttribute("style", "display: none");
}
for (var n in group.elements) {
var element = group.elements[n];
if (element[0] == 'label' && this.style == 'compact') continue;
if (groupEl.childNodes.length) {
groupEl.appendChild(document.createTextNode(" "));
}
groupEl.appendChild(element[1]);
}
container.appendChild(groupEl);
groupEls[name] = groupEl;
first = false;
}
};
};
with (Edittools) {
// Main group
var main = createGroup("main", "Standard");
with (main) {
addLabel("Insert:");
addInsertList("– — … ° ≈ ≠ ≤ ≥ ± − × ÷ ← → · §").addGap();
addLabel("Sign your username:");
addInsert("~~" + "~~");
}
// Wiki markup
var wikimarkup = createGroup("wikimarkup", "Wiki markup");
with (wikimarkup) {
addLabel("Wiki markup:");
addInsert("{{", "}}").addGap();
addInsert("|").addGap();
addInsert("[", "]").addGap();
addInsert("[[", "]]").addGap();
addInsert("[[Category:", "]]").addGap();
addInsert("#REDIRECT[[", "]]").addGap();
addInsert("<s>", "</s>").addGap();
addInsert("<sup>", "</sup>").addGap();
addInsert("<sub>", "</sub>").addGap();
addInsert("<code>", "</code>").addGap();
addInsert("<blockquote>", "</blockquote>").addGap();
addInsert("<ref>", "</ref>").addGap();
addInsert("{{Reflist}}").addGap();
addInsert("<references/>").addGap();
addInsert("<includeonly>", "</includeonly>").addGap();
addInsert("<noinclude>", "</noinclude>").addGap();
addInsert("{{DEFAULTSORT:", "}}").addGap();
addInsert("<no" + "wiki>", "</no" + "wiki>").addGap();
addInsert("<!-- ", " -->").addGap();
addInsert("<span class=\"plainlinks\">", "</span>");
addBullet();
addWikiLink("Wikipedia:Template messages", "templates");
}
// Symbols
var symbols = createGroup("symbols", "Symbols");
with (symbols) {
addLabel("Symbols:");
addInsertList("~ | ¡ ¿ † ‡ ↔ ↑ ↓ • ¶").addGap();
addInsertList("# ¹ ² ³ ½ ⅓ ⅔ ¼ ¾ ⅛ ⅜ ⅝ ⅞ ∞").addGap();
addInsertList("‘ “ ’ ”").addGap();
addInsertList("¤ ₳ ฿ ₵ ¢ ₡ ₢ $ ₫ ₯ € ₠ ₣ ƒ ₴ ₭ ₤ ℳ ₥ ₦ ₧ ₰");
addInsertList("£ ៛ ₨ ₪ ৳ ₮ ₩ ¥").addGap();
addInsertList("♠ ♣ ♥ ♦");
}
// Characters
var characters = createGroup("characters", "Characters");
with (characters) {
addLabel("Characters:");
addInsertList("Á á Ć ć É é Í í Ĺ ĺ Ń ń Ó ó Ŕ ŕ Ś ś Ú ú Ý ý Ź ź").addGap();
addInsertList("À à È è Ì ì Ò ò Ù ù").addGap();
addInsertList("Â â Ĉ ĉ Ê ê Ĝ ĝ Ĥ ĥ Î î Ĵ ĵ Ô ô Ŝ ŝ Û û Ŵ ŵ Ŷ ŷ").addGap();
addInsertList("Ä ä Ë ë Ï ï Ö ö Ü ü Ÿ ÿ").addGap();
addInsertList("ß").addGap();
addInsertList("Ã ã Ẽ ẽ Ĩ ĩ Ñ ñ Õ õ Ũ ũ Ỹ ỹ").addGap();
addInsertList("Ç ç Ģ ģ Ķ ķ Ļ ļ Ņ ņ Ŗ ŗ Ş ş Ţ ţ").addGap();
addInsertList("Đ đ").addGap();
addInsertList("Ů ů").addGap();
addInsertList("Ǎ ǎ Č č Ď ď Ě ě Ǐ ǐ Ľ ľ Ň ň Ǒ ǒ Ř ř Š š Ť ť Ǔ ǔ Ž ž").addGap();
addInsertList("Ā ā Ē ē Ī ī Ō ō Ū ū Ȳ ȳ Ǣ ǣ").addGap();
addInsertList("ǖ ǘ ǚ ǜ").addGap();
addInsertList("Ă ă Ĕ ĕ Ğ ğ Ĭ ĭ Ŏ ŏ Ŭ ŭ").addGap();
addInsertList("Ċ ċ Ė ė Ġ ġ İ ı Ż ż").addGap();
addInsertList("Ą ą Ę ę Į į Ǫ ǫ Ų ų").addGap();
addInsertList("Ḍ ḍ Ḥ ḥ Ḷ ḷ Ḹ ḹ Ṃ ṃ Ṇ ṇ Ṛ ṛ Ṝ ṝ Ṣ ṣ Ṭ ṭ").addGap();
addInsertList("Ł ł").addGap();
addInsertList("Ő ő Ű ű").addGap();
addInsertList("Ŀ ŀ").addGap();
addInsertList("Ħ ħ").addGap();
addInsertList("Ð ð Þ þ").addGap();
addInsertList("Œ œ").addGap();
addInsertList("Æ æ Ø ø Å å").addGap();
addInsertList("Ə ə");
addBullet();
addInsert("{{Unicode|", "}}");
}
// Greek
var greek = createGroup("greek", "Greek");
with (greek) {
addLabel("Greek:");
addInsertList("Ά ά Έ έ Ή ή Ί ί Ό ό Ύ ύ Ώ ώ").addGap();
addInsertList("Α α Β β Γ γ Δ δ").addGap();
addInsertList("Ε ε Ζ ζ Η η Θ θ").addGap();
addInsertList("Ι ι Κ κ Λ λ Μ μ").addGap();
addInsertList("Ν ν Ξ ξ Ο ο Π π").addGap();
addInsertList("Ρ ρ Σ σ ς Τ τ Υ υ").addGap();
addInsertList("Φ φ Χ χ Ψ ψ Ω ω").addGap();
addInsertList("");
addBullet();
addInsert("{{Polytonic|", "}}");
addBullet();
addWikiLink("Polytonic_orthography#Examples_of_polytonic_characters", "polytonic");
}
// Cyrillic
var cyrillic = createGroup("cyrillic", "Cyrillic");
with (cyrillic) {
addLabel("Cyrillic:");
addInsertList("А а Б б В в Г г").addGap();
addInsertList("Ґ ґ Ѓ ѓ Д д Ђ ђ").addGap();
addInsertList("Е е Ё ё Є є Ж ж").addGap();
addInsertList("З з Ѕ ѕ И и І і").addGap();
addInsertList("Ї ї Й й Ј ј К к").addGap();
addInsertList("Ќ ќ Л л Љ љ М м").addGap();
addInsertList("Н н Њ њ О о П п").addGap();
addInsertList("Р р С с Т т Ћ ћ").addGap();
addInsertList("У у Ў ў Ф ф Х х").addGap();
addInsertList("Ц ц Ч ч Џ џ Ш ш").addGap();
addInsertList("Щ щ Ъ ъ Ы ы Ь ь").addGap();
addInsertList("Э э Ю ю Я я");
}
// IPA
var ipa = createGroup("ipa", "IPA");
with (ipa) {
addLabel("IPA:");
addInsertList("t̪ d̪ ʈ ɖ ɟ ɡ ɢ ʡ ʔ").addGap();
addInsertList("ɸ ʃ ʒ ɕ ʑ ʂ ʐ ʝ ɣ ʁ ʕ ʜ ʢ ɦ").addGap();
addInsertList("ɱ ɳ ɲ ŋ ɴ").addGap();
addInsertList("ʋ ɹ ɻ ɰ").addGap();
addInsertList("ʙ ʀ ɾ ɽ").addGap();
addInsertList("ɫ ɬ ɮ ɺ ɭ ʎ ʟ").addGap();
addInsertList("ɥ ʍ ɧ").addGap();
addInsertList("ɓ ɗ ʄ ɠ ʛ").addGap();
addInsertList("ʘ ǀ ǃ ǂ ǁ").addGap();
addInsertList("ɨ ʉ ɯ").addGap();
addInsertList("ɪ ʏ ʊ").addGap();
addInsertList("ɘ ɵ ɤ").addGap();
addInsertList("ə ɚ").addGap();
addInsertList("ɛ ɜ ɝ ɞ ʌ ɔ").addGap();
addInsertList("ɐ ɶ ɑ ɒ").addGap();
addInsertList("ʰ ʷ ʲ ˠ ˤ ⁿ ˡ").addGap();
addInsertList("ˈ ˌ ː ˑ ̪");
addBullet();
addInsert("{{IPA|", "}}");
}
}
addOnloadHook(function () {
Edittools.install("editpage-specialchars");
});
/* </nowiki></pre> */
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.