Add onPluginsReady event, and join on it before firing onDeviceReady

This happens only when a magic variable (window.__onPluginsLoadedHack)
is set, which is done by the generated code in the automatic plugin
loader prototype. A temporary hack that can be removed when the
prototype is either rolled into the main line or scrapped.

The behavior is unchanged when the variable is not set.