MediaWiki:Common.js: Unterschied zwischen den Versionen

Zur Navigation springen Zur Suche springen
Zeile 3: Zeile 3:
 
   var sysopRights = true;  
 
   var sysopRights = true;  
  
 +
/*********************
 +
GLOSSAR
 +
*********************/
  
/*** GLOSSAR ***/
 
 
// s.a. vorlage:glossar   
 
// s.a. vorlage:glossar   
 
$('.glossar').each(function(){
 
$('.glossar').each(function(){
 
   var child = $(this).find('.g_box')
 
   var child = $(this).find('.g_box')
    , parent = $(this).closest('p, li') ;  
+
    , parent = $(this).closest('p, li') ;  
 
   $( parent).css("position", "relative");   
 
   $( parent).css("position", "relative");   
 
   
 
   
Zeile 22: Zeile 24:
 
   }
 
   }
 
   
 
   
   $( this).click(function(){ $( child).slideToggle('slow'); });
+
   $( this ).click(function(){ $( child).slideToggle('slow'); });
   $( this).mouseleave(function(){ $(child).slideUp('slow'); });  
+
   $( this ).mouseleave(function(){ $(child).slideUp('slow'); });  
 
   
 
   
 
});
 
});
 +
 +
/***********************************
 +
  NAVIGATION
 +
************************************/
 +
 +
var nav = $( "#nv" );
 +
var cont= $( "#content" );
 +
var search= $("<div id='search2'></div>").append($('#searchform'));
 +
var fixOK = 1;
 +
$('#chapters').append($(search));
 +
 +
/***********************************
 +
    Anpassen an Browserfenster, u.a.
 +
************************************/
 +
 +
var toggleNav =  $( "<div id='tS' title='Navigation vergößern' class='fas fa-bars'></div>" )
 +
  .click( function() {  $( nav ).toggleClass( 'nv_large' );  });
 +
$( nav ).append(toggleNav );
 +
 +
/*        Handys und kleine Bildschirme        */
 +
 +
function sizeX() {
 +
 +
var wiW = window.innerWidth ||  document.documentElement.offsetWidth || 0;
 +
var wiH = window.innerHeight ||  document.documentElement.offsetHeight || 0;
 +
 +
$( nav ).removeClass( 'nv_large' );
 +
 +
if (wiW < wiH*0.7 || wiW < 940) {
 +
fixOK = 0;  // fixed ausschalten
 +
$ (cont).addClass( 'mobileeee' );
 +
$ (nav).removeClass( 'fixed' );
 +
}
 +
else  {
 +
fixOK = 1;  // fixed einschalten
 +
$ (cont).removeClass( 'mobileeee' );
 +
}
 +
}
 +
 +
function sizeY() {
 +
//Maße und Elemente 
 +
  var body_height = document.getElementById("footer").offsetTop + 70
 +
    , screen_height = window.innerHeight ||
 +
      document.documentElement.offsetHeight
 +
    , diff = screen_height - body_height
 +
  // Höhe anpassen
 +
    , spacer =  document.getElementById("catlinks")?
 +
      document.getElementById("catlinks").parentNode.insertBefore(document.createElement("DIV"), document.getElementById("catlinks")) :
 +
      document.getElementById("bodyContent").appendChild( document.createElement("DIV") );
 +
 
 +
  spacer.style.paddingTop = diff > 0 ? diff +"px" : 0;
 +
}
 +
 +
sizeX();
 +
sizeY();
 +
window.onresize = function() { sizeX(); };
 +
// window.onresize = function() { sizeY(); };
  
/*** POPUPS ***/
+
/*****************
    if (wgNamespaceNumber != 6)
+
        Navigation
    {// Altes speichern und neue Elemente gestalten
+
*****************/
var pps = [];
 
