Jump to content

User:Jcstroh/vector.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Jcstroh (talk | contribs) at 07:48, 30 October 2009 (Reference mouseover). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
// Custom Google search
// Disabled
// importScript("User:Csewiki/vector.js");
// document.write('<link rel="stylesheet" type="text/css" href="/w/index.php?' +
//                'title=User:Csewiki/vector.css&action=raw&ctype=text/css"><\/link>');
//

// MouseOver for references, from sv:WP:Referenser
//
addOnloadHook( setupRefMouseOver );
 
function setupRefMouseOver() {
  var sups = document.getElementById( 'bodyContent' ).getElementsByTagName( 'sup' );
  for (i = 0; i < sups.length; i++ ) {
    if (sups[i].className == 'reference') {
      sups[i].onmouseover = refMouseOver;
    }
  }
}
 
function refMouseOver( event ) {
  if ( !event ) { // IE verkar inte skicka med event-parametern
    event = window.event;
  }
 
  if ( this.hasReferencePopup ) {
    return;
  }
 
  var referencePopupElement = document.getElementById( 'ref-popup' );
 
  if ( !referencePopupElement ) {
    referencePopupElement = document.createElement( 'span' );
    referencePopupElement.setAttribute( 'id', 'ref-popup' );
 
    referencePopupElement.style.position = 'fixed';
    referencePopupElement.style.zIndex = 100;
    referencePopupElement.style.background = 'white';
    referencePopupElement.style.border = '1px solid #808080';
    referencePopupElement.style.lineHeight = '1em';
 
    referencePopupElement.onmouseout = refMouseOut;
  } else {
    referencePopupElement.parentNode.hasReferencePopup = false;
  }
 
  var referenceId = this.firstChild.href.split( '#' )[1];
  var referenceText = document.getElementById( referenceId ).innerHTML;
  referencePopupElement.innerHTML = referenceText;
 
  referencePopupElement.style.left = event.clientX + 'px';
  referencePopupElement.style.top  = event.clientY + 'px';
  referencePopupElement.style.display = 'inline';
 
  this.appendChild( referencePopupElement );
 
  this.hasReferencePopup = true;
}
 
function refMouseOut( event ) {
  this.style.display = 'none';
  this.innerHTML = '';
  this.parentNode.hasReferencePopup = false;
}