MediaWiki:Common.js/edit.js: Difference between revisions

From OniGalore
Jump to navigation Jump to search
(making another URL protocol-relative)
(dropping in "dev" version from 2012 which apparently was supposed to fix problems caused by MW update)
Line 1: Line 1:
/* <pre> */
/* Version: 3.1
//<source lang="JavaScript">
* ============================================================
* en: ADD SOME EXTRA BUTTONS TO THE EDITPANEL
* de: FÜGE NEUE BUTTON IN DIE WERKZEUGLEISTE
* pt: ACRESCENTA ALGUNS BOTÕES EXTRAS AO PAINEL DE EDIÇÃO
* ============================================================
* 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
*
* window.rmEditButtons - Removes standard toolbar buttons
* window.XEBOrder - The order in which the buttons are displayed
* window.myButtons - Add user defined buttons
*/


//Version: 3.1
mw.loader.load( '//en.wikipedia.org/w/index.php?title=User:MarkS/XEB/live.css&action=raw&ctype=text/css', 'text/css' );
//============================================================
// ADD SOME EXTRA BUTTONS TO THE EDIT TOOLBAR
//============================================================


//================================
if (typeof XEBPopups === 'undefined') {
//Control Variables
XEBPopups = true;
//
}
//rmEditButtons - Removes standard toolbar buttons
if (typeof XEBHideDelay === 'undefined') {
//XEBOrder - The order in which the buttons are displayed
// Time before the popup disappears after the mouse moves out
 
window.XEBHideDelay = 0.5;
importStylesheetURI( '//wiki.oni2.net/MediaWiki:live.css&action=raw&ctype=text/css' );
}
 
if (typeof XEBExtendEditSummary === 'undefined') {
if(typeof XEBPopups== 'undefined')XEBPopups=true;
// Is the edit summary extended after a popup
if(typeof XEBHideDelay== 'undefined')XEBHideDelay=0.5; //Time before the popup disappears after the mouse moves out
window.XEBExtendEditSummary = true;
if(typeof XEBExtendEditSummary == 'undefined')XEBExtendEditSummary=true; // Is the edit summary extended after a popup
}


//fills the variable mwCustomEditButtons (s. function in /wikibits.js), with buttons for the Toolbar 
if (typeof usersignature === 'undefined') {
function addCustomButton(imageFile, speedTip, tagOpen, tagClose, sampleText){
var usersignature = '-- ~~' + '~~';
mwCustomEditButtons.push({
  "imageFile": imageFile,
  "speedTip": speedTip,
  "tagOpen": tagOpen,
  "tagClose": tagClose,
  "sampleText": sampleText});
}
}


if (typeof usersignature == 'undefined') var usersignature = '-- \~\~\~\~';
var Isrc = '//upload.wikimedia.org/wikipedia/commons/';


var Isrc='//wiki.oni2.net/w/images/';
var BDict = {
'A': ['e/e9/Button_headline2.png', 'Secondary headline', '\n===', '===', 'Secondary headline'],
'B': ['1/13/Button_enter.png', 'Line break', '<br />', '', ''],
'C': ['5/5f/Button_center.png', 'Center', '<div style="text-align: center;">\n', '\n<\/div>', 'Centred text'],
'D': ['e/ea/Button_align_left.png', 'Left-Align', '<div style="text-align: left; direction: ltr; margin-left: 1em;">\n', '\n<\/div>', 'Left-aligned text'],
'D1': ['a/a5/Button_align_right.png', 'Right-Align', '<div style="text-align: right; direction: ltr; margin-left: 1em;">\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', '<span style="color: ', '">Coloured text<\/span>', 'ColourName'],
'FS': ['1/1b/Button_miss_signature.png', 'Unsigned post', '<small><span class="autosigned">— Preceding [[Wikipedia:Signatures|unsigned]] comment added by [[User:', '|', ']] ([[User talk:', '|talk]] • [[Special:Contributions/', '|contribs]]) date</span></small><!-- Template:Unsigned -->', 'user name or IP'],
'G': ['9/9e/Btn_toolbar_gallery.png', 'Picture gallery', "\n<gallery>\nImage:", "|[[M63]]\nImage:Mona Lisa.jpg|[[Mona Lisa]]\nImage:Truite arc-en-ciel.jpg|Eine [[Forelle ]]\n<\/gallery>", 'M63.jpg'],
'H': ['7/74/Button_comment.png', 'Comment', "<!--", "-->", 'Comment'],
'I1': ['6/6a/Button_sup_letter.png', 'Superscript', '<sup>', '<\/sup>', 'Superscript text'],
'I2': ['a/aa/Button_sub_letter.png', 'Subscript', '<sub>', '<\/sub>', 'Subscript text'],
'J1': ['5/58/Button_small.png', 'Small', '<small>', '<\/small>', 'Small Text'],
'J2': ['5/56/Button_big.png', 'Big text', '<big>', '<\/big>', 'Big text'],
'K': ['b/b4/Button_category03.png', 'Category', "[[Category:", "]]", 'Category name'],
'L': ['8/8e/Button_shifting.png', 'Insert tab(s)', ':', '', ':'],
'M': ['f/fd/Button_blockquote.png', 'Insert block of quoted text', '<blockquote style="border: 1px solid blue; padding: 2em;">\n', '\n<\/blockquote>', 'Block quote'],
'N': ['4/4b/Button_nbsp.png', 'nonbreaking space', '&nbsp;', '', ''],
'O': ['2/23/Button_code.png', 'Insert code', '<code>', '<\/code>', 'Code'],
'P': ['3/3c/Button_pre.png', 'Pre formatted Text', '<pre>', '<\/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', '<ref>', '<\/ref>', 'Insert reference material'],
'R1': ['7/79/Button_reflink.png', 'Start a reference', '<ref name="', '', 'Reference name'],
'R2': ['9/99/Button_reflink_advanced_2.png', 'Insert reference material', '">', '</ref>', 'Reference material'],
'R3': ['1/1a/Button_reflink_advanced_3.png', 'No reference material', '', '"/>', ''],
'R4': ['9/9a/Button_references.png', 'Reference footer', "\n==Notes==\n<!--See http://en.wikipedia.org/wiki/Wikipedia:Footnotes for an explanation of how to generate footnotes using the <ref(erences/)> tags-->\n<div class=\'references-small\'>\n<references/>\n</div>", '', ''],
'S': ['c/c9/Button_strike.png', 'Strikeout', '<s>', '<\/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>', '<\/tt>', 'Teletype Text'],
'TL': ['3/37/Button_tl_template.png', 'Template link', "{{subst:" + "tl|", '}}', 'Template name'],
'U': ['f/fd/Button_underline.png', 'Underlined', "<u>", "<\/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>", "<\/noinclude>", 'Text'],
'Y2': ['7/79/Button_include.png', 'Include only', "<includeonly>", "<\/includeonly>", 'Text'],
'Z': ['3/35/Button_substitute.png', 'Substitute', "{{subst:", "}}", 'Template'],
'AI': ['1/1c/Button_advanced_image.png', 'Advanaced Image', "[[Image:", "|thumb|right|px|Caption]]", 'FileName.jpg'],
'GEO': ['b/b8/Button_Globe.png', 'Geo location', "", "", ""],
'TALK': ['4/49/Button_talk.png', 'Add talk template', "", "", ""]
};


// English Wikipedia creates 11 extra buttons which are stored in mwCustomEditButtons
var XEBOrder2 = [];
//  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','Third-level headline','\n===','===','Secondary headline'],
'B':['1/13/Button_enter.png','Line break','<br />','',''],
'C':['f/f7/Button_align_center.png','Center-aligned text','<div style="text-align: center;">\n','\n<\/div>','Centered text'],
'D':['e/ea/Button_align_left.png','Left-aligned text','<div style="text-align: left; direction: ltr; margin-left: 1em;">\n','\n<\/div>','Left-aligned text'],
'D1':['a/a5/Button_align_right.png','Right-aligned text','<div style="text-align: right; direction: ltr; margin-left: 1em;">\n','\n<\/div>','Right-aligned text'],
'E':['7/79/Button_cmpl_table.png','Smart Table','\n{| class="wikitable" \n|- \n| 1 || 2\n|- \n| 3 || 4','\n|}\n',''],
'F':['1/1e/Button_font_color.png','Colored text','<span style="color: ','">Colored text<\/span>','ColorName'],
'FS':['6/6d/Button_unsigned.png','Unsigned post','{{subst:unsigned|','|date}}','user name or IP'],
'G':['1/12/Button_gallery.png','Image gallery',"\n<gallery>\nImage:","|[[M63]]\nImage:Mona Lisa.jpg|[[Mona Lisa]]\nImage:Truite arc-en-ciel.jpg|Eine [[Forelle ]]\n<\/gallery>",'M63.jpg'],
'H':['7/74/Button_comment.png','Comment',"<!--","-->",'Comment'],
'I1':['d/d6/Button_superscript.png','Superscript','<sup>','<\/sup>','Superscript text'],
'I2':['b/bf/Button_subscript.png','Subscript','<sub>','<\/sub>','Subscript text'],
'J1':['d/d5/Button_small_text.png','Small text','<small>','<\/small>','Small Text'],
'J2':['9/99/Button_big_text.png','Big text','<big>','<\/big>','Big text'],
'K':['1/11/Button_category.png','Category',"[[Category:","]]",'Category name'],
'L':['e/e2/Button_tab_in.png','Insert tab',':','',':'],
'M':['f/fd/Button_blockquote.png','Quoted text block','<blockquote style="border: 1px solid blue; padding: 2em;">\n','\n<\/blockquote>','Block quote'],
'N':['4/4b/Button_nbsp.png','Insert non-breaking space','&nbsp;','',''],
'O':['2/23/Button_code.png','Code block','<code>','<\/code>','Code'],
'P':['3/3c/Button_pre.png','Pre-formatted text block','<pre>','<\/pre>','Pre-formatted text'],
'P1':['2/2e/Button_subpage.png','Link to sub-page','[[','/Sub_Page]]','Page'],
'Q':['1/1f/Button_list_tab.png','Definition (tabbed) list','\n; ','\n: Item 1\n: Item 2','Definition'],
'R':['e/ef/Button_reflink_start.png','Insert a reference','<ref>','<\/ref>','Insert reference material'],
'R1':['5/5f/Button_reflink_smart.png','Reference Wizard','<ref name="','','Reference name'],
'R2':['c/cb/Button_reflink_footer.png','Insert reference footer',"<references/>",'',''],
'S':['c/c9/Button_strike.png','Strikeout text','<s>','<\/s>','Struck-out text'],
'T':['5/59/Button_template.png','Template','{{','}}','Template name'],
'TS':['a/a1/Button_table_start.png','Start a table','{|','',''],
'TC':['5/59/Button_table_cell.png','Table cell','|','',''],
'TE':['f/f0/Button_table_end.png','End a table','','|}',''],
'TR':['7/70/Button_table_row.png','Start a table row','|-','',''],
'T1':['8/82/Button_teletype.png','Teletype text','<tt>','<\/tt>','Teletype Text'],
'TL':['d/d3/Button_subst_tmpl.png','Template (substituted)',"{{subst:"+"tl|",'}}','Template name'],
'U':['f/fd/Button_underline.png','Underlined text',"<u>","<\/u>",'Underlined text'],
'V':['c/c8/Button_redirect.png','Redirect',"#REDIRECT [[","]]",'Article Name'],
'W':['5/50/Button_list_num.png','Numbered list',"\n# ","\n# Element 2\n# Element 3",'Element 1'],
'X':['f/fa/Button_list_bull.png','Bulleted list',"\n* ","\n* Element B\n* Element C",'Element A'],
'Y1':['d/d5/Button_noinclude.png','No include',"<noinclude>","<\/noinclude>",'Text'],
'Y2':['6/63/Button_includeonly.png','Include only',"<includeonly>","<\/includeonly>",'Text'],
'Z':['3/35/Button_substitute.png','Substituted page link',"{{subst:","}}",'Template'],
'AI':['c/cc/Button_adv_image.png','Advanced image',"[[Image:","|thumb|right|px|Caption]]",'FileName.jpg']
};


