Moved JS logic from DTL to JS API.