Subversion Repositories DevTools

Rev

Rev 1281 | 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
3904 dpurdie 28
//eventX=ie4? event.clientX : ns6? e.clientX : e.x
29
//eventY=ie4? event.clientY : ns6? e.clientY : e.y
119 ghuddy 30
 
3904 dpurdie 31
// Dont use event location as it wobbles around
32
// Use location of parent element
33
var targ;
34
if (e.target) targ = e.target;
35
else if (e.srcElement) targ = e.srcElement;
36
if (targ.nodeType == 3) // defeat Safari bug
37
targ = targ.parentNode;
38
var rect = targ.getBoundingClientRect();
39
eventX = rect.left;
40
eventY = rect.bottom;
41
 
119 ghuddy 42
//Find out how close the mouse is to the corner of the window
43
var rightedge=ie4? document.body.clientWidth-eventX : window.innerWidth-eventX
44
var bottomedge=ie4? document.body.clientHeight-eventY : window.innerHeight-eventY
45
 
46
//position the horizontal position of the menu where the mouse was clicked
3904 dpurdie 47
var left=ie4? document.body.scrollLeft+eventX : ns6? window.pageXOffset+eventX : eventX
119 ghuddy 48
 
3904 dpurdie 49
//if the horizontal distance isn't enough to accomodate the width of the context menu
50
var delta = rightedge - menuobj.contentwidth;
51
if ( delta < 0 ) left+=delta;
52
 
119 ghuddy 53
//same concept with the vertical position
3904 dpurdie 54
var top = menuobj.thestyle.top=ie4? document.body.scrollTop+eventY : ns6? window.pageYOffset+eventY : eventY
55
 
56
// Don't adjust top. Assume menus are at the top. All adjusting will do is push the top off the screen
57
//delta = bottomedge-menuobj.contentheight;
58
//if (delta < 0) top += delta;
59
 
60
menuobj.thestyle.left=left;
61
menuobj.thestyle.top=top;
119 ghuddy 62
menuobj.thestyle.visibility="visible"
63
return false
64
}
65
 
66
function contains_ns6(a, b) {
67
//Determines if 1 element in contained in another- by Brainjar.com
68
while (b && b.parentNode)
69
if ((b = b.parentNode) == a)
70
return true;
71
return false;
72
}
73
 
74
function hidemenu(){
75
if (window.menuobj)
76
menuobj.thestyle.visibility=(ie4||ns6)? "hidden" : "hide"
77
}
78
 
79
function dynamichide(e){
80
if (ie4&&!menuobj.contains(e.toElement))
81
hidemenu()
82
else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
83
hidemenu()
84
}
85
 
86
function delayhidemenu(){
87
if (ie4||ns6||ns4)
88
delayhide=setTimeout("hidemenu()",500)
89
}
90
 
91
function clearhidemenu(){
92
if (window.delayhide)
93
clearTimeout(delayhide)
94
}
95
 
96
function highlightmenu(e,state){
97
if (document.all)
98
source_el=event.srcElement
99
else if (document.getElementById)
100
source_el=e.target
101
if (source_el.className=="menuitems"){
102
source_el.id=(state=="on")? "mouseoverstyle" : ""
103
}
104
else{
105
while(source_el.id!="popmenu"){
106
source_el=document.getElementById? source_el.parentNode : source_el.parentElement
107
if (source_el.className=="menuitems"){
108
source_el.id=(state=="on")? "mouseoverstyle" : ""
109
}
110
}
111
}
112
}
113
 
114
if (ie4||ns6)
115
document.onclick=hidemenu