MediaWiki:Common.js
Aus WORLDFISH WIKI
Version vom 5. März 2019, 21:15 Uhr von Web16 (Diskussion | Beiträge)
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); }); } } buttonList = [{"content":"#redirect","row":1,"prefix":"#redirect[[","suffix":"]]"},{"content":"(doi+)","row":1,"prefix":"[ (doi)]{{subst:","suffix":"reftemp}}"},{"content":"subst:reftemp","row":1,"prefix":"{{subst:","suffix":"reftemp}}"},{"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":"''[[ ]]''","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]]"}]; 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();