diff --git a/blocks/applyloanform/applyloanform.js b/blocks/applyloanform/applyloanform.js index a08c9bb5e6..ebf0091800 100644 --- a/blocks/applyloanform/applyloanform.js +++ b/blocks/applyloanform/applyloanform.js @@ -7,7 +7,7 @@ import { validationJSFunc } from './validation.js'; import AirDatepicker from '../datepickerlib/datepickerlib.js'; import Popper from '../datepickerlib/popper.js'; import { buttonCLick } from './loanformapi.js'; -import { fetchAPI } from '../../scripts/scripts.js'; +import { CFApiCall, fetchAPI } from '../../scripts/scripts.js'; export default async function decorate(block) { const cfURL = block.textContent.trim(); @@ -32,13 +32,6 @@ export default async function decorate(block) { } } -export async function CFApiCall(cfurl) { - const response = await fetchAPI('GET', cfurl); - const responseJson = await response.json(); - return responseJson; -} - - function applyLoanFormJson(data) { var mainObj = {}; diff --git a/blocks/aprcalculator/aprcalculator.js b/blocks/aprcalculator/aprcalculator.js index de80e6f90d..620b3829f3 100644 --- a/blocks/aprcalculator/aprcalculator.js +++ b/blocks/aprcalculator/aprcalculator.js @@ -1,13 +1,13 @@ -import { fetchAPI } from '../../scripts/scripts.js'; +import { calculatorFlatStrLogic, CFApiCall, fetchAPI } from '../../scripts/scripts.js'; import { homeLoanCalcFunc } from '../emiandeligiblitycalc/homeloancalculators.js'; import { homeloanCalHTML } from '../homeloancalculatorv2/templatehtmlv2.js'; export default async function decorate(block) { const cfURL = block.textContent.trim(); - const cfRepsonse = await CFApiCall(cfURL); - const repsonseData = cfRepsonse.data[0].data; - const jsonResponseData = JSON.parse(repsonseData); + const cfRepsonse = cfURL && await CFApiCall(cfURL); + const repsonseData = cfRepsonse.data; + const jsonResponseData = calculatorFlatStrLogic(repsonseData); block.innerHTML = homeloanCalHTML(jsonResponseData); @@ -34,12 +34,6 @@ export default async function decorate(block) { } } -export async function CFApiCall(cfurl) { - const response = await fetchAPI('GET', cfurl); - const responseJson = await response.json(); - return responseJson; -} - function onloadAPRCalc() { const isAprCalculator = document.querySelector('.homeloancalculator .apr'); if (isAprCalculator) { diff --git a/blocks/authorisedagencies/authorisedagencies.js b/blocks/authorisedagencies/authorisedagencies.js index 8f3dae5ae4..9439abb6d1 100644 --- a/blocks/authorisedagencies/authorisedagencies.js +++ b/blocks/authorisedagencies/authorisedagencies.js @@ -1,9 +1,9 @@ -import { fetchAPI, targetObject } from '../../scripts/scripts.js'; +import { CFApiCall, fetchAPI, targetObject } from '../../scripts/scripts.js'; import { ctaClickInteraction } from '../../dl.js'; export default async function decorate(block) { const cfURL = block.textContent.trim(); - const cfRepsonse = await fetchApiCall(cfURL); + const cfRepsonse = await CFApiCall(cfURL); const repsonseData = cfRepsonse.data; const result = Object.groupBy(repsonseData, ({ Location }) => { const lowercaseLocation = Location.toLowerCase(); @@ -158,8 +158,3 @@ export default async function decorate(block) { // }) }; } -export async function fetchApiCall(cfurl) { - const response = await fetchAPI('GET', cfurl); - const responseJson = await response.json(); - return responseJson; -} diff --git a/blocks/branchcarousel/branchcarousel.js b/blocks/branchcarousel/branchcarousel.js index 07e0bc0156..d3f10b7a4c 100644 --- a/blocks/branchcarousel/branchcarousel.js +++ b/blocks/branchcarousel/branchcarousel.js @@ -1,4 +1,4 @@ -import { fetchAPI } from '../../scripts/scripts.js'; +import { CFApiCall, fetchAPI } from '../../scripts/scripts.js'; import { setLocationObj } from '../moredetailsaddress/moredetailsaddress.js'; export default async function decorate(block) { @@ -25,8 +25,3 @@ export default async function decorate(block) { block.classList.add('dp-none'); } -export async function CFApiCall(linkURL) { - const response = await fetchAPI('GET', linkURL); - const responseJson = await response.json(); - return responseJson; -} diff --git a/blocks/branchkeyfeatures/branchkeyfeatures.js b/blocks/branchkeyfeatures/branchkeyfeatures.js index ba1b290d1a..5f4d9961a4 100644 --- a/blocks/branchkeyfeatures/branchkeyfeatures.js +++ b/blocks/branchkeyfeatures/branchkeyfeatures.js @@ -1,4 +1,4 @@ -import { fetchAPI } from '../../scripts/scripts.js'; +import { CFApiCall, fetchAPI } from '../../scripts/scripts.js'; import { featureDropDownClick } from '../keyfeatures/keyfeatures.js'; import { setLocationObj } from '../moredetailsaddress/moredetailsaddress.js'; @@ -52,9 +52,3 @@ export default async function decorate(block) { block.classList.add('dp-none'); } - -export async function CFApiCall(linkURL) { - const response = await fetchAPI('GET', linkURL); - const responseJson = await response.json(); - return responseJson; -} diff --git a/blocks/branchlocator/branchlocator-biz.js b/blocks/branchlocator/branchlocator-biz.js index 0121a9b976..ca4bfc2ae6 100644 --- a/blocks/branchlocator/branchlocator-biz.js +++ b/blocks/branchlocator/branchlocator-biz.js @@ -107,6 +107,11 @@ async function getStateCity(lat, lng) { setLocationObj.geoInfo.city = city.long_name; setLocationObj.geoInfo.state = region.long_name; setLocationObj.geoInfo.country = country.long_name; + + /* setLocationObj.getExcelData[region.long_name].filter((each) => { + return each['Location'].includes(city.long_name); + }); */ + resolve(); } else { reject('No results found'); diff --git a/blocks/branchlocator/branchlocator.js b/blocks/branchlocator/branchlocator.js index 1b906f803f..b53768703c 100644 --- a/blocks/branchlocator/branchlocator.js +++ b/blocks/branchlocator/branchlocator.js @@ -1,4 +1,4 @@ -import { branchURLStr, fetchAPI } from '../../scripts/scripts.js'; +import { branchURLStr, CFApiCall, fetchAPI } from '../../scripts/scripts.js'; import { dropDownStateCity, locateMeClick, onloadBranchLocator } from './branchlocator-biz.js'; import { setLocationObj } from './branchlocator-init.js'; @@ -93,12 +93,6 @@ export function innerBranchFunc(branchhList) { return innerBranch; } -export async function CFApiCall(cfurl) { - const response = await fetchAPI('GET', cfurl); - const responseJson = await response.json(); - return responseJson; -} - export default async function decorate(block) { const props = Array.from(block.children, (row) => row.firstElementChild); diff --git a/blocks/breadcrumb/breadcrumb.js b/blocks/breadcrumb/breadcrumb.js index df3465490a..ceb1401996 100644 --- a/blocks/breadcrumb/breadcrumb.js +++ b/blocks/breadcrumb/breadcrumb.js @@ -73,7 +73,7 @@ export default async function decorate(block) { 'aria-label': 'Breadcrumb', }); - if (multiText && multiUrl) { + if (multiText.innerText?.trim() && multiUrl.innerText?.trim()) { const breadcrumbsText = []; const multiUrls = multiUrl.innerText.trim().replace(/~/g, '/').split(','); multiText.innerText.trim().split(',').forEach((text, index) => { diff --git a/blocks/calculatorsection/calculatorsection.js b/blocks/calculatorsection/calculatorsection.js index 75fbf7bb75..9f5a8e3195 100644 --- a/blocks/calculatorsection/calculatorsection.js +++ b/blocks/calculatorsection/calculatorsection.js @@ -1,4 +1,4 @@ -import { fetchAPI } from '../../scripts/scripts.js'; +import { calculatorFlatStrLogic, CFApiCall, fetchAPI } from '../../scripts/scripts.js'; import { homeLoanCalcFunc } from '../emiandeligiblitycalc/homeloancalculators.js'; import { renderCalculatorData } from './renderdatafunc.js'; import { homeloanCalHTML } from '../homeloancalculatorv2/templatehtmlv2.js'; @@ -6,9 +6,9 @@ import { homeloanCalHTML } from '../homeloancalculatorv2/templatehtmlv2.js'; export default async function decorate(block) { const cfURL = block.textContent.trim(); - const cfRepsonse = await CFApiCall(cfURL); - const repsonseData = cfRepsonse.data[0].data; - const jsonResponseData = JSON.parse(repsonseData); + const cfRepsonse = cfURL && await CFApiCall(cfURL); + const repsonseData = cfRepsonse.data; + const jsonResponseData = calculatorFlatStrLogic(repsonseData); block.innerHTML = homeloanCalHTML(jsonResponseData); @@ -39,12 +39,6 @@ export default async function decorate(block) { } } -export async function CFApiCall(cfurl) { - const response = await fetchAPI('GET', cfurl); - const responseJson = await response.json(); - return responseJson; -} - export function readMoreFucn(block) { document.querySelector('.discalimer-details').classList.remove('dp-none'); if (block.querySelector('.discalimer-calc')) { diff --git a/blocks/code/code.js b/blocks/code/code.js index 631a1183d0..9a7bfce353 100644 --- a/blocks/code/code.js +++ b/blocks/code/code.js @@ -1,5 +1,5 @@ import { decorateIcons } from "../../scripts/aem.js"; -import { decoratePlaceholder } from "../../scripts/scripts.js"; +import { decodeHtmlSymbols, decoratePlaceholder } from "../../scripts/scripts.js"; import { mobileHeaderAnalytics } from "./code-analytics.js"; import { decorateTable } from "./table.js"; export default async function decorate(block) { @@ -9,7 +9,7 @@ export default async function decorate(block) { decorateTable(block) return block } - const titleData = block.children[0]?.querySelector('p')?.innerHTML.trim().replaceAll('<', '<').replaceAll('>', '>') || ''; + const titleData = decodeHtmlSymbols(block.children[0]?.querySelector('p')?.innerHTML.trim() || ''); block.innerHTML = ''; if (titleData) { const titleElement = document.createElement('div'); diff --git a/blocks/gstcalculator/gstcalculator.js b/blocks/gstcalculator/gstcalculator.js index 22fdbed604..f390cdaf71 100644 --- a/blocks/gstcalculator/gstcalculator.js +++ b/blocks/gstcalculator/gstcalculator.js @@ -1,18 +1,17 @@ -import { currenyCommaSeperation, fetchAPI } from '../../scripts/scripts.js'; +import { calculatorFlatStrLogic, CFApiCall, currenyCommaSeperation, fetchAPI } from '../../scripts/scripts.js'; import { homeLoanCalcFunc } from '../emiandeligiblitycalc/homeloancalculators.js'; import { homeloanCalHTML } from '../homeloancalculatorv2/templatehtmlv2.js'; export default async function decorate(block) { const cfURL = block.textContent.trim(); - const cfRepsonse = await CFApiCall(cfURL); - const repsonseData = cfRepsonse.data[0].data; - const jsonResponseData = JSON.parse(repsonseData); + const cfRepsonse = cfURL && await CFApiCall(cfURL); + const repsonseData = cfRepsonse.data; + const jsonResponseData = calculatorFlatStrLogic(repsonseData); block.innerHTML = homeloanCalHTML(jsonResponseData); - let elgCalDiv; let - elgOverlay; +let elgCalDiv; let elgOverlay; try { elgCalDiv = document.querySelector('.home-page-calculator-call-xf'); @@ -34,11 +33,6 @@ export default async function decorate(block) { } } -export async function CFApiCall(cfurl) { - const response = await fetchAPI('GET', cfurl); - const responseJson = await response.json(); - return responseJson; -} function onloadGSTCalc() { const isGstCalculator = document.querySelector('.homeloancalculator .gst'); diff --git a/blocks/homeloancalculatorv2/homeloancalculatorv2.js b/blocks/homeloancalculatorv2/homeloancalculatorv2.js index a098af1c2e..cdcfc34455 100644 --- a/blocks/homeloancalculatorv2/homeloancalculatorv2.js +++ b/blocks/homeloancalculatorv2/homeloancalculatorv2.js @@ -3,17 +3,16 @@ import { firstTabActive } from "./commonfile.js"; */ import { homeloanCalHTML } from './templatehtmlv2.js'; import { homeLoanCalcFunc } from './homeloancalculators.js'; import { calculatorTypeTabClick, mainTabClick, renderEmiEligibility } from './combineemieligibility.js'; -import { fetchAPI } from '../../scripts/scripts.js'; +import { calculatorFlatStrLogic, CFApiCall, fetchAPI } from '../../scripts/scripts.js'; -let calculatorType; let emiCalDiv; let - emiOverlay; +let calculatorType; let emiCalDiv; let emiOverlay; export default async function decorate(block) { const cfURL = block.textContent.trim(); const cfRepsonse = cfURL && await CFApiCall(cfURL); - const repsonseData = cfRepsonse && cfRepsonse.data[0].data; - const jsonResponseData = repsonseData && JSON.parse(repsonseData); + const repsonseData = cfRepsonse.data; + const jsonResponseData = calculatorFlatStrLogic(repsonseData); if (!jsonResponseData) return; @@ -63,12 +62,6 @@ export default async function decorate(block) { } } -export async function CFApiCall(cfurl) { - // const cfModification = cfurl?.replace("/content/dam/", "/api/assets/"); - const response = await fetchAPI('GET', cfurl); - const responseJson = await response.json(); - return responseJson; -} /* export function homeLoancalculatorCallXf() { document.querySelectorAll("[data-teaserv2-xf='home-page-calculator-call-xf']") && diff --git a/blocks/homeloancalculatorv2/templatehtmlv2.js b/blocks/homeloancalculatorv2/templatehtmlv2.js index 1f698861e0..4d2d6d66a8 100644 --- a/blocks/homeloancalculatorv2/templatehtmlv2.js +++ b/blocks/homeloancalculatorv2/templatehtmlv2.js @@ -7,7 +7,7 @@ export function homeloanCalHTML(callJson) { buttonLink2 = callJson.button2link.replace('DWEB', 'MWEB'); } - const salaried = callJson.salaried?.salariedcheck + const salaried = callJson.salaried?.salariedcheck == 'true' ? `
  • @@ -32,7 +32,7 @@ export function homeloanCalHTML(callJson) {
  • ` : ''; - const business = callJson.business?.businesscheck + const business = callJson.business?.businesscheck == 'true' ? `
  • @@ -59,7 +59,7 @@ export function homeloanCalHTML(callJson) { : ''; let emiinputdiv = ''; - callJson.chechboxemiobj.chechboxemi + callJson.chechboxemiobj.chechboxemi == 'true' && callJson.chechboxemiobj.loanamout.forEach((each, index) => { emiinputdiv += `
    @@ -89,7 +89,7 @@ export function homeloanCalHTML(callJson) { }); let eligibilityinputdiv = ''; - callJson.chechboxelibilityobj.chechboxemi + callJson.chechboxelibilityobj.chechboxemi == 'true' && callJson.chechboxelibilityobj.loanamout.forEach((each, index) => { eligibilityinputdiv += `
    @@ -135,7 +135,7 @@ export function homeloanCalHTML(callJson) {
    ` : ''; - const emidiv = callJson.chechboxemiobj.chechboxemi + const emidiv = callJson.chechboxemiobj.chechboxemi == 'true' ? `
    @@ -167,7 +167,7 @@ export function homeloanCalHTML(callJson) {
    ` : ''; - const eligibilitydiv = callJson.chechboxelibilityobj.chechboxemi + const eligibilitydiv = callJson.chechboxelibilityobj.chechboxemi == 'true' ? `
    diff --git a/blocks/moredetailsaddress/moredetailsaddress.js b/blocks/moredetailsaddress/moredetailsaddress.js index 9e0d16dd2b..4135ae24a1 100644 --- a/blocks/moredetailsaddress/moredetailsaddress.js +++ b/blocks/moredetailsaddress/moredetailsaddress.js @@ -1,19 +1,19 @@ -import { fetchAPI, getDay } from '../../scripts/scripts.js'; +import { CFApiCall, fetchAPI, getDay } from "../../scripts/scripts.js"; export const setLocationObj = {}; const locationInLatLan = {}; -setLocationObj.stateLi = ''; -setLocationObj.cityLi = ''; -setLocationObj.lat = ''; -setLocationObj.lng = ''; +setLocationObj.stateLi = ""; +setLocationObj.cityLi = ""; +setLocationObj.lat = ""; +setLocationObj.lng = ""; setLocationObj.cityhash = {}; -setLocationObj.address = ''; +setLocationObj.address = ""; setLocationObj.geoInfo = { - city: '', - state: '', - country: '', - location: '', - locationcode: '', + city: "", + state: "", + country: "", + location: "", + locationcode: "", }; export default async function decorate(block) { @@ -26,14 +26,14 @@ export default async function decorate(block) { // const jsonResponseData = JSON.parse(urlRepoonse?.data[0]?.branchlocatorobj); const jsonResponseData = urlRepoonse?.data; - if (sessionStorage.getItem('data')) { - setLocationObj.getExcelData = JSON.parse(sessionStorage.getItem('data')); + if (sessionStorage.getItem("data")) { + setLocationObj.getExcelData = JSON.parse(sessionStorage.getItem("data")); } else { setLocationObj.getExcelData = dropDownStateCity(jsonResponseData); - sessionStorage.setItem('data', JSON.stringify(setLocationObj.getExcelData)); + sessionStorage.setItem("data", JSON.stringify(setLocationObj.getExcelData)); } - image?.querySelector('picture > img')?.setAttribute('alt', imagealt?.textContent?.trim() || ''); + image?.querySelector("picture > img")?.setAttribute("alt", imagealt?.textContent?.trim() || ""); const html = `
    @@ -54,7 +54,7 @@ export default async function decorate(block) { export function returnLatLan() { return new Promise((resolve, reject) => { - if ('geolocation' in navigator) { + if ("geolocation" in navigator) { // Prompt user for permission to access their location navigator.geolocation.getCurrentPosition( // Success callback function @@ -70,12 +70,12 @@ export function returnLatLan() { (error) => { resolve(error); // Handle errors, e.g. user denied location sharing permissions - console.error('Error getting user location:', error); - }, + console.error("Error getting user location:", error); + } ); } else { // Geolocation is not supported by the browser - console.error('Geolocation is not supported by this browser.'); + console.error("Geolocation is not supported by this browser."); } }); } @@ -86,7 +86,7 @@ async function getStateCity(lat, lng) { .then(async (response) => { response = await response.json(); const { results } = response; - let reviewRating = ''; + let reviewRating = ""; if (results[0]) { for (let j = 0; j < results.length; j++) { if (results[j].place_id) { @@ -102,7 +102,7 @@ async function getStateCity(lat, lng) { resolve(); } else { - reject('No results found'); + reject("No results found"); } }) .catch((err) => { @@ -114,7 +114,7 @@ async function getStateCity(lat, lng) { function getStateName(lat, lan) { return new Promise((resolve, reject) => { - fetchAPI('GET', `https://maps.googleapis.com/maps/api/geocode/json?latlng=${lat},${lan}&sensor=true&key=AIzaSyDx1HwnCLjSSIm_gADqaYAZhSBh7hgcwTQ`) + fetchAPI("GET", `https://maps.googleapis.com/maps/api/geocode/json?latlng=${lat},${lan}&sensor=true&key=AIzaSyDx1HwnCLjSSIm_gADqaYAZhSBh7hgcwTQ`) .then((res) => { resolve(res); }) @@ -143,9 +143,13 @@ export function dropDownStateCity(response) { async function getReviewRating(placeID) { return new Promise((resolve, reject) => { // https://maps.googleapis.com/maps/api/place/details/json?place_id=${placeID}&key=AIzaSyDx1HwnCLjSSIm_gADqaYAZhSBh7hgcwTQ - fetchAPI('GET', `/content/piramalfinance/api/mapapi.json?place_id=${placeID}&key=AIzaSyDx1HwnCLjSSIm_gADqaYAZhSBh7hgcwTQ`) // api for the get request - .then((response) => response.json()) - .then((data) => resolve(data)).catch((error) => console.log(error)); + fetchAPI("GET", `/content/piramalfinance/api/mapapi.json?place_id=${placeID}&key=AIzaSyDx1HwnCLjSSIm_gADqaYAZhSBh7hgcwTQ`) // api for the get request + .then((response) => response.text()) + .then((data) => { + const newData = data.replace(/\"/g,'/"') + resolve(newData) + }) + .catch((error) => console.log(error)); /* fetchAPI('GET', `https://maps.googleapis.com/maps/api/place/details/json?place_id=${setLocationObj.placeid}&key=AIzaSyDx1HwnCLjSSIm_gADqaYAZhSBh7hgcwTQ`).then((res)=>{ resolve(res); @@ -156,12 +160,6 @@ async function getReviewRating(placeID) { }); } -export async function CFApiCall(cfurl) { - const response = await fetchAPI('GET', cfurl); - const responseJson = await response.json(); - return responseJson; -} - /* async function onbranchDetails(block) { let locationCodeURL = location.href.split("/").pop().split("-").pop(); @@ -226,21 +224,19 @@ async function onbranchDetails(block) { const searchBranchURL = location.href; // let searchBranchURL = "https://www.piramalfinance.com/branch-locator/loans-in-anakapalle-andhra-pradesh-6391"; - const splitSearch = searchBranchURL.split('/').pop(); - if (splitSearch.includes('loans-in')) { - const currentLocation = searchBranchURL.split('/').pop().split('-').pop(); + const splitSearch = searchBranchURL.split("/").pop(); + if (splitSearch.includes("loans-in")) { + const currentLocation = searchBranchURL.split("/").pop().split("-").pop(); const flatLocationData = Object.values(setLocationObj.getExcelData).flat(); // Flattening the nested arrays - const foundLocation = flatLocationData.find((location) => location['Location Code'] == currentLocation); - const { - State, City, 'Location Code': locationCode, Location, Latitude, Longitude, Address, Pincode, 'On Page Content': pageContent, - } = foundLocation; + const foundLocation = flatLocationData.find((location) => location["Location Code"] == currentLocation); + const { State, City, "Location Code": locationCode, Location, Latitude, Longitude, Address, Pincode, "On Page Content": pageContent } = foundLocation; setLocationObj.geoInfo.state = State; setLocationObj.geoInfo.city = City; setLocationObj.geoInfo.locationcode = locationCode; setLocationObj.geoInfo.location = Location; setLocationObj.lat = Latitude; setLocationObj.lng = Longitude; - setLocationObj.geoInfo.country = 'India'; // Country + setLocationObj.geoInfo.country = "India"; // Country setLocationObj.address = Address; setLocationObj.pincode = Pincode; setLocationObj.pagecontent = pageContent; @@ -254,12 +250,12 @@ async function onbranchDetails(block) { if (locationInLatLan.lat && locationInLatLan.lng) { setLocationObj.distance = calculateDistance(setLocationObj.lat, setLocationObj.lng, locationInLatLan.lat, locationInLatLan.lng); if (setLocationObj.distance.toFixed() <= 40) { - document.querySelectorAll('.address-info ul li')[2].innerText = `${setLocationObj.distance.toFixed()} Km away from your location`; + document.querySelectorAll(".address-info ul li")[2].innerText = `${setLocationObj.distance.toFixed()} Km away from your location`; } else { - document.querySelectorAll('.address-info ul li')[2].remove(); + document.querySelectorAll(".address-info ul li")[2].remove(); } } else { - document.querySelectorAll('.address-info ul li')[2].remove(); + document.querySelectorAll(".address-info ul li")[2].remove(); } }); @@ -306,13 +302,13 @@ function sortingNearestBranch(lat, lng, data) { } function renderData() { - document.querySelector('.address-title h1').innerText = setLocationObj.geoInfo.location; - document.querySelector('.address-desktop p').innerText = setLocationObj.address; - document.querySelector('.address-mobile p').innerText = setLocationObj.address; + document.querySelector(".address-title h1").innerText = setLocationObj.geoInfo.location; + document.querySelector(".address-desktop p").innerText = setLocationObj.address; + document.querySelector(".address-mobile p").innerText = setLocationObj.address; const currentDay = getDay(); setLocationObj.working?.forEach((element) => { if (element.includes(currentDay)) { - document.querySelector('.address-timing p').innerText = `${element}`; + document.querySelector(".address-timing p").innerText = `${element}`; } }); } @@ -322,52 +318,58 @@ function reviewRender() { if (!ratingSpan) { return false; } - document.querySelector('.branchcustomer-review-cards').querySelector('.carousel-inner').innerHTML = ratingSpan; - const reviewCards = document.querySelector('.branchcustomer-review-cards').querySelector('.carousel-inner').querySelectorAll('.carousel-item'); - const currentNextButton = document.querySelector('.branchcustomer-review-cards').querySelector('.glider-next'); - const currentPrevButton = document.querySelector('.branchcustomer-review-cards').querySelector('.glider-prev'); + document.querySelector(".branchcustomer-review-cards").querySelector(".carousel-inner").innerHTML = ratingSpan; + const reviewCards = document.querySelector(".branchcustomer-review-cards").querySelector(".carousel-inner").querySelectorAll(".carousel-item"); + const currentNextButton = document.querySelector(".branchcustomer-review-cards").querySelector(".glider-next"); + const currentPrevButton = document.querySelector(".branchcustomer-review-cards").querySelector(".glider-prev"); const observer = new IntersectionObserver((entries) => { - entries.forEach((entry) => { - const intersecting = entry.isIntersecting; - if (intersecting) { - new Glider(entry.target, { - slidesToShow: 1, - slidesToScroll: 1, - draggable: true, - scrollLock: true, - arrows: { - prev: currentPrevButton, - next: currentNextButton, - }, - responsive: [ - { breakpoint: 767, settings: { slidesToShow: 2, slidesToScroll: 1 } }, - { - breakpoint: 1025, - settings: { - slidesToShow: 3, slidesToScroll: 1, scrollLock: true, draggable: true, - }, + entries.forEach( + (entry) => { + const intersecting = entry.isIntersecting; + if (intersecting) { + new Glider(entry.target, { + slidesToShow: 1, + slidesToScroll: 1, + draggable: true, + scrollLock: true, + arrows: { + prev: currentPrevButton, + next: currentNextButton, }, - ], - }); - // observer.unobserve(entry.target); - } - }, { rootMargin: '50px' }); + responsive: [ + { breakpoint: 767, settings: { slidesToShow: 2, slidesToScroll: 1 } }, + { + breakpoint: 1025, + settings: { + slidesToShow: 3, + slidesToScroll: 1, + scrollLock: true, + draggable: true, + }, + }, + ], + }); + // observer.unobserve(entry.target); + } + }, + { rootMargin: "50px" } + ); }); - observer.observe(document.querySelector('.branchcustomer-review-cards').querySelector('.carousel-inner')); + observer.observe(document.querySelector(".branchcustomer-review-cards").querySelector(".carousel-inner")); if (reviewCards.length <= 3) { - document.querySelector('.branchcustomer-review-cards').querySelector('.carousel-inner').querySelector('.carousel-navigation-buttons').classList.add('dp-none'); + document.querySelector(".branchcustomer-review-cards").querySelector(".carousel-inner").querySelector(".carousel-navigation-buttons").classList.add("dp-none"); } } function renderRatingDiv() { - let html = ''; + let html = ""; if (setLocationObj.review) { setLocationObj.review.forEach((eachEle) => { - let starDiv = ''; + let starDiv = ""; const starToShow = eachEle.rating; - if ((5 - eachEle.rating == 0)) { + if (5 - eachEle.rating == 0) { for (let index = 0; index < starToShow; index++) { starDiv += ''; } @@ -383,8 +385,7 @@ function renderRatingDiv() { const subStringText = eachEle.text.length > 125 ? `${eachEle.text?.substring(0, 125)}...` : eachEle.text; - html - += `