Make javascript handle collapsing h3s or h2s

Part of this: https://trello.com/c/IVx0OoUI/214-manuals-grouping-headings-shouldn-t-be-collapsable-2

This PR completes the Javascript handling of working out if it is h2s or h3s that should be marked up to be collapsible. 

I'm interested on feedback on the JavaScript, the other files changed here are in supporting roles, nothing much to see there. With the JS though, is it obvious what I'm doing here? Is the conversion from "depth" to some heading clear?