var XEBOrder2=[];




addOnloadHook(initButtons);
initButtons();
if(!wgIsArticle)// only if edit
if (!mw.config.get( 'wgIsArticle' )) {
{
// only if edit
if(XEBPopups)hookEvent("load", extendButtons);
if (XEBPopups) {
$(extendButtons);
}
}
}


function initButtons(){
function initButtons() {


var bc,d;
var bc, d, i, customTools = {};


if (typeof XEBOrder!='string') // can be modified
if (typeof XEBOrder !== 'string') {
XEBOrder2="0,1,U,F,D,C,D1,4,A,2,3,E,G,8,H,9".split(",");
// can be modified
else if (XEBOrder.toLowerCase()=='all')  
XEBOrder2 = 'A,D,C,D1,F,U,J1,E,G,Q,W,X,K,L,H,O,R,T'.split(',');
for (b in BDict) XEBOrder2.push(b);
} else if (XEBOrder.toLowerCase() === 'all') {
else XEBOrder2=XEBOrder.toUpperCase().split(",");
$.each(BDict, function( b, value ){
XEBOrder2.push(b);
});
} else {
XEBOrder2 = XEBOrder.toUpperCase().split(',');
}


for (b in BDict) BDict[b][0] = Isrc+BDict[b][0]; // // Add the start of the URL (Isrc) to the XEB buttons
$.each(BDict, function( b, value ){
// If the user has defined any buttons then add them into the available button lists  
// Add the start of the URL (Isrc) to the XEB buttons
BDict[b][0] = Isrc + BDict[b][0];
});
// If the user has defined any buttons then add them into the available button lists
if (typeof myButtons === 'object') {
$.each(myButtons, function( b, value ){
// custom user buttons
BDict[b] = myButtons[b];
});
}


if (typeof myButtons=='object')
        mw.loader.using( 'user.options', function () {
  for (b in myButtons) BDict[b] = myButtons[b]; // custom user buttons
if ( mw.user.options.get('usebetatoolbar') ) {
// Add the media wiki standard buttons into the available buttons
// Use the enhanced edit toolbar
mw.loader.using( 'ext.wikiEditor.toolbar', function () {
$(function(){
// Build the new buttons
for (i = 0; i < XEBOrder2.length; i++) {
bc = BDict[XEBOrder2[i]];


for (b in mwEditButtons) { // add standard buttons for full XEB order changing
//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') {
customTools[ XEBOrder2[i] ] = {
label: bc[1],
type: 'button',
icon:  bc[0],
action: {
type: 'encapsulate',
options: {
pre: bc[2],
peri: bc[4],
post: bc[3]
}
}
};
}
}


// BDict[b]=[];
$('#wpTextbox1').wikiEditor( 'addToToolbar', {
BDict[b]=[mwEditButtons[b].imageFile,mwEditButtons[b].speedTip,mwEditButtons[b].tagOpen,mwEditButtons[b].tagClose,mwEditButtons[b].sampleText];
'sections': {
'extra': {
'type': 'toolbar',
'label': 'Extras'
}
},
'section': 'extra',
'groups': {
'my-buttons': {
'label': 'My buttons',
'tools': customTools
}
}
} );
});


// for (d in mwEditButtons[b]) BDict[b].push(mwEditButtons[b][d]);
} );
}
} else {
// Use the old edit toolbar
// Add the MediaWiki standard buttons into the available buttons
$.each(mw.toolbar.buttons, function( b, value ){
// add standard buttons for full XEB order changing
// BDict[b]=[];
BDict[b] = [ value.imageFile, value.speedTip, value.tagOpen, value.tagClose, value.sampleText];
 
// for (d in value) {BDict[b].push(value}[d]);
});


// Build the new buttons  
// Build the new buttons
for (i = 0; i < XEBOrder2.length; i++) {
bc = BDict[XEBOrder2[i]];


for (i=0;i<XEBOrder2.length;i++) {
//Check if bc is an object
bc = BDict[XEBOrder2[i]];
// - protects if user specified a non-existant buttons
// - IE causes a javascript error when viewing a page
if (typeof bc === 'object') {


//Check if bc is an object
//Call addButton from module mediawiki.action.edit
// - protects if user specified a non-existent button
mw.toolbar.addButton(bc[0], bc[1], bc[2], bc[3], bc[4] /* , imageId, selectText */ );
// - IE causes a javascript error when viewing a page
}
if(typeof bc=='object')
}
{


//Call addCustomButton in wikibits
// Remove the default buttons (if requested by the user)
addCustomButton(bc[0],bc[1],bc[2],bc[3],bc[4]);
eraseButtons();
}
}
}
        } );
 
// Remove the default buttons (if requested by the user)
eraseButtons();
}
}




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


function eraseButtons(){
function eraseButtons() {
var x, i, enExtraButtons;


//Remove the buttons the user doesn't want
//Remove the buttons the user doesn't want
        //Line below added so that we can use the defaults specified in XEBOrder2 above without duplicating the buttons that are already part of the toolbar -- Iritscen
if (typeof rmEditButtons !== 'object') {
        var rmEditButtons=["all"];
return;
}


if(typeof rmEditButtons!='object') return;
if (typeof rmEditButtons[0] === 'string' && rmEditButtons[0].toLowerCase() === 'all') {
// English Wikipedia creates 11 extra buttons which are stored in mwCustomEditButtons
// rather than mw.toolbar.buttons. However, there is no guarantee it will always be 11
// so we count them here.
enExtraButtons = window.mwCustomEditButtons.length;


if (typeof rmEditButtons[0] == 'string' && rmEditButtons[0].toLowerCase() == 'all')
mw.toolbar.buttons = [];
{
for (i = 0; i < enExtraButtons; i++) {
mwEditButtons=[];
window.mwCustomEditButtons.shift();
for(i=0;i<enExtraButtons;i++){mwCustomEditButtons.shift();}
}
}
}
//Sort the user's requests so we remove the button with the highest index first
//Sort the user's requests so we remove the button with the highest index first
//- This ensures we remove the buttons the user expects whatever order he requested the buttons in
//- This ensures we remove the buttons the user expects whatever order he requested the buttons in
rmEditButtons.sort(sortit);
window.rmEditButtons.sort(sortit);


//Remove individual buttons the user doesn't want  
//Remove individual buttons the user doesn't want
 
for (i = 0; i < rmEditButtons.length; i++) {
for(i=0;i<rmEditButtons.length;i++){
var n = rmEditButtons[i];
var n=rmEditButtons[i];
//Standard Wikimedia buttons
//Standard Wikimedia buttons
if(n>=0 && n<mwEditButtons.length){
if (n >= 0 && n < mw.toolbar.buttons.length) {
if(n<mwEditButtons.length){
if (n < mw.toolbar.buttons.length) {
var x = -1;
x = -1;
while((++x)<mwEditButtons.length)
while ((++x) < mw.toolbar.buttons.length) {
if(x>=n)
if (x >= n) {
mwEditButtons[x] = mwEditButtons[x+1];
mw.toolbar.buttons[x] = mw.toolbar.buttons[x + 1];
}
}
}
}
mwEditButtons.pop();
mw.toolbar.buttons.pop();
}
}
//Extra buttons in English Wikipedia
//Extra buttons in English Wikipedia
n=n-mwEditButtons.length;
n = n - mw.toolbar.buttons.length;
if(n>0 && n<mwCustomEditButtons.length){
if (n > 0 && n < window.mwCustomEditButtons.length) {
if(n<mwCustomEditButtons.length){
if (n < window.mwCustomEditButtons.length) {
var x = -1;
x = -1;
while((++x)<mwCustomEditButtons.length)
while ((++x) < window.mwCustomEditButtons.length) {
if(x>=n)
if (x >= n) {
mwCustomEditButtons[x] = mwCustomEditButtons[x+1];
window.mwCustomEditButtons[x] = window.mwCustomEditButtons[x + 1];
}
}
}
}
mwCustomEditButtons.pop();
window.mwCustomEditButtons.pop();
}
}
}
}
};
}


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


Line 197: Line 272:
//Function:
//Function:
//Purpose:
//Purpose:
// Adds extended onclick-function to some buttons  
// Adds extended onclick-function to some buttons
function extendButtons(){
function extendButtons() {
 
var allEditButtons = document.getElementById('toolbar');
if(!(allEditButtons = document.getElementById('toolbar'))) return false;
if ( !allEditButtons ) {
if(typeof editform != 'undefined')
return false;
if(!(window.editform = document.forms['editform'])) return false;
}
if (typeof editform !== 'undefined') {
if (!(window.editform = document.forms.editform)) {
return false;
}
}


//  table
//  table
extendAButton(Isrc+"7/79/Button_cmpl_table.png",XEBPopupTable)
extendAButton(Isrc + '0/04/Button_array.png', XEBPopupTable);
extendAButton(Isrc+"e/ef/Button_reflink_start.png",XEBPopupRef)
extendAButton(Isrc + '7/79/Button_reflink.png', XEBPopupRef);
extendAButton(Isrc+"c/cc/Button_adv_image.png",XEBPopupImage)
extendAButton(Isrc + 'b/b8/Button_Globe.png', XEBPopupGeoLink);
//extendAButton(Isrc+"d/d6/Button_superscript.png",XEBPopupFormattedText)
extendAButton(Isrc + '4/49/Button_talk.png', XEBPopupTalk);
 
extendAButton(Isrc + '1/1c/Button_advanced_image.png', XEBPopupImage);
//extendAButton(Isrc+'6/6a/Button_sup_letter.png',XEBPopupFormattedText);
// redirect -##IE doesn't like this line. Object doesn't support this property or method
// redirect -##IE doesn't like this line. Object doesn't support this property or method
//c=XEBOrder2.getIndex('V');
//c=XEBOrder2.getIndex('V');


// if(c != -1)
// if(c != -1)
// allEditButtons[bu_len+c].onclick=function(){
// allEditButtons[bu_len+c].onclick=function(){
// var a='#REDIRECT \[\['+prompt("Which page do you want to redirect to\?")+'\]\]';
// var a='#REDIRECT \[\['+prompt("Which page do you want to redirect to\?")+'\]\]';
// document.editform.elements['wpTextbox1'].value=a;
// document.editform.elements['wpTextbox1'].value=a;
// document.editform.elements['wpSummary'].value=a;
// document.editform.elements['wpSummary'].value=a;
// document.editform.elements['wpWatchthis'].checked=false
// document.editform.elements['wpWatchthis'].checked=false
//  };
//  };
};
}


function extendAButton(url,newfunc)
function extendAButton(url, newfunc) {
{
var i;
if(!(allEditButtons = document.getElementById('toolbar'))) return false;
var allEditButtons = document.getElementById('toolbar');
if(typeof editform != 'undefined')
if ( !allEditButtons ) {
if(!(window.editform = document.forms['editform'])) return false;
return false;
}
if (typeof editform !== 'undefined') {
if (!(window.editform = document.forms.editform)) {
return false;
}
}
allEditButtons = allEditButtons.getElementsByTagName('img');
allEditButtons = allEditButtons.getElementsByTagName('img');
for(i=0;i<allEditButtons.length;i++)
for (i = 0; i < allEditButtons.length; i++) {
{
if (allEditButtons[i].src === url) {
if(allEditButtons[i].src==url)
allEditButtons[i].onclick = newfunc;
{
allEditButtons[i].onclick=newfunc;
}
}
}
}
Line 241: Line 326:
//==========================================================================================================
//==========================================================================================================


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


me= document.getElementById("XEBPopup" & name);
var me = document.getElementById('XEBPopup' && name);
if(!(me==null))return me;
if (me !== null) {
me=document.createElement("div");
return me;
}
me = document.createElement('div');
XEBMainDiv.appendChild(me);
XEBMainDiv.appendChild(me);


me.id="XEBPopup";
me.id = 'XEBPopup';
me.style.position='absolute';
me.style.position = 'absolute';
me.display='none';
me.display = 'none';
me.visibility='hidden';
me.visibility = 'hidden';
me.onmouseout=CheckHideXEBPopup;
me.onmouseout = CheckHideXEBPopup;
me.onmouseover=cancelHidePopup;
me.onmouseover = cancelHidePopup;
return me;
return me;
}
}
 
