Rewrite dropdown JS to use module pattern

Use module pattern, and avoid anonymous functions.

Gives more self-documenting code. Also written to WP JS code standards.

See http://gamajo.com/javascript-module-pattern-example for the theory.