Close modals when clicking off them

Closes #3652
Merge pull request #3697 from novaugust/close-modal#3652

Close modals when clicking off them