Refactor javascript out of view