Added beforeClose event

It is now possible to perform clean-up operations right before modal gets destroyed. The tests attached document how to use this new functionality.