Added unload function execution capabilities #16
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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