Move javascript logic to coffeescript