src/js/build-html.js
function updateToc (headingsArray) {
    // If a fixed content container was set
    if (options.scrollContainer && document.querySelector(options.scrollContainer)) {
      var top = document.querySelector(options.scrollContainer).scrollTop
    } else {
      var top = document.documentElement.scrollTop || body.scrollTop
    }

    // Add fixed class at offset
    if (options.positionFixedSelector) {
      updateFixedSidebarClass()
    }

    // Get the top most heading currently visible on the page so we know what to highlight.
    var headings = headingsArray
    var topHeader
    // Using some instead of each so that we can escape early.
    if (currentlyHighlighting &&
      document.querySelector(options.tocSelector) !== null &&
      headings.length > 0) {
      some.call(headings, function (heading, i) {
        if (getHeadingTopPos(heading) > top + options.headingsOffset + 10) {
          // Don't allow negative index value.
          var index = (i === 0) ? i : i - 1
          topHeader = headings[index]
          return true
        } else if (i === headings.length - 1) {
          // This allows scrolling for the last heading on the page.
          topHeader = headings[headings.length - 1]
          return true
        }
      })

      // Remove the active class from the other tocLinks.
      var tocLinks = document.querySelector(options.tocSelector)
        .querySelectorAll('.' + options.linkClass)
      forEach.call(tocLinks, function (tocLink) {
        tocLink.className = tocLink.className.split(SPACE_CHAR + options.activeLinkClass).join('')
      })
      var tocLis = document.querySelector(options.tocSelector)
        .querySelectorAll('.' + options.listItemClass)
      forEach.call(tocLis, function (tocLi) {
        tocLi.className = tocLi.className.split(SPACE_CHAR + options.activeListItemClass).join('')
      })

      // Add the active class to the active tocLink.
      var activeTocLink = document.querySelector(options.tocSelector)
        .querySelector('.' + options.linkClass +
          '.node-name--' + topHeader.nodeName +
          '[href="#' + topHeader.id + '"]')
      if (activeTocLink.className.indexOf(options.activeLinkClass) === -1) {
        activeTocLink.className += SPACE_CHAR + options.activeLinkClass
      }
      var li = activeTocLink.parentNode
      if (li && li.className.indexOf(options.activeListItemClass) === -1) {
        li.className += SPACE_CHAR + options.activeListItemClass
      }

      var tocLists = document.querySelector(options.tocSelector)
        .querySelectorAll('.' + options.listClass + '.' + options.collapsibleClass)

      // Collapse the other collapsible lists.
      forEach.call(tocLists, function (list) {
        if (list.className.indexOf(options.isCollapsedClass) === -1) {
          list.className += SPACE_CHAR + options.isCollapsedClass
        }
      })

      // Expand the active link's collapsible list and its sibling if applicable.
      if (activeTocLink.nextSibling && activeTocLink.nextSibling.className.indexOf(options.isCollapsedClass) !== -1) {
        activeTocLink.nextSibling.className = activeTocLink.nextSibling.className.split(SPACE_CHAR + options.isCollapsedClass).join('')
      }
      removeCollapsedFromParents(activeTocLink.parentNode.parentNode)
    }
  }
function updateToc (headingsArray) {
    // If a fixed content container was set
    if (options.scrollContainer && document.querySelector(options.scrollContainer)) {
      var top = document.querySelector(options.scrollContainer).scrollTop
    } else {
      var top = document.documentElement.scrollTop || body.scrollTop
    }

    // Add fixed class at offset
    if (options.positionFixedSelector) {
      updateFixedSidebarClass()
    }

    // Get the top most heading currently visible on the page so we know what to highlight.
    var headings = headingsArray
    var topHeader
    // Using some instead of each so that we can escape early.
    if (currentlyHighlighting &&
      document.querySelector(options.tocSelector) !== null &&
      headings.length > 0) {
      some.call(headings, function (heading, i) {
        if (getHeadingTopPos(heading) > top + options.headingsOffset + 10) {
          // Don't allow negative index value.
          var index = (i === 0) ? i : i - 1
          topHeader = headings[index]
          return true
        } else if (i === headings.length - 1) {
          // This allows scrolling for the last heading on the page.
          topHeader = headings[headings.length - 1]
          return true
        }
      })

      // Remove the active class from the other tocLinks.
      var tocLinks = document.querySelector(options.tocSelector)
        .querySelectorAll('.' + options.linkClass)
      forEach.call(tocLinks, function (tocLink) {
        tocLink.className = tocLink.className.split(SPACE_CHAR + options.activeLinkClass).join('')
      })
      var tocLis = document.querySelector(options.tocSelector)
        .querySelectorAll('.' + options.listItemClass)
      forEach.call(tocLis, function (tocLi) {
        tocLi.className = tocLi.className.split(SPACE_CHAR + options.activeListItemClass).join('')
      })

      // Add the active class to the active tocLink.
      var activeTocLink = document.querySelector(options.tocSelector)
        .querySelector('.' + options.linkClass +
          '.node-name--' + topHeader.nodeName +
          '[href="#' + topHeader.id + '"]')
      if (activeTocLink.className.indexOf(options.activeLinkClass) === -1) {
        activeTocLink.className += SPACE_CHAR + options.activeLinkClass
      }
      var li = activeTocLink.parentNode
      if (li && li.className.indexOf(options.activeListItemClass) === -1) {
        li.className += SPACE_CHAR + options.activeListItemClass
      }

      var tocLists = document.querySelector(options.tocSelector)
        .querySelectorAll('.' + options.listClass + '.' + options.collapsibleClass)

      // Collapse the other collapsible lists.
      forEach.call(tocLists, function (list) {
        if (list.className.indexOf(options.isCollapsedClass) === -1) {
          list.className += SPACE_CHAR + options.isCollapsedClass
        }
      })

      // Expand the active link's collapsible list and its sibling if applicable.
      if (activeTocLink.nextSibling && activeTocLink.nextSibling.className.indexOf(options.isCollapsedClass) !== -1) {
        activeTocLink.nextSibling.className = activeTocLink.nextSibling.className.split(SPACE_CHAR + options.isCollapsedClass).join('')
      }
      removeCollapsedFromParents(activeTocLink.parentNode.parentNode)
    }
  }
