Use document/window from event target instead of global

Fixes #427

Test plan: not yet/will test our application on the browsers I have access to.

PS. View changes with ?w=1
I have no idea (this PR only indents it), but considering we never supported IE7, I assume so?