X: Cleanup base code

Several commits to document, cleanup and prepare the cockpit.js base code for the AMD loader.