1'use strict'; 2 3window.machic = {}; 4 5( 6function(machic, $) { 7 machic = machic || {}; 8 9 $.extend(machic, { 10 Swatches: { 11 init: function() { 12 var $term = $('.klbtheme-term'), 13 $active_term = $('.klbtheme-term:not(.klbtheme-disabled)'); 14 15 // load default value 16 $term.each(function() { 17 var $this = $(this), 18 term = $this.attr('data-term'), 19 attr = $this.closest('.klbtheme-terms').attr('data-attribute'), 20 $select_box = $this.closest('.klbtheme-terms').parent().find('select#' + attr), 21 val = $select_box.val(); 22 23 if ( val != '' && term == val ) { 24 $(this).addClass('klbtheme-selected').find('input[type="radio"]').prop('checked', true); 25 26 27 } 28 }); 29 30 31 $active_term.unbind('click touch').on('click touch', function(e) { 32 var $this = $(this), 33 term = $this.attr('data-term'), 34 title = $this.attr('title'), 35 attr = $this.closest('.klbtheme-terms').attr('data-attribute'), 36 $select_box = $this.closest('.klbtheme-terms').parent().find('select#' + attr); 37 38 if ( $this.hasClass('klbtheme-disabled') ) { 39 return false; 40 } 41 42 if ( !$this.hasClass('klbtheme-selected') ) { 43 $select_box.val(term).trigger('change'); 44 45 $this.closest('.klbtheme-terms').find('.klbtheme-selected').removeClass('klbtheme-selected').find('input[type="radio"]').prop('checked', false); 46 47 $this.addClass('klbtheme-selected').find('input[type="radio"]').prop('checked', true); 48 49 $(document).trigger('klbtheme_selected', [attr, term, title]); 50 } 51 52 e.preventDefault(); 53 }); 54 55 $(document).on('woocommerce_update_variation_values', function(e) { 56 $(e['target']).find('select').each(function() { 57 var $this = $(this); 58 var $terms = $this.parent().parent().find('.klbtheme-terms'); 59 60 $terms.find('.klbtheme-term').removeClass('klbtheme-enabled').addClass('klbtheme-disabled'); 61 62 $this.find('option.enabled').each(function() { 63 var val = $(this).val(); 64 65 $terms.find('.klbtheme-term[data-term="' + val + '"]').removeClass('klbtheme-disabled').addClass('klbtheme-enabled'); 66 }); 67 }); 68 }); 69 70 71 $('table.variations tr').each(function() { 72 if($(this).find('.klbtheme-selected').length !== 0){ 73 $(this).find('label').append('<span class="selected-value">: '+ $(this).find('.klbtheme-selected').html() +'</span>'); 74 } 75 }); 76 77 $(document).on('klbtheme_selected', function(e) { 78 $('span.selected-value').remove(); 79 $('table.variations tr').each(function() { 80 if($(this).find('.klbtheme-selected').length !== 0){ 81 $(this).find('label').append('<span class="selected-value">: '+ $(this).find('.klbtheme-selected').html() +'</span>'); 82 } 83 }); 84 }); 85 86 87 $(document).on('reset_data', function(e) { 88 $(document).trigger('klbtheme_reset'); 89 var $this = $(e['target']); 90 91 $('span.selected-value').remove(); 92 93 $this.find('.klbtheme-selected').removeClass('klbtheme-selected').find('input[type="radio"]').prop('checked', false); 94 95 $this.find('select').each(function() { 96 var attr = $(this).attr('id'); 97 var title = $(this).find('option:selected').text(); 98 var term = $(this).val(); 99 100 if ( term != '' ) { 101 $(this).parent().parent(). 102 find('.klbtheme-term[data-term="' + term + '"]'). 103 addClass('klbtheme-selected').find('input[type="radio"]'). 104 prop('checked', true); 105 106 $(document).trigger('klbtheme_reset', [attr, term, title]); 107 } 108 }); 109 }); 110 } 111 } 112 }); 113 114}).apply(this, [window.machic, jQuery]); 115 116( 117function(machic, $) { 118 119 $(document).on('wc_variation_form', function() { 120 if ( typeof machic.Swatches !== 'undefined' ) { 121 machic.Swatches.init(); 122 } 123 }); 124 $(document.body).on('klbtheme_variations_init', function() { 125 if ( typeof machic.Swatches !== 'undefined' ) { 126 machic.Swatches.init(); 127 } 128 $('.klbtheme-products-wrapper .variations_form').each(function () { 129 $(this).wc_variation_form(); 130 }); 131 }); 132 133 $(document).on('found_variation', function(e, t) { 134 if ( $(e['target']).closest('.klbtheme-loop-swatches').length ) { 135 var $product = $(e['target']).closest('.klbtheme-product'), 136 $atc = $product.find('.add_to_cart_button'), 137 $image = $product.find('.attachment-woocommerce_thumbnail'), 138 $price = $product.find('.price'); 139 140 if ( $atc.length ) { 141 $atc.addClass('klbtheme_add_to_cart').attr('data-variation_id', t['variation_id']).attr('data-product_sku', t['sku']); 142 143 if ( !t['is_purchasable'] || !t['is_in_stock'] ) {
144 $atc.addClass('disabled wc-variation-is-unavailable'); 145 } else { 146 $atc.removeClass('disabled wc-variation-is-unavailable'); 147 } 148 149 $atc.removeClass('added error loading'); 150 } 151 152 $product.find('a.added_to_cart').remove(); 153 154 // add to cart button text 155 if ( $atc.length ) { 156 $atc.text(klbtheme_vars.strings.button.add_to_cart); 157 } 158 159 // product image 160 if ( $image.length ) { 161 162 if ( $image.attr('data-src') == undefined ) { 163 $image.attr('data-src', $image.attr('src')); 164 } 165 166 if ( $image.attr('data-srcset') == undefined ) { 167 $image.attr('data-srcset', $image.attr('srcset')); 168 } 169 170 if ( $image.attr('data-sizes') == undefined ) { 171 $image.attr('data-sizes', $image.attr('sizes')); 172 } 173 174 if ( t['image']['src'] != undefined && t['image']['src'] != '' ) { 175 $image.attr('src', t['image']['src']); 176 } 177 178 if ( t['image']['srcset'] != undefined && t['image']['srcset'] != '' ) { 179 $image.attr('srcset', t['image']['srcset']); 180 } else { 181 $image.attr('srcset', ''); 182 } 183 184 if ( t['image']['sizes'] != undefined && t['image']['sizes'] != '' ) { 185 $image.attr('sizes', t['image']['sizes']); 186 } else { 187 $image.attr('sizes', ''); 188 } 189 } 190 191 // product price 192 if ( $price.length ) { 193 if ( $price.attr('data-price') == undefined ) { 194 $price.attr('data-price', $price.html()); 195 } 196 197 if ( t['price_html'] ) { 198 $price.html( t['price_html'] ); 199 } 200 } 201 202 $(document).trigger('klbtheme_archive_found_variation', [t]); 203 } 204 }); 205 206 $(document).on('reset_data', function(e) { 207 if ( $(e['target']).closest('.klbtheme-loop-swatches').length ) { 208 var $product = $(e['target']).closest('.klbtheme-product'), 209 $atc = $product.find('.add_to_cart_button'), 210 $image = $product.find('.attachment-woocommerce_thumbnail'), 211 $price = $product.find('.price'); 212 213 if ( $atc.length ) { 214 $atc.removeClass('klbtheme_add_to_cart disabled
214wc-variation-is-unavailable').attr('data-variation_id', '0').attr('data-product_sku', ''); 215 $atc.removeClass('added error loading'); 216 } 217 218 $product.find('a.added_to_cart').remove(); 219 220 // add to cart button text 221 if ( $atc.length ) { 222 $atc.text(klbtheme_vars.strings.button.select_options); 223 } 224 225 // product image 226 if ( $image.length ) { 227 $image.attr('src', $image.attr('data-src')); 228 $image.attr('srcset', $image.attr('data-srcset')); 229 $image.attr('sizes', $image.attr('data-sizes')); 230 } 231 232 // product price 233 if ( $price.length ) { 234 $price.html($price.attr('data-price')); 235 } 236 237 $(document).trigger('klbtheme_archive_reset_data'); 238 } 239 }); 240 241 $(document).on('click touch', '.klbtheme_add_to_cart', function(e) { 242 e.preventDefault(); 243 var $this = $(this); 244 var $product = $this.closest('.klbtheme-product'); 245 var attributes = {}; 246 247 $this.removeClass('added error').addClass('loading'); 248 249 if ($product.length) { 250 $product.find('a.added_to_cart').remove(); 251 252 $product.find('[name^="attribute"]').each(function() { 253 attributes[$(this).attr('data-attribute_name')] = $(this).val(); 254 }); 255 256 var data = { 257 action : 'product_attribute_add_to_cart', 258 nonce : klbtheme_vars.security, 259 product_id : $this.attr('data-product_id'), 260 variation_id : $this.attr('data-variation_id'), 261 quantity : $this.attr('data-quantity'), 262 attributes : JSON.stringify(attributes), 263 }; 264 265 $.post(klbtheme_vars.ajax_url, data, function(response) { 266 if (response) { 267 $this.removeClass('loading').addClass('added'); 268 $(document.body).trigger('added_to_cart').trigger('wc_fragment_refresh'); 269 } else { 270 $this.removeClass('loading').addClass('error'); 271 } 272 }); 273 } 274 }); 275 276 277 278 279 } 280).apply(this, [window.machic, jQuery]);
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.