Move JS to Includes, Minify, Load Editor Async

This also tries to fix some stuff in the custom JS code, e.g. wrapping
code in self-invoking functions to avoid setting global variables.