MediaWiki:Common.js: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Erik (Diskussion | Beiträge) K Versuch misslungen |
Erik (Diskussion | Beiträge) K Neue Buttons für die Edit-Leiste |
||
| Zeile 136: | Zeile 136: | ||
// END Dynamic Navigation Bars | // END Dynamic Navigation Bars | ||
// ============================================================ | // ============================================================ | ||
//============================================================ | |||
// 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. | |||
//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}); | |||
} | |||
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','<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{| {{Prettytable}} 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','{{subst:unsigned|','|date}}','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',' ','',''], | |||
'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'] | |||
}; | |||
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(","); | |||
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 (its not if just viewing the page, in which case IE might display an error) | |||
if(typeof bc!='object')return; | |||
addCustomButton(bc[0],bc[1],bc[2],bc[3],bc[4]); | |||
} | |||
// Remove the default buttons (if requested by the user) | |||
eraseButtons(); | |||
} | |||
addOnloadHook(initButtons); | |||
/** 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<enExtraButtons;i++){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 | |||
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<mwEditButtons.length){ | |||
if(n<mwEditButtons.length){ | |||
var x = -1; | |||
while((++x)<mwEditButtons.length) | |||
if(x>=n) | |||
mwEditButtons[x] = mwEditButtons[x+1]; | |||
} | |||
mwEditButtons.pop(); | |||
} | |||
//Extra buttons in English Wikipedia | |||
n=n-mwEditButtons.length; | |||
if(n>0 && n<mwCustomEditButtons.length){ | |||
if(n<mwCustomEditButtons.length){ | |||
var x = -1; | |||
while((++x)<mwCustomEditButtons.length) | |||
if(x>=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) | |||
} | |||
Version vom 1. Juli 2007, 19:16 Uhr
/* Jedes JavaScript hier wird für alle Benutzer für jede Seite geladen. */
// ============================================================
// BEGIN Enable multiple onload functions
// setup onload functions this way:
// aOnloadFunctions[aOnloadFunctions.length] = function_name; // without brackets!
if (!window.aOnloadFunctions) {
var aOnloadFunctions = new Array();
}
window.onload = function() {
if (window.aOnloadFunctions) {
for (var _i=0; _i<aOnloadFunctions.length; _i++) {
aOnloadFunctions[_i]();
}
}
}
// END Enable multiple onload functions
// ============================================================
// ============================================================
// BEGIN Dynamic Navigation Bars
// NEEDS Enable multiple onload functions
// set up the words in your language
var NavigationBarHide = 'Einklappen';
var NavigationBarShow = 'Ausklappen';
// set up max count of Navigation Bars on page,
// if there are more, all will be hidden
// NavigationBarShowDefault = 0; // all bars will be hidden
// NavigationBarShowDefault = 1; // on pages with more than 1 bar all bars will be hidden
NavigationBarShowDefault = 3;
if (typeof NavigationBarShowDefault == 'undefined' ) {
var NavigationBarShowDefault = 1;
}
// shows and hides content and picture (if available) of navigation bars
// Parameters:
// indexNavigationBar: the index of navigation bar to be toggled
function toggleNavigationBar(indexNavigationBar)
{
var NavToggle = document.getElementById("NavToggle" + indexNavigationBar);
var NavFrame = document.getElementById("NavFrame" + indexNavigationBar);
if (!NavFrame || !NavToggle) {
return false;
}
// if shown now
if (NavToggle.firstChild.data == NavigationBarHide) {
for (
var NavChild = NavFrame.firstChild;
NavChild != null;
NavChild = NavChild.nextSibling
) {
if (NavChild.className == 'NavPic') {
NavChild.style.display = 'none';
}
if (NavChild.className == 'NavContent') {
NavChild.style.display = 'none';
}
if (NavChild.className == 'NavToggle') {
NavChild.firstChild.data = NavigationBarShow;
}
}
// if hidden now
} else if (NavToggle.firstChild.data == NavigationBarShow) {
for (
var NavChild = NavFrame.firstChild;
NavChild != null;
NavChild = NavChild.nextSibling
) {
if (NavChild.className == 'NavPic') {
NavChild.style.display = 'block';
}
if (NavChild.className == 'NavContent') {
NavChild.style.display = 'block';
}
if (NavChild.className == 'NavToggle') {
NavChild.firstChild.data = NavigationBarHide;
}
}
}
}
// adds show/hide-button to navigation bars
function createNavigationBarToggleButton()
{
var indexNavigationBar = 0;
// iterate over all < div >-elements
for(
var i=0;
NavFrame = document.getElementsByTagName("div")[i];
i++
) {
// if found a navigation bar
if (NavFrame.className == "NavFrame") {
indexNavigationBar++;
var NavToggle = document.createElement("a");
NavToggle.className = 'NavToggle';
NavToggle.setAttribute('id', 'NavToggle' + indexNavigationBar);
NavToggle.setAttribute('href', 'javascript:toggleNavigationBar(' + indexNavigationBar + ');');
var NavToggleText = document.createTextNode(NavigationBarHide);
NavToggle.appendChild(NavToggleText);
// add NavToggle-Button as first div-element
// in < div class="NavFrame" >
NavFrame.insertBefore(
NavToggle,
NavFrame.firstChild
);
NavFrame.setAttribute('id', 'NavFrame' + indexNavigationBar);
}
}
// if more Navigation Bars found than Default: hide all
if (NavigationBarShowDefault < indexNavigationBar) {
for(
var i=1;
i<=indexNavigationBar;
i++
) {
toggleNavigationBar(i);
}
}
}
aOnloadFunctions[aOnloadFunctions.length] = createNavigationBarToggleButton;
// END Dynamic Navigation Bars
// ============================================================
//============================================================
// 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.
//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});
}
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','<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{| {{Prettytable}} 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','{{subst:unsigned|','|date}}','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',' ','',''],
'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']
};
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(",");
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 (its not if just viewing the page, in which case IE might display an error)
if(typeof bc!='object')return;
addCustomButton(bc[0],bc[1],bc[2],bc[3],bc[4]);
}
// Remove the default buttons (if requested by the user)
eraseButtons();
}
addOnloadHook(initButtons);
/** 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<enExtraButtons;i++){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
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<mwEditButtons.length){
if(n<mwEditButtons.length){
var x = -1;
while((++x)<mwEditButtons.length)
if(x>=n)
mwEditButtons[x] = mwEditButtons[x+1];
}
mwEditButtons.pop();
}
//Extra buttons in English Wikipedia
n=n-mwEditButtons.length;
if(n>0 && n<mwCustomEditButtons.length){
if(n<mwCustomEditButtons.length){
var x = -1;
while((++x)<mwCustomEditButtons.length)
if(x>=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)
}