Subversion Repositories DevTools

Rev

Rev 6591 | Rev 6610 | 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
3959 dpurdie 28
//eventX=ie4? event.clientX : ns6? e.clientX : e.x
29
//eventY=ie4? event.clientY : ns6? e.clientY : e.y
119 ghuddy 30
 
3959 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
3959 dpurdie 43
var rightedge=(document.body.clientWidth||window.innerWidth)-eventX;
44
var bottomedge=(document.body.clientHeight||window.innerHeight)-eventY;
119 ghuddy 45
 
46
//position the horizontal position of the menu where the mouse was clicked
3959 dpurdie 47
var left=ie4? document.body.scrollLeft+eventX : ns6? window.pageXOffset+eventX : eventX
119 ghuddy 48
 
3959 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
3959 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
 
5114 dpurdie 60
menuobj.thestyle.left=left+'px';
61
menuobj.thestyle.top=top+'px';
119 ghuddy 62
menuobj.thestyle.visibility="visible"
6591 dpurdie 63
 
64
// Stop onClick event propagating
65
if (!e)
66
  e = window.event;
67
 
68
//IE9 & Other Browsers
69
if (e.stopPropagation) {
70
  e.stopPropagation();
71
}
72
//IE8 and Lower
73
else {
74
  e.cancelBubble = true;
75
}
119 ghuddy 76
return false
77
}
78
 
79
function contains_ns6(a, b) {
80
//Determines if 1 element in contained in another- by Brainjar.com
81
while (b && b.parentNode)
82
if ((b = b.parentNode) == a)
83
return true;
84
return false;
85
}
86
 
87
function hidemenu(){
88
if (window.menuobj)
89
menuobj.thestyle.visibility=(ie4||ns6)? "hidden" : "hide"
90
}
91
 
92
function dynamichide(e){
93
if (ie4&&!menuobj.contains(e.toElement))
94
hidemenu()
95
else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
96
hidemenu()
97
}
98
 
99
function delayhidemenu(){
100
if (ie4||ns6||ns4)
101
delayhide=setTimeout("hidemenu()",500)
102
}
103
 
104
function clearhidemenu(){
105
if (window.delayhide)
106
clearTimeout(delayhide)
107
}
108
 
109
function highlightmenu(e,state){
110
if (document.all)
6592 dpurdie 111
    source_el=event.srcElement
119 ghuddy 112
else if (document.getElementById)
6592 dpurdie 113
    source_el=e.target
114
if (source_el.className.indexOf("menuitems") >= 0 ){
115
    source_el.id=(state=="on")? "mouseoverstyle" : "";
119 ghuddy 116
}
117
else{
6592 dpurdie 118
    while(source_el.id!="popmenu"){
119
            source_el=document.getElementById? source_el.parentNode : source_el.parentElement
120
            if (source_el.className.indexOf("menuitems") >= 0){
121
                source_el.id=(state=="on")? "mouseoverstyle" : "";
122
            }
123
    }
119 ghuddy 124
}
125
}
126
 
127
if (ie4||ns6)
128
document.onclick=hidemenu