blob: a31fcd01aa47ecefbfe93895fb7997b059dccc3f [file] [log] [blame]
{
"version": 3,
"sources": ["unit_fixed_header.ts"],
"sourcesContent": ["/*!\n * @license\n * Copyright 2019-2020 The Go Authors. All rights reserved.\n * Use of this source code is governed by a BSD-style\n * license that can be found in the LICENSE file.\n */\n\n/**\n * Shows a fixed element when a separate element begins to go out of view.\n */\nclass FixedHeaderController {\n private intersectionObserver: IntersectionObserver;\n\n /**\n * @param el The element to observe to determine whether to show the fixed element.\n * @param fixedEl The element to show when the other begins to go out of view.\n */\n constructor(private el: Element, private fixedEl: Element) {\n if (!el || !fixedEl) {\n throw new Error('Must provide sentinel and fixed elements to constructor.');\n }\n\n this.intersectionObserver = new IntersectionObserver(this.intersectionObserverCallback, {\n threshold: 1.0,\n });\n this.intersectionObserver.observe(this.el);\n\n // Fixed positioning on Safari iOS is very broken, and without this hack,\n // focusing on the overflow menu will cause all content to scroll.\n // The -webkit-overflow-scroll CSS property is only available on mobile\n // Safari, so check for it and set the appropriate style to fix this.\n if (\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (window.getComputedStyle(document.body) as any)['-webkit-overflow-scrolling'] !== undefined\n ) {\n [document.documentElement, document.body].forEach(el => {\n el.style.overflow = 'auto';\n });\n }\n }\n\n private intersectionObserverCallback: IntersectionObserverCallback = entries => {\n entries.forEach(entry => {\n if (entry.isIntersecting) {\n this.fixedEl.classList.remove('UnitFixedHeader--visible');\n } else {\n this.fixedEl.classList.add('UnitFixedHeader--visible');\n }\n });\n };\n}\n\nconst fixedHeaderSentinel = document.querySelector('.js-fixedHeaderSentinel');\nconst fixedHeader = document.querySelector('.js-fixedHeader');\nif (fixedHeaderSentinel && fixedHeader) {\n new FixedHeaderController(fixedHeaderSentinel, fixedHeader);\n}\n\nconst overflowSelect = document.querySelector<HTMLSelectElement>('.js-overflowSelect');\nif (overflowSelect) {\n overflowSelect.addEventListener('change', e => {\n window.location.href = (e.target as HTMLSelectElement).value;\n });\n}\n"],
"mappings": "AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,GAUA,2BAA4B,CAO1B,YAAoB,EAAqB,EAAkB,CAAvC,UAAqB,eAwBjC,kCAA6D,GAAW,CAC9E,EAAQ,QAAQ,GAAS,CACvB,AAAI,EAAM,eACR,KAAK,QAAQ,UAAU,OAAO,4BAE9B,KAAK,QAAQ,UAAU,IAAI,+BA5B/B,GAAI,CAAC,GAAM,CAAC,EACV,KAAM,IAAI,OAAM,4DAGlB,KAAK,qBAAuB,GAAI,sBAAqB,KAAK,6BAA8B,CACtF,UAAW,IAEb,KAAK,qBAAqB,QAAQ,KAAK,IAQpC,OAAO,iBAAiB,SAAS,MAAc,gCAAkC,QAElF,CAAC,SAAS,gBAAiB,SAAS,MAAM,QAAQ,GAAM,CACtD,EAAG,MAAM,SAAW,UAgB5B,KAAM,qBAAsB,SAAS,cAAc,2BAC7C,YAAc,SAAS,cAAc,mBAC3C,AAAI,qBAAuB,aACzB,GAAI,uBAAsB,oBAAqB,aAGjD,KAAM,gBAAiB,SAAS,cAAiC,sBACjE,AAAI,gBACF,eAAe,iBAAiB,SAAU,GAAK,CAC7C,OAAO,SAAS,KAAQ,EAAE,OAA6B",
"names": []
}