jgallen23/routie — pull request #16 by andreas-trad (2013-09-03 12:45:24+00:00)
Title: Added unload function execution capabilities

With the proposed addition the user can add an extra parameter when initializing routie so that an unload function is been executed when the user leaves a specific hash page.
The unload function is also been executed when the user leaves page or closes his browser (window.onbeforeunload event).
The way it operates is simple. Let's suppose the following example:
routie({
'apage/:id': function(id) {
/* handles the load part */
}
}, // here the classic routie operation ends and the new starts
{ // we define unload functions in exact the same way
'apage/:id': function(id) {
/* here we can write any code. This code will be executed when the user leaves the hash or actual page.
if the function returns a string then this string will be used for exit page confirmation either when the user goes to another hash or another physical page. If the function returns anything else but string (or nothing at all) no confirmation message will appear. Only the code will be executed */
}
} // the unload functions part ends. We don't have to declare functions for all of our hashes. Only for those for which we want an unload function to be executed.
); // routie ends