Refactor JS in map.erb