0

I've got a page with a bunch of items on it. Each item has a widget that, when clicked, brings up a YUI popup-style menu of options. So far, this is working fine.

I'm using jQuery/ajax calls to insert new items into the page, pushing existing items down. The items are being inserted correctly, but I now have to update, somehow, the positions of the items' popup menus to match the new positions of the widgets that invoke them. As far as I can tell, they're computed as page coordinates and stored away with the menu objects when the page is rendered, and are not automatically updated by the ajax insertions.

This is where my problem is: I've tried some jQuery that, for each menu, recomputes the menu item, does a removeListener() to kill the old menu, and does an addListener() to insert what should be the new one. This properly updates the positions of the menus when they're invoked, but breaks something else: If I click on a widget and bring up a menu, and then click somewhere else on the page, the menu stays on the screen instead of disappearing. I can click on other widgets and they, too, will appear. Notes: no errors show up in the console; hitting the ESCAPE key during the menu presentation still correctly hides the menu.

There must be a way to do this, but I'm lost. Any clues? Perhaps all I really need to do is update the context information of the menu; is there a way to do that without the delete-and-add listener sequence that seems to be screwing me up? Thanks!

Jim Miller
  • 3,291
  • 4
  • 39
  • 57
  • Update: It's looking like the trick may be to skip recreating the menu and, instead, set up a YUI context trigger for the menu overlays, which will cause the menu contexts to be re-computed. I've added this -- YAHOO.widget.Overlay.prototype.CONTEXT_TRIGGERS = YAHOO.widget.Overlay.prototype.CONTEXT_TRIGGERS.concat(["windowScroll"]); -- to the page, and, if I scroll the window after doing an insertion, everything is right. So now I need an event that will fire after an overlay is, I guess, moved, or something comparable. I've tried "moveEvent", but no luck. Does that help anyone? – Jim Miller Feb 24 '11 at 23:32
  • Update #2: adding "beforeShow" to the list of context triggers seems to be working. Still watching out for it, but... – Jim Miller Feb 24 '11 at 23:58
  • More documentation of my trials: FOr wht it's worth, adding the array of these events -- ["beforeShow", "windowScroll"] -- into the creation of the menu (new YAHOO.widget.Menu...) didn't work. – Jim Miller Feb 25 '11 at 00:04

1 Answers1

0

All continues to be well as noted in the updates; I'm declaring this to be answered.

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