User:MarkS/XEB.js

// //============================================================ // en: ADD SOME EXTRA BUTTONS TO THE EDITPANEL // de: FÜGE NEUE BUTTON IN DIE WERKZEUGLEISTE //============================================================ // Vorschläge für neue Buttons werden gerne entgegengenommen // Die Reihenfolge und Anzahl der Buttons ist über die (alphabetische) Variable XEBOrder wählbar.

//================================ //Control Variables // //rmEditButtons - Removes standard toolbar buttons //XEBOrder - The order in which the buttons are displayed

//fills the variable mwCustomEditButtons (s. function in /wikibits.js), with buttons for the Toolbar function addCustomButton(imageFile, speedTip, tagOpen, tagClose, sampleText){ mwCustomEditButtons.push({ "imageFile": imageFile,  "speedTip": speedTip,  "tagOpen": tagOpen,  "tagClose": tagClose,  "sampleText": sampleText}); }

if (typeof usersignature == 'undefined') var usersignature = '-- \~\~\~\~';

var Isrc='http://upload.wikimedia.org/wikipedia/commons/';

// English Wikipedia creates 11 extra buttons which are stored in mwCustomEditButtons // rather than mwEditButtons. However, there is no guarantee it will always be 11 // so we count them here. var enExtraButtons=mwCustomEditButtons.length;

var BDict={ 'A':['e/e9/Button_headline2.png','Secondary headline','\n===','===','Secondary headline'], 'B':['1/13/Button_enter.png','Line break',' ',,], 'C':['5/5f/Button_center.png','Center',' \n','\n<\/div>','Centred text'], 'D':['e/ea/Button_align_left.png','Left-Align',' \n','\n<\/div>','Left-aligned text'], 'D1':['a/a5/Button_align_right.png','Right-Align',' \n','\n<\/div>','Right-aligned text'], 'E':['0/04/Button_array.png','Table','\n{| class="wikitable" \n|- \n| 1 || 2\n|- \n| 3 || 4','\n|}\n',''], 'F':['1/1e/Button_font_color.png','Insert coloured text','Coloured text<\/span>','ColourName'], 'FS':['1/1b/Button_miss_signature.png','Unsigned post',,,'user name or IP'], 'G':, 'H':['7/74/Button_comment.png','Comment',"",'Comment'], 'I1':['6/6a/Button_sup_letter.png','Superscript',' ','<\/sup>','Superscript text'], 'I2':['a/aa/Button_sub_letter.png','Subscript',' ','<\/sub>','Subscript text'], 'J1':['5/58/Button_small.png','Small',' ','<\/small>','Small Text'], 'J2':['5/56/Button_big.png','Big text',' ','<\/big>','Big text'], 'K':['b/b4/Button_category03.png','Category',"",'Category name'], 'L':['8/8e/Button_shifting.png','Insert tab(s)',':','',':'], 'M':['f/fd/Button_blockquote.png','Insert block of quoted text','\n','\n<\/blockquote>','Block quote'], 'N':['4/4b/Button_nbsp.png','nonbreaking space',' ',,], 'O':['2/23/Button_code.png','Insert code',' ','<\/code>','Code'], 'P':['3/3c/Button_pre.png','Pre formatted Text',' ','<\/pre>','Pre formatted text'], 'P1':['9/93/Button_sub_link.png','Insert link to sub-page','','/Sub_Page','Page'], 'Q':['d/d3/Button_definition_list.png','Insert definition list','\n; ','\n: Item 1\n: Item 2','Definition'], 'R':['7/79/Button_reflink.png','Insert a reference',' ','Reference material'], 'R3':['1/1a/Button_reflink_advanced_3.png','No reference material',,'"/>',], 'R4':['9/9a/Button_references.png','Reference footer',"\n==Notes==\n\n\n \n ",,], 'S':['c/c9/Button_strike.png','Strikeout',' ','<\/s>','Struck out text'], 'T':['e/eb/Button_plantilla.png','Template',,'Template name'], 'TS':['a/a4/TableStart.png','Start a table','{|',,], 'TC':['7/71/TableCell.png','Table cell','|',,], 'TE':['0/06/TableEnd.png','End a table',,'|}',], 'TR':['4/4c/TableRow.png','Start a table row','|-',,], 'T1':['3/30/Tt_icon.png','Teletype text','','<\/tt>','Teletype Text'], 'TL':['3/37/Button_tl_template.png','Template link',"",,'Template name'], 'U':['f/fd/Button_underline.png','Underlined'," ","<\/u>",'Underlined text'], 'V':['c/c8/Button_redirect.png','Redirect',"#REDIRECT ","",'Article Name'], 'W':['8/88/Btn_toolbar_enum.png','Numbering',"\n# ","\n# Element 2\n# Element 3",'Element 1'], 'X':['1/11/Btn_toolbar_liste.png','List',"\n* ","\n* Element B\n* Element C",'Element A'], 'Y1':['c/ce/Button_no_include.png','No Include'," ","<\/noinclude>",'Text'], 'Y2':['7/79/Button_include.png','Include only'," ","<\/includeonly>",'Text'], 'Z':['3/35/Button_substitute.png','Substitute',"",'Template'], 'AI':, 'GEO':['b/b8/Button_Globe.png','Geo location',"","",""] };

