paulkinzett / toolbar

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

Use of class instead of id's for multiple toolbars on same page? #13

Open macsupport opened 11 years ago

macsupport commented 11 years ago

Is there a method to load the toolbar using classes for both the link and for the content div? I have an image gallery with buttons for each image ( favorite, print, info, etc.) and I want to use a single icon to click to open the toolbar but be able to use classes so I don't have to have an id for each toolbar ( the page has many images on it).

skyzyx commented 11 years ago

Using data attributes would be far better.

macsupport commented 11 years ago

Ahh, much better!

macsupport commented 11 years ago

Does this mean one can't do this? Not sure why it was closed without at least a comment.

paulkinzett commented 11 years ago

Hi

Sorry I thought this one was solved.

If you had HTML like below...

<div class="settings-button" data-toolbar="true"><img src="img/icon-cog-small.png" /></div>
<div class="settings-button" data-toolbar="true"><img src="img/icon-cog-small.png" /></div>
<div class="settings-button" data-toolbar="true"><img src="img/icon-cog-small.png" /></div>

Then you could load all the toolbars using the Js

$('div[data-toolbar]').toolbar({
    content: '#user-options',
    position: 'top'
});

Is that what you are after?

macsupport commented 11 years ago

Thanks. This works but the toolbar icons do not respond to a click. In this scenario, would I need a click handler for each icon? I tried:

$('.toolbar-icons a').on('click', function() {
                    $(this).click();                     
                });

Gives me "too much recursion"

bergmark commented 11 years ago

@macsupport click triggers the click handlers, so that's why it recurses.

qtronik commented 10 years ago

this on "toolbarItemClick" function do not return the cliked ITEM object but the tool bar trigger itself...

mvkamalesh commented 10 years ago

Hi Paul,

$('div[data-toolbar]').toolbar({ content: '#user-options', position: 'top' });

above works well but i need the content: part also to be unique?

I have a listing page with 10 posts per page i want each post to have a toolbar, currently same content tools for all the post. how do i achieve this.

regards, kamalesh mv

ashffaq commented 9 years ago

@mvkamalesh

I figured it out by writing the init script in the loop, you have to define and different id for each post,

          <?php $counter = 1 ?>

           <div class="btn-toolbar" id="sharebutton<?php echo $counter; ?>"></div>
            <div id="toolbar-options<?php echo $counter; ?>"  class="hidden">

            </div>
            <script type="text/javascript">
            $('#sharebutton<?php echo $counter; ?>').toolbar({
                content: '#toolbar-options<?php echo $counter; ?>',
                position: 'top',
                animation: 'bounce',
                adjustment: 25,
            });
            </script>

           <?php $counter ++ ?>

$counter will increase every time loop run and will create different ids