MediaWiki:Common.js
Erscheinungsbild
Hinweis: Leere nach dem Veröffentlichen den Browser-Cache, um die Änderungen sehen zu können.
- Firefox/Safari: Umschalttaste drücken und gleichzeitig Aktualisieren anklicken oder entweder Strg+F5 oder Strg+R (⌘+R auf dem Mac) drücken
- Google Chrome: Umschalttaste+Strg+R (⌘+Umschalttaste+R auf dem Mac) drücken
- Edge: Strg+F5 drücken oder Strg drücken und gleichzeitig Aktualisieren anklicken
/* Jedes JavaScript hier wird für alle Benutzer für jede Seite geladen. */
// END Enable multiple onload functions
// ============================================================
//----------------------------------------------------------------------------
//## Annotations, PageNumbers and LineBreaks
/** allows showing or hiding tags of a given class */
function showHideToggle(tagName, className, linkId, cookieName, showLabel, hideLabel) {
var show = true;
var elements;
var link;
/** initialize everything, to be called onload */
function init() {
elements = findTagsWithClass(tagName, className);
if (elements.length == 0) return;
var cookie = GetCookieOnWS(cookieName);
if (cookie) show = cookie == "true";
link = document.createElement("a");
link.style.cursor = 'pointer';
link.appendChild(document.createTextNode(""));
// TODO IE-memleak?
link.onclick = function() {
show = !show;
update();
};
var item = document.createElement("li");
item.setAttribute('id', linkId);
item.appendChild(link);
var specialPages = document.getElementById("t-specialpages");
if (specialPages) {
specialPages.parentNode.appendChild(item);
}
update();
}
/** show or hide elements and change toggle link accordingly */
function update() {
SetCookieOnWS(cookieName, show);
link.firstChild.data = show ? hideLabel : showLabel;
for (var i=0; i<elements.length; i++) {
var element = elements[i];
element.style.display = show ? "inline" : "none";
}
}
return init;
}
/** returns an Array containing all tags with a given tagName and className in the document */
function findTagsWithClass(tagName, className) {
var out = [];
var tags = document.getElementsByTagName(tagName);
for (var i=0; i<tags.length; i++) {
var tag = tags[i];
var reg = new RegExp(className);
if (tag.className.search(reg) != -1) {
out[out.length] = tag;
}
}
return out;
}
// see [[:Vorlage:Seite]]
$(document).ready( function() {
showHideToggle(
"span", // tagName
"PageNumber", // className
"t-pagenumbers", // linkId
"DisplayPageNumbers", // cookieName
"Seitenzahlen einblenden", // showLabel
"Seitenzahlen ausblenden"); // hideLabel
});
// see [[:Vorlage:An]]
$(document).ready( function() {
showHideToggle(
"span", // tagName
"Annotation", // className
"t-annotationdisplay", // linkId
"DisplayAnnotations", // cookieName
"Anmerkungen einblenden", // showLabel
"Anmerkungen ausblenden"); // hideLabel
});
//============================================================================
function interwikiExtra()
{
var spans = document.getElementsByTagName("span");
for(var i=0; i<spans.length; i++) {
var a = spans[i];
// if found a linkInfo span
if(a.className == "interwiki-info") {
// iterate over all <li>-elements
var count=0;
var lis = document.getElementsByTagName("li");
for (var j=0; j<lis.length; j++) {
var b = lis[j];
if(b.className == "interwiki-" + a.id) {
b.innerHTML = b.innerHTML + " "+a.title;
if(a.title == "(OV)") { b.title = "Originaltext"; }
}
else if(b.className == "interwiki-" + a.id.substr(0,a.id.length-1)) {
count = count+1;
if(a.id.charAt(a.id.length-1) == count) {
b.innerHTML = b.innerHTML + " "+a.title;
}
}
}
}
if(a.className == "AndereVersion") {
p = a.title.indexOf("|");
pvers = document.getElementById("p-version");
if (pvers == null) {
c = document.getElementById("column-one");
c.innerHTML = c.innerHTML
+ "<div class=\"portlet\" id=\"p-version\">"
+ "<h5>Andere Versionen</h5>"
+ "<div class=\"pBody\">"
+ "<ul>"
+ "</ul>"
+ "</div>";
pvers = document.getElementById("p-version");
}
e = pvers.getElementsByTagName("ul")[pvers.getElementsByTagName("ul").length -1];
if (p == "-1") {
var hr = document.createElement("hr");
var ul = document.createElement("ul");
e.parentNode.appendChild(hr);
e.parentNode.appendChild(ul);
} else {
e.innerHTML = e.innerHTML
+ "<li class=\"\"><a href='/wiki/"
+ a.title.substr(0,p)
+ "'>" + a.title.substr(p+1,a.title.length-1)+ "</a> " +"</li>";
}
}
}
}
$(document).ready(interwikiExtra);
function AdbMoveCiteBox() {
s = document.getElementById("adbcite");
if (s) {
t = document.getElementById("catlinks");
if (t) t.parentNode.insertBefore(s, t.previousSibling);
}
}
$(document).ready(AdbMoveCiteBox);
//--------------------------------------------------------------------------------
//## Cookies
function SetCookieOnWS(name,value) {
document.cookie = name + "=" + escape(value);
}
function GetCookieOnWS(name) {
var i =0;
while (i < document.cookie.length) {
if (document.cookie.substr(i,name.length) == name) {
var valend = document.cookie.indexOf(";",i+name.length+1);
if (valend == -1) {
valend = document.cookie.length;
}
return unescape(document.cookie.substring(i+name.length+1,valend));
}
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
}
/** Collapsible tables *********************************************************
*
* Description: Allows tables to be collapsed, showing only the header. See
* http://www.mediawiki.org/wiki/Manual:Collapsible_tables.
* Maintainers: [[**MAINTAINERS**]]
*/
var autoCollapse = 2;
var collapseCaption = 'Einklappen';
var expandCaption = 'Ausklappen';
function collapseTable( tableIndex ) {
var Button = document.getElementById( 'collapseButton' + tableIndex );
var Table = document.getElementById( 'collapsibleTable' + tableIndex );
if ( !Table || !Button ) {
return false;
}
var Rows = Table.rows;
if ( Button.firstChild.data == collapseCaption ) {
for ( var i = 1; i < Rows.length; i++ ) {
Rows[i].style.display = 'none';
}
Button.firstChild.data = expandCaption;
} else {
for ( var i = 1; i < Rows.length; i++ ) {
Rows[i].style.display = Rows[0].style.display;
}
Button.firstChild.data = collapseCaption;
}
}
function createCollapseButtons() {
var tableIndex = 0;
var NavigationBoxes = {};
var Tables = document.getElementsByTagName( 'table' );
for ( var i = 0; i < Tables.length; i++ ) {
if ( $( Tables[i] ).hasClass( 'collapsible' ) ) {
/* only add button and increment count if there is a header row to work with */
var HeaderRow = Tables[i].getElementsByTagName( 'tr' )[0];
if( !HeaderRow ) continue;
var Header = HeaderRow.getElementsByTagName( 'th' )[0];
if( !Header ) continue;
NavigationBoxes[tableIndex] = Tables[i];
Tables[i].setAttribute( 'id', 'collapsibleTable' + tableIndex );
var Button = document.createElement( 'span' );
var ButtonLink = document.createElement( 'a' );
var ButtonText = document.createTextNode( collapseCaption );
Button.className = 'collapseButton'; // Styles are declared in MediaWiki:Common.css
ButtonLink.style.color = Header.style.color;
ButtonLink.setAttribute( 'id', 'collapseButton' + tableIndex );
ButtonLink.setAttribute( 'href', "javascript:collapseTable(" + tableIndex + ");" );
ButtonLink.appendChild( ButtonText );
Button.appendChild( document.createTextNode( '[' ) );
Button.appendChild( ButtonLink );
Button.appendChild( document.createTextNode( ']' ) );
Header.insertBefore( Button, Header.childNodes[0] );
tableIndex++;
}
}
for ( var i = 0; i < tableIndex; i++ ) {
if ( hasClass( NavigationBoxes[i], 'collapsed' ) || ( tableIndex >= autoCollapse && hasClass( NavigationBoxes[i], 'autocollapse' ) ) ) {
collapseTable( i );
}
}
}
$(document).ready(createCollapseButtons);
/** Test if an element has a certain class **************************************
*
* Description: Uses regular expressions and caching for better performance.
* Maintainers: [[User:Mike Dillon]], [[User:R. Koot]], [[User:SG]]
*/
var hasClass = (function() {
var reCache = {};
return function( element, className ) {
return (reCache[className] ? reCache[className] : (reCache[className] = new RegExp("(?:\\s|^)" + className + "(?:\\s|$)"))).test(element.className);
};
})();
//Vordefinition für eigene Sonderzeichenleiste
MyChar = [];
MyCharText = [];
MyCharEnd = [];
MyCharDefault = [];
// ============================================================
// BEGIN import Onlyifediting-functions (z.B. für Dropdown-Leiste zum Einfügen von Sonderzeichen)
// SEE ALSO [[MediaWiki:Onlyifediting.js]]
//Im Bearbeitungsmodus?
if ($.inArray(mw.config.get('wgAction'), ['edit' , 'submit']) !== -1) {
importScript('MediaWiki:Onlyifediting.js');
}
// END import Onlyifediting-functions
// ============================================================
importScript('MediaWiki:ProofreadPage.js');
importScript('MediaWiki:DynamicView.js');
// disable easy lst
self.proofreadpage_raw_lst = true;
// custom collations (r86088)
tableSorterCollation={'Ä':'A', 'Ö':'O', 'Ü':'U', 'ä':'a', 'ö':'o', 'ü':'u', 'ß':'ss'};
// delete Byte Order Mark
(function(){
var action = mw.config.get('wgAction');
if(action !== 'edit' && action !== 'submit') { return; }
$(function() {
$('#wpTextbox1').val($('#wpTextbox1').val().replace(/\uFEFF/gi,''));
});
})();
// bugzilla:36310
if (mw.config.get('wgCanonicalSpecialPageName') === 'Movepage') {
$('#wpReason').prop('maxLength', 200);
}
// Results from Wikidata
// [[File:Wdsearch_script_screenshot.png]]
if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Search' || ( mw.config.get( 'wgArticleId' ) === 0 && mw.config.get( 'wgCanonicalSpecialPageName' ) === false ) ) {
mw.loader.load("//en.wikipedia.org/w/index.php?title=MediaWiki:Wdsearch.js&action=raw&ctype=text/javascript");
}
// Export nach Pdf, LaTeX, Epub, Odt
// mediawiki2latex.wmflabs.org
mw.util.addPortletLink ('p-tb', 'https://mediawiki2latex.wmflabs.org/'+'fill/'+encodeURIComponent('https://de.wikisource.org'+mw.config.get('wgArticlePath').replace('$1', encodeURIComponent(mw.config.get('wgPageName')))), 'Multi Format Export');