{"version":3,"file":"single-image-wide.js","sources":["../../../resources/javascript/entrypoint/single-image-wide.js","../../../resources/javascript/features/content-block/single-image-wide/index.js"],"sourcesContent":["import { initSingleImageWideBlocks } from '../features/content-block/single-image-wide';\nimport { onDOMContentLoaded } from '../util/loaded';\n\nonDOMContentLoaded(initSingleImageWideBlocks);\n","import { getContentBlockListName } from '..';\nimport { getProductElementData, trackProductElementClick, trackProductListImpressions } from '../../tracking/list';\n\n/**\n * Initialise Single Image Wide content blocks.\n *\n * This function must be called on pages that include Single Image Wide\n * content blocks, but no more than once per page load.\n */\nexport const initSingleImageWideBlocks = () => {\n  const observer = new IntersectionObserver((entries) => {\n    for (const entry of entries) {\n      if (!entry.isIntersecting) {\n        continue;\n      }\n\n      // Unobserve, so we only record impressions once per block.\n      observer.unobserve(entry.target);\n\n      // Add click event listeners to each hotspot in the look and get the\n      // tracking data from the DOM.\n      const list = getContentBlockListName(entry.target);\n      const hotspots = [...entry.target.querySelectorAll('.hotspots_position__point')]\n        .sort((a, b) => b.getBoundingClientRect().x < a.getBoundingClientRect().x);\n      const items = [];\n      for (const [position, hotspot] of hotspots.entries()) {\n        items.push(getProductElementData(hotspot, { position }));\n\n        hotspot.addEventListener('click', (e) => {\n          const product = e.target.closest('.hotspots_position__product');\n          if (product) {\n            trackProductElementClick(e, list, { position });\n          }\n        });\n      }\n\n      if (items.length > 0) {\n        trackProductListImpressions({ list, items });\n      }\n    }\n  });\n\n  [...document.querySelectorAll('.quality-promise-singleimage--wide')]\n    .filter(singleImageWide => !!singleImageWide.querySelector('.hotspots_position__points'))\n    .forEach(singleImageWide => observer.observe(singleImageWide));\n};\n"],"names":["onDOMContentLoaded","initSingleImageWideBlocks","observer","IntersectionObserver","entries","entry","isIntersecting","unobserve","target","list","getContentBlockListName","hotspots","querySelectorAll","sort","a","b","getBoundingClientRect","x","items","position","hotspot","push","getProductElementData","addEventListener","e","closest","trackProductElementClick","length","trackProductListImpressions","document","filter","singleImageWide","querySelector","forEach","observe"],"mappings":"yKAGAA,GCMyCC,KACvC,MAAMC,EAAW,IAAIC,sBAAsBC,IACzC,IAAK,MAAMC,KAASD,EAAS,CAC3B,IAAKC,EAAMC,eACT,SAIFJ,EAASK,UAAUF,EAAMG,QAIzB,MAAMC,EAAOC,EAAwBL,EAAMG,QACrCG,EAAW,IAAIN,EAAMG,OAAOI,iBAAiB,8BAChDC,MAAK,CAACC,EAAGC,IAAMA,EAAEC,wBAAwBC,EAAIH,EAAEE,wBAAwBC,IACpEC,EAAQ,GACd,IAAK,MAAOC,EAAUC,KAAYT,EAASP,UACzCc,EAAMG,KAAKC,EAAsBF,EAAS,CAAED,cAE5CC,EAAQG,iBAAiB,SAAUC,IACjBA,EAAEhB,OAAOiB,QAAQ,gCAE/BC,EAAyBF,EAAGf,EAAM,CAAEU,YACrC,IAIDD,EAAMS,OAAS,GACjBC,EAA4B,CAAEnB,OAAMS,SAEvC,KAGH,IAAIW,SAASjB,iBAAiB,uCAC3BkB,QAAOC,KAAqBA,EAAgBC,cAAc,gCAC1DC,SAAQF,GAAmB7B,EAASgC,QAAQH,IAAiB"}