codedance/jquery.AreYouSure — pull request #27 by barzik (2014-01-25 09:07:49+00:00)
Title: Adding callback just before the unload

Adding callback for unload event. The callback eanble the developer to override the default unload behavior. It is useful if you want to implement other behavior in case of anchor generetaed unload event. for example - themed modal window - See FaceBook for example. If the user is Ctrl+F5 the page, the regular unload event is being fired. If the user is clicking some link - themed modal is being opened. It can be achieved with AreYouSure using before_unload_callback like the example that I've attached in the readme.md.
The developer will have to implement the modal and will have to make sure that the click event will return false.

Here is a real life example:

```javascript
//calling are-you-sure
$('#my-adv-form').areYouSure({before_unload_callback: function() {
if(window.unload_source != 'anchor') { //if it is no anchor generated unload, proceed
return true;
}
}});
$('a').on('click', function() { //implementing the themed modal behavior. just like facebook
if($(this).first().data('events').click.length == 1) { //if we don't have anu other event than one click
window.unload_source = 'anchor';
window.unload_target = $(this).attr('href');
$('#unload_modal').modal(); //creating the modal
return false; //we don't want the link to work
}
});
$('#unload_modal_ok').on('click', function() { //handling the themed unload modal "Yes"
window.location.href = window.unload_target;
return false;
});
```