wapi-doc/layout/own-scripts.js
/*
  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.
*/
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.
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 .
function autoCollapse() {
  var windowHeight = getWindowDimensions()[1]
  var itemsHeight = 64 
  var itemsArray = Array.prototype.slice.call(
    document.querySelectorAll('nav .resource-group .heading')
  )
  itemsArray.forEach(function (item) {
    itemsHeight += item.parentNode.offsetHeight
  })
  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++) {
      var itemHeight = sortedItems[i].nextSibling.offsetHeight
      if (
        itemsHeight - itemHeight <= windowHeight ||
        i === sortedItems.length - 1
      ) {
        itemsHeight -= itemHeight
        toggleCollapseNav({ target: sortedItems[i].children[0] }, true)
        sortedItems.splice(i, 1)
        break
      }
    }
  }
}
function autoCollapse ( ) { var windowHeight = getWindowDimensions ( ) [ 1 ] var itemsHeight = 64 var itemsArray = Array . prototype . slice . call ( document . querySelectorAll ( 'nav .resource-group .heading' ) ) itemsArray . forEach ( function ( item ) { itemsHeight += item . parentNode . offsetHeight } ) 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 ++ ) { var itemHeight = sortedItems [ i ] . nextSibling . offsetHeight if ( itemsHeight - itemHeight <= windowHeight || i === sortedItems . length - 1 ) { itemsHeight -= itemHeight toggleCollapseNav ( { target : sortedItems [ i ] . children [ 0 ] } , true ) sortedItems . splice ( i , 1 ) break } } } }
Determine which navigation items should be auto-collapsed to show as many
as possible on the screen, based on the current window height.
Determine which navigation items should be auto - collapsed to show as many as possible on the screen based on the current window height .
/* Account for some padding */ // Get the total height of the navigation items // 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. // Will collapsing this item help? // 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.