Jump to content

User:Voice of All/extraeditbuttons.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
/* <nowiki> */
//============================================================
// Extra toolbar options
//============================================================
//********WRITTEN BY User:MarkS********
//This is a modified copy of a script by User:MarkS for extra features added by User:Voice of All.

// This is based on the original code on Wikipedia:Tools/Editing tools

function InsertButtonsToToolBar()
{
//Strike-Out Button
mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": "http://upload.wikimedia.org/wikipedia/en/c/c9/Button_strike.png",
    "speedTip": "Strike",
    "tagOpen": "<s>",
    "tagClose": "</s>",
    "sampleText": "Strike-through text"}
//Left-Text Button
mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": "http://upload.wikimedia.org/wikipedia/en/e/ea/Button_align_left.png",
    "speedTip": "Left-Align",
    "tagOpen": "<div style='text-align: left; direction: ltr; margin-left: 1em;'>\n",
    "tagClose": "\n</div>",
    "sampleText": "Left-aligned text"}
//Center-Text Button
mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": "http://upload.wikimedia.org/wikipedia/en/5/5f/Button_center.png",
    "speedTip": "Center",
    "tagOpen": "<div style='text-align: center;'>\n",
    "tagClose": "\n</div>",
    "sampleText": "Centered text"}
//Line break button
mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": "http://upload.wikimedia.org/wikipedia/en/1/13/Button_enter.png",
    "speedTip": "Line break",
    "tagOpen": "<br />",
    "tagClose": "",
    "sampleText": ""}
//Superscript
mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": "http://upload.wikimedia.org/wikipedia/en/8/80/Button_upper_letter.png",
    "speedTip": "Superscript",
    "tagOpen": "<sup>",
    "tagClose": "</sup>",
    "sampleText": "Superscript text"}
//Subscript
mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": "http://upload.wikimedia.org/wikipedia/en/7/70/Button_lower_letter.png",
    "speedTip": "Subscript",
    "tagOpen": "<sub>",
    "tagClose": "</sub>",
    "sampleText": "Subscript text"}
//Small Text
mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": "http://upload.wikimedia.org/wikipedia/en/5/58/Button_small.png",
    "speedTip": "Small",
    "tagOpen": "<small>",
    "tagClose": "</small>",
    "sampleText": "Small Text"}
//Comment
mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": "http://upload.wikimedia.org/wikipedia/en/3/34/Button_hide_comment.png",
    "speedTip": "Insert hidden Comment",
    "tagOpen": "<!-- ",
    "tagClose": " -->",
    "sampleText": "Comment"}
//Gallery
mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": "http://upload.wikimedia.org/wikipedia/en/1/12/Button_gallery.png",
    "speedTip": "Insert a picture gallery",
    "tagOpen": "\n<gallery>\n",
    "tagClose": "\n</gallery>",
    "sampleText": "Image:FileName.jpg|Caption1\\Image:FileName2.jpg|Caption2"}
//Secondary Headline
mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": "http://upload.wikimedia.org/wikipedia/en/e/e9/Button_headline2.png",
    "speedTip": "Secondary headline",
    "tagOpen": "\n===",
    "tagClose": "===",
    "sampleText": "Secondary headline"}
//Tabs
mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": "http://upload.wikimedia.org/wikipedia/en/8/8e/Button_shifting.png",
    "speedTip": "Insert tab(s)",
    "tagOpen": ":",
    "tagClose": "",
    "sampleText": ":"}
//Block Quote
mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": "http://upload.wikimedia.org/wikipedia/en/f/fd/Button_blockquote.png",
    "speedTip": "Insert block of quoted text",
    "tagOpen": "<blockquote style='border: 1px solid blue; padding: 2em;'>\n",
    "tagClose": "\n</blockquote>",
    "sampleText": "Block quote"}
//Colour
mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": "http://upload.wikimedia.org/wikipedia/en/1/1e/Button_font_color.png",
    "speedTip": "Insert colored text",
    "tagOpen": "<span style='color: ColorName'>",
    "tagClose": "</span>",
    "sampleText": "Span of text"}
