paulkinzett / toolbar

A tooltip style toolbar jQuery plugin
http://paulkinzett.github.com/toolbar/
MIT License
2.3k stars 321 forks source link

How do you close toolbar when an icon is clicked? #23

Closed photostu closed 10 years ago

photostu commented 11 years ago

Sorry if this is mentioned somewhere that I haven't read yet, but I can show my toolbars and have added dynamic click handlers for each of the icons, yet, how do you close the toolbar when an icon is clicked?

Thanks for your contribution!

photostu commented 11 years ago

I did find a work-around and perhaps this is the appropriate method currently, but what I did was get the element that the toolbar is attached to, then discover the 'toobarObj' object in the data property and call hide() off of that.

If there is a better way, I'm all ears, but this seems to work.

bora77 commented 11 years ago

Just started using this script and jquery, but for me this worked:

$('.myToolbarButton').on('toolbarItemClick', function(event) { $(this).trigger('click'); });

jakerocheleau commented 11 years ago

bora77 that code definitely works thank you. photostu I wish I could follow your method, I checked into the data property of the toolbar item itself and I get an undefined value. If you can share your codes I will definitely check them out.

But I think using the jQuery .trigger() method is easier because it's forcing the browser to recognize the click event and then naturally hide the menu. Also you can examine the clicked object data by using the console.dir() method which I just found on Stack.

  $('#toolbar-btn').on('toolbarItemClick', function(event){
    console.dir(event);
    $(this).trigger('click');
  });