MediaWiki:Extra-Editbuttons.js

From SpongePedia, the First SpongeBob Wiki.
Jump to: navigation, search

Note: After saving, 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: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Konqueror: Click Reload or press F5
  • Opera: Clear the cache in Tools → Preferences
var XEBOrder=[];
var attributes = ["imageFile","speedTip","tagOpen","tagClose","sampleText"];
var usersignature = '--\~\~\~\~';
var Isrc='http://de.spongepedia.org/skins/common/images/buttons/';
var BDict={
//'ID':['Bild','Tooltip','Vor Text','Nach Text','Beispiel'],
'A2':['headline2.png','First Heading','\n=== ',' ===','First Heading'],
'A3':['headline3.png','Minor Heading','\n==== ',' ====','Minor Heading'],
//Textformatierung
'U':['underline.png','Underlined Text','<u>','<\/u>','Underlined Text'],
'S':['strike.png','Striked Text','<s>','<\/s>','Striked Text'],
'SML':['small.png','Small Text','<small>','<\/small>','Small Text'],
'BIG':['big.png','Big Text','<big>','<\/big>','Big Text'],
'C':['center.png','Centered Text','<div style="text-align: center;">\n','\n<\/div>','Centered Text'],
'F':['color.png','Coloured Text','<span style="color: Farbe">','<\/span>','Coloured Text'],
'SUP':['sup.png','Raised Text','<sup>','<\/sup>','Raised Text'],
'SUB':['sub.png','Lowered Text','<sub>','<\/sub>','Lowered Text'],
'PRE':['pre.png','Preformatted Text','<pre>','<\/pre>','Preformatted Text'],
'COD':['code.png','Insert code','<code>','<\/code>','Code'],
'TT':['tt.png','Typewriter Text','<tt>','<\/tt>','Typewriter Text'],
//
'G':['gallery.png','Gallery','\n<gallery>\nDatei:55a SpongeBob.jpg|[[SpongeBob Schwammkopf]]\nDatei:PatrickStar.jpg|[[Patrick Star]]\nDatei:56b Thaddäus.jpg|[[Thaddäus Tentakel]]\n<\/gallery>','',''],
'T':['table.png','Table','\n{| class="wikitable" border="1" \n|- \n| 1 || 2\n|- \n| 3 || 4','\n|}\n',''],
//
'K':['category.png','Category','[[Category:',']]','Name of Category'],
'V':['template.png','Template','{{','}}','Name of Template'],
'EP':['episode.png','Episode','[[',' (Episode)|]]','Name of Episode'],
//Liste
'L1':['list.png','List','\n* Element A\n* Element B\n* Element C','',''],
'L2':['numlist.png','Numbered List','\n# Element 1\n# Element 2\n# Element 3','',''],
//
'BR':['br.png','Line Break (<br>)','<br>','',''],
'BR2':['br2.png','Line Break (<br />)','<br />','',''],
'KO':['comment.png','Hiden Comment','<!--','-->','Hidden Comment'],
'ST':['span.png','Marked Text','<span style="">','<\/span>','Marked Text'],
'NBS':['nbsp.png','Nonbreaking Space','&nbsp;','',''],
//
'L':['shift.png','Create a Tab',':','',':'],
'M':['blockquote.png','Quote','<blockquote style="border: 1px solid blue; padding: 2em;">\n','\n<\/blockquote>','Text'],
//
'W':['redirect.png','Redirect','#Redirect [[',']]','Ziel einfügen'],
'P':['sublink.png','Link to a paragraph','[[Page#',']]','Paragraph'],
//Zeichen
'CR':['copyright.png','Copyright','©','',''],
'AZ':['quotes.png','Quotation Marks','"','"','Text'],
'AP':['apostrophe.png','Apostrophe','’','',''],
'GS':['dash.png','Dash','–','',''],
//Vorlagen
'Y1':['noinclude.png','No Include','<noinclude>','<\/noinclude>','Text'],
'Y2':['includeonly.png','Include only','<includeonly>','<\/includeonly>','Text'],
//Abstimmungen
'VP':['pro.png','Pro','#{{pro}} ' + usersignature,'',''],
'VC':['contra.png','Contra','#{{contra}} ' + usersignature,'',''],
//
'X0':['bg.png','','','',''],
'X1':['bg.png','','','',''],
'X2':['bg.png','','','',''],
'X3':['bg.png','','','',''],
'X4':['bg.png','','','',''],
'X5':['bg.png','','','',''],
'X6':['bg.png','','','',''],
'X7':['bg.png','','','',''],
};

function addCustomButton(){
  var a = {};
  for (d in attributes) a[attributes[d]] = arguments[d];
  mwCustomEditButtons.push(a);
};

function initButtons(){
  var bc,d;
    if (typeof customEditButtons!='string') // can be modified
      XEBOrder="X0,A2,A3,U,S,SML,BIG,C,F,SUP,SUB,PRE,COD,TT,X1,G,T,X2,K,V,EP,L1,L2,X3,BR,BR2,KO,ST,NBS,X4,L,M,X5,W,P,X6,CR,AZ,AP,GS,X7,BK,ZI,FS,Y1,Y2,VP,VC".split(",");
    else if (customEditButtons.toLowerCase()=='all')
      for (b in BDict) XEBOrder.push(b);
    else XEBOrder=customEditButtons.split(",");

	for (b in BDict) BDict[b][0] = Isrc+BDict[b][0]; // // Add the start of the URL (Isrc) to the XEB buttons
	// If the user has defined any buttons then add them into the available button lists
	if (typeof myButtons=='object')
	  for (b in myButtons) BDict[b] = myButtons[b];	// custom user buttons
  // Add the media wiki standard buttons into the available buttons
	for (b in mwEditButtons) { // add standard buttons for full XEB order changing
		BDict[b]=[];
	//	for (d in mwEditButtons[b])
		for (d in attributes) BDict[b].push(mwEditButtons[b][attributes[d]]);
	}

	// Build the new buttons
	for (i=0;i<XEBOrder.length;i++) {
		bc = BDict[XEBOrder[i]];
		//try { // catch not existing button names
		addCustomButton(bc[0],bc[1],bc[2],bc[3],bc[4]);
		//}
		// catch(e) {continue}
	}
	// Remove the default buttons (if requested by the user)
	eraseButtons();
};


