Add "onBeforeClose" callback

I've added a callback the fires before calling close(). I'm using it for "Are you sure you want to close this dialog?" stuff. Merge it if you want it :-)