Sha256: 3b80d0f8c402bb13287c22ae6f00b4d541cfe2110a3ca5c97fada7e000afd68d

Contents?: true

Size: 964 Bytes

Versions: 6

Compression:

Stored size: 964 Bytes

Contents

// Rather than generating a new left-nav for every page, generate a single nav and use JS to expand the current page

(function (jtd) {

function initNavControls() {
  const siteNav = document.getElementById('site-nav')

  const pageUrl = siteNav.dataset.pageUrl
  const pageParent = siteNav.dataset.pageParent
  const pageGrandParent = siteNav.dataset.pageGrandParent

  console.log({pageUrl, pageParent, pageGrandParent})

  const navItems = siteNav.getElementsByClassName('nav-list-item')

  for (const navItem of navItems) {
    const itemUrl = navItem.dataset.url
    const itemTitle = navItem.dataset.title

    console.log({itemUrl, itemTitle})
    
    if (itemUrl === pageUrl || itemTitle === pageParent || itemTitle == pageGrandParent) {
      navItem.classList.add('active')
      navItem.querySelector('.nav-list-link').classList.add('active')

      navItem.scrollIntoView()
    }
  }
}

jtd.onReady(function(){
  initNavControls()
})

})(window.jtd)

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
fni-docs-theme-0.6.2 assets/js/jtd-nav.js
fni-docs-theme-0.6.1 assets/js/jtd-nav.js
fni-docs-theme-0.6.0 assets/js/jtd-nav.js
fni-docs-theme-0.5.0 assets/js/jtd-nav.js
fni-docs-theme-0.4.3 assets/js/jtd-nav.js
fni-docs-theme-0.4.2 assets/js/jtd-nav.js