[ 5 posts ]

mc_hendriks

  • Joined: Sat Apr 24, 2010 5:53 am
  • Posts: 43
  • Offline
  • Profile

AlloyUI Toolbar (gallery-aui-toolbar) handle click

Post Posted: Sat Sep 18, 2010 5:08 am
+0-
Is there a way to handle clicks on the toolbar thru one onMenuClick function?
It works when I add a handler to every label, would be nicer if it could be configured once and pass the id or label to the onMenuClick function.



Code:
AUI().ready('aui-toolbar', function(A) {
function onMenuClick(item) {
// handle toolbar clicks
    alert(item);
};
var component = new A.Toolbar(
    {
    activeState: true,
    children: [
        {label: 'Add', icon: 'plus',handler:function(){onMenuClick('add');}},
        {label: 'Remove', icon: 'minus'},
        {label: 'Config', icon: 'gear'}
        ]
    }).render('#toolbar');
});

mc_hendriks

  • Joined: Sat Apr 24, 2010 5:53 am
  • Posts: 43
  • Offline
  • Profile

Re: AlloyUI Toolbar (gallery-aui-toolbar) handle click

Post Posted: Sat Sep 18, 2010 5:09 am
+0-
see also:
http://www.digirent.nl/psmyui/vb/tb1.html

Nate Cavanaugh

YUI Contributor

  • Offline
  • Profile
Tags:

Re: AlloyUI Toolbar (gallery-aui-toolbar) handle click

Post Posted: Sun Sep 19, 2010 12:08 pm
+0-
Hi there,
You can add an "after" listener on the toolbar that will attach a listener after a child is added. If you dynamically add new buttons they'll also get the handler as well.

Code:
   function onMenuClick(item) {
      // handle toolbar clicks
       alert(item);
   };

   var component = new A.Toolbar(
      {
         activeState: true,
         after: {
            addChild: function(event) {
               event.child.set('handler', function(event) {
                  onMenuClick(this.get('id'));
               });
            }
         },
         children: [
            {label: 'Add', icon: 'plus'},
            {label: 'Remove', icon: 'minus'},
            {label: 'Config', icon: 'gear'}
         ]
      }
   ).render('#demo1');


You can set the level information you wish to pass to onMenuClick, even passing the event object itself and referring to the button via:
event.currentTarget.

Hopefully that helps, but let me know if you have any other questions.

Thanks,
Nate Cavanaugh

mc_hendriks

  • Joined: Sat Apr 24, 2010 5:53 am
  • Posts: 43
  • Offline
  • Profile

Re: AlloyUI Toolbar (gallery-aui-toolbar) handle click

Post Posted: Mon Sep 20, 2010 2:18 am
+0-
Thanks, this is what I was looking for.

Greetings Matthieu.

mc_hendriks

  • Joined: Sat Apr 24, 2010 5:53 am
  • Posts: 43
  • Offline
  • Profile

Re: AlloyUI Toolbar (gallery-aui-toolbar) handle click

Post Posted: Mon Sep 20, 2010 10:05 am
+0-
Its working for the complete working example see:

http://www.digirent.nl/psmyui/vb/tb1.html


Thanks.

Greetings Matthieu


Last edited by mc_hendriks on Fri Oct 08, 2010 3:41 am, edited 1 time in total.
  [ 5 posts ]
Display posts from previous:  Sort by  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum