#229: refactor previewing functionality's js parts