MediaWiki:Edittools.js

From BR Bullpen

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
/* 
See also:
* [[МедиаУики:Chick.js]]
* [[МедиаУики:Common.js]]
* [[МедиаУики:Standard.js]]
* [[МедиаУики:Cologneblue.js]]
* [[МедиаУики:Monobook.js]]
* [[МедиаУики:Myskin.js]]
* [[МедиаУики:Nostalgia.js]]
* [[МедиаУики:Simple.js]]

* [[МедиаУики:Iefixesplus.js]]
* [[МедиаУики:Mainpage.js]]
* [[МедиаУики:Imagespace.js]]
* [[МедиаУики:Search.js]]
* [[МедиаУики:Uploadplus.js]]
* [[МедиаУики:Unwatch.js]]
* [[МедиаУики:Onlyifediting.js]]
* [[МедиаУики:Wikificator.js]]
* [[МедиаУики:Translit.js]]
* [[МедиаУики:Edittools.js]]
----
<source lang="javascript"> */
 /** Edit Tools *************************************************************
  *
  *  Description: Add menu for selecting subsets of special characters and wikimarkup, 
  *               based on [[:en:User:Mike Dillon/Scripts/edittools.js]].
  *  Maintainers: [[:en:User:Mike Dillon]], [[:kk:User:AlefZet]] 
  */

var wgUserLanguage = 'en';
var wgArticlePath = '/bullpen/';
function wgULS(cn,tw,hk,sg,zh){
	return {//保證每一語言有值
		'zh-cn':cn||sg,
		'zh-sg':sg||cn,
		'zh-tw':tw||hk,
		'zh-hk':hk||tw,
		'zh':zh||cn||tw||hk||sg
	}[wgUserLanguage];
}
 

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, caption) {
        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;
        }
        if (!caption) caption = display;
        else caption = caption + " (" + display + ")";

        var a = document.createElement("a");
        a.setAttribute("href", "#");
        a.setAttribute("title", wgULS("Мәтін қыстыру: ", "Mätin qıstırw: ", "مٵتٸن قىستىرۋ: ", "Insert text: ") + caption);
        a.setAttribute("alt", wgULS("Мәтін қыстыру: ", "Mätin qıstırw: ", "مٵتٸن قىستىرۋ: ", "Insert text: ") + caption);
        a.setAttribute("class", "my-buttons");
        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.addBreak = function () {
        return addElement(this, "break", document.createElement("br"));
    };

    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.setAttribute("alt", 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 = "compact"; 

    this.clear = true;
    this.groups = {};

    this.addBreak = function () {
        if (this.style == 'compact') return this.addBreak();
        if (this.style == 'full') return this.addGap();
    };

    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.setAttribute("style", "display: inline");
            select.onchange = function () {
                var sel = this.options[this.selectedIndex].value;
                for (var name in groupEls) {
                    groupEls[name].style.display = (name == sel) ? "inline" : "none";
                    groupEls[name].style.visibility = (name == sel) ? "visible" : "hidden";
                }
            };
            container.appendChild(select);
            container.appendChild(document.createTextNode(" "));
        }

        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");
            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;
            if (this.style == 'compact') {
                for (var name in groupEls) {
                    groupEls[name].style.display = (name == "main") ? "inline" : "none";
                    groupEls[name].style.visibility = (name == "main") ? "visible" : "hidden";
                }
            }
        }
    };
};

