jQuery-EasyTabs icon indicating copy to clipboard operation
jQuery-EasyTabs copied to clipboard

Adding Callback to public select function

Open iNaD opened this issue 12 years ago • 1 comments

Hi guys,

as far as I can see in the source, it's currently not possible to change the tab programmatically and setting a callback. The only way is to bind the easytab:after event and unbind it after executing your callback stuff.

My jQuery experience isn't the best, but adding something like the following to the public select function enables the possibility to add anonymous callback functions:

plugin.publicMethods = {
  select: function(options){
        var tabSelector = options[0].tabSelector;
        var callback = options[0].callback;
        var $tab;

        /**
         * Tab selector stuff is here
         */
        plugin.selectTab($tab, callback);
  }
};

I don't know if this is the right way to pass multiple arguments to a public method with jQuery.

But now you can do stuff like:

$("#hotel-tab-container").easytabs('select', {
  tabSelector: '#ratings',
  callback: function() {
      $('html, body').animate({scrollTop: $("#id").offset().top}, 'slow');
  }
});

I hope someone will implement this the right way or tell me if this is quite right so I can make a pull request.

Yours Daniel

iNaD avatar Jul 25 '13 08:07 iNaD

You are correct that this can be done by binding once to the easytabs:after event hook, e.g.:

var mytabs = $('#my-tabs').easytabs();
mytabs.one('easytabs:after', function() {
  // callback code here
});
mytabs.easytabs('select', '#tab2');

That being said, I'd be open to implementing a callback for the public select function. I wouldn't do it the proposed way though, as I don't like the idea of having to pass an options object to the public method. I'd like to keep it simple so that to use the method, you just have to do mytabs.easytabs('select', '#tab2'). If we were to implement callback support, I'd just accept it as the optional third argument.

JangoSteve avatar Sep 05 '13 17:09 JangoSteve