add AMD module compatibility

Hi.

It'd be nice to have AMD module compatibility so I've made a pull request.
I've removed the window and undefined variables to make the factory more minimal, since these were not used.

Thanks.