jQuery(document).ready(function($){function wpcd_moreLessDescription(mLDElements){let num_words=Number(wpcd_main_js.word_count);let full_description,more,less;if(!mLDElements){full_description=$('.wpcd-full-description');more=$('.wpcd-more-description');less=$('.wpcd-less-description');}else{full_description=mLDElements.fullDescription;more=mLDElements.more;less=mLDElements.less;}full_description.each(function(){$this=$(this);var full_content=$this.html();var check=full_content.split(' ').length>num_words;if(check){var short_content=full_content.split(' ').slice(0,num_words).join(' ');$this.siblings('.wpcd-short-description').html(short_content+'...');$this.hide();$this.siblings('.wpcd-less-description').hide();}else{$(this).siblings('.wpcd-more-description').hide();$(this).siblings('.wpcd-more-description');$(this).siblings('.wpcd-less-description').hide();$(this).siblings('.wpcd-short-description').hide();}});more.click(function(e){e.preventDefault();$(this).siblings('.wpcd-full-description').show();$(this).siblings('.wpcd-less-description').show();$(this).siblings('.wpcd-short-description').hide();$(this).hide();});less.click(function(e){e.preventDefault();$(this).siblings('.wpcd-short-description').show();$(this).siblings('.wpcd-more-description').show();$(this).siblings('.wpcd-full-description').hide();$(this).hide();});};wpcd_moreLessDescription();console.log("here") $.each($('#wpcd_cat_ul > li'),function(){if($(this).children('a').attr('href')===window.location.href){$(this).children('a').addClass('active');}});const CouponsNavigation={categoriesPaginationSetTimeout:'',jsDataTax:'data-category',action:document.querySelector('#wpcd_coupon_pagination_wr')&&document.querySelector('#wpcd_coupon_pagination_wr').getAttribute('wpcd-data-action')?document.querySelector('#wpcd_coupon_pagination_wr').getAttribute('wpcd-data-action'):'',couponTemplate:$('#wpcd_coupon_template'),infinityScrollInArchive:document.querySelector('#wpcd_coupon_template')&&document.querySelector('#wpcd_coupon_template').getAttribute('wpcd-data-infinity_scroll_in_archive')?document.querySelector('#wpcd_coupon_template').getAttribute('wpcd-data-infinity_scroll_in_archive'):'',wpcdCatUl:document.querySelector('#wpcd_cat_ul'),wpcdDropbtn:document.querySelector('#wpcd_cat_ul .wpcd_dropbtn'),searchInputField:$('.wpcd_searchbar_search input'),searchText:'',couponPaginationActiveRequest:false,lastScroll:null,wpcdDocumentEventGenerate:function(eventName,element,details){if(eventName&&element){if(!details){details=true;}let event=new CustomEvent(eventName,{detail:details,bubbles:true});element.dispatchEvent(event);}},infinityScroll:function(event){if(CouponsNavigation.couponPaginationActiveRequest)return;if(!CouponsNavigation.lastScroll&&typeof CouponsNavigation.lastScroll==='object'){CouponsNavigation.lastScroll=$(this).scrollTop();return;}let currentScroll=$(this).scrollTop();if(currentScroll<=CouponsNavigation.lastScroll){CouponsNavigation.lastScroll=currentScroll;return;}CouponsNavigation.lastScroll=currentScroll;let wpcdCouponPaginationWr=document.querySelector('#wpcd_coupon_pagination_wr');if(wpcdCouponPaginationWr){const scrollAmount=document.documentElement.scrollTop||document.body.scrollTop;const pagWpCoordsY=wpcdCouponPaginationWr.getBoundingClientRect().top+window.pageYOffset;const windowHeight=window.innerHeight;if((scrollAmount+windowHeight)>=pagWpCoordsY){let hrefEl=wpcdCouponPaginationWr.querySelector('.current').nextElementSibling;if(hrefEl){const href=hrefEl.getAttribute('href');const href_arr=CouponsNavigation.wpcd_getUrlVar(href);const wpcd_coupon_taxonomy=href_arr['wpcd_category']?href_arr['wpcd_category']:href_arr['wpcd_vendor'];CouponsNavigation.couponPaginationActiveRequest=true;CouponsNavigation.wpcd_ajaxCouponCategoriesPagination(href_arr['wpcd_page_num'],wpcd_coupon_taxonomy);}}}},wpcd_ajaxCouponCategoriesPagination:function(wpcd_page_num,wpcd_coupon_taxonomy,sectionScrollTop=true){let wpcdCouponLoader=document.querySelector('.wpcd_coupon_loader');if(!this.infinityScrollInArchive||wpcd_page_num==1){if(sectionScrollTop){let scrollTop=$('.wpcd_archive_section').offset().top;$('html, body').animate({scrollTop:scrollTop-150},300);}}else{wpcdCouponLoader.classList.add('wpcd_coupon_loader_infinite_scroll');}wpcdCouponLoader.classList.remove('wpcd_coupon_hidden_loader');clearTimeout(this.categoriesPaginationSetTimeout);this.categoriesPaginationSetTimeout=setTimeout(function(){let coupon_template;let coupon_items_count;let coupon_sortby;let coupon_exclude_cat;let wpcd_data_coupon_page_url;let wpcd_data_category_coupons;let wpcd_data_vendor_coupons;let wpcd_data_ven_cat_id;let wpcd_coupon_taxonomy_category;let wpcd_coupon_taxonomy_vendor;if(CouponsNavigation.jsDataTax=='data-category'){wpcd_coupon_taxonomy_category=wpcd_coupon_taxonomy;}else if(CouponsNavigation.jsDataTax=='data-vendor'){wpcd_coupon_taxonomy_vendor=wpcd_coupon_taxonomy;}let wpcd_coupon_template=$('#wpcd_coupon_template');if(wpcd_coupon_template.length>0){coupon_template=wpcd_coupon_template.attr('wpcd-data-coupon_template');coupon_items_count=wpcd_coupon_template.attr('wpcd-data-coupon_items_count');coupon_sortby=wpcd_coupon_template.attr('wpcd-data-coupon_sortby');coupon_exclude_cat=wpcd_coupon_template.attr('wpcd-data-coupon_exclude_cat');wpcd_data_coupon_page_url=wpcd_coupon_template.attr('wpcd-data-coupon_page_url');wpcd_data_category_coupons=wpcd_coupon_template.attr('wpcd-data_category_coupons');wpcd_data_vendor_coupons=wpcd_coupon_template.attr('wpcd-data_vendor_coupons');wpcd_data_ven_cat_id=wpcd_coupon_template.attr('wpcd-data_ven_cat_id');}if(!coupon_template){coupon_template=undefined;}if(!wpcd_page_num){wpcd_page_num=undefined;}const search_text=CouponsNavigation.searchText?CouponsNavigation.searchText:undefined;$.ajax({type:'post',dataType:'json',url:wpcd_object.ajaxurl,data:{action:CouponsNavigation.action,security:wpcd_object.security,wpcd_category:wpcd_coupon_taxonomy_category,wpcd_vendor:wpcd_coupon_taxonomy_vendor,coupon_template:coupon_template,coupon_items_count:coupon_items_count,coupon_sortby:coupon_sortby,coupon_exclude_cat:coupon_exclude_cat,wpcd_data_coupon_page_url:wpcd_data_coupon_page_url,wpcd_data_category_coupons:wpcd_data_category_coupons,wpcd_data_vendor_coupons:wpcd_data_vendor_coupons,wpcd_data_ven_cat_id:wpcd_data_ven_cat_id,wpcd_page_num:wpcd_page_num,search_text:search_text},success:function(response){if(response){const coupon_container=$('.wpcd_coupon_archive_container');if(coupon_container.length>0){let count_down_span;let masterTooltip;let mLDElements;let wpcdCouponUl=coupon_container.find('#wpcd_coupon_ul');if(!CouponsNavigation.infinityScrollInArchive){coupon_container.html(response);$('#wpcd_coupon_pagination_wr a.page-numbers').off('click');$('#wpcd_coupon_pagination_wr a.page-numbers').on('click',function(e){e.preventDefault();const href=$(this).attr('href');const href_arr=CouponsNavigation.wpcd_getUrlVar(href);CouponsNavigation.wpcd_ajaxCouponCategoriesPagination(href_arr['wpcd_page_num'],wpcd_coupon_taxonomy,true);});masterTooltip=$('.masterTooltip');}else{$('#wpcd_coupon_pagination_wr').remove();if(wpcdCouponUl.length){if(wpcd_page_num==1){wpcdCouponUl.html(response);wpcdCouponUl.prepend('
');}else{wpcdCouponUl.append('');wpcdCouponUl.append(response);}}else{if(wpcd_page_num==1){coupon_container.html(response);wpcdCouponUl.prepend('');}else{coupon_container.append('');coupon_container.append(response);}}let boundaryBetweenOldAndNewItems=$('.boundaryBetweenOldAndNewItems');wpcdCouponLoader.classList.remove('wpcd_coupon_loader_infinite_scroll');let newItems=boundaryBetweenOldAndNewItems.nextAll('.wpcd_item');if(!newItems.length){newItems=boundaryBetweenOldAndNewItems.nextAll('.wpcd_coupon_li');}count_down_span=newItems.find('[data-countdown_coupon]');masterTooltip=newItems.find('.masterTooltip');mLDElements={};mLDElements.fullDescription=newItems.find('.wpcd-full-description');mLDElements.more=newItems.find('.wpcd-more-description');mLDElements.less=newItems.find('.wpcd-less-description');boundaryBetweenOldAndNewItems.remove();}wpcdCouponLoader.classList.add('wpcd_coupon_hidden_loader');wpcd_countDownFun(count_down_span);masterTooltip.hover(function(){var title=$(this).attr('title');$(this).data('tipText',title).removeAttr('title');$('').text(title).appendTo('body').fadeIn('slow');},function(){$(this).attr('title',$(this).data('tipText'));$('.wpcd-copy-tooltip').remove();}).mousemove(function(e){var mousex=e.pageX+20;var mousey=e.pageY+10;$('.wpcd-copy-tooltip').css({top:mousey,left:mousex})});if(!wpcd_coupon_taxonomy)wpcd_coupon_taxonomy='all';$.each($('#wpcd_cat_ul li'),function(){if($(this).children('a').attr(CouponsNavigation.jsDataTax)==wpcd_coupon_taxonomy){$(this).children('a').addClass('active');}else{$(this).children('a').removeClass('active');}});wpcd_moreLessDescription(mLDElements);}}else{}},complete:function(data){CouponsNavigation.couponPaginationActiveRequest=false;}});},500);},dropDownContDisplayBlock:function(){$(".wpcd_categories_in_dropdown > div").css('display','block');},dropDownContDisplayNone:function(){$(".wpcd_categories_in_dropdown > div").css('display','none');},wpcdCategoriesDropdown:function(){var sw=jQuery(".wpcd_div_nav_block").width();if(sw<850){$(".wpcd_categories_in_dropdown > div").addClass('wpcd_dropdown-content');$(".wpcd_categories_in_dropdown > a").css('display','inline');this.wpcdCatUl.addEventListener('mouseenter',this.dropDownContDisplayBlock,false);this.wpcdCatUl.addEventListener('mouseleave',this.dropDownContDisplayNone,false);this.wpcdDropbtn.addEventListener('click',this.dropDownContDisplayBlock,false);}else{$(".wpcd_categories_in_dropdown > div").removeClass('wpcd_dropdown-content');$(".wpcd_categories_in_dropdown > a").css('display','none');this.wpcdCatUl.removeEventListener('mouseenter',this.dropDownContDisplayBlock,false);this.wpcdCatUl.removeEventListener('mouseleave',this.dropDownContDisplayNone,false);this.wpcdDropbtn.removeEventListener('click',this.dropDownContDisplayBlock,false);}},wpcd_getUrlVar:function(urlVar){if(!urlVar)urlVar='';let arrayVar=[];let valueAndKey=[];let resultArray=[];arrayVar=(urlVar.substr(1)).split('&');if(arrayVar[0]=="")return false;for(let i=0;i