Ported to JS/JQuery