{"version":3,"sources":["webpack://gli-frontend/../web/themes/custom/gilderlehrman_theme/src/js/gli__anchor_jump_menu.js"],"names":["Drupal","$","behaviors","gliAnchorJumpMenu","attach","context","width","anchors","querySelectorAll","length","showHideMenu","noBoxShadow","heroBanner","document","querySelector","window","innerWidth","section_width","anchorMenuDiv","classList","remove","add","anchorMenuWrapper","anchorMenuContent","i","anchorContent","dataset","anchorText","anchorTarget","id","createElement","anchorMenuHandle","innerHTML","anchorMenuList","relativeElement","appendChild","anchorMenuDivClone","cloneNode","getElementById","insertAdjacentElement","Array","prototype","slice","call","children","forEach","item","offsetWidth","IntersectionObserver","entries","anchorMenuEntry","isIntersecting","boundingClientRect","top","setTimeout","root","rootMargin","threshold","observe","getElementsByTagName","addEventListener","e","contains","target","toggle","jQuery"],"mappings":"88BAAA,SAAEA,EAAQC,GAORD,EAAOE,UAAUC,kBAAoB,CACnCC,OADmC,SAC5BC,GACL,IA0EQC,EA1EFC,EAAUF,EAAQG,iBAAiB,mBACzC,GAAID,EAAQE,OAAQ,CAElB,IAFkB,IAkFTC,EAAT,WACE,IAAMC,EAAc,gBACdC,EAAaC,SAASC,cAAc,gBACtCC,OAAOC,WAAaC,GACtBC,EAAcC,UAAUC,OAAO,mBAC3BR,GACFA,EAAWO,UAAUE,IAAIV,KAI3BO,EAAcC,UAAUE,IAAI,mBACxBT,GACFA,EAAWO,UAAUC,OAAOT,IAK5BI,OAAOC,WAAa,IACtBM,EAAkBH,UAAUE,IAAI,mBAGhCC,EAAkBH,UAAUC,OAAO,oBAtGnCG,EAAoB,GACfC,EAAI,EAAGA,EAAIjB,EAAQE,OAAQe,IAAK,CACvC,IAAIC,EAAgBlB,EAAQiB,GAAGE,QAAQC,WACnCC,EAAerB,EAAQiB,GAAGK,GAC9BN,GAAqB,iBAAJ,OAAsBK,EAAtB,4CAAwEH,EAAxE,aAEnB,IAAMP,EAAgBb,EAAQyB,cAAc,OAC5CZ,EAAcC,UAAUE,IAAI,oBAC5B,IAAMC,EAA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iE,S","file":"/js/gli__anchor_jump_menu.js","sourcesContent":["((Drupal, $) => {\n\n /**\n * Set up the Anchor Jump Menu functionality.\n *\n * @type {Drupal~behavior}\n */\n Drupal.behaviors.gliAnchorJumpMenu = {\n attach(context) {\n const anchors = context.querySelectorAll('.js-anchor-item');\n if (anchors.length) {\n let anchorMenuContent = '';\n for (let i = 0; i < anchors.length; i++) {\n let anchorContent = anchors[i].dataset.anchorText;\n let anchorTarget = anchors[i].id;\n anchorMenuContent += `
  • ${ anchorContent }
  • `;\n }\n const anchorMenuDiv = context.createElement('div');\n anchorMenuDiv.classList.add('anchor-jump-menu');\n const anchorMenuWrapper = context.createElement('div');\n anchorMenuWrapper.classList.add('anchor-jump-menu__wrapper');\n const anchorMenuHandle = context.createElement('div');\n anchorMenuHandle.classList.add('anchor-jump-menu__handle', 'js-anchor-menu-handle');\n anchorMenuHandle.innerHTML = `\n
    \n
    \n `;\n const anchorMenuList = context.createElement('ul');\n anchorMenuList.classList.add('anchor-jump-menu__menu');\n anchorMenuList.innerHTML = `\n ${ anchorMenuContent }\n `;\n\n const relativeElement = context.createElement('div');\n anchorMenuWrapper.appendChild(relativeElement);\n anchorMenuDiv.appendChild(anchorMenuHandle);\n anchorMenuDiv.appendChild(anchorMenuList);\n anchorMenuWrapper.appendChild(anchorMenuDiv);\n const anchorMenuDivClone = anchorMenuDiv.cloneNode(true);\n anchorMenuDivClone.classList.add('visually-hidden');\n anchorMenuWrapper.appendChild(anchorMenuDivClone);\n context.getElementById('main').insertAdjacentElement(\"beforebegin\", anchorMenuWrapper);\n let section_width = calcMenuWidth();\n showHideMenu();\n\n // if (!anchorBurger) {\n // Switch to sidebar menu on scroll.\n const anchorMenuIntersectionOptions = {\n root: null,\n rootMargin: '0px',\n threshold: 0.5\n }\n\n const anchorMenuObserver = new IntersectionObserver(anchorMenuScrollHandler, anchorMenuIntersectionOptions);\n anchorMenuObserver.observe(relativeElement);\n // }\n function anchorMenuScrollHandler(entries) {\n const [anchorMenuEntry] = entries;\n if (anchorMenuEntry.isIntersecting) {\n anchorMenuDivClone.classList.add('visually-hidden');\n anchorMenuDivClone.classList.remove('anchor-jump-menu--hamburger')\n }\n else if (anchorMenuEntry.boundingClientRect.top < 0) {\n anchorMenuDivClone.classList.remove('visually-hidden');\n anchorMenuDivClone.classList.add(\"anchor-jump-menu--hamburger\", \"anchor-jump-menu--hidden\")\n setTimeout(\n () => {\n anchorMenuDivClone.classList.remove(\"anchor-jump-menu--hidden\");\n },\n 100);\n }\n }\n\n // Open/close functionality\n const docBody = context.getElementsByTagName('body')[0];\n\n docBody.addEventListener('click', (e) => {\n if (anchorMenuDivClone.contains(e.target)) {\n anchorMenuDivClone.classList.toggle('anchor-jump-menu--open');\n }\n });\n\n function calcMenuWidth() {\n let width = 0;\n let array = Array.prototype.slice.call(anchorMenuDiv.children[1].children);\n array.forEach((item) => {\n width += item.offsetWidth;\n });\n\n return width;\n }\n\n function showHideMenu() {\n const noBoxShadow = 'no-box-shadow';\n const heroBanner = document.querySelector('.hero-banner');\n if (window.innerWidth > section_width) {\n anchorMenuDiv.classList.remove('visually-hidden');\n if (heroBanner) {\n heroBanner.classList.add(noBoxShadow);\n }\n }\n else {\n anchorMenuDiv.classList.add('visually-hidden');\n if (heroBanner) {\n heroBanner.classList.remove(noBoxShadow);\n }\n }\n\n // Hide all on mobile.\n if (window.innerWidth < 701) {\n anchorMenuWrapper.classList.add('visually-hidden');\n }\n else {\n anchorMenuWrapper.classList.remove('visually-hidden');\n }\n }\n\n window.addEventListener('resize', () => {\n showHideMenu();\n });\n }\n }\n };\n})(Drupal, jQuery);\n"],"sourceRoot":""}