Closing a modal panel "onblur"


#1

I am looking for a way to close a modal panel if the user hits esc or click outside of the panel.

What is the best way to achieve this?