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

Re: [ydn-javascript] Newbie menu question

Expand Messages
  • Todd Kloots
    Christian - Your current workaround isn t necessary. You can pass your object as the second argument when you are calling the subscribe method. The object
    Message 1 of 4 , Sep 26, 2006
    • 0 Attachment
      Christian -

      Your current workaround isn't necessary. You can pass
      your object as the second argument when you are
      calling the "subscribe" method. The object reference
      that you pass to "subscribe" will then be available to
      you as the third argument in your click event handler.
      Your "this" will remain the MenuItem instance. This
      technique is demonstrated in that sample page that I
      sent you earlier:

      http://developer.yahoo.com/yui/examples/menu/example09.html

      I hope that helps you.

      - Todd


      --- Christian van der Leeden <leeden@...>
      wrote:

      > Hi Todd,
      >
      > thanks for the help, just looked into the example,
      > where "this" ==
      > the menu item.
      > I'd like "this" to be my object and not the menu
      > item, so I can call
      > the instance
      > methods of my object. Is that possible, too?
      >
      > Like
      >
      >
      MyHandlerObject.prototype.changeMySelectionToSomethingDependingOnTheMenu
      >
      > ItemClicked = function(menuItem) {
      > };
      >
      > MyHandlerObject.prototype.handleClickEvent =
      > function(type,
      > arguments, value) {
      > /* this == instance of MyHandlerObject */
      > var menuItem = /* how should I get the clicked menu
      > item? */
      >
      >
      this.changeMySelectionToSomethingDependingOnTheMenuItemClicked
      >
      > (menuItem);
      > };
      >
      > MyHandlerObject.prototype.setupMenu = function() {
      > ....
      > item.clickEvent.subscribe(this.handleClickEvent,
      > this,true);
      > ...
      > }
      >
      > My current workaround is to pass the menu item into
      > the fire method
      > as a second argument
      > (patching yui :-).
      >
      > Christian
      >
      > On 26.09.2006, at 19:14, Todd Kloots wrote:
      >
      > > Hi Christian -
      > >
      > > There is an existing YUI Menu example that
      > addresses
      > > handling click events:
      > >
      > >
      >
      http://developer.yahoo.com/yui/examples/menu/example09.html
      > >
      > > As you can see in the example, you'll be able to
      > find
      > > the index of the item that was click by checking
      > the
      > > "index" property inside you click event handler.
      > >
      > > Hope that "unlocks" your brain. :P
      > >
      > > - Todd
      > >
      > > --- Christian van der Leeden
      > <leeden@...>
      > > wrote:
      > >
      > >> Hi,
      > >>
      > >> I'm trying to setup a menu in Javascript (works
      > >> well), now I want to
      > >> trigger a java script function on click. So I
      > >> subscribe myself to the
      > >> onClick event of the MenuBarItem. Works, too. But
      > >> how can I access
      > >> the MenuBarItem that was clicked on? I'm building
      > >> the
      > >> Menu in a for loop, like:
      > >>
      > >> for(var j=0; j<response.selection.length; j++ )
      > {
      > >> item = new
      > >> YAHOO.widget.MenuBarItem(response.selection[j] +
      > >> "");
      > >>
      > >>
      > >
      >
      item.clickEvent.subscribe(this.handleNavigationPathClick,
      > >> this, true);
      > >> oMenu.addItem(item);
      > >> }
      > >>
      > >> I'm somehow missing something important... Any
      > hints
      > >> to resolve my
      > >> "brain lock" will be very appreciated.
      > >>
      > >> Thanx
      > >>
      > >> Christian
      > >> P.S.: Im trying to find what index was clicked
      > on,
      > >> e.g. if it was the
      > >> 4th element or the 5th element in the
      > >> menu
      > >>
      > >> -----------------------------------------------
      > >> Software Engineering
      > >> leeden@...
      > >> +49-89-189488-66
      > >>
      > >>
      > >>
      > >>
      > >>
      > >> Yahoo! Groups Links
      > >>
      > >>
      > >>
      > >> (Yahoo! ID required)
      > >>
      > >>
      > mailto:ydn-javascript-fullfeatured@yahoogroups.com
      > >>
      > >>
      > >>
      > >>
      > >>
      > >>
      > >>
      > >
      > >
      > >
      > >
      > >
      > >
      > > Yahoo! Groups Links
      > >
      > >
      > >
      > >
      > >
      > >
      > >
      > >
      > >
      >
      > -----------------------------------------------
      > Software Engineering
      > leeden@...
      > +49-89-189488-66
      >
      >
      >
      >
      >
      > Yahoo! Groups Links
      >
      >
      >
      > (Yahoo! ID required)
      >
      > mailto:ydn-javascript-fullfeatured@yahoogroups.com
      >
      >
      >
      >
      >
      >
      >
    Your message has been successfully submitted and would be delivered to recipients shortly.