{"version":3,"file":"blocks.js","sources":["../../resources/modern-javascript/blocks.js"],"sourcesContent":["import { initialiseSwiper } from './swiper/swiper.js';\nimport { initShowroomFinders } from './showrooms/showroomFinder.js';\nimport { RecentSwatches } from './swatch/RecentSwatches.js';\nimport { handleFragmentInit } from './pdp/fragments';\nimport { replaceElementHTML } from './pdp/replace';\n\ninitShowroomFinders();\n\nconst initRecentSwatches = () => {\n  const recentSwatchContainer = document.querySelector(\n    '[data-recent-swatches]',\n  );\n\n  if (!recentSwatchContainer) {\n    return;\n  }\n\n  const recentSwatches = new RecentSwatches();\n  const swatchGridModifierClasses = ['swiper-wrapper', 'swatch-grid--block'];\n\n  recentSwatches.renderRecentSwatches(swatchGridModifierClasses);\n};\n\ninitRecentSwatches();\n\nhandleFragmentInit(({ replace }) => {\n  if (replace?.crossSell) {\n    replaceElementHTML('.block--cross-sells', replace.crossSell);\n  }\n\n  if (replace?.range) {\n    replaceElementHTML('.block--range', replace.range);\n  }\n\n  const carousels = document.querySelectorAll('.block .swiper');\n  // This is reasonable as we exit out if a swpier alreaddy exists. Though perhaps not ideal.\n  for (const carousel of carousels ?? []) {\n\n    initialiseSwiper(carousel);\n  }\n});\n\nconst initReadMore = () => {\n  const readMoreContainers = document.querySelectorAll('.block__content .read-more');\n\n  if (!readMoreContainers) {\n    return;\n  }\n\n  readMoreContainers.forEach((container) => {\n    const button = container.querySelector('.js-read_more');\n\n    if (!button) {\n      return;\n    }\n\n    button.addEventListener('click', () => {\n      container.classList.toggle('read-more--active');\n      \n      if (container.classList.contains('read-more--active')) {\n        button.textContent = 'Read less';\n      } else {\n        button.textContent = '... Read more';\n      }\n    });\n  });\n}\n\ninitReadMore();\n"],"names":["initShowroomFinders","initRecentSwatches","document","querySelector","RecentSwatches","renderRecentSwatches","handleFragmentInit","replace","crossSell","replaceElementHTML","range","carousels","querySelectorAll","carousel","initialiseSwiper","initReadMore","readMoreContainers","forEach","container","button","addEventListener","classList","toggle","contains","textContent"],"mappings":"8bAMAA,IAE2BC,MAKzB,IAJ8BC,SAASC,cACrC,0BAIA,QAGqB,IAAIC,GAGZC,qBAFmB,CAAC,iBAAkB,sBAES,EAGhEJ,GAEAK,GAAmB,EAAGC,cACT,MAAPA,GAAAA,EAASC,WACXC,EAAmB,sBAAuBF,EAAQC,WAGzC,MAAPD,GAAAA,EAASG,OACXD,EAAmB,gBAAiBF,EAAQG,OAG9C,MAAMC,EAAYT,SAASU,iBAAiB,kBAE5C,IAAK,MAAMC,WAAYF,EAAAA,EAAa,GAElCG,EAAiBD,EAClB,IAGkBE,MACnB,MAAMC,EAAqBd,SAASU,iBAAiB,8BAEhDI,GAILA,EAAmBC,SAASC,IAC1B,MAAMC,EAASD,EAAUf,cAAc,iBAElCgB,GAILA,EAAOC,iBAAiB,SAAS,KAC/BF,EAAUG,UAAUC,OAAO,qBAEvBJ,EAAUG,UAAUE,SAAS,qBAC/BJ,EAAOK,YAAc,YAErBL,EAAOK,YAAc,eACtB,GACD,GACF,EAGJT"}