Right Click context menu how do I close it before I load it?

Having problems with DHTML Menu? There is usually somebody here who knows the answer.
Post Reply
darkcircuituk
Super Advanced
Super Advanced
Posts: 49
Joined: Sat Aug 21, 2004 2:57 pm

Right Click context menu how do I close it before I load it?

Post by darkcircuituk »

I have implemented frames on my website and as I wish to continue the right click menu across the frames, I have implemented the right click context menu on each page within the frames. This causes a major problem because now I can actually have several of the right click menus open at once (one on each frame).

Is it possible to close any open right click menus on any frame when someone right clicks again on any of the frames?

Thanks

Dave
User avatar
kevin3442
Milonic God
Milonic God
Posts: 2460
Joined: Sat Sep 07, 2002 12:09 am
Location: Lincoln, NE
Contact:

Post by kevin3442 »

Hi Dave,

The good news is that is should be possible. To do what you want would require looping through the frames and closing menus that are open in those frames before opening the new menu. The not-so-good news is that you'd have to edit the event handler that opens the context menu. That code is in contextmenu.js, which is copyrighted by Milonic, so it's not really for me to just edit as I see fit. I'll check to see if it's do-able.

Kevin
darkcircuituk
Super Advanced
Super Advanced
Posts: 49
Joined: Sat Aug 21, 2004 2:57 pm

Thanks Kevin

Post by darkcircuituk »

If you could do that for me and get back to me about it that would be great, thanks

Dave
darkcircuituk
Super Advanced
Super Advanced
Posts: 49
Joined: Sat Aug 21, 2004 2:57 pm

Slight Problem

Post by darkcircuituk »

I just checked and I am not implementing the contextmenu.js file, I am only implementing: menu_data.js, milonic_src.js and mmenudom.js. The right click menu seems to be running fine though, what functionality does the contextmenu.js file bring to the menu?

Thanks
Dave
User avatar
kevin3442
Milonic God
Milonic God
Posts: 2460
Joined: Sat Sep 07, 2002 12:09 am
Location: Lincoln, NE
Contact:

Re: Slight Problem

Post by kevin3442 »

Hi Dave,
darkcircuituk wrote:I just checked and I am not implementing the contextmenu.js file, I am only implementing: menu_data.js, milonic_src.js and mmenudom.js. The right click menu seems to be running fine though, what functionality does the contextmenu.js file bring to the menu?
contextmenu.js provides the functionality for context menus, so you must be using the code somewhere. Out of curiosity, I had a look at some of your earlier posts. At some point, you moved the essential code from contextmenu.js into your menu_data.js file. So, your menu_data.js file contains the event handler that's normally defined in contextmenu.js.

I have sent a note about the situation to Milonic. I'll report any answer I get back here.

Cheers,

Kevin
darkcircuituk
Super Advanced
Super Advanced
Posts: 49
Joined: Sat Aug 21, 2004 2:57 pm

Excellent, Thanks

Post by darkcircuituk »

Thats great, thank you very much!
darkcircuituk
Super Advanced
Super Advanced
Posts: 49
Joined: Sat Aug 21, 2004 2:57 pm

Got an Answer Yet Kevin?

Post by darkcircuituk »

Hey Kevin, you got an answer back from Milonic yet?
User avatar
Andy
Milonic
Milonic
Posts: 3308
Joined: Sun May 19, 2002 8:23 pm
Location: Menu Developer
Contact:

Post by Andy »

Hi,

It should be possible by calling the closeAllMenus function on each of your frames.

Something like this might do it:

frame1.closeAllMenus()
frame2.closeAllMenus()

Not tested it but it should work. If i had a URL, I could maybe write write a function to do it

Cheers
Andy
darkcircuituk
Super Advanced
Super Advanced
Posts: 49
Joined: Sat Aug 21, 2004 2:57 pm

Errrmmmm not too sure

Post by darkcircuituk »

Errrrrrrrr won't that just close all open menus if they are within the same js file, my problem is I am using two seperate js files, one for each different menu :-S

I can send you an example of what I am trying to achieve!
User avatar
Andy
Milonic
Milonic
Posts: 3308
Joined: Sun May 19, 2002 8:23 pm
Location: Menu Developer
Contact:

Post by Andy »

It will only close the volatile menus. Static (alwaysvisible) menus will remain open.

I'm guessing that if you have a context menu open, then you can't also have a pull down menu open so it won't be a problem.

-- Andy
User avatar
kevin3442
Milonic God
Milonic God
Posts: 2460
Joined: Sat Sep 07, 2002 12:09 am
Location: Lincoln, NE
Contact:

Post by kevin3442 »

Hi Dave,

Sorry it took me so long to reply. I've been traveling for the past couple of weeks and haven't had much time for the net.

I think Andy's post suggests pretty much the same thing I was suggesting. Calling the built-in closeAllMenus() function in each of the frames before opening the next context menu should take care of the issue. Seems to me the logical place to do thath would be withing the right-click event handler (which is normally defined in contextmenu.js, but which you seem to have moved into your menu_data.js file).

Suppose, for example, that you have three frames named "header", "side", and "body". You could find the following code:

Code: Select all

function rclick(e){
  if(contextDisabled)
  {
    _d.oncontextmenu=null
    return true;
  }
  if(_d.all) 
  {
    ev=event.button;
    contextObject=event.srcElement
  }
<... etc ...>
}
and change it to:

Code: Select all

function rclick(e){
  if(contextDisabled)
  {
    _d.oncontextmenu=null
    return true;
  }

  top.header.closeAllMenus();
  top.side.closeAllMenus();
  top.body.closeAllMenus();

  if(_d.all) 
  {
    ev=event.button;
    contextObject=event.srcElement
  }
<... etc ...>
}
You would, of course, make your code appropriate to the number of frames you have as well as their actual names. How you address the frames from the top would also depend on whether or not you have any nested frames.

Here's another option:

Another approach you could take would be to apply slight left and top offset to each your context menus, moving them slightly up and to the left when they open. Offset the menus just enough so that when they open, the pointer is automatically inside of the menu, highlighting the first item. That way, if the user decides not to do anything with the open menu, when he or she moves the pointer out of the menu, the menu will close automatically.

To apply an "up and left" offset, you'd use the top and left properties in the menu definition, like so:

Code: Select all

with(milonic=new menuname("contextMenu")){
top="offset=-3";
left="offset=-3";
style = contextStyle;
margin=3
aI("text=Milonic Home Page;url=/;image=http://milonic.com/images/home.gif");
aI("text=Print;url=javascript:window.print();separatorsize=1;image=http://milonic.com/images/print.gif");
<...etc...>
}
If you didn't want the first active item to be highlighted automatically, then you could use a header item at the top of the menu.

Hope that helps,

Kevin
Post Reply