view tooltip.js @ 1769:57276229a8c8

Cleanups.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 26 Oct 2017 22:20:25 +0300
parents 31a454a73f8e
children 78dcae610ce3
line wrap: on
line source

//
// Tooltip and other utility functions in JavaScript for BatMUD maps
// by Matti 'ccr' Hamalainen (Ggr Pupunen) <ccr@tnsp.org>
//
var myhl = -1;
var mytt = null;
var myx = 0;
var myy = 0;
document.onmousemove = utt;


// Change background style of given element
function shc(uid, ucolor)
{
  document.getElementById(uid).style['background'] = ucolor;
}


// Hilite map and list elements of given number
function qh(marker)
{
  if (myhl >= 0) qn(myhl);
  shc('maploc'+marker, 'white');
  shc('listloc'+marker, 'white');
  myhl = marker;
}

// Unlite
function qn(marker)
{
  shc('maploc'+ marker, 'black');
  shc('listloc'+ marker, 'black');
  myhl = -1;
  htt();
}


// Update the tooltip box
function utt(e)
{
  var x = document.all ? (window.event.x + document.body.scrollLeft) : e.pageX;
  var y = document.all ? (window.event.y + document.body.scrollTop)  : e.pageY;
  if (mytt != null)
  {
    var winW = 0, winH = 0;
    var boxW = mytt.clientWidth + 25, boxH = mytt.clientHeight + 25;

    if (typeof(window.innerWidth) == 'number')
    {
      // Non-MSIE
      winW = window.innerWidth;
      winH = window.innerHeight;
    } else
    if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))
    {
      // MSIE 6+ in 'standards compliant mode'
      winW = document.documentElement.clientWidth;
      winH = document.documentElement.clientHeight;
    } else
    if (document.body && (document.body.clientWidth || document.body.clientHeight))
    {
      // MSIE 4 compatible
      winW = document.body.clientWidth;
      winH = document.body.clientHeight;
    }

    if (x + boxW + 15 >= winW)
      x -= boxW;
    else
      x += 15;

    if (y + boxH + 15 >= winH)
      y -= boxH;
    else
      y += 15;

    myx = x;
    myy = y;

    mytt.style.left = x + "px";
    mytt.style.top  = y + "px";
  }
}

// Show tooltip
function stt(id)
{
  htt();

  mytt = document.getElementById("tt"+ id);
  
  mytt.style.left    = myx + "px";
  mytt.style.top     = myy + "px";
  mytt.style.display = "block";
}

// Hide tooltip
function htt()
{
  if (mytt)
  {
    mytt.style.display = "none";
  }
}


// Highlight one location (by index number) during page load
var httID;
var httST = 0;

function httBlink(marker)
{
  httST = !httST;
  var mcolor = httST ? "white" : "black";
  shc("maploc"+ marker, mcolor);
  shc("listloc"+ marker, mcolor);
}


function httOnLoad()
{
  var hstr = window.location.href;
  if (hstr.indexOf("?") >= 0)
  {
    var name = unescape(hstr.substr(hstr.indexOf("?") + 1).toLowerCase());
    httID = setInterval(function (qname) { httBlink(qname); }, 500, name);
  }
}