Move AMD logic to Elgg_RequireJS

Fixes module loading in subdomains
Avoids fatal if no module added before foot rendered
Avoids duplicate deps