MediaWiki:Common.js

Aus WORLDFISH WIKI
Wechseln zu: Navigation, Suche

Hinweis: Leere nach dem Speichern den Browser-Cache, um die Änderungen sehen zu können.

  • Firefox/Safari: Umschalttaste drücken und gleichzeitig Aktualisieren anklicken oder entweder Strg+F5 oder Strg+R (⌘+R auf dem Mac) drücken
  • Google Chrome: Umschalttaste+Strg+R (⌘+Umschalttaste+R auf dem Mac) drücken
  • Internet Explorer: Strg+F5 drücken oder Strg drücken und gleichzeitig Aktualisieren anklicken
  • Opera: Gehe zu Menü → Einstellungen (Opera → Einstellungen auf dem Mac) und dann auf Datenschutz & Sicherheit → Browserdaten löschen → Gespeicherte Bilder und Dateien.

        const POSITION_ABOVE = 0;
        const POSITION_BEYOND = 1;
        const ID_TOOLBAR = "cebToolbar";
        const ID_TOOLBAR_STYLE = "toolbarStyle";
        const CLASS_TOOLBAR = "buttonToolbar";
        const CLASS_TOP_BUTTON_BAR = "topButtonBar";
        const CLASS_HEADER = "header";

        // Set this value to the ID of the target text area:
        var nameOfTargetBox = null;
        var targetNode = null;

        //Insert buttons with properties text, icon, prefix, suffix, etc. (see createButtons for details)
        var buttonList = [];
        var headers = [];

        var topButtonContainer = null;
        var toolbarCSS = null;

        var reselectTextAfterInsert = false;

        function addToolbar(referenceNode, position)
        {
            if(!referenceNode) {
                console.error("Cannot add tool bar, invalid reference node");
                return;
            }

            const buttons = createButtons();

            const toolbar = document.createElement("div");
            toolbar.setAttribute("id", ID_TOOLBAR);
            toolbar.setAttribute("class", CLASS_TOOLBAR);

            if(toolbarCSS != null)
            {
                createToolbarCSS(toolbar);
            }

            topButtonContainer = document.createElement("div");
            topButtonContainer.setAttribute("class", CLASS_TOP_BUTTON_BAR);
            toolbar.appendChild(topButtonContainer);

            const toolbarTable = document.createElement("table");
            toolbarTable.setAttribute("style", "width: 100%");
            toolbar.appendChild(toolbarTable);

            var numRows = 0;

            for(var i = 0; i < buttonList.length; i++)
            {
                if(buttonList[i].row > numRows)
                    numRows = buttonList[i].row;
            }

            //Save all headers by their row index:
            const rowData = [];
            for(var i = 0; i < headers.length; i++)
            {
                rowData[headers[i].row - 1] = headers[i];
                if(headers[i].row > numRows)
                    numRows = headers[i].row;
            }

            const td = [];

            for(var i = 0; i < numRows; i++)
            {
                const tr = document.createElement("tr");
                if(rowData[i])
                {
                    const headerCell = document.createElement("td");
                    headerCell.innerText = rowData[i].text;
                    headerCell.setAttribute("class", CLASS_HEADER);
                    if(rowData[i].rowSpan > 1)
                        headerCell.setAttribute("rowspan", rowData[i].rowSpan);
                    tr.appendChild(headerCell);
                }
                td[i] = document.createElement("td");
                tr.appendChild(td[i]);
                toolbarTable.appendChild(tr);
            }

            for(var i = 0; i < buttons.length; i++)
            {
                const row = buttonList[i].row;
                if(row == 0)
                    topButtonContainer.appendChild(buttons[i]);
                else
                    td[row - 1].appendChild(buttons[i]);
            }

            if(position == POSITION_BEYOND)
                referenceNode.insertAdjacentElement("afterend", toolbar);
            else
                referenceNode.insertAdjacentElement("beforebegin", toolbar);
        }

        function createToolbarCSS(targetElement)
        {
            const element = document.createElement("style");
            element.innerHTML = toolbarCSS;
            targetElement.appendChild(element);
        }

        function insertText(textBeforeCursor, textAfterCursor) {
            const start = targetNode.selectionStart;
            const end = targetNode.selectionEnd;
            const text = targetNode.value;
            var output = text.substr(0, start) + textBeforeCursor;
            output += text.substr(start, end - start);
            output += textAfterCursor + text.substr(end, text.length - end);
            targetNode.value = output;
            if(reselectTextAfterInsert)
            {
                targetNode.selectionStart = start + textBeforeCursor.length;
                targetNode.selectionEnd = end + textBeforeCursor.length;
            }
            else
            {
                targetNode.selectionEnd = targetNode.selectionStart =  end + textBeforeCursor.length;
            }
            targetNode.focus();
        }

        function createButtons() {
            const buttonElements = [];
            for(var i = 0; i < buttonList.length; i++)
            {
                const button = buttonList[i];
                const buttonElement = document.createElement("button");
                buttonElement.type = "button";
                buttonElement.innerHTML = button.content;
                buttonElement.onclick = function () {
                    insertText(button.prefix, button.suffix);
                };
                buttonElements.push(buttonElement);
            }
            return buttonElements;
        }

        function setup() {
            /* Check if view is in edit mode and that the required modules are available. Then, customize the toolbar … */
            if ($.inArray(mw.config.get('wgAction'), ['edit', 'submit']) !== -1) {
                mw.loader.using('user.options').then(function () {
                    targetNode = document.getElementById(nameOfTargetBox);
                    addToolbar(targetNode, POSITION_BEYOND);
                });
            }
        }

        // End of Script
    

