Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejs
<script>
  const items = [];
  
  window.addEventListener('message', (event) => {
      if (event.data && event.data.eventName === 'iframeLoaded') {
   
      window.frames.wizartFittingRoom.postMessage({

             eventName: 'setFavoritesStore',

             payload: items,
   
      }, '*');
 
    } else if (event.data && event.data.eventName === 'addFavorite') {
 
        items.push(event.data.payload.item.vendor_code);
 
        window.frames.wizartFittingRoom.postMessage({
              eventName: 'setFavoritesStore',
   
          payload: items,

         }, '*');

     } else if (event.data && event.data.eventName === 'removeFavorite') {
          const foundIndex = items.findIndex(
 
            (item) => item === event.data.payload.item.vendor_code,
   
      );

         if (foundIndex !== -1) {
     
        items.splice(foundIndex, 1);
 
            window.frames.wizartFittingRoom.postMessage({
         
            eventName: 'setFavoritesStore',

                     payload: items,
     
            },
 
                '*',
     
        );
 
        }
 
    }
  }, false);
</script>