Fix slider JS (not taken from slider macro) and refactor code

This refs affinitic #5843