The confirmOn plugin shows a confirmation box when the provided events are triggered. It works exactly like jQuery's .on() but with a confirmation step between the event and the handler. When the user answers the confirmation dialog, the handler is called with the answer as a parameter, so you can decide what to do next. The user can press the escape key which closes the dialog and doesn't call the yes or no handlers.
Since there are only a few classes involved you can insert the classes into your existing stylesheet for performance sake.
Usage
Use .confirmOn() the same way as you use jQuery's .on(). Check http://api.jquery.com/on/ for the documentation.
There are some options that can be set to customize the plugin. Add them as the first argument of .confirmOn().
{
questionText: 'Are you sure?', // The confirmation question
classPrepend: 'confirmon', // Use another prefix for the classes used by the plugin
textYes: 'Yes', // Text on the button the user clicks when the handler should be called
textNo: 'No' // Text on the button the user clicks when the handler should not be called
}
Example
$('#myButton').confirmOn('click', function(e, confirmed){
if(confirmed) deleteSomethingImportant();
else {
//If we need to, we can do some actions here if the user cancelled the confirmation
}
})