[2565] | 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 | |
---|
[2568] | 13 | ypSlideOutMenu.Registry = []; |
---|
| 14 | ypSlideOutMenu.aniLen = 250; |
---|
| 15 | ypSlideOutMenu.hideDelay = 1000; |
---|
| 16 | ypSlideOutMenu.minCPUResolution = 10; |
---|
[2565] | 17 | |
---|
| 18 | // constructor |
---|
| 19 | function ypSlideOutMenu(id, dir, left, top, width, height,pos) |
---|
| 20 | { |
---|
[2568] | 21 | this.ie = document.all ? 1 : 0; |
---|
| 22 | this.ns4 = document.layers ? 1 : 0; |
---|
| 23 | this.dom = document.getElementById ? 1 : 0; |
---|
[2565] | 24 | |
---|
| 25 | if (this.ie || this.ns4 || this.dom) { |
---|
[2568] | 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; |
---|
[2565] | 36 | |
---|
| 37 | // global reference to this object |
---|
[2568] | 38 | this.gRef = "ypSlideOutMenu_"+id; |
---|
| 39 | eval(this.gRef+"=this"); |
---|
[2565] | 40 | |
---|
| 41 | // add this menu object to an internal list of all menus |
---|
[2568] | 42 | ypSlideOutMenu.Registry[id] = this; |
---|
[2565] | 43 | |
---|
[2568] | 44 | var d = document; |
---|
[2565] | 45 | |
---|
| 46 | var strCSS = '<style type="text/css">'; |
---|
[2568] | 47 | strCSS += '#' + this.id + 'Container { visibility:hidden; '; |
---|
[2565] | 48 | if(pos) |
---|
| 49 | { |
---|
[2568] | 50 | strCSS += pos+':' + left + 'px; '; |
---|
[2565] | 51 | } |
---|
| 52 | else |
---|
| 53 | { |
---|
[2568] | 54 | strCSS += 'left:' + left + 'px; '; |
---|
[2565] | 55 | } |
---|
[2568] | 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 += '}'; |
---|
[2565] | 63 | strCSS += '</style>'; |
---|
| 64 | |
---|
[2568] | 65 | d.write(strCSS); |
---|
[2565] | 66 | |
---|
[2568] | 67 | this.load(); |
---|
[2565] | 68 | } |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | ypSlideOutMenu.prototype.load = function() { |
---|
[2568] | 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; |
---|
[2565] | 78 | |
---|
[2568] | 79 | if (!obj1 || !obj2) |
---|
| 80 | window.setTimeout(this.gRef + ".load()", 100); |
---|
[2565] | 81 | else { |
---|
[2568] | 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 ; |
---|
[2565] | 88 | |
---|
| 89 | // set event handlers. |
---|
| 90 | if (this.ns4) this.menu.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT); |
---|
[2568] | 91 | this.menu.onmouseover = new Function("ypSlideOutMenu.showMenu('" + this.id + "')"); |
---|
| 92 | this.menu.onmouseout = new Function("ypSlideOutMenu.hideMenu('" + this.id + "')"); |
---|
[2565] | 93 | |
---|
| 94 | //set initial state |
---|
[2568] | 95 | this.endSlide(); |
---|
[2565] | 96 | } |
---|
[2568] | 97 | }; |
---|
[2565] | 98 | |
---|
| 99 | ypSlideOutMenu.showMenu = function(id) |
---|
| 100 | { |
---|
[2568] | 101 | var reg = ypSlideOutMenu.Registry; |
---|
| 102 | var obj = ypSlideOutMenu.Registry[id]; |
---|
[2565] | 103 | |
---|
| 104 | //document.all.select.style="visibily:hidden"; |
---|
| 105 | |
---|
| 106 | |
---|
| 107 | //temporarly hide all selectboxes to fix IE bug with z-index |
---|
[2568] | 108 | if(document.all); |
---|
[2565] | 109 | { |
---|
| 110 | for (var i=0; i<document.all.length; i++) { |
---|
[2568] | 111 | o = document.all(i); |
---|
[2565] | 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) { |
---|
[2568] | 121 | obj.over = true; |
---|
[2565] | 122 | |
---|
| 123 | // close other menus. |
---|
[2568] | 124 | for (menu in reg) if (id != menu) ypSlideOutMenu.hide(menu); |
---|
[2565] | 125 | |
---|
| 126 | // if this menu is scheduled to close, cancel it. |
---|
[2568] | 127 | if (obj.hideTimer) { |
---|
| 128 | reg[id].hideTimer = window.clearTimeout(reg[id].hideTimer); |
---|
| 129 | } |
---|
[2565] | 130 | |
---|
| 131 | // if this menu is closed, open it. |
---|
[2568] | 132 | if (!obj.open && !obj.aniTimer) reg[id].startSlide(true); |
---|
[2565] | 133 | } |
---|
[2568] | 134 | }; |
---|
[2565] | 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 |
---|
[2568] | 140 | var obj = ypSlideOutMenu.Registry[id]; |
---|
[2565] | 141 | if (obj.container) { |
---|
[2568] | 142 | if (obj.hideTimer) window.clearTimeout(obj.hideTimer); |
---|
[2565] | 143 | obj.hideTimer = window.setTimeout("ypSlideOutMenu.hide('" + id + "')", ypSlideOutMenu.hideDelay); |
---|
| 144 | } |
---|
[2568] | 145 | }; |
---|
[2565] | 146 | |
---|
| 147 | ypSlideOutMenu.hide = function(id) |
---|
| 148 | { |
---|
[2568] | 149 | var obj = ypSlideOutMenu.Registry[id]; |
---|
| 150 | obj.over = false; |
---|
[2565] | 151 | |
---|
[2568] | 152 | if (obj.hideTimer) window.clearTimeout(obj.hideTimer); |
---|
[2565] | 153 | |
---|
| 154 | // flag that this scheduled event has occured. |
---|
[2568] | 155 | obj.hideTimer = 0; |
---|
[2565] | 156 | |
---|
| 157 | // if this menu is open, close it. |
---|
[2568] | 158 | if (obj.open && !obj.aniTimer) obj.startSlide(false); |
---|
[2565] | 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++) { |
---|
[2568] | 164 | o = document.all(i); |
---|
[2565] | 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 | |
---|
[2568] | 174 | }; |
---|
[2565] | 175 | |
---|
| 176 | ypSlideOutMenu.prototype.startSlide = function(open) { |
---|
[2568] | 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 | }; |
---|
[2565] | 183 | |
---|
| 184 | ypSlideOutMenu.prototype.slide = function() { |
---|
[2568] | 185 | var elapsed = (new Date()).getTime() - this.startTime; |
---|
| 186 | if (elapsed > ypSlideOutMenu.aniLen) this.endSlide(); |
---|
[2565] | 187 | else { |
---|
[2568] | 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; |
---|
[2565] | 193 | |
---|
[2568] | 194 | this.moveTo(d); |
---|
[2565] | 195 | } |
---|
[2568] | 196 | }; |
---|
[2565] | 197 | |
---|
| 198 | ypSlideOutMenu.prototype.endSlide = function() { |
---|
[2568] | 199 | this.aniTimer = window.clearTimeout(this.aniTimer); |
---|
| 200 | this.moveTo(this.open ? this.outPos : this.homePos); |
---|
| 201 | if (!this.open) this.setVisibility(false); |
---|
[2565] | 202 | if ((this.open && !this.over) || (!this.open && this.over)) { |
---|
[2568] | 203 | this.startSlide(this.over); |
---|
[2565] | 204 | } |
---|
[2568] | 205 | }; |
---|
[2565] | 206 | |
---|
| 207 | ypSlideOutMenu.prototype.setVisibility = function(bShow) { |
---|
[2568] | 208 | var s = this.ns4 ? this.container : this.container.style; |
---|
| 209 | s.visibility = bShow ? "visible" : "hidden"; |
---|
| 210 | }; |
---|
[2565] | 211 | ypSlideOutMenu.prototype.moveTo = function(p) { |
---|
[2568] | 212 | this.style[this.orientation == "h" ? "left" : "top"] = this.ns4 ? p : p + "px"; |
---|
| 213 | }; |
---|
[2565] | 214 | ypSlideOutMenu.prototype.getPos = function(c) { |
---|
[2568] | 215 | return parseInt(this.style[c]); |
---|
| 216 | }; |
---|
[2565] | 217 | |
---|
| 218 | // events |
---|
[2568] | 219 | ypSlideOutMenu.prototype.onactivate = function() { }; |
---|
| 220 | ypSlideOutMenu.prototype.ondeactivate = function() { }; |
---|