//Code
mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": "http://upload.wikimedia.org/wikipedia/en/2/23/Button_code.png",
    "speedTip": "Insert code",
    "tagOpen": "<code>",
    "tagClose": "</code>",
    "sampleText": "Code"}
//Sub-Link
mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": "http://upload.wikimedia.org/wikipedia/en/9/93/Button_sub_link.png",
    "speedTip": "Insert link to sub-page",
    "tagOpen": "[[Page#",
    "tagClose": "]]",
    "sampleText": "Sub_page"}
//Definition List
mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": "http://upload.wikimedia.org/wikipedia/en/d/d3/Button_definition_list.png",
    "speedTip": "Insert definition list",
    "tagOpen": "\n; ",
    "tagClose": " : ",
    "sampleText": "Insert text"}
//Template button
mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": "http://upload.wikimedia.org/wikipedia/commons/3/3b/Button_template_alt.png",
    "speedTip": "Template",
    "tagOpen": "{{",
    "tagClose": "}}",
    "sampleText": "Template name"}
//Category button
mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": "http://upload.wikimedia.org/wikipedia/commons/5/5a/Button_category_alt.png",
    "speedTip": "Category",
    "tagOpen": "[[Category:",
    "tagClose": "]]",
    "sampleText": "Category title"}
//Reference link button
mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": "http://upload.wikimedia.org/wikipedia/commons/7/79/Button_reflink.png",
    "speedTip": "<ref>",
    "tagOpen": "<ref>",
    "tagClose": "</ref>",
    "sampleText": "Insert reference material"}
//Reference button
mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": "http://upload.wikimedia.org/wikipedia/commons/a/a0/Button_references_alt.png",
    "speedTip": "Reference footer",
    "tagOpen": "<references/>",
    "tagClose": "",
    "sampleText": ""}
}
addOnloadHook( InsertButtonsToToolBar );

//============================================================
// Table generator
//============================================================

/**
 *
 * English: Generate an array using Mediawiki syntax
 *
 * @author: fr:user:dake (language conversion and  new options added by en:user:Voice of All)
 * @version: 0.1
 */
 
function generateTableau(nbCol, nbRow, border, cborder, styleHeader, styleLine, exfield, align)
{
	var code = "\n";
	if (styleHeader==1) {
                code += '{| border="' + border + '" align="' + align + '" style="text-align: center;"\n';
                code += "|'''TABLE NAME'''\n";
		code += '{{' + 'Standard table|' + cborder + '|#cccccc}}\n';
	} else {
		code += '{| border="' + cborder + '" align="' + align + '" style="text-align: center;"\n';
		code += '|+\n';
	}
	
        if (exfield==true) code += '!\n';
	
        for (var i=1;i<nbCol+1;i++) code += '! style="background: #BBEEFF;"|FIELD ' + i + '\n';

        var items = 0;
	for (var j=0;j<nbRow;j++) {
		if ((j+1)%2==0 && styleLine==1 && exfield==true) {
                        items+=1;
			code += '|-bgcolor="#EFEFEF"\n'
			code += '! style="background: #FFBBBB;"|ITEM ' + items + '\n';
		}
                   else if ((j+1)%2==0 && styleLine==1 && exfield==false) {
			code += '|-bgcolor="#EFEFEF"\n'
		}  else if (exfield==true) {	
                        items+=1;	
			code += '|-----\n'
			code += '! style="background: #FFBBBB;"|ITEM ' + items + '\n';
		}
                  else if (exfield==false) {		
			code += '|-----\n'
		}
		
		for (var i=0;i<nbCol;i++) code += '| element\n';
	}
	
	if (styleHeader==1) code += '|}\n';
	else code += '|+\n';
	code += '|}\n';
	insertTags('','', code); 
}

/**
 *
 * English: Open a popup with parameters to generate an array. 
 * The number of rows/columns can be modified. Some additional
 * parameters are related to templates available on :fr
 *
 * @author: fr:user:dake
 * @version: 0.1
 */
 
