Added helper for async JavaScript

Moved ugly JS code from views to the gem.