buttonList = [{"content":"#redirect","row":1,"prefix":"#redirect[[","suffix":"]]"},{"content":"(doi+)","row":1,"prefix":"[ (doi)]{{subst:","suffix":"reftemp}}"},{"content":"subst:reftemp","row":1,"prefix":" <includeonly>[https://wf-wiki.de/index.php/Vorlage:Common.js Zitatseite]</includeonly>&nbsp;<noinclude>[[Category:Literaturvorlage]]</noinclude>","suffix":""},{"content":"falsche Art","row":1,"prefix":"<span style=\"color: red; text-decoration: line-through;\">''Misidentifizierter Artname''</span> -->''[[richtiger Artname]]''","suffix":""},{"content":"!!","row":1,"prefix":"<span style=\"color: red\">'''!!'''</span>","suffix":""},{"content":"ETY","row":1,"prefix":"(Übersetzt aus: [ The ETYFish Project])","suffix":""},{"content":"Autoren++","row":1,"prefix":"Der Autorenname {{BASEPAGENAME}} könnte auf folgende Personen verweisen:","suffix":""},{"content":"disambig","row":1,"prefix":"{{disambig}}","suffix":""},{"content":"(Karte)","row":1,"prefix":"[ (Karte)]","suffix":""},{"content":"&apos;&apos;[[ ]]&apos;&apos;","row":2,"prefix":"''[[","suffix":"]]''"},{"content":"[ ]","row":2,"prefix":"[","suffix":"]"},{"content":"[[ ]]","row":2,"prefix":"[[","suffix":"]]"},{"content":"{{ }}","row":2,"prefix":"{{","suffix":"}}"},{"content":"{{a|x}}","row":2,"prefix":"{{a|","suffix":"|}}"},{"content":"{{a||x}}","row":2,"prefix":"{{a||","suffix":"}}"},{"content":"{{aut|}}","row":2,"prefix":"{{aut|","suffix":"}}"},{"content":"†","row":2,"prefix":"†","suffix":""},{"content":"♂","row":2,"prefix":"♂","suffix":""},{"content":"♀","row":2,"prefix":"♀","suffix":""},{"content":"br /","row":2,"prefix":"<br /","suffix":">"},{"content":"Liste(Pub)","row":3,"prefix":"Liste der von [[","suffix":"]] beschriebenen und in Worldfish Wiki bereits erfassten Taxa  [[Category:Taxa by author]]"},{"content":"Art(simp)","row":3,"prefix":"__NOTOC__ <!--† ♂♀ --> =='''{{aut|(Autoren}}, Jahr)'''== <!---------------------------  Taxonavigation  --------------------------> {| style=\"width:100%; background:#fcfcfc; margin-top:2em;\"  |- valign=\"top\"  |style=\"width:50%; padding:0 1em 0 2em; color:#000; border:1px solid #ccc;\"|  {{Gattung}}<br />  == Synonyme == ''[[]]'' {{aut|Name}}, Jahr  == Lokale Bezeichnung == [[Trivialbezeichnung]]  <!--------------------------- Platz für Abbildungen  --------------------------> | style=\"width:50%; padding:0 1em; background:#f5fffa; border:1px solid #ccc;\" id=mf-sow|  |} == Typen == '''Holotypus:''' [[Type# .<br /> Siehe: [http://researcharchive.calacademy.org/research/ichthyology/catalog/fishcatget.asp?spid=0 {{aut|Eschmeyer, W.N., Fricke, R. & Van der Laan, R.}} (eds.) {{CURRENTYEAR}}. ''Catalog of Fishes'' electronic version]<br /> '''Typusfundort:''' .  == Etymologie == .  == Verbreitung == .  == IUCN Status == [https://www.iucnredlist.org/details/ IUCN ('''I'''nternational '''U'''nion for '''C'''onservation of '''N'''ature and Natural Resources) = Weltnaturschutzunion '''Rote Liste bedrohter Arten''']  [[Datei:Status iucn3.1.svg.png|300px|mini|Die Gefährdungsstufen gemäß IUCN <p style=\"color: #FF0000; background-color: #000000;\">'''EX''' Extinct (ausgestorben)</p> <p style=\"color: #FFFFFF; background-color: #000000;\">'''EW''' Extinct in the Wild (in der Natur ausgestorben)</p> <span style=\"color: red\">'''CR''' Critically Endangered (vom Aussterben bedroht)</span><br /> <p style=\"color: #FF7722;\">'''EN''' Endangered (stark gefährdet)</p> <p style=\"color: #EECC00;\">'''VU''' Vulnerable (gefährdet)</p> <p style=\"color: #77EE00;\">'''NT''' Near Threatened (potenziell gefährdet)</p> <p style=\"color: #44AA00;\">'''LC''' Least Concern (nicht gefährdet)</p> '''RE''' Regionally Extinct (regional oder national ausgestorben)<br /> '''DD''' Data Deficient (ungenügende Datengrundlage)<br /> '''NE''' Not Evaluated (nicht beurteilt)]]  '''Status:''' Stand tt.mm.jjjj: '''NE''' Not Evaluated (nicht beurteilt)<br /> '''Gefahren für diese Art:''' (nicht beurteilt)  ==Literatur== {{}}[: , <span style=\"color: red\">'''!!'''</span>]  ===Links=== * [http://www.fishbase.org/summary/0000 FishBase]  [[Category: taxa]] [[Category: taxa]] [[Category: taxa]] [[Category:art]] ","suffix":""},{"content":"Art(†)","row":3,"prefix":"__NOTOC__ <!--† ♂♀ --> =='''{{aut|(Autoren}}, Jahr)'''== <!---------------------------  Taxonavigation  --------------------------> {| style=\"width:100%; background:#fcfcfc; margin-top:2em;\"  |- valign=\"top\"  |style=\"width:50%; padding:0 1em 0 2em; color:#000; border:1px solid #ccc;\"|  {{Gattung}}<br />  == Synonyme == †''[[]]'' {{aut|Name}}, Jahr  <!--------------------------- Platz für Abbildungen  --------------------------> | style=\"width:50%; padding:0 1em; background:#f5fffa; border:1px solid #ccc;\" id=mf-sow|  |} == Typen == '''Holotypus:''' [[Type# .<br /> '''Typusfundort:''' .  == Etymologie == .  == Verbreitung == .  ==Literatur== {{}}[: , <span style=\"color: red\">'''!!'''</span>]  ===Links=== *   [[Category: taxa]] [[Category: taxa]] [[Category: taxa]] [[Category:art]] ","suffix":""},{"content":"Art(sp.)","row":3,"prefix":"__NOTOC__ <!--† ♂♀ --> <!---------------------------  Taxonavigation  --------------------------> {| style=\"width:100%; background:#fcfcfc; margin-top:2em;\"  |- valign=\"top\"  |style=\"width:50%; padding:0 1em 0 2em; color:#000; border:1px solid #ccc;\"|  {{Gattung}}<br />  == Lokale Bezeichnung == [[Trivialbezeichnung]]  <!--------------------------- Platz für Abbildungen  --------------------------> | style=\"width:50%; padding:0 1em; background:#f5fffa; border:1px solid #ccc;\" id=mf-sow|  |}  == Verbreitung == .  ==Literatur== {{}}  ===Links===   [[Category:art]] ","suffix":""},{"content":"Synonym","row":3,"prefix":"__NOTOC__ =='''{{aut|Autorname}}, Jahr'''== <!---------------------------  Taxonavigation  --------------------------> {| style=\"width:100%; background:#fcfcfc; margin-top:2em;\"  |- valign=\"top\"  |style=\"width:50%; padding:0 1em 0 2em; color:#000; border:1px solid #ccc;\"|  {{Gattung}}<br />  == Status == <div class=\"float-right\" style=\"background-color:yellow; border: 2px solid #FF0000; padding: 0.5em; width: !100%;\"> {| style=\"width:100%; text-align:center; \" | |} <big>gilt als Synonym von    '''''[[Propterus]]'''''    {{aut|Agassiz}}, 1834'''</big> </div>  <!--------------------------- Platz für Abbildungen  --------------------------> | style=\"width:50%; padding:0 1em; background:#f5fffa; border:1px solid #ccc;\" id=mf-sow|   |} == Typen ==  '''Holotypus:''' [[Type#|]] .<br /> '''Typusfundort:''' .   == Etymologie == .  ==Literatur== {{}}[: ] ===Links=== * [http://researcharchive.calacademy.org/research/ichthyology/catalog/fishcatget.asp?spid=2 {{aut|Eschmeyer, W.N., Fricke, R. & Van der Laan, R.}} (eds.) {{CURRENTYEAR}}. ''Catalog of Fishes'' electronic version]<br />   [[Category: taxa]] [[Category: taxa]] [[Category: taxa]] [[Category: Synonym]] ","suffix":""},{"content":"Gattung","row":3,"prefix":"__NOTOC__ =='''{{aut|Autoren}}, Jahr'''== <!---------------------------  Taxonavigation  --------------------------> {| style=\"width:100%; background:#fcfcfc; margin-top:2em;\"  |- valign=\"top\"  |style=\"width:50%; padding:0 1em 0 2em; color:#000; border:1px solid #ccc;\"|  {{Gattung}}  == Typusart == ''[[  <!--------------------------- Platz für Abbildungen  --------------------------> | style=\"width:50%; padding:0 1em; background:#f5fffa; border:1px solid #ccc;\" id=mf-sow|  |} == Arten ==  †{{splast|G|attung|art}} {{aut|Autor}}, Jahr<br />  == Etymologie == * ==Literatur== {{ , }}[: , <span style=\"color: red\">'''!!'''</span>]  ===Links=== * [http://researcharchive.calacademy.org/research/ichthyology/catalog/fishcatget.asp?tbl=genus&genid=0000 {{aut|Eschmeyer, W.N., Fricke, R. & Van der Laan, R.}} (eds.) {{CURRENTYEAR}}. ''Catalog of Fishes'' electronic version] * [http://www.fishbase.org/nomenclature/SpeciesList.php?genus={{BASEPAGENAME}} FishBase]  [[Category: taxa]] [[Category: taxa]] [[Category: taxa]] [[Category:Gattung]] ","suffix":""},{"content":"Familie","row":3,"prefix":"__NOTOC__ =='''{{aut|Autoren}}, Jahr'''== <!---------------------------  Taxonavigation  --------------------------> {| style=\"width:100%; background:#fcfcfc; margin-top:2em;\"  |- valign=\"top\"  |style=\"width:50%; padding:0 1em 0 2em; color:#000; border:1px solid #ccc;\"|  {{Familie}}  == Typusgattung == ''[[  <!--------------------------- Platz für Abbildungen  --------------------------> | style=\"width:50%; padding:0 1em; background:#f5fffa; border:1px solid #ccc;\" id=mf-sow|  |} == Zugehörige xxx ==  †''[[xxx]]'' {{aut|Autor}}, Jahr<br /> †[[xxx]] {{aut|Autor}}, Jahr<br />  ==Literatur== {{ , }}[: , <span style=\"color: red\">'''!!'''</span>] {{Van der Laan et al., 2014}}[: ] ===Links===   [[Category: taxa]] [[Category: taxa]] [[Category: taxa]] [[Category:höhere Taxa]] ","suffix":""},{"content":"Autor","row":3,"prefix":"'''{{BASEPAGENAME}}'''   * Institution/Adresse * E-mail  ==Beschriebene Taxa== {{taxa}}  ==Publikationen==","suffix":""},{"content":"Status","row":3,"prefix":"== Status == <div class=\"float-right\" style=\"background-color:yellow; border: 2px solid #FF0000; padding: 0.5em; width: !100%;\"> {| style=\"width:100%; text-align:center; \" | |} <big>gilt als Synonym von    '''''[[Propterus]]'''''    {{aut|Agassiz}}, 1834'''</big> </div>","suffix":""}];
headers = [];
nameOfTargetBox = "wpTextbox1";
toolbarCSS = "" + 
"        .buttonToolbar td" + 
"        {" + 
"            vertical-align: top;" + 
"        }" + 
"        .buttonToolbar .header" + 
"        {" + 
"            width: 1%;" + 
"            padding: 2px;" + 
"            vertical-align: center;" + 
"            white-space: nowrap;" + 
"        }" + 
"        .buttonToolbar button" + 
"        {" + 
"            width: auto;" + 
"            margin: 2px;" + 
"        }" + 
"    ";
setup();