Zum Inhalt springen

MediaWiki:Gadget-ReferenceTooltips.js

aus Wikipedia, der freien Enzyklopädie
Dies ist eine alte Version dieser Seite, zuletzt bearbeitet am 26. April 2012 um 09:55 Uhr durch Kaldari (Diskussion | Beiträge) (testing). Sie kann sich erheblich von der aktuellen Version unterscheiden.

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
// See [[mw:Reference Tooltips]]

window.pg || $(document).ready( function($) {

    // Make sure we are in article, project, or help namespace
    if ( wgCanonicalNamespace === '' || wgCanonicalNamespace === 'Project' || wgCanonicalNamespace === 'Help' ) {
    
        $(".reference").each( function() {
            var tooltipNode, timer;
            function findRef( h ){
                    h = h.firstChild.getAttribute("href"); h = h && h.split("#"); h = h && h[1];
                    h = h && document.getElementById( h );
                    return h;
            }
            function hide(){
                    if( tooltipNode && tooltipNode.parentNode == document.body ) {
                            timer = setTimeout( function() {
                                    $(tooltipNode).animate({opacity: 0}, 100, function(){ document.body.removeChild( tooltipNode ) })
                            }, 100)
                    } else {
                            var h = findRef( this );
                            h && (h.style.border = "");
                    }
            }
            function show(){
                    if( !tooltipNode.parentNode || tooltipNode.parentNode.nodeType === 11 ){
                            document.body.appendChild( tooltipNode );
                    }
                    $(tooltipNode).stop().animate({opacity: 1}, 100)
                    clearTimeout( timer );
            }
            $(this).hover(function(){
            	// If timer already exists, kill it and reset
				if( timer ) {
					clearTimeout( timer );
					timer = null;
				}
				var _this = this;
				timer = setTimeout(function() {
					var h = findRef( _this );
					if( !h ){return};
					if( ( window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0 ) + $(window).height() > $( h ).offset().top ) {
							h.style.border = "#080086 2px solid";
							return;
					}
					if(!tooltipNode){
							tooltipNode = document.createElement("ul");
							tooltipNode.className = "referencetooltip";
							var c = tooltipNode.appendChild( h.cloneNode( true ) );
							try {
									if( c.firstChild.nodeName != "A" ) {
											while( c.childNodes[1].nodeName == "A" && c.childNodes[1].getAttribute( "href" ).indexOf("#cite_ref-") !== -1 ) {
													do { c.removeChild( c.childNodes[1] ) } while ( c.childNodes[1].nodeValue == " " );
											}
									}
							} catch (e) { mw.log(e) }
							c.removeChild( c.firstChild );
							tooltipNode.appendChild( document.createElement( "li" ) );
							$(tooltipNode).hover(show, hide);
					}
					show();
					var o = $(_this).offset(), oH = tooltipNode.offsetHeight;
					$(tooltipNode).css({top: o.top - oH, left: o.left - 7 });
					if( tooltipNode.offsetHeight > oH ) { // is it squished against the right side of the page?
							$(tooltipNode).css({left:'auto',right:0});
							tooltipNode.lastChild.style.marginLeft = (o.left - tooltipNode.offsetLeft) + "px";
					}
				}, 500);
            }, hide)
            
        } );
        
    }

} );