//Function:
//Function:
// CheckHideXEBPopup
// CheckHideXEBPopup
Line 271: Line 357:
// When the onMouseEvent is fired on the popup
// When the onMouseEvent is fired on the popup


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


function cancelHidePopup()
function cancelHidePopup() {
{
clearTimeout(curPopup.hideTimeout);
clearTimeout(curPopup.hideTimeout)
}
}


function hideXEBPopup(){
function hideXEBPopup() {
XEBMainDiv= document.getElementById("XEB");
var XEBMainDiv = document.getElementById('XEB');
m= document.getElementById("XEBPopup");
var m = document.getElementById('XEBPopup');
XEBMainDiv.removeChild(m);
XEBMainDiv.removeChild(m);
}
}


function XEBstartDrag(e)
function XEBstartDrag(e) {
{
var m = new GetPos(e || event);
m=new GetPos(e||event);
curPopup.startDrag.mouse = m;
curPopup.startDrag.mouse=m;
curPopup.startDrag.floatpopup.y = parseInt(curPopup.div.style.top, 10);
curPopup.startDrag.floatpopup.y=parseInt(curPopup.div.style.top);
curPopup.startDrag.floatpopup.x = parseInt(curPopup.div.style.left, 10);
curPopup.startDrag.floatpopup.x=parseInt(curPopup.div.style.left);
curPopup.dragging = true;
curPopup.dragging=true;
}
}


function XEBstopDrag(e)
function XEBstopDrag(e) {
{
if (curPopup.dragging === false) {
if(curPopup.dragging==false)return;
return;
curPopup.dragging=false;
}
curPopup.dragging = false;
}
}


function XEBDrag(e)
function XEBDrag(e) {
{
if (curPopup.dragging === false) {
if(curPopup.dragging==false)return;
return;
}


m=new GetPos(e||event);
var m = new GetPos(e || event);
x=parseInt(curPopup.startDrag.floatpopup.x+(m.x-curPopup.startDrag.mouse.x));
var x = parseInt(curPopup.startDrag.floatpopup.x + (m.x - curPopup.startDrag.mouse.x), 10);
y=parseInt(curPopup.startDrag.floatpopup.y+(m.y-curPopup.startDrag.mouse.y));
var y = parseInt(curPopup.startDrag.floatpopup.y + (m.y - curPopup.startDrag.mouse.y), 10);


curPopup.div.style.top=y+"px";
curPopup.div.style.top = y + 'px';
curPopup.div.style.left=x+"px";
curPopup.div.style.left = x + 'px';


curPopup.x=x;
curPopup.x = x;
curPopup.y=y;
curPopup.y = y;
}
}


Line 342: Line 428:
//=============================================================================
//=============================================================================


function XEBPopup(name,x,y)
function XEBPopup(name, x, y) {
{
// Make sure the popup can appear on the screen
// Make sure the popup can appear on the screen
this.IESelectedRange = XEBgetIESelectedRange();


this.IESelectedRange=XEBgetIESelectedRange();
var winW = (is_gecko) ? window.innerWidth : document.body.offsetWidth;
if ((winW - this.width) < x) {
x = (winW - this.width);
}


winW=(is_gecko)?window.innerWidth:document.body.offsetWidth;
this.div = getXEBPopupDiv(name);
if((winW-this.width)<x)x=(winW-this.width);
this.div.style.zIndex = 2000;
this.div.display = 'inline';
this.div.visibility = 'visible';
this.div.style.top = y + 'px';
this.x = x;
this.y = y;
this.name = name;


this.div=getXEBPopupDiv(name);
this.startDrag = {};
this.div.style.zIndex=2000;
this.startDrag.floatpopup = {};
this.div.display="inline";
this.div.visibility="visible";
this.div.style.top=y + "px";
this.x=x;
this.y=y;
this.name=name;
 
this.startDrag=new Object;
this.startDrag.floatpopup=new Object;
}
}


function setInnerHTML(text)
function setInnerHTML(text) {
{
var i;
winW=(is_gecko)?window.innerWidth:document.body.offsetWidth;
var winW = (is_gecko) ? window.innerWidth : document.body.offsetWidth;
if((winW-this.width)<this.x)this.x=(winW-this.width);
if ((winW - this.width) < this.x) {
this.div.style.left=this.x+ "px";
this.x = (winW - this.width);
}
this.div.style.left = this.x + 'px';


mt="<div id='XEBmnu' style='width:" + this.width + "px' >";
var mt = '<div id="XEBmnu" style="width:' + this.width + 'px" >';
mt+='<div id="XEBmnuTitle" class="XEBPopupTitle" onmousedown="XEBstartDrag(event)" onmouseup="XEBstopDrag(event)" onmousemove="XEBDrag(event)">Title</div>'
mt += '<div id="XEBmnuTitle" class="XEBPopupTitle" onmousedown="XEBstartDrag(event)" onmouseup="XEBstopDrag(event)" onmousemove="XEBDrag(event)">Title</div>';
mt+=text;
mt += text;
mt+="</div>";
mt += '</div>';
this.div.innerHTML=mt;
this.div.innerHTML = mt;
//Turn off autocomplete. If the mouse moves over the autocomplete popup then x,y in CheckHidePopup is relative to the
//Turn off autocomplete. If the mouse moves over the autocomplete popup then x,y in CheckHidePopup is relative to the
// autocomplete popup and our popup is hidden
// autocomplete popup and our popup is hidden
var InTexts = this.div.getElementsByTagName('input');
var InTexts = this.div.getElementsByTagName('input');
for (var i = 0; i < InTexts.length; i++) {
for (i = 0; i < InTexts.length; i++) {
        var theInput = InTexts[i];
var theInput = InTexts[i];
if (theInput.type == 'text'){theInput.setAttribute('autocomplete','off');}
if (theInput.type === 'text') {
theInput.setAttribute('autocomplete', 'off');
}
}
}
//Add rollover features to menu items. Doing it here means we don't have to do it for each menu
//Add rollover features to menu items. Doing it here means we don't have to do it for each menu
x=XEBgetElementsByClassName(this.div,'XEBMnuItm','span');
var x = XEBgetElementsByClassName(this.div, 'XEBMnuItm', 'span');
for (var i = 0; i < x.length; i++) {
for (i = 0; i < x.length; i++) {
        var theItm = x[i];
var theItm = x[i];
theItm.onmouseout=XEBMenuMouseOut;
theItm.onmouseout = XEBMenuMouseOut;
theItm.onmouseover=XEBMenuMouseOver;
theItm.onmouseover = XEBMenuMouseOver;
}
}


this.div.style.borderWidth='thin';
this.div.style.borderWidth = 'thin';
this.div.style.borderStyle='solid';
this.div.style.borderStyle = 'solid';
this.div.style.backgroundColor='#D0D0D0';
this.div.style.backgroundColor = '#D0D0D0';
}
}
XEBPopup.prototype.width=250;
XEBPopup.prototype.width = 250;
XEBPopup.prototype.dragging=false;
XEBPopup.prototype.dragging = false;
XEBPopup.prototype.setInnerHTML=setInnerHTML;
XEBPopup.prototype.setInnerHTML = setInnerHTML;


var curPopup;
var curPopup;


function GetPos(e)
function GetPos(e) {
{
this.x = e.clientX - 10 + document.documentElement.scrollLeft + document.body.scrollLeft;
this.x=e.clientX-10+ document.documentElement.scrollLeft + document.body.scrollLeft;
this.y = e.clientY - 10 + document.documentElement.scrollTop + document.body.scrollTop;
this.y=e.clientY-10+ document.documentElement.scrollTop + document.body.scrollTop;
}
}


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


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


mt='<p>Enter the table parameters below: <\/p>'
var mt = '<p>Enter the table parameters below: <\/p>' +
+'<form name="XEBPopupTableForm">'
'<form name="XEBPopupTableForm">' +
+'Table caption: <input type="checkbox" name="inputCaption"><p\/>'
'Table caption: <input type="checkbox" name="inputCaption"><p\/>' +
+'Table alignment: center<input type="checkbox" name="inputAlign"><p\/>'
'Table alignment: center<input type="checkbox" name="inputAlign"><p\/>' +
+'Table headline: colored<input type="checkbox" name="inputHead"><p\/>'
'Table headline: colored<input type="checkbox" name="inputHead"><p\/>' +
+'Number of rows: <input type="text" name="inputRow" value="3" size="2"><p\/>'
'Number of rows: <input type="text" name="inputRow" value="3" size="2"><p\/>' +
+'Number of columns: <input type="text" name="inputCol" value="3" size="2"><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\/>'
// 'Alternating grey lines: <input type="checkbox" name="inputLine" checked="1" ><p\/>' +
+'Item column: <input type="checkbox" name="inputItems" ><p\/>'
'Item column: <input type="checkbox" name="inputItems" ><p\/>' +
+'Sortable: <input type="checkbox" name="inputSort" ><p\/>'
'Sortable: <input type="checkbox" name="inputSort" ><p\/>' +
+'<\/form>'
'<\/form>' +
+'<i>The default table allows for fields and values only.<\/i><p\/>'
'<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\/>'
'Check "Item column" to allow for the table to have fields, items, and values.<\/i><p\/>' +
+'<p><button onClick="javascript:insertTableCode()">Insert</button>'
'<p><button onClick="javascript:insertTableCode()">Insert</button>' +
+'<button onClick="hideXEBPopup()">Cancel</button>'
'<button onClick="hideXEBPopup()">Cancel</button>';


curPopup.setInnerHTML(mt);
curPopup.setInnerHTML(mt);
Line 432: Line 521:
}
}


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


//generateTable(caption, exhead, nbCol, nbRow, exfield, align);
//generateTable(caption, exhead, nbCol, nbRow, exfield, align);
 
var code = '\n';
var code = "\n";
code += '{| {{prettytable}} ' + align + ' '; // en: class="wikitable"
code += '{| class="wikitable" ' + align + ' ';
code += (f.inputSort.checked) ? 'class="sortable" \n' : '\n';
code+=(f.inputSort.checked)?'class="sortable" \n':'\n';
code += caption + exhead;
code += caption + exhead;
if (exfield) code += '!\n';
if (exfield) {
for (i=1;i<nbCol+1;i++) code += '! COLUMN ' + i + '\n';
code += '!\n';
}
for (i = 1; i < nbCol + 1; i++) {
code += '! FELD ' + i + '\n';
}
var items = 0;
var items = 0;
for (var j=0;j<nbRow;j++){
for (var j = 0; j < nbRow; j++) {
if (exfield) {  
if (exfield) {
items++;
items++;
code += '|-\n! style="background: #FFDDDD;"|ITEM ' + items + '\n';
code += '|-\n! style="background: #FFDDDD;"|ITEM ' + items + '\n';
} else code += '|-\n';
} else {
for (i=0;i<nbCol;i++) code += '| Element\n';
code += '|-\n';
}
for (i = 0; i < nbCol; i++) {
code += '| Element ' + i + '\n';
}
}
}
code += '|}\n';
code += '|}\n';
hideXEBPopup();
hideXEBPopup();
insertTags('','', code);
insertTags('', '', code);
extendSummary('table');
extendSummary('table');


return false;
return false;
}
}


