Escape single quotes from JavaScript code in image selection.

- TODO: we plan to replace this JavaScript by a better mechasism.