var XEBOrder2=[]; if (typeof XEBOrder!='string') // can be modified XEBOrder2="A,B,D,C,D1,F,U,S,I1,I2,J1,E,G,Q,W,X,K,L,M,H,O,R,T,V".split(","); else if (XEBOrder.toLowerCase=='all') for (b in BDict) XEBOrder2.push(b); else XEBOrder2=XEBOrder.toUpperCase.split(",");

$(initButtons); if(!wgIsArticle)// only if edit { 	hookEvent("load", extendButtons); }

function initButtons{

var bc,d;

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]) BDict[b].push(mwEditButtons[b][d]); }

// Build the new buttons

for (i=0;i<XEBOrder2.length;i++) { bc = BDict[XEBOrder2[i]];

//Check if bc is an object // - protects if user specified a non-existant buttons // - IE causes a javascript error when viewing a page if(typeof bc=='object') {			addCustomButton(bc[0],bc[1],bc[2],bc[3],bc[4]); }	}

// Remove the default buttons (if requested by the user) eraseButtons; }

/** en: Removes arbitrary standard buttons from the toolbar * @author: de:User:Olliminatore * @version: 0.1 (01.10.2006) **/

function eraseButtons{

//Remove the buttons the user doesn't want

if(typeof rmEditButtons!='object') return;

if (typeof rmEditButtons[0] == 'string' && rmEditButtons[0].toLowerCase == 'all') {		mwEditButtons=[]; for(i=0;i=0 && n=n) mwEditButtons[x] = mwEditButtons[x+1]; }		mwEditButtons.pop; }		//Extra buttons in English Wikipedia n=n-mwEditButtons.length; if(n>0 && n=n) mwCustomEditButtons[x] = mwCustomEditButtons[x+1]; }		mwCustomEditButtons.pop; }	} };

//Function: //	sortit //Purpose: //	Used to sort the rmEditButtons array into descending order function sortit(a,b){ return(b-a) }

// Adds extended onclick-function to some buttons function extendButtons{ if(!(allEditButtons = document.getElementById('toolbar'))) return false; if(typeof editform != 'undefined') if(!(window.editform = document.forms['editform'])) return false; XEBOrder2.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; // own signature if (bu_len>0){ if(typeof rmEditButtons=='object' && rmEditButtons.pop==10) c=1; mwEditButtons[bu_len-2+c].tagOpen=usersignature; if(usersignature != '-- \~\~\~\~') allEditButtons[bu_len-2+c].src=Isrc+'d/d1/Button_mysignature.png'; }	// table c=XEBOrder2.getIndex('E'); if(c != -1) allEditButtons[bu_len+c].onclick=XEBPopupTable; // ref c=XEBOrder2.getIndex('R'); if(c != -1) allEditButtons[bu_len+c].onclick=XEBPopupRef;

// redirect c=XEBOrder2.getIndex('V');

if(c != -1) allEditButtons[bu_len+c].onclick=function{ var a='#REDIRECT \[\['+prompt("Wohin soll der Redirect\?")+'\]\]'; editform.elements['wpTextbox1'].value=a; editform.elements['wpSummary'].value=a; editform.elements['wpWatchthis'].checked=false }; };

//========================================================================================================== // General purpose popup code //==========================================================================================================

function getXEBPopupDiv {	XEBMainDiv= document.getElementById("XEB"); if(XEBMainDiv==null){ XEBMainDiv=document.createElement("div"); document.body.appendChild(XEBMainDiv); XEBMainDiv.id="XEB"; }

me= document.getElementById("XEBPopup"); if(!(me==null))return me; me=document.createElement("div"); XEBMainDiv.appendChild(me);

me.id="XEBPopup"; me.style.position='absolute'; me.display='none'; me.visibility='hidden'; me.onmouseout=CheckHideXEBPopup; return me; }

//Function: //	CheckHideXEBPopup //Purpose: //	Looks at the cursor position and if it has moved outside the popup it will close the popup //Called: //	When the onMouseEvent is fired on the popup

