luv-assets 1.1.13 → 1.1.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/js/cart.min.js +1 -0
- package/dist/js/pay.min.js +1 -0
- package/dist/js/product.min.js +1 -1
- package/package.json +1 -1
- package/readme.txt +8 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function updateQty(item_id,up_type,qty=null){var data={item_id:item_id,up_type:up_type};if(qty!==null)data.qty=qty;data[csrfName]=csrfVal;$.ajax({url:updateCartInfoUrl,type:"POST",dataType:"json",data:data,success:function(response){if(response.status==="success"){if(up_type==="remove"){$('.cart-item-js[data-item-id="'+item_id+'"]').fadeOut(300,function(){$(this).remove();updateCheckoutButton()})}else{updateCheckoutButton()}}else{alert(response.message||"Update failed")}},error:function(){alert("Network error")}})}function updateCheckoutButton(){const $checkedItems=$(".item-checkbox-js:checked");const checkedCount=$checkedItems.length;let total=0;$checkedItems.each(function(){const price=parseFloat($(this).data("price"))||0;const qty=parseInt($("#qty-js-"+$(this).val()).val())||0;total+=price*qty});$("#total-price-js").text(total.toFixed(2));$("#checkout-count-js").text(checkedCount);$("#btn-checkout-js").prop("disabled",checkedCount===0);const allChecked=$(".item-checkbox-js").length>0&&$checkedItems.length===$(".item-checkbox-js").length;$("#check-all-js").prop("checked",allChecked)}function paypalBuynowCreatePayment(){if(!paypal_client_id)return;$("#paypal-button-container").empty();var fundingSources=[paypal.FUNDING.PAYPAL];fundingSources.forEach(function(fundingSource){var button=paypal.Buttons({fundingSource:fundingSource,style:{height:38,label:"buynow"},onClick:function(){const total=parseFloat($("#total-price-js").text());if(isNaN(total)||total<=0){showToast(translations.itemRequired,"#toast-js");return false}return true},createOrder:function(data,actions){return fetch(paypalCreateOrderUrl,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({[csrfName]:csrfVal})}).then(function(res){return res.json()}).then(function(order){if(order.id==="-1")throw new Error(order.message);return order.id})},onCancel:data=>{},onApprove:function(data,actions){return fetch(paypalCaptureOrderUrl,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(Object.assign(data,{[csrfName]:csrfVal}))}).then(function(res){return res.json()}).then(function(orderData){if(orderData.order_sn==="-1"){if(orderData.error_issue==="INSTRUMENT_DECLINED"){return actions.restart()}throw new Error(orderData.message)}window.location.href=paypalFinishOrderUrl+"?order_sn="+encodeURIComponent(orderData.order_sn)})},onError:function(err){alert(err.toString())}});if(button.isEligible()){button.render("#paypal-button-container")}})}$(document).ready(function(){$(document).on("change",".item-checkbox-js",function(){var item_id=$(this).val();var checked=$(this).is(":checked")?1:0;var data={item_id:item_id,checked:checked};data[csrfName]=csrfVal;$.ajax({url:selectOneProductUrl,type:"POST",dataType:"json",data:data,success:function(response){if(response.status==="success"){updateCheckoutButton()}}})});$("#check-all-js").on("change",function(){var checked=$(this).is(":checked")?1:0;var data={checked:checked};data[csrfName]=csrfVal;$.ajax({url:selectAllProductUrl,type:"POST",dataType:"json",data:data,success:function(response){if(response.status==="success"){$(".item-checkbox-js").prop("checked",checked);updateCheckoutButton()}}})});$(document).on("click",".item-plus-js",function(){var $input=$("#qty-js-"+$(this).data("item-id"));var qty=parseInt($input.val())||1;if(qty<max_qty){$input.val(qty+1);updateQty($(this).data("item-id"),"add_one")}});$(document).on("click",".item-minus-js",function(){var $input=$("#qty-js-"+$(this).data("item-id"));var qty=parseInt($input.val())||1;if(qty>1){$input.val(qty-1);updateQty($(this).data("item-id"),"less_one")}});$(document).on("change input",'[id^="qty-js-"]',function(){var item_id=$(this).attr("id").replace("qty-js-","");var qty=parseInt($(this).val())||1;qty=Math.max(1,Math.min(max_qty,qty));$(this).val(qty);updateQty(item_id,"set_num",qty)});var pendingDeleteItemId=null;$("#removeDialog").on("show.bs.modal",function(event){var button=$(event.relatedTarget);pendingDeleteItemId=button.data("item-id")});$("#removeDialog .btn-primary").on("click",function(){if(pendingDeleteItemId){updateQty(pendingDeleteItemId,"remove");$("#removeDialog").modal("hide");pendingDeleteItemId=null}});$("#btn-checkout-js").on("click",function(){if($(this).prop("disabled")){return}$(this).prop("disabled",true);const selectedCount=$(".item-checkbox-js:checked").length;if(selectedCount===0){$(this).prop("disabled",false);showToast(translations.itemRequired,"#toast-js");return false}$(this).prop("disabled",true).text(translations.checkoutIng);window.location.href=checkoutUrl});if(paypal_client_id!==""&&has_product){if(typeof paypal==="undefined"){webLoadScript(paypalSdkUrl,function(){paypalBuynowCreatePayment()})}else{paypalBuynowCreatePayment()}}});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
window.PaymentSDKs=window.PaymentSDKs||{paypalLoaded:false,useepayLoaded:false,activeMethod:null};const PaymentManager={init(){const checkedRadio=document.querySelector('input[name="payment_code"]:checked');if(checkedRadio){this.switchTo(checkedRadio.value)}$(document).on("change",'input[name="payment_code"]',e=>{this.switchTo(e.target.value)})},switchTo(method){if(window.PaymentSDKs.activeMethod===method)return;$(".payment-body-js").addClass("d-none");$(`.payment-body-js[data-method="${method}"]`).removeClass("d-none");if(method==="payment_paypal_sdk"){initPayPal()}else if(method==="payment_useepay_sdk"){initUseePay()}window.PaymentSDKs.activeMethod=method}};function initPayPal(){const container=document.querySelector('.payment-body-js[data-method="payment_paypal_sdk"]');if(!container||container.dataset.initialized==="1")return;if(typeof paypal==="undefined"){if(window.paypalScriptLoading)return;window.paypalScriptLoading=true;webLoadScript(payment_ui_configs.payment_paypal_sdk.paypalSdkUrl,()=>{window.paypalScriptLoading=false;renderPayPalButtons()})}else{renderPayPalButtons()}container.dataset.initialized="1"}function renderPayPalButtons(){const container=document.getElementById("paypal-buttons-container");if(container.dataset.rendered==="1")return;paypal.Buttons({createOrder:(data,actions)=>{var data_params={order_sn:orderSN};return fetch(payment_ui_configs.payment_paypal_sdk.paypalCreateOrderUrl,{method:"post",body:JSON.stringify(data_params),headers:{"content-type":"application/json"}}).then(response=>{if(!response.ok){throw new Error("Network response was not ok")}return response.json()}).then(order=>{if(order.id=="-1"){throw new Error(order.message)}return order.id}).catch(error=>{alert(error)})},onCancel:data=>{},onApprove:(data,actions)=>fetch(payment_ui_configs.payment_paypal_sdk.paypalCaptureOrderUrl,{method:"post",body:JSON.stringify(data),headers:{"content-type":"application/json"}}).then(response=>{if(!response.ok){throw new Error("Network response was not ok")}return response.json()}).then(orderData=>{if(orderData.order_sn=="-1"){if(orderData.error_issue==="INSTRUMENT_DECLINED"){alert(orderData.message);return actions.restart()}else{throw new Error(orderData.message)}}actions.redirect(`${finishPayUrl}?order_sn=${orderSn}`)}).catch(error=>{alert(error)})}).render("#paypal-buttons-container");container.dataset.rendered="1"}function initUseePay(){const container=document.querySelector('.payment-body-js[data-method="payment_useepay_sdk"]');if(!container||container.dataset.initialized==="1")return;if(typeof useePay==="undefined"){if(window.useepayScriptLoading)return;window.useepayScriptLoading=true;webLoadScript(payment_ui_configs.payment_useepay_sdk.useepaySdkUrl,()=>{window.useepayScriptLoading=false;setupUseePay()})}else{setupUseePay()}container.dataset.initialized="1"}function setupUseePay(){const container=document.getElementById("useepayCardElement");if(container.dataset.rendered==="1")return;const useepay=UseePay({env:payment_ui_configs.payment_useepay_sdk.useepay_env,merchantNo:payment_ui_configs.payment_useepay_sdk.useepay_merchant_no,layout:"multiLine",locale:navigator.language});useepay.mount(container);let $submitBtn=$("#useepaySubmit");useepay.on("change",(valid,code,message)=>{if(valid){$submitBtn.prop("disabled",false);$("#useepayErrorTip").removeClass("d-block").text("")}else{$submitBtn.prop("disabled",true);$("#useepayErrorTip").addClass("d-block").text(message)}});$submitBtn.off("click").on("click",function(){if($submitBtn.prop("disabled")){return}$submitBtn.prop("disabled",true).text(translations.restIng);useepay.validate((valid,code,message)=>{if(!valid){$("#useepayErrorTip").addClass("d-block").text(message);$submitBtn.prop("disabled",false).text(translations.payOrderText);return}$.ajax({url:payment_ui_configs.payment_useepay_sdk.useepayCreateTokenUrl,method:"POST",data:{order_sn:$("#order_sn").val(),deviceChannel:"browser",acceptHeader:navigator.userAgent,colorDepth:screen.colorDepth,javaEnabled:navigator.javaEnabled?"true":"false",language:navigator.language,screenHeight:screen.height,screenWidth:screen.width,timeZoneOffset:(new Date).getTimezoneOffset(),userAgent:navigator.userAgent},success:function(res){$submitBtn.prop("disabled",false).text(translations.payOrderText);if(res.status!=="success"){alert(res.message);return}useepay.confirm(res.data.token,function(confirmRes){$submitBtn.prop("disabled",false).text(translations.payOrderText);if(!confirmRes.success){alert(confirmRes.message);return}$.ajax({url:payment_ui_configs.payment_useepay_sdk.useepayResultUrl,method:"POST",data:JSON.parse(confirmRes.data),success:function(result){if(result.status==="success"){window.location.href=finishPayUrl+"?order_sn="+orderSN}else{alert(result.message)}}})})},error:function(XMLHttpRequest,textStatus,errorThrown){alert("Oops! Something went wrong. Please try again later.");$submitBtn.prop("disabled",false).text(translations.payOrderText)}})})});container.dataset.rendered="1"}function checkAddressInput($input){const value=$input.val();const required=$input.prop("required");if(required&&value===""){return false}if($input.attr("name")=="editForm[billing_email]"){if(!check_email(value)){return false}}return true}function loadStatesByCountry(country){$.get(changeCountryUrl,{country:country}).done(function(data){$("#address-state-js").html(data.stateHtml)}).fail(function(){alert("Failed to load states")})}function loadBillingAddress(){var url=billingAddressDetailUrl+"?order_sn="+orderSN;$.get(url).done(function(data){$("#current-billing-address-name-js").text(data.title);$("#current-billing-address-full-js").text(data.full)}).fail(function(){alert("Failed to load address list")})}function openBillingAddressForm(){var url=billingAddressFormUrl+"?order_sn="+orderSN;$("#billingAddressFormLabel").text(translations.titleBillingAddressFormEdit);$.get(url).done(function(html){$("#billingAddressFormOffcanvas .offcanvas-body").html(html.html);const formOffcanvas=new bootstrap.Offcanvas(document.getElementById("billingAddressFormOffcanvas"));formOffcanvas.show()}).fail(function(){alert("Failed to load billing address form")})}function collectBillingAddressData(){var result={success:true,data:{},error:{}};$("#billing-address-form input, #billing-address-form select").each(function(){var $this=$(this);if(!checkAddressInput($this)){result.success=false;result.error=$this;return false}else{if(typeof $this.attr("name")!="undefined"){var key=$this.attr("name");var value=$this.val();result.data[key]=value;if(key=="editForm[state]"){if($this.attr("id")=="state-select-js"){result.data["editForm[state_name]"]=$this.find("option:selected").text()}else{result.data["editForm[state_name]"]=value}}}}});return result}$(document).ready(function(){PaymentManager.init();$("#billing-address-js").on("click",function(){openBillingAddressForm();return false});document.getElementById("billingAddressFormOffcanvas").addEventListener("hidden.bs.offcanvas",function(){loadBillingAddress()});$("#countryModal").on("show.bs.modal",function(e){const currentCode=$("#country-code-input-js").val();$(".country-item-js .country-checked-js").remove();if(currentCode){const $item=$('.country-item-js[data-code="'+currentCode+'"]');if($item.length){$item.find("span").after('<span class="country-checked-js"><i class="fa-solid fa-check text-danger"></i></span>');const $group=$item.closest(".alphabet-group-js");if($group.length){$group.removeClass("d-none")}setTimeout(()=>{$item[0].scrollIntoView({behavior:"smooth",block:"center"})},100);return}}setTimeout(()=>{document.getElementById("common-group-js")?.scrollIntoView({behavior:"smooth",block:"start"})},100)});$(document).on("click",".alphabet-js",function(){const letter=$(this).attr("rel");const $group=$("#alphabet-"+letter);if($group.hasClass("d-none")){$group.removeClass("d-none")}$group[0].scrollIntoView({behavior:"smooth",block:"start"})});$(document).on("click",".country-item-js",function(){const code=$(this).data("code");const name=$(this).data("name");$("#country-code-input-js").val(code);$("#country-name-readonly-js").val(name);$("#country-name-input-js").val(name);$("#countryModal").modal("hide");loadStatesByCountry(code)});$(document).on("focus","#billing-address-form input",function(){$(this).removeClass("is-invalid");$(this).next().removeClass("d-block")}).on("blur","#billing-address-form input",function(){if(!checkAddressInput($(this))){$(this).addClass("is-invalid");$(this).next().addClass("d-block")}});$(document).on("click","#btn-save-billing-address-js",function(){var $btn=$(this);if($btn.prop("disabled")){return false}$btn.prop("disabled",true).text(translations.savIng);var addressData=collectBillingAddressData();if(!addressData.success){$(this).prop("disabled",false).text(translations.save);addressData.error.addClass("is-invalid");addressData.error.next().addClass("d-block");return false}$.ajax({url:billingAddressSaveUrl,timeout:6e3,dataType:"json",type:"post",data:addressData.data,success:function(data){$btn.prop("disabled",false).text(translations.save);if(data.status=="success"){bootstrap.Offcanvas.getInstance(document.getElementById("billingAddressFormOffcanvas"))?.hide();showToast(translations.toastUpdateBillingAddressSuccess,"#toast-js")}else{alert(data.message)}},error:function(XMLHttpRequest,textStatus,errorThrown){alert("Oops! Something went wrong. Please try again later.");$btn.prop("disabled",false).text(translations.save)}})})});
|
package/dist/js/product.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function saveProductToLocalStorage(product_spu,maxHistoryLength=30){let productHistory=JSON.parse(localStorage.getItem(product_history_key))||[];const index=productHistory.indexOf(product_spu);if(index>-1){productHistory.splice(index,1)}productHistory.unshift(product_spu);if(productHistory.length>maxHistoryLength){productHistory=productHistory.slice(0,maxHistoryLength)}localStorage.setItem(product_history_key,JSON.stringify(productHistory))}function fetchAndDisplayViewedProducts(history_url){let productHistory=JSON.parse(localStorage.getItem(product_history_key)||"[]");if(productHistory.length===0){return}const viewedProductsElement=$("#viewed-products-js");viewedProductsElement.empty();$.ajax({url:history_url,method:"POST",data:{productIds:productHistory},success:function(response){viewedProductsElement.html(response.html)},error:function(){viewedProductsElement.html("<p>Failed to load viewed products.</p>")}})}function scrollToElement(targetElement,header_height){const headerHeight=header_height||60;const targetOffsetTop=targetElement.offset().top-headerHeight;$("html, body").animate({scrollTop:targetOffsetTop},{duration:300,easing:"swing"})}function renderSizeChart(){const sizes=Object.keys($size_charts);if(sizes.length===1){renderSizeChartSingle()}else{renderSizeChartMulti()}const tab=['<ul class="nav nav-tabs mb-4" id="sizeTabs" role="tablist">'];for(i=0;i<sizes.length;i++){const key=sizes[i];tab.push('<li class="nav-item" role="presentation">');tab.push(`<button class="nav-link ${i===0?"active":""}" id="${key}-tab" data-bs-toggle="tab" data-bs-target="#${key}" type="button">${key}</button>`);tab.push("</li>")}tab.push("</ul>");const content=['<div class="tab-content" id="sizeTabsContent">'];for(i=0;i<sizes.length;i++){const key=sizes[i];const size=$size_charts[key];content.push(`<div class="table-responsive tab-pane fade ${i===0?"show active":""}" id="${key}" role="tabpanel" aria-labelledby="${key}-tab">`);content.push(renderTable(size));content.push("</div>")}content.push("</div>");$("#panelsStayOpen-sizeChart .accordion-body").append(tab.join(""));$("#panelsStayOpen-sizeChart .accordion-body").append(content.join(""))}function renderSizeChartMulti(){}function renderSizeChartSingle(){}function renderTable(data){const table=['<table class="table table-sm table-bordered table-striped size-table">'];const thead=["<thead>"];const tbody=["<tbody>"];const attrNames=[];for(const size in data){data[size].forEach(item=>{if(!attrNames.includes(item.attr_name)){attrNames.push(item.attr_name)}});break}thead.push("<tr>");thead.push("<th>Size</th>");attrNames.forEach(name=>{thead.push(`<th>${name}</th>`)});thead.push("</tr>");tbody.push("");for(const size in data){const row=["<tr><td>"+size.toUpperCase()+"</td>"];const measurements={};data[size].forEach(m=>{measurements[m.attr_name]=`${m.inch}`});attrNames.forEach(name=>{row.push(`<td>${measurements[name]||"—"}</td>`)});tbody.push(row.join(""))}tbody.push("</tbody>");table.push(thead.join(""));table.push(tbody.join(""));table.push("</table>");return table.join("")}function renderSizeChartEle(){const sizes=Object.keys($size_charts);for(i=0;i<sizes.length;i++){const key=sizes[i];const size=$size_charts[key];renderTableEle(size,key+"Table"+default_size_unit,default_size_unit);renderTableEle(size,key+"Table"+second_size_unit,second_size_unit)}}function renderTableEle(data,tableId,system){const $table=$(`#${tableId}`);const $thead=$table.find("thead tr");const $tbody=$table.find("tbody");const key=system.toLowerCase();const attrNames=[];for(const size in data){data[size].forEach(item=>{if(!attrNames.includes(item.attr_name)){attrNames.push(item.attr_name)}});break}$thead.empty().append("<th>Size</th>");attrNames.forEach(name=>{$thead.append(`<th>${name}</th>`)});$tbody.empty();for(const size in data){const row=["<tr><td>"+size.toUpperCase()+"</td>"];const measurements={};data[size].forEach(m=>{measurements[m.attr_name]=`${m[key]}`});attrNames.forEach(name=>{row.push(`<td>${measurements[name]||"—"}</td>`)});row.push("</tr>");$tbody.append(row.join(""))}}function loadProductDetail(productInfo){let rows="";if(productInfo.spu_attr.length>0){for(let index=0;index<productInfo.spu_attr.length;index++){const detail=productInfo.spu_attr[index];const row=`\n <tr>\n <td>${detail.attr_name}</td>\n <td>${detail.value_name}</td>\n </tr>`;rows+=row}}if(productInfo.custom_attr.length>0){for(let index=0;index<productInfo.custom_attr.length;index++){const detail=productInfo.custom_attr[index];const tr="<tr>";const td=`<td>${detail.attr_name}</td>`;let lists="<td><ul>";for(let i=0;i<detail.list.length;i++){const value=detail.list[i];const listItem=`<li>${value.measurements_name}: ${value.value_with_unit}</li>`;lists+=listItem}lists+="</ul></td>";rows+=tr+td+lists+"</tr>"}}$(".product_detail_img").attr("src",productInfo["image"]);$(".product_detail_name").html(productInfo["name"]);$(".product_detail_price").html(`${ecommerce_product.symbol}${productInfo["price"]}`);$(".product_qty_val").html(productInfo["qty"]);$(".product-options-js tbody").html(rows);return}function parseHeight(heightStr){const match=heightStr.match(/^(\d+)'?(\d*)"?$/);if(!match){throw new Error("Invalid height format. Expected format like '5'6 or 5'6\"")}const feet=parseInt(match[1],10)||0;const inches=parseInt(match[2],10)||0;return{feet:feet,inches:inches}}function initCustomize(relatedAttr,sizeSystem,attrValue){let sizeUnit;if(sizeSystem==="imperial"){sizeUnit="inch"}else{sizeUnit="cm"}let selectedAttr={};let pointCode;for(let i=0;i<$size_charts[relatedAttr][attrValue].length;i++){pointCode=$size_charts[relatedAttr][attrValue][i]["point_code"];if(pointCode==="height"){if(sizeUnit==="inch"){const{feet:feet,inches:inches}=parseHeight($size_charts[relatedAttr][attrValue][i]["ft"]);$("#feet").val(feet);$("#inches").val(inches)}else{$("#cm").val($size_charts[relatedAttr][attrValue][i][sizeUnit])}}else{selectedAttr[pointCode]=$size_charts[relatedAttr][attrValue][i][sizeUnit]}}const $inputs=$(`#${relatedAttr}-custom-form-container input.custom-input-js`);$inputs.each(function(){const name=$(this).attr("name");if(selectedAttr[name]){$(this).val(selectedAttr[name])}})}function calculateProductPrice(productInfo){let totalPrice=parseFloat(ecommerce_product.price);if(productInfo["spu_attr"]&&typeof productInfo["spu_attr"]==="object"&&productInfo["spu_attr"]!==null){for(let key in productInfo["spu_attr"]){if(productInfo["spu_attr"][key].value_price>0){totalPrice+=parseFloat(productInfo["spu_attr"][key].value_price)}}}if(productInfo["custom_attr"]&&typeof productInfo["custom_attr"]==="object"&&productInfo["custom_attr"]!==null){for(let key in productInfo["custom_attr"]){if(productInfo["custom_attr"][key].value_price>0){totalPrice+=parseFloat(productInfo["custom_attr"][key].value_price)}}}totalPrice=totalPrice.toFixed(2);product_info.price=totalPrice;return totalPrice}function checkCustomInfo($input){const value=$input.val();const required=$input.prop("required");if(required&&(value===""||value===0)){return false}const min=parseFloat($input.attr("min"));if(!isNaN(min)&&value<min){return false}const max=parseFloat($input.attr("max"));if(!isNaN(max)&&value>max){return false}return true}function getSpuAttrValueInfo(attr,attrValue){const attrValueInfo={attr_code:attr,value_code:attrValue,attr_name:$sku_map[attr].attr_name,value_name:$sku_map[attr]["values"][attrValue].value_name,value_price:$sku_map[attr]["values"][attrValue].value_price,base_value_price:$sku_map[attr]["values"][attrValue].base_value_price};return attrValueInfo}function getCustomAttrValueInfo(attr,attrValue,value_price,base_value_price){let value_code,value_name;if(!attrValue){value_code="";value_name=""}else{value_code=attrValue;value_name=$sku_map[attr]["values"][attrValue].value_name}const attrValueInfo={attr_code:attr,value_code:value_code,attr_name:$sku_map[attr].attr_name,value_name:value_name,value_price:value_price,base_value_price:base_value_price};return attrValueInfo}function setProductSpuAttr(attr,attrValue,options){const attrValueInfo=getSpuAttrValueInfo(attr,attrValue);const newSpuAttr={...product_info.spu_attr,[attr]:attrValueInfo};if(product_info.custom_attr&&product_info.custom_attr.hasOwnProperty(attr)){delete product_info.custom_attr[attr]}const updates={spu_attr:newSpuAttr};if(options&&options.attrImg){updates.image=options.imgSrc}updateProductInfo(updates)}function setProductCustomAttr(attr,attrValue,value_price,base_value_price){const attrValueInfo=getCustomAttrValueInfo(attr,attrValue,value_price,base_value_price);const newCustomAttr={...product_info.custom_attr,[attr]:attrValueInfo};if(product_info.spu_attr&&product_info.spu_attr.hasOwnProperty(attr)){delete product_info.spu_attr[attr]}updateProductInfo({custom_attr:newCustomAttr})}function switchToSpuAttr(attr,attrValue){if(product_info.custom_attr&&product_info.custom_attr.hasOwnProperty(attr)){delete product_info.custom_attr[attr]}if(attrValue){setProductSpuAttr(attr,attrValue)}}function setProductImage(img_src){var filename=img_src.split("/").splice(-1).toString();product_info["image"]=img_src;updateProductInfo({image:img_src})}function initProductAttr(){product_info["name"]=ecommerce_product.name;product_info["price"]=ecommerce_product.price;product_info["image"]=$("#product-main-image-js").val();product_info["product_id"]=ecommerce_product.id;product_info["spu"]=ecommerce_product.spu;product_info["qty"]=1;product_info["spu_attr"]={};product_info["custom_attr"]={};for(let index=0;index<$selected_sku_list.length;index++){const attr=$selected_sku_list[index].attr_code;const attrValue=$selected_sku_list[index].value_code;setProductSpuAttr(attr,attrValue)}}function getFilenameFromImgSrc(imgSrc){const filename=imgSrc.split("/").splice(-1).toString();return filename}function getIndexByImgSrc(imgSrc){let index=-1;$(".swiper-slide img").each(function(i,element){const currentImgSrc=$(this).data("src");const filename=getFilenameFromImgSrc(currentImgSrc);if(filename===getFilenameFromImgSrc(imgSrc)){index=i;return}});return index}function goToSlide(index,speed=null){swiper.slideTo(index,speed,false)}function updateProductInfo(updates){const keys=Object.keys(updates);for(let index=0;index<keys.length;index++){const key=keys[index];if(key==="image"){const imgSrc=updates[key];const index=getIndexByImgSrc(imgSrc);goToSlide(index)}}Object.assign(product_info,updates);$(document).trigger("product:updated",[product_info])}function renderProductUI(info){const price=calculateProductPrice(info);$("#total-price").text(`${ecommerce_product.symbol}${price}`)}function showAttrErrorMessage(attr){$(`#${attr}-error-message`).addClass("d-block")}function hideAttrErrorMessage(attr){$(`#${attr}-error-message`).removeClass("d-block")}function isAllRequiredAttrsSelected(requiredAttrs=$spu_attr){return requiredAttrs.every(attr=>product_info.spu_attr[attr]||product_info.custom_attr[attr])}function getProductInfo(){var result={success:false,data:{name:product_info.name,product_id:product_info.product_id,spu:product_info.spu,qty:product_info.qty,image:product_info.image,price:product_info.price,spu_attr:[],size_chart:{},custom_attr:[]},errors:[]};var $selected_size_charts={};for(var index=0;index<$spu_attr.length;index++){var errror={type:null,key:null,jQueryElement:null};var attr=$spu_attr[index];if(product_info.spu_attr&&typeof product_info.spu_attr==="object"&&product_info.spu_attr!==null&&product_info.spu_attr[attr]&&typeof product_info.spu_attr[attr]==="object"&&product_info.spu_attr[attr]!==null){result.data.spu_attr.push(product_info.spu_attr[attr]);var value_code=product_info.spu_attr[attr].value_code;if($size_charts.hasOwnProperty(attr)&&$size_charts[attr].hasOwnProperty(value_code)){$selected_size_charts[attr]=$size_charts[attr][value_code]}}else if(product_info.custom_attr&&typeof product_info.custom_attr==="object"&&product_info.custom_attr!==null&&product_info.custom_attr[attr]&&typeof product_info.custom_attr[attr]==="object"&&product_info.custom_attr[attr]!==null){product_info.custom_attr[attr].list=[];cusResult=collectCustomMeasurements(attr);if(cusResult.errors.length>0){errror.type="custom_attr";errror.jQueryElement=cusResult.errors[0];result.errors.push(errror);return result}else{cusResult.data.forEach(function(item){product_info.custom_attr[attr].list.push(item)})}result.data.custom_attr.push(product_info.custom_attr[attr])}else{errror.type="spu_attr";errror.key=attr;errror.jQueryElement=$(`#${attr}`);result.errors.push(errror);return result}}if(Object.keys($selected_size_charts).length>0){product_info.size_chart=$selected_size_charts;result.data.size_chart=product_info.size_chart}result.success=true;return result}function renderErrorMsg(err){scrollToElement(err.jQueryElement);if(err.type==="spu_attr"){showAttrErrorMessage(err.key)}else if(err.type==="custom_attr"){err.jQueryElement.addClass("is-invalid");err.jQueryElement.focus()}}function collectCustomMeasurements(attr){var result={success:true,data:[],errors:[]};var $container=$("#"+attr+"-custom-form-container");$container.find("div.input-group").each(function(){var $group=$(this);if(!$group.is(":visible")){return true}var $input=$group.find("input").first();if(!checkCustomInfo($input)){result.success=false;result.errors.push($input);return false}var name=$input.attr("name");var $labelSpan=$group.find(".measurements-label-js");var measurements_name=$labelSpan.length?$labelSpan.text().trim():"Unknown";if(name==="feet"){var feet=$input.val();var $inchesEle=$group.find("#inches");if(!checkCustomInfo($inchesEle)){result.success=false;result.errors.push($inchesEle);return false}var inches=$inchesEle.val();if(feet!==""&&inches!==""){var measurements_code=$group.data("measurements-code");result.data.push({measurements_code:measurements_code,measurements_name:measurements_name,value_with_unit:feet+"'"+inches+'"'})}}else{var value=$input.val();if(value!==""){var measurements_code=name;var $unitSpan=$group.find(".custom-input-unit-js");var unit=$unitSpan.length?$unitSpan.text().trim():"";result.data.push({measurements_code:measurements_code,measurements_name:measurements_name,value_with_unit:value+" "+unit})}}});return result}function init_share(){var ogUrl=$('meta[property="og:url"]').attr("content");var ogTitle=$('meta[property="og:title"]').attr("content");var elems=$("[data-sharer]");for(var i=0;i<elems.length;i++){elems[i].setAttribute("data-url",ogUrl);elems[i].setAttribute("data-title",ogTitle)}$("#affiliate-link-url-input-js").val(ogUrl)}function handleFavoriteClickThrottle(e){e.preventDefault();var self=$(this);$.ajax({url:productFavoriteUrl,method:"GET",data:{spu:ecommerce_product.spu},dataType:"json",timeout:5e3}).done(function(response){loginStatus=response.loginStatus;if(!loginStatus){window.location.href=memberLoginUrl;return}if(response.favoriteStatus){self.addClass("text-danger")}else{self.removeClass("text-danger")}showToast(response.content,"#toast-js")}).fail(function(){alert("Operation failed. Please try again later.")}).always(function(){})}function handleFavoriteClickA(e){e.preventDefault();e.stopPropagation();var self=$(this);if(self.prop("disabled")){return}self.prop("disabled",true);self.addClass("opacity-50");$.ajax({url:productFavoriteUrl,method:"GET",data:{spu:ecommerce_product.spu},dataType:"json",timeout:5e3}).done(function(response){loginStatus=response.loginStatus;if(!loginStatus){window.location.href=memberLoginUrl;return}if(response.favoriteStatus){self.addClass("text-danger")}else{self.removeClass("text-danger")}showToast(response.content,"#toast-js")}).fail(function(){alert("Operation failed. Please try again later.")}).always(function(){self.prop("disabled",false);self.removeClass("opacity-50")})}function handleFavoriteClickB(e){e.preventDefault();e.stopPropagation();var self=$(this);self.toggleClass("text-danger");$.ajax({url:productFavoriteUrl,method:"GET",data:{spu:ecommerce_product.spu},dataType:"json",timeout:5e3}).done(function(response){loginStatus=response.loginStatus;if(!loginStatus){window.location.href=memberLoginUrl;return}if(response.favoriteStatus){self.addClass("text-danger")}else{self.removeClass("text-danger")}showToast(response.content,"#toast-js")}).fail(function(){self.toggleClass("text-danger");showToast("Operation failed","#toast-js")}).always(function(){})}function checkRemark(customer_remark){if(customer_remark.length>order_remark_max_length){return false}return true}function handleAddToCartClick(e){e.preventDefault();e.stopPropagation();var self=$(this);if(self.prop("disabled")){return}self.prop("disabled",true);self.addClass("opacity-50");var result=getProductInfo();if(!result.success){self.prop("disabled",false);self.removeClass("opacity-50");showToast("Failed to obtain product information. Please refresh and try again.","#toast-js");return}var remark=$("#customer-remark-js").val();if(!checkRemark(remark)){self.prop("disabled",false);self.removeClass("opacity-50");showToast(order_remark_message,"#toast-js")}var data_params=result.data;data_params["customer_remark"]=remark;$.ajax({async:true,timeout:6e3,dataType:"json",type:"post",data:JSON.stringify(data_params),url:addToCartUrl,success:function(response){if(response.status=="success"){var items_count=response.items_count;$(".cart-item-count-js").text(items_count);var $modal=$("#productBottomSheet");var modalInstance=bootstrap.Modal.getOrCreateInstance($modal[0]);modalInstance.hide()}showToast(response.message,"#toast-js")},error:function(XMLHttpRequest,textStatus,errorThrown){let message="Operation failed. Please try again later.";if(textStatus==="timeout"){message="Request timed out. Please check your network and try again."}else if(XMLHttpRequest.status===0){message="Network connection failed. Please check your internet."}else if(XMLHttpRequest.status===401){window.location.href=memberLoginUrl;return}else if(XMLHttpRequest.status>=500){message="Server is busy. Please try again later."}else if(XMLHttpRequest.status>=400){message="Invalid request. Please try again."}else{console.error("AJAX Error:",textStatus,errorThrown)}},complete:function(){self.prop("disabled",false);self.removeClass("opacity-50")}})}function paypalBuynowCreatePayment(){var FUNDING_SOURCES=[paypal.FUNDING.PAYPAL];FUNDING_SOURCES.forEach(function(fundingSource){var button=paypal.Buttons({fundingSource:fundingSource,style:{label:"buynow"},onClick:function(){var remark=$("#customer-remark-js").val();if(!checkRemark(remark)){self.prop("disabled",false);self.removeClass("opacity-50");showToast(order_remark_message,"#toast-js");return false}return true},createOrder:(data,actions)=>{var result=getProductInfo();var data_params=result.data;data_params["customer_remark"]=$("#customer-remark-js").val();return fetch(paypalCreateOrderUrl,{method:"post",body:JSON.stringify(data_params),headers:{"content-type":"application/json"}}).then(response=>{if(!response.ok){throw new Error("Network response was not ok")}return response.json()}).then(order=>{if(order.id=="-1"){throw new Error(order.message)}return order.id}).catch(error=>{alert(error)})},onApprove:(data,actions)=>fetch(paypalCaptureOrderUrl,{method:"post",body:JSON.stringify(data),headers:{"content-type":"application/json"}}).then(response=>{if(!response.ok){throw new Error("Network response was not ok!")}return response.json()}).then(orderData=>{if(orderData.order_sn=="-1"){if(orderData.error_issue==="INSTRUMENT_DECLINED"){alert(orderData.message);return actions.restart()}else{throw new Error(orderData.message)}}const order_sn=orderData.order_sn;actions.redirect(`${paypalFinishOrderUrl}?order_sn=${order_sn}`)}).catch(error=>{alert(error)})});if(button.isEligible()){button.render("#product-paypal-container-js")}})}$(function(){const lazyLoadInstance=new LazyLoad({});$(document).on("product:updated",(e,info)=>{renderProductUI(info)});swiper=new Swiper(".swiper",{autoplay:{delay:5e3},pagination:{el:".swiper-pagination",type:"fraction",renderFraction:function(currentClass,totalClass){return'<span class="swiper-pagination-current">'+currentClass+'</span> / <span class="swiper-pagination-total">'+totalClass+"</span>"}}});initProductAttr();fetchAndDisplayViewedProducts(historyUrl);saveProductToLocalStorage(ecommerce_product.spu);if(products_more_count>products_more_count_min){$("#product-list-more").infiniteScroll({path:function(){if(this.loadCount<products_more_max_page-1){return UrlUtils.mergeParams(productsMoreUrl,{p:this.loadCount+1})}},append:false,history:false,responseBody:"json",fetchOptions:{method:"GET",headers:{"X-Requested-With":"XMLHttpRequest","Content-Type":"application/json",Accept:"application/json"}},checkLastPage:true,scrollThreshold:100,status:".page-load-status",prefill:false,debug:false});$("#product-list-more").on("load.infiniteScroll",function(event,body,path){if(body&&body.html&&body.html.trim()!==""){$(this).append(body.html);if(lazyLoadInstance){lazyLoadInstance.update()}}});$("#product-list-more").on("error.infiniteScroll",function(event,error,path){alert("Failed to load more products.")});$("#product-list-more").on("append.infiniteScroll",function(event,body,path,items){});$("#product-list-more").on("last.infiniteScroll",function(){})}$("#panelsStayOpen-sizeChart").on("show.bs.collapse",function(){if(!$(this).data("rendered")){renderSizeChartEle();$(this).data("rendered",true)}});let currentUnit=default_size_unit;function switchSizeUnit(unit){currentUnit=unit;const activeTabContentPrefix=$("#sizeTabs .nav-link.active").data("content-prefix");const contentId=activeTabContentPrefix+unit;$("#"+contentId).addClass("show active").siblings(".tab-pane").removeClass("show active");if(unit===default_size_unit){$("#switchToDefault-js").addClass("btn-danger").removeClass("btn-secondary");$("#switchToSecond-js").addClass("btn-secondary").removeClass("btn-danger")}else{$("#switchToSecond-js").addClass("btn-danger").removeClass("btn-secondary");$("#switchToDefault-js").addClass("btn-secondary").removeClass("btn-danger")}}$("#switchToDefault-js").on("click",function(){switchSizeUnit(default_size_unit)});$("#switchToSecond-js").on("click",function(){switchSizeUnit(second_size_unit)});$("#sizeTabs .nav-link").on("shown.bs.tab",function(){switchSizeUnit(currentUnit)});$("#affiliate-link-url-copy-js").on("click",function(e){e.preventDefault();var $this=$(this);const textToCopy=$("#affiliate-link-url-input-js").val().trim();if(!textToCopy){return}copyTextToClipboard(textToCopy).then(function(success){$btn.find(".affiliate-link-url-copy-label-js").addClass("d-none");$btn.find(".affiliate-link-url-copy-label-copied-js").removeClass("d-none");setTimeout(function(){$btn.find(".affiliate-link-url-copy-label-js").removeClass("d-none");$btn.find(".affiliate-link-url-copy-label-copied-js").addClass("d-none")},2e3);if(!success){console.error("Failed to copy link.")}})});$(".product-info-attr-js").on("click",".attr-value-js button",function(e){e.preventDefault();const self=$(this);const $fieldset=self.closest("fieldset");const attr=$fieldset.attr("id");const attrValue=self.data("attr-value");self.closest("div").find("button").removeClass("border-danger");self.removeClass("border-light");self.addClass("border-danger");hideAttrErrorMessage(attr);$fieldset.find(".product-selected-attr-value-js").data("value",attrValue).data("value-for-restore",attrValue).text($sku_map[attr]["values"][attrValue].value_name);const attrHasPrice=$sku_map[attr].attr_has_price;const attrImg=self.data("attr-img");const options={attrHasPrice:attrHasPrice,attrImg:attrImg};if(attrImg===1){var img_src=self.find("img").attr("src");options.imgSrc=img_src}setProductSpuAttr(attr,attrValue,options);const showSizeChart=$sku_map[attr].show_size_value_chart;if(showSizeChart===1){const $chartContainer=$fieldset.find(".product-selected-chart-js");const $chartBody=$chartContainer.find("tbody");if($size_charts[attr][attrValue]){let rows="";$.each($size_charts[attr][attrValue],function(index,detail){const imperialValue=detail.ft?detail.ft:detail.inch?detail.inch+" in":"";const row=`\n <tr>\n <td>${detail.attr_name}</td>\n <td>${imperialValue}</td>\n <td>${detail.cm} cm</td>\n </tr>`;rows+=row});$chartBody.html(rows);$chartContainer.removeClass("d-none")}}const showSizeCustom=$sku_map[attr].show_size_custom;if(showSizeCustom===1){const $customCheckbox=$fieldset.find(".custom-toggle-checkbox-js");if($customCheckbox.is(":checked")){$customCheckbox.prop("checked",false).trigger("change")}}});$(".product-info-attr-js").on("change",".custom-toggle-checkbox-js",function(){const self=$(this);const customPrice=self.data("custom_price");const baseCustomPrice=self.data("base-custom-price");const $fieldset=self.closest("fieldset");const targetFormId=self.attr("aria-controls");const isChecked=self.is(":checked");$("#"+targetFormId).toggleClass("d-none",!isChecked).attr("aria-hidden",!isChecked);self.attr("aria-expanded",isChecked);const relatedAttr=$fieldset.attr("id");const relatedAttrValue=$fieldset.find(".product-selected-attr-value-js").data("value-for-restore");if(isChecked){$fieldset.find(".d-flex button").removeClass("border-danger");$fieldset.find(".product-selected-attr-value-js").data("value","").text("");hideAttrErrorMessage(relatedAttr);if(relatedAttrValue){const size_unit=$("#"+targetFormId).find(".unit-selector-js").val();initCustomize(relatedAttr,size_unit,relatedAttrValue)}$fieldset.find(".product-selected-chart-js").addClass("d-none");setProductCustomAttr(relatedAttr,relatedAttrValue,customPrice,baseCustomPrice)}else{$fieldset.find(".d-flex button").each(function(){if($(this).data("attr-value")==relatedAttrValue){$(this).removeClass("border-light");$(this).addClass("border-danger")}});if(relatedAttrValue){$fieldset.find(".product-selected-attr-value-js").data("value",relatedAttrValue).data("value-for-restore",relatedAttrValue).text($sku_map[relatedAttr]["values"][relatedAttrValue].value_name)}$fieldset.find(".product-selected-chart-js").removeClass("d-none");switchToSpuAttr(relatedAttr,relatedAttrValue)}});$(".product-info-attr-js").on("change",".unit-selector-js",function(){const $this=$(this);const sizeUnit=$this.val();const $fieldset=$this.closest("fieldset");const relatedAttr=$fieldset.attr("id");const relatedAttrValue=$fieldset.find(".product-selected-attr-value-js").data("value-for-restore");const imperialHeight=$("#imperial-height");const metricHeight=$("#metric-height");const weightUnitLabel=$("#weight-unit-label");const $cus_units=$fieldset.find(".custom-input-unit-js");if(sizeUnit==="imperial"){if(imperialHeight){imperialHeight.removeClass("d-none");metricHeight.addClass("d-none");weightUnitLabel.text("lb")}$cus_units.each(function(){$(this).text("in")})}else{if(imperialHeight){imperialHeight.addClass("d-none");metricHeight.removeClass("d-none");weightUnitLabel.text("kg")}$cus_units.each(function(){$(this).text("cm")})}if(relatedAttrValue){initCustomize(relatedAttr,sizeUnit,relatedAttrValue)}});$(".product-info-attr-js").on("focus",".custom-form-container-js input",function(){$(this).removeClass("is-invalid")}).on("blur",".custom-form-container-js input",function(){if(!checkCustomInfo($(this))){$(this).addClass("is-invalid")}});const $quantityInput=$("#quantity");const $minusBtn=$("#qty-minus-js");const $plusBtn=$("#qty-plus-js");function updateQuantity(newQty){newQty=Math.max(1,Math.min(newQty,max_qty));$quantityInput.val(newQty);product_info.qty=newQty;$minusBtn.toggleClass("disabled",newQty<=1);$plusBtn.toggleClass("disabled",newQty>=max_qty)}$minusBtn.on("click",function(){if($(this).hasClass("disabled"))return;const current=parseInt($quantityInput.val(),10)||1;updateQuantity(current-1)});$plusBtn.on("click",function(){if($(this).hasClass("disabled"))return;const current=parseInt($quantityInput.val(),10)||1;updateQuantity(current+1)});$quantityInput.on("input",function(){let val=parseInt($(this).val(),10);if(isNaN(val)){return}val=Math.max(1,Math.min(val,max_qty));updateQuantity(val)});$quantityInput.on("blur",function(){let val=parseInt($(this).val(),10);if(isNaN(val)||val<1){updateQuantity(1)}else if(val>max_qty){updateQuantity(max_qty)}else{updateQuantity(val)}});$("#product-detail-icon-share-js").click(function(e){e.preventDefault();init_share();var $modal=$("#shareBottomSheet");var modalInstance=new bootstrap.Modal($modal[0]);modalInstance.show()});$("#shareBottomSheet").on("hidden.bs.modal",function(){});$(".product-info-attr-js").on("click","button.measurement-trigger-js",function(e){e.preventDefault();var code=$(this).data("measurements-code");var name=$size_custom_image[code]["local_img_title"];$("#measurementBottomSheetModalLabel").text(name);const imagePath=$size_custom_image[code]["local_img"];if(imagePath){$("#modalImage").attr("src",imagePath)}const htmlContent=$size_custom_image[code]["local_img_desc"];if(htmlContent){$("#modalHtml").html(htmlContent)}var trigger=code;var $modal=$("#measurementBottomSheet");$modal.data("trigger-source",trigger);var modalInstance=new bootstrap.Modal($modal[0]);modalInstance.show()});$("#measurementBottomSheet").on("hidden.bs.modal",function(){var triggerSource=$(this).data("trigger-source");$(this).removeData("trigger-source")});$("#product-favorite-js").click(handleFavoriteClickA);$(".product-view-js").on("click","button",function(e){e.preventDefault();var result=getProductInfo();if(!result.success){renderErrorMsg(result.errors[0]);return false}loadProductDetail(result.data);var trigger=$(this).data("trigger");$("#productBottomSheetModalLabel").text($(this).text());if(trigger=="product-add-cart-view-js"){$("#product-add-cart-js").removeClass("d-none");$("#product-paypal-container-js").addClass("d-none")}else if(trigger=="product-buy-now-view-js"){if(typeof paypal=="undefined"){webLoadScript(paypalSdkUrl,function(){paypalBuynowCreatePayment()})}else{paypalBuynowCreatePayment()}$("#product-add-cart-js").addClass("d-none");$("#product-paypal-container-js").removeClass("d-none")}var $modal=$("#productBottomSheet");$modal.data("trigger-source",trigger);var modalInstance=bootstrap.Modal.getOrCreateInstance($modal[0]);modalInstance.show()});$("#productBottomSheet").on("hidden.bs.modal",function(){var triggerSource=$(this).data("trigger-source");if(triggerSource==="product-buy-now-view-js"){$("#paypal-button-container").empty()}$(this).removeData("trigger-source")});$("#product-add-cart-js").click(handleAddToCartClick);$("#customer-remark-js").on("focus",function(){$(this).removeClass("is-invalid")}).on("blur",function(){if(!checkRemark($(this).val())){$(this).addClass("is-invalid");showToast(order_remark_message,"#toast-js")}})});
|
|
1
|
+
function saveProductToLocalStorage(product_spu,maxHistoryLength=30){let productHistory=JSON.parse(localStorage.getItem(product_history_key))||[];const index=productHistory.indexOf(product_spu);if(index>-1){productHistory.splice(index,1)}productHistory.unshift(product_spu);if(productHistory.length>maxHistoryLength){productHistory=productHistory.slice(0,maxHistoryLength)}localStorage.setItem(product_history_key,JSON.stringify(productHistory))}function fetchAndDisplayViewedProducts(history_url){let productHistory=JSON.parse(localStorage.getItem(product_history_key)||"[]");if(productHistory.length===0){return}const viewedProductsElement=$("#viewed-products-js");viewedProductsElement.empty();$.ajax({url:history_url,method:"POST",data:{productIds:productHistory},success:function(response){viewedProductsElement.html(response.html)},error:function(){viewedProductsElement.html("<p>Failed to load viewed products.</p>")}})}function scrollToElement(targetElement,header_height){const headerHeight=header_height||60;const targetOffsetTop=targetElement.offset().top-headerHeight;$("html, body").animate({scrollTop:targetOffsetTop},{duration:300,easing:"swing"})}function renderSizeChart(){const sizes=Object.keys($size_charts);if(sizes.length===1){renderSizeChartSingle()}else{renderSizeChartMulti()}const tab=['<ul class="nav nav-tabs mb-4" id="sizeTabs" role="tablist">'];for(i=0;i<sizes.length;i++){const key=sizes[i];tab.push('<li class="nav-item" role="presentation">');tab.push(`<button class="nav-link ${i===0?"active":""}" id="${key}-tab" data-bs-toggle="tab" data-bs-target="#${key}" type="button">${key}</button>`);tab.push("</li>")}tab.push("</ul>");const content=['<div class="tab-content" id="sizeTabsContent">'];for(i=0;i<sizes.length;i++){const key=sizes[i];const size=$size_charts[key];content.push(`<div class="table-responsive tab-pane fade ${i===0?"show active":""}" id="${key}" role="tabpanel" aria-labelledby="${key}-tab">`);content.push(renderTable(size));content.push("</div>")}content.push("</div>");$("#panelsStayOpen-sizeChart .accordion-body").append(tab.join(""));$("#panelsStayOpen-sizeChart .accordion-body").append(content.join(""))}function renderSizeChartMulti(){}function renderSizeChartSingle(){}function renderTable(data){const table=['<table class="table table-sm table-bordered table-striped size-table">'];const thead=["<thead>"];const tbody=["<tbody>"];const attrNames=[];for(const size in data){data[size].forEach(item=>{if(!attrNames.includes(item.attr_name)){attrNames.push(item.attr_name)}});break}thead.push("<tr>");thead.push("<th>Size</th>");attrNames.forEach(name=>{thead.push(`<th>${name}</th>`)});thead.push("</tr>");tbody.push("");for(const size in data){const row=["<tr><td>"+size.toUpperCase()+"</td>"];const measurements={};data[size].forEach(m=>{measurements[m.attr_name]=`${m.inch}`});attrNames.forEach(name=>{row.push(`<td>${measurements[name]||"—"}</td>`)});tbody.push(row.join(""))}tbody.push("</tbody>");table.push(thead.join(""));table.push(tbody.join(""));table.push("</table>");return table.join("")}function renderSizeChartEle(){const sizes=Object.keys($size_charts);for(i=0;i<sizes.length;i++){const key=sizes[i];const size=$size_charts[key];renderTableEle(size,key+"Table"+default_size_unit,default_size_unit);renderTableEle(size,key+"Table"+second_size_unit,second_size_unit)}}function renderTableEle(data,tableId,system){const $table=$(`#${tableId}`);const $thead=$table.find("thead tr");const $tbody=$table.find("tbody");const key=system.toLowerCase();const attrNames=[];for(const size in data){data[size].forEach(item=>{if(!attrNames.includes(item.attr_name)){attrNames.push(item.attr_name)}});break}$thead.empty().append("<th>Size</th>");attrNames.forEach(name=>{$thead.append(`<th>${name}</th>`)});$tbody.empty();for(const size in data){const row=["<tr><td>"+size.toUpperCase()+"</td>"];const measurements={};data[size].forEach(m=>{measurements[m.attr_name]=`${m[key]}`});attrNames.forEach(name=>{row.push(`<td>${measurements[name]||"—"}</td>`)});row.push("</tr>");$tbody.append(row.join(""))}}function loadProductDetail(productInfo){let rows="";if(productInfo.spu_attr.length>0){for(let index=0;index<productInfo.spu_attr.length;index++){const detail=productInfo.spu_attr[index];const row=`\n <tr>\n <td>${detail.attr_name}</td>\n <td>${detail.value_name}</td>\n </tr>`;rows+=row}}if(productInfo.custom_attr.length>0){for(let index=0;index<productInfo.custom_attr.length;index++){const detail=productInfo.custom_attr[index];const tr="<tr>";const td=`<td>${detail.attr_name}</td>`;let lists="<td><ul>";for(let i=0;i<detail.list.length;i++){const value=detail.list[i];const listItem=`<li>${value.measurements_name}: ${value.value_with_unit}</li>`;lists+=listItem}lists+="</ul></td>";rows+=tr+td+lists+"</tr>"}}$(".product_detail_img").attr("src",productInfo["image"]);$(".product_detail_name").html(productInfo["name"]);$(".product_detail_price").html(`${ecommerce_product.symbol}${productInfo["price"]}`);$(".product_qty_val").html(productInfo["qty"]);$(".product-options-js tbody").html(rows);return}function parseHeight(heightStr){const match=heightStr.match(/^(\d+)'?(\d*)"?$/);if(!match){throw new Error("Invalid height format. Expected format like '5'6 or 5'6\"")}const feet=parseInt(match[1],10)||0;const inches=parseInt(match[2],10)||0;return{feet:feet,inches:inches}}function initCustomize(relatedAttr,sizeSystem,attrValue){let sizeUnit;if(sizeSystem==="imperial"){sizeUnit="inch"}else{sizeUnit="cm"}let selectedAttr={};let pointCode;for(let i=0;i<$size_charts[relatedAttr][attrValue].length;i++){pointCode=$size_charts[relatedAttr][attrValue][i]["point_code"];if(pointCode==="height"){if(sizeUnit==="inch"){const{feet:feet,inches:inches}=parseHeight($size_charts[relatedAttr][attrValue][i]["ft"]);$("#feet").val(feet);$("#inches").val(inches)}else{$("#cm").val($size_charts[relatedAttr][attrValue][i][sizeUnit])}}else{selectedAttr[pointCode]=$size_charts[relatedAttr][attrValue][i][sizeUnit]}}const $inputs=$(`#${relatedAttr}-custom-form-container input.custom-input-js`);$inputs.each(function(){const name=$(this).attr("name");if(selectedAttr[name]){$(this).val(selectedAttr[name])}})}function calculateProductPrice(productInfo){let totalPrice=parseFloat(ecommerce_product.price);if(productInfo["spu_attr"]&&typeof productInfo["spu_attr"]==="object"&&productInfo["spu_attr"]!==null){for(let key in productInfo["spu_attr"]){if(productInfo["spu_attr"][key].value_price>0){totalPrice+=parseFloat(productInfo["spu_attr"][key].value_price)}}}if(productInfo["custom_attr"]&&typeof productInfo["custom_attr"]==="object"&&productInfo["custom_attr"]!==null){for(let key in productInfo["custom_attr"]){if(productInfo["custom_attr"][key].value_price>0){totalPrice+=parseFloat(productInfo["custom_attr"][key].value_price)}}}totalPrice=totalPrice.toFixed(2);product_info.price=totalPrice;return totalPrice}function checkCustomInfo($input){const value=$input.val();const required=$input.prop("required");if(required&&(value===""||value===0)){return false}const min=parseFloat($input.attr("min"));if(!isNaN(min)&&value<min){return false}const max=parseFloat($input.attr("max"));if(!isNaN(max)&&value>max){return false}return true}function getSpuAttrValueInfo(attr,attrValue){const attrValueInfo={attr_code:attr,value_code:attrValue,attr_name:$sku_map[attr].attr_name,value_name:$sku_map[attr]["values"][attrValue].value_name,value_price:$sku_map[attr]["values"][attrValue].value_price,base_value_price:$sku_map[attr]["values"][attrValue].base_value_price};return attrValueInfo}function getCustomAttrValueInfo(attr,attrValue,value_price,base_value_price){let value_code,value_name;if(!attrValue){value_code="";value_name=""}else{value_code=attrValue;value_name=$sku_map[attr]["values"][attrValue].value_name}const attrValueInfo={attr_code:attr,value_code:value_code,attr_name:$sku_map[attr].attr_name,value_name:value_name,value_price:value_price,base_value_price:base_value_price};return attrValueInfo}function setProductSpuAttr(attr,attrValue,options){const attrValueInfo=getSpuAttrValueInfo(attr,attrValue);const newSpuAttr={...product_info.spu_attr,[attr]:attrValueInfo};if(product_info.custom_attr&&product_info.custom_attr.hasOwnProperty(attr)){delete product_info.custom_attr[attr]}const updates={spu_attr:newSpuAttr};if(options&&options.attrImg){updates.image=options.imgSrc}updateProductInfo(updates)}function setProductCustomAttr(attr,attrValue,value_price,base_value_price){const attrValueInfo=getCustomAttrValueInfo(attr,attrValue,value_price,base_value_price);const newCustomAttr={...product_info.custom_attr,[attr]:attrValueInfo};if(product_info.spu_attr&&product_info.spu_attr.hasOwnProperty(attr)){delete product_info.spu_attr[attr]}updateProductInfo({custom_attr:newCustomAttr})}function switchToSpuAttr(attr,attrValue){if(product_info.custom_attr&&product_info.custom_attr.hasOwnProperty(attr)){delete product_info.custom_attr[attr]}if(attrValue){setProductSpuAttr(attr,attrValue)}}function setProductImage(img_src){var filename=img_src.split("/").splice(-1).toString();product_info["image"]=img_src;updateProductInfo({image:img_src})}function initProductAttr(){product_info["name"]=ecommerce_product.name;product_info["price"]=ecommerce_product.price;product_info["image"]=$("#product-main-image-js").val();product_info["product_id"]=ecommerce_product.id;product_info["spu"]=ecommerce_product.spu;product_info["qty"]=1;product_info["spu_attr"]={};product_info["custom_attr"]={};for(let index=0;index<$selected_sku_list.length;index++){const attr=$selected_sku_list[index].attr_code;const attrValue=$selected_sku_list[index].value_code;setProductSpuAttr(attr,attrValue)}}function getFilenameFromImgSrc(imgSrc){const filename=imgSrc.split("/").splice(-1).toString();return filename}function getIndexByImgSrc(imgSrc){let index=-1;$(".swiper-slide img").each(function(i,element){const currentImgSrc=$(this).data("src");const filename=getFilenameFromImgSrc(currentImgSrc);if(filename===getFilenameFromImgSrc(imgSrc)){index=i;return}});return index}function goToSlide(index,speed=null){swiper.slideTo(index,speed,false)}function updateProductInfo(updates){const keys=Object.keys(updates);for(let index=0;index<keys.length;index++){const key=keys[index];if(key==="image"){const imgSrc=updates[key];const index=getIndexByImgSrc(imgSrc);goToSlide(index)}}Object.assign(product_info,updates);$(document).trigger("product:updated",[product_info])}function renderProductUI(info){const price=calculateProductPrice(info);$("#total-price").text(`${ecommerce_product.symbol}${price}`)}function showAttrErrorMessage(attr){$(`#${attr}-error-message`).addClass("d-block")}function hideAttrErrorMessage(attr){$(`#${attr}-error-message`).removeClass("d-block")}function isAllRequiredAttrsSelected(requiredAttrs=$spu_attr){return requiredAttrs.every(attr=>product_info.spu_attr[attr]||product_info.custom_attr[attr])}function getProductInfo(){var result={success:false,data:{name:product_info.name,product_id:product_info.product_id,spu:product_info.spu,qty:product_info.qty,image:product_info.image,price:product_info.price,spu_attr:[],size_chart:{},custom_attr:[]},errors:[]};var $selected_size_charts={};for(var index=0;index<$spu_attr.length;index++){var errror={type:null,key:null,jQueryElement:null};var attr=$spu_attr[index];if(product_info.spu_attr&&typeof product_info.spu_attr==="object"&&product_info.spu_attr!==null&&product_info.spu_attr[attr]&&typeof product_info.spu_attr[attr]==="object"&&product_info.spu_attr[attr]!==null){result.data.spu_attr.push(product_info.spu_attr[attr]);var value_code=product_info.spu_attr[attr].value_code;if($size_charts.hasOwnProperty(attr)&&$size_charts[attr].hasOwnProperty(value_code)){$selected_size_charts[attr]=$size_charts[attr][value_code]}}else if(product_info.custom_attr&&typeof product_info.custom_attr==="object"&&product_info.custom_attr!==null&&product_info.custom_attr[attr]&&typeof product_info.custom_attr[attr]==="object"&&product_info.custom_attr[attr]!==null){product_info.custom_attr[attr].list=[];cusResult=collectCustomMeasurements(attr);if(cusResult.errors.length>0){errror.type="custom_attr";errror.jQueryElement=cusResult.errors[0];result.errors.push(errror);return result}else{cusResult.data.forEach(function(item){product_info.custom_attr[attr].list.push(item)})}result.data.custom_attr.push(product_info.custom_attr[attr])}else{errror.type="spu_attr";errror.key=attr;errror.jQueryElement=$(`#${attr}`);result.errors.push(errror);return result}}if(Object.keys($selected_size_charts).length>0){product_info.size_chart=$selected_size_charts;result.data.size_chart=product_info.size_chart}result.success=true;return result}function renderErrorMsg(err){scrollToElement(err.jQueryElement);if(err.type==="spu_attr"){showAttrErrorMessage(err.key)}else if(err.type==="custom_attr"){err.jQueryElement.addClass("is-invalid");err.jQueryElement.focus()}}function collectCustomMeasurements(attr){var result={success:true,data:[],errors:[]};var $container=$("#"+attr+"-custom-form-container");$container.find("div.input-group").each(function(){var $group=$(this);if(!$group.is(":visible")){return true}var $input=$group.find("input").first();if(!checkCustomInfo($input)){result.success=false;result.errors.push($input);return false}var name=$input.attr("name");var $labelSpan=$group.find(".measurements-label-js");var measurements_name=$labelSpan.length?$labelSpan.text().trim():"Unknown";if(name==="feet"){var feet=$input.val();var $inchesEle=$group.find("#inches");if(!checkCustomInfo($inchesEle)){result.success=false;result.errors.push($inchesEle);return false}var inches=$inchesEle.val();if(feet!==""&&inches!==""){var measurements_code=$group.data("measurements-code");result.data.push({measurements_code:measurements_code,measurements_name:measurements_name,value_with_unit:feet+"'"+inches+'"'})}}else{var value=$input.val();if(value!==""){var measurements_code=name;var $unitSpan=$group.find(".custom-input-unit-js");var unit=$unitSpan.length?$unitSpan.text().trim():"";result.data.push({measurements_code:measurements_code,measurements_name:measurements_name,value_with_unit:value+" "+unit})}}});return result}function init_share(){var ogUrl=$('meta[property="og:url"]').attr("content");var ogTitle=$('meta[property="og:title"]').attr("content");var elems=$("[data-sharer]");for(var i=0;i<elems.length;i++){elems[i].setAttribute("data-url",ogUrl);elems[i].setAttribute("data-title",ogTitle)}$("#affiliate-link-url-input-js").val(ogUrl)}function handleFavoriteClickThrottle(e){e.preventDefault();var self=$(this);$.ajax({url:productFavoriteUrl,method:"GET",data:{spu:ecommerce_product.spu},dataType:"json",timeout:5e3}).done(function(response){loginStatus=response.loginStatus;if(!loginStatus){window.location.href=memberLoginUrl;return}if(response.favoriteStatus){self.addClass("text-danger")}else{self.removeClass("text-danger")}showToast(response.content,"#toast-js")}).fail(function(){alert("Operation failed. Please try again later.")}).always(function(){})}function handleFavoriteClickA(e){e.preventDefault();e.stopPropagation();var self=$(this);if(self.prop("disabled")){return}self.prop("disabled",true);self.addClass("opacity-50");$.ajax({url:productFavoriteUrl,method:"GET",data:{spu:ecommerce_product.spu},dataType:"json",timeout:5e3}).done(function(response){loginStatus=response.loginStatus;if(!loginStatus){window.location.href=memberLoginUrl;return}if(response.favoriteStatus){self.addClass("text-danger")}else{self.removeClass("text-danger")}showToast(response.content,"#toast-js")}).fail(function(){alert("Operation failed. Please try again later.")}).always(function(){self.prop("disabled",false);self.removeClass("opacity-50")})}function handleFavoriteClickB(e){e.preventDefault();e.stopPropagation();var self=$(this);self.toggleClass("text-danger");$.ajax({url:productFavoriteUrl,method:"GET",data:{spu:ecommerce_product.spu},dataType:"json",timeout:5e3}).done(function(response){loginStatus=response.loginStatus;if(!loginStatus){window.location.href=memberLoginUrl;return}if(response.favoriteStatus){self.addClass("text-danger")}else{self.removeClass("text-danger")}showToast(response.content,"#toast-js")}).fail(function(){self.toggleClass("text-danger");showToast("Operation failed","#toast-js")}).always(function(){})}function checkRemark(customer_remark){if(customer_remark.length>order_remark_max_length){return false}return true}function handleAddToCartClick(e){e.preventDefault();e.stopPropagation();var self=$(this);if(self.prop("disabled")){return}self.prop("disabled",true);self.addClass("opacity-50");var result=getProductInfo();if(!result.success){self.prop("disabled",false);self.removeClass("opacity-50");showToast("Failed to obtain product information. Please refresh and try again.","#toast-js");return}var remark=$("#customer-remark-js").val();if(!checkRemark(remark)){self.prop("disabled",false);self.removeClass("opacity-50");showToast(order_remark_message,"#toast-js")}var data_params=result.data;data_params["customer_remark"]=remark;$.ajax({async:true,timeout:6e3,dataType:"json",type:"post",data:JSON.stringify(data_params),url:addToCartUrl,success:function(response){if(response.status=="success"){var items_count=response.items_count;$(".cart-item-count-js").text(items_count);var $modal=$("#productBottomSheet");var modalInstance=bootstrap.Modal.getOrCreateInstance($modal[0]);modalInstance.hide()}showToast(response.message,"#toast-js")},error:function(XMLHttpRequest,textStatus,errorThrown){let message="Operation failed. Please try again later.";if(textStatus==="timeout"){message="Request timed out. Please check your network and try again."}else if(XMLHttpRequest.status===0){message="Network connection failed. Please check your internet."}else if(XMLHttpRequest.status===401){window.location.href=memberLoginUrl;return}else if(XMLHttpRequest.status>=500){message="Server is busy. Please try again later."}else if(XMLHttpRequest.status>=400){message="Invalid request. Please try again."}else{console.error("AJAX Error:",textStatus,errorThrown)}},complete:function(){self.prop("disabled",false);self.removeClass("opacity-50")}})}function paypalBuynowCreatePayment(){const container=document.getElementById("product-paypal-container-js");if(container.dataset.rendered==="1")return;var FUNDING_SOURCES=[paypal.FUNDING.PAYPAL];FUNDING_SOURCES.forEach(function(fundingSource){var button=paypal.Buttons({fundingSource:fundingSource,style:{label:"buynow"},onClick:function(){var remark=$("#customer-remark-js").val();if(!checkRemark(remark)){self.prop("disabled",false);self.removeClass("opacity-50");showToast(order_remark_message,"#toast-js");return false}return true},createOrder:(data,actions)=>{var result=getProductInfo();var data_params=result.data;data_params["customer_remark"]=$("#customer-remark-js").val();return fetch(paypalCreateOrderUrl,{method:"post",body:JSON.stringify(data_params),headers:{"content-type":"application/json"}}).then(response=>{if(!response.ok){throw new Error("Network response was not ok")}return response.json()}).then(order=>{if(order.id=="-1"){throw new Error(order.message)}return order.id}).catch(error=>{alert(error)})},onCancel:data=>{},onApprove:(data,actions)=>fetch(paypalCaptureOrderUrl,{method:"post",body:JSON.stringify(data),headers:{"content-type":"application/json"}}).then(response=>{if(!response.ok){throw new Error("Network response was not ok!")}return response.json()}).then(orderData=>{if(orderData.order_sn=="-1"){if(orderData.error_issue==="INSTRUMENT_DECLINED"){alert(orderData.message);return actions.restart()}else{throw new Error(orderData.message)}}const order_sn=orderData.order_sn;actions.redirect(`${paypalFinishOrderUrl}?order_sn=${order_sn}`)}).catch(error=>{alert(error)})});if(button.isEligible()){button.render("#product-paypal-container-js")}container.dataset.rendered="1"})}$(function(){const lazyLoadInstance=new LazyLoad({});$(document).on("product:updated",(e,info)=>{renderProductUI(info)});swiper=new Swiper(".swiper",{autoplay:{delay:5e3},pagination:{el:".swiper-pagination",type:"fraction",renderFraction:function(currentClass,totalClass){return'<span class="swiper-pagination-current">'+currentClass+'</span> / <span class="swiper-pagination-total">'+totalClass+"</span>"}}});initProductAttr();fetchAndDisplayViewedProducts(historyUrl);saveProductToLocalStorage(ecommerce_product.spu);if(products_more_count>products_more_count_min){$("#product-list-more").infiniteScroll({path:function(){if(this.loadCount<products_more_max_page-1){return UrlUtils.mergeParams(productsMoreUrl,{p:this.loadCount+1})}},append:false,history:false,responseBody:"json",fetchOptions:{method:"GET",headers:{"X-Requested-With":"XMLHttpRequest","Content-Type":"application/json",Accept:"application/json"}},checkLastPage:true,scrollThreshold:100,status:".page-load-status",prefill:false,debug:false});$("#product-list-more").on("load.infiniteScroll",function(event,body,path){if(body&&body.html&&body.html.trim()!==""){$(this).append(body.html);if(lazyLoadInstance){lazyLoadInstance.update()}}});$("#product-list-more").on("error.infiniteScroll",function(event,error,path){alert("Failed to load more products.")});$("#product-list-more").on("append.infiniteScroll",function(event,body,path,items){});$("#product-list-more").on("last.infiniteScroll",function(){})}$("#panelsStayOpen-sizeChart").on("show.bs.collapse",function(){if(!$(this).data("rendered")){renderSizeChartEle();$(this).data("rendered",true)}});let currentUnit=default_size_unit;function switchSizeUnit(unit){currentUnit=unit;const activeTabContentPrefix=$("#sizeTabs .nav-link.active").data("content-prefix");const contentId=activeTabContentPrefix+unit;$("#"+contentId).addClass("show active").siblings(".tab-pane").removeClass("show active");if(unit===default_size_unit){$("#switchToDefault-js").addClass("btn-danger").removeClass("btn-secondary");$("#switchToSecond-js").addClass("btn-secondary").removeClass("btn-danger")}else{$("#switchToSecond-js").addClass("btn-danger").removeClass("btn-secondary");$("#switchToDefault-js").addClass("btn-secondary").removeClass("btn-danger")}}$("#switchToDefault-js").on("click",function(){switchSizeUnit(default_size_unit)});$("#switchToSecond-js").on("click",function(){switchSizeUnit(second_size_unit)});$("#sizeTabs .nav-link").on("shown.bs.tab",function(){switchSizeUnit(currentUnit)});$("#affiliate-link-url-copy-js").on("click",function(e){e.preventDefault();var $this=$(this);const textToCopy=$("#affiliate-link-url-input-js").val().trim();if(!textToCopy){return}copyTextToClipboard(textToCopy).then(function(success){$btn.find(".affiliate-link-url-copy-label-js").addClass("d-none");$btn.find(".affiliate-link-url-copy-label-copied-js").removeClass("d-none");setTimeout(function(){$btn.find(".affiliate-link-url-copy-label-js").removeClass("d-none");$btn.find(".affiliate-link-url-copy-label-copied-js").addClass("d-none")},2e3);if(!success){console.error("Failed to copy link.")}})});$(".product-info-attr-js").on("click",".attr-value-js button",function(e){e.preventDefault();const self=$(this);const $fieldset=self.closest("fieldset");const attr=$fieldset.attr("id");const attrValue=self.data("attr-value");self.closest("div").find("button").removeClass("border-danger");self.removeClass("border-light");self.addClass("border-danger");hideAttrErrorMessage(attr);$fieldset.find(".product-selected-attr-value-js").data("value",attrValue).data("value-for-restore",attrValue).text($sku_map[attr]["values"][attrValue].value_name);const attrHasPrice=$sku_map[attr].attr_has_price;const attrImg=self.data("attr-img");const options={attrHasPrice:attrHasPrice,attrImg:attrImg};if(attrImg===1){var img_src=self.find("img").attr("src");options.imgSrc=img_src}setProductSpuAttr(attr,attrValue,options);const showSizeChart=$sku_map[attr].show_size_value_chart;if(showSizeChart===1){const $chartContainer=$fieldset.find(".product-selected-chart-js");const $chartBody=$chartContainer.find("tbody");if($size_charts[attr][attrValue]){let rows="";$.each($size_charts[attr][attrValue],function(index,detail){const imperialValue=detail.ft?detail.ft:detail.inch?detail.inch+" in":"";const row=`\n <tr>\n <td>${detail.attr_name}</td>\n <td>${imperialValue}</td>\n <td>${detail.cm} cm</td>\n </tr>`;rows+=row});$chartBody.html(rows);$chartContainer.removeClass("d-none")}}const showSizeCustom=$sku_map[attr].show_size_custom;if(showSizeCustom===1){const $customCheckbox=$fieldset.find(".custom-toggle-checkbox-js");if($customCheckbox.is(":checked")){$customCheckbox.prop("checked",false).trigger("change")}}});$(".product-info-attr-js").on("change",".custom-toggle-checkbox-js",function(){const self=$(this);const customPrice=self.data("custom_price");const baseCustomPrice=self.data("base-custom-price");const $fieldset=self.closest("fieldset");const targetFormId=self.attr("aria-controls");const isChecked=self.is(":checked");$("#"+targetFormId).toggleClass("d-none",!isChecked).attr("aria-hidden",!isChecked);self.attr("aria-expanded",isChecked);const relatedAttr=$fieldset.attr("id");const relatedAttrValue=$fieldset.find(".product-selected-attr-value-js").data("value-for-restore");if(isChecked){$fieldset.find(".d-flex button").removeClass("border-danger");$fieldset.find(".product-selected-attr-value-js").data("value","").text("");hideAttrErrorMessage(relatedAttr);if(relatedAttrValue){const size_unit=$("#"+targetFormId).find(".unit-selector-js").val();initCustomize(relatedAttr,size_unit,relatedAttrValue)}$fieldset.find(".product-selected-chart-js").addClass("d-none");setProductCustomAttr(relatedAttr,relatedAttrValue,customPrice,baseCustomPrice)}else{$fieldset.find(".d-flex button").each(function(){if($(this).data("attr-value")==relatedAttrValue){$(this).removeClass("border-light");$(this).addClass("border-danger")}});if(relatedAttrValue){$fieldset.find(".product-selected-attr-value-js").data("value",relatedAttrValue).data("value-for-restore",relatedAttrValue).text($sku_map[relatedAttr]["values"][relatedAttrValue].value_name)}$fieldset.find(".product-selected-chart-js").removeClass("d-none");switchToSpuAttr(relatedAttr,relatedAttrValue)}});$(".product-info-attr-js").on("change",".unit-selector-js",function(){const $this=$(this);const sizeUnit=$this.val();const $fieldset=$this.closest("fieldset");const relatedAttr=$fieldset.attr("id");const relatedAttrValue=$fieldset.find(".product-selected-attr-value-js").data("value-for-restore");const imperialHeight=$("#imperial-height");const metricHeight=$("#metric-height");const weightUnitLabel=$("#weight-unit-label");const $cus_units=$fieldset.find(".custom-input-unit-js");if(sizeUnit==="imperial"){if(imperialHeight){imperialHeight.removeClass("d-none");metricHeight.addClass("d-none");weightUnitLabel.text("lb")}$cus_units.each(function(){$(this).text("in")})}else{if(imperialHeight){imperialHeight.addClass("d-none");metricHeight.removeClass("d-none");weightUnitLabel.text("kg")}$cus_units.each(function(){$(this).text("cm")})}if(relatedAttrValue){initCustomize(relatedAttr,sizeUnit,relatedAttrValue)}});$(".product-info-attr-js").on("focus",".custom-form-container-js input",function(){$(this).removeClass("is-invalid")}).on("blur",".custom-form-container-js input",function(){if(!checkCustomInfo($(this))){$(this).addClass("is-invalid")}});const $quantityInput=$("#quantity");const $minusBtn=$("#qty-minus-js");const $plusBtn=$("#qty-plus-js");function updateQuantity(newQty){newQty=Math.max(1,Math.min(newQty,max_qty));$quantityInput.val(newQty);product_info.qty=newQty;$minusBtn.toggleClass("disabled",newQty<=1);$plusBtn.toggleClass("disabled",newQty>=max_qty)}$minusBtn.on("click",function(){if($(this).hasClass("disabled"))return;const current=parseInt($quantityInput.val(),10)||1;updateQuantity(current-1)});$plusBtn.on("click",function(){if($(this).hasClass("disabled"))return;const current=parseInt($quantityInput.val(),10)||1;updateQuantity(current+1)});$quantityInput.on("input",function(){let val=parseInt($(this).val(),10);if(isNaN(val)){return}val=Math.max(1,Math.min(val,max_qty));updateQuantity(val)});$quantityInput.on("blur",function(){let val=parseInt($(this).val(),10);if(isNaN(val)||val<1){updateQuantity(1)}else if(val>max_qty){updateQuantity(max_qty)}else{updateQuantity(val)}});$("#product-detail-icon-share-js").click(function(e){e.preventDefault();init_share();var $modal=$("#shareBottomSheet");var modalInstance=new bootstrap.Modal($modal[0]);modalInstance.show()});$("#shareBottomSheet").on("hidden.bs.modal",function(){});$(".product-info-attr-js").on("click","button.measurement-trigger-js",function(e){e.preventDefault();var code=$(this).data("measurements-code");var name=$size_custom_image[code]["local_img_title"];$("#measurementBottomSheetModalLabel").text(name);const imagePath=$size_custom_image[code]["local_img"];if(imagePath){$("#modalImage").attr("src",imagePath)}const htmlContent=$size_custom_image[code]["local_img_desc"];if(htmlContent){$("#modalHtml").html(htmlContent)}var trigger=code;var $modal=$("#measurementBottomSheet");$modal.data("trigger-source",trigger);var modalInstance=new bootstrap.Modal($modal[0]);modalInstance.show()});$("#measurementBottomSheet").on("hidden.bs.modal",function(){var triggerSource=$(this).data("trigger-source");$(this).removeData("trigger-source")});$("#product-favorite-js").click(handleFavoriteClickA);$(".product-view-js").on("click","button",function(e){e.preventDefault();var result=getProductInfo();if(!result.success){renderErrorMsg(result.errors[0]);return false}loadProductDetail(result.data);var trigger=$(this).data("trigger");$("#productBottomSheetModalLabel").text($(this).text());if(trigger=="product-add-cart-view-js"){$("#product-add-cart-js").removeClass("d-none");$("#product-paypal-container-js").addClass("d-none")}else if(trigger=="product-buy-now-view-js"){if(typeof paypal=="undefined"){webLoadScript(paypalSdkUrl,function(){paypalBuynowCreatePayment()})}else{paypalBuynowCreatePayment()}$("#product-add-cart-js").addClass("d-none");$("#product-paypal-container-js").removeClass("d-none")}var $modal=$("#productBottomSheet");$modal.data("trigger-source",trigger);var modalInstance=bootstrap.Modal.getOrCreateInstance($modal[0]);modalInstance.show()});$("#productBottomSheet").on("hidden.bs.modal",function(){var triggerSource=$(this).data("trigger-source");if(triggerSource==="product-buy-now-view-js"){$("#paypal-button-container").empty()}$(this).removeData("trigger-source")});$("#product-add-cart-js").click(handleAddToCartClick);$("#customer-remark-js").on("focus",function(){$(this).removeClass("is-invalid")}).on("blur",function(){if(!checkRemark($(this).val())){$(this).addClass("is-invalid");showToast(order_remark_message,"#toast-js")}})});
|
package/package.json
CHANGED
package/readme.txt
CHANGED
|
@@ -19,6 +19,8 @@ terser 负责压缩js
|
|
|
19
19
|
terser src/js/forgot-password.js -o dist/js/forgot-password.min.js
|
|
20
20
|
terser src/js/reset-password.js -o dist/js/reset-password.min.js
|
|
21
21
|
terser src/js/order.js -o dist/js/order.min.js
|
|
22
|
+
terser src/js/cart.js -o dist/js/cart.min.js
|
|
23
|
+
terser src/js/pay.js -o dist/js/pay.min.js
|
|
22
24
|
-----------
|
|
23
25
|
// load any GitHub release, commit, or branch
|
|
24
26
|
// note: we recommend using npm for projects that support it
|
|
@@ -26,7 +28,7 @@ https://cdn.jsdelivr.net/gh/user/repo@version/file
|
|
|
26
28
|
github:
|
|
27
29
|
https://cdn.jsdelivr.net/gh/chenhl/luv@main/dist/css/style.css
|
|
28
30
|
|
|
29
|
-
|
|
31
|
+
---------------------
|
|
30
32
|
npm :
|
|
31
33
|
https://cdn.jsdelivr.net/npm/luv-assets@latest/dist/css/style.css
|
|
32
34
|
|
|
@@ -39,4 +41,8 @@ npm publish --access public
|
|
|
39
41
|
npm version patch
|
|
40
42
|
|
|
41
43
|
# 发布新版本
|
|
42
|
-
npm publish
|
|
44
|
+
npm publish
|
|
45
|
+
|
|
46
|
+
# token update
|
|
47
|
+
npm config set //registry.npmjs.org/:_authToken=YOUR_TOKEN_HERE
|
|
48
|
+
-----------------------------
|