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.