Image & File fields: Improved JS to better handle library option

Signed-off-by: Elliot Condon <e@elliotcondon.com>
Unterminated function fix (reported in #58 by @iceicetimmy)
Merge pull request #87 from om4james/jsfixes

Unterminated function fix