// Get the text currently selected by user in the textAra
// Get the text currently selected by user in the textAra
// This code is based on part of the insertTags function in wikibits.js
// This code is based on part of the insertTags function in wikibits.js


function XEBGetSelectedText()
function XEBGetSelectedText() {
{
var txtarea, theSelection;
var txtarea;
if (document.editform) {
if (document.editform) {
txtarea = document.editform.wpTextbox1;
txtarea = document.editform.wpTextbox1;
Line 480: Line 576:
}
}
// IE & Opera
// IE & Opera
if (document.selection && !is_gecko)
if (document.selection && !is_gecko) {
{
theSelection = document.selection.createRange().text;
var theSelection = document.selection.createRange().text;
if (!theSelection) {
if (!theSelection) theSelection='';
theSelection = '';
}
}
}
// Mozilla
// Mozilla
else if(txtarea.selectionStart || txtarea.selectionStart == '0') {
else if (txtarea.selectionStart || txtarea.selectionStart === 0) {
var replaced = false;
var replaced = false;
var startPos = txtarea.selectionStart;
var startPos = txtarea.selectionStart;
var endPos = txtarea.selectionEnd;
var endPos = txtarea.selectionEnd;
var theSelection = (txtarea.value).substring(startPos, endPos);
theSelection = (txtarea.value).substring(startPos, endPos);
if (!theSelection) theSelection='';
if (!theSelection) {
theSelection = '';
}
}
}
return theSelection;
return theSelection;
Line 497: Line 596:


//Notes:
//Notes:
// IE loses the cursor position in the textarea when the popup is used.  
// IE loses the cursor position in the textarea when the popup is used.
// So we save the cursor position here
// So we save the cursor position here
function XEBgetIESelectedRange(){
function XEBgetIESelectedRange() {
var IESel=new Object;
var IESel = {};
var txtarea;
var txtarea;
if (document.editform) {
if (document.editform) {
Line 511: Line 610:
}
}
// IE & Opera
// IE & Opera
 
if (document.selection && !is_gecko) {
if (document.selection && !is_gecko)
{
txtarea.focus();
txtarea.focus();
IESel.Rng=document.selection.createRange();
IESel.Rng = document.selection.createRange();
return IESel;
return IESel;
}
}
}
}


function XEBinsertText(beforeText,selText,afterText,IESelectedRange) {
function XEBinsertText(beforeText, selText, afterText, IESelectedRange) {
var newText=beforeText + selText + afterText;
var newText = beforeText + selText + afterText;
var txtarea;
var txtarea, tr;
if (document.editform) {
if (document.editform) {
txtarea = document.editform.wpTextbox1;
txtarea = document.editform.wpTextbox1;
Line 532: Line 629:


// IE
// IE
if (document.selection && !is_gecko) {
if (document.selection && !is_gecko) {


tr=IESelectedRange.Rng;
tr = IESelectedRange.Rng;
tr.text=newText;
tr.text = newText;
txtarea.focus();
txtarea.focus();
//txtarea.caretpos=tr.duplicate();
//txtarea.caretpos=tr.duplicate();
Line 542: Line 639:
return;
return;


// Mozilla
// Mozilla
} else if(txtarea.selectionStart || txtarea.selectionStart == '0') {
} else if (txtarea.selectionStart || txtarea.selectionStart === 0) {
var replaced = false;
var replaced = false;
var startPos = txtarea.selectionStart;
var startPos = txtarea.selectionStart;
var endPos = txtarea.selectionEnd;
var endPos = txtarea.selectionEnd;


if (endPos-startPos) {
if (endPos - startPos) {
replaced = true;
replaced = true;
}
}
var scrollTop = txtarea.scrollTop;
var scrollTop = txtarea.scrollTop;
// var myText = (txtarea.value).substring(startPos, endPos);
// var myText = (txtarea.value).substring(startPos, endPos);
// if (!myText) {
// if (!myText) {
// myText=sampleText;
// myText=sampleText;
// }
// }
// if (myText.charAt(myText.length - 1) == " ") { // exclude ending space char, if any
// if (myText.charAt(myText.length - 1) == " ") { // exclude ending space char, if any
// subst = tagOpen + myText.substring(0, (myText.length - 1)) + tagClose + " ";
// subst = tagOpen + myText.substring(0, (myText.length - 1)) + tagClose + " ";
// } else {
// } else {
// subst = tagOpen + myText + tagClose;
// subst = tagOpen + myText + tagClose;
// }
// }
txtarea.value = txtarea.value.substring(0, startPos) + newText +
txtarea.value = txtarea.value.substring(0, startPos) + newText + txtarea.value.substring(endPos, txtarea.value.length);
txtarea.value.substring(endPos, txtarea.value.length);
txtarea.focus();
txtarea.focus();
//set new selection
//set new selection
if (!replaced) {
if (!replaced) {
var cPos = startPos+(newText.length);
var cPos = startPos + (newText.length);
txtarea.selectionStart = cPos;
txtarea.selectionStart = cPos;
txtarea.selectionEnd = cPos;
txtarea.selectionEnd = cPos;
} else {
} else {
txtarea.selectionStart = startPos+beforeText.length;
txtarea.selectionStart = startPos + beforeText.length;
txtarea.selectionEnd = startPos+beforeText.length+selText.length;
txtarea.selectionEnd = startPos + beforeText.length + selText.length;
}
}
txtarea.scrollTop = scrollTop;
txtarea.scrollTop = scrollTop;


// All other browsers get no toolbar.
// All other browsers get no toolbar.
// There was previously support for a crippled "help"
// There was previously support for a crippled "help"
// bar, but that caused more problems than it solved.
// bar, but that caused more problems than it solved.
}
}
// reposition cursor if possible
// reposition cursor if possible
Line 583: Line 679:


txtarea.caretPos = document.selection.createRange().duplicate();
txtarea.caretPos = document.selection.createRange().duplicate();
//txtarea.caretPos =IESelectedRange.Rng;
//txtarea.caretPos =IESelectedRange.Rng;
}
}
txtarea.focus();
txtarea.focus();
}
}




//============================================================
//============================================================
// Table generator  
// Table generator
//============================================================
//============================================================
/** en: Generate an array using Mediawiki syntax
/** en: Generate an array using MediaWiki syntax
* @author: originally from fr:user:dake
* @author: originally from fr:user:dake
* @version: 0.2 */
* @version: 0.2 */
function generateTable(caption, exhead, nbCol, nbRow, exfield, align){
function generateTable(caption, exhead, nbCol, nbRow, exfield, align) {
}
};




function XEBPopupRef(e){
function XEBPopupRef(e) {


m=new GetPos(e||event);
var m = new GetPos(e || event);


curPopup=new XEBPopup("ref",m.x,m.y);
curPopup = new XEBPopup('ref', m.x, m.y);
curPopup.width=500;
curPopup.width = 300;
mt='<p>Enter the reference parameters below: <\/p>'
var mt = '<p>Enter the reference parameters below: <\/p>' +
+'<form name="XEBPopupRefForm">'
'<form name="XEBPopupRefForm">' +
+'Name:<input type="text" name="refName" value="" size="10"><p\/>'
'Name:<input type="text" name="refName" value="" size="10"><p\/>' +
+'Material:<input type="text" name="refMaterial" value="' + XEBGetSelectedText() + '" size="20">'
'Material:<input type="text" name="refMaterial" value="' + XEBGetSelectedText() +
+'<\/form>'
'" size="20">' +
+'<p><button onClick="javascript:insertRef()">Insert</button>'
'<\/form>' +
+'<button onClick="hideXEBPopup()">Cancel</button>';
'<p><button onClick="javascript:insertRef()">Insert</button>' +
'<button onClick="hideXEBPopup()">Cancel</button>';


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


function insertRef(){
function insertRef() {
f=document.XEBPopupRefForm;
var f = document.XEBPopupRefForm;
var refName = f.refName.value;
var refName = f.refName.value;
var refMaterial=f.refMaterial.value;
var refMaterial = f.refMaterial.value;
 
hideXEBPopup();
hideXEBPopup();
var code1='<ref';
var code1 = '<ref';
code1+=(refName)?' name="'+refName+'">':'>';  
code1 += (refName) ? ' name="' + refName + '">' : '>';
code2=refMaterial;
var code2 = refMaterial;
code3='<\/ref>'
var code3 = '<\/ref>';
XEBinsertText(code1,code2,code3,curPopup.IESelectedRange);
XEBinsertText(code1, code2, code3, curPopup.IESelectedRange);


extendSummary('ref');
extendSummary('ref');
return false;
return false;
}  
}


function XEBPopupImage(e)
//===GEO LINK Function==================================================
{
m=new GetPos(e||event);


curPopup=new XEBPopup("image",m.x,m.y);
function XEBPopupGeoLink(e) {
curPopup.width=300;
var m = new GetPos(e || event);


mt='<p>Enter the image parameters below: <\/p>'
curPopup = new XEBPopup('geo', m.x, m.y);
+'<form name="XEBPopupImageForm">'
curPopup.width = 300;
+'File:<input type="text" name="imgFile" value="' + XEBGetSelectedText() + '" size="30"><br>'
var mt = '<p>Enter the location parameters below: <\/p>' +
+'Type:<SELECT NAME="imgType">'
'<form name="XEBPopupGeoLinkForm">' +
+'<OPTION VALUE="thumb">Thumbnail'
'Location:<p\/>' +
+'<OPTION VALUE="frame">Frame'
'<table style="background: transparent;">' +
+'<OPTION VALUE="none">[not specified]'
'<tr><td>Latitude:<\/td><td><input type="text" autocomplete="off" name="geoLatDeg" value="" size="4"><\/td>' +
+'</SELECT><br>'
'<td><input type="text" name="geoLatMin" size="4"><\/td>' +
+'Location:<SELECT NAME="imgLocation">'
'<td><input type="text" name="geoLatSec" size="4"><\/td>' +
+'<OPTION VALUE="left">Left'
'<td><select name="geoLatNS"><option value="N">N<option value="S">S</select><\/td><\/tr>' +
+'<OPTION VALUE="center">Centre'
'<tr><td>Longitude:<\/td><td><input type="text" name="geoLonDeg" value="" size="4"><\/td>' +
+'<OPTION VALUE="right">Right'
'<td><input type="text" name="geoLonMin" value="" size="4"><\/td>' +
+'<OPTION VALUE="none">None'
'<td><input type="text" name="geoLonSec" value="" size="4"><\/td>' +
+'</SELECT><br>'
'<td><select name="geoLonEW"><option value="E">E<option value="W">W</select><\/td><\/tr>' +
+'Size:<input type="text" name="imgSize" value="100" size="3">px<br>'
'<\/table>' +
+'Caption:<input type="text" name="imgCaption" value="" size="30"><\/p>'
'Region:<input type="text" name="geoRegion" value="" size="4"><p\/>' +
+'<\/form>'
'Type:' +
+'<p><button onClick="javascript:XEBInsertImage()">Insert</button>'
'<SELECT NAME="geoType" size="5">' +
+'<button onClick="hideXEBPopup()">Cancel</button>';
'<OPTION VALUE="country">Country<OPTION VALUE="state">State' +
'<OPTION VALUE="adm1st">Admin unit, 1st level<OPTION VALUE="adm2st">Admin unit, 2nd level' +
'<OPTION VALUE="city">City<OPTION VALUE="airport">Airport' +
'<OPTION VALUE="mountain">Mountain<OPTION VALUE="isle">Isle' +
'<OPTION VALUE="waterbody">Waterbody<OPTION VALUE="landmark" SELECTED>Landmark' +
'<OPTION VALUE="forest">forest</SELECT><br>' +
'Title: <input type="checkbox" name="geoTitle" ><p\/>' +
'<\/form>' +
'<p><button onClick="javascript:insertGeoLink()">Insert</button>' +
'<button onClick="hideXEBPopup()">Cancel</button>';
 
curPopup.setInnerHTML(mt);
document.paramForm.refName.focus();
return true;
 
}
function insertGeoLink() {
var f = document.XEBPopupGeoLinkForm;
 
var code = '{{Coor ';
if (f.geoTitle.checked) {
code += 'title ';
}
var ft = 'dms';
if (f.geoLatSec.value === '' && f.geoLonSec.value === '') {
ft = 'dm';
}
if (ft === 'dm' && f.geoLatMin.value === '' && f.geoLonMin.value === '') {
ft = 'd';
}
code += ft;
code += '|' + f.geoLatDeg.value;
code += (ft === 'dm' || ft === 'dms') ? '|' + f.geoLatMin.value : '';
code += (ft === 'dms') ? '|' + f.geoLatSec.value : '';
code += '|' + f.geoLatNS.value;
code += '|' + f.geoLonDeg.value;
code += (ft === 'dm' || ft === 'dms') ? '|' + f.geoLonMin.value : '';
code += (ft === 'dms') ? '|' + f.geoLonSec.value : '';
code += '|' + f.geoLonEW.value;
code += '|type:' + f.geoType.value + '_region:' + f.geoRegion.value;
code += '}}';
insertTags('', '', code);
extendSummary('geo-location');
hideXEBPopup();
return false;
}
 
//===Talk Page entry Function===========================================
 
function XEBPopupTalk(e) {
var m = new GetPos(e || event);
 
curPopup = new XEBPopup('talk', m.x, m.y);
curPopup.width = 200;
var mt = '<div style="font-size:medium"><p>Please choose:<\/p>';
mt += '<span class="XEBMnuItm" onclick="XEBInsertTalk(1)">Test1<\/span><br>';
mt += '<span class="XEBMnuItm" onclick="XEBInsertTalk(2)">Self Test<\/span><br>';
mt += '<span class="XEBMnuItm" onclick="XEBInsertTalk(3)">Nonsense<\/span><br>';
mt += '<span class="XEBMnuItm" onclick="XEBInsertTalk(4)">Please stop<\/span><br>';
mt += '<span class="XEBMnuItm" onclick="XEBInsertTalk(5)">Last chance<\/span><br>';
mt += '<span class="XEBMnuItm" onclick="XEBInsertTalk(6)">Blanking<\/span><br>';
mt += '<span class="XEBMnuItm" onclick="XEBInsertTalk(7)">Blatant<\/span><br>';
mt += '<span class="XEBMnuItm" ;onclick="XEBInsertTalk(8)">*BLOCKED*<\/span><br>';
mt += '<span class="XEBMnuItm" onclick="XEBInsertTalk(9)">Spam<\/span><br>';
mt += '<span class="XEBMnuItm" onclick="XEBInsertTalk(10)">Npov<\/span><br>';
 
curPopup.setInnerHTML(mt);
 
return true;
 
}
 
function XEBInsertTalk(itm) {
var code = {
1: '{' + '{subst:test1-n|}}',
2: '{' + '{subst:selftest-n|}}',
3: '{' + '{subst:test2-n|}}',
4: '{' + '{subst:test3-n|}}',
5: '{' + '{subst:test4-n|}}',
6: '{' + '{subst:test2a-n|}}',
7: '{' + '{subst:bv-n|}}',
8: '{' + '{subst:blantant|}}',
9: '{' + '{subst:spam-n|}}',
10: '{' + '{subst:NPOV user}}'
};
hideXEBPopup();
insertTags('', '', code[ itm ]);
return false;
}
function XEBPopupImage(e) {
var m = new GetPos(e || event);
 
curPopup = new XEBPopup('image', m.x, m.y);
curPopup.width = 300;
 
var mt = '<p>Enter the image parameters below: <\/p>' +
'<form name="XEBPopupImageForm">' +
'File:<input type="text" name="imgFile" value="' + XEBGetSelectedText() + '" size="30"><br>' +
'Type:<SELECT NAME="imgType">' +
'<OPTION VALUE="thumb">Thumbnail' +
'<OPTION VALUE="frame">Frame' +
'<OPTION VALUE="none">[not specified]' +
'</SELECT><br>' +
'Location:<SELECT NAME="imgLocation">' +
'<OPTION VALUE="left">Left' +
'<OPTION VALUE="center">Centre' +
'<OPTION VALUE="right">Right' +
'<OPTION VALUE="none">None' +
'</SELECT><br>' +
'Size:<input type="text" name="imgSize" value="100" size="3">px<br>' +
'Caption:<input type="text" name="imgCaption" value="" size="30"><\/p>' +
'<\/form>' +
'<p><button onClick="javascript:XEBInsertImage()">Insert</button>' +
'<button onClick="hideXEBPopup()">Cancel</button>';


curPopup.setInnerHTML(mt);
curPopup.setInnerHTML(mt);
Line 666: Line 873:
return true;
return true;
}
}
function XEBInsertImage()
 
{
function XEBInsertImage() {
f=document.XEBPopupImageForm;
var f = document.XEBPopupImageForm;
hideXEBPopup();
hideXEBPopup();
var code='[[Image:';
var code = '[[Image:';
code+=f.imgFile.value;
code += f.imgFile.value;
code+='|'+f.imgType.value;
code += '|' + f.imgType.value;
code+='|'+f.imgLocation.value;
code += '|' + f.imgLocation.value;
code+='|'+f.imgSize.value;
code += '|' + f.imgSize.value;
code+='|'+f.imgCaption.value;
code += '|' + f.imgCaption.value;
code+=']]';
code += ']]';
insertTags('','', code);
insertTags('', '', code);
extendSummary('image');
extendSummary('image');


Line 683: Line 890:
}
}


function XEBPopupFormattedText(e)
function XEBPopupFormattedText(e) {
{
var m = new GetPos(e || event);
m=new GetPos(e||event);
 
curPopup = new XEBPopup('image', m.x, m.y);
curPopup.width = 300;


curPopup=new XEBPopup("image",m.x,m.y);
var mt = '<form name="XEBPopupImageForm">' +
curPopup.width=300;
'<table  style="background: transparent;">' +
'<tr><td>Bold:<\/td><td><input type="checkbox" name="textBold"><\/td>' +
mt='<form name="XEBPopupImageForm">'
'<td>Superscript:<\/td><td><input type="checkbox" name="textSuperscript"><\/td><\/tr>' +
+'<table  style="background: transparent;">'
'<tr><td>Italic:<\/td><td><input type="checkbox" name="textItalic"><\/td>' +
+'<tr><td>Bold:<\/td><td><input type="checkbox" name="textBold"><\/td>'
'<td>Subscript:<\/td><td><input type="checkbox" name="textSubscript"><\/td><\/tr>' +
+'<td>Superscript:<\/td><td><input type="checkbox" name="textSuperscript"><\/td><\/tr>'
'<tr><td>Strike:<\/td><td><input type="checkbox" name="textStrike"><\/td>' +
+'<tr><td>Italic:<\/td><td><input type="checkbox" name="textItalic"><\/td>'
'<td>&nbsp;<\/td><\/tr>' +
+'<td>Subscript:<\/td><td><input type="checkbox" name="textSubscript"><\/td><\/tr>'
'</table>' +
+'<tr><td>Strike:<\/td><td><input type="checkbox" name="textStrike"><\/td>'
'Size:<SELECT NAME="textSize">' +
+'<td>&nbsp;<\/td><\/tr>'
'<OPTION VALUE="small">small' +
+'</table>'
'<OPTION VALUE="normal">[Normal]' +
+'Size:<SELECT NAME="textSize">'
'<OPTION VALUE="big">big' +
+'<OPTION VALUE="small">small'
'</SELECT><br><table style="background:transparent;"><tr><td>Colour:<\/td><td>' +
+'<OPTION VALUE="normal">[Normal]'
'<table width="100px">' +
+'<OPTION VALUE="big">big'
'<tr><td colspan="4">None<\/td></tr>' +
+'</SELECT><br><table style="background:transparent;"><tr><td>Color:<\/td><td>'
'<tr><td bgcolor="aqua">&nbsp;<\/td><td bgcolor="gray"> &nbsp;<\/td>' +
+'<table width="100px">'
'<td bgcolor="olive">&nbsp;<\/td><td bgcolor="navy">&nbsp;<\/td><\/tr>' +
+'<tr><td colspan="4">None<\/td></tr>'
'<tr><td bgcolor="black">&nbsp;<\/td><td bgcolor="green"> &nbsp;<\/td>' +
+'<tr><td bgcolor="aqua">&nbsp;<\/td><td bgcolor="gray"> &nbsp;<\/td>'
'<td bgcolor="purple">&nbsp;<\/td><td bgcolor="teal">&nbsp;<\/td><\/tr>' +
+'<td bgcolor="olive">&nbsp;<\/td><td bgcolor="navy">&nbsp;<\/td><\/tr>'
'<tr><td bgcolor="blue">&nbsp;<\/td><td bgcolor="lime">&nbsp;<\/td>' +
+'<tr><td bgcolor="black">&nbsp;<\/td><td bgcolor="green"> &nbsp;<\/td>'
'<td bgcolor="red">&nbsp;<\/td><td bgcolor="white">&nbsp;<\/td><\/tr>' +
+'<td bgcolor="purple">&nbsp;<\/td><td bgcolor="teal">&nbsp;<\/td><\/tr>'
'<tr><td bgcolor="fuchsia">&nbsp;<\/td><td bgcolor="maroon">&nbsp;<\/td>' +
+'<tr><td bgcolor="blue">&nbsp;<\/td><td bgcolor="lime">&nbsp;<\/td>'
'<td bgcolor="silver">&nbsp;<\/td><td bgcolor="yellow">&nbsp;<\/td><\/tr>' +
+'<td bgcolor="red">&nbsp;<\/td><td bgcolor="white">&nbsp;<\/td><\/tr>'
'</table><\/td><\/tr>' +
+'<tr><td bgcolor="fuchsia">&nbsp;<\/td><td bgcolor="maroon">&nbsp;<\/td>'
'<\/form>' +
+'<td bgcolor="silver">&nbsp;<\/td><td bgcolor="yellow">&nbsp;<\/td><\/tr>'
'Sample:' +
+'</table><\/td><\/tr>'
'<span id="sampleText">Text</span>"' +
+'<\/form>'
'<p><button onClick="javascript:XEBInsertFormattedText()">Insert</button>' +
+'Sample:'
'<button onClick="hideXEBPopup()">Cancel</button>';
+'<span id="sampleText">Text</span>"'
+'<p><button onClick="javascript:XEBInsertFormattedText()">Insert</button>'
+'<button onClick="hideXEBPopup()">Cancel</button>';


curPopup.setInnerHTML(mt);
curPopup.setInnerHTML(mt);
Line 726: Line 932:
}
}


function XEBUpdateSampleText()
function XEBUpdateSampleText() {
{
var f = document.XEBPopupImageForm;
f=document.XEBPopupImageForm;
}
}


//====================
//====================


function XEBMenuMouseOut(e)
function XEBMenuMouseOut(e) {
{
var targ;
var targ;
if (!e) var e = window.event;
if (!e) {
if (e.target) targ = e.target;
e = window.event;
else if (e.srcElement) targ = e.srcElement;
}
if (e.target) {
targ = e.target;
} else if (e.srcElement) {
targ = e.srcElement;
}


targ.style.color='black';
targ.style.color = 'black';
}
}


function XEBMenuMouseOver(e)
function XEBMenuMouseOver(e) {
{ var targ;
var targ;
if (!e) var e = window.event;
if (!e) {
if (e.target) targ = e.target;
e = window.event;
else if (e.srcElement) targ = e.srcElement;
}
if (e.target) {
targ = e.target;
} else if (e.srcElement) {
targ = e.srcElement;
}


targ.style.color='red';
targ.style.color = 'red';
}
}


Line 756: Line 970:
//=======================================================================
//=======================================================================


function XEBgetElementsByClassName(parent,clsName,htmltag){  
function XEBgetElementsByClassName(parent, clsName, htmltag) {
var arr = new Array();  
var arr = [], elem;
var elems = parent.getElementsByTagName(htmltag);
var elems = parent.getElementsByTagName(htmltag);
for ( var cls, i = 0; ( elem = elems[i] ); i++ ){
for (var cls, i = 0;
if ( elem.className == clsName ){
(elem = elems[i]); i++) {
if (elem.className === clsName) {
arr[arr.length] = elem;
arr[arr.length] = elem;
}
}
Line 767: Line 982:
}
}


function extendSummary(newText)
function extendSummary(newText) {
{
if (!XEBExtendEditSummary) {
if(!XEBExtendEditSummary)return;
return;
s=document.editform.elements['wpSummary'].value;
}
s+=(s=='')?newText:' +'+newText;
var s = document.editform.elements.wpSummary.value;
document.editform.elements['wpSummary'].value=s;
s += (s === '') ? newText : ' +' + newText;
document.editform.elements.wpSummary.value = s;
}
}


 
function bug(msg) {
//fix edit summary prompt for undo
if (mw.config.get( 'wgUserName' ) === 'MarkS') {
//this code fixes the fact that the undo function combined with the "no edit summary prompter" causes problems if leaving the
alert(msg);
//edit summary unchanged
}
//this was added by [[User:Deskana]], code by [[User:Tra]]
}
//see bug 8912
addOnloadHook(function () {
    if (document.location.search.indexOf("undo=") != -1
        && document.getElementsByName('wpAutoSummary')[0]) {
        document.getElementsByName('wpAutoSummary')[0].value='1';
    }
})
 
//</source>
/* </pre> */

Revision as of 18:25, 14 November 2015

/* Version: 3.1
 * ============================================================
 * en: ADD SOME EXTRA BUTTONS TO THE EDITPANEL
 * de: FÜGE NEUE BUTTON IN DIE WERKZEUGLEISTE
 * pt: ACRESCENTA ALGUNS BOTÕES EXTRAS AO PAINEL DE EDIÇÃO
 * ============================================================
 * 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
 *
 * window.rmEditButtons - Removes standard toolbar buttons
 * window.XEBOrder - The order in which the buttons are displayed
 * window.myButtons - Add user defined buttons
 */

mw.loader.load( '//en.wikipedia.org/w/index.php?title=User:MarkS/XEB/live.css&action=raw&ctype=text/css', 'text/css' );

if (typeof XEBPopups === 'undefined') {
	XEBPopups = true;
}
if (typeof XEBHideDelay === 'undefined') {
	// Time before the popup disappears after the mouse moves out
	window.XEBHideDelay = 0.5;
}
if (typeof XEBExtendEditSummary === 'undefined') {
	// Is the edit summary extended after a popup
	window.XEBExtendEditSummary = true;
}

if (typeof usersignature === 'undefined') {
	var usersignature = '-- ~~' + '~~';
}

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

var BDict = {
	'A': ['e/e9/Button_headline2.png', 'Secondary headline', '\n===', '===', 'Secondary headline'],
	'B': ['1/13/Button_enter.png', 'Line break', '<br />', '', ''],
	'C': ['5/5f/Button_center.png', 'Center', '<div style="text-align: center;">\n', '\n<\/div>', 'Centred text'],
	'D': ['e/ea/Button_align_left.png', 'Left-Align', '<div style="text-align: left; direction: ltr; margin-left: 1em;">\n', '\n<\/div>', 'Left-aligned text'],
	'D1': ['a/a5/Button_align_right.png', 'Right-Align', '<div style="text-align: right; direction: ltr; margin-left: 1em;">\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', '<span style="color: ', '">Coloured text<\/span>', 'ColourName'],
	'FS': ['1/1b/Button_miss_signature.png', 'Unsigned post', '<small><span class="autosigned">— Preceding [[Wikipedia:Signatures|unsigned]] comment added by [[User:', '|', ']] ([[User talk:', '|talk]] • [[Special:Contributions/', '|contribs]]) date</span></small><!-- Template:Unsigned -->', 'user name or IP'],
	'G': ['9/9e/Btn_toolbar_gallery.png', 'Picture gallery', "\n<gallery>\nImage:", "|[[M63]]\nImage:Mona Lisa.jpg|[[Mona Lisa]]\nImage:Truite arc-en-ciel.jpg|Eine [[Forelle ]]\n<\/gallery>", 'M63.jpg'],
	'H': ['7/74/Button_comment.png', 'Comment', "<!--", "-->", 'Comment'],
	'I1': ['6/6a/Button_sup_letter.png', 'Superscript', '<sup>', '<\/sup>', 'Superscript text'],
	'I2': ['a/aa/Button_sub_letter.png', 'Subscript', '<sub>', '<\/sub>', 'Subscript text'],
	'J1': ['5/58/Button_small.png', 'Small', '<small>', '<\/small>', 'Small Text'],
	'J2': ['5/56/Button_big.png', 'Big text', '<big>', '<\/big>', 'Big text'],
	'K': ['b/b4/Button_category03.png', 'Category', "[[Category:", "]]", 'Category name'],
	'L': ['8/8e/Button_shifting.png', 'Insert tab(s)', ':', '', ':'],
	'M': ['f/fd/Button_blockquote.png', 'Insert block of quoted text', '<blockquote style="border: 1px solid blue; padding: 2em;">\n', '\n<\/blockquote>', 'Block quote'],
	'N': ['4/4b/Button_nbsp.png', 'nonbreaking space', '&nbsp;', '', ''],
	'O': ['2/23/Button_code.png', 'Insert code', '<code>', '<\/code>', 'Code'],
	'P': ['3/3c/Button_pre.png', 'Pre formatted Text', '<pre>', '<\/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', '<ref>', '<\/ref>', 'Insert reference material'],
	'R1': ['7/79/Button_reflink.png', 'Start a reference', '<ref name="', '', 'Reference name'],
	'R2': ['9/99/Button_reflink_advanced_2.png', 'Insert reference material', '">', '</ref>', 'Reference material'],
	'R3': ['1/1a/Button_reflink_advanced_3.png', 'No reference material', '', '"/>', ''],
	'R4': ['9/9a/Button_references.png', 'Reference footer', "\n==Notes==\n<!--See http://en.wikipedia.org/wiki/Wikipedia:Footnotes for an explanation of how to generate footnotes using the <ref(erences/)> tags-->\n<div class=\'references-small\'>\n<references/>\n</div>", '', ''],
	'S': ['c/c9/Button_strike.png', 'Strikeout', '<s>', '<\/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>', '<\/tt>', 'Teletype Text'],
	'TL': ['3/37/Button_tl_template.png', 'Template link', "{{subst:" + "tl|", '}}', 'Template name'],
	'U': ['f/fd/Button_underline.png', 'Underlined', "<u>", "<\/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>", "<\/noinclude>", 'Text'],
	'Y2': ['7/79/Button_include.png', 'Include only', "<includeonly>", "<\/includeonly>", 'Text'],
	'Z': ['3/35/Button_substitute.png', 'Substitute', "{{subst:", "}}", 'Template'],
	'AI': ['1/1c/Button_advanced_image.png', 'Advanaced Image', "[[Image:", "|thumb|right|px|Caption]]", 'FileName.jpg'],
	'GEO': ['b/b8/Button_Globe.png', 'Geo location', "", "", ""],
	'TALK': ['4/49/Button_talk.png', 'Add talk template', "", "", ""]
};

var XEBOrder2 = [];




initButtons();
if (!mw.config.get( 'wgIsArticle' )) {
	// only if edit
	if (XEBPopups) {
		$(extendButtons);
	}
}

function initButtons() {

	var bc, d, i, customTools = {};

	if (typeof XEBOrder !== 'string') {
		// can be modified
		XEBOrder2 = 'A,D,C,D1,F,U,J1,E,G,Q,W,X,K,L,H,O,R,T'.split(',');
	} else if (XEBOrder.toLowerCase() === 'all') {
		$.each(BDict, function( b, value ){
			XEBOrder2.push(b);
		});
	} else {
		XEBOrder2 = XEBOrder.toUpperCase().split(',');
	}

	$.each(BDict, function( b, value ){
		// Add the start of the URL (Isrc) to the XEB buttons
		BDict[b][0] = Isrc + BDict[b][0];
	});
	// If the user has defined any buttons then add them into the available button lists
	if (typeof myButtons === 'object') {
		$.each(myButtons, function( b, value ){
			// custom user buttons
			BDict[b] = myButtons[b];
		});
	}

        mw.loader.using( 'user.options', function () {
		if ( mw.user.options.get('usebetatoolbar') ) {
			// Use the enhanced edit toolbar
			mw.loader.using( 'ext.wikiEditor.toolbar', function () {
				$(function(){
					// 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') {
							customTools[ XEBOrder2[i] ] = {
								label: bc[1],
								type: 'button',
								icon:  bc[0],
								action: {
									type: 'encapsulate',
									options: {
										pre: bc[2],
										peri: bc[4],
										post: bc[3]
									}
								}
							};
						}
					}

					$('#wpTextbox1').wikiEditor( 'addToToolbar', {
						'sections': {
							'extra': {
								'type': 'toolbar',
								'label': 'Extras'
							}
						},
						'section': 'extra',
						'groups': {
							'my-buttons': {
								'label': 'My buttons',
								'tools': customTools
							}
						}
					} );
				});

			} );
		} else {
			// Use the old edit toolbar
			// Add the MediaWiki standard buttons into the available buttons
			$.each(mw.toolbar.buttons, function( b, value ){
				// add standard buttons for full XEB order changing
				//	BDict[b]=[];
				BDict[b] = [ value.imageFile, value.speedTip, value.tagOpen, value.tagClose, value.sampleText];

				// for (d in value) {BDict[b].push(value}[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') {

					//Call addButton from module mediawiki.action.edit
					mw.toolbar.addButton(bc[0], bc[1], bc[2], bc[3], bc[4] /* , imageId, selectText */ );
				}
			}

			// 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() {
	var x, i, enExtraButtons;

	//Remove the buttons the user doesn't want
	if (typeof rmEditButtons !== 'object') {
		return;
	}

	if (typeof rmEditButtons[0] === 'string' && rmEditButtons[0].toLowerCase() === 'all') {
		// English Wikipedia creates 11 extra buttons which are stored in mwCustomEditButtons
		// rather than mw.toolbar.buttons. However, there is no guarantee it will always be 11
		// so we count them here.
		enExtraButtons = window.mwCustomEditButtons.length;

		mw.toolbar.buttons = [];
		for (i = 0; i < enExtraButtons; i++) {
			window.mwCustomEditButtons.shift();
		}
	}
	//Sort the user's requests so we remove the button with the highest index first
	//- This ensures we remove the buttons the user expects whatever order he requested the buttons in
	window.rmEditButtons.sort(sortit);

	//Remove individual buttons the user doesn't want
	for (i = 0; i < rmEditButtons.length; i++) {
		var n = rmEditButtons[i];
		//Standard Wikimedia buttons
		if (n >= 0 && n < mw.toolbar.buttons.length) {
			if (n < mw.toolbar.buttons.length) {
				x = -1;
				while ((++x) < mw.toolbar.buttons.length) {
					if (x >= n) {
						mw.toolbar.buttons[x] = mw.toolbar.buttons[x + 1];
					}
				}
			}
			mw.toolbar.buttons.pop();
		}
		//Extra buttons in English Wikipedia
		n = n - mw.toolbar.buttons.length;
		if (n > 0 && n < window.mwCustomEditButtons.length) {
			if (n < window.mwCustomEditButtons.length) {
				x = -1;
				while ((++x) < window.mwCustomEditButtons.length) {
					if (x >= n) {
						window.mwCustomEditButtons[x] = window.mwCustomEditButtons[x + 1];
					}
				}
			}
			window.mwCustomEditButtons.pop();
		}
	}
}

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


//Function:
//Purpose:
//	Adds extended onclick-function to some buttons
function extendButtons() {
	var allEditButtons = document.getElementById('toolbar');
	if ( !allEditButtons ) {
		return false;
	}
	if (typeof editform !== 'undefined') {
		if (!(window.editform = document.forms.editform)) {
			return false;
		}
	}

	//  table
	extendAButton(Isrc + '0/04/Button_array.png', XEBPopupTable);
	extendAButton(Isrc + '7/79/Button_reflink.png', XEBPopupRef);
	extendAButton(Isrc + 'b/b8/Button_Globe.png', XEBPopupGeoLink);
	extendAButton(Isrc + '4/49/Button_talk.png', XEBPopupTalk);
	extendAButton(Isrc + '1/1c/Button_advanced_image.png', XEBPopupImage);
	//extendAButton(Isrc+'6/6a/Button_sup_letter.png',XEBPopupFormattedText);
	// redirect -##IE doesn't like this line. Object doesn't support this property or method
	//c=XEBOrder2.getIndex('V');

	//	if(c != -1)
	//		allEditButtons[bu_len+c].onclick=function(){
	//		var a='#REDIRECT \[\['+prompt("Which page do you want to redirect to\?")+'\]\]';
	//		document.editform.elements['wpTextbox1'].value=a;
	//		document.editform.elements['wpSummary'].value=a;
	//		document.editform.elements['wpWatchthis'].checked=false
	//  };
}

function extendAButton(url, newfunc) {
	var i;
	var allEditButtons = document.getElementById('toolbar');
	if ( !allEditButtons ) {
		return false;
	}
	if (typeof editform !== 'undefined') {
		if (!(window.editform = document.forms.editform)) {
			return false;
		}
	}
	allEditButtons = allEditButtons.getElementsByTagName('img');
	for (i = 0; i < allEditButtons.length; i++) {
		if (allEditButtons[i].src === url) {
			allEditButtons[i].onclick = newfunc;
		}
	}
}

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

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

	var me = document.getElementById('XEBPopup' && name);
	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;
	me.onmouseover = cancelHidePopup;
	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) {
	var x, y, ph, s, pl, pt, pw;
	var m = document.getElementById('XEBmnu');
	if (is_gecko) {
		ph = m.offsetHeight;
		x = e.clientX + window.scrollX;
		y = e.clientY + window.scrollY;
		s = window.getComputedStyle(m, '');
		ph = s.height;
		ph = Number(ph.substring(0, ph.length - 2));
	} else {
		x = event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;
		y = event.clientY + document.documentElement.scrollTop + document.body.scrollTop;
		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;
	}
	curPopup.hideTimeout = setTimeout(hideXEBPopup, XEBHideDelay * 1000);
}

function cancelHidePopup() {
	clearTimeout(curPopup.hideTimeout);
}

function hideXEBPopup() {
	var XEBMainDiv = document.getElementById('XEB');
	var m = document.getElementById('XEBPopup');
	XEBMainDiv.removeChild(m);
}

function XEBstartDrag(e) {
	var m = new GetPos(e || event);
	curPopup.startDrag.mouse = m;
	curPopup.startDrag.floatpopup.y = parseInt(curPopup.div.style.top, 10);
	curPopup.startDrag.floatpopup.x = parseInt(curPopup.div.style.left, 10);
	curPopup.dragging = true;
}

function XEBstopDrag(e) {
	if (curPopup.dragging === false) {
		return;
	}
	curPopup.dragging = false;
}

function XEBDrag(e) {
	if (curPopup.dragging === false) {
		return;
	}

	var m = new GetPos(e || event);
	var x = parseInt(curPopup.startDrag.floatpopup.x + (m.x - curPopup.startDrag.mouse.x), 10);
	var y = parseInt(curPopup.startDrag.floatpopup.y + (m.y - curPopup.startDrag.mouse.y), 10);

	curPopup.div.style.top = y + 'px';
	curPopup.div.style.left = x + 'px';

	curPopup.x = x;
	curPopup.y = y;
}

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

function XEBPopup(name, x, y) {
	// Make sure the popup can appear on the screen
	this.IESelectedRange = XEBgetIESelectedRange();

	var winW = (is_gecko) ? window.innerWidth : document.body.offsetWidth;
	if ((winW - this.width) < x) {
		x = (winW - this.width);
	}

	this.div = getXEBPopupDiv(name);
	this.div.style.zIndex = 2000;
	this.div.display = 'inline';
	this.div.visibility = 'visible';
	this.div.style.top = y + 'px';
	this.x = x;
	this.y = y;
	this.name = name;

	this.startDrag = {};
	this.startDrag.floatpopup = {};
}

function setInnerHTML(text) {
	var i;
	var winW = (is_gecko) ? window.innerWidth : document.body.offsetWidth;
	if ((winW - this.width) < this.x) {
		this.x = (winW - this.width);
	}
	this.div.style.left = this.x + 'px';

	var mt = '<div id="XEBmnu" style="width:' + this.width + 'px" >';
	mt += '<div id="XEBmnuTitle" class="XEBPopupTitle" onmousedown="XEBstartDrag(event)" onmouseup="XEBstopDrag(event)" onmousemove="XEBDrag(event)">Title</div>';
	mt += text;
	mt += '</div>';
	this.div.innerHTML = mt;
	//Turn off autocomplete. If the mouse moves over the autocomplete popup then x,y in CheckHidePopup is relative to the
	// autocomplete popup and our popup is hidden
	var InTexts = this.div.getElementsByTagName('input');
	for (i = 0; i < InTexts.length; i++) {
		var theInput = InTexts[i];
		if (theInput.type === 'text') {
			theInput.setAttribute('autocomplete', 'off');
		}
	}
	//Add rollover features to menu items. Doing it here means we don't have to do it for each menu
	var x = XEBgetElementsByClassName(this.div, 'XEBMnuItm', 'span');
	for (i = 0; i < x.length; i++) {
		var theItm = x[i];
		theItm.onmouseout = XEBMenuMouseOut;
		theItm.onmouseover = XEBMenuMouseOver;
	}

	this.div.style.borderWidth = 'thin';
	this.div.style.borderStyle = 'solid';
	this.div.style.backgroundColor = '#D0D0D0';
}
XEBPopup.prototype.width = 250;
XEBPopup.prototype.dragging = false;
XEBPopup.prototype.setInnerHTML = setInnerHTML;

var curPopup;

function GetPos(e) {
	this.x = e.clientX - 10 + document.documentElement.scrollLeft + document.body.scrollLeft;
	this.y = e.clientY - 10 + document.documentElement.scrollTop + document.body.scrollTop;
}

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

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

	var mt = '<p>Enter the table parameters below: <\/p>' +
		'<form name="XEBPopupTableForm">' +
		'Table caption: <input type="checkbox" name="inputCaption"><p\/>' +
		'Table alignment: center<input type="checkbox" name="inputAlign"><p\/>' +
		'Table headline: colored<input type="checkbox" name="inputHead"><p\/>' +
		'Number of rows: <input type="text" name="inputRow" value="3" size="2"><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\/>' +
		'Sortable: <input type="checkbox" name="inputSort" ><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\/>' +
		'<p><button onClick="javascript:insertTableCode()">Insert</button>' +
		'<button onClick="hideXEBPopup()">Cancel</button>';

	curPopup.setInnerHTML(mt);

	return true;
}

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

	//generateTable(caption, exhead, nbCol, nbRow, exfield, align);
	var code = '\n';
	code += '{| {{prettytable}} ' + align + ' '; // en: class="wikitable"
	code += (f.inputSort.checked) ? 'class="sortable" \n' : '\n';
	code += 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 ' + i + '\n';
		}
	}
	code += '|}\n';
	hideXEBPopup();
	insertTags('', '', code);
	extendSummary('table');

	return false;
}

// Get the text currently selected by user in the textAra
// This code is based on part of the insertTags function in wikibits.js

function XEBGetSelectedText() {
	var txtarea, theSelection;
	if (document.editform) {
		txtarea = document.editform.wpTextbox1;
	} else {
		// some alternate form? take the first one we can find
		var areas = document.getElementsByTagName('textarea');

		txtarea = areas[0];
	}
	// IE & Opera
	if (document.selection && !is_gecko) {
		theSelection = document.selection.createRange().text;
		if (!theSelection) {
			theSelection = '';
		}
	}
	// Mozilla
	else if (txtarea.selectionStart || txtarea.selectionStart === 0) {
		var replaced = false;
		var startPos = txtarea.selectionStart;
		var endPos = txtarea.selectionEnd;
		theSelection = (txtarea.value).substring(startPos, endPos);
		if (!theSelection) {
			theSelection = '';
		}
	}
	return theSelection;
}

//Notes:
//	IE loses the cursor position in the textarea when the popup is used.
//	So we save the cursor position here
function XEBgetIESelectedRange() {
	var IESel = {};
	var txtarea;
	if (document.editform) {
		txtarea = document.editform.wpTextbox1;
	} else {
		// some alternate form? take the first one we can find
		var areas = document.getElementsByTagName('textarea');

		txtarea = areas[0];
	}
	// IE & Opera
	if (document.selection && !is_gecko) {
		txtarea.focus();
		IESel.Rng = document.selection.createRange();
		return IESel;
	}
}

function XEBinsertText(beforeText, selText, afterText, IESelectedRange) {
	var newText = beforeText + selText + afterText;
	var txtarea, tr;
	if (document.editform) {
		txtarea = document.editform.wpTextbox1;
	} else {
		// some alternate form? take the first one we can find
		var areas = document.getElementsByTagName('textarea');
		txtarea = areas[0];
	}

	// IE
	if (document.selection && !is_gecko) {

		tr = IESelectedRange.Rng;
		tr.text = newText;
		txtarea.focus();
		//txtarea.caretpos=tr.duplicate();
		tr.select();

		return;

		// Mozilla
	} else if (txtarea.selectionStart || txtarea.selectionStart === 0) {
		var replaced = false;
		var startPos = txtarea.selectionStart;
		var endPos = txtarea.selectionEnd;

		if (endPos - startPos) {
			replaced = true;
		}
		var scrollTop = txtarea.scrollTop;
		//		var myText = (txtarea.value).substring(startPos, endPos);
		//		if (!myText) {
		//			myText=sampleText;
		//		}
		//		if (myText.charAt(myText.length - 1) == " ") { // exclude ending space char, if any
		//			subst = tagOpen + myText.substring(0, (myText.length - 1)) + tagClose + " ";
		//		} else {
		//			subst = tagOpen + myText + tagClose;
		//		}
		txtarea.value = txtarea.value.substring(0, startPos) + newText + txtarea.value.substring(endPos, txtarea.value.length);
		txtarea.focus();
		//set new selection
		if (!replaced) {
			var cPos = startPos + (newText.length);
			txtarea.selectionStart = cPos;
			txtarea.selectionEnd = cPos;
		} else {
			txtarea.selectionStart = startPos + beforeText.length;
			txtarea.selectionEnd = startPos + beforeText.length + selText.length;
		}
		txtarea.scrollTop = scrollTop;

		// All other browsers get no toolbar.
		// There was previously support for a crippled "help"
		// bar, but that caused more problems than it solved.
	}
	// reposition cursor if possible
	if (txtarea.createTextRange) {

		txtarea.caretPos = document.selection.createRange().duplicate();
		//txtarea.caretPos =IESelectedRange.Rng;
	}
	txtarea.focus();
}


//============================================================
// 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) {
}


function XEBPopupRef(e) {

	var m = new GetPos(e || event);

	curPopup = new XEBPopup('ref', m.x, m.y);
	curPopup.width = 300;
	var mt = '<p>Enter the reference parameters below: <\/p>' +
		'<form name="XEBPopupRefForm">' +
		'Name:<input type="text" name="refName" value="" size="10"><p\/>' +
		'Material:<input type="text" name="refMaterial" value="' + XEBGetSelectedText() +
		'" size="20">' +
		'<\/form>' +
		'<p><button onClick="javascript:insertRef()">Insert</button>' +
		'<button onClick="hideXEBPopup()">Cancel</button>';

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

function insertRef() {
	var f = document.XEBPopupRefForm;
	var refName = f.refName.value;
	var refMaterial = f.refMaterial.value;

	hideXEBPopup();
	var code1 = '<ref';
	code1 += (refName) ? ' name="' + refName + '">' : '>';
	var code2 = refMaterial;
	var code3 = '<\/ref>';
	XEBinsertText(code1, code2, code3, curPopup.IESelectedRange);

	extendSummary('ref');
	return false;
}

//===GEO LINK Function==================================================

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

	curPopup = new XEBPopup('geo', m.x, m.y);
	curPopup.width = 300;
	var mt = '<p>Enter the location parameters below: <\/p>' +
		'<form name="XEBPopupGeoLinkForm">' +
		'Location:<p\/>' +
		'<table style="background: transparent;">' +
		'<tr><td>Latitude:<\/td><td><input type="text" autocomplete="off" name="geoLatDeg" value="" size="4"><\/td>' +
		'<td><input type="text" name="geoLatMin" size="4"><\/td>' +
		'<td><input type="text" name="geoLatSec" size="4"><\/td>' +
		'<td><select name="geoLatNS"><option value="N">N<option value="S">S</select><\/td><\/tr>' +
		'<tr><td>Longitude:<\/td><td><input type="text" name="geoLonDeg" value="" size="4"><\/td>' +
		'<td><input type="text" name="geoLonMin" value="" size="4"><\/td>' +
		'<td><input type="text" name="geoLonSec" value="" size="4"><\/td>' +
		'<td><select name="geoLonEW"><option value="E">E<option value="W">W</select><\/td><\/tr>' +
		'<\/table>' +
		'Region:<input type="text" name="geoRegion" value="" size="4"><p\/>' +
		'Type:' +
		'<SELECT NAME="geoType" size="5">' +
		'<OPTION VALUE="country">Country<OPTION VALUE="state">State' +
		'<OPTION VALUE="adm1st">Admin unit, 1st level<OPTION VALUE="adm2st">Admin unit, 2nd level' +
		'<OPTION VALUE="city">City<OPTION VALUE="airport">Airport' +
		'<OPTION VALUE="mountain">Mountain<OPTION VALUE="isle">Isle' +
		'<OPTION VALUE="waterbody">Waterbody<OPTION VALUE="landmark" SELECTED>Landmark' +
		'<OPTION VALUE="forest">forest</SELECT><br>' +
		'Title: <input type="checkbox" name="geoTitle" ><p\/>' +
		'<\/form>' +
		'<p><button onClick="javascript:insertGeoLink()">Insert</button>' +
		'<button onClick="hideXEBPopup()">Cancel</button>';

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

}
function insertGeoLink() {
	var f = document.XEBPopupGeoLinkForm;

	var code = '{{Coor ';
	if (f.geoTitle.checked) {
		code += 'title ';
	}
	var ft = 'dms';
	if (f.geoLatSec.value === '' && f.geoLonSec.value === '') {
		ft = 'dm';
	}
	if (ft === 'dm' && f.geoLatMin.value === '' && f.geoLonMin.value === '') {
		ft = 'd';
	}
	code += ft;
	code += '|' + f.geoLatDeg.value;
	code += (ft === 'dm' || ft === 'dms') ? '|' + f.geoLatMin.value : '';
	code += (ft === 'dms') ? '|' + f.geoLatSec.value : '';
	code += '|' + f.geoLatNS.value;
	code += '|' + f.geoLonDeg.value;
	code += (ft === 'dm' || ft === 'dms') ? '|' + f.geoLonMin.value : '';
	code += (ft === 'dms') ? '|' + f.geoLonSec.value : '';
	code += '|' + f.geoLonEW.value;
	code += '|type:' + f.geoType.value + '_region:' + f.geoRegion.value;
	code += '}}';
	insertTags('', '', code);
	extendSummary('geo-location');
	hideXEBPopup();
	return false;
}

//===Talk Page entry Function===========================================

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

	curPopup = new XEBPopup('talk', m.x, m.y);
	curPopup.width = 200;
	var mt = '<div style="font-size:medium"><p>Please choose:<\/p>';
	mt += '<span class="XEBMnuItm" onclick="XEBInsertTalk(1)">Test1<\/span><br>';
	mt += '<span class="XEBMnuItm" onclick="XEBInsertTalk(2)">Self Test<\/span><br>';
	mt += '<span class="XEBMnuItm" onclick="XEBInsertTalk(3)">Nonsense<\/span><br>';
	mt += '<span class="XEBMnuItm" onclick="XEBInsertTalk(4)">Please stop<\/span><br>';
	mt += '<span class="XEBMnuItm" onclick="XEBInsertTalk(5)">Last chance<\/span><br>';
	mt += '<span class="XEBMnuItm" onclick="XEBInsertTalk(6)">Blanking<\/span><br>';
	mt += '<span class="XEBMnuItm" onclick="XEBInsertTalk(7)">Blatant<\/span><br>';
	mt += '<span class="XEBMnuItm" ;onclick="XEBInsertTalk(8)">*BLOCKED*<\/span><br>';
	mt += '<span class="XEBMnuItm" onclick="XEBInsertTalk(9)">Spam<\/span><br>';
	mt += '<span class="XEBMnuItm" onclick="XEBInsertTalk(10)">Npov<\/span><br>';

	curPopup.setInnerHTML(mt);

	return true;

}

