document.addEventListener("DOMContentLoaded", () => {
const domain = "https://productreview.myappgurus.com/api/",
customerId = __st.cid,
shopId = __st.a,
shopName = Shopify.shop,
reviewData = (document.querySelector('.mag-product-review-summary').textContent.trim() != '') ? JSON.parse(document.querySelector('.mag-product-review-summary').textContent) : {};
const getFirstImage = (imageUrl) => {
if (!imageUrl) return null;
// Check if image URL contains multiple images (comma-separated)
if (imageUrl.includes(',')) {
const images = imageUrl.split(',');
return images[0].trim(); // Return first image URL
}
return imageUrl; // Return single image URL
}
const metafieldUpdater = () => {
fetch(`${domain}metafieldDatasUpdates`, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-type': 'application/json',
'Authorization': `Bearer ${window.sessionToken}`
},
body: JSON.stringify({
shop: Shopify.shop,
}),
})
.then(response => response.json())
.then(response => {
if (response) {
customArraysdata = myappgurusreviewsettings;
}
});
}
let customArraysdata = false;
const myappgurusreviewsettings = window.myappgurusreviewsettings;
if (myappgurusreviewsettings && myappgurusreviewsettings.length > 0) {
customArraysdata = myappgurusreviewsettings;
} else {
customArraysdata = false;
}
if (myappgurusreviewsettings == null || myappgurusreviewsettings == undefined || myappgurusreviewsettings == "") {
metafieldUpdater();
}
const customArrayData = (customArraysdata) ? JSON.parse(customArraysdata) : {};
// const toptenreviews = window.toptenmyappgurusreview;
// const reviewspopup = (toptenreviews) ? JSON.parse(toptenreviews) : {};
// const latesttenReview = reviewspopup.sort((a, b) => new Date(b.created_at) - new Date(a.created_at));
// const latestReview = latesttenReview.length > 0 ? latesttenReview[0] : null;
const toptenreviews = window.toptenmyappgurusreview || "[]";
let reviewspopup = [];
try {
reviewspopup = JSON.parse(toptenreviews);
if (!Array.isArray(reviewspopup)) {
reviewspopup = [];
}
} catch (error) {
console.error("Error parsing reviews JSON:", error);
reviewspopup = [];
}
const latesttenReview = reviewspopup.length
? reviewspopup.sort((a, b) => new Date(b.created_at) - new Date(a.created_at))
: [];
const latestReview = latesttenReview.length > 0 ? latesttenReview[0] : null;
function formatDateAndRelativeTime(dateString) {
const inputDate = new Date(dateString);
const currentDate = new Date();
const formattedDate = inputDate.toISOString().split('T')[0];
const diffYears = currentDate.getFullYear() - inputDate.getFullYear();
const diffMonths = (currentDate.getMonth() - inputDate.getMonth()) + (diffYears * 12);
let relativeTime;
if (diffYears >= 1) {
relativeTime = `${diffYears} year${diffYears > 1 ? 's' : ''} ago on ${formattedDate}`;
} else if (diffMonths >= 6) {
relativeTime = `6 months ago on ${formattedDate}`;
} else if (diffMonths >= 3) {
relativeTime = `3 months ago on ${formattedDate}`;
} else if (diffMonths >= 1) {
relativeTime = `1 month ago on ${formattedDate}`;
} else {
relativeTime = `on ${formattedDate}`;
}
return {
relativeTime: relativeTime,
formattedDate: formattedDate
};
}
const checkFileType = (url) => { let extension = url.split('.').pop().toLowerCase(), videoExtensions = ['mp4', 'mov', 'webm', 'mkv']; if (videoExtensions.includes(extension)) { return 'video'; } else { return 'image'; } }
const appendElementInHtml = (data) => { let parser = new DOMParser(), htmlBtnDocument = parser.parseFromString(data, 'text/html'), htmlBtnElement = htmlBtnDocument.body.firstChild; return htmlBtnElement; }
// const isLink = (str) => {const urlPattern = /^(https?:\/\/)?([\da-z.-]+)\.([a-z.]{2,6})([/\w .-]*)*\/?$/; return urlPattern.test(str);}
const isLink = (url) => {
if (url.startsWith('https://cdn.shopify.com')) {
return url;
} else if (url.startsWith('assets/')) {
let fullUrl = `${domain}${url}`;
return fullUrl;
} else {
return url;
}
}
const starStyleCollectionPage = (star_style, color, response, status) => {
let reviews = '',
starColor = (color !== null && color.trim() !== '' && color !== undefined)
? color : 'currentColor',
ratings = (response != undefined) ? (response.average != undefined) ? parseFloat(response.average).toFixed(1) : '0.0' : '0.0',
ratingCount = (response != undefined) ? (response.totalCount != undefined) ? response.totalCount : '0' : '0';
switch (star_style) {
case 'single_star_with_rating':
reviews = ``;
if (Math.floor(ratings) !== 0) {
reviews += star((response != undefined) ? (parseFloat(response.average) !== 0) ? 'filled' : 'not-filled' : 'not-filled', starColor);
reviews += `(${ratings})`;
} else {
reviews += starWithNoRating('not-filled');
}
reviews += ``;
break;
case 'single_star_with_total_reviews':
reviews = ``;
if (Math.floor(ratings) !== 0) {
reviews += star((response != undefined) ? (parseFloat(response.average) !== 0) ? 'filled' : 'not-filled' : 'not-filled', starColor);
reviews += `(${ratingCount})`;
} else {
reviews += starWithNoRating('not-filled');
}
reviews += ``;
break;
case 'star_with_rating_or_total_reviews':
reviews = ``;
if (Math.floor(ratings) !== 0) {
reviews += star((response != undefined) ? (parseFloat(response.average) !== 0) ? 'filled' : 'not-filled' : 'not-filled', starColor);
reviews += `${ratings} (${ratingCount})`;
} else {
reviews += starWithNoRating('not-filled');
}
reviews += ``;
break;
case 'star_with_rating':
reviews += ``;
for (index = 0; index < 5; index++) {
if (index < Math.floor(ratings) && Math.floor(ratings) != 0) {
reviews += star('filled', starColor);
} else if ((ratings - Math.floor(ratings)) > 0 && index < Math.ceil(ratings)) {
reviews += star('half-filled', starColor);
} else {
reviews += (Math.floor(ratings) !== 0) ? star('not-filled', starColor) : starWithNoRating('not-filled');
}
}
if (Math.floor(ratings) !== 0) {
reviews += `(${ratings})`
}
reviews += ``;
break;
case 'star_with_total_reviews':
reviews += ``;
for (index = 0; index < 5; index++) {
if (index < Math.floor(ratings) && Math.floor(ratings) != 0) {
reviews += star('filled', starColor);
} else if ((ratings - Math.floor(ratings)) > 0 && index < Math.ceil(ratings)) {
reviews += star('half-filled', starColor);
} else {
reviews += (Math.floor(ratings) !== 0) ? star('not-filled', starColor) : starWithNoRating('not-filled');
}
}
if (Math.floor(ratings) !== 0) {
reviews += `(${ratingCount})`
}
reviews += ``;
break;
case 'star_rating':
reviews += ``;
let reviewLabel = (__st.a === 76038046042 || __st.a === 75680579909 || __st.a === 77037207880) ? status == true ? ratingCount > 1 ? 'Reviews' : 'Review' : '' : '';
for (index = 0; index < 5; index++) {
if (index < Math.floor(ratings) && Math.floor(ratings) != 0) {
reviews += star('filled', starColor);
} else if ((ratings - Math.floor(ratings)) > 0 && index < Math.ceil(ratings)) {
reviews += star('half-filled', starColor);
} else {
reviews += (Math.floor(ratings) !== 0) ? star('not-filled', starColor) : starWithNoRating('not-filled');
}
}
if (Math.floor(ratings) !== 0) {
reviews += `${ratings} (${ratingCount}${reviewLabel ? ` ${reviewLabel}` : ''})`
}
reviews += ``;
break;
default:
break;
}
return reviews;
}
const checkLogo = () => {
let formLogo = document.querySelector('#erpReviewFrom .mag-logo-image');
if (!formLogo || (document.querySelector('.mag-logo-image').getAttribute('style') != 'display:block !important;') || (document.querySelector('.form.mag-logo-wrapper').getAttribute('style') != 'display:flex !important;') || (document.querySelector('.form.mag-logo-wrapper a').getAttribute('style') != 'display:flex !important;') || (document.querySelector('.form.mag-logo-wrapper a span')?.getAttribute('style') != 'display:inline !important;') || (document.querySelector('.form.mag-logo-wrapper a img').getAttribute('style') != 'display:inline !important;')) {
if ((__st.a !== 82898092358)) {
if (customArrayData.removeWaterMark != '1') {
if (__st.a == '13326581') {
} else {
let logoData = `
You can't add a review because you haven't bought this product.
`;
document.querySelector('.epr-form-content-wrapp').scrollIntoView({ behavior: 'smooth', block: 'start' });
setTimeout(() => {
document.querySelector('#alert-text').innerHTML = '';
}, 10000);
}
});
}
var checkReviewRestriction = () => {
let targetClass = document.querySelector('#mag-product-review'),
proId = targetClass?.getAttribute('data-product'),
writeReviewBtn = '';
switch (customArrayData.reviewRestrictions[0]) {
case "no_restrictions":
writeReviewBtn = `${window.myappgurus.form && window.myappgurus.form.custom_settings && window.myappgurus.form.custom_settings.review_btn ? window.myappgurus.form.custom_settings.review_btn : window.myappgurus.prm.form.review_btn}
`;
appendFormOnProductPage(true, 'no_restrictions');
break;
case "only_buyers":
writeReviewBtn = `${window.myappgurus.form && window.myappgurus.form.custom_settings && window.myappgurus.form.custom_settings.review_btn ? window.myappgurus.form.custom_settings.review_btn : window.myappgurus.prm.form.review_btn}
`;
appendFormOnProductPage(true, 'only_buyers');
break;
case "only_buyers_with_review_request_email":
if (window.location.href.includes('mag_customer_email=')) {
writeReviewBtn = `${window.myappgurus.form && window.myappgurus.form.custom_settings && window.myappgurus.form.custom_settings.review_btn ? window.myappgurus.form.custom_settings.review_btn : window.myappgurus.prm.form.review_btn}
`;
appendFormOnProductPage(true, 'only_buyers_with_review_request_email');
} else {
appendFormOnProductPage(false, 'only_buyers_with_review_request_email');
}
break;
default:
appendFormOnProductPage(true, '');
break;
}
}
if (customArrayData.showPopUpWidget == true && latestReview) {
const popupHtml = `
`;
document.body.insertAdjacentHTML('beforeend', popupHtml);
const popupElement = document.querySelector('.mag-product-float-popup');
const updatePopupClass = () => {
popupElement.classList.toggle(`${customArrayData.widgetPosition}-shown`);
};
const intervalId = setInterval(updatePopupClass, 10000);
document.querySelector('.mag-product-close-icon').addEventListener('click', () => {
clearInterval(intervalId);
popupElement.remove();
});
}
var appendFormOnProductPage = (writeReviewBtn, type) => {
let targetClass = document.querySelector('#mag-product-review'),
proId = targetClass?.getAttribute('data-product'),
proHandle = targetClass?.getAttribute('data-product-handle'),
protitle = document.querySelector('#epr-product-title-review')?.getAttribute('data-product-title'),
starcolor = (customArrayData.reviewStarcolor !== undefined && customArrayData.reviewStarcolor !== '') ? customArrayData.reviewStarcolor : 'currentColor',
reviewDataJson = reviewData.filter(item => { return item.productId == proId });
if (customArrayData.allowVideoUploads == true) {
var imagelabel = window.myappgurus.prm.form.form_fields.review_image_video;
} else {
var imagelabel = window.myappgurus.prm.form.form_fields.review_image;
}
var customerEmail = (window.location.href.includes('mag_customer_email=')) ? window.location.href.split('mag_customer_email=')[1].split('&')[0] : '';
var productRating = (window.location.href.includes('mag_rating=')) ? window.location.href.split('mag_rating=')[1].split('&')[0] : '';
var customerName = (window.location.href.includes('mag_customer_name=')) ? window.location.href.split('mag_customer_name=')[1].split('&')[0] : '';
var reviewTitle = (window.location.href.includes('mag_review_title=')) ? window.location.href.split('mag_review_title=')[1].split('&')[0] : '';
var reviewDescription = (window.location.href.includes('mag_review_description=')) ? window.location.href.split('mag_review_description=')[1].split('&')[0] : '';
var deliveryRating = (window.location.href.includes('mag_delivery_review=')) ? window.location.href.split('mag_delivery_review=')[1].split('&')[0] : '';
var paymentRating = (window.location.href.includes('mag_payment_review=')) ? window.location.href.split('mag_payment_review=')[1].split('&')[0] : '';
var priceRating = (window.location.href.includes('mag_price_review=')) ? window.location.href.split('mag_price_review=')[1].split('&')[0] : '';
var customerEmailValue = customerEmail ? decodeURIComponent(customerEmail) : '';
var ratingValue = productRating ? decodeURIComponent(productRating) : '';
var customerNameValue = customerName ? decodeURIComponent(customerName) : '';
var reviewTitleValue = reviewTitle ? decodeURIComponent(reviewTitle) : '';
var reviewDescriptionValue = reviewDescription ? decodeURIComponent(reviewDescription) : '';
var deliveryRatingValue = deliveryRating ? decodeURIComponent(deliveryRating) : '';
var paymentRatingValue = paymentRating ? decodeURIComponent(paymentRating) : '';
var priceRatingValue = priceRating ? decodeURIComponent(priceRating) : '';
var prefillRatings = {
'rating': ratingValue,
'delivery_review': deliveryRatingValue,
'payment_review': paymentRatingValue,
'price_review': priceRatingValue
};
var product_base_url = window.location.href;
var product_base_url_split = product_base_url.split('?mag_');
var new_product_base_url = product_base_url_split[0];
var formSubmittedMediaReminder = 'MediaReminder'
var formData = `
${window.myappgurus.form && window.myappgurus.form.custom_settings && window.myappgurus.form.custom_settings.block_heading ?
window.myappgurus.form.custom_settings.block_heading : window.myappgurus.prm.form.block_heading}
${parseFloat(response.rating).toFixed(1)}/5.0
${reviews}
${response.count} ${window.myappgurus.form && window.myappgurus.form.custom_settings && window.myappgurus.form.custom_settings.subtitle2 ?
window.myappgurus.form.custom_settings.subtitle2 : window.myappgurus.prm.form.subtitle2}
${(writeReviewBtn == true) ? `
${window.myappgurus.form && window.myappgurus.form.custom_settings && window.myappgurus.form.custom_settings.review_btn ? window.myappgurus.form.custom_settings.review_btn : window.myappgurus.prm.form.review_btn}
` : ''}
`;
} else {
var reviewData = (writeReviewBtn == true) ? `
` : '';
}
if (document.querySelector(`#mag-product-review[data-product="${proId}"]`)) {
document.querySelector(`#mag-product-review[data-product="${proId}"]`).innerHTML = reviewData;
}
showAllReviews(proId, proHandle);
showReview();
reviewValueChange(prefillRatings);
formSubmit();
checkLogo();
showRatingWiseReviews();
cancelFormBtn();
countCharacters();
});
}
var countCharacters = () => {
addEventListener('keyup', () => {
var textarea = document.querySelector("textarea[name='description']");
var maxLength = 1500;
var charCount = textarea.value.length;
var charCountElement = document.querySelector('#charCount');
charCountElement.textContent = charCount + ' / ' + maxLength;
if (charCount > maxLength) {
textarea.value = textarea.value.slice(0, maxLength);
charCountElement.style.color = 'red';
} else {
charCountElement.style.color = 'black';
}
var textareaTitle = document.querySelector("input[name='title']");
var maxLengthTitle = 50;
var charCountTitle = textareaTitle.value.length;
var charCountElementTitle = document.querySelector('#charCountTitle');
charCountElementTitle.textContent = charCountTitle + ' / ' + maxLengthTitle;
if (charCountTitle > maxLengthTitle) {
textareaTitle.value = textareaTitle.value.slice(0, maxLengthTitle);
charCountElementTitle.style.color = 'red';
} else {
charCountElementTitle.style.color = 'black';
}
});
}
var cancelFormBtn = () => {
let cancelBtn = document.querySelector('#mag-cancel-btn-text');
if (cancelBtn) {
cancelBtn.addEventListener('click', () => {
document.querySelector('#erpReviewFrom').reset();
document.querySelector('[name="rating"]').value = '';
if (document.querySelector('[name="payment_review"]')) {
document.querySelector('[name="payment_review"]').value = '';
}
if (document.querySelector('[name="price_review"]')) {
document.querySelector('[name="price_review"]').value = '';
}
if (document.querySelector('[name="delivery_review"]')) {
document.querySelector('[name="delivery_review"]').value = '';
}
document.querySelectorAll('.bi-star-fill.mag-ratings').forEach(curr => {
curr.setAttribute('fill', 'none');
});
document.querySelectorAll('#erpReviewFrom span').forEach(span => {
span.textContent = '';
});
document.querySelector('.epr-review-form').classList.toggle('hide');
document.querySelector('.epr-review').scrollIntoView({ behavior: 'smooth', block: 'start' });
});
}
}
var formSubmit = () => {
let form = document.querySelector('#erpReviewFrom'),
fileExtension = [];
if (form) {
form.addEventListener('submit', (e) => {
e.preventDefault();
let proId = document.querySelector('#mag-product-review').getAttribute('data-product');
let name = (document.querySelector('#name')) ? document.querySelector('#name').value : '';
let email = (document.querySelector('#email')) ? document.querySelector('#email').value : '';
let title = (document.querySelector('#title')) ? document.querySelector('#title').value : '';
let description = (document.querySelector('#description')) ? document.querySelector('#description').value : '';
let namePattern = /^[a-zA-Z]*$/;
let emailPattern = /^[a-zA-Z0-9._%+-]+@[a-zA-Z]{3,63}\.[a-zA-Z]{2,3}$/;
document.querySelector('.mag-review-required').classList.add('hide');
(document.querySelector('.mag-name-value')) ? document.querySelector('.mag-name-value').innerHTML = '' : '';
(document.querySelector('.mag-email-value')) ? document.querySelector('.mag-email-value').innerHTML = '' : '';
(document.querySelector('.mag-title-value')) ? document.querySelector('.mag-title-value').innerHTML = '' : '';
(document.querySelector('.mag-description-value')) ? document.querySelector('.mag-description-value').innerHTML = '' : '';
(document.querySelector('.required-review-image')) ? document.querySelector('.required-review-image').innerHTML = '' : '';
if (customArrayData.allowVideoUploads == "1") {
fileExtension = ['jpeg', 'jpg', 'png', 'gif', 'svg', 'mp4', 'mov', 'webm', 'mkv'];
} else {
fileExtension = ['jpeg', 'jpg', 'png', 'gif', 'svg'];
}
if (document.querySelector('[name="rating"]').value == '') {
document.querySelector('.mag-review-required').classList.remove('hide');
} else if (document.querySelector('#review_image') && (document.querySelector('#review_image').value != '') && fileExtension.includes(document.querySelector('#review_image').value.split('.').pop().toLowerCase()) == false) {
document.querySelector('.mag-review-required').classList.add('hide');
document.querySelector('.required-review-image').innerHTML = window.myappgurus.prm.form.validation_message.file_type;
} else if (document.querySelector('#review_image')?.files[0]?.size > 2000000) {
document.querySelector('.mag-review-required').classList.add('hide');
document.querySelector('.required-review-image').innerHTML = window.myappgurus.prm.form.validation_message.file_size;
}
else if (!name && name.trim() == "" && window.myappgurus.prm.form_elements.name == "false") {
document.querySelector('.mag-name-value').innerHTML = "Name field is required.";
document.querySelector('#name').scrollIntoView({ behavior: 'smooth', block: 'start' });
}
else if (name && name.length > 50) {
document.querySelector('.mag-name-value').innerHTML = "Name field exceeds character limit.";
document.querySelector('#name').scrollIntoView({ behavior: 'smooth', block: 'start' });
}
else if (!email && email.trim() == "") {
document.querySelector('.mag-email-value').innerHTML = "Email field is required.";
document.querySelector('#email').scrollIntoView({ behavior: 'smooth', block: 'start' });
}
else if (email && email.length > 320) {
let email = document.querySelector('#email').value.split('@');
email[0].length > 64 ? document.querySelector('.mag-email-value').innerHTML = "Email field exceeds character limit." : document.querySelector('.mag-email-value').innerHTML = "";
email[1].length > 255 ? document.querySelector('.mag-email-value').innerHTML = "Email field exceeds character limit." : document.querySelector('.mag-email-value').innerHTML = "";
document.querySelector('#email').scrollIntoView({ behavior: 'smooth', block: 'start' });
}
else if (title && title.trim() == '') {
document.querySelector('.mag-title-value').innerHTML = "Title field is required.";
document.querySelector('#title').scrollIntoView({ behavior: 'smooth', block: 'start' });
}
else if (title && title.length > 150) {
document.querySelector('.mag-title-value').innerHTML = "Title field exceeds character limit.";
document.querySelector('#title').scrollIntoView({ behavior: 'smooth', block: 'start' });
}
else if (!description && description.trim() == "") {
document.querySelector('.mag-description-value').innerHTML = "Description field is required.";
document.querySelector('#description').scrollIntoView({ behavior: 'smooth', block: 'start' });
}
else if (description && description.length >= 1500) {
document.querySelector('.mag-description-value').innerHTML = "Description field exceeds character limit.";
document.querySelector('#description').scrollIntoView({ behavior: 'smooth', block: 'start' });
}
else {
(document.querySelector('#submit-btn-text')) ? document.querySelector('#submit-btn-text').innerHTML = window.myappgurus.prm.form.form_fields.submit_button_clicked : '';
if (form.getAttribute('data-id') == 'only_buyers') {
checkOnlyBuyers(form, email, proId);
} else {
submitReviewForm(form);
}
}
});
}
}
var checkEmailDomain = (emailInput, submitButton) => {
const emailValue = emailInput.value.trim();
const emailDomain = emailValue.split("@")[1] || "";
const restrictedDomains = customArrayData?.restrictedEmailDomains || []
const restrictedDomainMessage = "Email domain is not allowed";
const emailValueSpan = document.querySelector('.mag-email-value');
if (!emailValueSpan) {
return false;
}
emailInput.addEventListener('input', () => {
emailValueSpan.textContent = '';
submitButton.removeAttribute("disabled");
submitButton.classList.remove('not-click');
});
if (restrictedDomains.includes(emailDomain)) {
emailValueSpan.textContent = restrictedDomainMessage;
emailValueSpan.style.color = "red";
submitButton.setAttribute("disabled", "disabled");
return false;
} else {
emailValueSpan.textContent = '';
submitButton.removeAttribute("disabled");
return true;
}
};
var submitReviewForm = (formData) => {
document.querySelector('.mag-review-required').classList.add('hide');
(document.querySelector('.mag-name-value')) ? document.querySelector('.mag-name-value').innerHTML = '' : '';
(document.querySelector('.mag-email-value')) ? document.querySelector('.mag-email-value').innerHTML = '' : '';
(document.querySelector('.mag-title-value')) ? document.querySelector('.mag-title-value').innerHTML = '' : '';
(document.querySelector('.mag-description-value')) ? document.querySelector('.mag-description-value').innerHTML = '' : '';
document.querySelectorAll('.bi-star-fill.mag-ratings').forEach(element => {
element.classList.remove('filled');
});
(document.querySelector('.required-review-image')) ? document.querySelector('.required-review-image').innerHTML = '' : '';
document.querySelector('#submit-btn-text').classList.add('not-click');
let fd = new FormData(formData);
const emailInput = document.getElementById("email");
const submitButton = document.getElementById("submit-btn-text");
if (!checkEmailDomain(emailInput, submitButton)) {
return;
}
fetch(`${domain}erpReviewFrom`, {
method: "POST",
headers: {
'Accept': 'application/json',
'Authorization': `Bearer ${window.sessionToken}`
},
body: fd,
})
.then(res => res.json())
.then(response => {
if (response.status == 'review_exists') {
formData.reset();
document.querySelector('[name="rating"]').value = '';
if (document.querySelector('[name="payment_review"]')) {
document.querySelector('[name="payment_review"]').value = '';
}
if (document.querySelector('[name="price_review"]')) {
document.querySelector('[name="price_review"]').value = '';
}
if (document.querySelector('[name="delivery_review"]')) {
document.querySelector('[name="delivery_review"]').value = '';
}
document.querySelectorAll('.bi-star-fill.mag-ratings').forEach(curr => {
curr.setAttribute('fill', 'none');
});
document.querySelectorAll('.bi-star-fill.mag-ratings').forEach(curr => {
curr.setAttribute('fill', 'none');
});
document.querySelector('#submit-btn-text').classList.remove('not-click');
document.querySelector('#submit-btn-text').innerHTML = window.myappgurus.prm.form.form_fields.submit_btn;
document.querySelector('#charCountTitle').innerHTML = '0 / 50';
document.querySelector('#charCount').innerHTML = '0 / 1500';
document.querySelector('.epr-review-form').classList.add('hide');
document.querySelector('#alert-text').innerHTML = `
${window.myappgurus.form.success_message.success_msg3 ? window.myappgurus.form.success_message.success_msg3 : "Your existing review has been updated successfully."}
`;
document.querySelector('.epr-form-content-wrapp').scrollIntoView({ behavior: 'smooth', block: 'start' });
setTimeout(() => {
document.querySelector('#alert-text').innerHTML = '';
}, 3000);
}
else if (response.status == 'approval_status') {
formData.reset();
document.querySelector('[name="rating"]').value = '';
if (document.querySelector('[name="payment_review"]')) {
document.querySelector('[name="payment_review"]').value = '';
}
if (document.querySelector('[name="price_review"]')) {
document.querySelector('[name="price_review"]').value = '';
}
if (document.querySelector('[name="delivery_review"]')) {
document.querySelector('[name="delivery_review"]').value = '';
}
document.querySelectorAll('.bi-star-fill.mag-ratings').forEach(curr => {
curr.setAttribute('fill', 'none');
});
document.querySelectorAll('.bi-star-fill.mag-ratings').forEach(curr => {
curr.setAttribute('fill', 'none');
});
document.querySelector('#submit-btn-text').classList.remove('not-click');
document.querySelector('#submit-btn-text').innerHTML = window.myappgurus.prm.form.form_fields.submit_btn;
document.querySelector('#charCountTitle').innerHTML = '0 / 50';
document.querySelector('#charCount').innerHTML = '0 / 1500';
document.querySelector('.epr-review-form').classList.add('hide');
document.querySelector('#alert-text').innerHTML = `
${window.myappgurus.form.success_message.success_msg4 ? window.myappgurus.form.success_message.success_msg4 : "Your review have been submitted."}
`;
document.querySelector('.epr-form-content-wrapp').scrollIntoView({ behavior: 'smooth', block: 'start' });
setTimeout(() => {
document.querySelector('#alert-text').innerHTML = '';
}, 3000);
}
else if (response.status == 'success') {
formData.reset();
document.querySelector('[name="rating"]').value = '';
if (document.querySelector('[name="payment_review"]')) {
document.querySelector('[name="payment_review"]').value = '';
}
if (document.querySelector('[name="price_review"]')) {
document.querySelector('[name="price_review"]').value = '';
}
if (document.querySelector('[name="delivery_review"]')) {
document.querySelector('[name="delivery_review"]').value = '';
}
document.querySelectorAll('.bi-star-fill.mag-ratings').forEach(curr => {
curr.setAttribute('fill', 'none');
});
document.querySelectorAll('.bi-star-fill.mag-ratings').forEach(curr => {
curr.setAttribute('fill', 'none');
});
document.querySelector('#submit-btn-text').classList.remove('not-click');
document.querySelector('#submit-btn-text').innerHTML = window.myappgurus.prm.form.form_fields.submit_btn;
document.querySelector('#charCountTitle').innerHTML = '0 / 50';
document.querySelector('#charCount').innerHTML = '0 / 1500';
document.querySelector('.epr-review-form').classList.add('hide');
document.querySelector('#alert-text').innerHTML = `
${window.myappgurus.prm.form.form_fields.success_message}
`;
document.querySelector('.epr-form-content-wrapp').scrollIntoView({ behavior: 'smooth', block: 'start' });
setTimeout(() => {
document.querySelector('#alert-text').innerHTML = '';
}, 3000);
}
else if (response.status == 'media_added_successfully') {
formData.reset();
document.querySelector('[name="rating"]').value = '';
if (document.querySelector('[name="payment_review"]')) {
document.querySelector('[name="payment_review"]').value = '';
}
if (document.querySelector('[name="price_review"]')) {
document.querySelector('[name="price_review"]').value = '';
}
if (document.querySelector('[name="delivery_review"]')) {
document.querySelector('[name="delivery_review"]').value = '';
}
document.querySelectorAll('.bi-star-fill.mag-ratings').forEach(curr => {
curr.setAttribute('fill', 'none');
});
document.querySelectorAll('.bi-star-fill.mag-ratings').forEach(curr => {
curr.setAttribute('fill', 'none');
});
document.querySelector('#submit-btn-text').classList.remove('not-click');
document.querySelector('#submit-btn-text').innerHTML = window.myappgurus.prm.form.form_fields.submit_btn;
document.querySelector('#charCountTitle').innerHTML = '0 / 50';
document.querySelector('#charCount').innerHTML = '0 / 1500';
document.querySelector('.epr-review-form').classList.add('hide');
document.querySelector('#alert-text').innerHTML = `
${window.myappgurus.form.success_message.success_msg3 ? window.myappgurus.form.success_message.success_msg3 : "Your existing review has been updated successfully."}
`;
document.querySelector('.epr-form-content-wrapp').scrollIntoView({ behavior: 'smooth', block: 'start' });
setTimeout(() => {
document.querySelector('#alert-text').innerHTML = '';
}, 3000);
}
});
}
var reviewValueChange = (prefillRatings) => {
var prefillRatingStars = (category, rating) => {
if (rating) {
let stars = document.querySelectorAll(`.bi-star-fill.mag-ratings[data-rating='${category}']`);
let starcolor = (customArrayData.reviewStarcolor !== null && customArrayData.reviewStarcolor !== undefined) ? customArrayData.reviewStarcolor : 'orange';
stars.forEach((star, index) => {
if (index < parseInt(rating)) {
star.classList.add('prefilled');
star.setAttribute('fill', starcolor);
star.setAttribute('stroke', starcolor);
} else {
star.classList.add('prefilled');
star.setAttribute('fill', 'none');
star.setAttribute('stroke', starcolor);
}
});
document.getElementById(category).value = rating;
}
}
if (prefillRatings) {
for (let key in prefillRatings) {
if (prefillRatings.hasOwnProperty(key)) {
prefillRatingStars(key, prefillRatings[key]);
}
}
}
let reviews = document.querySelectorAll('.bi-star-fill.mag-ratings');
if (reviews) {
reviews.forEach(curr => {
curr.addEventListener('click', () => {
if (!curr.classList.contains('prefilled')) {
let val = curr.getAttribute('star-data'),
reviewType = curr.getAttribute('data-rating'),
starcolor = (customArrayData.reviewStarcolor !== null && customArrayData.reviewStarcolor !== undefined) ? customArrayData.reviewStarcolor : 'orange',
reviewRating = document.querySelectorAll(`.mag-ratings[data-rating="${reviewType}"]`);
reviewRating.forEach((curr, index) => {
if (index < parseInt(val)) {
curr.classList.add('filled');
curr.setAttribute('fill', starcolor);
curr.setAttribute('stroke', starcolor);
} else {
curr.classList.remove('filled');
curr.setAttribute('fill', 'none');
curr.setAttribute('stroke', starcolor);
}
});
document.querySelector(`[name="${reviewType}"]`).value = val;
document.querySelector('.mag-review-required').classList.add('hide');
}
});
curr.addEventListener('mouseover', () => {
if (!curr.classList.contains('prefilled')) {
let val = curr.getAttribute('star-data'),
reviewType = curr.getAttribute('data-rating'),
starcolor = (customArrayData.reviewStarcolor !== null && customArrayData.reviewStarcolor !== undefined) ? customArrayData.reviewStarcolor : 'orange',
reviewRating = document.querySelectorAll(`.mag-ratings[data-rating="${reviewType}"]`);
reviewRating.forEach((curr, index) => {
if (index < parseInt(val)) {
curr.classList.add('hovered');
curr.setAttribute('fill', starcolor);
curr.setAttribute('stroke', starcolor);
}
});
}
});
curr.addEventListener('mouseout', () => {
if (!curr.classList.contains('prefilled')) {
if (curr.classList.contains('hovered')) {
reviewType = curr.getAttribute('data-rating'),
starcolor = (customArrayData.reviewStarcolor !== null && customArrayData.reviewStarcolor !== undefined) ? customArrayData.reviewStarcolor : 'orange',
reviewRating = document.querySelectorAll(`.mag-ratings[data-rating="${reviewType}"]`);
reviewRating.forEach((curr) => {
if (!curr.classList.contains('filled')) {
curr.classList.remove('hovered');
curr.setAttribute('fill', 'none');
curr.setAttribute('stroke', starcolor);
}
});
}
}
});
});
}
};
var showReview = () => {
let reviewBtn = document.querySelectorAll('.epr-collaps-btn');
if (reviewBtn) {
reviewBtn.forEach(curr => {
curr.addEventListener('click', () => {
checkLogo();
document.querySelector('.epr-review-form').classList.toggle('hide');
});
});
}
}
var showAllReviews = (proId, proHandle) => {
if (customArrayData.reviewListingPattern[0] != 'slider') {
fetch(`${domain}getAllReviewToshow`, {
method: "POST",
headers: {
'Accept': 'application/json',
'Content-type': 'application/json',
'Authorization': `Bearer ${window.sessionToken}`
},
body: JSON.stringify({
proId: proId,
proHandle: proHandle,
shopId: shopId,
shopName: shopName,
sortingTypeValue: customArrayData.reviewListSorting,
}),
})
.then(res => res.json())
.then(response => {
switch (customArrayData.reviewListingPattern[0]) {
case 'list':
showReviewsOnFrontInList(response, customArrayData.reviewListSorting, null, null);
break;
case 'grid':
showReviewsOnFrontInGrid(response, customArrayData.reviewListSorting, null, null);
break;
default:
break;
}
});
} else {
fetch(`${domain}getAllReviewSlider`, {
method: "POST",
headers: {
'Accept': 'application/json',
'Content-type': 'application/json',
'Authorization': `Bearer ${window.sessionToken}`
},
body: JSON.stringify({
proId: proId,
proHandle: proHandle,
shopId: shopId,
shopName: shopName
}),
})
.then(res => res.json())
.then(response => {
showReviewsOnFrontInSlider(response.getData, 'product');
});
}
}
function hideContactInformation(text) {
if (text !== null) {
var pattern = /(\b\d{3}[-.\s]?\d{3}[-.\s]?\d{4}\b)|(\b\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,6}\b)/g;
var hiddenText = text.replace(pattern, function (match) {
var length = match.length;
return "*".repeat(length);
});
}
return hiddenText;
}
var showReviewsOnFrontInList = (response, sortingTypeValue, url, review) => {
if (response.getData.data == undefined) {
var responseData = response.getData;
} else {
var responseData = response.getData.data;
}
let targetClass = document.querySelector('#mag-product-review');
let proId = targetClass?.getAttribute('data-product');
let proHandle = targetClass?.getAttribute('data-product-handle');
let starcolor = (customArrayData.reviewStarcolor !== null && customArrayData.reviewStarcolor !== undefined) ? customArrayData.reviewStarcolor : 'orange';
let html = `${(responseData.length > 0) ? `` : ''}
`,
reviewPaginationFun = reviewPagination(response, url);
for (i = 0; i < responseData.length; i++) {
let starRating = '',
starColor = (customArrayData.reviewStarcolor) ? customArrayData.reviewStarcolor : 'orange',
reviewVerifiedFun = reviewVerified(responseData[i]),
reviewFooterFun = reviewFooter(responseData[i]);
date = formatDateAndRelativeTime(responseData[i].created_at);
let hiddenTitle = "";
let hiddenDescription = "";
if (customArrayData.restrictPersonalInfo == "1") {
hiddenTitle = hideContactInformation(responseData[i].title || '');
hiddenDescription = hideContactInformation(
responseData[i].description || ''
);
} else {
hiddenTitle = responseData[i].title || '';
hiddenDescription = responseData[i].description || '';
}
for (index = 0; index < 5; index++) {
if (index < Math.floor(responseData[i].rating) && Math.floor(responseData[i].rating) != 0) {
starRating += star('filled', starColor);
} else if ((responseData[i].rating - Math.floor(responseData[i].rating)) > 0 && index < Math.ceil(responseData[i].rating)) {
starRating += star('half-filled', starColor);
} else {
starRating += star('not-filled', starColor);
}
}
html += `
${(responseData[i].review_image !== null && responseData[i].review_image.trim() !== "")
?
checkFileType(getFirstImage(responseData[i].review_image)) == 'video'
?
`
`
:
`
)})
`
:
`
${(responseData[i].name?.trim() != '' && responseData[i].name?.trim() != undefined)
?
responseData[i].name?.trim().slice(0, 1)
:
'N'}
`
}
${(responseData[i].name) !== null ? responseData[i].name : ''}${reviewVerifiedFun}
${starRating}
${customArrayData.reviewDate !== undefined ? customArrayData.reviewDate == '1' ? `
${date.formattedDate}` : '' : ''}
${(responseData[i].title !== null) ? hiddenTitle : ''}
${responseData[i].description !== null ?
`
${hiddenDescription.length > 200
? `${hiddenDescription.substring(0, 200)}... ${window.myappgurus.form ? window.myappgurus.form.read_more : 'Read more'}
`
: `${hiddenDescription}
`}
${hiddenDescription}
`
: ``}
${(responseData[i].review_status == 'published' || responseData[i].review_status == 1 || responseData[i].review_status == 'all')
?
(responseData[i].replay !== null && responseData[i].replay?.trim() != '')
?
``
:
''
:
''}
${reviewFooterFun}
`;
}
html += "
";
if (response.getData.next_page_url != null || response.getData.prev_page_url != null) {
html += reviewPaginationFun;
}
if (document.querySelector('#epr-product-reviews')) {
document.querySelector('#epr-product-reviews').innerHTML = html;
}
if (document.querySelector('.see-all-reviews') && !document.querySelector('.see-all-reviews').classList.contains('hide')) {
document.querySelector('.see-all-reviews').addEventListener('click', function handleClick() {
document.querySelector('.see-all-reviews').classList.add('hide');
showAllReviews(proId, proHandle);
document.querySelector('#epr-product-reviews').scrollIntoView({ behavior: 'smooth', block: 'start' });
document.querySelector('.see-all-reviews').removeEventListener('click', handleClick);
});
}
showSocialMedia();
showWholeReply();
clickPagination('list', sortingTypeValue, review);
sortingReviews();
showWholeReviewDescription();
}
var showWholeReply = () => {
let readMoreBtn = document.querySelectorAll('.readMore');
if (readMoreBtn) {
readMoreBtn.forEach(curr => {
curr.addEventListener('click', () => {
let id = curr.getAttribute('data-id'),
reviewReply = document.querySelector(`.mag-comment-content[data-id="${id}"]`);
document.querySelector(`.readMore[data-id="${id}"]`).classList.toggle('hide');
if (!curr.classList.contains('hide')) {
reviewReply.querySelector('p').innerHTML = reviewReply.getAttribute('data-content');
document.querySelector(`.readMore[data-id="${id}"]`).innerHTML = window.myappgurus.form ? window.myappgurus.form.read_less : 'Read less';
} else {
reviewReply.querySelector('p').innerHTML = reviewReply.getAttribute('data-content').substring(0, 200) + '...';
document.querySelector(`.readMore[data-id="${id}"]`).innerHTML = window.myappgurus.form ? window.myappgurus.form.read_more : 'Read more';
}
});
});
}
}
var showReviewsOnFrontInGrid = (response, sortingTypeValue, url, review) => {
if (response.getData.data == undefined) {
var responseData = response.getData;
} else {
var responseData = response.getData.data;
}
let targetClass = document.querySelector('#mag-product-review');
let proId = targetClass?.getAttribute('data-product');
let proHandle = targetClass?.getAttribute('data-product-handle');
let starcolor = (customArrayData.reviewStarcolor !== null && customArrayData.reviewStarcolor !== undefined) ? customArrayData.reviewStarcolor : 'orange';
let html = `${(responseData.length > 0) ? `` : ''}
`,
reviewPaginationFun = reviewPagination(response, url);
for (i = 0; i < responseData.length; i++) {
let starRating = '',
starColor = (customArrayData.reviewStarcolor) ? customArrayData.reviewStarcolor : 'orange',
reviewVerifiedFun = reviewVerified(responseData[i]),
reviewFooterFun = reviewFooter(responseData[i]);
date = formatDateAndRelativeTime(responseData[i].created_at);
let hiddenTitle = "";
let hiddenDescription = "";
if (customArrayData.restrictPersonalInfo == "1") {
hiddenTitle = hideContactInformation(responseData[i].title);
hiddenDescription = hideContactInformation(
responseData[i].description
);
} else {
hiddenTitle = responseData[i].title;
hiddenDescription = responseData[i].description;
}
for (index = 0; index < 5; index++) {
if (index < Math.floor(responseData[i].rating) && Math.floor(responseData[i].rating) != 0) {
starRating += star('filled', starColor);
} else if ((responseData[i].rating - Math.floor(responseData[i].rating)) > 0 && index < Math.ceil(responseData[i].rating)) {
starRating += star('half-filled', starColor);
} else {
starRating += star('not-filled', starColor);
}
}
html += `
${(responseData[i].review_image !== null && responseData[i].review_image.trim() !== "")
?
checkFileType(getFirstImage(responseData[i].review_image)) == 'video'
?
`
`
:
`
)})
`
:
`
${(responseData[i].name?.trim() != '' && responseData[i].name?.trim() != undefined)
?
responseData[i].name?.trim().slice(0, 1)
:
'N'}
`
}
${(responseData[i].name) !== null ? responseData[i].name : ''}${reviewVerifiedFun}
${starRating}
${customArrayData.reviewDate !== undefined ? customArrayData.reviewDate == '1' ? `${date.formattedDate}` : '' : ''}
${(responseData[i].title !== null) ? hiddenTitle : ''}
${responseData[i].description !== null ?
`
${hiddenDescription.length > 200
? `${hiddenDescription.substring(0, 200)}... ${window.myappgurus.form ? window.myappgurus.form.read_more : 'Read more'}
`
: `${hiddenDescription}
`}
${hiddenDescription}
`
: ``}
${(responseData[i].review_status == 'published' || responseData[i].review_status == 1 || responseData[i].review_status == 'all')
?
(responseData[i].replay !== null && responseData[i].replay?.trim() != '')
?
``
:
''
:
''}
`;
}
html += "
";
if (response.getData.next_page_url != null || response.getData.prev_page_url != null) {
html += reviewPaginationFun;
}
if (document.querySelector('#epr-product-reviews')) {
document.querySelector('#epr-product-reviews').innerHTML = html;
}
if (document.querySelector('.see-all-reviews')) {
if (!document.querySelector('.see-all-reviews').classList.contains('hide')) {
document.querySelector('.see-all-reviews').addEventListener('click', function handleClick() {
document.documentElement.style.setProperty('--star-color', starcolor);
document.querySelector('.see-all-reviews').classList.add('hide');
showAllReviews(proId, proHandle);
document.querySelector('#epr-product-reviews').scrollIntoView({ behavior: 'smooth', block: 'start' });
document.querySelector('.see-all-reviews').removeEventListener('click', handleClick);
});
}
}
showSocialMedia();
showWholeReply();
clickPagination('grid', sortingTypeValue, review);
sortingReviews();
showWholeReviewDescription();
}
var clickPagination = (type, sortingTypeValue, review) => {
let pagination = document.querySelectorAll('.relative-inner')
proId = document.querySelector('#mag-product-review')?.getAttribute('data-product'),
proHandle = document.querySelector('#mag-product-review')?.getAttribute('data-product-handle');
if (pagination) {
pagination.forEach(curr => {
curr.addEventListener('click', () => {
let url = curr.getAttribute('page_url');
if (url != null) {
fetch(url, {
method: "POST",
headers: {
'Accept': 'application/json',
'Content-type': 'application/json',
'Authorization': `Bearer ${window.sessionToken}`
},
body: JSON.stringify({
proId: proId,
proHandle: proHandle,
shopId: shopId,
shopName: shopName,
sortingTypeValue: sortingTypeValue,
review: review,
}),
})
.then(res => res.json())
.then(response => {
document.querySelector('#epr-product-reviews').scrollIntoView({ behavior: 'smooth', block: 'start' });
switch (type) {
case 'list':
showReviewsOnFrontInList(response, sortingTypeValue, url, review);
break;
case 'grid':
showReviewsOnFrontInGrid(response, sortingTypeValue, url, review);
break;
default:
break;
}
})
}
});
})
}
}
var showReviewsOnFrontInSlider = (response, page) => {
let targetClass = document.querySelector('#mag-product-review');
let proId = targetClass?.getAttribute('data-product');
let proHandle = targetClass?.getAttribute('data-product-handle');
let linkElement = document.createElement('link'),
scriptElement = document.createElement('script');
linkElement.rel = 'stylesheet';
linkElement.href = 'https://cdn.jsdelivr.net/npm/swiper@11/swiper-bundle.min.css';
document.head.appendChild(linkElement);
scriptElement.src = 'https://cdn.jsdelivr.net/npm/swiper@11/swiper-bundle.min.js';
scriptElement.onload = function () {
initSwiper(response, page);
};
document.head.appendChild(scriptElement);
}
var initSwiper = (response, page) => {
let starcolor = (customArrayData.reviewStarcolor !== null && customArrayData.reviewStarcolor !== undefined) ? customArrayData.reviewStarcolor : 'orange';
let html = `${page == 'product' ? (response.length > 0) ? `` : '' : ''}
`;
for (i = 0; i < response.length; i++) {
let starRating = '',
starColor = (customArrayData.reviewStarcolor) ? customArrayData.reviewStarcolor : "currentColor",
reviewVerifiedFun = reviewVerified(response[i]),
date = formatDateAndRelativeTime(response[i].created_at);
imgdata = `${(response[i].review_image !== null && response[i].review_image.trim() !== "")
?
checkFileType(getFirstImage(response[i].review_image)) == 'video'
?
`
`
:
`
)})
`
:
`
${(response[i].name?.trim() != '' && response[i].name?.trim() != undefined)
?
response[i].name?.trim().slice(0, 1)
:
'N'}
`
}`;
let hiddenTitle = "";
let hiddenDescription = "";
if (customArrayData.restrictPersonalInfo == "1") {
hiddenTitle = hideContactInformation(response[i].title);
hiddenDescription = hideContactInformation(
response[i].description
);
} else {
hiddenTitle = response[i].title;
hiddenDescription = response[i].description;
}
for (index = 0; index < 5; index++) {
if (index < Math.floor(response[i].rating) && Math.floor(response[i].rating) != 0) {
starRating += star('filled', starColor);
} else if ((response[i].rating - Math.floor(response[i].rating)) > 0 && index < Math.ceil(response[i].rating)) {
starRating += star('half-filled', starColor);
} else {
starRating += star('not-filled', starColor);
}
}
html += `
${imgdata}
${customArrayData.reviewDate !== undefined ? customArrayData.reviewDate == '1' ? `
${date.formattedDate}` : '' : ''}
${(response[i].title !== null) ? hiddenTitle : ''}
${response[i].description !== null ?
`
${hiddenDescription.length > 200
? `${hiddenDescription.substring(0, 200)}... ${window.myappgurus.form ? window.myappgurus.form.read_more : 'Read more'}
`
: `${hiddenDescription}
`}
${hiddenDescription}
`
: ``}
`;
}
html += `
${response.length > 0 ? `
` : ''}
`;
if (page == 'all') {
if (response.length != 0) {
let swiperSlider = `
${html}
${(__st.a !== 82898092358) ? (customArrayData.removeWaterMark != "1") ? `
` : '' : ''}`;
let swiperSliderEle = appendElementInHtml(swiperSlider);
document.querySelector('main').insertAdjacentElement('beforeend', swiperSliderEle);
}
} else if (page == 'product') {
if (document.querySelector('#epr-product-reviews')) {
document.querySelector('#epr-product-reviews').innerHTML = html;
}
sortingReviews();
} else if (page == 'customstore') {
if (document.querySelector('.mag-all-reviews')) {
document.querySelector('.mag-all-reviews').innerHTML = html;
}
}
if (__st.a == '80656499020') {
document.querySelector('.mag-logo-image').style.display = 'none';
}
var swiper = new Swiper(".mySwiper", {
slidesPerView: 1,
spaceBetween: 10,
autoplay: {
delay: window.myappgurus.prm.slider_duration * 1000,
disableOnInteraction: false,
},
navigation: {
nextEl: ".swiper-button-next",
prevEl: ".swiper-button-prev",
},
pagination: {
el: ".swiper-pagination",
clickable: true,
},
breakpoints: {
640: {
slidesPerView: 1,
},
768: {
slidesPerView: 3,
},
1024: {
slidesPerView: 3,
},
},
});
if (document.querySelector('.see-all-reviews') && !document.querySelector('.see-all-reviews').classList.contains('hide')) {
document.querySelector('.see-all-reviews').addEventListener('click', function handleClick() {
document.querySelector('.see-all-reviews').classList.add('hide');
showAllReviews(proId, proHandle);
document.querySelector('#epr-product-reviews').scrollIntoView({ behavior: 'smooth', block: 'start' });
document.querySelector('.see-all-reviews').removeEventListener('click', handleClick);
});
}
showWholeReviewDescription();
}
var showSocialMedia = () => {
let shareReview = document.querySelectorAll('[data-toggle="collapse"]');
if (shareReview) {
shareReview.forEach(curr => {
curr.addEventListener('click', () => {
let id = curr.getAttribute('data-id');
document.querySelector(`#collapseExample_${id}`).classList.toggle('hide')
});
});
}
}
var sortingReviews = () => {
let sortingType = document.querySelector('.mag-select-menu'),
targetClass = document.querySelector('#mag-product-review'),
sortingTypeOptions = document.querySelectorAll('.mag-select-menu .options .option'),
proId = targetClass?.getAttribute('data-product'),
proHandle = targetClass?.getAttribute('data-product-handle');
if (sortingType) {
sortingType.addEventListener('click', () => {
sortingType.classList.toggle('active');
sortingType.querySelector('ul.options').removeAttribute('style');
});
}
if (sortingTypeOptions) {
sortingTypeOptions.forEach(curr => {
curr.addEventListener('click', () => {
let sortingTypeValue = curr.getAttribute('data-id');
if (customArrayData.reviewListingPattern[0] == 'slider') {
fetch(`${domain}getSortingReviewDataSlider`, {
method: "POST",
headers: {
'Accept': 'application/json',
'Content-type': 'application/json',
'Authorization': `Bearer ${window.sessionToken}`
},
body: JSON.stringify({
proId: proId,
proHandle: proHandle,
shopId: shopId,
shopName: shopName,
sortingTypeValue: sortingTypeValue,
}),
})
.then(res => res.json())
.then(response => {
showReviewsOnFrontInSlider(response.getData, 'product');
});
} else {
fetch(`${domain}getSortingReviewData`, {
method: "POST",
headers: {
'Accept': 'application/json',
'Content-type': 'application/json',
'Authorization': `Bearer ${window.sessionToken}`
},
body: JSON.stringify({
proId: proId,
proHandle: proHandle,
shopId: shopId,
shopName: shopName,
sortingTypeValue: sortingTypeValue,
}),
})
.then(res => res.json())
.then(response => {
switch (customArrayData.reviewListingPattern[0]) {
case 'list':
showReviewsOnFrontInList(response, sortingTypeValue, null, null);
break;
case 'grid':
showReviewsOnFrontInGrid(response, sortingTypeValue, null, null);
break;
default:
break;
}
});
}
});
});
}
}
authenticate();
});
${(responseData[i].replay?.length > 200) ? `${responseData[i].replay.substring(0, 200)}...` : responseData[i].replay}
${(responseData[i].replay?.length > 200) ? `` : ''}