Move Javascript so it can be used in preview mode