New code to close modals (#1301)

The code before was failing because there was no open-modal link in
the situation described in #1301.  Reworked the code to make it
cleaner and fix the bug.  Removed the code that closed the dialog when
you click outside of it.  I think having the close button is enough.