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B,EAAK,GAC/B,KAAK,G","sources":["webpack://endrun/./app/javascript/app/shortcodes/annotation_2.js"],"sourcesContent":["/**\n * Removes all element-based children, but *not* text nodes.\n *\n * @param {Element} el\n * @returns {Element}\n */\nfunction removeAllNonTextElementChildren(el) {\n while (el.lastElementChild) {\n el.removeChild(el.lastElementChild);\n }\n\n return el;\n}\n\nfunction textWithoutChildren(/** @type {Element} */ el) {\n return removeAllNonTextElementChildren(el.cloneNode(true)).textContent;\n}\n\nfunction annoBodyForSelector(/** @type {Element} */ el) {\n const index = el.getAttribute('data-index');\n const post = el.closest('article');\n\n return post.querySelector(`.post-annotation-2-body[data-index=\"${index}\"]`);\n}\n\nfunction distToTop(/** @type {Element} */ el) {\n const bodyTop = document.body.getBoundingClientRect().top;\n const elTop = el.getBoundingClientRect().top;\n const headerHeight = document\n .querySelector('header')\n .getBoundingClientRect().height;\n\n return elTop - bodyTop + headerHeight;\n}\n\nfunction recalculateOffset(\n /** @type {Element} */ selector,\n /** @type {Element} */ body\n) {\n const selectorOffset = distToTop(selector);\n\n const title = textWithoutChildren(selector);\n const titleElement = body.querySelector('.title');\n titleElement.textContent = title;\n\n if (document.body.classList.contains('mobile')) {\n body.style.position = 'static';\n body.style.top = '0';\n body.style.display = 'block';\n\n return;\n }\n\n window.requestAnimationFrame(() => {\n body.style.position = 'absolute';\n body.style.top = `${selectorOffset}px`;\n body.style.display = 'block';\n });\n\n return body;\n}\n\nfunction buildAnnotations() {\n const annotationBodyElement = document.querySelector(\n '.post-annotation-2-body'\n );\n annotationBodyElement.style.display = 'none';\n\n const annotationSelectorElements = document.querySelectorAll(\n '.post-annotation-2-selector'\n );\n\n annotationSelectorElements.forEach((element) => {\n const body = annoBodyForSelector(element);\n\n recalculateOffset(element, body);\n\n window.requestAnimationFrame(() => {\n recalculateOffset(element, body);\n });\n\n window.addEventListener('tmp_resize', () => {\n recalculateOffset(element, body);\n });\n\n window.addEventListener('tmp_reflow', () => {\n recalculateOffset(element, body);\n });\n\n window.setTimeout(() => {\n recalculateOffset(element, body);\n }, 250);\n\n window.setTimeout(() => {\n recalculateOffset(element, body);\n }, 2500);\n });\n}\n\nbuildAnnotations();\n"],"names":["recalculateOffset","selector","body","selectorOffset","el","bodyTop","document","getBoundingClientRect","top","querySelector","height","distToTop","title","lastElementChild","removeChild","removeAllNonTextElementChildren","cloneNode","textContent","classList","contains","style","position","display","window","requestAnimationFrame","querySelectorAll","forEach","element","index","getAttribute","closest","annoBodyForSelector","addEventListener","setTimeout"],"sourceRoot":""}