MediaWiki:Common.js: Difference between revisions

Jump to navigation Jump to search
Content deleted Content added
imported>Hendrik Brummermann
from http://de.wikipedia.org/wiki/MediaWiki:Common.js
imported>Hendrik Brummermann
No edit summary
Line 1: Line 1:
//================================================================================
//================================================================================
//*** Dynamic Expandableigation Bars
//*** Dynamic Expandable Bars
// set up the words in your language
// set up the words in your language
var ExpandableigationBarHide = 'Einklappen';
var ExpandableBarHide = 'Einklappen';
var ExpandableigationBarShow = 'Ausklappen';
var ExpandableBarShow = 'Ausklappen';
// set up max count of Expandableigation Bars on page,
// set up max count of Expandable Bars on page,
// if there are more, all will be hidden
// if there are more, all will be hidden
// ExpandableigationBarShowDefault = 0; // all bars will be hidden
// ExpandableBarShowDefault = 0; // all bars will be hidden
// ExpandableigationBarShowDefault = 1; // on pages with more than 1 bar all bars will be hidden
// ExpandableBarShowDefault = 1; // on pages with more than 1 bar all bars will be hidden
// adds show/hide-button to Expandableigation bars
// adds show/hide-button to Expandable bars
jQuery( document ).ready(function() {
jQuery( document ).ready(function() {
if(!mw.user.options.exists( 'ExpandableigationBarShowDefault' )){
if(!mw.user.options.exists( 'ExpandableBarShowDefault' )){
if (typeof ExpandableigationBarShowDefault != 'undefined' ) {
if (typeof ExpandableBarShowDefault != 'undefined' ) {
mw.user.options.set( 'ExpandableigationBarShowDefault',ExpandableigationBarShowDefault)
mw.user.options.set( 'ExpandableBarShowDefault',ExpandableBarShowDefault)
}
}
}
}
// shows and hides content and picture (if available) of Expandableigation bars
// shows and hides content and picture (if available) of Expandable bars
// Parameters:
// Parameters:
// indexExpandableigationBar: the index of Expandableigation bar to be toggled
// indexExpandableBar: the index of Expandable bar to be toggled
function toggleExpandableigationBar(ExpandableToggle, ExpandableFrame)
function toggleExpandableBar(ExpandableToggle, ExpandableFrame)
{
{
if (!ExpandableFrame || !ExpandableToggle) {
if (!ExpandableFrame || !ExpandableToggle) {
Line 29: Line 29:
// if shown now
// if shown now
if (ExpandableToggle.firstChild.data == ExpandableigationBarHide) {
if (ExpandableToggle.firstChild.data == ExpandableBarHide) {
for (
for (
var ExpandableChild = ExpandableFrame.firstChild;
var ExpandableChild = ExpandableFrame.firstChild;
Line 42: Line 42:
}
}
if (ExpandableChild.className == 'ExpandableToggle') {
if (ExpandableChild.className == 'ExpandableToggle') {
ExpandableChild.firstChild.data = ExpandableigationBarShow;
ExpandableChild.firstChild.data = ExpandableBarShow;
}
}
}
}
// if hidden now
// if hidden now
} else if (ExpandableToggle.firstChild.data == ExpandableigationBarShow) {
} else if (ExpandableToggle.firstChild.data == ExpandableBarShow) {
for (
for (
var ExpandableChild = ExpandableFrame.firstChild;
var ExpandableChild = ExpandableFrame.firstChild;
Line 60: Line 60:
}
}
if (ExpandableChild.className == 'ExpandableToggle') {
if (ExpandableChild.className == 'ExpandableToggle') {
ExpandableChild.firstChild.data = ExpandableigationBarHide;
ExpandableChild.firstChild.data = ExpandableBarHide;
}
}
}
}
Line 66: Line 66:
}
}
function toggleExpandableigationBarFunction(ExpandableToggle, ExpandableFrame) {
function toggleExpandableBarFunction(ExpandableToggle, ExpandableFrame) {
return function() {
return function() {
toggleExpandableigationBar(ExpandableToggle, ExpandableFrame);
toggleExpandableBar(ExpandableToggle, ExpandableFrame);
return false;
return false;
};
};
Line 75: Line 75:
var ExpandableFrames = mw.util.$content.find( 'div.ExpandableFrame' );
var ExpandableFrames = mw.util.$content.find( 'div.ExpandableFrame' );
// if more Expandableigation Bars found and not template namespace than Default: hide all
// if more Expandable Bars found and not template namespace than Default: hide all
var initiallyToggle = mw.user.options.get( 'ExpandableigationBarShowDefault',1 ) < ExpandableFrames.length && mw.config.get( 'wgNamespaceNumber' ) != 10;
var initiallyToggle = mw.user.options.get( 'ExpandableBarShowDefault',1 ) < ExpandableFrames.length && mw.config.get( 'wgNamespaceNumber' ) != 10;
for (var i=0; i<ExpandableFrames.length; i++) {
for (var i=0; i<ExpandableFrames.length; i++) {
var ExpandableFrame = ExpandableFrames[i];
var ExpandableFrame = ExpandableFrames[i];
Line 83: Line 83:
ExpandableToggle.setAttribute('href', '#');
ExpandableToggle.setAttribute('href', '#');
var ExpandableToggleText = document.createTextNode(ExpandableigationBarHide);
var ExpandableToggleText = document.createTextNode(ExpandableBarHide);
ExpandableToggle.appendChild(ExpandableToggleText);
ExpandableToggle.appendChild(ExpandableToggleText);
Line 90: Line 90:
ExpandableFrame.insertBefore(ExpandableToggle, ExpandableFrame.firstChild);
ExpandableFrame.insertBefore(ExpandableToggle, ExpandableFrame.firstChild);
ExpandableToggle.onclick = toggleExpandableigationBarFunction(ExpandableToggle, ExpandableFrame);
ExpandableToggle.onclick = toggleExpandableBarFunction(ExpandableToggle, ExpandableFrame);
if (initiallyToggle) {
if (initiallyToggle) {
toggleExpandableigationBar(ExpandableToggle, ExpandableFrame);
toggleExpandableBar(ExpandableToggle, ExpandableFrame);
}
}
}
}