• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

JavaScript troubles

Brian23

Banned
For my computer class I'm supposed to fix this problem with our school's web site.
Our Web Page
It's a problem with the javascript. Unfortunantly, I didn't write the script and I don't know java very well, so I'm kind of stuck. My teacher is demanding that I fix it by monday or I don't pass.
The problem is when you do a mouseover on one of the buttons, sometimes the popup menu comes up at a weird spot. Sometimes not all of the menu is even visible. Anyways, I've been looking at the code for days now, and I found where the problem is:
this is from the file L0_menu.js: (I hope this shows up right when i post it)

function showmenu(e,which){

if (!document.all&&!document.getElementById&&!document.layers)
return

clearhidemenu()

menuobj=ie4? document.all.popmenu : ns6? document.getElementById("popmenu") : ns4? document.popmenu : ""
menuobj.thestyle=(ie4||ns6)? menuobj.style : menuobj
if (ie4||ns6)
menuobj.innerHTML=which
else{
menuobj.document.write('<layer name=gui bgColor=#E6E6E6 width=165 onmouseover="clearhidemenu()" onmouseout="hidemenu()">'+which+'</layer>')
menuobj.document.close()
}

menuobj.contentwidth=(ie4||ns6)? menuobj.offsetWidth : menuobj.document.gui.document.width
menuobj.contentheight=(ie4||ns6)? menuobj.offsetHeight : menuobj.document.gui.document.height
eventX=ie4? event.clientX : ns6? e.clientX : e.x
eventY=ie4? event.clientY : ns6? e.clientY : e.y

//Find out how close the mouse is to the corner of the window
var rightedge=ie4? document.body.clientWidth-eventX : window.innerWidth-eventX
var bottomedge=ie4? document.body.clientHeight-eventY : window.innerHeight-eventY

//if the horizontal distance isn't enough to accomodate the width of the context menu
if (rightedge<menuobj.contentwidth)
//move the horizontal position of the menu to the left by it's width
menuobj.thestyle.left=ie4? document.body.scrollLeft+eventX-menuobj.contentwidth : ns6? window.pageXOffset+eventX-menuobj.contentwidth : eventX-menuobj.contentwidth
else
//position the horizontal position of the menu where the mouse was clicked
menuobj.thestyle.left=ie4? document.body.scrollLeft+120 : ns6? window.pageXOffset+eventX : eventX

//same concept with the vertical position
if (bottomedge<menuobj.contentheight)
menuobj.thestyle.top=ie4? document.body.scrollTop+eventY-menuobj.contentheight : ns6? window.pageYOffset+eventY-menuobj.contentheight : //eventY-menuobj.contentheight
else
menuobj.thestyle.top=ie4? document.body.scrollTop+event.clientY : ns6? window.pageYOffset+eventY : eventY
menuobj.thestyle.visibility="visible"
return false
}

It's the last part that's the problem; I need to figure out how to make the popup menu appear just to the right of the button you're doing a mouseover of. I do have an idea of how to solve this problem, but I don't know how to implement it cause I don't know java well. (I'm more of a C++ dude)
My idea is to write code that figures out which button you're hovering over, and then sets the vertical popup location to a constant + document.body.scrollTop. The constant would change depending on which button you hover over. So I need to figure out the code to do that. please help! Thanks in advance!

Brian
 
first off... javascript != java

second... if you knwo what to do, then just look at the given code and you should be able to figure out the statements. javascript's DOM is prety easy to figure out if you just look at a few lines of code. less variable declarations, javascript and c++'s sytactic expressions are damn close

hope this helps
 
Back
Top