function popupTable()
{
  var popup = window.open('','name','height=400,width=500,scrollbars=yes');
  
  javaCode =  '<script type="text\/javascript">function insertCode(){';
  javaCode += 'var row = parseInt(document.paramForm.inputRow.value); '
  javaCode += 'var col = parseInt(document.paramForm.inputCol.value); '
  javaCode += 'var bord = parseInt(document.paramForm.inputBorder.value); '
  javaCode += 'var cbord = parseInt(document.paramForm.inputCBorder.value); '
  javaCode += 'var styleHeader = document.paramForm.inputHeader.checked; '
  javaCode += 'var styleLine = document.paramForm.inputLine.checked; '
  javaCode += 'var exfield = document.paramForm.inputItems.checked; '
  javaCode += 'var align = document.paramForm.inputAlign.value; '
  javaCode += 'window.opener.generateTableau(col,row,bord,cbord,styleHeader,styleLine,exfield,align); '
  javaCode += "alert('Table created! Note that the text \"Standard table\" must remain.'); "
  javaCode += 'window.close(); '
  javaCode += '}<\/script>';
  
  popup.document.write('<html><head><title>Make table</title>');
  popup.document.write('<script type="text\/javascript" src="\/skins-1.5\/common\/wikibits.js"><!-- wikibits js --><\/script>');
  popup.document.write('<style type="text\/css" media="screen,projection">/*<![CDATA[*/ @import "\/skins-1.5\/monobook\/main.css?5"; /*]]>*/<\/style>');
  popup.document.write(javaCode); 
  popup.document.write('</head><body>');
  popup.document.write('<p>Enter the table parameters: </p>');
  popup.document.write('<form name="paramForm">');
  popup.document.write('Table alignment: <input type="text" name="inputAlign" value="center" ><p>');
  popup.document.write('Number of rows: <input type="text" name="inputRow" value="3" ><p>');
  popup.document.write('Number of columns: <input type="text" name="inputCol" value="3" ><p>');
  popup.document.write('Table border style (number): <input type="text" name="inputBorder" value="1" ><p>');
  popup.document.write('Cell border style (number): <input type="text" name="inputCBorder" value="0" ><p>');
  popup.document.write('<input type="checkbox" name="inputHeader" checked="1" > Table header ' + ' ');
  popup.document.write(' ' + ' <input type="checkbox" name="inputLine" checked="1" > Alternating grey lines<p>');
  popup.document.write('Item column: <input type="checkbox" name="inputItems" ><p>');
  popup.document.write('</form">');
  popup.document.write('Note:<i> The default table consist of matrix suitable for fields and values only. Check "Item column" to allow for the table to have fields, items, and values.</i><p>');
  popup.document.write('Note:<i> You cannot set the "Table border style" if "Table header" is not checked.</i><p>');
  popup.document.write('<p><a href="javascript:insertCode()"> Insert table into window</a></p>');
  popup.document.write('<p><a href="javascript:self.close()"> Close (cancel)</a></p>');
  popup.document.write('</body></html>');
  popup.document.close();
}

//Ressemble à la fonction de /skins-1.5/commons/wikibits.js pour insérer un autre lien que insertTags
function marque_tab()
{
 var toolbar = document.getElementById('toolbar');
 if (!toolbar) return false;
 
 var textbox = document.getElementById('wpTextbox1');
 if (!textbox) return false;
 
 if (!document.selection && textbox.selectionStart == null)
 return false;
 
 var image = document.createElement("img");
 image.width = 23;
 image.height = 22;
 image.src = 'http://upload.wikimedia.org/wikipedia/fr/0/04/Button_array.png';
 image.border = 0;
 image.alt = 'Table';
 image.title = 'Make table';
 image.style.cursor = "pointer";
 image.onclick = function() {
   popupTable();
   return false;
 }
 toolbar.appendChild(image);
}

addOnloadHook(marque_tab);
/* </nowiki> */