`this` is not `window` in `module.exports`
at least, code need `module.exports = factory(window, document);`

What do you want to mean by `}(this, function (w, d) {` ?