1 | /***************************************************** |
---|
2 | * ypSlideOutMenu |
---|
3 | * 3/04/2001 |
---|
4 | * |
---|
5 | * a nice little script to create exclusive, slide-out |
---|
6 | * menus for ns4, ns6, mozilla, opera, ie4, ie5 on |
---|
7 | * mac and win32. I've got no linux or unix to test on but |
---|
8 | * it should(?) work... |
---|
9 | * |
---|
10 | * --youngpup-- |
---|
11 | *****************************************************/ |
---|
12 | |
---|
13 | ypSlideOutMenu.Registry = []; |
---|
14 | ypSlideOutMenu.aniLen = 250; |
---|
15 | ypSlideOutMenu.hideDelay = 1000; |
---|
16 | ypSlideOutMenu.minCPUResolution = 10; |
---|
17 | |
---|
18 | // constructor |
---|
19 | function ypSlideOutMenu(id, dir, left, top, width, height,pos) |
---|
20 | { |
---|
21 | this.ie = document.all ? 1 : 0; |
---|
22 | this.ns4 = document.layers ? 1 : 0; |
---|
23 | this.dom = document.getElementById ? 1 : 0; |
---|
24 | |
---|
25 | if (this.ie || this.ns4 || this.dom) { |
---|
26 | this.id = id; |
---|
27 | this.dir = dir; |
---|
28 | this.orientation = dir == "left" || dir == "right" ? "h" : "v"; |
---|
29 | this.dirType = dir == "right" || dir == "down" ? "-" : "+"; |
---|
30 | this.dim = this.orientation == "h" ? width : height; |
---|
31 | this.hideTimer = false; |
---|
32 | this.aniTimer = false; |
---|
33 | this.open = false; |
---|
34 | this.over = false; |
---|
35 | this.startTime = 0; |
---|
36 | |
---|
37 | // global reference to this object |
---|
38 | this.gRef = "ypSlideOutMenu_"+id; |
---|
39 | eval(this.gRef+"=this"); |
---|
40 | |
---|
41 | // add this menu object to an internal list of all menus |
---|
42 | ypSlideOutMenu.Registry[id] = this; |
---|
43 | |
---|
44 | var d = document; |
---|
45 | |
---|
46 | var strCSS = '<style type="text/css">'; |
---|
47 | strCSS += '#' + this.id + 'Container { visibility:hidden; '; |
---|
48 | if(pos) |
---|
49 | { |
---|
50 | strCSS += pos+':' + left + 'px; '; |
---|
51 | } |
---|
52 | else |
---|
53 | { |
---|
54 | strCSS += 'left:' + left + 'px; '; |
---|
55 | } |
---|
56 | strCSS += 'top:' + top + 'px; '; |
---|
57 | strCSS += 'overflow:visible; z-index:10000; }'; |
---|
58 | strCSS += '#' + this.id + 'Container, #' + this.id + 'Content { position:absolute; '; |
---|
59 | strCSS += 'width:' + width + 'px; '; |
---|
60 | // strCSS += 'height:' + height + 'px; '; |
---|
61 | // strCSS += 'clip:rect(0 ' + width + ' ' + height + ' 0); '; |
---|
62 | strCSS += '}'; |
---|
63 | strCSS += '</style>'; |
---|
64 | |
---|
65 | d.write(strCSS); |
---|
66 | |
---|
67 | this.load(); |
---|
68 | } |
---|
69 | } |
---|
70 | |
---|
71 | ypSlideOutMenu.prototype.load = function() { |
---|
72 | var d = document; |
---|
73 | var lyrId1 = this.id + "Container"; |
---|
74 | var lyrId2 = this.id + "Content"; |
---|
75 | var obj1 = this.dom ? d.getElementById(lyrId1) : this.ie ? d.all[lyrId1] : d.layers[lyrId1]; |
---|
76 | if (obj1) var obj2 = this.ns4 ? obj1.layers[lyrId2] : this.ie ? d.all[lyrId2] : d.getElementById(lyrId2); |
---|
77 | var temp; |
---|
78 | |
---|
79 | if (!obj1 || !obj2) |
---|
80 | window.setTimeout(this.gRef + ".load()", 100); |
---|
81 | else { |
---|
82 | this.container = obj1; |
---|
83 | this.menu = obj2; |
---|
84 | this.style = this.ns4 ? this.menu : this.menu.style; |
---|
85 | this.homePos = eval("0" + this.dirType + this.dim); |
---|
86 | this.outPos = 0; |
---|
87 | this.accelConst = (this.outPos - this.homePos) / ypSlideOutMenu.aniLen / ypSlideOutMenu.aniLen ; |
---|
88 | |
---|
89 | // set event handlers. |
---|
90 | if (this.ns4) this.menu.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT); |
---|
91 | this.menu.onmouseover = new Function("ypSlideOutMenu.showMenu('" + this.id + "')"); |
---|
92 | this.menu.onmouseout = new Function("ypSlideOutMenu.hideMenu('" + this.id + "')"); |
---|
93 | |
---|
94 | //set initial state |
---|
95 | this.endSlide(); |
---|
96 | } |
---|
97 | }; |
---|
98 | |
---|
99 | ypSlideOutMenu.showMenu = function(id) |
---|
100 | { |
---|
101 | var reg = ypSlideOutMenu.Registry; |
---|
102 | var obj = ypSlideOutMenu.Registry[id]; |
---|
103 | |
---|
104 | //document.all.select.style="visibily:hidden"; |
---|
105 | |
---|
106 | |
---|
107 | //temporarly hide all selectboxes to fix IE bug with z-index |
---|
108 | if(document.all); |
---|
109 | { |
---|
110 | for (var i=0; i<document.all.length; i++) { |
---|
111 | o = document.all(i); |
---|
112 | if (o.type == 'select-one' || o.type == 'select-multiple') { |
---|
113 | // todo: add check for select in div? |
---|
114 | if (o.style) o.style.display = 'none'; |
---|
115 | } |
---|
116 | } |
---|
117 | } |
---|
118 | |
---|
119 | |
---|
120 | if (obj.container) { |
---|
121 | obj.over = true; |
---|
122 | |
---|
123 | // close other menus. |
---|
124 | for (menu in reg) if (id != menu) ypSlideOutMenu.hide(menu); |
---|
125 | |
---|
126 | // if this menu is scheduled to close, cancel it. |
---|
127 | if (obj.hideTimer) { |
---|
128 | reg[id].hideTimer = window.clearTimeout(reg[id].hideTimer); |
---|
129 | } |
---|
130 | |
---|
131 | // if this menu is closed, open it. |
---|
132 | if (!obj.open && !obj.aniTimer) reg[id].startSlide(true); |
---|
133 | } |
---|
134 | }; |
---|
135 | |
---|
136 | ypSlideOutMenu.hideMenu = function(id) |
---|
137 | { |
---|
138 | // schedules the menu to close after <hideDelay> ms, which |
---|
139 | // gives the user time to cancel the action if they accidentally moused out |
---|
140 | var obj = ypSlideOutMenu.Registry[id]; |
---|
141 | if (obj.container) { |
---|
142 | if (obj.hideTimer) window.clearTimeout(obj.hideTimer); |
---|
143 | obj.hideTimer = window.setTimeout("ypSlideOutMenu.hide('" + id + "')", ypSlideOutMenu.hideDelay); |
---|
144 | } |
---|
145 | }; |
---|
146 | |
---|
147 | ypSlideOutMenu.hide = function(id) |
---|
148 | { |
---|
149 | var obj = ypSlideOutMenu.Registry[id]; |
---|
150 | obj.over = false; |
---|
151 | |
---|
152 | if (obj.hideTimer) window.clearTimeout(obj.hideTimer); |
---|
153 | |
---|
154 | // flag that this scheduled event has occured. |
---|
155 | obj.hideTimer = 0; |
---|
156 | |
---|
157 | // if this menu is open, close it. |
---|
158 | if (obj.open && !obj.aniTimer) obj.startSlide(false); |
---|
159 | |
---|
160 | //show all selectboxes again to fix IE bug with z-index |
---|
161 | if(document.all) |
---|
162 | { |
---|
163 | for (var i=0; i<document.all.length; i++) { |
---|
164 | o = document.all(i); |
---|
165 | if (o.type == 'select-one' || o.type == 'select-multiple') { |
---|
166 | // todo: add check for select in div? |
---|
167 | if (o.style) o.style.display = 'inline'; |
---|
168 | } |
---|
169 | } |
---|
170 | } |
---|
171 | |
---|
172 | |
---|
173 | |
---|
174 | }; |
---|
175 | |
---|
176 | ypSlideOutMenu.prototype.startSlide = function(open) { |
---|
177 | this[open ? "onactivate" : "ondeactivate"](); |
---|
178 | this.open = open; |
---|
179 | if (open) this.setVisibility(true); |
---|
180 | this.startTime = (new Date()).getTime() ; |
---|
181 | this.aniTimer = window.setInterval(this.gRef + ".slide()", ypSlideOutMenu.minCPUResolution); |
---|
182 | }; |
---|
183 | |
---|
184 | ypSlideOutMenu.prototype.slide = function() { |
---|
185 | var elapsed = (new Date()).getTime() - this.startTime; |
---|
186 | if (elapsed > ypSlideOutMenu.aniLen) this.endSlide(); |
---|
187 | else { |
---|
188 | var d = Math.round(Math.pow(ypSlideOutMenu.aniLen-elapsed, 2) * this.accelConst); |
---|
189 | if (this.open && this.dirType == "-") d = -d; |
---|
190 | else if (this.open && this.dirType == "+") d = -d; |
---|
191 | else if (!this.open && this.dirType == "-") d = -this.dim + d; |
---|
192 | else d = this.dim + d; |
---|
193 | |
---|
194 | this.moveTo(d); |
---|
195 | } |
---|
196 | }; |
---|
197 | |
---|
198 | ypSlideOutMenu.prototype.endSlide = function() { |
---|
199 | this.aniTimer = window.clearTimeout(this.aniTimer); |
---|
200 | this.moveTo(this.open ? this.outPos : this.homePos); |
---|
201 | if (!this.open) this.setVisibility(false); |
---|
202 | if ((this.open && !this.over) || (!this.open && this.over)) { |
---|
203 | this.startSlide(this.over); |
---|
204 | } |
---|
205 | }; |
---|
206 | |
---|
207 | ypSlideOutMenu.prototype.setVisibility = function(bShow) { |
---|
208 | var s = this.ns4 ? this.container : this.container.style; |
---|
209 | s.visibility = bShow ? "visible" : "hidden"; |
---|
210 | }; |
---|
211 | ypSlideOutMenu.prototype.moveTo = function(p) { |
---|
212 | this.style[this.orientation == "h" ? "left" : "top"] = this.ns4 ? p : p + "px"; |
---|
213 | }; |
---|
214 | ypSlideOutMenu.prototype.getPos = function(c) { |
---|
215 | return parseInt(this.style[c]); |
---|
216 | }; |
---|
217 | |
---|
218 | // events |
---|
219 | ypSlideOutMenu.prototype.onactivate = function() { }; |
---|
220 | ypSlideOutMenu.prototype.ondeactivate = function() { }; |
---|