Is it possible to move this from the template to a js file?