function CheckHideXEBPopup(e){ m= document.getElementById("XEBmnu"); if(is_gecko) {		var x=e.clientX + window.scrollX; var y=e.clientY + window.scrollY;; s=window.getComputedStyle(m,""); ph=s.height; ph=Number(ph.substring(0,ph.length-2)); }	else {		var x=event.clientX+ document.documentElement.scrollLeft + document.body.scrollLeft; var y=event.clientY+ document.documentElement.scrollTop + document.body.scrollTop; s=m.currentStyle; ph=m.offsetHeight; }	pl=curPopup.x;	pt=curPopup.y;	pw=m.style.width; pw=Number(pw.substring(0,pw.length-2)); if(x>(pl+2)&&x<(pl+pw-5)&&y>(pt+2)&&y<(pt+ph-5))return;

hideXEBPopup; }

function hideXEBPopup{ m= document.getElementById("XEBmnu"); m.style.visibility="hidden"; m.display="none"; m.innerHTML=""; }

//============================================================================= // Popup: Table //=============================================================================

function XEBPopup(x,y) {	// Make sure the popup can appear on the screen winW=(is_gecko)?window.innerWidth:document.body.offsetWidth; if((winW-this.width)"; mt=mt+text; mt=mt+" "; this.div.innerHTML=mt; } XEBPopup.prototype.width=250; XEBPopup.prototype.setInnerHTML=setInnerHTML;

var curPopup;

function GetPos(e) { //	if(is_gecko) //	{ //this.x=e.clientX-10+ window.scrollX; //this.y=e.clientY-10+ window.scrollY;; this.x=e.clientX-10+ document.documentElement.scrollLeft + document.body.scrollLeft; this.y=e.clientY-10+ document.documentElement.scrollTop + document.body.scrollTop; //	} //	else //	{ //		this.x=event.clientX-10+ document.documentElement.scrollLeft + document.body.scrollLeft; //		this.y=event.clientY-10+ document.documentElement.scrollTop + document.body.scrollTop; //	} }

function XEBPopupTable(e){ m=new GetPos(e||event);

curPopup=new XEBPopup(m.x,m.y); //me=curPopup.div;

mt=' Enter the table parameters below: <\/p>' +'' +'Table caption: ' +'Table alignment: center' +'Table headline: colored' +'Number of rows: <p\/>' +'Number of columns: <input type="text" name="inputCol" value="3" size="2"><p\/>' //+'Alternating grey lines: <input type="checkbox" name="inputLine" checked="1" ><p\/>' +'Item column: <input type="checkbox" name="inputItems" ><p\/>' +'<\/form">'		+'<i>The default table allows for fields and values only.<\/i><p\/>'		+'Check "Item column" to allow for the table to have fields, items, and values.<\/i><p\/>'		+' <button onClick="javascript:insertCode">Insert '		+'<button onClick="hideXEBPopup">Cancel '

curPopup.setInnerHTML(mt);

return true; }

function insertCode{ f=document.paramForm; var caption = (f.inputCaption.checked)?"|+ TABLE CAPTION \n":""; var exhead = (f.inputHead.checked)?'|- style="background: #DDFFDD;"\n':""; var nbRow = parseInt(f.inputRow.value); var nbCol = parseInt(f.inputCol.value); var exfield = f.inputItems.checked; var align = (f.inputAlign.checked)?'align="center"':""; hideXEBPopup; generateTable(caption, exhead, nbCol, nbRow, exfield, align); }

//============================================================ // Table generator //============================================================ /** en: Generate an array using Mediawiki syntax * @author: originally from fr:user:dake * @version: 0.2 */ function generateTable(caption, exhead, nbCol, nbRow, exfield, align){ var code = "\n"; code += '{| ' + align + '\n' // en: class="wikitable" + caption + exhead; 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 XEBPopupRef(e){ m=new GetPos(e||event);

curPopup=new XEBPopup(m.x,m.y);

mt=' Enter the reference parameters below: <\/p>' +'<form name="paramForm">' +'Name:<input type="text" name="refName" value="" size="10"><p\/>' +'Material:<input type="text" name="refMaterial" value="" size="20">' +'<\/form">'		+' <button onClick="javascript:insertRef">Insert '		+'<button onClick="hideXEBPopup">Cancel ';

curPopup.setInnerHTML(mt); document.paramForm.refName.focus; return true; }

function insertRef{ f=document.paramForm; var refName = f.refName.value; var refMaterial=f.refMaterial.value; hideXEBPopup; var code='<ref'; code+=(refName!='')?' name="'+refName+"'>":">"; 	code+=f.refMaterial+'<\/ref>';

insertTags(,, code); editform.elements['wpSummary'].value+=' Ref+'; return false; }

//======================================================================= // Other functions //=======================================================================

function bug(msg) {	if(wgUserName=='MarkS')alert(msg); }

//