var awdClonedBody;
var $ssf_jQueryDoc=jQuery(document);
function awdDropDownFilterClicked(thisfilter){
var $thisfilter=jQuery(thisfilter);
if($thisfilter.attr('href')!=''&&typeof $thisfilter.attr('href')!='undefined'){
ajaxurl=$thisfilter.attr('href');
}else{
if($thisfilter.val()!=''){
ajaxurl=$thisfilter.val();
}}
if(fww_variables.use_ajax!=='noajax'){
fwwLoadAjaxProducts(ajaxurl);
return false;
}else{
}
window.location.href=ajaxurl;
return;
}
$ssf_jQueryDoc.on('click', '.widget.checkboxlist li', function(){
});
function fwwLoadAjaxProducts(url){
w=window,
d=document,
e=d.documentElement,
g=d.getElementsByTagName('body')[0],
x=w.innerWidth||e.clientWidth||g.clientWidth;
if(jQuery('.products').length==0||(x < 850&&fww_variables.use_ajax!=='ajaxeverywhere')){
if(jQuery('.products').length==0){
console.log('no products archive exists - aborting ajax');
}
window.location.href=url;
return;
}
jQuery('.products').first().html('<div class="wpi-fww-preloader"><wpi-fww-spinner><div class="wpi-fww-spinner-container active"><div class="wpi-fww-spinner-layer"><div class="wpi-fww-spinner-circle-clipper left"><div class="wpi-fww-spinner-circle"></div></div><div class="wpi-fww-spinner-circle-clipper right"><div class="wpi-fww-spinner-circle"></div></div></div></div></wpi-fww-spinner></div>');
jQuery.ajax({
type: "GET",
async: true,
url:url,
dataType: "html",
success: function (data){
pagetitle=jQuery('title', data).text();
history.pushState({url: url}, pagetitle, url);
ssf_fill_ajax_products(data);
jQuery(document).trigger('faster-woo-widgets-complete', [data]);
},
error: function(e){
console.log('got error from next page');
console.log(e);
jQuery('.products').removeClass('fwwproductsloading');
},
complete: function(data){
}});
}
function ssf_fill_ajax_products(data){
sidebarid='.sidebar,.area-sidebar-shop,aside[role="complementary"],.widget-area,.sidebar-container,.shop-sidebar,.woocommerce-sidebar,.primary-sidebar,.secondary-sidebar';
if(jQuery('.products').length==0){
jQuery('.woocommerce-info').parent().replaceWith(jQuery('.products', data).parent());
if(jQuery('.woocommerce-info').length==0){
wooinfoparent='.' + jQuery('.woocommerce-info', data).parent().attr('class');
wooinfoparent=sidebarid.replace(/ /g, '.');
jQuery(wooinfoparent).replaceWith(jQuery(wooinfoparent, data));
}}else{
jQuery('.products').replaceWith(jQuery('.products', data));
}
jQuery(sidebarid).each(function(){
var $currentSidebar=jQuery(this);
var $newSidebar=jQuery('.' + $currentSidebar.attr('class').split(' ').join('.'), data).first();
if($newSidebar.length > 0){
$currentSidebar.html($newSidebar.html());
}});
jQuery('.fww_sidebar').empty();
jQuery('.fww_sidebar').append(jQuery('.fww_sidebar', data).children());
jQuery('#fww_topbar').empty();
jQuery('#fww_topbar').append(jQuery('#fww_topbar', data).children());
jQuery(document).attr('title', jQuery(data).filter('title').text());
jQuery('.fww_archive_title').replaceWith(jQuery('.fww_archive_title', data).first());
jQuery('.woocommerce-result-count').replaceWith(jQuery('.woocommerce-result-count', data).first());
jQuery('.shop_header').replaceWith(jQuery('.shop_header', data).first());
jQuery('.page-title').replaceWith(jQuery('.page-title', data).first());
jQuery('h1').first().replaceWith(jQuery('h1', data).first());
jQuery('#fww_topbar').replaceWith(jQuery('#fww_topbar', data).first());
jQuery('.woocommerce-breadcrumb').replaceWith(jQuery('.woocommerce-breadcrumb', data).first());
var $currentPagination=jQuery('.woocommerce-pagination');
var $newPagination=jQuery('.woocommerce-pagination', data);
if($newPagination.length > 0){
if($currentPagination.length > 0){
$currentPagination.replaceWith($newPagination);
}else{
jQuery('.products').after($newPagination);
}}else{
$currentPagination.remove();
}
jQuery('.pager_wrapper').replaceWith(jQuery('.pager_wrapper', data).first());
if(jQuery('.pager_wrapper').length==0){
jQuery('.products').parent().append(jQuery('.pager_wrapper', data).first());
}
if(typeof auto_infinite_scroll==='function'){
auto_infinite_scroll(options_isw);
}
fww_doc_ready();
jQuery('.products').removeClass('fwwproductsloading');
}
window.addEventListener('popstate', function (e){
if(fww_variables.use_ajax!=='noajax'){
fwwLoadAjaxProducts(window.location.href);
return false;
}});
function fww_createCookie(name, value, days){
var expires;
if(days){
var date=new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
expires="; expires=" + date.toGMTString();
}else{
expires="";
}
document.cookie=encodeURIComponent(name) + "=" + encodeURIComponent(value) + expires + "; path=/";
}
function fww_readCookie(name){
var nameEQ=encodeURIComponent(name) + "=";
var ca=document.cookie.split(';');
for (var i=0; i < ca.length; i++){
var c=ca[i];
while (c.charAt(0)===' ')
c=c.substring(1, c.length);
if(c.indexOf(nameEQ)===0)
return decodeURIComponent(c.substring(nameEQ.length, c.length));
}
return null;
}
function fww_eraseCookie(name){
createCookie(name, "", -1);
}
jQuery.expr.pseudos.fwwicontains=function(a, i, m){
return jQuery(a).text().toUpperCase()
.indexOf(m[3].toUpperCase()) >=0;
};
var ssf_ajax_searches=[];
var ssf_presearch_ajax_contents=[];
var ssf_presearch_ajax_page=[];
function ssf_debounce(func, wait){
let timeoutId=null;
return function(...args){
if(timeoutId!==null){
clearTimeout(timeoutId);
}
timeoutId=setTimeout(()=> {
func.apply(this, args);
}, wait);
};}
var ssf_debouncedEventHandler=ssf_debounce(keyUpHandler_for_search, 100);
$ssf_jQueryDoc.on('keyup', 'input[type="text"].fww-inline-search', ssf_debouncedEventHandler);
function keyUpHandler_for_search(){
if(jQuery(this).closest('.fww-widget-content').hasClass('ssf_ajax')){
var $input=jQuery(this);
var instance=$input.closest('.fwwfilter').attr('id');
var $widgetContent=jQuery('#' + instance + ' .fww-widget-content ul.awdff');
var $nextPageButton=jQuery('#' + instance + ' .ssf_next_page');
if(instance in ssf_presearch_ajax_contents){
if($input.val()===''){
console.log('retrieving html');
$widgetContent.html(ssf_presearch_ajax_contents[instance]);
$nextPageButton.data('next_page', ssf_presearch_ajax_page[instance]);
delete ssf_presearch_ajax_contents[instance];
delete ssf_presearch_ajax_page[instance];
return;
}}else{
console.log('storing html');
ssf_presearch_ajax_contents[instance]=$widgetContent.html();
ssf_presearch_ajax_page[instance]=$nextPageButton.data('next_page');
}
ssf_filter_pagination=jQuery('#' + instance).find('.ssf_next_page');
ssf_filter_pagination.data('ssf_next_page', 2);
var ajax_search_data={
action: 'ssf_ajax_widget',
next_page: 1,
items_per_page: ssf_filter_pagination.data('items_per_page'),
instance_id: instance,
widget_class: ssf_filter_pagination.data('widget_class'),
search: jQuery(this).val(),
source_url: document.location.href
};
jQuery('#' + instance + ' .fww-widget-content.ssf_ajax').addClass('ssf_loading');
if(instance in ssf_ajax_searches){
}else{
console.log ('starting array searches array');
ssf_ajax_searches[instance]=[];
}
if(ssf_ajax_searches[instance].length > 0){
for(let eachsearch of ssf_ajax_searches[instance]){
console.log ('clearing search');
eachsearch.abort();
}
ssf_ajax_searches[instance]=[];
}
console.log(ajax_search_data);
ssf_ajax_searches[instance].push(jQuery.ajax({
type: "GET",
async: true,
url:fww_variables.ajaxurl,
data: ajax_search_data,
instance_id: ssf_filter_pagination.data('instance_id'),
next_page: ssf_filter_pagination.data('next_page'),
ajax_search: jQuery(this).val(),
dataType: "html",
success: function (data){
if(this.ajax_search!=jQuery('#' + this.instance_id + ' input[type="text"].fww-inline-search').val()){
console.log('mismatch in returned data - will avoid overwriting dom');
return;
}
if(data==''){
console.log('nothing found for this search');
jQuery('#' + this.instance_id + ' .fww-widget-content ul.awdff').html('<li class="ssf_ajax_no_matches">' + fww_variables.ssf_t_nomatches + '</li>');
jQuery('#' + this.instance_id + ' .ssf_next_page').data('next_page', 'end');
}else{
jQuery('#' + this.instance_id + ' .fww-widget-content ul.awdff').html(jQuery('.fww-widget-content ul.awdff > li', data));
jQuery('#' + this.instance_id + ' .ssf_next_page').data('next_page', '2');
}},
error: function(e){
},
complete: function(e){
console.log('ssf ajax search complete');
jQuery('#' + this.instance_id + ' .fww-widget-content.ssf_ajax').removeClass('ssf_loading');
}})
);
}else{
var searchVal=jQuery(this).val().toLowerCase();
jQuery('li, option', jQuery(this).parents('.widget')).addClass('fww-hidden-item');
var matchedItems=jQuery('li', jQuery(this).parents('.widget')).filter(function(){
var text=jQuery(this).find('> a').text().toLowerCase();
return text.indexOf(searchVal)!==-1;
});
matchedItems.each(function(){
jQuery(this).removeClass('fww-hidden-item');
jQuery(this).parents('li').removeClass('fww-hidden-item');
jQuery(this).find('li').removeClass('fww-hidden-item');
});
/*
jQuery('li,option', jQuery(this).parents('.widget')).addClass('fww-hidden-item');
jQuery('li', jQuery(this).parents('.widget')).each(function(){
var currentLi=jQuery(this);
var text=currentLi.find('> a').text().toLowerCase();
if(text.indexOf(searchVal)!==-1){
currentLi.removeClass('fww-hidden-item');
currentLi.parents('li').removeClass('fww-hidden-item');
currentLi.find('li').removeClass('fww-hidden-item');
}});
jQuery('option', jQuery(this).parents('.widget')).each(function(){
var currentLi=jQuery(this);
var text=currentLi.text().toLowerCase();
if(text.indexOf(searchVal)!==-1){
currentLi.removeClass('fww-hidden-item');
}});
*/
if(searchVal.length==0){
jQuery('li', jQuery(this).parents('.widget')).removeClass('fww-hidden-item');
}
jQuery('.fww-no-results-found', jQuery(this).parents('.widget')).hide();
jQuery('.fww-no-results-found .noresultssearch', jQuery(this).parents('.widget')).html(jQuery(this).val());
if(jQuery('li', jQuery(this).parents('.widget')).not('.fww-hidden-item').length==0&&jQuery('option', jQuery(this).parents('.widget')).not('.fww-hidden-item').length==0){
jQuery('.fww-no-results-found', jQuery(this).parents('.widget')).show();
}}
}
$ssf_jQueryDoc.on('click', 'input[type="text"].fww-inline-search', function(e){
e.stopPropagation();
});
$ssf_jQueryDoc.on('click', 'button.fww-inline-search-clear-button', function(e){
jQuery('input[type="text"].fww-inline-search').val('');
jQuery('.fww-no-results-found', jQuery(this).parents('.widget')).hide();
jQuery('li', jQuery(this).parents('.widget')).removeClass('fww-hidden-item');
jQuery('option', jQuery(this).parents('.widget')).removeClass('fww-hidden-item');
e.stopPropagation();
});
$ssf_jQueryDoc.on('click', '.fww-widget-toggle', function(){
if(jQuery(this).closest('.widget').hasClass('accordion')){
if(jQuery(this).closest('.widget').hasClass('hide-fww-content')){
jQuery('.fwwfilter.accordion').each(function(){
if(!jQuery(this).hasClass('hide-fww-content')){
cookieid=jQuery(this).attr('id');
jQuery(this).addClass('hide-fww-content');
fww_createCookie(cookieid, 'h', 7);
}});
jQuery(this).closest('.widget').removeClass('hide-fww-content');
cookieid=jQuery(this).closest('.widget').attr('id');
fww_createCookie(cookieid, 's', 7);
}else{
jQuery(this).closest('.widget').addClass('hide-fww-content');
cookieid=jQuery(this).closest('.widget').attr('id');
fww_createCookie(cookieid, 'h', 7);
}}else{
jQuery(this).closest('.widget').toggleClass('hide-fww-content');
cookieid=jQuery(this).closest('.widget').attr('id');
if(jQuery('#' + cookieid).hasClass('hide-fww-content')){
fww_createCookie(cookieid, 'h', 7);
}else{
fww_createCookie(cookieid, 's', 7);
}}
});
$ssf_jQueryDoc.on('click', '#awdffrecentproducts .removerecentproduct', function(){
jQuery(this).closest('li').remove();
productslist=jQuery('#awdffrecentproducts ul').html();
localStorage.setItem('fww-recently-viewed', productslist);
});
$ssf_jQueryDoc.on('click', '.fwwtaxaccordion', function(e){
jQuery(this).closest('li').toggleClass('showaccordionchildren');
var clickedtoggle=jQuery(this).closest('li');
jQuery(this).closest('.widget').find('.showaccordionchildren').each(function(){
if(jQuery(this)[0]!==clickedtoggle[0]&&clickedtoggle.closest(this).length==0){
jQuery(this).removeClass('showaccordionchildren');
}});
e.stopPropagation();
});
$ssf_jQueryDoc.ready(function(){
jQuery('.ssf_ajax_widget.ssf_on_load').not('.loading').not('.ssf-delay-execution').each(function(){
var $widget=jQuery(this);
ssf_load_ajax_widget($widget);
});
fww_doc_ready();
});
function ssf_load_ajax_widget($widget){
$widget.addClass('loading');
console.log('loading ajax using widget and source_url: ' + document.location.href);
jQuery.ajax({
type: "GET",
url: '/wp-json/ssf/v1/widget/tax',
data: {
widget_id: $widget.data('widget-id'),
source_url: document.location.href
},
success: function (data){
$new_widget=jQuery(data.data.widget_html);
$new_widget=jQuery('.ssf_ajax_widget', $new_widget);
$widget.replaceWith($new_widget);
fww_doc_ready('#' + $widget.data('widget-id'));
jQuery(document).trigger('ssf_ajax_widget_ready', { widget_id: $widget.data('widget-id')});
},
complete: function(data){
},
error: function (jqXHR, textStatus, errorThrown){
console.error('Error:', textStatus, errorThrown);
}});
}
document.addEventListener('DOMContentLoaded', function(){
jQuery('.fwwfilter a.ssf-bad-bot-controller').each(function(){
jQuery(this).attr('href', jQuery(this).data('bad-bots-href'));
jQuery(this).removeClass('ssf-bad-bot-controller');
});
});
function fww_doc_ready(ssf_widget_selector=''){
console.log('calling doc ready with ' + ssf_widget_selector);
jQuery('.fwwfilter a.ssf-bad-bot-controller').each(function(){
jQuery(this).attr('href', jQuery(this).data('bad-bots-href'));
jQuery(this).removeClass('ssf-bad-bot-controller');
});
jQuery(ssf_widget_selector + ' .fww-widget-content.ssf_ajax').each(function(){
var ajax_search_data={
action: 'ssf_get_ajax_selected_items',
source_url: document.location.href,
taxonomy: jQuery(this).data('taxonomy')
};
jQuery.ajax({
type: "GET",
async: true,
url:fww_variables.ajaxurl,
data: ajax_search_data,
dataType: "html",
context: this,
success: function (data){
var returnedData=jQuery(data);
var currentTaxonomy=jQuery(this).data('taxonomy');
returnedData.find('a').each(function(){
var ajaxHref=jQuery(this).attr('href');
jQuery('.fww-widget-content.ssf_ajax[data-taxonomy="' + currentTaxonomy + '"] a[href="' + ajaxHref + '"]').each(function(){
jQuery(this).closest('li').remove();
});
});
jQuery('.awdff', this).prepend(data);
updateSSFContainerCounts();
},
error: function(e){
},
complete: function(e){
}});
});
var productslist=localStorage.getItem('fww-recently-viewed');
if(!productslist||typeof(productslist)=='undefined'||productslist=='undefined') productslist='';
if(jQuery('.fww-single-product-html').length > 0){
var newProduct=jQuery('.fww-single-product-html').html();
if(productslist.indexOf(newProduct)==-1){
productslist=newProduct + productslist;
}
if(productslist!==''){
var pl=jQuery('<ul>' + productslist + '</ul>');
while (jQuery('li', pl).length > 3){
jQuery('li:last-child', pl).remove();
}
productslist=pl.html();
}
localStorage.setItem('fww-recently-viewed', productslist);
}
if(jQuery('#awdffrecentproducts').length > 0){
jQuery('#awdffrecentproducts').html('<ul class="product_list_widget">' + productslist + '</ul>');
}
jQuery(ssf_widget_selector + '.fwwfilter').each(function(){
let url=new URL(location.href);
url.searchParams.delete('swcfpc');
var chosenurl=url.toString();
chosenurl_splited=chosenurl=chosenurl.split('/' + fww_variables.pagination_base + '/');
if(chosenurl.length==1){
chosenurl=chosenurl[0];
}else{
chosenurl=chosenurl[0] + '/';
var chosenurl_params=chosenurl_splited[1].split('?');
chosenurl=chosenurl + '?' + chosenurl_params[1];
}
let non_filter_params=(new URL(chosenurl)).searchParams;
fww_variables.url_parameters.forEach(function(item, index){
non_filter_params.delete(item);
});
chosenurl=new URL(chosenurl);
chosenurl.searchParams.forEach(function(value, key){
if(key.startsWith('expand_')) return;
if(key=='s') return;
if(non_filter_params.has(key)){
let link_custom_attributes=fww_variables.link_custom_attributes;
if(link_custom_attributes){
if(Array.isArray(link_custom_attributes)&&link_custom_attributes.includes(key)){
return;
}}
chosenurl.searchParams.delete(key);
}});
var currentPath=chosenurl.href;
currentPath=currentPath.replace(/%2C/g, ',');
var $candidates=jQuery('a[data-term-link], option[data-term-link]', this);
$candidates.each(function(){
var canonicalPath=jQuery(this).attr('data-term-link');
canonicalPath=canonicalPath.replace(/%2C/g, ',');
if(currentPath.includes(canonicalPath)){
jQuery(this).closest('ul').closest('li').find('a.chosen').removeClass('chosen');
jQuery(this).addClass('chosen');
}});
jQuery('a.chosen:not(.clearfilters)', this).each(function(){
jQuery(this).attr('href', jQuery(this).data('remove_url'));
jQuery(this).parents('li.cat-item').addClass('selected');
});
});
jQuery(ssf_widget_selector + '.fwwfilter .accordion .selected').addClass('showaccordionchildren');
jQuery(ssf_widget_selector + '.fwwfilter.fwwscroll ul li.selected').each(function(){
jQuery(this).get(0).scrollIntoView();
});
if(jQuery(ssf_widget_selector + ' .fww-widget-content.ssf_ajax').length==0){
updateSSFContainerCounts();
}
jQuery('.fwwcontainer.popovergroup').each(function(){
popovergroup=jQuery(this).data('popovergroup');
popover_title=jQuery(this).data('popover-group_title');
jQuery('.fwwcontainer.popovergroup[data-popovergroup="' + popovergroup + '"]:gt(0)').hide();
jQuery('.fwwpopoutbuttontitle', this).html(popover_title);
});
jQuery('.fwwcontainer.popoutgroup').each(function(){
popoutgroup=jQuery(this).data('popoutgroup');
popout_title=jQuery(this).data('popout-group_title');
jQuery('.fwwcontainer.popoutgroup[data-popoutgroup="' + popoutgroup + '"]:gt(0)').hide();
jQuery('.fwwpopoutbuttontitle', this).html(popout_title);
});
jQuery('.ssf_range_slider').each(function(){
var range_slider=jQuery(this)[0];
if(range_slider.noUiSlider){
return;
}
if(jQuery(this).data('matchtype')=='minmax'){
range_slider_event_listener=noUiSlider.create(range_slider, {
start: [jQuery(this).data('slider_min'), jQuery(this).data('slider_max')],
step: jQuery(this).data('slider_step'),
tooltips: [wNumb({decimals: 0}), wNumb({decimals: 0})],
margin: 1,
connect: true,
orientation: 'horizontal',
behaviour: 'tap-drag',
range: {
'min': jQuery(this).data('slider_min'),
'max': jQuery(this).data('slider_max')
}});
range_slider_event_listener.on('update', function (values, handle, unencoded, tap, positions, noUiSlider){
jQuery(this.target).closest('.ssf_range_content').find('.range-filter-fields .min input').val(Math.round(values[0]));
jQuery(this.target).closest('.ssf_range_content').find('.range-filter-fields .max input').val(Math.round(values[1]));
});
}
if(jQuery(this).data('matchtype')=='min'||jQuery(this).data('matchtype')=='max'||jQuery(this).data('matchtype')=='exact'){
var slider_min=jQuery(this).data('slider_min');
var slider_max=jQuery(this).data('slider_max');
range_slider_event_listener=noUiSlider.create(range_slider, {
start: [0],
step: jQuery(this).data('slider_step'),
tooltips: [wNumb({decimals: 0})],
connect: false,
orientation: 'horizontal',
range: {
'min': jQuery(this).data('slider_min'),
'max': jQuery(this).data('slider_max')
}});
}
if(jQuery(this).data('matchtype')=='min'){
range_slider_event_listener.on('update', function (values, handle, unencoded, tap, positions, noUiSlider){
jQuery(this.target).closest('.ssf_range_content').find('.range-filter-fields .min input').val(Math.round(values[0]));
});
}
if(jQuery(this).data('matchtype')=='max'){
range_slider_event_listener.on('update', function (values, handle, unencoded, tap, positions, noUiSlider){
jQuery(this.target).closest('.ssf_range_content').find('.range-filter-fields .max input').val(Math.round(values[0]));
});
}
if(jQuery(this).data('matchtype')=='exact'){
range_slider_event_listener.on('update', function (values, handle, unencoded, tap, positions, noUiSlider){
jQuery(this.target).closest('.ssf_range_content').find('.range-filter-fields .exact input').val(Math.round(values[0]));
});
}
range_slider_event_listener.on('end', function (values, handle){
if(jQuery(this.target).closest('.ssf_range_content').find('.fwwpriceform').hasClass('nopriceboxes')){
jQuery(this.target).closest('ssf_range_content').find('.range-filter-fields .ssf_apply_range_filter').trigger('click');
}});
min_param=jQuery(this).data('min_param');
max_param=jQuery(this).data('max_param');
exact_param=jQuery(this).data('exact_param');
if(jQuery(this).data('matchtype')=='exact'){
this.noUiSlider.set([getUrlParameterOrNull(exact_param)]);
}
if(jQuery(this).data('matchtype')=='minmax'){
this.noUiSlider.set([getUrlParameterOrNull(min_param) , getUrlParameterOrNull(max_param)]);
}
if(jQuery(this).data('matchtype')=='min'){
this.noUiSlider.set([getUrlParameterOrNull(min_param)]);
}
if(jQuery(this).data('matchtype')=='max'){
this.noUiSlider.set([getUrlParameterOrNull(max_param)]);
}});
jQuery('.ssf_existing_meta').each(function(){
meta_key=jQuery(this).data('meta_key');
if(jQuery('.pff-field.min.' + meta_key).length > 0){
jQuery('.min', this).html(jQuery('.pff-field.min.' + meta_key + ' label').html());
}
if(jQuery('.pff-field.max.' + meta_key).length > 0){
jQuery('.max', this).html(jQuery('.pff-field.max.' + meta_key + ' label').html());
}
if(jQuery('.pff-field.exact.' + meta_key).length > 0){
jQuery('.exact', this).html(jQuery('.pff-field.exact.' + meta_key + ' label').html());
}});
if(fww_variables.hide_top_filters=='hideonmobile'){
if(jQuery(window).width() > 720){
jQuery('#fww_topbar').css('display','block');
}}
jQuery('.fwwcontainer.ssf_ajax_event:not(.ssf_event_added)').each(function(){
var $container=jQuery(this);
$container.addClass('ssf_event_added');
var eventName=$container.data('event-name');
var handleEvent=function(e){
ssf_load_ajax_widget(jQuery('.ssf_ajax_widget', $container));
jQuery(document).off(eventName, handleEvent);
};
if(eventName){
jQuery(document).on(eventName, handleEvent);
}});
if(ssf_widget_selector==''){
jQuery(document).trigger('ssf_doc_ready');
}}
window.addEventListener('popstate', function (e){
if(jQuery('#awdffrecentproducts').length > 0){
var productslist=localStorage.getItem('fww-recently-viewed');
if(!productslist||typeof(productslist)=='undefined'||productslist=='undefined') productslist='';
jQuery('#awdffrecentproducts').html('<ul class="product_list_widget">' + productslist + '</ul>');
}});
$ssf_jQueryDoc.on('mouseenter', '.fwwcontainer.ssf_ajax_hover:not(.ssf_ajax_loading)', function(){
console.log('loading on hover');
var $widget=jQuery(this);
$widget.addClass('ssf_ajax_loading');
ssf_load_ajax_widget(jQuery('.ssf_ajax_widget', this));
});
$ssf_jQueryDoc.on('click', '.fwwcontainer.popout button.fwwpopout, .fwwcontainer.popoutgroup button.fwwpopout', function(e){
if((jQuery(this).parent().hasClass('ssf_ajax_click')||jQuery(this).parent().hasClass('ssf_ajax_hover')||jQuery(this).parent().find('.ssf-delay-execution').length > 0)&&!jQuery(this).parent().hasClass('ssf_ajax_loading')){
jQuery(this).parent().addClass('ssf_ajax_loading');
ssf_load_ajax_widget(jQuery(this).parents('.fwwcontainer').find('.ssf_ajax_widget'));
}
if(jQuery(this).closest('.popoutgroup').length > 0){
popoutgroup=jQuery(this).closest('.popoutgroup').data('popoutgroup');
var popoutid=jQuery(this).closest('.popoutgroup').find('.popout-container').first().attr('id');
jQuery('.fwwcontainer.popoutgroup[data-popoutgroup="' + popoutgroup + '"]').each(function(){
if(jQuery(this).find('#' + popoutid).length > 0){
return;
}
jQuery(this).find('.fwwfilter').detach().appendTo('#' + popoutid);
});
}
if(jQuery(this).closest('.fwwcontainer.popout, .fwwcontainer.popoutgroup').hasClass('open')){
jQuery(this).closest('.fwwcontainer.popout, .fwwcontainer.popoutgroup').removeClass('open');
jQuery(this).closest('.fwwcontainer.popout, .fwwcontainer.popoutgroup').find('.popout-container').hide();
}else{
jQuery('.fwwcontainer.popout, .fwwcontainer.popoutgroup').removeClass('open');
jQuery('.fwwcontainer.popout .popout-container, .fwwcontainer.popoutgroup .popout-container').hide();
jQuery(this).closest('.fwwcontainer.popout, .fwwcontainer.popoutgroup').find('.popout-container').show();
jQuery(this).closest('.fwwcontainer.popout, .fwwcontainer.popoutgroup').addClass('open');
}
e.stopPropagation();
});
$ssf_jQueryDoc.on('click', '.fwwcontainer .popout-container, .ssf .dialog-content', function(e){
e.stopPropagation();
});
$ssf_jQueryDoc.on('click', function(){
jQuery('.fwwcontainer.popout, .fwwcontainer.popoutgroup').removeClass('open');
jQuery('.fwwcontainer.popout .popout-container, .fwwcontainer.popoutgroup .popout-container').hide();
});
$ssf_jQueryDoc.on('click', 'div.ssf-close-popover', function(e){
jQuery(this).closest('.dialog-container.ssf').attr('aria-hidden', 'true');
});
$ssf_jQueryDoc.on('click', '.fwwcontainer.popover button.fwwpopover, .fwwcontainer.popovergroup button.fwwpopover', function(e){
var dialogid=jQuery(this).data('a11y-dialog-show');
if(jQuery(this).closest('.popovergroup').length > 0){
popovergroup=jQuery(this).closest('.popovergroup').data('popovergroup');
jQuery('.fwwcontainer.popovergroup[data-popovergroup="' + popovergroup + '"]').each(function(){
if(jQuery(this).find('#' + dialogid).length > 0){
return;
}
jQuery(this).find('.fwwfilter').detach().appendTo('#' + dialogid + ' .dialog-content');
});
}
const element=document.getElementById(dialogid);
const dialog=new A11yDialog(element);
dialog.show();
});
function sff_check_scroll(el){
if(jQuery(el).scrollTop() + jQuery(el).innerHeight() >=jQuery(el)[0].scrollHeight - 20){
instance=jQuery(el).closest('.fwwfilter').attr('id');
ssf_scroll_filter(instance);
}}
$ssf_jQueryDoc.on('click', '.woocommerce-pagination a, .page-numbers', function(e){
if(fww_variables.use_ajax!=='noajax'){
e.preventDefault();
e.stopPropagation();
var paginationUrl=jQuery(this).attr('href');
if(paginationUrl&&paginationUrl!=='javascript:void(0);'){
fwwLoadAjaxProducts(paginationUrl);
}
return false;
}});
function ssf_scroll_filter(instance){
ssf_filter_pagination=jQuery('#' + instance).find('.ssf_next_page');
if(ssf_filter_pagination.data('next_page')=='end'){
return;
}
if(ssf_filter_pagination.parents('.fwwfilter').find('.fww-widget-content.ssf_ajax').hasClass('ssf_loading')){
console.log('ssf already loading, will wait for data before attempting another scroll');
return;
}
search=ssf_filter_pagination.parents('.fwwfilter').find('.fww-inline-search').val();
var next_page_data={
action: 'ssf_ajax_widget',
next_page: ssf_filter_pagination.data('next_page'),
items_per_page: ssf_filter_pagination.data('items_per_page'),
instance_id: ssf_filter_pagination.data('instance_id'),
widget_class: ssf_filter_pagination.data('widget_class'),
search: search,
source_url: document.location.href
};
console.log('scrolling');
console.log(next_page_data);
jQuery('#' + instance + ' .fww-widget-content.ssf_ajax').addClass('ssf_loading');
jQuery.ajax({
type: "GET",
async: true,
url:fww_variables.ajaxurl,
data: next_page_data,
instance_id: ssf_filter_pagination.data('instance_id'),
next_page: ssf_filter_pagination.data('next_page'),
dataType: "html",
success: function (data){
var instance_selector='#' + this.instance_id;
if(data==''){
jQuery(instance_selector + ' .ssf_next_page').data('next_page', 'end');
}else{
if(jQuery(instance_selector + ' .ssf_next_page').data('next_page')==this.next_page){
jQuery(instance_selector + ' .ssf_next_page').data('next_page', this.next_page+1);
fresh_page=jQuery('.fww-widget-content ul.awdff > li', data);
var existingHrefs=jQuery(instance_selector + ' .fww-widget-content ul.awdff a').map(function(){
return jQuery(this).attr('href');
}).get();
jQuery(instance_selector + ' .fww-widget-content ul.awdff li.selected').each(function(){
var title=jQuery('a', this).attr('title');
let removedItem=jQuery('a[title="' + title + '"]', fresh_page).closest('li').remove();
fresh_page=fresh_page.not(removedItem);
});
/*
fresh_page.each(function(){
var href=jQuery(this).find('a').attr('href');
if(!existingHrefs.includes(href)){
jQuery(instance_selector + ' .fww-widget-content ul.awdff').append(this);
existingHrefs.push(href);
}});
*/
jQuery(instance_selector + ' .fww-widget-content ul.awdff').append(fresh_page);
}}
},
error: function(e){
console.log('ajax error');
console.log(e);
},
complete: function(e){
console.log('ajax complete');
console.log(e);
jQuery('#' + this.instance_id + ' .fww-widget-content.ssf_ajax').removeClass('ssf_loading');
}});
}
$ssf_jQueryDoc.on('click', 'button.ssf_show_filters', function(){
if(jQuery('#fww_topbar').css('display')=='none'){
jQuery('#fww_topbar').css('display','block');
}else{
jQuery('#fww_topbar').css('display','none');
}});
var getUrlParameterOrNull=function getUrlParameterOrNull(sParam){
var sPageURL=window.location.search.substring(1),
sURLVariables=sPageURL.split('&'),
sParameterName,
i;
for (i=0; i < sURLVariables.length; i++){
sParameterName=sURLVariables[i].split('=');
if(sParameterName[0]===sParam){
return sParameterName[1]===undefined ? true:decodeURIComponent(sParameterName[1]);
}}
return null;
};
$ssf_jQueryDoc.on('change', '.range-filter-fields .min input', function(){
jQuery(this).closest('.ssf_range_content').find('.ssf_range_slider')[0].noUiSlider.set([jQuery(this).val(), null]);
});
$ssf_jQueryDoc.on('change', '.range-filter-fields .max input', function(){
jQuery(this).closest('.ssf_range_content').find('.ssf_range_slider')[0].noUiSlider.set([null, jQuery(this).val()]);
});
$ssf_jQueryDoc.on('click', '.ssf_range_form .ssf_apply_range_filter', function(){
matchtype=jQuery(this).closest('.ssf_range_form').data('matchtype');
console.log(matchtype);
if(jQuery(this).closest('.ssf_range_form').find('.min input').val()==''&&jQuery(this).closest('.ssf_range_form').find('.max input').val()==''){
return false;
}
if(jQuery(this).closest('.ssf_range_form').find('.min input').val()==''){
matchtype='max';
}
if(jQuery(this).closest('.ssf_range_form').find('.max input').val()==''){
matchtype='min';
}
url=jQuery(this).closest('.ssf_range_form').data(matchtype + 'url');
if(matchtype=='minmax'||matchtype=='min'){
url=url.replace('=SSF_META_MIN', '=' + jQuery(this).closest('.ssf_range_form').find('.min input').val());
}
if(matchtype=='minmax'||matchtype=='max'){
url=url.replace('=SSF_META_MAX', '=' + jQuery(this).closest('.ssf_range_form').find('.max input').val());
}
if(matchtype=='exact'){
url=url.replace('=SSF_META_EXACT', '=' + jQuery(this).closest('.ssf_range_form').find('.exact input').val());
}
if(fww_variables.use_ajax!=='noajax'){
fwwLoadAjaxProducts(url);
return false;
}else{
}
window.location.href=url;
});
$ssf_jQueryDoc.on('change', '.ssf_range_content > select', function(){
if(jQuery(this).val()!==''){
window.location.href=jQuery(this).val();
}});
function updateSSFContainerCounts(){
jQuery('.fwwfilter .selectedcountcontainer').each(function(){
totalselected=jQuery(this).closest('.fwwfilter').find('.chosen:not(.clearfilters)').length;
if(jQuery('.fww-widget-content.ssf_ajax').length==0){
console.log('no ajax widget on page');
if(jQuery(this).closest('.fwwcontainer').find('.widget_awd_show_existing_filters_widget').length > 0){
totalselected--;
console.log('removed a count 1.2');
}}
if(totalselected > 0){
jQuery(this).html('<span class="selectedcount">' + totalselected + '</span>');
}});
var last_ssf_container='';
jQuery('.fwwcontainer .selectedcountcontainer').each(function(){
this_ssf_container=jQuery(this).closest('.fwwcontainer').data('popoutgroup');
if(typeof this_ssf_container=='undefined'){
this_ssf_container=jQuery(this).closest('.fwwcontainer').data('popovergroup');
}
if(last_ssf_container!=this_ssf_container&&this_ssf_container!=''){
if(jQuery(this).closest('.popoutgroup, .popovergroup').length > 0){
popoutgroup=jQuery(this).closest('.popoutgroup, .popovergroup').data('popoutgroup');
if(typeof popoutgroup=='undefined'){
popoutgroup=jQuery(this).closest('.popoutgroup, .popovergroup').data('popovergroup');
}
var popoutid=jQuery(this).closest('.popoutgroup, .popovergroup').find('.popout-container, .dialog-container').first().attr('id');
jQuery('.fwwcontainer.popoutgroup[data-popoutgroup="' + popoutgroup + '"], .fwwcontainer.popovergroup[data-popovergroup="' + popoutgroup + '"]').each(function(){
if(jQuery(this).find('#' + popoutid).length > 0){
return;
}
jQuery(this).find('.fwwfilter').detach().appendTo('#' + popoutid);
});
}else{
}}
totalselected=jQuery(this).closest('.fwwcontainer').find('.chosen:not(.clearfilters)').length;
if(jQuery('.fww-widget-content.ssf_ajax').length==0){
if(jQuery(this).closest('.widget_awd_show_existing_filters_widget').length > 0){
totalselected--;
totalselected--;
console.log('removed a count 2.1');
}
if(jQuery(this).closest('.fwwcontainer').find('.widget_awd_show_existing_filters_widget').length > 0){
totalselected--;
console.log('removed a count 2.2');
}}
if(totalselected > 0&&(typeof this_ssf_container=='undefined'||this_ssf_container!=last_ssf_container)){
jQuery(this).html('<span class="selectedcount">' + totalselected + '</span>');
}
last_ssf_container=jQuery(this).closest('.fwwcontainer').data('popoutgroup');
});
}
let selectedUrls=[];
$ssf_jQueryDoc.on('click', '.widget_awd_fast_attribute_widget a, .widget_awd_show_existing_filters_widget a, .widget_awd_fast_category_widget a, .widget_fww_custom_tax_widget a, a.fwwattributelink, .widget_fww_instock_widget input[type="radio"], .widget_fww_onsale_widget input[type="radio"]', function(e){
if(jQuery(this).attr('type')!='radio'){
}
if(jQuery('.apply-filter-button').length > 0){
group='';
if(jQuery(this).closest('.fwwcontainer').length > 0){
group=jQuery(this).closest('.fwwcontainer').data('popoutgroup');
if(typeof group=='undefined'){
group=jQuery(this).closest('.fwwcontainer').data('popovergroup');
}
if(typeof group=='undefined'){
group='';
}
console.log('checking for apply button for group: ' + group);
if(jQuery('.apply-filter-button[data-group="' + group + '"]').length > 0){
console.log('there is an apply button for this group');
let urlPart=this.getAttribute('href').replace(this.getAttribute('data-remove_url'), '');
if(!selectedUrls.includes(urlPart)){
selectedUrls.push(urlPart);
}else{
let index=selectedUrls.indexOf(urlPart);
if(index > -1){
selectedUrls.splice(index, 1);
}}
this.style.color=this.style.color==='red' ? '':'red';
return false;
}}
}
awdDropDownFilterClicked(this);
});
$ssf_jQueryDoc.on('click', 'input.apply-filter-button', function(e){
e.preventDefault();
let baseUrl="http://localhost/";
let combinedUrl=baseUrl + selectedUrls.join('/');
alert(combinedUrl);
window.location.href=combinedUrl;
});
document.addEventListener('click', function (e){
const a=e.target.closest('.fww-widget-content');
if(!a) return;
e.preventDefault();
}, true);