Reimplement document click listener

Make each instance add its own listener to the document click event,
otherwise if we remove the first instance from the DOM, no other
instances (existing or newly-created) will close up their dropdown when
clicking away.