rawnet/jquery-switch — Issue #2: Callback / event for trigger action would be nice
Author: aquam8
Created: 2011-12-20 05:08:43+00:00
State: open

Hi,
I'd like to be called when the slider has been moved so i can do something (like sending an event, storing something, etc.) So a dedicated callback function of an event we can register to would be nice.

I've modified the bind function so that they publish an event when the slide happens:

$switch.bind('slide:on', function() {
$switch.data('animating', true).attr('data-dragging', 'false');
$master.stop().animate({ left: masterOn }, 'fast', function() {
$switch.data('animating', false).data('select').val(values.on);
$switch.removeClass('off').addClass('on');
});
$switch.trigger('slide', values.on); // ADDED THIS HERE
});

// slide to the "off" position
$switch.bind('slide:off', function() {
$switch.data('animating', true).attr('data-dragging', 'false');
$master.stop().animate({ left: masterOff }, 'fast', function() {
$switch.data('animating', false).data('select').val(values.off);
$switch.removeClass('on').addClass('off');
});
$switch.trigger('slide', values.off); // ADDED THIS HERE
});

You can also add other notification event when the transitiom is finished etc.. Here i'm using the same event and passing the customized value.

I then do in my code:
this._$switch.bind('slide', function(event, type) {
[...]

}

My 2cents

Thank you anyway, your project is helpful