Hide sub menus if all pages in the sub menu is hidden.

Based on ysors pull request #2925 now with tests.