0

I have a page with a couple of widgets on it, each of which, when clicked, brings up a yui popup menu: If I click on widget 1, its menu comes up. If I now click on widget 2, widget 1's menu gets a hide event, and widget 2's menu gets a show event and comes up. I'd like to change this so that, when widget 1's menu is up, it must be explicitly dismissed by a click on the page background (and/or, perhaps, another click on the widget or the escape key) before the menu attached to widget 2 is allowed to appear.

I've set up some beforeShowEvent and beforeHideEvent handlers on the menus, hoping to be able to use some method (a global variable? ick) of keeping track of when a menu is present and showing or hiding accordingly, but it's not working -- these handlers can't tell the difference between a click on the page background and a click on widget 2 (at least, not as I've done it so far). Is there any way to do what I'm trying to do? Thanks!

Jim Miller
  • 3,291
  • 4
  • 39
  • 57

1 Answers1

1

I think that a combination of clicktohide: false

Boolean indicating if the Menu will automatically be hidden if the user clicks outside of it. This property is only applied when the "position" configuration property is set to dynamic and is automatically applied to all submenus.

and keepopen: true

Boolean indicating if the menu should remain open when clicked.

will take care of this.

http://developer.yahoo.com/yui/menu/#configref

Matt Ball
  • 354,903
  • 100
  • 647
  • 710
  • It's a step: clicktohide is definitely helpful; I was already doing keepopen. But those, by themselves, don't prevent a click on widget 2 from bringing up menu 2 in addition to menu 1. What I have now is (a) a beforeShowEvent handler sets a global to true, indicating that a menu is visible, (b) a beforeHideEvent handler clears it, and (c) the addListener call invokes a function that checks the state of that global, and only shows the menu if the global is false. Kinda yucky, but close: this keeps menu 2 from coming up, but I can't get menu 1 to go away after a selection. More work needed... – Jim Miller Apr 04 '11 at 19:29
  • I think I've got it now: the addListener-invoked function needed to hide the menu after a click on the widget, and I needed a clickEvent handler to hide the menu after a click on a menu item. Kinda ugly, but it seems to be working. Thanks for the help (you're not to blame for any of the ugliness...)! – Jim Miller Apr 04 '11 at 19:48