{"version":3,"sources":["keyLocationsMapBlock.js"],"names":["keyLocationsMapBlock","checkLinks","el","querySelectorAll","forEach","locationLink","locationLinkUrl","getAttribute","startsWith","locationTargetElement","document","querySelector","remove","addEventListener","e","preventDefault","scrollIntoView","behavior","block","inline","checkLocationElement","window","history","pushState","tagName","toLowerCase","open","getPlotLocation","multiplier","map","mapHeight","clientHeight","mapWidth","clientWidth","plot","x","dataset","plotX","y","plotY","calcTopPosition","calcRightPosition","setAttribute","drawLines","loopPlots","hasAttribute","plots","svg","createElementNS","appendChild","firstChild","removeChild","plotCoordinates","plotId","parseFloat","calcLeftPosition","push","i","length","line","finalLine","bindPoints","targets","target","bounding","getBoundingClientRect","top","left","bottom","innerHeight","documentElement","right","innerWidth","checkLocationVisibility","handleDocumentClick","classList","add","documentClickListener","event","contains","removeEventListener","initBlock","setTimeout","ControlBinders","register"],"mappings":"AAAA,MAAMA,qBAAuB,MAC3B,MAaMC,EAAaC,IACjBA,EAAGC,iBAAiB,yBAAyBC,QAAQC,IACnD,MAAMC,EAAkBD,EAAaE,aAAa,QAElD,GAAID,EAAgBE,WAAW,KAAM,CACnC,MAAMC,EAAwBC,SAASC,cAAcL,GAEvB,OAA1BG,EACFJ,EAAaO,SAEbP,EAAaQ,iBAAiB,QAASC,IACrCA,EAAEC,iBACFN,EAAsBO,eAAe,CACnCC,SAAU,SACVC,MAAO,SACPC,OAAQ,WAEVC,EAAqBX,GACrBY,OAAOC,QAAQC,UAAU,KAAM,KAAMjB,SAOzCc,EAAuBlB,IACM,YAA7BA,EAAGsB,QAAQC,gBACRvB,EAAGwB,OACNxB,EAAGwB,MAAO,KAKVC,EAAkB,CAACzB,EAAI0B,KAC3B,MACMC,EADa3B,EAAGS,cAAc,cACbA,cAAc,OACrC,IAAImB,EAAYD,EAAIE,aAAeH,EAC/BI,EAAWH,EAAII,YACnB/B,EAAGC,iBAAiB,eAAeC,QAAQ8B,IACzC,MAAMC,EAAID,EAAKE,QAAQC,MACjBC,EAAIJ,EA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AAc,KAClCiD,EAAQ1D,QAAQ2D,IACdA,EAAOY,UAAU/D,OAAO,8DAG5BkD,EAAQ1D,QAAQ2D,IACdA,EAAOlD,iBAAiB,aAAc,IAAMqB,EAAKyC,UAAUC,IAAI,8CAC/Db,EAAOlD,iBAAiB,aAAc,IAAMqB,EAAKyC,UAAU/D,OAAO,gDAGpE,MAAM8D,EAAsB,KAC1B,MAAMG,EAAwBC,IAC5BhB,EAAQ1D,QAAQ2D,IACTA,EAAOgB,SAASD,EAAMf,SAAY7B,EAAK6C,SAASD,EAAMf,UACzDA,EAAOY,UAAU/D,OAAO,0DACxBF,SAASsE,oBAAoB,QAASH,OAK5CnE,SAASG,iBAAiB,QAASgE,QAM3C,MAAO,CACLI,UA1LgB/E,IAChBgF,WAAW,KACTvD,EAAgBzB,EAAI,GACpByC,EAAUzC,GACV2D,EAAW3D,GACXD,EAAWC,IACV,IACHmB,OAAOR,iBAAiB,SAAU,KAChCc,EAAgBzB,EAAI,GACpByC,EAAUzC,QAVa,GA+L7BiF,eAAeC,SAAS,iCAAkClF,GAAMF,qBAAqBiF,UAAU/E","sourcesContent":["const keyLocationsMapBlock = (() => {\r\n\r\n const initBlock = (el) => {\r\n setTimeout(()=>{\r\n getPlotLocation(el, 1);\r\n drawLines(el);\r\n bindPoints(el);\r\n checkLinks(el); \r\n }, 60)\r\n window.addEventListener('resize', () => {\r\n getPlotLocation(el, 1);\r\n drawLines(el);\r\n });\r\n };\r\n \r\n const checkLinks = (el) => {\r\n el.querySelectorAll(\"[data-key-location] a\").forEach(locationLink =>{\r\n const locationLinkUrl = locationLink.getAttribute(\"href\");\r\n if (locationLinkUrl.startsWith('#')) {\r\n\r\n const locationTargetElement = document.querySelector(locationLinkUrl);\r\n if (locationTargetElement === null) {\r\n locationLink.remove()\r\n } else {\r\n locationLink.addEventListener(\"click\", e => {\r\n e.preventDefault();\r\n locationTargetElement.scrollIntoView({behavior: \"smooth\", block: \"center\", inline: \"center\"});\r\n checkLocationElement(locationTargetElement);\r\n window.history.pushState(null, null, locationLinkUrl);\r\n })\r\n }\r\n }\r\n \r\n })\r\n }\r\n \r\n const checkLocationElement = (el) =>{\r\n if (el.tagName.toLowerCase() === \"details\") {\r\n if (!el.open) {\r\n el.open = true;\r\n }\r\n }\r\n }\r\n\r\n const getPlotLocation = (el, multiplier) => {\r\n const mapWrapper = el.querySelector('[data-map]');\r\n const map = mapWrapper.querySelector('img');\r\n let mapHeight = (map.clientHeight * multiplier);\r\n let mapWidth = map.clientWidth;\r\n el.querySelectorAll('[data-plot]').forEach(plot => {\r\n const x = plot.dataset.plotX;\r\n const y = plot.dataset.plotY;\r\n const calcTopPosition = mapHeight * y;\r\n const calcRightPosition = mapWidth * (1 - x);\r\n plot.setAttribute('style', `top:${calcTopPosition}px; right:${calcRightPosition}px`);\r\n });\r\n };\r\n\r\n const drawLines = (el) => {\r\n let loopPlots = el.hasAttribute(\"data-loop-plots\");\r\n const plots = el.querySelectorAll('.key-locations-map-block__map__plot');\r\n let svg = el.querySelector('.key-locations-map-block__map__lines');\r\n\r\n if (svg) {\r\n svg.remove();\r\n }\r\n\r\n svg = document.createElementNS(\"http://www.w3.org/2000/svg\", \"svg\");\r\n svg.setAttribute(\"class\", \"key-locations-map-block__map__lines\");\r\n svg.setAttribute(\"width\", el.querySelector('img').clientWidth);\r\n svg.setAttribute(\"height\", el.querySelector('img').clientHeight);\r\n el.querySelector('.key-locations-map-block__map__media').appendChild(svg);\r\n\r\n // Clear previous lines\r\n while (svg.firstChild) {\r\n svg.removeChild(svg.firstChild);\r\n }\r\n\r\n const plotCoordinates = [];\r\n const mapWrapper = el.querySelector('[data-map]');\r\n const map = mapWrapper.querySelector('img');\r\n let mapHeight = map.clientHeight;\r\n let mapWidth = map.clientWidth;\r\n\r\n plots.forEach(plot => {\r\n if (plot.dataset.plotId !== \"0\") {\r\n const x = parseFloat(plot.dataset.plotX);\r\n const y = parseFloat(plot.dataset.plotY);\r\n const calcTopPosition = mapHeight * y;\r\n const calcLeftPosition = mapWidth * x;\r\n plotCoordinates.push({ x: calcLeftPosition, y: calcTopPosition });\r\n } else {\r\n plotCoordinates.push(null); // Maintain the index with a null value\r\n }\r\n });\r\n\r\n for (let i = 0; i < plotCoordinates.length - 1; i++) {\r\n if (plotCoordinates[i] && plotCoordinates[i + 1]) { // Only draw line if both points are not null\r\n const line = document.createElementNS(\"http://www.w3.org/2000/svg\", \"line\");\r\n line.setAttribute(\"x1\", plotCoordinates[i].x);\r\n line.setAttribute(\"y1\", plotCoordinates[i].y);\r\n line.setAttribute(\"x2\", plotCoordinates[i + 1].x);\r\n line.setAttribute(\"y2\", plotCoordinates[i + 1].y);\r\n line.setAttribute(\"stroke\", \"black\");\r\n line.setAttribute(\"stroke-width\", \"2\");\r\n line.setAttribute(\"stroke-dasharray\", \"4\"); // Adding the dashed line style\r\n svg.appendChild(line);\r\n }\r\n }\r\n \r\n // Close loop\r\n if (loopPlots && plotCoordinates.length > 1 && plotCoordinates[0] && plotCoordinates[plotCoordinates.length - 1]) {\r\n const finalLine = document.createElementNS(\"http://www.w3.org/2000/svg\", \"line\");\r\n finalLine.setAttribute(\"x1\", plotCoordinates[plotCoordinates.length - 1].x);\r\n finalLine.setAttribute(\"y1\", plotCoordinates[plotCoordinates.length - 1].y);\r\n finalLine.setAttribute(\"x2\", plotCoordinates[0].x);\r\n finalLine.setAttribute(\"y2\", plotCoordinates[0].y);\r\n finalLine.setAttribute(\"stroke\", \"black\");\r\n finalLine.setAttribute(\"stroke-width\", \"2\");\r\n finalLine.setAttribute(\"stroke-dasharray\", \"4\"); // Adding the dashed line style\r\n svg.appendChild(finalLine);\r\n }\r\n };\r\n \r\n const checkLocationVisibility = (target) =>{\r\n const bounding = target.getBoundingClientRect();\r\n // If not in viewport\r\n if (\r\n bounding.top < 0 ||\r\n bounding.left < 0 ||\r\n bounding.bottom > (window.innerHeight || document.documentElement.clientHeight) ||\r\n bounding.right > (window.innerWidth || document.documentElement.clientWidth)\r\n ) {\r\n target.scrollIntoView({ behavior: \"smooth\", block: \"center\", inline: \"center\" });\r\n }\r\n }\r\n\r\n \r\n const bindPoints = (el) =>{\r\n \r\n el.querySelectorAll('[data-plot]').forEach(plot => {\r\n const plotId = plot.dataset.plotId;\r\n const targets = el.querySelectorAll(`[data-key-location=\"${plotId}\"]`);\r\n if(targets.length > 0){\r\n plot.addEventListener(\"click\", ()=>\r\n {\r\n targets.forEach(target =>{\r\n checkLocationVisibility(target);\r\n })\r\n handleDocumentClick();\r\n });\r\n \r\n plot.addEventListener(\"mouseenter\", ()=> {\r\n targets.forEach(target => {\r\n target.classList.add(\"key-locations-map-block__locations__items__item--hover\");\r\n })\r\n })\r\n plot.addEventListener(\"mouseleave\", ()=> {\r\n targets.forEach(target =>{\r\n target.classList.remove(\"key-locations-map-block__locations__items__item--hover\");\r\n })\r\n })\r\n\r\n targets.forEach(target => {\r\n target.addEventListener(\"mouseenter\", () => plot.classList.add(\"key-locations-map-block__map__plot--hover\"));\r\n target.addEventListener(\"mouseleave\", () => plot.classList.remove(\"key-locations-map-block__map__plot--hover\"));\r\n })\r\n\r\n const handleDocumentClick = () => {\r\n const documentClickListener = (event) => {\r\n targets.forEach(target => {\r\n if (!target.contains(event.target) && !plot.contains(event.target)) {\r\n target.classList.remove(\"key-locations-map-block__locations__items__item--hover\");\r\n document.removeEventListener(\"click\", documentClickListener);\r\n }\r\n })\r\n };\r\n document.addEventListener(\"click\", documentClickListener);\r\n };\r\n }\r\n \r\n })\r\n }\r\n return {initBlock}\r\n})();\r\n\r\nControlBinders.register('[data-key-locations-map-block]', el => keyLocationsMapBlock.initBlock(el));"],"file":"keyLocationsMapBlock-min.js"}