Subversion Repositories DevTools

Rev

Rev 119 | Rev 3904 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
119 ghuddy 1
/*
2
 *    DROPDOWN MENU
3
 */
4
 
5
var ie4=document.all&&navigator.userAgent.indexOf("Opera")==-1
6
var ns6=(document.getElementById&&!document.all)||navigator.userAgent.indexOf("Opera")==0
7
var ns4=document.layers
8
 
9
function showmenu(e,which){
10
 
11
if (!document.all&&!document.getElementById&&!document.layers)
12
return
13
 
14
clearhidemenu()
15
 
16
menuobj=ie4? document.all.popmenu : ns6? document.getElementById("popmenu") : ns4? document.popmenu : ""
17
menuobj.thestyle=(ie4||ns6)? menuobj.style : menuobj
18
 
19
if (ie4||ns6)
20
menuobj.innerHTML=which
21
else{
22
menuobj.document.write('<layer name=gui bgColor=#E6E6E6 width=165 onmouseover="clearhidemenu()" onmouseout="hidemenu()">'+which+'</layer>')
23
menuobj.document.close()
24
}
25
 
26
menuobj.contentwidth=(ie4||ns6)? menuobj.offsetWidth : menuobj.document.gui.document.width
27
menuobj.contentheight=(ie4||ns6)? menuobj.offsetHeight : menuobj.document.gui.document.height
28
eventX=ie4? event.clientX : ns6? e.clientX : e.x
29
eventY=ie4? event.clientY : ns6? e.clientY : e.y
30
 
31
//Find out how close the mouse is to the corner of the window
32
var rightedge=ie4? document.body.clientWidth-eventX : window.innerWidth-eventX
33
var bottomedge=ie4? document.body.clientHeight-eventY : window.innerHeight-eventY
34
 
35
//if the horizontal distance isn't enough to accomodate the width of the context menu
36
if (rightedge<menuobj.contentwidth)
37
//move the horizontal position of the menu to the left by it's width
38
menuobj.thestyle.left=ie4? document.body.scrollLeft+eventX-menuobj.contentwidth : ns6? window.pageXOffset+eventX-menuobj.contentwidth : eventX-menuobj.contentwidth
39
else
40
//position the horizontal position of the menu where the mouse was clicked
41
menuobj.thestyle.left=ie4? document.body.scrollLeft+eventX : ns6? window.pageXOffset+eventX : eventX
42
 
43
//same concept with the vertical position
44
if (bottomedge<menuobj.contentheight)
45
menuobj.thestyle.top=ie4? document.body.scrollTop+eventY-menuobj.contentheight : ns6? window.pageYOffset+eventY-menuobj.contentheight : eventY-menuobj.contentheight
46
else
47
menuobj.thestyle.top=ie4? document.body.scrollTop+event.clientY : ns6? window.pageYOffset+eventY : eventY
48
menuobj.thestyle.visibility="visible"
49
return false
50
}
51
 
52
function contains_ns6(a, b) {
53
//Determines if 1 element in contained in another- by Brainjar.com
54
while (b && b.parentNode)
55
if ((b = b.parentNode) == a)
56
return true;
57
return false;
58
}
59
 
60
function hidemenu(){
61
if (window.menuobj)
62
menuobj.thestyle.visibility=(ie4||ns6)? "hidden" : "hide"
63
}
64
 
65
function dynamichide(e){
66
if (ie4&&!menuobj.contains(e.toElement))
67
hidemenu()
68
else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
69
hidemenu()
70
}
71
 
72
function delayhidemenu(){
73
if (ie4||ns6||ns4)
74
delayhide=setTimeout("hidemenu()",500)
75
}
76
 
77
function clearhidemenu(){
78
if (window.delayhide)
79
clearTimeout(delayhide)
80
}
81
 
82
function highlightmenu(e,state){
83
if (document.all)
84
source_el=event.srcElement
85
else if (document.getElementById)
86
source_el=e.target
87
if (source_el.className=="menuitems"){
88
source_el.id=(state=="on")? "mouseoverstyle" : ""
89
}
90
else{
91
while(source_el.id!="popmenu"){
92
source_el=document.getElementById? source_el.parentNode : source_el.parentElement
93
if (source_el.className=="menuitems"){
94
source_el.id=(state=="on")? "mouseoverstyle" : ""
95
}
96
}
97
}
98
}
99
 
100
if (ie4||ns6)
101
document.onclick=hidemenu