Loading ...
Sorry, an error occurred while loading the content.
 

Re: [ydn-javascript] expand nested submenus to show selected menu item

Expand Messages
  • Todd Kloots
    Hey Jack - When a menu is hidden, its selection is cleared. So, when the menu is clicked you ll have to store a reference to the selected item and then use
    Message 1 of 2 , Apr 1, 2008
      Hey Jack -

      When a menu is hidden, its selection is cleared. So, when the menu is
      clicked you'll have to store a reference to the selected item and then
      use the "parent" property to crawl up and show each parent menu. That
      said, why are you doing this? What is the use case here? This
      interaction you are trying to create doesn't make sense to me. I have
      never used an application where a button's flyout menu appears pre-
      expanded with the selected item shown.

      - Todd

      Jack Bates wrote:
      > Awesome, thanks Todd, that works.
      >
      > Now, when I show the menu, and the selected menu item is nested in a
      > submenu, I need to expand it's parent submenus, so the user can find the
      > selected menu item.
      >
      > I tried to achieve this using the following:
      > http://cgi.sfu.ca/~jdbates/tmp/yui/200803310/test.html
      >
      > button.getMenu().subscribe('show', function (type, args)
      > {
      > if (button.get('selectedMenuItem') != null)
      > {
      > button.get('selectedMenuItem').parent.show();
      > }
      > });
      >
      > I select a menu item in a submenu, "BBB". When I subsequently show the
      > menu, I expect the submenu containing "BBB" - the "AAA" submenu - to be
      > expanded.
      >
      > Instead however, only the root menu is shown.
      >
      > How do I expand nested submenus to show the selected menu item when the
      > menu is shown?
      >
      > Thanks again, Jack
      >
      >
      >> Jack -
      >>
      >> The MenuItem that was the target of the click event will be sent back
      >> in
      >> the arguments array that is passed back to your handler. This is
      >> covered in this section of the Menu landing page:
      >> http://developer.yahoo.com/yui/menu/#addingeventlisteners
      >>
      >> - Todd
      >>
      >> Jack Bates wrote:
      >>
      >>> When a sub menu item is clicked, how can I get that menu item?
      >>>
      >>> I applied a "click" event handler to a menu button in order to
      >>>
      >> change
      >>
      >>> the button label when a menu item is selected:
      >>>
      >>> button.getMenu().subscribe('click', function (event)
      >>> {
      >>> button.set('label',
      >>> button.getMenu().activeItem.cfg.getProperty('text'));
      >>> });
      >>>
      >>> It works for simple menu items, but not for sub menu items:
      >>> http://cgi.sfu.ca/~jdbates/tmp/yui/200803280/test.html
      >>>
      >>> In this test case, selecting either "AAA" or "CCC" will correctly
      >>>
      >> change
      >>
      >>> the button label. However selecting the "BBB" sub menu item
      >>>
      >> incorrectly
      >>
      >>> changes the button label to "AAA"
      >>>
      >>> How can I get the sub menu item which was clicked, so I can set the
      >>> button label to "BBB" when "BBB" is selected?
      >>>
      >>> Thanks and best wishes, Jack
      >>>
    Your message has been successfully submitted and would be delivered to recipients shortly.