summaryrefslogtreecommitdiff
path: root/javascript/examples/example8.html
blob: 8192cfcdd67af7c5383aa9ad13da34810e3cb470 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"
            "http://www.w3.org/TR/REC-html40/strict.dtd">
<html>
  <head>
    <title>[DOM Tooltip] Example 8: Custom Context Menu</title>
    <style>
@import url(example.css);
table {
  border-collapse: collapse;
  background-color: #E6E6E6;
  color: #000000;
  border: 0;
  width: 148px;
  margin: 0 auto;
}
td {
  padding: 2px 2px 2px 20px;
  text-align: left;
  font-size: 12px;
  font-family: sans-serif;
}
td.hover {
}
td.hr {
  padding: 2px;
  height: 4px;
}
td.hr {
  cursor: default;
  background-color: #E6E6E6;
}
div.hr {
  border: 1px inset #E6E6E6;
  height: 0px;
  font-size: 0px;
}
    </style>
    <script type="text/javascript" language="javascript" src="../domLib.js"></script>
    <script type="text/javascript" language="javascript" src="../domTT.js"></script>
    <script type="text/javascript" language="javascript">
var domTT_styleClass = 'domTTMenu';
try
{
    window.defaultStatus = 'Right click (or Ctrl+click) for menu';
}
// permission denied
catch(e) {}
var menuId;
onload = function()
{
    var tmp_type = 'sticky';
    if (window.location.search == '?velcro')
	{
        tmp_type = 'velcro';
    }

    domTT_addPredefined('menu', 'content', document.getElementById('menu'), 'caption', false, 'type', tmp_type, 'statusText', 'Select Option...', 'clearMouse', false, 'offsetX', 0, 'offsetY', 0);

	document.oncontextmenu = function(in_event)
	{ 
		if (typeof(in_event) == 'undefined')
		{
			in_event = event;
		}

	    if (in_event.ctrlKey)
		{
	        return;
	    }
	
	    if (domTT_isActive(menuId))
		{
	        domTT_deactivate(menuId);
	    }
	    else
		{
	        menuId = domTT_activate(this, in_event, 'predefined', 'menu');
	    }
	    
	    return false;
	};
	
	document.onmousedown = function(in_event)
	{ 
		if (typeof(in_event) == 'undefined')
		{
			in_event = event;
		}

	    if (domLib_isOpera || domLib_isKonq)
		{
	        if ((domLib_isKonq || in_event[domLib_eventButton] == 1) && domTT_isActive(menuId))
			{
	            domTT_deactivate(menuId); 
	        }
	        else if (in_event.ctrlKey)
			{
	            menuId = domTT_activate(this, in_event, 'predefined', 'menu');
				return false; 
	        }
	    }
	    else
		{
	        if (in_event[domLib_eventButton] == 1 && domTT_isActive(menuId))
			{ 
	            domTT_deactivate(menuId); 
	        } 
	    }
	};
}

function HoverMe(in_this)
{
    in_this.style.backgroundColor = '#4C59A6';
    in_this.style.color = '#FFFFFF';
    in_this.style.cursor = domLib_isIE ? 'hand' : 'pointer';
}

function UnhoverMe(in_this)
{
    in_this.style.backgroundColor = '';
    in_this.style.color = '';
    in_this.style.cursor = '';
}
    </script>
  </head>
  <body>
    <div class="title">Example 8: Custom Context Menu</div>
    <div class="main">
    <p>This example thinks way outside the box, replacing the context menu with a custom tooltip.  Right click on the page to see a custom context menu. (If you are on Opera 7 or Konqueror, use CTRL+click).  Hold down control key to get a regular context menu (If you are on Opera 7 or Konqueror, get the context menu with a right click).</p>
    <p>To try out the <em>velcro</em> tooltip for this menu, <a href="example8.html?velcro">reload</a> the page with the 'type' option set to 'velcro'. Notice when you mouse out of the tip, it destroys itself.  No need to click somewhere on the page to kill the menu.</p>
    </div>
    <div style="float: left;"><a href="example7.html">&#171;Example 7</a></div><div style="float: right;"><a href="example9.html">Example 9&#187;</a></div>
    <div style="display: none;" id="tooltipPool">
      <table id="menu" onselectstart="return false;">
        <tr>
          <td onmouseover="HoverMe(this);" onmouseout="UnhoverMe(this);">Custom Item</td>
        </tr>
        <tr>
          <td onmouseover="HoverMe(this);" onmouseout="UnhoverMe(this);">Another Item</td>
        </tr>
        <tr>
          <td class="hr"><div class="hr"></div></td>
        </tr>
        <tr>
          <td onmouseover="HoverMe(this);" onmouseout="UnhoverMe(this);">New Section</td>
        </tr>
      </table>
    </div>
  </body>
</html>