{"version":3,"sources":["mobile-read-more.js"],"names":["hero","document","querySelector","classList","contains","viewport","Viewport","AndrewMartin","breakpoints","toggleReadMore","_hero$querySelector","text","addEventListener","e","matches","stopPropagation","readMore","add","parentElement","remove","isClamped","element","scrollHeight","clientHeight","checkClamping","querySelectorAll","forEach","textEl","style","display","resize"],"mappings":"AAKA,IAAMA,KAAOC,SAASC,cAAc,SAEpC,IAA8C,IAA1CF,KAAKG,UAAUC,SAAS,cAAyB,CACjD,IAAMC,SAAW,IAAIC,SAASC,aAAaC,aAQrCC,eAAiB,WAAM,IAAAC,EACnBC,EAAwC,QAApCD,EAAGV,KAAKE,cAAc,sBAAc,IAAAQ,EAAAA,EAAIV,KAAKE,cAAc,uBAEhES,GAILA,EAAKC,iBAAiB,QAAS,SAACC,GAG5B,GAFiBR,SAASS,QAAQ,UAElC,CAIAD,EAAEE,kBAEF,IAAMC,EAAWL,EAAKT,cAAc,oBAC/BS,EAAKR,UAAUC,SAAS,cACzBO,EAAKR,UAAUc,IAAI,YACnBD,EAASE,cAAcC,SAP3B,CASJ,EACJ,EAQMC,UAAY,SAACC,GACf,OAAOA,EAAQC,aAAeD,EAAQE,YAC1C,EAMMC,cAAgB,WAClBxB,KAAKyB,iBAAiB,eAAeC,QAAQ,SAAAC,GACzC,IAAMX,EAAWW,EAAOzB,cAAc,cAClCc,IACII,UAAUO,GACVX,EAASY,MAAMC,QAAU,SAEzBb,EAASY,MAAMC,QAAU,OAGrC,EACJ,EAEAxB,SAASyB,OAAQ,WACbN,eACJ,GAEAf,iBACAe,eACJ","file":"../../javascript/mobile-read-more.js","sourcesContent":["/**\n * mobile-read-more.js\n *\n * Handles the \"Read more\" functionality for mobile devices on hero text sections.\n */\nconst hero = document.querySelector('.hero');\n\nif (hero.classList.contains('hero--home') === false) {\n    const viewport = new Viewport(AndrewMartin.breakpoints);\n\n\n    /**\n     * Attaches a click event listener to the hero text element on mobile devices (window width <= 550).\n     * When clicked, expands the text and removes the \"read more\" element.\n     * Does nothing if not on mobile or if the hero text element is not found.\n     */\n    const toggleReadMore = () => {\n        const text = hero.querySelector('.hero__text') ?? hero.querySelector('.hero__text--mobile');\n\n        if (!text) {\n            return;\n        }\n\n        text.addEventListener('click', (e) => {\n            const isMobile = viewport.matches('mobile');\n\n            if (!isMobile) {\n                return;\n            }\n\n            e.stopPropagation();\n\n            const readMore = text.querySelector('.read-more__text');\n            if (!text.classList.contains('expanded')) {\n                text.classList.add('expanded');\n                readMore.parentElement.remove();\n            }\n        });\n    }\n\n    /**\n     * Checks if the text element is clamped (i.e., overflowing its container).\n     *\n     * @param {*} element\n     * @returns {boolean} True if clamped, false otherwise.\n     */\n    const isClamped = (element) => {\n        return element.scrollHeight > element.clientHeight;\n    }\n\n    /**\n     * Checks all hero text elements for clamping and shows/hides the \"read more\" element accordingly.\n     * Also called on window resize to adjust visibility.\n     */\n    const checkClamping = () => {\n        hero.querySelectorAll('.hero__text').forEach(textEl => {\n            const readMore = textEl.querySelector('.read-more');\n            if (readMore) {\n                if (isClamped(textEl)) {\n                    readMore.style.display = 'inline';\n                } else {\n                    readMore.style.display = 'none';\n                }\n            }\n        });\n    }\n\n    viewport.resize( () => {\n        checkClamping();\n    });\n\n    toggleReadMore();\n    checkClamping();\n}\n"],"sourceRoot":"../../../../resources/javascript"}