Move javascript from template to js file