Hi,
I created solution for you on codepen
A Pen by xszaboj[
^]
I am not able to call you API from codepen. So a wrote you some comments where to call what.
Feel free to tweak it to your needs. Hope it will help you achive what you need to do. Any questions just ask, and i will try to help.