code: function autoCollapse() {
    var windowHeight = getWindowDimensions()[1];
    var itemsHeight = 64; /* Account for some padding */
    var itemsArray = Array.prototype.slice.call(
      document.querySelectorAll('nav .resource-group .heading'));
  
    // Get the total height of the navigation items
    itemsArray.forEach(function (item) {
      itemsHeight += item.parentNode.offsetHeight;
    });
  
    // Should we auto-collapse any nav items? Try to find the smallest item
    // that can be collapsed to show all items on the screen. If not possible,
    // then collapse the largest item and do it again. First, sort the items
    // by height from smallest to largest.
    var sortedItems = itemsArray.sort(function (a, b) {
      return a.parentNode.offsetHeight - b.parentNode.offsetHeight;
    });
  
    while (sortedItems.length && itemsHeight > windowHeight) {
      for (var i = 0; i < sortedItems.length; i++) {
        // Will collapsing this item help?
        var itemHeight = sortedItems[i].nextSibling.offsetHeight;
        if ((itemsHeight - itemHeight <= windowHeight) || i === sortedItems.length - 1) {
          // It will, so let's collapse it, remove its content height from
          // our total and then remove it from our list of candidates
          // that can be collapsed.
          itemsHeight -= itemHeight;
          toggleCollapseNav({target: sortedItems[i].children[0]}, true);
          sortedItems.splice(i, 1);
          break;
        }
      }
    }
  }
docs: /*
  Determine which navigation items should be auto-collapsed to show as many
  as possible on the screen, based on the current window height. This also
  collapses them.