{"version":3,"sources":["webpack:///./src/js/modules/jumpLinkList.js"],"names":["Module","this","dom","anchors","document","querySelectorAll","navContainer","el","querySelector","length","style","display","buildJumpLinks","links","map","anchor","id","camelize","dataset","join","innerHTML","jumpLiks","forEach","link","addEventListener","handleJumpLinkClick","bind","handleCheckInitialAnchor","hash","window","location","jumpToAnchor","e","preventDefault","targetId","target","getAttribute","push","getElementById","replace","gsap","to","duration","scrollTo","offsetTop","history","pushState","Component"],"mappings":"2xEAIMA,E,iXAEFC,KAAKC,IAAM,CACTC,QAAS,EAAIC,SAASC,iBAAiB,kBACvCC,aAAcL,KAAKM,GAAGC,cAAc,0BAGlCP,KAAKC,IAAIC,QAAQM,SACnBR,KAAKM,GAAGG,MAAMC,QAAU,SAG1BV,KAAKW,mB,uCAGU,WACf,GAAIX,KAAKC,IAAIC,QAAQM,OAAQ,CAC3B,IAAMI,EAAQZ,KAAKC,IAAIC,QACpBW,KAAI,SAAAC,GAEH,OADAA,EAAOC,GAAKC,YAASF,EAAOG,QAAQH,QACpC,wBAAwBA,EAAOC,GAA/B,aAAsCD,EAAOG,QAAQH,OAArD,gBAEDI,KAAK,IAERlB,KAAKC,IAAII,aAAac,UAAYP,EAClCZ,KAAKC,IAAImB,SAAT,EAAwBpB,KAAKC,IAAII,aAAaD,iBAAiB,MAC/DJ,KAAKC,IAAImB,SAASC,SAAQ,SAAAC,GAAI,OAC5BA,EAAKC,iBAAiB,QAAS,EAAKC,oBAAoBC,KAAK,OAE/DzB,KAAK0B,8B,iDAIkB,IACjBC,EAASC,OAAOC,SAAhBF,KAEJA,GACF3B,KAAK8B,aAAaH,K,0CAIFI,GAClBA,EAAEC,iBAEF,IAAMC,EAAWF,EAAEG,OAAOC,aAAa,QACvCnC,KAAK8B,aAAaG,GAAU,K,mCAGjBA,EAAUG,GACrB,IAAMF,EAAS/B,SAASkC,eAAeJ,EAASK,QAAQ,IAAK,KAEzDJ,IACFK,IAAKC,GAAGZ,OAAQ,CAAEa,SAAU,EAAGC,SAAUR,EAAOS,UAAY,MAExDP,GACFQ,QAAQC,UAAU,KAAM,KAAMZ,S,8BAtDjBa,aA4DN/C","file":"56.53ed69a3f0d1f3172c94.js","sourcesContent":["import { Component } from '@verndale/core';\r\nimport { gsap } from 'gsap';\r\nimport { camelize } from '../helpers';\r\n\r\nclass Module extends Component {\r\n setupDefaults() {\r\n this.dom = {\r\n anchors: [...document.querySelectorAll('[data-anchor]')],\r\n navContainer: this.el.querySelector('.jump-link-list__list')\r\n };\r\n\r\n if (this.dom.anchors.length) {\r\n this.el.style.display = 'block';\r\n }\r\n\r\n this.buildJumpLinks();\r\n }\r\n\r\n buildJumpLinks() {\r\n if (this.dom.anchors.length) {\r\n const links = this.dom.anchors\r\n .map(anchor => {\r\n anchor.id = camelize(anchor.dataset.anchor);\r\n return `<li><a href=\"#${anchor.id}\">${anchor.dataset.anchor}</a></li>`;\r\n })\r\n .join('');\r\n\r\n this.dom.navContainer.innerHTML = links;\r\n this.dom.jumpLiks = [...this.dom.navContainer.querySelectorAll('a')];\r\n this.dom.jumpLiks.forEach(link =>\r\n link.addEventListener('click', this.handleJumpLinkClick.bind(this))\r\n );\r\n this.handleCheckInitialAnchor();\r\n }\r\n }\r\n\r\n handleCheckInitialAnchor() {\r\n const { hash } = window.location;\r\n\r\n if (hash) {\r\n this.jumpToAnchor(hash);\r\n }\r\n }\r\n\r\n handleJumpLinkClick(e) {\r\n e.preventDefault();\r\n\r\n const targetId = e.target.getAttribute('href');\r\n this.jumpToAnchor(targetId, true);\r\n }\r\n\r\n jumpToAnchor(targetId, push) {\r\n const target = document.getElementById(targetId.replace('#', ''));\r\n\r\n if (target) {\r\n gsap.to(window, { duration: 1, scrollTo: target.offsetTop - 150 });\r\n\r\n if (push) {\r\n history.pushState(null, null, targetId);\r\n }\r\n }\r\n }\r\n}\r\n\r\nexport default Module;\r\n"],"sourceRoot":""}