User:Karl Dickman/tablebutton.js

//============================================================ // 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 generateTable(nbCol, nbRow, exfield) {       code = '\n{| class="wikitable"\n'; code += "|+ TABLE CAPTION \n"; if (exfield==true) code += '!\n'; for (var i=1;i<nbCol+1;i++) code += '! FIELD ' + i + '\n';

var items = 0; for (var j=0;j<nbRow;j++) {                  if (exfield==true) { items++; code += '|-\n' code += '! ITEM ' + items + '\n'; } else if (exfield==false) { code += '|-\n' }                   for (var i=0;ifunction insertCode{'; javaCode += 'var row = parseInt(document.paramForm.inputRow.value); '; javaCode += 'var col = parseInt(document.paramForm.inputCol.value); '; javaCode += 'var exfield = document.paramForm.inputItems.checked; '; javaCode += 'window.opener.generateTable(col,row,exfield);'; javaCode += 'window.close; ' javaCode += '}<\/script>'; popup.document.write('  Make table '); popup.document.write('<\/script>'); popup.document.write('/*<![CDATA[*/ @import "\/skins-1.5\/wikistandard\/main.css?5"; /*]]>*/<\/style>'); popup.document.write(javaCode); popup.document.write(' '); popup.document.write(' Enter the table parameters below: '); popup.document.write(''); popup.document.write('Number of rows:  '); popup.document.write('Number of columns:  '); popup.document.write('Item column:  '); popup.document.write(' '); popup.document.write('The default table contains one row of fields. '); popup.document.write('Check "Item column" to give the table a field row and an item column. '); popup.document.write('  Insert table    |'); popup.document.write('   Cancel '); popup.document.write(' '); popup.document.close; }

//Ressemble à la fonction de /skins-1.5/commons/wikibits.js pour insérer un autre lien que insertTags function table_button { 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/commons/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); }

// Changes made on Sat, 30 Sep 2006 20:28 UTC, seems to work on IE addOnloadHook(table_button);