var all, pfeiltasten, usePfeiltasten, ppScreen;
 
  
var body_width = document.body.offsetWidth;
+
var nav2 = document.getElementById('nv');  
var body_height = document.body.offsetHeight;
 
  
function setPopup() {
+
function findPos(b) { //Position von b ( = nav2) ermitteln
 
   var a = 0;
 
   var a = 0;
// FOR Schleife
+
   if(b.offsetParent)
   for (var i=0;i<document.getElementsByTagName('img').length;i++) {
+
     for(a = b.offsetTop;b = b.offsetParent;)
// 1. Bedingungen für Popup
+
       a += b.offsetTop;
    if (document.getElementsByTagName('img')[i].src.indexOf('thumb')!=-1
+
  return[a];
      && document.getElementsByTagName('img')[i].parentNode.tagName == 'A'
 
      && document.getElementsByTagName('img')[i].width > 100)
 
      var thumb = document.getElementsByTagName('img')[i];
 
     else
 
      continue;
 
// 2. Bedingungen für Popup
 
    var bildSrc = thumb.src.replace(/thumb\//, '');
 
      bildSrc = bildSrc.slice(0,(bildSrc.indexOf(bildSrc.split('/')[bildSrc.split('/').length-1]))-1);
 
    var link = thumb.parentNode.href;     
 
    var bildname = link.split(':')[link.split(':').length-1];   
 
    var ppText = document.getElementById('pp_'+bildname) ||
 
      document.getElementById('pp_'+bildname.toLowerCase()) || false;
 
    if (!ppText)
 
      continue;
 
// Link ändern
 
    thumb.parentNode.href = 'javascript:open_popup('+a+')';
 
    thumb.parentNode.title = 'Popup öffnen'; 
 
// images in neues Objekt laden
 
    pps[a] = {};
 
    pps[a].image = new Image;   
 
    pps[a].image.src = bildSrc; 
 
// Popups gestalten
 
    pps[a].div = document.body.appendChild(document.createElement('div'));
 
      pps[a].div.className = 'ppDiv';
 
      pps[a].div.style.display = 'none';
 
    pps[a].frame = pps[a].div.appendChild(document.createElement('div'));
 
      pps[a].frame.className = 'ppFrame';
 
      pps[a].frame.appendChild(pps[a].image);
 
    pps[a].index =pps[a].frame.appendChild(document.createElement('div'));
 
      pps[a].index.className = 'ppIndex';
 
    pps[a].back = pps[a].frame.appendChild(document.createElement('a'))
 
      pps[a].back.className  = 'ppBack';
 
      pps[a].back.title  = 'voriges Bild';
 
      pps[a].back.innerHTML= '<span class="fa fa-chevron-left"></span>';
 
      pps[a].back.href = 'javascript:open_popup('+(a-1)+')';
 
    pps[a].next = pps[a].frame.appendChild(document.createElement('a'));
 
      pps[a].next.className = 'ppNext';
 
      pps[a].next.title = 'nächstes Bild';
 
      pps[a].next.innerHTML= '<span class="fa fa-chevron-right"></span>';
 
      pps[a].next.href = 'javascript:open_popup('+(a+1)+')';
 
    pps[a].click = pps[a].frame.appendChild(document.createElement('div'));   
 
       pps[a].click.className = 'ppClick'; 
 
      pps[a].click.innerHTML =
 
        '<span>Ins Bild klicken oder Pfeiltasten [&larr;] [&rarr;] = Neues Bild!<br/>' +  
 
        'Sonst wo klicken oder [Esc] = Bild schließen!</span>';
 
// bildtext in popup einfuegen
 
    pps[a].text = pps[a].div.appendChild(ppText);  
 
      pps[a].text.className = 'ppText';
 
    var bildlinks = pps[a].text.appendChild(document.createElement('p'));
 
      bildlinks.className = 'editsection';
 
      bildlinks.innerHTML += '<a href="'+link+'">[Bildseite]</a> ';
 
      if (sysopRights)
 
        bildlinks.innerHTML += '<a href="'+link+'?action=edit">[edit]</a> ';
 
    pps[a].vollbildlink = pps[a].text.appendChild(document.createElement('div'));
 
      pps[a].vollbildlink.className = 'editsection';
 
// ausblenden
 
    pps[a].div.onclick =
 
    pps[a].click.onclick =
 
    pps[a].text.onclick = hidePopup;
 
// weiterzählen
 
    a++;
 
  } // Ende FOR
 
// Arrays zählen
 
  all = pps.length;
 
// schwarze leinwand
 
  ppScreen = document.body.appendChild(document.createElement('div'));
 
  ppScreen.id = 'ppScreen';
 
  with (ppScreen.style) {
 
    //width = document.body.offsetWidth+'px';
 
    //height = document.body.offsetHeight+'px';
 
    display = 'none';
 
  } 
 
  ppScreen.onclick = hidePopup;
 
 
}
 
}
 +
var nvY = findPos(nav2);
 +
 +
function fixNv() {
  
/////// POPUP ÖFFNEN
+
if (!fixOK) return;   
function open_popup(p,g) {
+
     //Scrollposition ermitteln
  p = (p < all) ? (p < 0) ? all + p : p : all - p;
 
  g = g || 0;
 
// Anpassen der Bildgroesse
 
  var screen_height = window.innerHeight || document.documentElement.offsetHeight;
 
  var screen_width = window.innerWidth-27 || document.documentElement.offsetWidth-27;
 
//Originalgroesse speichern
 
  pps[p].width = pps[p].width || pps[p].image.width;
 
  pps[p].height = pps[p].height || pps[p].image.height;
 
// Link für übergroße Bilder
 
  var vbLink = '<a href="javascript:open_popup('+p+','+1+')">'+
 
    'Volle Auflösung ('+pps[p].height+' x '+pps[p].width+' px)</a>';
 
// Vollbild anzeigen
 
  if (g) {
 
    pps[p].image.width = pps[p].width;
 
    pps[p].image.height = pps[p].height;
 
    pps[p].vollbildlink.innerHTML = '';
 
  }
 
// Verkleinertes Bild
 
  else {
 
    if (pps[p].width > screen_width-8) {
 
      pps[p].image.height = pps[p].height/pps[p].width*(screen_width-8);
 
      pps[p].image.width  = screen_width-8 ;
 
      pps[p].vollbildlink.innerHTML = vbLink;
 
    }
 
    if (pps[p].height > screen_height-30) {
 
      pps[p].image.width = pps[p].width/pps[p].height*(screen_height-30);
 
      pps[p].image.height = screen_height-30 ;
 
      pps[p].vollbildlink.innerHTML = vbLink;
 
     }
 
  }
 
// Frame und Text positionieren
 
  var diffWidth  = (screen_width - 8 - pps[p].image.width)/2;
 
  var diffHeight = (screen_height - 30 - pps[p].image.height)/2;
 
 
   var scrY = document.documentElement.scrollTop || // Explorer 6 Strict
 
   var scrY = document.documentElement.scrollTop || // Explorer 6 Strict
    document.body.scrollTop || //all other Explorers
+
document.body.scrollTop || //all other Explorers
    self.pageYOffset || 0;
+
self.pageYOffset ||
  pps[p].frame.style.marginLeft = g ? 0 : diffWidth + 'px';
+
0;
   pps[p].text.style.clear = (diffWidth < 160) ? 'left' : 'none';
+
   if(self.pageYOffset)
// Bilder Index anzeigen
+
    scrY = self.pageYOffset;
  pps[p].index.innerHTML = 'Bild '+(p+1)+'/'+all;
+
   else if(document.documentElement && document.documentElement.scrollTop)
// nur ein Bild
+
     scrY = document.documentElement.scrollTop;
   if (all == 1) {
+
   else if(document.body)
    pps[p].back.style.visibility =
+
     scrY = document.body.scrollTop;
     pps[p].next.style.visibility = 'hidden';
+
  if(fixOK && typeof document.body.style.maxHeight !== "undefined" && nav2!=='') // nur neuere Browser
    pps[p].click.innerHTML = '<span>Beliebiger Klick oder [Esc] = Bild schließen!</span>' ;
+
    nav2.className scrY > nvY - 30 ? "fixed" : "";
   }
+
   else nav2.className = "";
// Pfeiltasten
 
  usePfeiltasten = true;
 
  pfeiltasten = function(e) {
 
     e=e||event;
 
    if (e.keyCode && usePfeiltasten)
 
      switch (e.keyCode) {
 
        case 39:  open_popup(p+1);break;
 
        case 102: open_popup(p+1);break;
 
case 37: open_popup(p-1); break;
 
        case 100: open_popup(p-1); break;
 
case 27: hidePopup(); break;
 
      }
 
  }
 
  document.onkeydown = pfeiltasten;
 
// Einblenden
 
  ppScreen.style.display = 'block';
 
  pps[p].div.style.top g ? scrY+'px' : (scrY + diffHeight/2)+'px';  
 
   for (var i=0;i<all;i++)
 
    pps[i].div.style.display = i==p? 'block' : 'none';
 
 
}
 
}
 +
  //Menü stabilisieren
 +
var toggleFix = $("<div title = 'Menü oben stabilisieren' id = 'tF' class='fa fa-arrow-up'></div>").click( function() { menuTop(); } );
 +
$( "#chapters" ).append( toggleFix ); 
  
// popup-Div aufblenden (dzt. ungenutzt)
+
function menuTop() {
function initFade(x) {
+
   fixOK = 0;
   for (var i=5;i<11;i++)
+
$( nav).removeClass( 'fixed' );  
    setTimeout('setOpacity('+i+','+x+')',40*i);
 
  return false;
 
}
 
function setOpacity(value,x) {
 
  pps[x].image.style.opacity = value/10;
 
  pps[x].image.style.filter = 'alpha(opacity=' + value*10 + ')';
 
 
}
 
}
 +
function styleNv() {
 +
  var selflink = document.getElementById('chapters').getElementsByTagName('STRONG')[0]||0;
 +
  if (selflink && selflink.parentNode.parentNode.parentNode.tagName == 'LI') {
 +
    selflink.parentNode.parentNode.parentNode.className='self_parent';
 +
    //selflink.parentNode.parentNode.parentNode.className='selflink';
 +
  } 
 +
}
 +
styleNv();
 +
 +
window.onscroll = fixNv;
 +
 +
//Navigation Hover
  
///////////// popup-Div SCHLIESSEN
+
$('#chapters div[id]').on("touchstart", function (e) {
 +
'use strict'; //satisfy code inspectors
 +
var link = $(this); //preselect the link
 +
if (link.hasClass('hover')) {
 +
  return true;
 +
}
 +
else {
 +
  $('#chapters div[id]').removeClass('hover');
 +
  link.addClass('hover');
 +
  return false; //extra, and to make sure the function has consistent return points
 +
}
 +
});
  
function hidePopup() {  
+
/***********************************
  ppScreen.style.display = 'none';
+
      Change redirected address line
  for (var i in pps)
+
***********************************/
    pps[i].div.style.display = 'none';
+
( function ( $, mw ) {
// Pfeiltasten nicht mehr verwenden
+
if ( !window.history || !window.history.replaceState ) {
  usePfeiltasten = false;
+
return;
}
+
}
 +
 +
mw.loader.using( 'jquery.mwExtension', function () {
 +
var articlePathRE, pathQuery, path;
 +
 +
articlePathRE = new RegExp(
 +
'^' +
 +
$.escapeRE( mw.config.get( 'wgArticlePath' ) ).replace( '\\$1', mw.config.get( 'wgArticlePath' ).indexOf( '?' ) >= -1 ? '([^?]*)' : '([^&]*)' ) +
 +
'$'
 +
);
 +
pathQuery = location.pathname + ( location.search ? '?' + location.search : '' );
 +
// Only execute on paths matching the article path (don't squash query arguments)
 +
if ( articlePathRE.test( pathQuery ) ) {
 +
path = mw.util.wikiGetlink( mw.config.get( 'wgPageName' ) );
 +
path += window.location.hash || '';
 +
window.history.replaceState( {}, document.title, path );
 +
}
 +
} );
  
setPopup();
+
}( jQuery, mediaWiki ) );
    }
 

