Extract $ in MercuryTest.js
Move all state and events to the top level