nap.js 4.13 KB
Newer Older
1 2 3 4 5 6 7 8
jQuery(document).ready(function() {

    jQuery(document).on('click', ".download_file", function() {
        var id;
        var download_link = jQuery('.download_file_link').attr('href');
        var current_var = jQuery('.download_file_link').attr('id');
        var variation_id = jQuery('input[name="variation_id"]').val();
        if (variation_id == 0)
Nahla Shiri's avatar
Nahla Shiri committed
9 10 11
            id = current_var;
        else
            id = variation_id;
12 13
        var link = download_link + 'variation_id=' + id;
        window.open(link, '_blank');
imac's avatar
imac committed
14

15
        return false;
imac's avatar
imac committed
16 17

    });
18 19 20



Nahla Shiri's avatar
Nahla Shiri committed
21
    jQuery('li.format-list:first-child input').attr('checked', true);
22 23 24 25 26 27 28 29 30 31 32 33
    jQuery(document).on('change', '.color-list input,.format-list input ', function() {

        var varID = jQuery('input[name="variation_id"]').val();
        if (varID != 0) {
            var price = jQuery('.woocommerce-variation-price .woocommerce-Price-amount').text();
            var pq = jQuery('.woocommerce-variation-description').text();
            jQuery('.price .crete').text(price);
            jQuery('.pq').text(pq);
        }

        var name = jQuery(this).attr('name');
        if (jQuery(this).is(':checked') && name == 'attribute_pa_couleur') {
Nahla Shiri's avatar
Nahla Shiri committed
34
            jQuery('li.format-list:first-child input').attr('checked', true);
35 36 37 38
            jQuery('.info-color').text(jQuery(this).attr('value'));
        }

        if (jQuery(this).is(':checked') && name == 'attribute_pa_format') {
Nahla Shiri's avatar
Nahla Shiri committed
39 40 41
            var format = jQuery('.format-list.selected .format-desc').text();
            jQuery('.info-format').text(format);
            jQuery('.info-format-txt').text(format);
42 43 44 45 46 47
        }
    });

    jQuery("#search-btn").on('click', function() {
        jQuery('article').show();
        jQuery('.list-animation section').show();
Nahla Shiri's avatar
Nahla Shiri committed
48 49
        jQuery('article').removeClass('selected');
        jQuery('article').removeClass('hidden');
50 51 52


        //filtre couleur
Nahla Shiri's avatar
Nahla Shiri committed
53
       var tabcolor = [];
54
        i = 0;
Nahla Shiri's avatar
Nahla Shiri committed
55
        jQuery("#pa_couleur .selected").each(function() {
56 57
            tabcolor[i++] = jQuery(this).attr('data-color');
        });
Nahla Shiri's avatar
Nahla Shiri committed
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
        
        var tabformat = [];
        i = 0;
        jQuery("#pa_format .selected").each(function() {
            tabformat[i++] = jQuery(this).text();
        });
        
        var tabmatiere = [];
        i = 0;
        jQuery("#pa_matiere .selected").each(function() {
            tabmatiere[i++] = jQuery(this).text();
        });
        var selected_colors = tabcolor.join(',');
        var selected_formats = tabformat.join(',');
        var selected_matiere = tabmatiere.join(',');
        var params = { pa_couleur:selected_colors, pa_format:selected_formats, pa_matiere: selected_matiere};
        window.location.href = "?" +jQuery.param(params);
         
        /*history.pushState({}, null, "?" + jQuery.param(params));
        jQuery.ajax({
            
        type: 'GET',
        url: '', 
        data: {"pa_couleur": selected_colors,"pa_format":selected_formats},
        success: function(data) {
           
        },
        error: function() {
            
        }
    });
89 90
        jQuery(".product-list article li").each(function() {
            var product_color = jQuery(this).attr('data-color');
Nahla Shiri's avatar
Nahla Shiri committed
91 92
            var product_format = jQuery(this).attr('data-format');
            if (jQuery.inArray(product_color, tabcolor) >= 0 || jQuery.inArray(product_format, tabformat) >= 0) {
93 94 95

                jQuery(this).closest('article').addClass('in_search');

Nahla Shiri's avatar
Nahla Shiri committed
96
            }
97 98 99

        });

Nahla Shiri's avatar
Nahla Shiri committed
100 101 102
*/
   
    });
103 104
    if(jQuery.urlParam('pa_format')!='' || jQuery.urlParam('pa_couleur')!='' || jQuery.urlParam('pa_matiere')!=''){
     jQuery('.list-animation section').each(function() {
Nahla Shiri's avatar
Nahla Shiri committed
105 106 107
                
            if (jQuery(this).find('article.selected').length == 0) {
              
108
                jQuery(this).hide();
Nahla Shiri's avatar
Nahla Shiri committed
109
            }
110 111 112 113 114 115 116 117 118 119 120 121
             });
         }
         
        jQuery('.filter-bloc ').each(function() {
               
            if (jQuery(this).find('.bloc-content').length == 0) {
              
                jQuery(this).hide();
            }
             });

});
Nahla Shiri's avatar
Nahla Shiri committed
122

123 124 125 126
jQuery.urlParam = function(name){
	var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href);
	return results[1] || 0;
}