more JS refactoring to share code between pop up and detail view