Fixed for working in webworker

using document instead of window.document was giving the error "document is not defined".
I am using chrome canary 28 (latest)
Merge pull request #718 from basarat/patch-1

Fixed for working in webworker