with (Edittools) {
    // Main group
    var main = createGroup("main", "Қазақ пернетақтасы");
    with (main) {
        addLabel("Қазақ пернетақтасы:").addBreak();
        addInsertList("Ё Ә І Ң Ғ Ү Ұ Қ Ө Һ").addGap();
        addInsertList("Ä Ç É Ğ İ Ï Ñ Ö Ş Ü Ý").addGap();
        addInsert("ʺ", "", "", "Жуандық белгісі");
        addInsert("ʼ", "", "", "Типографикалық апостроф");
        addInsert("—", "", "", "Ұзынша тире");
        addInsert("%", "", "", "Пайыз");
        addInsert("#", "", "", "Жасуша").addGap();
        addInsert("«", "»", "", "Қырлы тырнақшалар");
        addInsert("„", "“", "", "Ілмек тырнақшалар").addBreak();
        addInsertList("ё ә і ң ғ ү ұ қ ө һ").addGap();
        addInsertList("ä ç é ğ ı ï ñ ö ş ü ý").addGap();
        addInsert("ʹ", "", "", "Жіңішкелік белгісі");
        addInsert("", "́", "", "Екпін" );
        addInsert("−", "", "", "Минус");
        addInsert("…", "", "", "Үшнүктелік");
        addInsert("|", "", "", "Тік сызық").addGap();
        addInsert("&nbsp;", "", "", "Жырылмайтын кемтік");
    }

    // Wiki markup
    var wikimarkup = createGroup("wikimarkup", "Уики белгілеу");
    with (wikimarkup) {
        addLabel("Уики белгілеу:").addBreak();
        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("Уикипедия:Үлгі хабарлары", "templates");
    }

    // Symbols
    var symbols = createGroup("symbols", "Арнайы нышандар");
    with (symbols) {
        addLabel("Арнайы нышандар:").addBreak();
        addInsertList("– — … ° ≈ ≠ ≤ ≥ ± − × ÷ ← → · §").addGap();
        addInsertList("~ | ¡ ¿ † ‡ ↔ ↑ ↓ • ¶").addGap();
        addInsertList("# ¹ ² ³ ½ ⅓ ⅔ ¼ ¾ ⅛ ⅜ ⅝ ⅞ ∞").addGap();
        addInsertList("‘ “ ’ ”").addGap();
        addInsertList("® ™ © ℗ @ Å ℃ ℉ Ω µ").addGap();
        addInsertList("¤ ₳ ฿ ₵ ¢ ₡ ₢ $ ₫ ₯ € ₠ ₣ ƒ ₴ ₭ ₤ ℳ ₥ ₦ ₧ ₰");
        addInsertList("£ ៛ ₨ ₪ ৳ ₮ ₩ ¥ 〒").addGap();
        addInsertList("♠ ♣ ♥ ♦");
    }

    // Characters
    var latinx = createGroup("latinx", "Латын/Роман жазуы");
    with (latinx) {
        addLabel("Латын/Роман жазуы:").addBreak();
        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|", "}}");
    }

    // Turkic
    var turkic = createGroup("turkic", "Түркі латын жазуы");
    with (turkic) {
        addLabel("Түркі латын жазуы:").addBreak();
        addInsertList("Ä Â B Ç Ch É Ê Ə Ğ Gʻ Ƣ Ⱨ İ Í Ï Î Ƅ Ⱪ L Ň Ñ Ŋ").addGap(); 
        addInsertList("Ö Oʻ Ɵ Ş Sh Ü Û Ý Ž Ƶ Ⱬ").addBreak();
        addInsertList("ä â ʙ ç ch é ê ə ğ gʻ ƣ ⱨ ı í ï î ƅ ⱪ ʟ ň ñ ŋ ng ö oʻ ɵ ş sh ü û ý ž ƶ ⱬ").addGap();
        addInsertList("ʺ ʹ ʼ");
    }

    // Cyrillic
    var cyrillic = createGroup("cyrillic", "Кирил жазуы");
    with (cyrillic) {
        addLabel("Кирил жазуы:").addBreak();
        addInsertList("Ӑ Ӗ Ҕ Җ Ҙ Ҡ Ҥ Ҫ Ӳ").addGap();
        addInsertList("Ґ Ѓ Ђ Ѐ Ё Є Ѕ Ѝ І Ї Ј Љ Њ Ћ Ќ Ў Џ Ѣ Ѳ Ѵ").addBreak();
        addInsertList("ӑ ӗ ҕ җ ҙ ҡ ҥ ҫ ӳ").addGap();
        addInsertList("ґ ѓ ђ ѐ ё є ѕ ѝ і ї ј љ њ ћ ќ ў џ ѣ ѳ ѵ");
    }

    // Greek
    var polytonic = createGroup("polytonic", "Юнан жазуы");
    with (polytonic) {
        addLabel("Юнан жазуы:").addBreak();
        addInsertList("Α Β Γ Δ Ε Ζ Η Θ Ι Κ Λ Μ Ν Ξ Ο Π Ρ Σ").addGap();
        addInsertList("Τ Υ Φ Χ Ψ Ω").addGap();
        addInsertList("Ά Έ Ή Ί Ό Ύ Ώ").addBreak();
        addInsertList("α β γ δ ε ζ η θ ι κ λ μ ν ξ ο π ρ σ");
        addInsertList("ς τ υ φ χ ψ ω").addGap();
        addInsertList("ά έ ή ί ό ύ ώ");
        addBullet();
        addInsert("{{Polytonic|", "}}");
        addBullet();
        addWikiLink("Политоникалық_емле#Политоникалық_әріптерінің_мысалы", "polytonic");
    }

    // Tote
    var tote = createGroup("tote", "Төте жазу");
    with (tote) {
        addLabel("Төте жазу:").addBreak();
        addInsert("ا", "", "", "А");
        addInsert("ٵ", "", "", "Ә");
        addInsert("ب", "", "", "Б");
        addInsert("پ", "", "", "П");
        addInsert("ت", "", "", "Т");
        addInsert("ج", "", "", "Ж");
        addInsert("چ", "", "", "Ч");
        addInsert("د", "", "", "Д");
        addInsert("ر", "", "", "Р");
        addInsert("ز", "", "", "З");
        addInsert("س", "", "", "Ш");
        addInsert("ع", "", "", "Ғ");
        addInsert("ف", "", "", "Ф");
        addInsert("ق", "", "", "Қ");
        addInsert("ك", "", "", "К");
        addInsert("گ", "", "", "Г");
        addInsert("ل", "", "", "Л");
        addInsert("م", "", "", "М");
        addInsert("ن", "", "", "Н");
        addInsert("ڭ", "", "", "Ң");
        addInsert("ھ", "", "", "Һ");
        addInsert("ە", "", "", "Е");
        addInsert("و", "", "", "О");
        addInsert("ٶ", "", "", "Ө");
        addInsert("ۋ", "", "", "У");
        addInsert("ۇ", "", "", "Ұ");
        addInsert("ٷ", "", "", "Ү");
        addInsert("ۆ", "", "", "В");
        addInsert("ى", "", "", "Ы");
        addInsert("ٸ", "", "", "І");
        addInsert("ي", "", "", "И");
        addInsert("يو", "", "", "Ё");
        addInsert("لا", "", "", "ЛА").addGap();
        addInsert("۰", "", "", "0");
        addInsert("۱", "", "", "1");
        addInsert("۲", "", "", "2");
        addInsert("۳", "", "", "3");
        addInsert("۴", "", "", "4");
        addInsert("۵", "", "", "5");
        addInsert("۶", "", "", "6");
        addInsert("۷", "", "", "7");
        addInsert("۸", "", "", "8");
        addInsert("۹", "", "", "9").addGap();
        addInsert("٬", "", "", "Мыңдық бөлгіші");
        addInsert("٫", "", "", "Жарнақ бөлгіші").addGap();
        addInsertList("٪ ٭ ، ؛ ؟");
    }

    // Hebrew
    var hebrew = createGroup("hebrew", "Иврит/идиш жазуы");
    with (hebrew) {
        addLabel("Иврит/идиш жазуы:").addBreak();
        addInsertList("א אַ אָ ב בֿ ג ד ה ו וּ װ ױ ז ח ט י יִ ײ ײַ כ כּ ך ל מ ם נ ן ס ע פּ פֿ ף צ ץ ק ר ש שׂ ת תּ ׳ ״");
    }

    // IPA
    var ipa = createGroup("ipa", "IPA");
    with (ipa) {
        addLabel("IPA:").addBreak();
        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("ˈ ˌ ː ˑ  ̪");
        addLabel("Индоеуропеистика:");
        addInsertList("ḱ ǵ ʰ ʷ h₁ h₂ h₃ m̥ n̥ l̥ r̥ ē ō þ ð ƕ");
        addBullet();
        addLabel("Египтология:");
        addInsertList("3 ỉ y ˁ w b p f m n r h ḥ ḫ ẖ s ś š ḳ k g t ṯ d ḏ ");
        addBullet();
        addInsert("{{IPA|", "}}");
    }
}

addOnloadHook(function () {
    Edittools.install("editpage-specialchars");
});

/* </source> */