Version vom 17. Dezember 2018, 14:26 Uhr

for (var i in wgUserGroups)
 if (wgUserGroups[i] === 'sysop')
  var sysopRights = true; 

/********************* 
	GLOSSAR 
*********************/ 

// s.a. vorlage:glossar  
$('.glossar').each(function(){
  var child = $(this).find('.g_box')
    , parent = $(this).closest('p, li') ; 
  $( parent).css("position", "relative");   
 
  var diff = ($(this).width() - $(child).width()) / 2
    , left = $(this).position().left + diff
    , right = $(parent).width() - ($(this).position().left + $(child).width() + 14);
 
   if ( left < -10) {
     $( child).css("left", diff - left -10 + 'px'); 
   }
    if (right < 0 ) { 
     $( child).css("left", right + 'px');
   }
 
  $( this ).click(function(){ $( child).slideToggle('slow'); });
  $( this ).mouseleave(function(){ $(child).slideUp('slow'); }); 
 
});
 
/***********************************
   NAVIGATION
************************************/

var nav = $( "#nv" ); 
var cont= $( "#content" ); 
var search= $("<div id='search2'></div>").append($('#searchform')); 
var fixOK = 1;
$('#chapters').append($(search));
 
/***********************************
    Anpassen an Browserfenster, u.a.
************************************/
 
