Click to See Complete Forum and Search --> : Javascript n00b...need menu help
Pselus
09-09-2003, 12:56 PM
ok, I'm a .Net programmer and I can read and understand Javascript...but to code it from scratch...no dice and no time to learn (in a crunch at work)
I have this menu system that I use on the intranet website...it's a menu system created by Dreamweaver MX (it works for me so I don't complain and don't have time to get something better)
1 problem....the menus open on mouseover....I need the menus to open on mouseclick.....other than that I want them to act the same...disappear when not hovered over and all that jazz....
if I gave you guys the code could someone explain to me the change that I need to make? I'm sure it can't be that big of a change....
file is at http://www.livethislife.net/ltl/downloads/mm_menu.js
I appreciate any help given on this.
well, i moved the check-and-show-dropdown codes from the onMenuItemOver function to the onMenuItemAction function, plz see whether it works or not (rename the .txt to .js first).
thx,
Pselus
09-10-2003, 09:53 AM
oh dear lord...
well thx for your help....but when you uploaded in .txt format it took away all code formatting (look at your text file)
I'm gonna try to find what you did and change it in the origional file.
Pselus
09-10-2003, 10:03 AM
ok....I finally got the code formatted right (opened it in .Net and it formatted it properly then saved from there) and no...that in fact did not stop them opening on mouseover.
:p
here is what the menu code looks like after I build it dynamically through .Net (based on what's in SQL for each user)
http://www.livethislife.net/ltl/downloads/nav.txt
wow...that's weird...if you don't right click and save it actually takes a text file and (at least in IE 6.0) it builds a web page....even though it's not an extension of a webpage.
anyway...right click and save.
i think i didn't make it right. one question though, you just want to click to open a menu but still hover to open the sub-menus, or all click to open a menu and its sub-menus?
Pselus
09-10-2003, 12:48 PM
well if possible, click to open menu, hover to open submenu....but if that's difficult (since I'm assuming both menus and submenus are using the same object)....then click to open both at the least
now I've got an odd problem...I renamed my file before trying to use yours....then I tried yours and it did nothing different so I deleted it and renamed my file back....now when you go over an item it no longer highlights the text white and it also does nothing when you click a menu item.....
gotta figure this one out first now....
btw, thx for you help.
*edit*
I downloaded the mm_menu.js I had posted...and that fixed it....
actually it's easier to do click to open a menu then hover to open its sub-menus.
the image links in the nav page which trigger the menus are not part of the menu codes, they just detect onmouseover and onmouseout to show and hide a menu.
for those links, i moved the onmouseover codes to the href part so that it needs to be clicked to open a menu, i then coded a new js function to check whether the page has a menu shown already and use it for the onmouseover, thus you will click to open a menu, and if the page still has the menu shown, hovering other links will open their menus, if the page has hided the menu, then hovering the links won't do anything.
thx,
Pselus
09-10-2003, 01:44 PM
no thank YOU
now I hope I can impliment this because that nav.txt file I posted is built dynamically when the page loads....I just gotta look at your code and work it into that
once again, thx
Pselus
10-13-2003, 03:13 PM
just wanted to go back and thank you again Xin....code works wonderfully and does exactly what it needs to....you're my hero.
Pselus
12-23-2003, 09:57 AM
sorry to dig this up and bug you again Xin...but after adding an item to the menu (with a straight copy and paste of my own code) it started erroring. If you have script debugging turned off in IE then the menu still works perfectly...it just shows an error on the bottom of IE...
any idea why? I haven't changed your code at all...but the error happens when you go over the menu...so I think it might still be trying to open onmouseover or something...
the most annoying part is that it still works...but my bosses are dead set on getting rid of it.
Pselus
12-23-2003, 11:30 AM
for anyone else that might help...here is the problem. This code:
yxShowMenu(window.mnuSetup,0,20,null,'imgSetup')
errors...
here is the yxShowMenu sub:
var yxMenuShown=false;
function yxShowMenu(menu, x, y, child, imgname) {
if (yxMenuShown) {
MM_showMenu(menu, x, y, child, imgname)
}
}
and the mm_showMenu sub:
function MM_showMenu(menu, x, y, child, imgname) {
if (!window.mmWroteMenu) return;
MM_clearTimeout();
if (menu) {
var obj = FIND(imgname) || document.images[imgname] || document.links[imgname] || document.anchors[imgname];
x = moveXbySlicePos (x, obj);
y = moveYbySlicePos (y, obj);
}
if (document.layers) {
if (menu) {
var l = menu.menuLayer || menu;
l.top = l.left = 1;
hideActiveMenus();
if (this.visibility) l = this;
window.ActiveMenu = l;
} else {
var l = child;
}
if (!l) return;
for (var i=0; i<l.layers.length; i++) {
if (!l.layers[i].isHilite) l.layers[i].visibility = "inherit";
if (l.layers[i].document.layers.length > 0) MM_showMenu(null, "relative", "relative", l.layers[i]);
}
if (l.parentLayer) {
if (x != "relative") l.parentLayer.left = x || window.pageX || 0;
if (l.parentLayer.left + l.clip.width > window.innerWidth) l.parentLayer.left -= (l.parentLayer.left + l.clip.width - window.innerWidth);
if (y != "relative") l.parentLayer.top = y || window.pageY || 0;
if (l.parentLayer.isContainer) {
l.Menu.xOffset = window.pageXOffset;
l.Menu.yOffset = window.pageYOffset;
l.parentLayer.clip.width = window.ActiveMenu.clip.width +2;
l.parentLayer.clip.height = window.ActiveMenu.clip.height +2;
if (l.parentLayer.menuContainerBgColor && l.Menu.menuBgOpaque ) l.parentLayer.document.bgColor = l.parentLayer.menuContainerBgColor;
}
}
l.visibility = "inherit";
if (l.Menu) l.Menu.container.visibility = "inherit";
} else if (FIND("menuItem0")) {
var l = menu.menuLayer || menu;
hideActiveMenus();
if (typeof(l) == "string") l = FIND(l);
window.ActiveMenu = l;
var s = l.style;
s.visibility = "inherit";
if (x != "relative") {
s.pixelLeft = x || (window.pageX + document.body.scrollLeft) || 0;
s.left = s.pixelLeft + 'px';
}
if (y != "relative") {
s.pixelTop = y || (window.pageY + document.body.scrollTop) || 0;
s.top = s.pixelTop + 'px';
}
l.Menu.xOffset = document.body.scrollLeft;
l.Menu.yOffset = document.body.scrollTop;
}
if (menu) window.activeMenus[window.activeMenus.length] = l;
MM_clearTimeout();
yxMenuShown=true;
}
the error I get says object expected on that first line of code I gave.
could you post the testing URL?
thx.
Pselus
12-23-2003, 12:14 PM
it's an intranet site...
:(
and due to non-disclosure agreements there is no way I could share it with you...
what other information could I provide to figure this out?
a zip of the menu pages and all the js it includes would help.
Pselus
12-23-2003, 12:30 PM
getting it now...
do you have the ability to run an ASP.Net website?
actually I think (considering this is the only thing I'm working on right now) I'll take the time to make a working internet site using these menu's and see how that goes...I'll send you the link when I get it.
because of non-disclosure crap I'd hafta take out a TON of code to zip and give it to you...which is the same amount of work as taking that code out and making a working site with just the menus
actually i just need to re-create the same error, so what i need is:
- the menu page
- the js needed to show the menu on the page
i can't run asp stuffs, the view source in ie can save you a copy of the asp output and that's what i need for debugging.
thx,
Pselus
12-23-2003, 12:38 PM
"did you ever know that you're my hero?"
Menu zipfile (http://www.livethislife.net/ltl/downloads/Menu.zip)
Pselus
12-23-2003, 12:41 PM
so I'm running the html file I gave you the link for...and with the mm_menu.js file in the same folder....no error happens and the menu's work.
:(
the menu's work normally anyway but they raise an error when you put the mouse over one of the images.
too bad the bosses won't go with the simple fix...turn off script debugging and hide the bottom bar in IE....
i tried it on ie and netscape7, the menu page didn't get me any error message. how is it running on your end?
Pselus
12-23-2003, 01:21 PM
like I said, as an html page = no errors...as an ASP.Net page (essentially an HTML page from the menu's point of view) I get an error that doesn't stop any work...but the bosses refuse to let it sit there.
oh well
thx for the help anyway
there could be a typo in the html page:
<A onmouseover="yxShowMenu(window.mnuReports,0,20,null,'imgReports')" onmouseout=MM_startTimeout(); href="javascript:onmouseover="MM_showMenuwindow.mnuReports 0,20,null,?imgReports?);?(,></A>
the "MM_showMenuwindow.mnuReports 0" should be "MM_showMenu(window.mnuReports, 0".
thx,
Pselus
12-23-2003, 01:45 PM
it is that in my html page and the aspx page and whenever I view source...dunno how yours got like that.
I'm working on selling the bosses on just ignoring it...cause like I said everything WORKS 100% like it should...there is just an error message in IE...
from the menupage.html in your zip, just do a text search on "MM_showMenuwindow".