{"version":3,"sources":["webpack://@verndale/toolkit/./src/js/modules/table-of-contents.js"],"names":["Module","Component","defaultOption","$link","$option","hash","e","newHash"],"mappings":"kJAEA,MAAMA,UAAeC,WAAU,CAC7B,eAAgB,CACd,KAAK,IAAM,CACT,QAAS,KAAK,GAAG,cAAc,6BAA6B,EAC5D,OAAQ,KAAK,GAAG,iBAAiB,sBAAsB,EACvD,SAAU,KAAK,GAAG,cAAc,eAAe,CACjD,EAEA,KAAK,IAAI,QAAQ,UAAY,GAE7B,MAAMC,EAAgB,SAAS,cAAc,QAAQ,EACrDA,EAAc,MAAQ,GACtBA,EAAc,UAAY,KAAK,IAAI,SAAS,UAC5C,KAAK,IAAI,QAAQ,YAAYA,CAAa,EAE1C,KAAK,IAAI,OAAO,QAAQC,GAAS,CAC/B,MAAMC,EAAU,SAAS,cAAc,QAAQ,EAC/CA,EAAQ,MAAQD,EAAM,KACtBC,EAAQ,UAAYD,EAAM,UAC1B,KAAK,IAAI,QAAQ,YAAYC,CAAO,CACtC,CAAC,EAED,KAAM,CAAC,KAAAC,CAAI,EAAI,OAAO,SAClBA,IACF,OAAO,SAAS,KAAO,GACvB,OAAO,SAAS,KAAOA,EAEvB,KAAK,IAAI,OAAO,QAAQF,GAAS,CAC/BA,EAAM,UAAU,OAAO,6BAA6B,EAChDA,EAAM,KAAK,MAAM,GAAG,EAAE,KAAOE,EAAK,MAAM,GAAG,EAAE,IAC/CF,EAAM,UAAU,IAAI,6BAA6B,CAErD,CAAC,EAEL,CAEA,cAAe,CACb,KAAK,IAAI,OAAO,QAAQA,GAAS,CAC/BA,EAAM,iBAAiB,QAAS,KAAK,gBAAgB,KAAK,IAAI,CAAC,CACjE,CAAC,EACD,KAAK,IAAI,QAAQ,iBAAiB,SAAU,KAAK,qBAAqB,KAAK,IAAI,CAAC,CAClF,CAEA,sBAAuB,CACrB,OAAO,SAAS,KAAO,GACvB,OAAO,SAAS,KAAO,KAAK,IAAI,QAAQ,KAC1C,CAEA,gBAAgBG,EAAG,CACjB,MAAMC,EAAUD,EAAE,OAAO,KAAK,MAAM,GAAG,EAAE,GACzC,KAAK,IAAI,QAAQ,MAAQ,IAAIC,IAC7B,KAAK,IAAI,QAAQ,cAAc,IAAI,MAAM,QAAQ,CAAC,EAElD,KAAK,IAAI,OAAO,QAAQJ,GAAS,CAC/BA,EAAM,UAAU,OAAO,6BAA6B,CACtD,CAAC,EACDG,EAAE,OAAO,UAAU,IAAI,6BAA6B,CACtD,CACF,CAEA,UAAeN,C","file":"scripts/865.333d048a.js","sourcesContent":["import { Component } from '@verndale/core';\n\nclass Module extends Component {\n setupDefaults() {\n this.dom = {\n $select: this.el.querySelector('#table-of-contents-dropdown'),\n $links: this.el.querySelectorAll('.toc__list-item-link'),\n $heading: this.el.querySelector('.toc__list h3')\n };\n\n this.dom.$select.innerHTML = '';\n\n const defaultOption = document.createElement('option');\n defaultOption.value = '';\n defaultOption.innerHTML = this.dom.$heading.innerHTML;\n this.dom.$select.appendChild(defaultOption);\n\n this.dom.$links.forEach($link => {\n const $option = document.createElement('option');\n $option.value = $link.hash;\n $option.innerHTML = $link.innerHTML;\n this.dom.$select.appendChild($option);\n });\n\n const {hash} = window.location;\n if (hash) {\n window.location.hash = \"\";\n window.location.hash = hash;\n\n this.dom.$links.forEach($link => {\n $link.classList.remove('toc__list-item-link--active');\n if ($link.href.split('#')[1] === hash.split('#')[1]) {\n $link.classList.add('toc__list-item-link--active');\n }\n });\n }\n }\n\n addListeners() {\n this.dom.$links.forEach($link => {\n $link.addEventListener('click', this.handleLinkClick.bind(this));\n });\n this.dom.$select.addEventListener('change', this.handleDropdownChange.bind(this));\n }\n\n handleDropdownChange() {\n window.location.hash = \"\";\n window.location.hash = this.dom.$select.value;\n }\n\n handleLinkClick(e) {\n const newHash = e.target.href.split('#')[1];\n this.dom.$select.value = `#${newHash}`;\n this.dom.$select.dispatchEvent(new Event('change'));\n\n this.dom.$links.forEach($link => {\n $link.classList.remove('toc__list-item-link--active');\n });\n e.target.classList.add('toc__list-item-link--active');\n }\n}\n\nexport default Module;\n"],"sourceRoot":""}