(function($){
"use strict";
$(document).ready(function() {
//Product Filter
function get_filter(){
var filter = {};
filter['tab_list']=[];
$('#tab-list-filter li a').each(function(){
filter['tab_list'].push($(this).attr('data-value'));
})
$('ul.attr-list').each(function(){
var key = $(this).attr('data-key');
filter[key]=[];
$(this).find('li a').each(function(){
if($(this).hasClass('selected')) filter[key].push($(this).attr('data-value'));
})
})
filter['price'] = $( "#get-filter-price" ).val();
return filter;
}
$('.filter-ajax').on("click",function(){
$('.tab-content').html('
');
var data_filter = get_filter();
var number = $('#tab-list-filter').attr('data-number');
var order = $('#tab-list-filter').attr('data-order');
var orderby = $('#tab-list-filter').attr('data-orderby');
var tab_is = $('#tab-list-filter').attr('data-tab_is');
var pre = $('#tab-list-filter').attr('data-pre');
var product_type = $('#tab-list-filter').attr('data-product_type');
var action = $('#tab-list-filter').attr('data-action');
var style = $('#tab-list-filter').attr('data-style');
// console.log(data_filter);
// console.log(JSON.parse(JSON.stringify([1, 'false', false])));
$.ajax({
type : "post",
url : ajax_process.ajaxurl,
crossDomain: true,
data: {
action: action,
data_filter: data_filter,
number: number,
order: order,
orderby: orderby,
tab_is: tab_is,
pre: pre,
product_type: product_type,
style: style,
},
success: function(data){
if(data[data.length-1] == '0' ){
data = data.split('');
data[data.length-1] = '';
data = data.join('');
}
$('.tab-content').html(data);
},
error: function(MLHttpRequest, textStatus, errorThrown){
console.log(errorThrown);
}
});
})
$('.tab-content').on("click",".load-page.active",function(e){
e.preventDefault();
})
$('.tab-content').on("click",".load-page:not(.active)",function(e){
e.preventDefault();
$(this).parents('.tab-pane').find('ul.list-product').append('');
$(this).parents('ul').find('.load-page').removeClass('active');
$(this).addClass('active')
var seff = $(this);
var data_filter = get_filter();
var tab_value = $('#tab-list-filter li.active').find('a').attr('data-value');
var number = $('#tab-list-filter').attr('data-number');
var order = $('#tab-list-filter').attr('data-order');
var orderby = $('#tab-list-filter').attr('data-orderby');
var tab_is = $('#tab-list-filter').attr('data-tab_is');
var pre = $('#tab-list-filter').attr('data-pre');
var product_type = $('#tab-list-filter').attr('data-product_type');
var paged = $(this).html();
$.ajax({
type : "post",
url : ajax_process.ajaxurl,
crossDomain: true,
data: {
action: "load_page_product",
data_filter: data_filter,
tab_value: tab_value,
number: number,
order: order,
orderby: orderby,
tab_is: tab_is,
paged: paged,
product_type: product_type,
},
success: function(data){
if(data[data.length-1] == '0' ){
data = data.split('');
data[data.length-1] = '';
data = data.join('');
}
console.log(data);
seff.parents('.tab-pane').find('ul.list-product').html(data);
},
error: function(MLHttpRequest, textStatus, errorThrown){
console.log(errorThrown);
}
});
})
$('.tab-content').on("click",".loadmore-ajax",function(e){
e.preventDefault();
var seff = $(this);
var data_filter = get_filter();
var item_slug = $(this).attr('data-item_slug');
var paged = $(this).attr('data-paged');
// var max_page = $(this).attr('data-max_page');
var max_page_ajax = $(this).attr('data-max_page_ajax');
var item_slug = $(this).attr('data-tab_value');
var number = $('#tab-list-filter').attr('data-number');
var order = $('#tab-list-filter').attr('data-order');
var orderby = $('#tab-list-filter').attr('data-orderby');
var style = $('#tab-list-filter').attr('data-style');
console.log(style);
var page_new;
if(paged == 1){
if(number <= 4) page_new = Number(paged) +1;
else{
if(number % 4 == 0) page_new = Number(number/4) +1;
else page_new = Number(number/4) + 2;
}
}
else page_new = Number(paged) +1;
if(Number(paged) < Number(max_page_ajax)){
$(this).parents('.tab-pane').find('ul.list-product').append('');
$.ajax({
type : "post",
url : ajax_process.ajaxurl,
crossDomain: true,
data: {
action: "load_more_product",
data_filter: data_filter,
item_slug: item_slug,
// max_page: max_page,
max_page_ajax: max_page_ajax,
number: number,
order: order,
orderby: orderby,
paged: paged,
style: style,
},
success: function(data){
$('.ajax-loading').remove();
if(data[data.length-1] == '0' ){
data = data.split('');
data[data.length-1] = '';
data = data.join('');
}
console.log(data);
seff.parents('.tab-pane').find('ul.list-product').append(data);
$('.loadmore-ajax').attr('data-paged',page_new);
if(Number(page_new) >= Number(max_page_ajax)){
seff.fadeOut();
}
},
error: function(MLHttpRequest, textStatus, errorThrown){
console.log(errorThrown);
}
});
}
})
$('#get-filter-price').on("click",function(){
$('.tab-content').html('');
var data_filter = get_filter();
var number = $('#tab-list-filter').attr('data-number');
var order = $('#tab-list-filter').attr('data-order');
var orderby = $('#tab-list-filter').attr('data-orderby');
var tab_is = $('#tab-list-filter').attr('data-tab_is');
var pre = $('#tab-list-filter').attr('data-pre');
var product_type = $('#tab-list-filter').attr('data-product_type');
var action = $('#tab-list-filter').attr('data-action');
var style = $('#tab-list-filter').attr('data-style');
console.log(data_filter);
// console.log(JSON.parse(JSON.stringify([1, 'false', false])));
$.ajax({
type : "post",
url : ajax_process.ajaxurl,
crossDomain: true,
data: {
action: action,
data_filter: data_filter,
number: number,
order: order,
orderby: orderby,
tab_is: tab_is,
pre: pre,
product_type: product_type,
style: style,
},
success: function(data){
if(data[data.length-1] == '0' ){
data = data.split('');
data[data.length-1] = '';
data = data.join('');
}
$('.tab-content').html(data);
},
error: function(MLHttpRequest, textStatus, errorThrown){
console.log(errorThrown);
}
});
})
//Set section
$('#checkform').on("click",function(){
var checked = $(this).is(':checked');
$.ajax({
type : "post",
url : ajax_process.ajaxurl,
crossDomain: true,
data: {
action: "set_dont_show",
checked: checked
},
success: function(data){
},
error: function(MLHttpRequest, textStatus, errorThrown){
console.log(errorThrown);
}
});
})
/// Woocommerce Ajax
$("body").on("click",".add_to_cart_button:not(.product_type_variable)",function(e){
e.preventDefault();
var product_id = $(this).attr("data-product_id");
var seff = $(this);
seff.append('');
$.ajax({
type : "post",
url : ajax_process.ajaxurl,
crossDomain: true,
data: {
action: "add_to_cart",
product_id: product_id
},
success: function(data){
seff.find('.fa-spinner').remove();
var cart_content = data.fragments['div.widget_shopping_cart_content'];
// console.log(data.fragments['div.widget_shopping_cart_content']);
$('.mini-cart-content').html(cart_content);
var count_item = cart_content.split("',
prevText:''
});
/*!
* Variations Plugin
*/
!function(a,b,c,d){a.fn.wc_variation_form=function(){var c=this,f=c.closest(".product"),g=parseInt(c.data("product_id"),10),h=c.data("product_variations"),i=h===!1,j=!1,k=c.find(".reset_variations");return c.unbind("check_variations update_variation_values found_variation"),c.find(".reset_variations").unbind("click"),c.find(".variations select").unbind("change focusin"),c.on("click",".reset_variations",function(){return c.find(".variations select").val("").change(),c.trigger("reset_data"),!1}).on("reload_product_variations",function(){h=c.data("product_variations"),i=h===!1}).on("reset_data",function(){var b={".sku":"o_sku",".product_weight":"o_weight",".product_dimensions":"o_dimensions"};a.each(b,function(a,b){var c=f.find(a);c.attr("data-"+b)&&c.text(c.attr("data-"+b))}),c.wc_variations_description_update(""),c.trigger("reset_image"),c.find(".single_variation_wrap").slideUp(200).trigger("hide_variation")}).on("reset_image",function(){var a=f.find("div.images img:eq(0)"),b=f.find("div.images a.zoom:eq(0)"),c=a.attr("data-o_src"),e=a.attr("data-o_title"),g=a.attr("data-o_title"),h=b.attr("data-o_href");c!==d&&a.attr("src",c),h!==d&&b.attr("href",h),e!==d&&(a.attr("title",e),b.attr("title",e)),g!==d&&a.attr("alt",g)}).on("change",".variations select",function(){if(c.find('input[name="variation_id"], input.variation_id').val("").change(),c.find(".wc-no-matching-variations").remove(),i){j&&j.abort();var b=!0,d=!1,e={};c.find(".variations select").each(function(){var c=a(this).data("attribute_name")||a(this).attr("name");0===a(this).val().length?b=!1:d=!0,e[c]=a(this).val()}),b?(e.product_id=g,j=a.ajax({url:wc_cart_fragments_params.wc_ajax_url.toString().replace("%%endpoint%%","get_variation"),type:"POST",data:e,success:function(a){a?(c.find('input[name="variation_id"], input.variation_id').val(a.variation_id).change(),c.trigger("found_variation",[a])):(c.trigger("reset_data"),c.find(".single_variation_wrap").after(''+wc_add_to_cart_variation_params.i18n_no_matching_variations_text+"
"),c.find(".wc-no-matching-variations").slideDown(200))}})):c.trigger("reset_data"),d?"hidden"===k.css("visibility")&&k.css("visibility","visible").hide().fadeIn():k.css("visibility","hidden")}else c.trigger("woocommerce_variation_select_change"),c.trigger("check_variations",["",!1]),a(this).blur();c.trigger("woocommerce_variation_has_changed")}).on("focusin touchstart",".variations select",function(){i||(c.trigger("woocommerce_variation_select_focusin"),c.trigger("check_variations",[a(this).data("attribute_name")||a(this).attr("name"),!0]))}).on("found_variation",function(a,b){var e=f.find("div.images img:eq(0)"),g=f.find("div.images a.zoom:eq(0)"),h=e.attr("data-o_src"),i=e.attr("data-o_title"),j=e.attr("data-o_alt"),k=g.attr("data-o_href"),l=b.image_src,m=b.image_link,n=b.image_caption,o=b.image_title;c.find(".single_variation").html(b.price_html+b.availability_html),h===d&&(h=e.attr("src")?e.attr("src"):"",e.attr("data-o_src",h)),k===d&&(k=g.attr("href")?g.attr("href"):"",g.attr("data-o_href",k)),i===d&&(i=e.attr("title")?e.attr("title"):"",e.attr("data-o_title",i)),j===d&&(j=e.attr("alt")?e.attr("alt"):"",e.attr("data-o_alt",j)),l&&l.length>1?(e.attr("src",l).attr("alt",o).attr("title",o),g.attr("href",m).attr("title",n)):(e.attr("src",h).attr("alt",j).attr("title",i),g.attr("href",k).attr("title",i));var p=c.find(".single_variation_wrap"),q=f.find(".product_meta").find(".sku"),r=f.find(".product_weight"),s=f.find(".product_dimensions");q.attr("data-o_sku")||q.attr("data-o_sku",q.text()),r.attr("data-o_weight")||r.attr("data-o_weight",r.text()),s.attr("data-o_dimensions")||s.attr("data-o_dimensions",s.text()),b.sku?q.text(b.sku):q.text(q.attr("data-o_sku")),b.weight?r.text(b.weight):r.text(r.attr("data-o_weight")),b.dimensions?s.text(b.dimensions):s.text(s.attr("data-o_dimensions"));var t=!1,u=!1;b.is_purchasable&&b.is_in_stock&&b.variation_is_visible||(u=!0),b.variation_is_visible||c.find(".single_variation").html(""+wc_add_to_cart_variation_params.i18n_unavailable_text+"
"),""!==b.min_qty?p.find(".quantity input.qty").attr("min",b.min_qty).val(b.min_qty):p.find(".quantity input.qty").removeAttr("min"),""!==b.max_qty?p.find(".quantity input.qty").attr("max",b.max_qty):p.find(".quantity input.qty").removeAttr("max"),"yes"===b.is_sold_individually&&(p.find(".quantity input.qty").val("1"),t=!0),t?p.find(".quantity").hide():u||p.find(".quantity").show(),u?p.is(":visible")?c.find(".variations_button").slideUp(200):c.find(".variations_button").hide():p.is(":visible")?c.find(".variations_button").slideDown(200):c.find(".variations_button").show(),c.wc_variations_description_update(b.variation_description),p.slideDown(200).trigger("show_variation",[b])}).on("check_variations",function(c,d,f){if(!i){var g=!0,j=!1,k={},l=a(this),m=l.find(".reset_variations");l.find(".variations select").each(function(){var b=a(this).data("attribute_name")||a(this).attr("name");0===a(this).val().length?g=!1:j=!0,d&&b===d?(g=!1,k[b]=""):k[b]=a(this).val()});var n=e.find_matching_variations(h,k);if(g){var o=n.shift();o?(l.find('input[name="variation_id"], input.variation_id').val(o.variation_id).change(),l.trigger("found_variation",[o])):(l.find(".variations select").val(""),f||l.trigger("reset_data"),b.alert(wc_add_to_cart_variation_params.i18n_no_matching_variations_text))}else l.trigger("update_variation_values",[n]),f||l.trigger("reset_data"),d||l.find(".single_variation_wrap").slideUp(200).trigger("hide_variation");j?"hidden"===m.css("visibility")&&m.css("visibility","visible").hide().fadeIn():m.css("visibility","hidden")}}).on("update_variation_values",function(b,d){i||(c.find(".variations select").each(function(b,c){var e,f=a(c);f.data("attribute_options")||f.data("attribute_options",f.find("option:gt(0)").get()),f.find("option:gt(0)").remove(),f.append(f.data("attribute_options")),f.find("option:gt(0)").removeClass("attached"),f.find("option:gt(0)").removeClass("enabled"),f.find("option:gt(0)").removeAttr("disabled"),e="undefined"!=typeof f.data("attribute_name")?f.data("attribute_name"):f.attr("name");for(var g in d)if("undefined"!=typeof d[g]){var h=d[g].attributes;for(var i in h)if(h.hasOwnProperty(i)){var j=h[i];if(i===e){var k="";d[g].variation_is_active&&(k="enabled"),j?(j=a("").html(j).text(),j=j.replace(/'/g,"\\'"),j=j.replace(/"/g,'\\"'),f.find('option[value="'+j+'"]').addClass("attached "+k)):f.find("option:gt(0)").addClass("attached "+k)}}}f.find("option:gt(0):not(.attached)").remove(),f.find("option:gt(0):not(.enabled)").attr("disabled","disabled")}),c.trigger("woocommerce_update_variation_values"))}),c.trigger("wc_variation_form"),c};var e={find_matching_variations:function(a,b){for(var c=[],d=0;d'+b+"").hide()),c.find(".woocommerce-variation-description").slideDown(200));else{var e=d.outerHeight(!0),f=0,g=!1;d.css("height",e),d.html(b),d.css("height","auto"),f=d.outerHeight(!0),Math.abs(f-e)>1&&(g=!0,d.css("height",e)),g&&d.animate({height:f},{duration:200,queue:!1,always:function(){d.css({height:"auto"})}})}},a(function(){"undefined"!=typeof wc_add_to_cart_variation_params&&a(".variations_form").each(function(){a(this).wc_variation_form().find(".variations select:eq(0)").change()})})}(jQuery,window,document);
//Select Size
$('.selected-attr-size span').text($('.select-attr-size li').first().find('a').text());
$('body').click(function(){
$('.select-attr-size').slideUp();
});
$('.selected-attr-size').click(function(event){
event.preventDefault();
event.stopPropagation();
$(this).parent().find('.select-attr-size').slideToggle();
$(this).parent().next().find('select').trigger( 'focusin' );
var content = '';
var old_content = $(this).parent().find('.select-attr-size').html();
var current_val = $(this).parent().find('.select-attr-size').find('a.selected').parent().attr('data-attribute');
$(this).parent().next().find('select').find('option').each(function(){
var val = $(this).attr('value');
var title = $(this).html();
var el_class = '';
if(current_val == val) el_class = ' class="selected" ';
content += ''+title+'';
})
if(content != old_content) $(this).parent().find('.select-attr-size').html(content);
});
$('body').on('click','.select-attr-size a',function(event){
event.preventDefault();
// console.log($(this));
$(this).parents('.select-attr-size').find('a').removeClass('selected');
$(this).addClass('selected');
$(this).parents('.attr-product').find('.selected-attr-size').find('span').text($(this).text());
});
//Select Color
$('body').on('click','.attr-color li a',function(event){
// console.log($(this));
event.preventDefault();
$('.attr-color li a').removeClass('selected');
$(this).addClass('selected');
});
$('body').on('click','.select-attr-size li',function(event){
console.log($(this));
var attribute = $(this).attr('data-attribute');
var id = $(this).parent().attr('data-attribute-id');
console.log($(this).parents('.attr-product').next().find('select').html());
$(this).parents('.attr-product').next().find('select').val(attribute);
$(this).parents('.attr-product').next().find('select').trigger( 'change' );
$(this).parents('.attr-product').next().find('select').trigger( 'focusin' );
// $('#'+id).val(attribute);
// $('#'+id).trigger( 'change' );
// $('#'+id).trigger( 'focusin' );
})
$('.attr-color').hover(function(){
var old_html = $(this).next().find('select').html();
var current_val = $(this).find('.select-attr-color').find('a.selected').parent().attr('data-attribute');
$(this).next().find('select').trigger( 'focusin' );
var content = '';
$(this).next().find('select').find('option').each(function(){
var val = $(this).attr('value');
var title = $(this).html();
var el_class = '';
if(current_val == val) el_class = ' class="selected" ';
if(val != '') content += '';
})
if(old_html != content) $(this).find('.select-attr-color').html(content);
})
$('body').on('click','.select-attr-color li',function(event){
var attribute = $(this).attr('data-attribute');
var id = $(this).parent().attr('data-attribute-id');
$(this).parents('.attr-product').next().find('select').val(attribute);
$(this).parents('.attr-product').next().find('select').trigger( 'change' );
$(this).parents('.attr-product').next().find('select').trigger( 'focusin' );
// $('#'+id).val(attribute);
// $('#'+id).trigger( 'change' );
// $('#'+id).trigger( 'focusin' );
return false;
})
// END FIX
//QUANTITY CLICK
$(".quantity").find(".qty-up").on("click",function(){
var min = $(this).prev().attr("min");
var max = $(this).prev().attr("max");
var step = $(this).prev().attr("step");
if(step === undefined) step = 1;
if(max !==undefined && Number($(this).prev().val())< Number(max) || max === undefined){
if(step!='') $(this).prev().val(Number($(this).prev().val())+Number(step));
}
return false;
})
$(".quantity").find(".qty-down").on("click",function(){
var min = $(this).next().attr("min");
var max = $(this).next().attr("max");
var step = $(this).next().attr("step");
if(step === undefined) step = 1;
if(Number($(this).next().val()) > 1){
if(min !==undefined && $(this).next().val()>min || min === undefined){
if(step!='') $(this).next().val(Number($(this).next().val())-Number(step));
}
}
return false;
})
$("input.qty-val").on("keyup change",function(){
var max = $(this).attr('max');
if( Number($(this).val()) > Number(max) ) $(this).val(max);
})
//END
},
error: function(MLHttpRequest, textStatus, errorThrown){
console.log(errorThrown);
}
});
return false;
})
});
})(jQuery);