added support for CommonJS, AMD and fall back to window