var toggleNav =  $( "<div id='tS' title='Navigation vergößern' class='fas fa-bars'></div>" )
  .click( function() {  $( nav ).toggleClass( 'nv_large' );  });
$( nav ).append(toggleNav );
 
/*         Handys und kleine Bildschirme        */ 
 
function sizeX() {
 
var wiW = window.innerWidth ||  document.documentElement.offsetWidth || 0;
var wiH = window.innerHeight ||  document.documentElement.offsetHeight || 0;
 
$( nav ).removeClass( 'nv_large' );
 
if (wiW < wiH*0.7 || wiW < 940) {
 fixOK = 0;  // fixed ausschalten
 $ (cont).addClass( 'mobileeee' ); 
 $ (nav).removeClass( 'fixed' ); 
 }
else  {
 fixOK = 1;  // fixed einschalten
 $ (cont).removeClass( 'mobileeee' ); 
 }
} 

function sizeY() {
	//Maße und Elemente  
  var body_height = document.getElementById("footer").offsetTop + 70
    , screen_height = window.innerHeight ||
      document.documentElement.offsetHeight
    , diff = screen_height - body_height
   // Höhe anpassen
    , spacer =  document.getElementById("catlinks")? 
      document.getElementById("catlinks").parentNode.insertBefore(document.createElement("DIV"), document.getElementById("catlinks")) :
      document.getElementById("bodyContent").appendChild( document.createElement("DIV") );
   
   spacer.style.paddingTop = diff > 0 ? diff +"px" : 0;	
}

