Thank you very much Iftekharul Islam for this helpful solution.
Narek Gevorkyan

Thanks Narek. Sorry I did not create pull request. The nature of the project required the code to be private. But it is ok now that we have published. You can grab the modified js with a working prototype here-

Let me know if anything!