PageSourceSearch

https://diaridigital.tarragona21.com/wp-content/cache/min/1/wp-con…/js/builder-scripts.js?ver=1790804611

js tarragona21.com collected 2026-10-02 10:04:30 UTC 65,011 bytes, 220 lines download raw bytes

1(function(){window.addEventListener('elementor/frontend/init',function(){elementorFrontend.hooks.addAction('frontend/element_ready/smart_post_show_pro_template.default',function($scope){if(typeof init==='function'){init()}})})})();function init(){const socialLinkCopy=()=>{const socialLinks=document.querySelectorAll('.sp-smart-post-social-share .sp-smart-post-copy-btn');if(0<socialLinks.length){socialLinks.forEach((element)=>{element.addEventListener('click',(e)=>{e.preventDefault();const link=e.target.closest('.sp-smart-post-copy-btn').getAttribute('data-url');if(link&&navigator.clipboard){navigator.clipboard.writeText(link)}else{console.log('Clipboard API not supported or link missing.')}})})}};const modal=()=>{const modalContainers=document.querySelectorAll('.sp-smart-post-modal-container');let imageSize;const getNextPostId=(direction,currentId,allIds)=>{const index=allIds.indexOf(String(currentId));if(index===-1){return currentId}
2if(direction==='next'){return allIds[(index+1)%allIds.length]}else if(direction==='prev'){return allIds[(index-1+allIds.length)%allIds.length]}
3return currentId};const getReadingTime=(content,attr)=>{const text=content.trim();const characterCount=text.length;const wordCount=text.split(/\s+/).filter(Boolean).length;const allCount={words:wordCount,chars:characterCount,};attr=JSON.parse(attr);const type=attr?.unit;return `${Math.floor(
4				parseInt(allCount[type]) / parseInt(attr.value)
5			)} Min Read`};const sendPostIdAjax=(postId,modal)=>{fetch(sp_smart_post_block_localize.ajaxUrl,{method:'POST',headers:{'Content-Type':'application/x-www-form-urlencoded',},body:new URLSearchParams({action:'sp_handle_post_id',nonce:sp_smart_post_block_localize.ajaxNonce,post_id:postId,image_size:imageSize,}),}).then((res)=>res.json()).then((data)=>{if(data.success){const postData=data.data;const modalImage=postData.post_image;const modalTitle=postData.title;const modalAuthor=postData.author_name;const modalDate=postData.date_time;const modalTaxonomy=postData.meta_taxonomy;const modalBadges=postData.post_badges_list;const modalContent=postData.content.replace(/^"|"$/g,'');const modalComment=postData.post_data.comment_count;const modalViews=postData.post_views;const modalLike=postData.like_button;const readingTimeContainer=modal.querySelector('.sp-smart-post-reading-time');const readValue=readingTimeContainer?readingTimeContainer.dataset.readTime:'';let readTime;if(readValue){readTime=getReadingTime(modalContent.replace(/<\/?p>/g,''),readValue)}
6modal.querySelector('.sp-smart-post-card-modal-image').innerHTML=modalImage;modal.querySelector('.sp-post-modal-title').textContent=modalTitle;const authorEl=modal.querySelector('.sp-meta-author');if(authorEl){authorEl.innerText=modalAuthor}
7const dateEl=modal.querySelector('.sp-meta-date');if(dateEl){dateEl.innerText=modalDate}
8const commentsEl=modal.querySelector('.sp-meta-comments');if(commentsEl){commentsEl.innerText=modalComment}
9const viewsEl=modal.querySelector('.sp-meta-views');if(viewsEl){viewsEl.innerText=modalViews}
10const likesEl=modal.querySelector('.sp-smart-post-likes');if(likesEl){likesEl.innerHTML=modalLike}
11const readTimeEl=modal.querySelector('.sp-meta-reading-time');if(readTimeEl){readTimeEl.innerHTML=readTime}
12const postBadgesEl=modal.querySelector('.sp-title-badges-list');if(postBadgesEl&&modalBadges&&modalBadges?.length>0){const listItems=modalBadges.map((item)=>`<li class="sp-title-badge-item">${item.name}</li>`)?.join('');postBadgesEl.innerHTML=listItems}
13modal.querySelector('.sp-post-modal-excerpt').innerHTML=modalContent;modal.querySelector('.sp-meta-taxonomy-category').innerText=modalTaxonomy;setTimeout(()=>{modal.style.opacity=1},300)}else{console.log('PHP error:',data.data)}}).catch((err)=>{console.log('Fetch error:',err)})};const cleanData=(modal)=>{modal.querySelector('.sp-smart-post-card-modal-image').innerHTML='';modal.querySelector('.sp-post-modal-title').textContent='';modal.querySelector('.sp-meta-taxonomy-category').innerText='';modal.querySelector('.sp-post-modal-excerpt').innerHTML=''};const openModal=(e,container)=>{e.preventDefault();let modalData;const modal=container.querySelector('.sp-smart-post-modal-container');imageSize=container.querySelector('.sp-smart-post-modal-container .sp-smart-post-card-modal-image').dataset.imageSize;const clickedCard=e.target.closest('.sp-smart-post-card');const clickedTitle=clickedCard?.querySelector('.sp-smart-post-title-wrapper');if(!clickedTitle){return}
14let activePostId=String(clickedTitle.dataset.postId);const allTitles=container.querySelectorAll('.sp-smart-post-title-wrapper');const allIds=[...new Set(Array.from(allTitles).map((item)=>item.dataset.postId)),];const nextBtn=container.querySelector('.sp-smart-modal-next');const prevBtn=container.querySelector('.sp-smart-modal-prev');const setupNav=(btn,direction)=>
14{if(!btn){return}
15btn.onclick=()=>{activePostId=getNextPostId(direction,activePostId,allIds);sendPostIdAjax(activePostId,modal)}};setupNav(nextBtn,'next');setupNav(prevBtn,'prev');modal.classList.add('is_open')};const closeModal=(closeBtn)=>{const modal=closeBtn.closest('.sp-smart-post-modal-container');modal.style.opacity=0;if(modal){modal.classList.remove('is_open')}
16cleanData(modal)};modalContainers.forEach((modal)=>{const box=modal.querySelector('.sp-smart-post-modal-content');const nextBtn=modal.querySelector('.sp-smart-modal-next');const prevBtn=modal.querySelector('.sp-smart-modal-prev');modal.querySelectorAll('.sp-modal-close-btn.cursor').forEach((btn)=>{btn.addEventListener('click',()=>closeModal(btn))});modal.addEventListener('click',(event)=>{const clickedEl=event.target;if(!box.contains(clickedEl)&&clickedEl!==nextBtn&&clickedEl!==prevBtn&&(!nextBtn||!nextBtn.contains(clickedEl))&&(!prevBtn||!prevBtn.contains(clickedEl))){closeModal(box)}})});modalContainers.forEach((modal)=>{if(!modal.textContent.trim()){return}
17const container=modal.parentElement;container.addEventListener('click',(e)=>{if(e.target.closest('.sp-smart-post-modal-container')){return}
18const trigger=e.target.closest('.sp-smart-post-card-image a, .sp-smart-post-title-wrapper, .sp-smart-post-read-more-button a');if(!trigger){return}
19const clickedCard=trigger.closest('.sp-smart-post-card');
19if(!clickedCard){return}
20const clickedTitle=clickedCard.querySelector('.sp-smart-post-title-wrapper');if(!clickedTitle||!clickedTitle.dataset.postId){return}
21e.preventDefault();modal.style.opacity=0;sendPostIdAjax(clickedTitle.dataset.postId,modal);openModal(e,container)})})};const initSmartPostFeatures=(context=document)=>{const sliderWrappers=context.querySelectorAll('.sp-slider-wrapper');sliderWrappers.forEach((slideWrapper)=>{if(!slideWrapper.classList.contains('sp-slider-initialized')){new SPSlider(slideWrapper,{loop:!0,autoplay:!0,interval:3000,speed:600,});slideWrapper.classList.add('sp-slider-initialized')}});const videoPostList=context.querySelectorAll('.sp-smart-video-player');videoPostList.forEach((videoContainer)=>{if(!videoContainer.classList.contains('sp-video-initialized')){const videoUrl=videoContainer.dataset.video_url;const featureImage=videoContainer.dataset.image_url;const videoCaption=videoContainer.dataset.video_caption;new SpSmartVideoPlayer(videoContainer,videoUrl,{featureImage,videoCaption,showFeatureImage:!0,transitionSpeed:500,});videoContainer.classList.add('sp-video-initialized')}
22videoContainer.addEventListener('click',function(event){event.preventDefault();event.stopPropagation();const featureVideo=videoContainer.querySelector('video');if(featureVideo){if(featureVideo.paused){featureVideo.play()}else{featureVideo.pause()}}})})};initSmartPostFeatures();socialLinkCopy();modal();const paginationDotNumber=(paginationClass)=>{return{el:paginationClass,clickable:!0,renderBullet(index,className){return('<span class="'+className+'">'+(index+1)+'</span>')},}};const safeJSONParse=(str,fallback={})=>{try{return JSON.parse(str)||fallback}catch(e){console.log('Failed to parse JSON:',str,e);return fallback}};document.querySelectorAll('.sp-smart-post-timeline-three').forEach((containerEl)=>{const swiperEl=containerEl.querySelector('.swiper-container');if(!swiperEl){return}
23const getBlockId=containerEl.getAttribute('id')||'';const blockId=getBlockId?`#${getBlockId}`:'';const postContainers=containerEl.querySelectorAll(`${blockId} .sp-smart-post-timeline-three-post-container`);const wrapper=document.querySelector(`${blockId} .timeline-three-layout-two .swiper-wrapper`);const timelineBorder=document.querySelector(`${blockId} .timeline-three-layout-two .sp-smart-post-timeline-border`);let maxHeight=0;postContainers.forEach((post)=>{maxHeight=Math.max(maxHeight,post.clientHeight)});maxHeight+=60;if(wrapper){wrapper.style.marginTop=`${maxHeight}px`}
24if(timelineBorder){timelineBorder.style.marginTop=`${maxHeight}px`}
25const options=safeJSONParse(swiperEl.getAttribute('data-swiper-options'));if(!Object.keys(options).length){return}
26new PCPSwiper(swiperEl,options)});document.querySelectorAll('.sp-smart-post-thumbnail-slider.sp-smart-post-block-wrapper').forEach((containerEl)=>{const[mainSwiperEl,thumbsSwiperEl]=containerEl.querySelectorAll('.swiper-container');const thumbsOptions=safeJSONParse(containerEl.querySelector('.sp-smart-post-swiper2')?.getAttribute('data-swiper-options')?.replace(/u0022/g,'"'));const mainOptions=safeJSONParse(mainSwiperEl?.getAttribute('data-swiper-options')?.replace(/u0022/g,'"'));if(!mainSwiperEl||!thumbsSwiperEl||!Object.keys(mainOptions).length){return}
27const thumbsSwiper=new PCPSwiper(thumbsSwiperEl,thumbsOptions);const carouselPagination=mainOptions?.pagination;const paginationClassName=carouselPagination?.el;const numberPagination=mainOptions?.pagination?.paginationType?!0:!1;const mainSwiper=new PCPSwiper(mainSwiperEl,{...mainOptions,thumbs:{swiper:thumbsSwiper},pagination:!numberPagination?carouselPagination:paginationDotNumber(paginationClassName),})});document.querySelectorAll('.sp-smart-post-block-wrapper.sp-smart-thumbnail-slider-two').forEach((containerEl)=>{const[mainSwiperEl,thumbsSwiperEl]=containerEl.querySelectorAll('.swiper-container');const thumbsOptions=safeJSONParse(containerEl.querySelector('.sp-smart-post-swiper2')?.getAttribute('data-swiper-options')?.replace(/u0022/g,'"'));const mainOptions=safeJSONParse(mainSwiperEl?.getAttribute('data-swiper-options')?.replace(/u0022/g,'"'));if(!mainSwiperEl||!thumbsSwiperEl||!Object.keys(mainOptions).length){return}
28const thumbsSwiper=new PCPSwiper(thumbsSwiperEl,thumbsOptions);const mainSwiper=new PCPSwiper(mainSwiperEl,{...mainOptions,thumbs:{swiper:thumbsSwiper},})});const throttle=(callback)=>{let ticking=!1;return(...args)=>{if(!ticking){window.requestAnimationFrame(()=>{callback(...args);ticking=!1});ticking=!0}}};const initTimelineScroll=()=>{const allTimelinesData=[];document.querySelectorAll('.sp-smart-post-show-scroll-wrapper').forEach((timelineWrapper)=>{const blockId=timelineWrapper.id;if(!blockId){return}
29const postCards=timelineWrapper.querySelectorAll('.sp-smart-post-timeline-one-post-container .sp-smart-indicator-circle');const indicatorArrows=timelineWrapper.querySelectorAll('.sp-smart-post-timeline-one-post-container .sp-smart-indicator-arrow');const timelineContainer=timelineWrapper.querySelector('.sp-smart-post-timeline-container');let styleTag=timelineWrapper.querySelector('style.sps-dynamic-styles');if(!styleTag){styleTag=document.createElement('style');styleTag.className='sps-dynamic-styles';timelineWrapper.insertBefore(styleTag,timelineWrapper.firstChild)}
30if(timelineContainer){allTimelinesData.push({wrapper:timelineWrapper,blockId,postCards,indicatorArrows,timelineContainer,styleTag,})}});if(allTimelinesData.length===0){return}
31const handleTimelineScrolls=()=>{const scrollY=window.scrollY;const pageHeight=Math.max(document.body.offsetHeight);allTimelinesData.forEach((data)=>{const wrapperRect=data.wrapper.getBoundingClientRect();if(wrapperRect.bottom>=0&&wrapperRect.top<=window.innerHeight){const scrollPosition=scrollY+200;const indicatorActive=(elements)=>
31{elements.forEach((el)=>{const elTop=el.getBoundingClientRect().top+scrollY;if(scrollY+505>elTop||scrollPosition+700>=pageHeight){el.classList.add('active')}else{el.classList.remove('active')}})};indicatorActive(data.postCards);indicatorActive(data.indicatorArrows);const timelineRect=data.timelineContainer.getBoundingClientRect();const timelineTop=timelineRect.top+scrollY;let height=320;let heightUnit='px';if(timelineRect.bottom-518<0||scrollPosition+700>=pageHeight){height=100;heightUnit='%'}else if(scrollPosition>timelineTop&&timelineRect.bottom-518>0){height=scrollPosition+320-timelineTop}
32const styleContent=`#${data.blockId} .sp-smart-post-timeline-container::after { height: ${height}${heightUnit} !important; }`;if(data.styleTag.textContent!==styleContent){data.styleTag.textContent=styleContent}}})};window.addEventListener('scroll',throttle(handleTimelineScrolls))};initTimelineScroll();function updatePaginationData(section,data){if(!section||!data){return}
33section.dataset.pages=data.total_pages;section.dataset.current=data.current_page;if(section?.dataset.pages<2){section.style.display='none'}else{section.style.display='flex'}
34if(section?.dataset.pages<2){return!1}
35updatePaginationUI(section);createPaginationSection(section)}
36const createPaginationSection=(section)=>{const totalPages=parseInt(section.dataset.pages,10);const currentPage=parseInt(section.dataset.current,10);const paginationtype=section?.dataset.paginationtype;if(paginationtype=='pagination'){if(!totalPages||totalPages<2){return}
37const paginationContainer=section.querySelector('.sp-smart-post-pagination-buttons');if(!paginationContainer){return}
38paginationContainer.innerHTML='';const prevBtn=document.createElement('a');prevBtn.href='#';prevBtn.className='page-numbers prev';if(currentPage===1){prevBtn.classList.add('disabled')}
39prevBtn.innerHTML=`<i class="sp-icon-left-open"></i> Previous`;paginationContainer.appendChild(prevBtn);for(let i=1;i<=totalPages;i++){const pageBtn=document.createElement('a');pageBtn.href='#';pageBtn.className='page-numbers';pageBtn.dataset.page=i;pageBtn.textContent=i;if(i===currentPage){pageBtn.classList.add('current')}
40paginationContainer.appendChild(pageBtn)}
41const nextBtn=document.createElement('a');nextBtn.href='#';nextBtn.className='page-numbers next';if(currentPage===totalPages){nextBtn.classList.add('disabled')}
42nextBtn.innerHTML=`Next <i class="sp-icon-right-open"></i>`;paginationContainer.appendChild(nextBtn)}};const updatePaginationUI=(section)=>{const current=parseInt(section.dataset.current,10);const total=parseInt(section.dataset.pages,10);const paginationtype=section?.dataset.paginationtype;section.querySelectorAll('.page-numbers[data-page]').forEach((link)=>{const page=parseInt(link.dataset.page,10);link.classList.toggle('current',page===current)});const prev=section.querySelector('.page-numbers.prev');const next=section.querySelector('.page-numbers.next');const loadMoreWrapper=section.querySelector('.sp-smart-post-load-more-button');if(prev){prev.classList.toggle('disabled',current<=1)}
43if(next){next.classList.toggle('disabled',current>=total)}
44const[prevNav,nextNav]=section.querySelectorAll('.sp-smart-post-grid-nav-arrow-btn');if(prevNav&&nextNav){prevNav.style.pointerEvents=current<=1?'none':'auto';prevNav.style.opacity=current<=1?'0.5':'1';nextNav.style.pointerEvents=current>=total?'none':'auto';nextNav.style.opacity=current>=total?'0.5':'1'}
45if(loadMoreWrapper){if(current>=total){const loadMoreWrapperBtn=loadMoreWrapper.querySelector('a');if(loadMoreWrapperBtn){loadMoreWrapperBtn.style.display='none'}}else{loadMoreWrapper.style.display='block'}}};function hasFilterCounts(count_data){if(!count_data||typeof count_data!=='object'){return!1}
46return Object.entries(count_data).some(([key,value])=>{if(key==='pagination'){return!1}
47return Array.isArray(value)&&value.length>0})}
48function getBlockParams(){const url=new URL(window.location.href);const params=new URLSearchParams(url.search);const blockParams={};for(const[key,value]of params.entries()){if(key==='block'||key.startsWith('tx_')||key.startsWith('sps_')){blockParams[key]=value}}
49return blockParams}
50function updateSelectByParams(params,blockParent){for(const key in params){if('sps_page'===key){const value=params[key];const pagination_section=blockParent.querySelector('.sp-smart-post-pagination-section');pagination_section.dataset.current=value}
50else if('sps_search'===key){const search_input=blockParent.querySelector(`input[name="${key}"]`);const value=params[key];search_input.value=value}else if('sps_date'===key){const selectDate=blockParent.querySelector('.sp-smart-post-show-date-filter-date-value');const value=params[key];const formatted=value.replace(/^from-/,'').replace(/-to-/,' - ');if(selectDate){selectDate.innerText=formatted}}else if('sps_preset_date'===key){const slectorData=blockParent.querySelector('.sp-smart-post-live-filter-dropdown-date, .sp-smart-post-live-filter-button-date');const presetType=slectorData.dataset.presetType;const labels={today:'Today',yesterday:'Yesterday',lastSevenDays:'Last 7 Days',lastThirtyDays:'Last 30 Days',thisWeek:'This Week',lastWeek:'Last Week',thisMonth:'This Month',lastMonth:'Last Month',thisYear:'This Year',};const value=params[key];const label=labels[value];if(presetType==='dropdown'){const selectDate=blockParent.querySelector('.sp-smart-post-show-date-filter-date-value');selectDate.innerText=label}
51const allLinks=slectorData.querySelectorAll('li > a');allLinks.forEach((link)=>{if(link.textContent.trim()===label){link.classList.add('active')}else{link.classList.remove('active')}})}else{const select=blockParent.querySelector(`select[name="${key}"]`);if(select){const value=params[key];const option=select.querySelector(`option[value="${value}"]`);if(option){option.disabled=!1;option.selected=!0;select.value=value}}}}}
52function wrapSlidesForEffect(containerEl,sps_swiper_option,effectsRequiringWrapping=['fade','cube','flip']){if(sps_swiper_option?.effect&&effectsRequiringWrapping.includes(sps_swiper_option.effect)){const slidesPerView=Math.max(1,parseInt(sps_swiper_option?.slidesPerView)||1);if(slidesPerView>1){const swiperWrapper=containerEl.querySelector('.swiper-wrapper');const loopItems=containerEl.querySelectorAll('.sp-slide-item');loopItems.forEach((item)=>{item.classList.remove('swiper-slide')});if(swiperWrapper&&loopItems.length>0){const fragment=document.createDocumentFragment();for(let i=0;i<loopItems.length;i+=slidesPerView){const slideWrapper=document.createElement('div');slideWrapper.className='swiper-slide';const endIndex=Math.min(i+slidesPerView,loopItems.length);for(let j=i;j<endIndex;j++){slideWrapper.appendChild(loopItems[j].cloneNode(!0))}
53fragment.appendChild(slideWrapper)}
54swiperWrapper.innerHTML='';swiperWrapper.appendChild(fragment)}}}}
55const selected_params=getBlockParams();document.querySelectorAll('.sp-smart-post-wrapper').forEach((container)=>{const preloader=container?.querySelector('.sp-smart-post-show-pro-pre-query .sp-smart-post-preloader');if(preloader){setTimeout(()=>{preloader.classList.remove('sp-d-block');preloader.classList.add('sp-d-hidden');container.classList.add('sp-smart-preloader-removed')},500)}
56const socialCopyLinks=container.querySelectorAll('.sp-copy-url-area .sp-smart-post-copy-btn');if(socialCopyLinks.length>0){let classText;socialCopyLinks.forEach((socialCopyLink)=>{socialCopyLink.addEventListener('click',(e)=>{const copyText=socialCopyLink.querySelector('.sp-post-url-copy-popup');copyText.classList.remove('sp-d-hidden');copyText.classList.add('sp-d-block');clearTimeout(classText);classText=setTimeout(()=>{copyText.classList.remove('sp-d-block');copyText.classList.add('sp-d-hidden')},2000)})})}
57if(container?.classList.contains('sp-smart-post-thumbnail-slider')||container?.classList.contains('sp-smart-post-thumbnail-slider-two')||container?.classList.contains('sp-smart-thumbnail-slider-two')){return!1}
58const blockParent=container.closest('.wp-block-sp-smart-post-show-smart-post-parent');const blockId=container.dataset.blockid;const page_id=container.dataset.pageid||'';const block_location=container.dataset.location||'';if(blockParent&&selected_params?.block===blockId){updateSelectByParams(selected_params,blockParent)}
59const containerEl=container.querySelector('.layout-standard, .layout-center, .swiper-container, .sp_marquee-container');let sps_swiper=null;let sps_swiper_option={};let sps_marquee=null;let sps_marquee_option={};if(containerEl?.classList.contains('swiper-container')){const options=safeJSONParse(containerEl.getAttribute('data-swiper-options')?.replace(/u0022/g,'"'));if(!Object.keys(options).length){return}
60const paginationOptions=options?.pagination;const paginationClassName=paginationOptions?.el;const isNumberPagination=!!options.pagination?.paginationType;sps_swiper_option={...options,pagination:isNumberPagination?paginationDotNumber(paginationClassName):paginationOptions,};if(sps_swiper_option.effect&&['fade','cube','flip'].includes(sps_swiper_option?.effect)){wrapSlidesForEffect(containerEl,sps_swiper_option)}
61sps_swiper=new PCPSwiper(containerEl,sps_swiper_option)}
62if(containerEl?.classList.contains('sp_marquee-container')){sps_marquee_option=safeJSONParse(containerEl.getAttribute('data-options'));if(!Object.keys(sps_marquee_option).length){return}
63sps_marquee_option={speed:sps_marquee_option.speed||500,direction:sps_marquee_option.direction==='left_to_right'?'right':'left',pauseOnHover:sps_marquee_option.pauseOnHover!==!1,slidesPerView:sps_marquee_option.slidesPerView||1,slidesPerViewMobile:sps_marquee_option.slidesPerViewMobile||1,slidesPerViewTablet:sps_marquee_option.slidesPerViewTablet||1,spaceBetween:sps_marquee_option.spaceBetween||0,spaceBetweenMobile:sps_marquee_option.spaceBetweenMobile||0,spaceBetweenTablet:sps_marquee_option.spaceBetweenTablet||0,};sps_marquee=new SP_Marquee(containerEl,sps_marquee_option)}
64let sps_date;let sps_preset_date;const filter_fields=blockParent?.querySelectorAll('.sp-smart-post-live-filter-parent select[name], .sp-smart-post-live-filter-parent input[name]')||[];const filter_relation=blockParent?.querySelector('.sp-smart-post-live-filter-parent')?.dataset.relation||'and';const loadQueryData=(state)=>{state.block_location=block_location;return fetch(sp_smart_post_block_localize.restUrl,{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify(state),}).then((res)=>res.json())};
64function updateURLQuery(customParams){const baseUrl=new URL(sp_smart_post_block_localize.permalink_structure||window.location.href);const params=new URLSearchParams(baseUrl.search);const allowedKeys=['page_id','block','tx_category','sps_date','sps_preset_date','sps_sort','sps_search','sps_page',];if(blockId){params.set('block',blockId)}
65Object.entries(customParams).forEach(([key,value])=>{if(!allowedKeys.includes(key))return;if(value!==''&&value!==null&&value!==undefined){params.set(key,value)}else{params.delete(key)}});[...params.keys()].forEach((key)=>{if(!allowedKeys.includes(key)){params.delete(key)}});baseUrl.search=params.toString();window.history.replaceState({},'',baseUrl.toString())}
66function getFilterState(event,update_url=!0,pagination_section=null){const state={};const currentField=event?.target||null;pagination_section=pagination_section??currentField?.closest('.sp-smart-post-pagination-section');if(pagination_section&&'pagination'==pagination_section?.dataset.paginationtype&&currentField.tagName==='A'){const currentPage=parseInt(pagination_section.dataset.current,10);newPage=1;if(currentField.classList.contains('prev')){newPage=currentPage-1}else if(currentField.classList.contains('next')){newPage=currentPage+1}else{newPage=parseInt(currentField.dataset.page,10)}
67if(newPage>1){state.sps_page=newPage||1}}
68filter_fields.forEach((field)=>{let key=field.name;const value=field.value.trim();if(key==='blog_search'){key='search'}
69state.sps_preset_date=sps_preset_date?sps_preset_date:'';state.sps_date=sps_date?sps_date:'';state[key]=value});if(update_url){updateURLQuery(state)}
70if(Object.keys(state).length>0){state.block=blockId;state.page_id=page_id;state.relation=filter_relation}
71return state}
72let currentState=getFilterState(null,!1);function debounce(fn,delay){let timer;return function(...args){clearTimeout(timer);timer=setTimeout(()=>fn.apply(this,args),delay)}}
73const pagination_section=container.querySelector('.sp-smart-post-pagination-section');const loadMoreWrapper=pagination_section?.querySelector('.sp-smart-post-load-more-button');let fromDate;let toDate;function datePicker(){blockParent.querySelectorAll('[sps-date-filter-calendar]').forEach((calendar)=>{const currentDate=new Date();const defaultDate=selected_params.sps_date;if(defaultDate&&defaultDate.startsWith('from-')){const match=defaultDate.match(/from-(\d{2})-(\d{2})-(\d{4})-to-(\d{2})-(\d{2})-(\d{4})/);if(match){fromDate=new Date(match[3],match[2]-1,match[1]);toDate=new Date(match[6],match[5]-1,match[4])}}
74const monthNames=['January','February','March','April','May','June','July','August','September','October','November','December',];const grid=calendar.querySelector('.sps-smart-post-date-filter-calendar-grid');const monthLabel=calendar.querySelector('.sps-date-filter-month-label');const yearLabel=calendar.querySelector('.sps-date-filter-year-label');const monthList=calendar.querySelector('.sps-date-filter-month-list');const yearList=calendar.querySelector('.sps-date-filter-year-list');if(!grid||!monthLabel||!yearLabel)return;const daysInMonth=(date)=>new Date(date.getFullYear(),date.getMonth()+1,0).getDate();const firstDayOfMonth=(date)=>new Date(date.getFullYear(),date.getMonth(),1).getDay();const formatDate=(date)=>{if(!date)return'';return `${String(date.getDate()).padStart(2, '0')}-${String(
75							date.getMonth() + 1
76						).padStart(2, '0')}-${date.getFullYear()}`};const sameDate=(d1,d2)=>d1&&d2&&d1.getDate()===d2.getDate()&&d1.getMonth()===d2.getMonth()&&d1.getFullYear()===d2.getFullYear();const inRange=(date)=>fromDate&&toDate&&date>fromDate&&date<toDate;function renderCalendar(){grid.innerHTML='';monthLabel.textContent=monthNames[currentDate.getMonth()];yearLabel.textContent=currentDate.getFullYear();const days=[];const prevMonthDays=new Date(currentDate.getFullYear(),currentDate.getMonth(),0).getDate();const firstDay=firstDayOfMonth(currentDate);for(let i=prevMonthDays-firstDay+1;i<=prevMonthDays;i++){days.push({day:i,current:!1})}
77for(let i=1;i<=daysInMonth(currentDate);i++){days.push({day:i,current:!0})}
78let nextMonthDay=1;while(days.length<42){days.push({day:nextMonthDay++,current:!1,})}
79days.forEach((d)=>{const btn=document.createElement('button');const dateObj=new Date(currentDate.getFullYear(),currentDate.getMonth(),d.day);btn.textContent=d.day;btn.className='sps-smart-post-date-filter-calendar-day '+(d.current?'current-month':'other-month');if(sameDate(dateObj,fromDate))
80btn.classList.add('from');if(sameDate(dateObj,toDate))
81btn.classList.add('to');if(inRange(dateObj))btn.classList.add('in-range');btn.addEventListener('click',(e)=>{if(!d.current)return;e.stopPropagation();monthList.style.display='none';yearList.style.display='none';if(fromDate&&toDate){fromDate=dateObj;toDate=null;
81renderCalendar();return}
82if(!fromDate){fromDate=dateObj;renderCalendar();return}
83if(!toDate){if(dateObj<fromDate){toDate=fromDate;fromDate=dateObj}else{toDate=dateObj}
84renderCalendar();closeDropdown()}});grid.appendChild(btn)})}
85function closeDropdown(){const dropdown=calendar.closest('.sp-smart-post-live-filter-dropdown-date');const button=calendar.closest('.sp-smart-post-date-filter')?.querySelector('.sp-smart-post-live-filter-btn');if(dropdown)dropdown.classList.remove('open');if(button){button.setAttribute('aria-expanded','false');const span=button.querySelector('.sp-smart-post-show-date-filter-date-value');if(span){span.textContent=formatDate(fromDate)+' - '+formatDate(toDate);sps_date='from-'+formatDate(fromDate)+'-to-'+formatDate(toDate);currentState.sps_date='from-'+formatDate(fromDate)+'-to-'+formatDate(toDate);updateURLQuery(currentState);if(preloader){preloader.classList.add('sp-d-block');container.classList.remove('sp-smart-preloader-removed')}
86let itemsEl=null;delete currentState.html;loadQueryData(currentState).then((data)=>{if(!data.success){return}
87if(pagination_section){pagination_section.dataset.current=1}
88if(sps_marquee&&containerEl.classList.contains('sp_marquee-container')){container.querySelector('.sp_marquee-content').innerHTML=data.html;sps_marquee=new SP_Marquee(containerEl,sps_marquee_option)}else if(sps_swiper){sps_swiper.destroy(!0);container.querySelector('.swiper-wrapper').innerHTML=data.html;if(sps_swiper_option.effect&&['fade','cube','flip'].includes(sps_swiper_option?.effect)){wrapSlidesForEffect(containerEl,sps_swiper_option)}
89sps_swiper=new PCPSwiper(containerEl,sps_swiper_option)}else{const items=container.querySelector('.sp-smart-post-items');items.innerHTML=data.html;itemsEl=items;if(itemsEl){const childItems=itemsEl.querySelectorAll('.sp-smart-post-card, .swiper-slide');childItems.forEach((el,index)=>{el.style.opacity=0;el.style.animation=`fadeIn 0.7s ease-in-out forwards`;el.style.animationDelay=`${index * 0.1}s`})}}
90const termCounts=data.count_data;if(termCounts&&hasFilterCounts(termCounts)){updateFilterCounts(termCounts,pagination_section,blockParent);updateAllSmartPostFilterCounts(blockParent)}else if(Object.keys(currentState).length>0){blockParent.querySelectorAll('.sp-smart-post-taxonomy-filter select option').forEach((option)=>{const slug=option.value;if(slug){option.textContent=`${capitalize(
91														slug
92													)} (0)`;option.disabled=!0}});Object.entries(termCounts).forEach(([taxonomy,terms])=>{if(taxonomy==='pagination'&&pagination_section){updatePaginationData(pagination_section,terms)}});updateAllSmartPostFilterCounts(blockParent)}else{resetFilterCounts(blockParent)}
93socialLinkCopy();modal();initTimelineScroll();initSmartPostFeatures();if(preloader){setTimeout(()=>{preloader.classList.remove('sp-d-block');preloader.classList.add('sp-d-hidden');container.classList.add('sp-smart-preloader-removed')},200)}
94if(loadMoreWrapper){const no_more_button=loadMoreWrapper.querySelector('.sps-no-more-post');if(no_more_button){const loadMoreWrapperBTN=loadMoreWrapper.querySelector('a');if(loadMoreWrapperBTN){loadMoreWrapperBTN.style.display='flex'}
95no_more_button.style.display='none'}}})}}}
96calendar.querySelector('.sps-date-filter-nav-prev')?.addEventListener('click',(e)=>{e.stopPropagation();currentDate.setMonth(currentDate.getMonth()-1);renderCalendar()});calendar.querySelector('.sps-date-filter-nav-next')?.addEventListener('click',(e)=>{e.stopPropagation();currentDate.setMonth(currentDate.getMonth()+1);renderCalendar()});monthNames.forEach((m,i)=>{const btn=document.createElement('button');btn.textContent=m;btn.onclick=(e)=>{e.stopPropagation();currentDate.setMonth(i);renderCalendar();monthList.style.display='none'};monthList.appendChild(btn)});const currentYear=new Date().getFullYear();for(let y=currentYear;y>=2000;y--){const btn=document.createElement('button');btn.textContent=y;btn.onclick=(e)=>{e.stopPropagation();currentDate.setFullYear(y);renderCalendar();yearList.style.display='none'};yearList.appendChild(btn)}
97const monthTrigger=calendar.querySelector('.sps-date-filter-month-trigger');if(monthTrigger&&!monthTrigger.dataset.bound){monthTrigger.dataset.bound='true';monthTrigger.addEventListener('click',(e)=>{e.stopPropagation();monthList.style.display=monthList.style.display==='block'?'none':'block';yearList.style.display='none'})}
98const yearTrigger=calendar.querySelector('.sps-date-filter-year-tr
98igger');if(yearTrigger&&!yearTrigger.dataset.bound){yearTrigger.dataset.bound='true';yearTrigger?.addEventListener('click',(e)=>{e.stopPropagation();yearList.style.display=yearList.style.display==='block'?'none':'block';monthList.style.display='none'})}
99document.addEventListener('click',(e)=>{if(!calendar.contains(e.target)){monthList.style.display='none';yearList.style.display='none'}});renderCalendar()})}
100function datePreset(){const dateilter=blockParent.querySelector('.sp-smart-post-date-filter-main');if(dateilter){dateilter.querySelectorAll('a[data-value]').forEach((link)=>{const dropdown=blockParent.querySelector('.sp-smart-post-live-filter-dropdown-date, .sp-smart-post-live-filter-button-date');const presetType=dropdown.dataset.presetType;const button=blockParent.querySelector('.sp-smart-post-date-filter > .sp-smart-post-live-filter-btn');link.addEventListener('click',function(e){e.preventDefault();blockParent.querySelectorAll('a[data-value]').forEach((l)=>l.classList.remove('active'));this.classList.add('active');if(presetType==='dropdown'){const label=button.querySelector('.sp-smart-post-show-date-filter-date-value');if(label)label.textContent=this.textContent;dropdown.classList.remove('open');button.setAttribute('aria-expanded','false')}
101sps_preset_date=this.dataset.value;currentState.sps_preset_date=sps_preset_date;updateURLQuery(currentState);if(preloader){preloader.classList.add('sp-d-block');container.classList.remove('sp-smart-preloader-removed')}
102let itemsEl=null;delete currentState.html;loadQueryData(currentState).then((data)=>{if(!data.success){return}
103if(pagination_section){pagination_section.dataset.current=1}
104if(sps_marquee&&containerEl.classList.contains('sp_marquee-container')){container.querySelector('.sp_marquee-content').innerHTML=data.html;sps_marquee=new SP_Marquee(containerEl,sps_marquee_option)}else if(sps_swiper){sps_swiper.destroy(!0);container.querySelector('.swiper-wrapper').innerHTML=data.html;if(sps_swiper_option.effect&&['fade','cube','flip'].includes(sps_swiper_option?.effect)){wrapSlidesForEffect(containerEl,sps_swiper_option)}
105sps_swiper=new PCPSwiper(containerEl,sps_swiper_option)}else{const items=container.querySelector('.sp-smart-post-items');items.innerHTML=data.html;itemsEl=items;if(itemsEl){const childItems=itemsEl.querySelectorAll('.sp-smart-post-card, .swiper-slide');childItems.forEach((el,index)=>{el.style.opacity=0;el.style.animation=`fadeIn 0.7s ease-in-out forwards`;el.style.animationDelay=`${index * 0.1}s`})}}
106const termCounts=data.count_data;if(termCounts&&hasFilterCounts(termCounts)){updateFilterCounts(termCounts,pagination_section,blockParent);updateAllSmartPostFilterCounts(blockParent)}else if(Object.keys(currentState).length>0){blockParent.querySelectorAll('.sp-smart-post-taxonomy-filter select option').forEach((option)=>{const slug=option.value;if(slug){option.textContent=`${capitalize(
107												slug
108											)} (0)`;option.disabled=!0}});Object.entries(termCounts).forEach(([taxonomy,terms])=>{if(taxonomy==='pagination'&&pagination_section){updatePaginationData(pagination_section,terms)}});updateAllSmartPostFilterCounts(blockParent)}else{resetFilterCounts(blockParent)}
109socialLinkCopy();modal();initTimelineScroll();initSmartPostFeatures();if(preloader){setTimeout(()=>{preloader.classList.remove('sp-d-block');preloader.classList.add('sp-d-hidden');container.classList.add('sp-smart-preloader-removed')},200)}
110if(loadMoreWrapper){const no_more_button=loadMoreWrapper.querySelector('.sps-no-more-post');if(no_more_button){const loadMoreWrapperBTN=loadMoreWrapper.querySelector('a');if(loadMoreWrapperBTN){loadMoreWrapperBTN.style.display='flex'}
111no_more_button.style.display='none'}}})})})}}
112function resetTaxonomyFilter(){const taxonomyEl=blockParent.querySelector('.sp-smart-post-taxonomy-filter');if(!taxonomyEl){return}
113const allText=taxonomyEl.dataset.allText||'All';const btnTextEl=taxonomyEl.querySelector('.sp-smart-post-live-filter-btn span');if(btnTextEl){btnTextEl.textContent=allText}
114const links=taxonomyEl.querySelectorAll('.sps-live-filter-nav-link');links.forEach((link)=>{link.classList.remove('active');link.removeAttribute('aria-current')});const allLink=taxonomyEl.querySelector('.sps-live-filter-nav-link[data-value=""]');
114if(allLink){allLink.classList.add('active');allLink.setAttribute('aria-current','true')}
115const select=taxonomyEl.querySelector('select');if(select){select.value=''}}
116function resetSortFilter(){const sortEl=blockParent.querySelector('.sp-smart-post-sort-filter');if(!sortEl){return}
117const placeholder=sortEl.dataset.sortPlaceholder||'None';const btnTextEl=sortEl.querySelector('.sp-smart-post-live-filter-btn span');if(btnTextEl){btnTextEl.textContent=placeholder}
118const links=sortEl.querySelectorAll('.sps-live-filter-nav-link');links.forEach((link)=>{link.classList.remove('active');link.removeAttribute('aria-current')});const noneLink=sortEl.querySelector('.sps-live-filter-nav-link[data-value=""]');if(noneLink){noneLink.classList.add('active');noneLink.setAttribute('aria-current','true')}
119const select=sortEl.querySelector('select[name="sps_sort"]');if(select){select.value=''}}
120function resetDateFilter(){const dateFilterEl=blockParent.querySelector('.sp-smart-post-date-filter');if(!dateFilterEl){return}
121const button=dateFilterEl.querySelector('.sp-smart-post-live-filter-btn');if(button){const label=button.querySelector('.sp-smart-post-show-date-filter-date-value');const defaultLabel=label.dataset.defaultLabel||'Select';if(label)label.textContent=defaultLabel}
122const links=dateFilterEl.querySelectorAll('a[data-value]');links.forEach((link)=>{link.classList.remove('active');link.removeAttribute('aria-current')});const defaultLink=dateFilterEl.querySelector('a[data-value=""]');if(defaultLink){defaultLink.classList.add('active');defaultLink.setAttribute('aria-current','true')}
123currentState.sps_preset_date='';sps_preset_date='';fromDate=null;toDate=null;datePicker()}
124function clearFilter(){const clearFilterWrapper=blockParent.querySelectorAll('.sp-smart-post-clear-filter-main');clearFilterWrapper.forEach((wrapper)=>{wrapper.addEventListener('click',async(e)=>{e.preventDefault();currentState={block:blockId,block_location,page_id,relation:filter_relation,sps_search:'',sps_sort:'',tx_category:'',};sps_date='';sps_preset_date='';resetTaxonomyFilter();resetSortFilter();resetDateFilter();const searchInput=blockParent.querySelector('.sp-smart-post-search-field > input');if(searchInput)searchInput.value='';updateURLQuery(currentState);if(preloader){preloader.classList.add('sp-d-block');container.classList.remove('sp-smart-preloader-removed')}
125const data=await loadQueryData(currentState);if(!data?.success)return;if(pagination_section){pagination_section.dataset.current=1}
126if(sps_marquee&&containerEl.classList.contains('sp_marquee-container')){container.querySelector('.sp_marquee-content').innerHTML=data.html;sps_marquee=new SP_Marquee(containerEl,sps_marquee_option)}else if(sps_swiper){sps_swiper.destroy(!0);container.querySelector('.swiper-wrapper').innerHTML=data.html;if(['fade','cube','flip'].includes(sps_swiper_option?.effect)){wrapSlidesForEffect(containerEl,sps_swiper_option)}
127sps_swiper=new PCPSwiper(containerEl,sps_swiper_option)}else{const items=container.querySelector('.sp-smart-post-items');items.innerHTML=data.html;items.querySelectorAll('.sp-smart-post-card, .swiper-slide').forEach((el,index)=>{el.style.opacity=0;el.style.animation='fadeIn 0.7s ease-in-out forwards';el.style.animationDelay=`${index * 0.1}s`})}
128if(data.count_data&&hasFilterCounts(data.count_data)){updateFilterCounts(data.count_data,pagination_section,blockParent);updateAllSmartPostFilterCounts(blockParent)}else{resetFilterCounts(blockParent)}
129socialLinkCopy();modal();initTimelineScroll();initSmartPostFeatures();if(preloader){setTimeout(()=>{preloader.classList.remove('sp-d-block');preloader.classList.add('sp-d-hidden');container.classList.add('sp-smart-preloader-removed')},200)}
130if(loadMoreWrapper){const noMoreBtn=loadMoreWrapper.querySelector('.sps-no-more-post');const loadMoreBtn=loadMoreWrapper.querySelector('a');if(loadMoreBtn)loadMoreBtn.style.display='flex';if(noMoreBtn)noMoreBtn.style.display='none'}})})}
131if(page_id&&filter_fields.length>0){currentState.html=!1;loadQueryData(currentState).then((data)=>{if(!data.success){return}
132const termCounts=data.count_data;if(termCounts&&hasFilterCounts(termCounts)){updateFilterCounts(termCounts,!1,blockParent);updateAllSmartPostFilterCounts(blockParent)}else if(Object.keys(currentState).length>0){blockParent.querySelectorAll('.sp-smart-filter-area select option').forEach((option)=>{const slug=option.value;if(slug){option.textContent=`${capitalize(
133										slug
134									)} (0)`;option.disabled=!0}})}else{resetFilterCounts(blockParent)}
135initTimelineScroll()}).catch();const eventHandler=(e)=>{currentState=getFilterState(e);if(preloader){preloader.classList.add('sp-d-block');container.classList.remove('sp-smart-preloader-removed')}
136let itemsEl=null;loadQueryData(currentState).then((data)=>
136{if(!data.success){return}
137if(pagination_section){pagination_section.dataset.current=1}
138if(sps_marquee&&containerEl.classList.contains('sp_marquee-container')){container.querySelector('.sp_marquee-content').innerHTML=data.html;sps_marquee=new SP_Marquee(containerEl,sps_marquee_option)}else if(sps_swiper){sps_swiper.destroy(!0);container.querySelector('.swiper-wrapper').innerHTML=data.html;if(sps_swiper_option.effect&&['fade','cube','flip'].includes(sps_swiper_option?.effect)){wrapSlidesForEffect(containerEl,sps_swiper_option)}
139sps_swiper=new PCPSwiper(containerEl,sps_swiper_option)}else{const items=container.querySelector('.sp-smart-post-items');items.innerHTML=data.html;itemsEl=items;if(itemsEl){const childItems=itemsEl.querySelectorAll('.sp-smart-post-card, .swiper-slide');childItems.forEach((el,index)=>{el.style.opacity=0;el.style.animation=`fadeIn 0.7s ease-in-out forwards`;el.style.animationDelay=`${index * 0.1}s`})}}
140const termCounts=data.count_data;if(termCounts&&hasFilterCounts(termCounts)){updateFilterCounts(termCounts,pagination_section,blockParent);updateAllSmartPostFilterCounts(blockParent)}else if(Object.keys(currentState).length>0){blockParent.querySelectorAll('.sp-smart-post-taxonomy-filter select option').forEach((option)=>{const slug=option.value;if(slug){option.textContent=`${capitalize(
141										slug
142									)} (0)`;option.disabled=!0}});Object.entries(termCounts).forEach(([taxonomy,terms])=>{if(taxonomy==='pagination'&&pagination_section){updatePaginationData(pagination_section,terms)}});updateAllSmartPostFilterCounts(blockParent)}else{resetFilterCounts(blockParent)}
143socialLinkCopy();modal();initTimelineScroll();initSmartPostFeatures();if(preloader){setTimeout(()=>{preloader.classList.remove('sp-d-block');preloader.classList.add('sp-d-hidden');container.classList.add('sp-smart-preloader-removed')},200)}
144if(loadMoreWrapper){const no_more_button=loadMoreWrapper.querySelector('.sps-no-more-post');if(no_more_button){const loadMoreWrapperBTN=loadMoreWrapper.querySelector('a');if(loadMoreWrapperBTN){loadMoreWrapperBTN.style.display='flex'}
145no_more_button.style.display='none'}}})};filter_fields.forEach((field)=>{const isInput=field.tagName==='INPUT';const eventName=isInput?'input':'change';field.addEventListener(eventName,isInput?debounce(eventHandler,400):eventHandler)});datePreset();datePicker();clearFilter()}
146function dateFilterToggle(){const mainFilters=blockParent?.querySelectorAll('.sp-smart-post-date-filter-main');mainFilters?.forEach((wrapper)=>{const button=wrapper.querySelector('.sp-smart-post-live-filter-btn');const dropdown=wrapper.querySelector('.sp-smart-post-live-filter-dropdown-date');if(!button||!dropdown)return;button.addEventListener('click',function(e){e.preventDefault();e.stopPropagation();dropdown.classList.toggle('open');button.setAttribute('aria-expanded',dropdown.classList.contains('open')?'true':'false')});document.addEventListener('click',function(e){if(!wrapper.contains(e.target)){dropdown.classList.remove('open');button.setAttribute('aria-expanded','false')}})})}
147dateFilterToggle();if(!pagination_section){return}
148let current=parseInt(pagination_section.dataset.current,10);let total=parseInt(pagination_section.dataset.pages,10);const endMessage=pagination_section.dataset.endmessage??'';const pagination_type=pagination_section.dataset.paginationtype;let contents=container.querySelector(pagination_type==='load-more'?'.sp-smart-post-dynamic-grid-contents,.sp-smart-post-grid-five-static-contents,.sp-smart-post-grid-six-dynamic-contents,.sp-smart-post-timeline-container,.sp-smart-post-small-items,.sp-smart-post-list-one-container':'.sp-smart-post-items,.sp-smart-post-list-item');const updateCurrent=(newPage)=>{pagination_section.dataset.current=newPage;current=newPage};const appendHtml=(html)=>{contents.insertAdjacentHTML('beforeend',html);return contents};const replaceHtml=(html)=>{contents.innerHTML=html;return contents};const loadPage=(page,mode='replace',currentState={})=>{total=parseInt(pagination_section.dataset.pages,10);if(page<1||page>total||page===current){return}
149contents=container.querySelector(pagination_type==='load-more'?'.sp-smart-post-dynamic-grid-contents,.sp-smart-post-grid-five-static-contents,.sp-smart-post-grid-six-dynamic-contents,.sp-smart-post-timeline-container,.sp-smart-post-small-items,.sp-smart-post-list-one-container':'.sp-smart-post-items,.sp-smart-post-list-item');currentState={...currentState,sps_page:page,pagination_type,block:blockId,page_id,};const infinitePreloader=pagination_section.querySelector('.sp-smart-post-show-preloading');const buttonPreloader=pagination_section.querySelector('.sp-smart-post-show-preloader');if(isInfiniteScroll){if(infinitePreloader){infinitePreloader.style.display='block'}}else{if(buttonPreloader){buttonPreloader?.classList?.remove('sp-d-hidden')}
150buttonPreloader?.classList?.add('sp-d-block')}
151loadQueryData(currentState).then((data)=>
151{if(!data.success){return}
152if(mode==='append'){const existingCount=contents.querySelectorAll('.sp-smart-post-card, .swiper-slide').length;appendHtml(data.html);const allItems=contents.querySelectorAll('.sp-smart-post-card, .swiper-slide');allItems.forEach((el,index)=>{if(index>=existingCount){el.style.opacity=0;el.style.animation=`fadeIn 0.7s ease-in-out forwards`;el.style.animationDelay=`${
153									(index - existingCount) * 0.1
154								}s`}})}else{replaceHtml(data.html);const childItems=contents.querySelectorAll('.sp-smart-post-card, .swiper-slide');childItems.forEach((el,index)=>{el.style.opacity=0;el.style.animation=`fadeIn 0.7s ease-in-out forwards`;el.style.animationDelay=`${index * 0.1}s`})}
155updateCurrent(page);updatePaginationUI(pagination_section);socialLinkCopy();initSmartPostFeatures();modal();initTimelineScroll();loadMoreWrapper?.classList.remove('sps_disabled');if(isInfiniteScroll){if(infinitePreloader){infinitePreloader.style.display='none'}}else{if(buttonPreloader){buttonPreloader?.classList?.remove('sp-d-block')}
156buttonPreloader?.classList?.add('sp-d-hidden')}
157if(page>=total&&loadMoreWrapper){loadMoreWrapper.insertAdjacentHTML('beforeend',`<span class="sps-no-more-post">${endMessage}</span>`);const loadMoreWrapperBtn=loadMoreWrapper.querySelector('a');loadMoreWrapperBtn.style.display='none'}}).catch((err)=>console.log('Pagination Error:',err))};const loadMoreBtn=loadMoreWrapper?.querySelector('a');const isInfiniteScroll=!!loadMoreWrapper?.querySelector('.sp-smart-post-show-preloading');if(isInfiniteScroll&&'IntersectionObserver' in window){const observer=new IntersectionObserver((entries)=>{if(entries[0].isIntersecting){current=parseInt(pagination_section.dataset.current,10);if(current<total){currentState=getFilterState(null,!0,pagination_section);const preloader=loadMoreWrapper.querySelector('.sp-smart-post-show-preloading');if(preloader){preloader.style.display='block'}
158loadPage(current+1,'append',currentState)}}},{rootMargin:'100px'});if(loadMoreWrapper){observer.observe(loadMoreWrapper)}}else if(loadMoreBtn){const load_more_preloader=loadMoreWrapper?.querySelector('.sp-smart-post-show-preloader');loadMoreBtn.addEventListener('click',(e)=>{e.preventDefault();load_more_preloader.classList.remove('sp-d-hidden');load_more_preloader.classList.add('sp-d-block');loadMoreWrapper.classList.add('sps_disabled');current=parseInt(pagination_section.dataset.current,10);currentState=getFilterState(e,!1);loadPage(current+1,'append',currentState)})}
159const paginationContainer=pagination_section.querySelector('.sp-smart-post-pagination-buttons');paginationContainer?.addEventListener('click',(e)=>{const btn=e.target.closest('.page-numbers');if(!btn||btn.classList.contains('disabled')||btn.classList.contains('current')){return}
160e.preventDefault();const currentPage=parseInt(pagination_section.dataset.current,10);let newPage=null;if(btn.classList.contains('prev')){newPage=currentPage-1}else if(btn.classList.contains('next')){newPage=currentPage+1}else{newPage=parseInt(btn.dataset.page,10)}
161if(isNaN(newPage)||newPage===currentPage){return}
162const currentState=getFilterState(e);loadPage(newPage,'replace',currentState);pagination_section.dataset.current=newPage});const navArrows=pagination_section.querySelectorAll('.sp-smart-post-grid-nav-arrow-btn');if(navArrows.length===2){const[prevArrow,nextArrow]=navArrows;prevArrow.addEventListener('click',(e)=>{e.preventDefault();currentState=getFilterState(e);loadPage(current-1,'replace',currentState)});nextArrow.addEventListener('click',(e)=>{e.preventDefault();currentState=getFilterState(e);current=parseInt(pagination_section.dataset.current,10);loadPage(current+1,'replace',currentState)})}
163updatePaginationUI(pagination_section)});function capitalize(str){if(!str){return''}
164return str.charAt(0).toUpperCase()+str.slice(1)}
165function updateFilterCounts(termCounts,pagination_section,blockParent){if(!termCounts||!blockParent){return}
166const show_count=!0;Object.entries(termCounts).forEach(([taxonomy,terms])=>{if(taxonomy==='pagination'&&pagination_section){updatePaginationData(pagination_section,terms);return}
167const select=blockParent.querySelector(`#filter-${taxonomy}`);if(!select){return}
168Array.from(select.options).forEach((option)=>{const slug=option.value;if(!slug||!terms){return}
169const isSelected=option.selected;const defaultLabel=option.getAttribute('data-label')||slug;const term=terms.find((t)=>t.slug==slug);if(term){const count=show_count?`(${term.count})`:'';option.textContent=`${capitalize(defaultLabel)} ${count}`;option.disabled=!1}else{const count=show_count?`(0)`:'';option.textContent=`${capitalize(defaultLabel)} (0)`;option.disabled=!isSelected}})})}
170function resetFilterCounts(blockParent){if(!blockParent){return}
171blockParent.querySelectorAll('.sp-smart-filter-area select option').forEach((option)=>{const slug=option.value;if(!slug){return}
172const defaultCount=option.getAttribute('data-default-count');if(defaultCount!==null){option.textContent=`${capitalize(
173						option.getAttribute('data-label') || slug
174					)} (${defaultCount})`;option.disabled=!1}})}
175const filterWrappers=document.querySelectorAll('.sp-smart-post-taxonomy-filter, .sp-smart-post-sort-filter');function handleDropdownClick(e,dropdown,oppositeDropdown,spanLabel,select){const item=e.target.closest('a');if(!item||item.classList.contains('disabled'))return;e.preventDefault();if(oppositeDropdown){const links=oppositeDropdown.querySelectorAll('.sps-live-filter-nav-link');links.forEach((link)=>link.classList.remove('active'))}
176dropdown.querySelectorAll('a').forEach((el)=>el.classList.remove('active'));item.classList.add('active');const value=item.getAttribute('data-value');const label=item.getAttribute('data-label');const countMatch=item.textContent.match(/\((\d+)\)/);const count=countMatch?countMatch[1]:'';if(spanLabel){spanLabel.innerHTML=`${label}${count ? `(${count})` : ''}`}
177if(select){select.value=value;select.dispatchEvent(new Event('change'))}
178dropdown.classList.remove('open')}
179function setupFilterWrapper(wrapper){const btn=wrapper.querySelector('.sp-smart-post-live-filter-btn');const dropdown=wrapper.querySelector('.sp-smart-post-live-filter-dropdown, .sp-smart-post-live-filter-button, .sp-smart-post-live-filter-button-date');const secondDropdown=wrapper.querySelector('.sps-live-filter-dropdown-menu');const spanLabel=btn?.querySelector('span');const select=wrapper.closest('.sp-smart-post-live-filter-wrapper')?.querySelector('select');if(!select){return}
180if(btn&&dropdown){btn.addEventListener('click',(e)=>{e.preventDefault();dropdown.classList.toggle('open')})}
181if(dropdown){dropdown.addEventListener('click',(e)=>handleDropdownClick(e,dropdown,secondDropdown,spanLabel,select))}
182if(secondDropdown){secondDropdown.addEventListener('click',(e)=>handleDropdownClick(e,secondDropdown,dropdown,spanLabel,select))}}
183filterWrappers.forEach(setupFilterWrapper);document.addEventListener('click',(e)=>{document.querySelectorAll('.sp-smart-post-live-filter-dropdown.open').forEach((dropdown)=>{const btn=dropdown.previousElementSibling;if(!dropdown.contains(e.target)&&(!btn||!btn.contains(e.target))){dropdown.classList.remove('open')}})});const imagesLoaded=(el,callback)=>{const images=el.querySelectorAll('img');let loadedCount=0;if(images.length===0){return callback()}
184images.forEach((img)=>{if(img.complete){loadedCount++;if(loadedCount===images.length){callback()}}else{img.onload=img.onerror=()=>{loadedCount++;if(loadedCount===images.length){callback()}}}})};const getBlockIdFromChild=(child)=>{const wrapper=child.closest('.sp-smart-post-wrapper');return wrapper?wrapper.id:null};const carouselContainers=document.querySelectorAll('.sp-smart-post-swiper.sp-equal-height-wrapper');carouselContainers.forEach((carousel)=>{const containerId=getBlockIdFromChild(carousel);const equalHeightEnabled=carousel.dataset.equalHeight=='1';let container=document.getElementById(containerId);if(!container){const iframe=document.querySelector('iframe');const iframeDoc=iframe?.contentWindow?.document;container=iframeDoc?.getElementById(containerId)||null}
185if(container){const cards=container.querySelectorAll('.sp-smart-post-card');const applyEqualHeight=()=>{if(!cards.length){return}
186if(equalHeightEnabled){let maxHeight=0;cards.forEach((card)=>{card.style.height='auto';const height=card.offsetHeight;if(height>maxHeight){maxHeight=height}});cards.forEach((card)=>{card.style.height=`${maxHeight}px`})}else{cards.forEach((card)=>{card.style.height='auto'})}};imagesLoaded(container,applyEqualHeight)}});update_selection_field_count();const containers=document.querySelectorAll('.sps-live-filter-layout-two');
186containers.forEach((container)=>{const style=container.dataset.style;let currentPage=parseInt(container.dataset.currentPage);let isDropdownOpen=container.dataset.isDropdownOpen==='true';const totalPages=parseInt(container.dataset.totalPages);const dropdown=container.querySelector('.sps-live-filter-dropdown');const dropdownList=container.querySelector('.sps-live-filter-dropdown-menu');if(dropdownList&&dropdownList?.children.length===0){dropdown.style.display='none'}
187function updateState(){container.dataset.currentPage=currentPage;container.dataset.isDropdownOpen=isDropdownOpen}
188function toggleDropdown(){isDropdownOpen=!isDropdownOpen;updateState();updateUI()}
189function closeDropdown(){isDropdownOpen=!1;updateState();updateUI()}
190function nextPage(){if(currentPage<totalPages-1){currentPage++;updateState()}}
191function prevPage(){if(currentPage>0){currentPage--;updateState()}}
192function updateUI(){if(dropdown){if(isDropdownOpen){dropdown.classList.add('active')}else{dropdown.classList.remove('active')}}}
193container.addEventListener('click',function(e){if(e.target.closest('.sps-live-filter-nav-link')&&!e.target.closest('.sps-live-filter-dropdown')){e.preventDefault();const id=e.target.closest('.sps-live-filter-nav-link').dataset.id}
194if(e.target.closest('.sps-live-filter-dropdown .sps-live-filter-nav-link')){e.preventDefault();if(style!=='navigation'){toggleDropdown()}}
195if(e.target.closest('.sps-live-filter-dropdown-item')){e.preventDefault();const id=e.target.closest('.sps-live-filter-dropdown-item').dataset.id}
196if(e.target.closest('.sps-pagination-prev')){e.preventDefault();prevPage()}
197if(e.target.closest('.sps-pagination-next')){e.preventDefault();nextPage()}});document.addEventListener('click',function(e){if(!container.contains(e.target)){closeDropdown()}})});wrapLines()}
198window.init=init;function update_selection_field_count(){document.querySelectorAll('.sp-smart-post-live-filter-wrapper').forEach((wrapper)=>{const selectEl=wrapper.querySelector('select');const dropdownUl=wrapper.querySelector('.sp-smart-post-live-filter-dropdown, .sp-smart-post-live-filter-button, .sp-smart-post-live-filter-button-date');const moreButton=wrapper.querySelector('.sps-live-filter-dropdown-menu');buildSmartFilterDropdown(selectEl,dropdownUl,moreButton)})}
199function buildSmartFilterDropdown(selectEl,dropdownUl,moreButton){if(!selectEl||!dropdownUl)return;dropdownUl.innerHTML='';if(moreButton)moreButton.innerHTML='';const options=Array.from(selectEl.options);let attributes={};try{const dataAtt=selectEl.dataset.att;attributes=dataAtt&&dataAtt!=='undefined'?JSON.parse(dataAtt):{}}catch(e){console.warn('Invalid JSON in data-att:',e);attributes={}}
200const{taxonomyLimit,taxonomyStyle,filterType,uniqueId}=attributes;let device='Desktop';if(window.innerWidth<=781)device='Mobile';else if(window.innerWidth<=1024)device='Tablet';const limit=taxonomyLimit&&taxonomyLimit.device?taxonomyLimit.device[device]||3:3;if(taxonomyStyle==='navigation'){let currentPage=parseInt(dropdownUl.dataset.currentPage)||1;const totalPages=Math.ceil(options.length/limit);currentPage=Math.max(1,Math.min(currentPage,totalPages));dropdownUl.dataset.currentPage=currentPage;const startIndex=(currentPage-1)*limit;const endIndex=startIndex+limit;const currentOptions=options.slice(startIndex,endIndex);currentOptions.forEach((option)=>{const value=option.value;if(value===undefined)return;const label=option.getAttribute('data-label')||option.textContent.trim();const count=option.getAttribute('data-default-count')||'';const isSelected=option.selected??!1;const isDisabled=parseInt(count)===0;const li=document.createElement('li');const a=document.createElement('a');li.classList.add('sps-live-filter-nav-item');a.classList.add('sps-live-filter-nav-link');a.href='#';a.setAttribute('data-value',value);a.setAttribute('data-label',label);a.textContent=`${label}${count ? `(${count})` : ''}`;li.appendChild(a);if(label){dropdownUl.appendChild(li)}});const paginationContainer=document.createElement('div');paginationContainer.className='pagination-controls';const container=document.querySelector(`#${uniqueId}`);const prev=container.querySelector('.sps-pagination-prev');const next=container.querySelector('.sps-pagination-next');prev.addEventListener('click',()=>{dropdownUl.dataset.currentPage=currentPage-1;buildSmartFilterDropdown(selectEl,dropdownUl,moreButton)});const pageIndicator=document.createElement('span');pageIndicator.className='pagination-info';pageIndicator.textContent=`Page ${currentPage} of ${totalPages}`;next.addEventListener('click',()=>{dropdownUl.dataset.currentPage=currentPage+1;buildSmartFilterDropdown(selectEl,dropdownUl,moreButton)})}else if(moreButton){const optionsOne=options.slice(0,limit);const optionsTwo=options.slice(limit);if(filterType!=='dropdown'){optionsOne.forEach((option)=>{const value=option.value;if(value===undefined)return;const label=option.getAttribute('data-label')||option.textContent.trim();const count=option.getAttribute('data-default-count')||'';const li=document.createElement('li');const a=document.createElement('a');li.classList.add('sps-live-filter-nav-item');a.classList.add('sps-live-filter-nav-link');if(label==='All'){a.classList.add('active')}
201a.href='#';a.setAttribute('data-value',value);a.setAttribute('data-label',label);a.textContent=`${label}${count ? `(${count})` : ''}`;li.appendChild(a);if(label){dropdownUl.appendChild(li)}})}
202Array.from(filterType==='dropdown'?options:optionsTwo).forEach((option)=>{const value=option.value;if(value===undefined)return;const label=option.getAttribute('data-label')||option.textContent.trim();const a=document.createElement('a');a.classList.add('sps-live-filter-nav-link');a.href='#';a.setAttribute('data-value',value);a.setAttribute('data-label',label);a.textContent=label;moreButton.appendChild(a)})}else{options.forEach((option)=>{const value=option.value;if(value===undefined)return;const label=option.getAttribute('data-label')||option.textContent.trim();const count=option.getAttribute('data-default-count')||'';const li=document.createElement('li');const a=document.createElement('a');li.classList.add('sps-live-filter-nav-item');a.classList.add('sps-live-filter-nav-link');a.href='#';a.setAttribute('data-value',value);a.setAttribute('data-label',label);a.textContent=`${label}${count ? `(${count})` : ''}`;if(!count&&selectEl.id!=='filter-sort'){a.classList.add('active')}
203li.appendChild(a);dropdownUl.appendChild(li)})}}
204function updateAllSmartPostFilterCounts(blockParent){const wrappers=blockParent.querySelectorAll('.sp-smart-post-live-filter-wrapper');wrappers.forEach((wrapper)=>{const select=wrapper.querySelector('select');const dropdown=wrapper.querySelector('.sp-smart-post-live-filter-dropdown, .sp-smart-post-live-filter-button, .sp-smart-post-live-filter-button-date');const selectedButton=wrapper.querySelector('.sp-smart-post-live-filter-btn span');const this_filter=wrapper.querySelector('.sp-smart-post-live-filter');if(select.id==='filter-sort'){const optionMap=Array.from(select.options).reduce((map,option)=>{const value=option.value;const label=option.getAttribute('data-label')||option.textContent.trim();const isSelected=option.selected??!1;map[value]={label,isSelected};return map},{});dropdown.querySelectorAll('a').forEach((a)=>{const value=a.getAttribute('data-value');const{label,isSelected}=optionMap[value];if(isSelected){dropdown.querySelectorAll('a').forEach((el)=>el.classList.remove('active'));a.classList.add('active')}});if(select.value&&selectedButton){const{label,count}=optionMap[select.value]||{};if(label!==undefined){selectedButton.textContent=`${label}`}}}
205if(!select||!dropdown||select.id==='filter-sort'){return}
206const show_count=this_filter?.getAttribute('data-show-count');const optionMap=Array.from(select.options).reduce((map,option)=>{const value=option.value;const label=option.getAttribute('data-label')||option.textContent.trim();const countMatch=option.textContent.trim().match(/\((\d+)\)/);const count=countMatch?countMatch[1]:'0';const isSelected=option.selected??!1;map[value]={label,count,isSelected};return map},{});if(select.value&&selectedButton){const{label,count}=optionMap[select.value]||{};const count_text=show_count?`(${count})`:'';if(label!==undefined){selectedButton.textContent=`${label} ${count_text}`}}
207dropdown.querySelectorAll('a').forEach((a)=>{const value=a.getAttribute('data-value');if(!value||!optionMap[value]){return}
208const{label,count,isSelected}=optionMap[value];a.setAttribute('data-label',label);a.setAttribute('data-default-count',count);const count_text=show_count?`(${count})`:'';a.textContent=`${label} ${count_text}`;if(parseInt(count)===0){a.classList.add('disabled');a.setAttribute('aria-disabled','true')}else{a.classList.remove('disabled');a.removeAttribute('aria-disabled');if(isSelected){dropdown.querySelectorAll('a').forEach((el)=>el.classList.remove('active'));a.classList.add('active')}}})})}
209function wrapLines(){const selector=`
210        .sp-smart-post-grid-two .sp-smart-post-title,
211        .sp-smart-post-grid-three .sp-smart-post-title,
212        .sp-smart-post-carousel-two .sp-smart-post-title,
213        .sp-smart-post-slider .sp-smart-post-title,
214        .sp-smart-post-slider-two .sp-smart-post-title,
215        .sp-smart-post-thumbnail-slider .sp-smart-post-title,
216        .sp-smart-post-thumbnail-slide-two .sp-smart-post-title,
217        .sp-smart-post-grid-four .sp-smart-post-title,
218        .sp-smart-post-grid-five .sp-smart-post-title,
219        .sp-smart-post-grid-six .sp-smart-post-title,
220        .sp-smart-post-timeline-two .sp-smart-post-title`;document.querySelectorAll(selector).forEach((title)=>{if(title.dataset.processed==='true')return;const textElement=title.querySelector('.sp-smart-post-title-text');if(!textElement)return;const text=textElement.textContent.trim();if(!text)return;const temp=document.createElement('div');const style=window.getComputedStyle(textElement);Object.assign(temp.style,{position:'absolute',visibility:'hidden',whiteSpace:'nowrap',fontSize:style.fontSize,fontFamily:style.fontFamily,fontWeight:style.fontWeight,});document.body.appendChild(temp);const containerWidth=textElement.offsetWidth||title.offsetWidth;const words=text.split(' ');const lines=[];let currentLine='';words.forEach((word)=>{const testLine=currentLine?`${currentLine} ${word}`:word;temp.textContent=testLine;if(temp.offsetWidth>containerWidth&&currentLine){lines.push(currentLine);currentLine=word}else{currentLine=testLine}});if(currentLine)lines.push(currentLine);document.body.removeChild(temp);textElement.innerHTML='';
220lines.forEach((line,index)=>{const span=document.createElement('span');span.className='line';span.textContent=line;textElement.appendChild(span);if(index<lines.length-1){textElement.appendChild(document.createElement('br'))}});title.dataset.processed='true'})}

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