PageSourceSearch

https://francesvalentine.com/cdn/shop/t/684/assets/swym-collections-logic.js?v=151091076956075058011789275715

js francesvalentine.com collected 2026-09-24 19:24:31 UTC 22,074 bytes, 8 lines download raw bytes

1let currentVariantId,productData,arrayOfSwymCollectionsButtons,variantImagesArray,selectedVariant={},globalActionArray=[],globalListArray=[],globalProductsInListArray=[],selectCallBackObj=[],productURL;function customErrorHandling(error){_swat.ui.uiRef.showErrorNotification({message:error})}function customSuccessHandling(success){_swat.ui.uiRef.showSuccessNotification({message:success})}function performListAction(event){let listId=event.target.getAttribute("list-id"),variantInList=event.target.getAttribute("variantExistsInList")==="true";var product={epi:currentVariantId,empi:productData.product.id,du:productURL};function updateGlobalListArray2(){_swat.fetchLists({callbackFn:function(lists){globalListArray=lists,globalListArray.forEach(list=>{let listElement=document.querySelector(`.swym-custom-list-button[data-list-id="${list.lid}"]`);listElement&&(listElement.innerHTML=`${list.lname} (${list.listcontents.length})`)})},errorFn:function(error){console.log("Error while fetching all Lists",error)}})}if(variantInList){let onSuccess=function(deletedProduct){event.target.setAttribute("variantexistsinlist","false"),event.target.innerHTML="Add",updateGlobalListArray2(),generateUpdateMessage()},onError=function(error){console.log("Error while deleting the Product",error)};_swat.deleteFromList(listId,product,onSuccess,onError)}else{let onSuccess=function(addedListItem){event.target.setAttribute("variantexistsinlist","true"),event.target.innerHTML="Remove";let listName=event.target.getAttribute("list-name");updateGlobalListArray2();let updateMessage=`${productData.product.title} has been successfully added to ${listName}`;customSuccessHandling(updateMessage)},onError=function(error){console.log("Error while adding the Product to the List",error)};_swat.addToList(listId,product,onSuccess,onError)}}function onSwymLoadCallback(swat){const currentLanguage=swat.retailerSettings.UI.Language?swat.retailerSettings.UI.Language:"english",swymCollectionsModal=document.getElementById("swym-custom-collections-modal-background"),desktopModalTitle=document.getElementById("swym-custom-modal-title"),multipleListParentContainer=document.getElementById("swym-custom-multiple-list-parent-container"),selectPreferenceText=document.getElementById("swym-custom-select-preference-text"),selectListsText=document.getElementById("swym-custom-select-wishlists-text"),createListGuideText=document.getElementById("swym-list-guide-text"),webpageBody=document.querySelector("body"),modalCloseButton=document.getElementById("swym-custom-modal-close"),mobileModalTitle=document.getElementById("swym-custom-mobile-title"),createListModalTitle=document.getElementById("swym-create-list-title"),variantSelectionContainer=document.getElementById("swym-custom-variant-selector-container"),addToWishlistButton=document.getElementById("swym-custom-add-to-wishlist-button"),isSingleWishlist=!swat.retailerSettings.Wishlist.EnableCollections,listIdContainer=document.getElementById("swym-custom-list-id-container"),createListButton=document.getElementById("swym-custom-create-list-button"),confirmListNameButton=document.getElementById("swym-custom-confirm-list-button"),createListContainer=document.getElementById("swym-custom-backdrop"),cancelListCreationButton=document.getElementById("swym-custom-notconfirm-list-button"),listNameInput=document.getElementById("swym-custom-new-list-name-input"),variantImage=document.getElementById("swym-custom-primary-image"),vendorTitle=document.getElementById("swym-custom-vendor-title"),productTitle=document.getElementById("swym-custom-product-title"),price=document.getElementById("swym-custom-variant-price"),variantTitle=document.getElementById("swym-custom-variant-title"),imgBlobContainer=document.getElementById("swym-custom-image-blob-container"),imageSliderContainer=document.getElementById("swym-custom-images-slide-container"),prevButton=document.getElementById("swym-custom-slide-arrow-prev"),nextButton=document.getElementById("swym-custom-slide-arrow-next"),translationsObject={english:{defaultWishlistTitle:themeSettings.defaultWishlistTitle,desktopModalTitle:themeSettings.desktopModalTitle,addedToSingleList:themeSettings.addedToSingleList,addedToMultipleLists:themeSettings.addedToMultipleLists,selectPreferenceText:themeSettings.selectPreferenceText,selectWishlistText:themeSettings.selectWishlistText,createListButtonText:themeSettings.createListButtonText,createListInputPlaceHolder:themeSettings.createListInputPlaceHolder,addToWishlistTextNoListSelected:themeSettings.addToWishlistTextNoListSelected,addToWishlistTextAddState:themeSettings.addToWishlistTextAddState,addToWishlistTextUpdateState:themeSettings.addToWishlistTextUpdateState,singleWishlistButtonAddText:themeSettings.singleWishlistButtonAddText,singleWishlistButtonRemoveText:themeSettings.singleWishlistButtonRemoveText,createListModalTitle:themeSettings.createListModalTitle,createListGuideText:themeSettings.createListGuideText,confirmNewListButtonText:themeSettings.confirmNewListButtonText,notificationAddText:themeSettings.notificationAddText,notificationRemoveText:themeSettings.notificationRemoveText,notificationUpdateText:themeSettings.notificationUpdateText,listNameError:themeSettings.listNameError,listNameNotUniqueError:themeSettings.listNameNotUniqueError,listLimitErrorMessage:themeSettings.listLimitErrorMessage}},currentLanguageOption=translationsObject[currentLanguage]?translationsObject[currentLanguage]:translationsObject.english,defaultWishlistTitle=currentLanguageOption.defaultWishlistTitle;(function(){desktopModalTitle.textContent=currentLanguageOption.desktopModalTitle,selectPreferenceText.textContent=currentLanguageOption.selectPreferenceText,selectListsText.textContent=currentLanguageOption.selectWishlistText,createListButton.textContent=currentLanguageOption.createListButtonText,createListGuideText.textContent=currentLanguageOption.createListGuideText,createListModalTitle.textContent=currentLanguageOption.createListModalTitle,confirmListNameButton.textContent=currentLanguageOption.confirmNewListButtonText,listNameInput.setAttribute("placeholder",currentLanguageOption.createListInputPlaceHolder)})();function debounce_leading(func,timeout=300){let timer;return(...args)=>{timer||func.apply(this,args),clearTimeout(timer),timer=setTimeout(()=>{timer=void 0},timeout)}}async function persistWishlistButtonsState(){return new Promise((resolve,reject)=>{let onSuccess=function(lists){if(globalListArray=lists,lists.length<1&&isSingleWishlist){let listConfig={lname:"My Wishlist"},onSuccess2=function(newList){updateGlobalListArray()},onError2=function(error){console.log("Error while creating a List",error)};swat.createList(listConfig,onSuccess2,onError2)}
1lists.forEach(list=>{list.listcontents.forEach(product=>{let productId=product.empi,buttonToFill=document.querySelector(`button#swym-collections[data-product-id="${productId}"]`);buttonToFill&&!buttonToFill.classList.contains("swym-added")&&SwymUtils.addClass(buttonToFill,"swym-added")})}),resolve()},onError=function(error){console.error("Error while fetching all Lists",error),reject(error)};swat.fetchLists({callbackFn:onSuccess,errorFn:onError})})}async function handleRemoveFromWishlistButtonState(productId){try{if(await persistWishlistButtonsState(),!globalListArray.some(list=>list.listcontents.some(product=>product.empi===productId))){const buttonToUnFill=document.querySelector(`button#swym-collections[data-product-id="${productId}"]`);buttonToUnFill&&SwymUtils.removeClass(buttonToUnFill,"swym-added")}}catch(error){console.error("An error occurred:",error)}}function handleAddedToWishlistButtonState(productId){let buttonToFill=document.querySelector(`button#swym-collections[data-product-id="${productId}"]`);buttonToFill&&!buttonToFill.classList.contains("swym-added")&&SwymUtils.addClass(buttonToFill,"swym-added")}swat.evtLayer.addEventListener(swat.JSEvents.removedFromWishlist,function(data){let productId=data.detail.d.empi;handleRemoveFromWishlistButtonState(productId)}),swat.evtLayer.addEventListener(swat.JSEvents.addedToWishlist,function(data){let productId=data.detail.d.empi;handleAddedToWishlistButtonState(productId)});function showZoomedView(e){const zoomedView=document.createElement("div"),zoomedImage=new Image;SwymUtils.addClass(zoomedView,"zoomed-image"),zoomedImage.src=e.target.src,zoomedView.appendChild(zoomedImage);const closeButton=document.createElement("button");closeButton.setAttribute("aria-label","Close zoomed image"),closeButton.classList.add("swym-zoomed-image-close-button","close-button"),closeButton.innerHTML="&times;",closeButton.addEventListener("click",()=>{document.body.removeChild(zoomedView)}),zoomedView.appendChild(closeButton),document.body.appendChild(zoomedView),zoomedView.addEventListener("click",event=>{event.target===zoomedView&&document.body.removeChild(zoomedView)})}function addImgBlobClickListener(event){const imgBlobSrc=event.target.getAttribute("src"),allImgBlobs=document.querySelectorAll("#swym-custom-image-blob");variantImage.src=imgBlobSrc,allImgBlobs.forEach(imgBlob=>{imgBlob!==event.target&&imgBlob.classList.remove("selected")}),SwymUtils.toggleClass(event.target,"selected")}function addImageSliderEventListeners(){const slide=document.querySelector(".swym-custom-slider-image");nextButton.addEventListener("click",()=>{const slideWidth=slide.clientWidth;imageSliderContainer.scrollLeft+=slideWidth}),prevButton.addEventListener("click",()=>{const slideWidth=slide.clientWidth;imageSliderContainer.scrollLeft-=slideWidth})}function initializeSwipeableImageSlider(){let imageSlides=[];variantImagesArray.forEach((image,index)=>{const imageSlide=document.createElement("img");imageSlide.src=image.src,imageSlide.ariaLabel=`product-image-${index}`,imageSlide.className="swym-custom-slider-image",imageSlide.width="250",imageSlide.height="250",imageSlide.addEventListener("click",showZoomedView),imageSlides.push(imageSlide),imageSliderContainer.appendChild(imageSlide)}),addImageSliderEventListeners()}function addImageCarousel(){variantImagesArray=productData.product.images,initializeSwipeableImageSlider();const imgTags=variantImagesArray.map((image,index)=>{const imgTag=document.createElement("img");return imgTag.width="24",imgTag.height="24",imgTag.ariaLabel=`Product Secondary Image-${index}`,imgTag.id="swym-custom-image-blob",imgTag.src=image.src,imgTag.addEventListener("click",addImgBlobClickListener),imgTag});imgBlobContainer.innerHTML="",imgBlobContainer.append(...imgTags)}function updateListHandler(){let listInputs=document.querySelectorAll(".swym-custom-list-button");globalActionArray=[],listInputs.forEach(input=>{!input.checked&&input.classList.contains("variant-in-wishlist")?globalActionArray.push({actionType:"remove",listId:`${input.getAttribute("data-list-id")}`}):input.checked&&!input.classList.contains("variant-in-wishlist")&&globalActionArray.push({actionType:"add",listId:`${input.getAttribute("data-list-id")}`})}),toggleAddToWishlistButtonState()}function isVariantPresentInLists(){if(!isSingleWishlist)globalListArray.forEach(list=>{const listId=list.lid,listInput=document.querySelector(`#swym-list-action-btn[list-id="${listId}"]`),variantIsPresent=listInput&&list.listcontents.some(variant=>variant.epi===currentVariantId);listInput&&(listInput.setAttribute("variantexistsinlist",variantIsPresent),variantIsPresent?listInput.innerHTML="Remove":listInput.innerHTML="Add")});else{const variantInWishlist=globalProductsInListArray.some(product=>product.epi===currentVariantId);addToWishlistButton.classList.toggle("variant-in-wishlist",variantInWishlist),addToWishlistButton.textContent=variantInWishlist?currentLanguageOption.singleWishlistButtonRemoveText:currentLanguageOption.addToWishlistTextAddState}toggleAddToWishlistButtonState()}function listSelectionEventlistener(){document.querySelectorAll(".swym-custom-list-button").forEach(input=>{input.addEventListener("click",e=>{e.target.classList.contains("selected")?e.target.classList.remove("selected"):e.target.classList.add("selected"),updateListHandler()})}),isVariantPresentInLists()}function addWishlists(){if(isSingleWishlist)isSingleWishlist&&(swat.fetch(allWishlistedProducts=>{globalProductsInListArray=allWishlistedProducts,isVariantPresentInLists()},error=>
1customErrorHandling(error.description)),toggleVariantData());else{multipleListParentContainer.classList.remove("swym-hide-container"),createListButton.classList.remove("swym-hide-container"),addToWishlistButton.innerHTML="Done";const onSuccess=lists=>{globalListArray=lists;const listItemsHTML=lists.map(list=>{let variantExistsInList=list.listcontents.some(product=>product.epi==currentVariantId);return`
2                    <div id="swym-list-action-wrapper" class="swym-global-font-family">
3                        <div id="${list.lid}-${productData.product.id}" list-name="${list.lname}" aria-label="Select ${list.lname}" class="swym-custom-list-button" type="checkbox" data-list-id="${list.lid}">${list.lname} (${list.listcontents.length})</div>
4                        <button list-id="${list.lid}" list-name="${list.lname}" onclick="performListAction(event)" id="swym-list-action-btn" variantExistsInList="${variantExistsInList}">${variantExistsInList?"Remove":"Add"}</button>
5                    </div>`}).join("");listIdContainer.innerHTML=listItemsHTML,listSelectionEventlistener(),isVariantPresentInLists(),globalListArray.length<1&&createListButton.click(),toggleVariantData()},onError=error=>customErrorHandling(error.description);swat.fetchLists({callbackFn:onSuccess,errorFn:onError})}}function toggleVariantData(){getSelectedVariant(selectCallBackObj);const currentProductTitle=productData.product.title,currentProductVendor=productData.product.vendor,alterNateVariantImages=productData.product.images,currentVariantTitle=selectedVariant.title.replace(/\//g,""),currentVariantPrice=swat.currency+" "+selectedVariant.price,imageId=selectedVariant.image_id;vendorTitle.innerHTML="By: "+currentProductVendor,productTitle.innerHTML=currentProductTitle,variantTitle.innerHTML=currentVariantTitle,price.innerHTML=currentVariantPrice;for(let i=0;i<alterNateVariantImages.length;i++)alterNateVariantImages[i].id==imageId?variantImage.setAttribute("src",alterNateVariantImages[i].src):variantImage.setAttribute("src",productData.product.image.src)}function addProductData(){const product=productData.product;variantImage.src=product.image.src,vendorTitle.innerHTML=product.vendor,productTitle.innerHTML=product.title,mobileModalTitle.textContent=product.title,price.innerHTML=product.variants[0].price,addWishlists(),addImageCarousel(),renderVariantSelectors(productData)}(function(){function showCreateListContainer(){const newWishlistTitle=defaultWishlistTitle+" "+(globalListArray.length+1);globalListArray.length>=10?customErrorHandling(currentLanguageOption.listLimitErrorMessage):(createListContainer.classList.remove("swym-hide-container"),createListButton.setAttribute("disabled",!0),listNameInput.value=newWishlistTitle,listNameInput.select())}function hideCreateListContainer(){createListContainer.classList.add("swym-hide-container"),createListButton.removeAttribute("disabled")}createListButton.addEventListener("click",showCreateListContainer),cancelListCreationButton.addEventListener("click",hideCreateListContainer),createListContainer.addEventListener("click",e=>{e.target===createListContainer&&hideCreateListContainer()})})(),(function(){confirmListNameButton.addEventListener("click",()=>{const listName=listNameInput.value.trim();if(listName.length<3||listName.length>50)customErrorHandling(currentLanguageOption.listNameError),resetListNameInput();else if(isListNameAlreadyExists(listName)){const errorMessage=`${listName} ${currentLanguageOption.listNameNotUniqueError}`;customErrorHandling(errorMessage),resetListNameInput()}else createList(listName)});function resetListNameInput(){listNameInput.value="",listNameInput.focus(),listNameInput.select()}function isListNameAlreadyExists(name){return globalListArray.some(list=>list.lname===name)}function createList(listName){const listConfig={lname:listName};swat.createList(listConfig,newList=>{addWishlists(),createListContainer.classList.add("swym-hide-container"),createListButton.removeAttribute("disabled")},error=>customErrorHandling(error.description))}})();function toggleAddToWishlistButtonState(){if(!isSingleWishlist&&globalActionArray.length!==0){const hasRemoveAction=globalActionArray.some(action=>action.actionType==="remove");addToWishlistButton.removeAttribute("disabled"),addToWishlistButton.textContent=hasRemoveAction?currentLanguageOption.addToWishlistTextUpdateState:currentLanguageOption.addToWishlistTextAddState}}function updateVariantInLists(){const product={epi:currentVariantId,empi:productData.product.id,du:productURL};isSingleWishlist?handleSingleWishlist(product):closeCollectionsModal(),closeCollectionsModal()}function handleSingleWishlist(product){let lid=globalListArray[0].lid,onSuccess=function(addedListItem){},onError=function(error){console.log("Error while adding the Product to the List",error)};if(addToWishlistButton.classList.contains("variant-in-wishlist")){swat.deleteFromList(lid,product,onSuccess,onError);const updateMessage=`${productTitle.textContent} ${variantTitle.textContent} ${currentLanguageOption.notificationRemoveText}`;customSuccessHandling(updateMessage)}else{swat.addToList(lid,product,onSuccess,onError);const updateMessage=`${productTitle.textContent} ${variantTitle.textContent} ${currentLanguageOption.notificationAddText}`;customSuccessHandling(updateMessage)}}function convertObjectToString(selectCallBackObj2){return Object.values(selectCallBackObj2).join(" / ")}function getSelectedVariant(selectCallBackObj2){globalActionArray=[];const variants=productData.product.variants;let variantComboUnavailable=!1;
5variants.forEach(variant=>{convertObjectToString(selectCallBackObj2)==variant.title&&(variantComboUnavailable=!0,selectedVariant=variant,currentVariantId=variant.id)}),variantComboUnavailable?(addToWishlistButton.removeAttribute("disabled"),addToWishlistButton.textContent="Done"):(addToWishlistButton.setAttribute("disabled",!0),addToWishlistButton.textContent="Combination Unavailable"),isVariantPresentInLists()}function handleRadioButtonClick(event){const selectedValue=event.target.value,optionIndex=event.currentTarget.getAttribute("optionIndex");selectCallBackObj={...selectCallBackObj,[optionIndex]:selectedValue},event.currentTarget.parentNode.querySelectorAll(`label[for="${event.target.id}"]`).forEach(label=>{label.classList.add("selected")}),event.currentTarget.parentNode.querySelectorAll(`input[type="radio"]:not([value="${selectedValue}"])`).forEach(radio=>{event.currentTarget.parentNode.querySelectorAll(`label[for="${radio.id}"]`).forEach(label=>{label.classList.remove("selected")})}),toggleVariantData()}function createRadioGroup(option,optionIndex){const variantOptions=option.values.map(value=>`<input style="display: none;" selected="${value==selectedVariant[`option${optionIndex+1}`]}" id="${option.name}-${value}" type="radio" name="${option.name}" optionIndex="${optionIndex}" value="${value}" aria-label="${option.name} ${value}"></input>
6                        <label class="swym-filter-labels" for="${option.name}-${value}">${value}</label>`).join(""),radioGroup=document.createElement("div");radioGroup.setAttribute("class",`${option.name} swym-filter-option-name`),radioGroup.innerHTML=`<div id="swymOptionName" selected value="${option.name}">${option.name}</div>
7                                  <div class="swym-radio-buttons-container">${variantOptions}</div>`;const radioButtons=radioGroup.querySelectorAll(`[name="${option.name}"]`);for(let i=0;i<radioButtons.length;i++)radioButtons[i].addEventListener("click",function(event){handleRadioButtonClick(event,productData)});return radioGroup}function renderVariantSelectors(){const variantSelectors=productData.product.options.map((option,optionIndex)=>createRadioGroup(option,optionIndex));variantSelectionContainer.innerHTML="",variantSelectors.forEach(variantSelector=>{variantSelectionContainer.append(variantSelector)}),variantSelectors.forEach(variantSelector=>{const radioButtons=variantSelector.querySelectorAll('input[type="radio"]');radioButtons.length>0&&radioButtons[0].click()})}function closeCollectionsModal(){selectCallBackObj={},swymCollectionsModal.classList.add("swym-hide-container"),webpageBody.classList.remove("swym-modal-active"),imageSliderContainer.innerHTML="",variantSelectionContainer.innerHTML="",imgBlobContainer.innerHTML="",listIdContainer.innerHTML=""}function openCollectionsModal(){addProductData(productData),swymCollectionsModal.classList.remove("swym-hide-container"),variantImage.addEventListener("click",showZoomedView),webpageBody.classList.add("swym-modal-active"),globalActionArray=[],window.addEventListener("click",event=>{event.target===swymCollectionsModal&&closeCollectionsModal()}),imageSliderContainer.scrollLeft=0}function fetchProductDetails(event){productURL=event.currentTarget.getAttribute("data-product-url").split("?")[0];const shopifyProductEndpoint=productURL+".json";fetch(shopifyProductEndpoint).then(res=>res.json()).then(productJson=>{productData=productJson,selectedVariant=productData.product.variants[0],openCollectionsModal()})}function addEventListeners(){if(arrayOfSwymCollectionsButtons=document.querySelectorAll("#swym-collections"),arrayOfSwymCollectionsButtons)for(let i=0;i<arrayOfSwymCollectionsButtons.length;i++)arrayOfSwymCollectionsButtons[i].addEventListener("click",debounce_leading(fetchProductDetails,500)),SwymUtils.addClass(arrayOfSwymCollectionsButtons[i],"swym-custom-loaded");modalCloseButton.addEventListener("click",closeCollectionsModal),addToWishlistButton.addEventListener("click",debounce_leading(updateVariantInLists,500)),persistWishlistButtonsState()}addEventListeners()}window.SwymCallbacks||(window.SwymCallbacks=[]),window.SwymCallbacks.push(onSwymLoadCallback);
8//# sourceMappingURL=/cdn/shop/t/684/assets/swym-collections-logic.js.map?v=151091076956075058011789275715

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.