1 |
|
---|
2 | // Dropdown menu control
|
---|
3 |
|
---|
4 | function Dropdown(activatorId, dropdownId) {
|
---|
5 |
|
---|
6 | // store activator and dropdown elements
|
---|
7 | this.activator = document.getElementById(activatorId);
|
---|
8 | this.dropdown = document.getElementById(dropdownId);
|
---|
9 | this.activatorImage = document.getElementById(activatorId + "Image");
|
---|
10 |
|
---|
11 | // wire up show/hide events
|
---|
12 | registerEventHandler(this.activator,'mouseover', getInstanceDelegate(this, "show"));
|
---|
13 | registerEventHandler(this.activator,'mouseout', getInstanceDelegate(this, "requestHide"));
|
---|
14 | registerEventHandler(this.dropdown,'mouseover', getInstanceDelegate(this, "show"));
|
---|
15 | registerEventHandler(this.dropdown,'mouseout', getInstanceDelegate(this, "requestHide"));
|
---|
16 |
|
---|
17 | // fix visibility and position
|
---|
18 | this.dropdown.style.visibility = 'hidden';
|
---|
19 | this.dropdown.style.position = 'absolute';
|
---|
20 | this.reposition(null);
|
---|
21 |
|
---|
22 | // wire up repositioning event
|
---|
23 | registerEventHandler(window, 'resize', getInstanceDelegate(this, "reposition"));
|
---|
24 |
|
---|
25 |
|
---|
26 | }
|
---|
27 |
|
---|
28 | Dropdown.prototype.show = function(e) {
|
---|
29 | clearTimeout(this.timer);
|
---|
30 | this.dropdown.style.visibility = 'visible';
|
---|
31 | if (this.activatorImage != null)
|
---|
32 | this.activatorImage.src = dropDownHoverImage.src;
|
---|
33 | if (this.activator != null)
|
---|
34 | this.activator.className = "filterOnHover";
|
---|
35 | }
|
---|
36 |
|
---|
37 | Dropdown.prototype.hide = function(e) {
|
---|
38 | this.dropdown.style.visibility = 'hidden';
|
---|
39 | if (this.activatorImage != null)
|
---|
40 | this.activatorImage.src = dropDownImage.src;
|
---|
41 | if (this.activator != null)
|
---|
42 | this.activator.className = "filter";
|
---|
43 | }
|
---|
44 |
|
---|
45 | Dropdown.prototype.requestHide = function(e) {
|
---|
46 | this.timer = setTimeout( getInstanceDelegate(this, "hide"), 250);
|
---|
47 | }
|
---|
48 |
|
---|
49 | Dropdown.prototype.reposition = function(e) {
|
---|
50 |
|
---|
51 | // get position of activator
|
---|
52 | var offsetLeft = 0;
|
---|
53 | var offsetTop = 0;
|
---|
54 | var offsetElement = this.activator;
|
---|
55 |
|
---|
56 | while (offsetElement) {
|
---|
57 | offsetLeft += offsetElement.offsetLeft;
|
---|
58 | offsetTop += offsetElement.offsetTop;
|
---|
59 | offsetElement = offsetElement.offsetParent;
|
---|
60 | }
|
---|
61 |
|
---|
62 | // set position of dropdown relative to it
|
---|
63 | this.dropdown.style.left = offsetLeft;
|
---|
64 | this.dropdown.style.top = offsetTop + this.activator.offsetHeight;
|
---|
65 | }
|
---|
66 |
|
---|
67 | Dropdown.prototype.SetActivatorLabel = function(labelId)
|
---|
68 | {
|
---|
69 | // get the children of the activator node, which includes the label nodes
|
---|
70 | var labelNodes = this.activator.childNodes;
|
---|
71 |
|
---|
72 |
|
---|
73 | for(var labelCount=0; labelCount < labelNodes.length; labelCount++)
|
---|
74 | {
|
---|
75 | if(labelNodes[labelCount].tagName == 'LABEL')
|
---|
76 | {
|
---|
77 | var labelNodeId = labelNodes[labelCount].getAttribute('id');
|
---|
78 | if (labelNodeId == labelId)
|
---|
79 | {
|
---|
80 | labelNodes[labelCount].style.display = "inline";
|
---|
81 | }
|
---|
82 | else
|
---|
83 | {
|
---|
84 | labelNodes[labelCount].style.display = "none";
|
---|
85 | }
|
---|
86 | }
|
---|
87 | }
|
---|
88 | }
|
---|
89 |
|
---|