function XEBInsertTalk(itm) {
	var code = {
		1: '{' + '{subst:test1-n|}}',
		2: '{' + '{subst:selftest-n|}}',
		3: '{' + '{subst:test2-n|}}',
		4: '{' + '{subst:test3-n|}}',
		5: '{' + '{subst:test4-n|}}',
		6: '{' + '{subst:test2a-n|}}',
		7: '{' + '{subst:bv-n|}}',
		8: '{' + '{subst:blantant|}}',
		9: '{' + '{subst:spam-n|}}',
		10: '{' + '{subst:NPOV user}}'
	};
	hideXEBPopup();
	insertTags('', '', code[ itm ]);
	return false;
}
function XEBPopupImage(e) {
	var m = new GetPos(e || event);

	curPopup = new XEBPopup('image', m.x, m.y);
	curPopup.width = 300;

	var mt = '<p>Enter the image parameters below: <\/p>' +
		'<form name="XEBPopupImageForm">' +
		'File:<input type="text" name="imgFile" value="' + XEBGetSelectedText() + '" size="30"><br>' +
		'Type:<SELECT NAME="imgType">' +
		'<OPTION VALUE="thumb">Thumbnail' +
		'<OPTION VALUE="frame">Frame' +
		'<OPTION VALUE="none">[not specified]' +
		'</SELECT><br>' +
		'Location:<SELECT NAME="imgLocation">' +
		'<OPTION VALUE="left">Left' +
		'<OPTION VALUE="center">Centre' +
		'<OPTION VALUE="right">Right' +
		'<OPTION VALUE="none">None' +
		'</SELECT><br>' +
		'Size:<input type="text" name="imgSize" value="100" size="3">px<br>' +
		'Caption:<input type="text" name="imgCaption" value="" size="30"><\/p>' +
		'<\/form>' +
		'<p><button onClick="javascript:XEBInsertImage()">Insert</button>' +
		'<button onClick="hideXEBPopup()">Cancel</button>';

	curPopup.setInnerHTML(mt);

	return true;
}

