OpenCores
URL https://opencores.org/ocsvn/cpu8080/cpu8080/trunk

Subversion Repositories cpu8080

[/] [cpu8080/] [trunk/] [project/] [cpu8080_html/] [fit/] [tooltips.js] - Blame information for rev 33

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 samiam9512
/*  Your are permitted to reuse this code as long as the following copyright
2
    notice is not removed:
3
 
4
    This HTML tip handling is copyright 1998 by insideDHTML.com, LLC. More information about this
5
    code can be found at Inside Dynamic HTML: HTTP://www.insideDHTML.com
6
*/
7
 
8
 
9
// Support for all collection
10
var allSupport = document.all!=null;
11
 
12
function setupEventObject(e) {
13
  // Map NS event object to IEs
14
  if (e==null) return; // IE returns
15
  window.event = e;
16
  window.event.fromElement = e.target;
17
  window.event.toElement = e.target;
18
  window.event.srcElement = e.target;
19
  window.event.x = e.x;
20
  window.event.y = e.y;
21
  // Route the event to the original element
22
  // Necessary to make sure _tip is set.
23
  window.event.srcElement.handleEvent(e);
24
}
25
 
26
function checkName(src) {
27
  // Look for tooltip in IE
28
  while ((src!=null) && (src._tip==null))
29
    src = src.parentElement;
30
  return src;
31
}
32
 
33
function getElement(elName) {
34
  // Get an element from its ID
35
  if (allSupport) return document.all[elName];
36
  else            return document.layers[elName];
37
}
38
 
39
function writeContents(el, tip) {
40
  // Replace the contents of the tooltip
41
  if (allSupport)
42
    el.innerHTML = tip;
43
  else {
44
    // In NS, insert a table to work around
45
    // stylesheet rendering bug.
46
    // NS fails to apply style sheets when writing
47
    // contents into a positioned element.
48
    el.document.open();
49
    el.document.write("<TABLE WIDTH=200 BORDER=1 bordercolor=black><TR><TD WIDTH=100% BGCOLOR=yellow>");
50
    el.document.write(tip);
51
    el.document.write("</TD></TR></TABLE>");
52
    el.document.close();
53
  }
54
}
55
 
56
function getOffset(el, which) {
57
  // Function for IE to calculate position
58
  // of an element.
59
  var amount = el["offset"+which];
60
  if (which=="Top") amount+=el.offsetHeight;
61
  el = el.offsetParent;
62
  while (el!=null) {
63
    amount+=el["offset"+which];
64
    el = el.offsetParent;
65
  }
66
  return amount;
67
}
68
 
69
 
70
function setPosition(el) {
71
  // Set the position of an element
72
 
73
  src = window.event.srcElement
74
  if (allSupport) {
75
    el.style.pixelTop = getOffset(src, "Top");
76
    el.style.pixelLeft = getOffset(src, "Left");
77
  }
78
  else {
79
    el.top = src.y + 20; //window.event.y + 15
80
    el.left = src.x; //window.event.x
81
  }
82
}
83
 
84
function setVisibility(el, bDisplay) {
85
  // Hide or show to tip
86
  if (bDisplay) {
87
    if (allSupport) el.style.visibility = "visible";
88
    else            el.visibility = "show";
89
  }
90
  else {
91
    if (allSupport) el.style.visibility = "hidden";
92
    else            el.visibility = "hidden";
93
  }
94
}
95
 
96
 
97
function displayContents(tip) {
98
  // Display the tooltip.
99
  var el = getElement("tipBox");
100
  writeContents(el, tip);
101
  setPosition(el);
102
  setVisibility(el, true);
103
}
104
 
105
 
106
function doMouseOver(e) {
107
  // Mouse moves over an element
108
  setupEventObject(e);
109
  var el, tip;
110
  if ((el = checkName(window.event.srcElement))!=null) {
111
    if  (!el._display) {
112
      displayContents(el._tip);
113
      el._display = true;
114
    }
115
  }
116
}
117
 
118
function doMouseOut(e) {
119
  // Mouse leaves an element
120
  setupEventObject(e);
121
  el = checkName(window.event.srcElement);
122
  var el, tip;
123
  if ((el = checkName(window.event.srcElement))!=null) {
124
    if (el._display) {
125
      if ((el.contains==null) || (!el.contains(window.event.toElement))) {
126
        setVisibility(getElement("tipBox"), false);
127
        el._display = false;
128
      }
129
    }
130
  }
131
}
132
 
133
function doLoad() {
134
  // Do Loading
135
  if ((window.document.captureEvents==null) && (!allSupport))
136
    return; // Not IE4 or NS4
137
  if (window.document.captureEvents!=null)  // NS - capture events
138
    window.document.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT)
139
  window.document.onmouseover = doMouseOver;
140
  window.document.onmouseout = doMouseOut;
141
}
142
 
143
window.onload = doLoad;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.