All what you would have to change is the way the map variable is initialized, implement some module/function for adding layers to the map and change the way of loading the legend.
Instead of creating map based on a webmap, you can initialize the map with an empty map, add a basemap to it (either from your server or any other source), some layers (also from any source), and load the legends from the layers. There would be nothing to do with the popups, because after the map is created from a webmap, it behaves the same way like it would be if you created it by yourself.
You could try to do everything from scratch - but it takes some time to create a customizable, multilingual app such as this one ;]