Add support for RequireJS and other AMD loaders

Related to Issue #278, here's a proposed fix that supports both AMD loaders and standard window-scoped variables.