rawnet/jquery-switch — pull request #3 by aquam8 (2011-12-23 00:22:08+00:00)
Title: Added "slide" event notification and a function hook "before" to run before any slide action

This adds a "slide" event notification passing the customized new value after the transition has happened. So you can get notified by doing this:

something.bind("slide", function(event, slide_val)) {
// Do something with slide_val ...
});

Also there's an optional function hook "before(...)" that is run before any on/off/toggle action. Returning false prevents to action while true let the action happen.

before(...) takes 3 arguments: - controls: the control object so you can run your own action e.g. control.on()
- type: on/off - custom_type: the custom values for on/off

$("select").switchify({
before: function(controls, type, custom_type) {
// do something asynchronous that has some callbacks for success and/or error for example.
$.ajax(
//...
success: function() {
// Do something custom here, and then call the transition silently so before function is not called.
controls[type]({silent: true}); // like controls.on({silent: true});
},
error: function(){
// the slider won't move because there was an error.
}
// ...
);

return false;
}
});