use document instead of window
Merge branch 'master' into gh-pages