MediaWiki:Navigation.js: Unterschied zwischen den Versionen

Zur Navigation springen Zur Suche springen
Zeile 100: Zeile 100:
 
}  
 
}  
 
styleNv();
 
styleNv();
 +
function styleNv2() {
 +
  var selflink = $( '.page-Alltag_Jahr_Shogatsu #chapters .selflink' );
 +
  alert (selflink.tagName );
 +
}
 +
$( document ).on('click', '.page-Alltag_Jahr_Shogatsu', styleNv2);
 
window.onscroll = fixNv;
 
window.onscroll = fixNv;
  

Version vom 6. August 2017, 14:06 Uhr

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'>&#9776;</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( 'mobile' ); 
 $ (nav).removeClass( 'fixed' ); 
 }
else  {
 fixOK = 1;  // fixed einschalten
 $ (cont).removeClass( 'mobile' ); 
 }
} 

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
  var 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 - 16 ? "fixed" : "absolute";
  else nav2.className = "absolute";
}
   //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' );
 $( nav).addClass( 'absolute' );
}
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';
  }  
} 
styleNv();
function styleNv2() {
  var selflink = $( '.page-Alltag_Jahr_Shogatsu #chapters .selflink' );
  alert (selflink.tagName );
} 
$( document ).on('click', '.page-Alltag_Jahr_Shogatsu', styleNv2);
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
 } 
});
/*
$(document).ready(function() {
    $('#chapters div[id]').bind('touchstart touchend', function(e) {
        //e.preventDefault();
        $(this).toggleClass('hover');
    });
});*/
/*****************
         Top Arrows
*****************/

function PageHomeArrows()
{
        //if (!wgNamespaceNumber || wgNamespaceNumber <100) return;
        var c = document.getElementById("bodyContent") || document.getElementById("mw_content") || document.getElementById("article");
        if (!c) return;
        for (var level = 2; level <= 3; ++level) {
                var h = c.getElementsByTagName("h" + level);
                for (var i = 0; i < h.length; ++i) {
                        if (h[i].offsetTop>screen.availHeight) { 
var top= function( ) {window.scrollTo(0,0);}
var arrow = $("<a>top↑</a>").attr({ 
title: "zum Seitenanfang",
"class": "toparrow noprint"
}) 
$(arrow).on( "click", top);

arrow.appendTo( h[i] );
                        }
                }
        }
}
$(PageHomeArrows);