sizeX();
sizeY();
window.onresize = function() { sizeX(); };
// window.onresize = function() { sizeY(); };

/*****************
         Navigation
*****************/

var nav2 = document.getElementById('nv'); 

function findPos(b) {  //Position von b ( = nav2) ermitteln
  var a = 0;
  if(b.offsetParent)
    for(a = b.offsetTop;b = b.offsetParent;)
      a += b.offsetTop;
  return[a];
}
var nvY = findPos(nav2);

function fixNv() {	 

if (!fixOK) return;  
    //Scrollposition ermitteln	
  var scrY = document.documentElement.scrollTop || // Explorer 6 Strict
	document.body.scrollTop || //all other Explorers
	self.pageYOffset ||
	0;
  if(self.pageYOffset)
    scrY = self.pageYOffset;
  else if(document.documentElement && document.documentElement.scrollTop)
    scrY = document.documentElement.scrollTop;
  else if(document.body)
    scrY = document.body.scrollTop;
  if(fixOK && typeof document.body.style.maxHeight !== "undefined" && nav2!=='') // nur neuere Browser
    nav2.className =  scrY > nvY - 30 ? "fixed" : "";
  else nav2.className = "";
}
   //Menü stabilisieren
var toggleFix = $("<div title = 'Menü oben stabilisieren' id = 'tF' class='fa fa-arrow-up'></div>").click( function() { menuTop(); } );
$( "#chapters" ).append( toggleFix );  

function menuTop() {
  fixOK = 0;
 $( nav).removeClass( 'fixed' ); 
}
function styleNv() {
  var selflink = document.getElementById('chapters').getElementsByTagName('STRONG')[0]||0;
  if (selflink && selflink.parentNode.parentNode.parentNode.tagName == 'LI') {
    selflink.parentNode.parentNode.parentNode.className='self_parent';
    //selflink.parentNode.parentNode.parentNode.className='selflink';
  }  
} 
styleNv();
 
window.onscroll = fixNv;

//Navigation Hover

$('#chapters div[id]').on("touchstart", function (e) {
 'use strict'; //satisfy code inspectors
 var link = $(this); //preselect the link
 if (link.hasClass('hover')) {
  return true;
 } 
 else {
  $('#chapters div[id]').removeClass('hover'); 
  link.addClass('hover'); 
  return false; //extra, and to make sure the function has consistent return points
 } 
});

/***********************************
       Change redirected address line 
***********************************/
( function ( $, mw ) {
	if ( !window.history || !window.history.replaceState ) {
		return;
	}
 
	mw.loader.using( 'jquery.mwExtension', function () {
		var articlePathRE, pathQuery, path;
 
		articlePathRE = new RegExp(
			'^' +
			$.escapeRE( mw.config.get( 'wgArticlePath' ) ).replace( '\\$1', mw.config.get( 'wgArticlePath' ).indexOf( '?' ) >= -1 ? '([^?]*)' : '([^&]*)' ) +
			'$'
		);
		pathQuery = location.pathname + ( location.search ? '?' + location.search : '' );
		// Only execute on paths matching the article path (don't squash query arguments)
		if ( articlePathRE.test( pathQuery ) ) {
			path = mw.util.wikiGetlink( mw.config.get( 'wgPageName' ) );
			path += window.location.hash || '';
			window.history.replaceState( {}, document.title, path );
		}
	} );

}( jQuery, mediaWiki ) );