VE-1670: Handle escape key properly in media preview

Copied method from WikiaMediaInsertDialog to handle the escape key properly.