// Table generator
/** @author: originally from fr:user:dake
* @version: 0.2 */

function generateTable(caption, exhead, nbCol, nbRow, exfield, align){
  var code = "\n";
  code += '{| class="wikitable" ' + align + '\n';
    if (exfield) code += '!\n';
      for (i=1;i<nbCol+1;i++) code += '! FELD ' + i + '\n';
      var items = 0;
      for (var j=0;j<nbRow;j++){
    if (exfield) {
      items++;
      code += '|-\n! style="background: #FFDDDD;"|ITEM ' + items + '\n';
    }
    else code += '|-\n';
      for (i=0;i<nbCol;i++) code += '| Element\n';
	  }
    code += '|}\n';
    insertTags('','', code);
    editform.elements['wpSummary'].value+=' table+';
    return false
};

function popupTable(){
  var popup = window.open('about:blank','WPtable','height=200,width=300,scrollbars=yes');
  var javaCode = '<script type="text\/javascript">function insertCode(){'
  +'var caption = (document.paramForm.inputCaption.checked)?"\|\+ TABLE CAPTION \\n":""; '
  +'var exhead = (document.paramForm.inputHead.checked)?\'\|\- style=\"background: #DDFFDD;\"\\n\':""; '
  +'var row = parseInt(document.paramForm.inputRow.value); '
  +'var col = parseInt(document.paramForm.inputCol.value); '
  +'var exfield = document.paramForm.inputItems.checked; '
  +'var align = (document.paramForm.inputAlign.checked)?\'align="center"\':""; '
  +'window.opener.generateTable(caption,exhead,col,row,exfield,align); '
  +'window.close()}<\/script>';

  popup.document.write('<html><head><title>Tabelle erstellen<\/title>'
  + javaCode +'<\/head><body>'
  +'<form name="paramForm">'
  +'Anzahl der Reihen: <input type="text" name="inputRow" value="3" size="2" \/><p\/>'
  +'Anzahl der Spalten: <input type="text" name="inputCol" value="3" size="2" \/><p\/>'
  +'Tabelle zentrieren <input type="checkbox" name="inputAlign" \/><p\/>'
  +'<\/form">'
  +'<p><a href="javascript:insertCode()">Tabelle einfügen<\/a> &nbsp; |'
  +' &nbsp;<a href="javascript:self.close()">Schließen<\/a><\/p>'
  +'<\/body><\/html>');
  popup.document.close();
  return false
};

function extendButtons(){
  if(!(allEditButtons = document.getElementById('toolbar'))) return false;
  if(typeof editform == 'undefined')
  if(!(window.editform = document.editform)) return false;

  XEBOrder.getIndex = function (item){
  if(is_gecko) return this.indexOf(item);
  else //is IE (Opera < 9)
    for (var i=0;i < this.length;i++) if (this[i]==item) return Number(i);
   	return -1
    }
    var searchbox = allEditButtons.getElementsByTagName('span')[0];
    if (searchbox) allEditButtons.appendChild(searchbox) // pay Zocky/Search Box

    allEditButtons = allEditButtons.getElementsByTagName('img');

    var bu_len = mwEditButtons.length;
    var c=0;

  if(!allEditButtons.length) return false;
	
  // Tabelle
  if((c=XEBOrder.getIndex('T')) != -1) allEditButtons[bu_len+c].onclick=popupTable;

  // Weiterleitung
  c=XEBOrder.getIndex('W');
    if(c != -1)
      allEditButtons[bu_len+c].onclick=function(){
        if (a = window.prompt("Ziel der Weiterleitung", "")) {
        a = '\#WEITERLEITUNG \[\[' + a + '\]\]';
        }
      };

  if((c = XEBOrder.getIndex('X0')) != -1) allEditButtons[bu_len+c].width = 3;
  if((c = XEBOrder.getIndex('X1')) != -1) allEditButtons[bu_len+c].width = 3;
  if((c = XEBOrder.getIndex('X2')) != -1) allEditButtons[bu_len+c].width = 3;
  if((c = XEBOrder.getIndex('X3')) != -1) allEditButtons[bu_len+c].width = 3;
  if((c = XEBOrder.getIndex('X4')) != -1) allEditButtons[bu_len+c].width = 3;
  if((c = XEBOrder.getIndex('X5')) != -1) allEditButtons[bu_len+c].width = 3;
  if((c = XEBOrder.getIndex('X6')) != -1) allEditButtons[bu_len+c].width = 3;
  if((c = XEBOrder.getIndex('X7')) != -1) allEditButtons[bu_len+c].width = 3;
  if((c = XEBOrder.getIndex('X8')) != -1) allEditButtons[bu_len+c].width = 3;
  if((c = XEBOrder.getIndex('X9')) != -1) allEditButtons[bu_len+c].width = 3;
};

if ((wgAction=="edit") || (wgAction=="submit"))
  addOnloadHook(initButtons);

if(!wgIsArticle) // only if edit
  hookEvent("load", extendButtons);
Personal tools
Namespaces

Variants
Actions
Navigation
community
content
Toolbox