function XEBInsertImage() {
	var f = document.XEBPopupImageForm;
	hideXEBPopup();
	var code = '[[Image:';
	code += f.imgFile.value;
	code += '|' + f.imgType.value;
	code += '|' + f.imgLocation.value;
	code += '|' + f.imgSize.value;
	code += '|' + f.imgCaption.value;
	code += ']]';
	insertTags('', '', code);
	extendSummary('image');

	return false;
}

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

	curPopup = new XEBPopup('image', m.x, m.y);
	curPopup.width = 300;

	var mt = '<form name="XEBPopupImageForm">' +
		'<table  style="background: transparent;">' +
		'<tr><td>Bold:<\/td><td><input type="checkbox" name="textBold"><\/td>' +
		'<td>Superscript:<\/td><td><input type="checkbox" name="textSuperscript"><\/td><\/tr>' +
		'<tr><td>Italic:<\/td><td><input type="checkbox" name="textItalic"><\/td>' +
		'<td>Subscript:<\/td><td><input type="checkbox" name="textSubscript"><\/td><\/tr>' +
		'<tr><td>Strike:<\/td><td><input type="checkbox" name="textStrike"><\/td>' +
		'<td>&nbsp;<\/td><\/tr>' +
		'</table>' +
		'Size:<SELECT NAME="textSize">' +
		'<OPTION VALUE="small">small' +
		'<OPTION VALUE="normal">[Normal]' +
		'<OPTION VALUE="big">big' +
		'</SELECT><br><table style="background:transparent;"><tr><td>Colour:<\/td><td>' +
		'<table width="100px">' +
		'<tr><td colspan="4">None<\/td></tr>' +
		'<tr><td bgcolor="aqua">&nbsp;<\/td><td bgcolor="gray"> &nbsp;<\/td>' +
		'<td bgcolor="olive">&nbsp;<\/td><td bgcolor="navy">&nbsp;<\/td><\/tr>' +
		'<tr><td bgcolor="black">&nbsp;<\/td><td bgcolor="green"> &nbsp;<\/td>' +
		'<td bgcolor="purple">&nbsp;<\/td><td bgcolor="teal">&nbsp;<\/td><\/tr>' +
		'<tr><td bgcolor="blue">&nbsp;<\/td><td bgcolor="lime">&nbsp;<\/td>' +
		'<td bgcolor="red">&nbsp;<\/td><td bgcolor="white">&nbsp;<\/td><\/tr>' +
		'<tr><td bgcolor="fuchsia">&nbsp;<\/td><td bgcolor="maroon">&nbsp;<\/td>' +
		'<td bgcolor="silver">&nbsp;<\/td><td bgcolor="yellow">&nbsp;<\/td><\/tr>' +
		'</table><\/td><\/tr>' +
		'<\/form>' +
		'Sample:' +
		'<span id="sampleText">Text</span>"' +
		'<p><button onClick="javascript:XEBInsertFormattedText()">Insert</button>' +
		'<button onClick="hideXEBPopup()">Cancel</button>';

	curPopup.setInnerHTML(mt);

	return true;
}

