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
My bad, I got confused by GitHub's diff. I thought you had split out the IE8 case but I see that was already separate.