function updateToc ( headingsArray ) { // If a fixed content container was set if ( options . scrollContainer && document . querySelector ( options . scrollContainer ) ) { var top = document . querySelector ( options . scrollContainer ) . scrollTop } else { var top = document . documentElement . scrollTop || body . scrollTop } // Add fixed class at offset if ( options . positionFixedSelector ) { updateFixedSidebarClass ( ) } // Get the top most heading currently visible on the page so we know what to highlight. var headings = headingsArray var topHeader // Using some instead of each so that we can escape early. if ( currentlyHighlighting && document . querySelector ( options . tocSelector ) !== null && headings . length > 0 ) { some . call ( headings , function ( heading , i ) { if ( getHeadingTopPos ( heading ) > top + options . headingsOffset + 10 ) { // Don't allow negative index value. var index = ( i === 0 ) ? i : i - 1 topHeader = headings [ index ] return true } else if ( i === headings . length - 1 ) { // This allows scrolling for the last heading on the page. topHeader = headings [ headings . length - 1 ] return true } } ) // Remove the active class from the other tocLinks. var tocLinks = document . querySelector ( options . tocSelector ) . querySelectorAll ( '.' + options . linkClass ) forEach . call ( tocLinks , function ( tocLink ) { tocLink . className = tocLink . className . split ( SPACE_CHAR + options . activeLinkClass ) . join ( '' ) } ) var tocLis = document . querySelector ( options . tocSelector ) . querySelectorAll ( '.' + options . listItemClass ) forEach . call ( tocLis , function ( tocLi ) { tocLi . className = tocLi . className . split ( SPACE_CHAR + options . activeListItemClass ) . join ( '' ) } ) // Add the active class to the active tocLink. var activeTocLink = document . querySelector ( options . tocSelector ) . querySelector ( '.' + options . linkClass + '.node-name--' + topHeader . nodeName + '[href="#' + topHeader . id + '"]' ) if ( activeTocLink . className . indexOf ( options . activeLinkClass ) === - 1 ) { activeTocLink . className += SPACE_CHAR + options . activeLinkClass } var li = activeTocLink . parentNode if ( li && li . className . indexOf ( options . activeListItemClass ) === - 1 ) { li . className += SPACE_CHAR + options . activeListItemClass } var tocLists = document . querySelector ( options . tocSelector ) . querySelectorAll ( '.' + options . listClass + '.' + options . collapsibleClass ) // Collapse the other collapsible lists. forEach . call ( tocLists , function ( list ) { if ( list . className . indexOf ( options . isCollapsedClass ) === - 1 ) { list . className += SPACE_CHAR + options . isCollapsedClass } } ) // Expand the active link's collapsible list and its sibling if applicable. if ( activeTocLink . nextSibling && activeTocLink . nextSibling . className . indexOf ( options . isCollapsedClass ) !== - 1 ) { activeTocLink . nextSibling . className = activeTocLink . nextSibling . className . split ( SPACE_CHAR + options . isCollapsedClass ) . join ( '' ) } removeCollapsedFromParents ( activeTocLink . parentNode . parentNode ) } }
Update TOC highlighting and collpased groupings.
Update TOC highlighting and collpased groupings .