function XEBUpdateSampleText() {
	var f = document.XEBPopupImageForm;
}

//====================

function XEBMenuMouseOut(e) {
	var targ;
	if (!e) {
		e = window.event;
	}
	if (e.target) {
		targ = e.target;
	} else if (e.srcElement) {
		targ = e.srcElement;
	}

	targ.style.color = 'black';
}

function XEBMenuMouseOver(e) {
	var targ;
	if (!e) {
		e = window.event;
	}
	if (e.target) {
		targ = e.target;
	} else if (e.srcElement) {
		targ = e.srcElement;
	}

	targ.style.color = 'red';
}

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

function XEBgetElementsByClassName(parent, clsName, htmltag) {
	var arr = [], elem;
	var elems = parent.getElementsByTagName(htmltag);
	for (var cls, i = 0;
	(elem = elems[i]); i++) {
		if (elem.className === clsName) {
			arr[arr.length] = elem;
		}
	}
	return arr;
}

function extendSummary(newText) {
	if (!XEBExtendEditSummary) {
		return;
	}
	var s = document.editform.elements.wpSummary.value;
	s += (s === '') ? newText : ' +' + newText;
	document.editform.elements.wpSummary.value = s;
}

function bug(msg) {
	if (mw.config.get( 'wgUserName' ) === 'MarkS') {
		alert(msg);
	}
}