Streamline attachments javascript

Initialize the necessary elements on $(document).ready(), rather than on
every click.

See #362

Hat tip to @yura121