Add AMD/require.js loading capability if present

Added standard jQuery wrapper for require.js and other AMD javascript loaders, if used. If loaded normally it will just work as before. Tests still run.

Side note: Pushing here instead of original repository because I wanted the retry callback functionality, maybe you can push it onwards or I'll make a new patch later.