PageSourceSearch

https://silabo.pt/wp-content/plugins/woocommerce-radio-buttons/woo…/add-to-cart-variation.min.js?ver=6.9.9

js silabo.pt collected 2026-10-01 14:34:41 UTC 12,761 bytes, 361 lines download raw bytes

1jQuery(document).ready(function($) {
2 
3    /**
4     * Variations form handling
5     */
6    $('form.variations_form')
7 
8        // On clicking the reset variation button
9        .on( 'click', '.reset_variations', function( event ) {
10 
11            //$(this).closest('form.variations_form').find('.variations input:radio').val('').change();
12            //$(this).find('.variations input:radio:checked').each( function() {
13                //$(this).checked = false;
14            //}
15            return false;
16        } )
17 
18        // Upon changing an option
19        .on( 'change', '.variations input:radio', function( event ) {
20             
21            $variation_form = $(this).closest('form.variations_form');
22            $variation_form.find('input[name=variation_id]').val('').change();
23             
24            $variation_form
25                .trigger( 'woocommerce_variation_radio_change' )
26                .trigger( 'check_variations', [ '', false ] );
27             
28            $(this).blur();
29 
30            if( $().uniform && $.isFunction( $.uniform.update ) ) {
31                $.uniform.update();
32            }
33 
34        } )
35 
36        // Upon gaining focus
37        .on( 'focusin', '.variations input:radio', function( event ) {
38 
39            $variation_form = $(this).closest('form.variations_form');
40 
41            $variation_form
42                .trigger( 'woocommerce_variation_radio_focusin' )
43                .trigger( 'check_variations', [ $(this).attr('name'), true ] );
44 
45        } )
46 
47        // Check variations
48        .on( 'check_variations', function( event, exclude, focus ) {
49            var all_set             = true;
50            var any_set             = false;
51            var showing_variation   = false;
52            var current_settings    = {};
53            var $variation_form     = $(this);
54            var $reset_variations   = $variation_form.find('.reset_variations');
55 
56            $variation_form.find('.variations input:radio:checked').each( function() {
57 
58                if ( $(this).val().length == 0 ) {
59                    all_set = false;
60                } else {
61                    any_set = true;
62                }
63 
64                if ( exclude && $(this).attr('name') == exclude ) {
65 
66                    all_set = false;
67                    current_settings[$(this).attr('name')] = '';
68 
69                } else {
70 
71                    // Encode entities
72                    value = $(this).val()
73                        .replace(/&/g, '&')
74                        .replace(/"/g, '"')
75                        .replace(/'/g, "'")
76                        .replace(/</g, '<')
77                        .replace(/>/g, '>');
78 
79                    // Add to settings array
80                    current_settings[ $(this).attr('name') ] = value;
81 
82                }
83 
84            });
85 
86            var product_id          = parseInt( $variation_form.attr( 'data-product_id' ) );
87            var all_variations      = window[ "product_variations_" + product_id ];
88             
89            // Fallback
90            if ( ! all_variations )
91                all_variations = window[ "product_variations" ];
92             
93            var matching_variations = find_matching_variations( all_variations, current_settings );
94 
95            if ( all_set ) {
96 
97                var variation = matching_variations.pop();
98 
99                if ( variation ) {
100                if ( ! exclude ) {
101                    $variation_form.find('.single_variation_wrap').slideDown('200');
102                }
103                    // Found - set ID
104                    $variation_form
105                        .find('input[name=variation_id]')
106                        .val( variation.variation_id )
107                        .change();
108                     
109                    $variation_form.trigger( 'found_variation', [ variation ] );
110 
111                } else {
112 
113                    // Nothing found - reset fields
114                    //$variation_form.find('.variations input:radio').val('');
115                    if ( ! exclude ) {
116                    $variation_form.find('.single_variation_wrap').slide
116Up('200');
117                }
118                    if ( ! focus )
119                        $variation_form.trigger( 'reset_image' );
120 
121                }
122 
123            } else {
124 
125                $variation_form.trigger( 'update_variation_values', [ matching_variations ] );
126 
127                if ( ! focus )
128                    $variation_form.trigger( 'reset_image' );
129 
130                if ( ! exclude ) {
131                    $variation_form.find('.single_variation_wrap').slideUp('200');
132                }
133 
134            }
135 
136            if ( any_set ) {
137 
138                if ( $reset_variations.css('visibility') == 'hidden' )
139                    $reset_variations.css('visibility','visible').hide().fadeIn();
140 
141            } else {
142 
143                $reset_variations.css('visibility','hidden');
144 
145            }
146 
147        } )
148 
149        // Reset product image
150        .on( 'reset_image', function( event ) {
151 
152            var $product        = $(this).closest( '.product' );
153            var $product_img    = $product.find( 'div.images img:eq(0)' );
154            var $product_link   = $product.find( 'div.images a.zoom:eq(0)' );
155            var o_src           = $product_img.attr('data-o_src');
156            var o_title         = $product_img.attr('data-o_title');
157            var o_href          = $product_link.attr('data-o_href');
158 
159            if ( o_src && o_href && o_title ) {
160                $product_img
161                    .attr( 'src', o_src )
162                    .attr( 'alt', o_title )
163                    .attr( 'title', o_title );
164                $product_link
165                    .attr( 'href', o_href );
166            }
167 
168        } )
169 
170        // Disable option fields that are unavaiable for current set of attributes
171        .on( 'update_variation_values', function( event, variations ) {
172 
173            $variation_form = $(this).closest('form.variations_form');
174 
175            // Loop through selects and disable/enable options based on selections
176            $variation_form.find('.variations input:radio').each(function( index, el ){
177 
178                current_attr_radio = $(el);
179 
180                // Disable all
181                current_attr_radio.find('option:gt(0)').attr('checked', 'checked');
182 
183                // Get name
184                var current_attr_name   = current_attr_radio.attr('name');
185 
186                // Loop through variations
187                for ( num in variations ) {
188 
189                    var attributes = variations[ num ].attributes;
190 
191                    for ( attr_name in attributes ) {
192 
193                        var attr_val = attributes[ attr_name ];
194 
195                        if ( attr_name == current_attr_name ) {
196 
197                            if ( attr_val ) {
198 
199                                // Decode entities
200                                attr_val = $("<div/>").html( attr_val ).text();
201 
202                                // Add slashes
203                                attr_val = attr_val.replace(/'/g, "\\'");
204                                attr_val = attr_val.replace(/"/g, "\\\"");
205 
206                                // Compare the meercat
207                                current_attr_radio.find('option[value="' + attr_val + '"]').removeAttr('checked');
208 
209                            } else {
210                                current_attr_radio.find('option').removeAttr('checked');
211                            }
212 
213                        }
214 
215                    }
216 
217                }
218 
219            });
220 
221            // Custom event for when variations have been updated
222            $variation_form.trigger('woocommerce_update_variation_values');
223 
224        } )
225 
226        // Show single variation details (price, stock, image)
227        .on( 'found_variation', function( event, variation ) {
228            var $variation_form = $(this);
229            
230            var $product        = $(this).closest( '.product' );
231            var $product_img    = $product.find( 'div.images img:eq(0)' );
232            var $product_link   = $product.find( 'div.images a.zoom:eq(0)' );
233             
234            var o_src           = $product_img.attr('data-o_src');
235            var o_title         = $product_img.attr('data-o_title');
236            var o_href          = $product_link.attr('data-o_href');
237 
238            var variation_image = variation.image_src;
239            var variation_link = variation.image_link;
240            var variation_title = variation.image_title;
241 
242            $variation_form.find('.variations_button').show();
243            $variation_form.find('.single_variation').html( variation.price_html + variation.availability_html );
244 
245            if ( ! o_src ) {
246                o_src = ( ! $product_img.attr('src') ) ? '' : $product_img.attr('src');
247                $product_img.attr('data-o_src', o_src );
248            }
249 
250            if ( ! o_href ) {
251                o_href = ( ! $product_link.attr('href') ) ? '' : $product_link.attr('href');
252                $product_link.attr('data-o_href', o_href );
253            }
254 
255            if ( ! o_title ) {
256                o_title = ( ! $product_img.attr('title') ) ? '' : $product_img.attr('title');
257                $product_img.attr('data-o_title', o_title );
258            }
259 
260            if ( variation_image && variation_image.length > 1 ) {
261                $product_img
262                    .attr( 'src', variation_image )
263                    .attr( 'alt', variation_title )
264                    .attr( 'title', variation_title );
265                $product_link
266                    .attr( 'href', variation_link );
267            } else {
268                $product_img
269                    .attr( 'src', o_src )
270                    .attr( 'alt', o_title )
271                    .attr( 'title', o_title );
272                $product_link
273                    .attr( 'href', o_href );
274            }
275 
276            var $single_variation_wrap = $variation_form.find('.single_variation_wrap');
277 
278            if ( variation.sku )
279                 $product.find('.product_meta').find('.sku').text( variation.sku );
280            else
281                 $product.find('.product_meta').find('.sku').text('');
282 
283            $single_variation_wrap.find('.quantity').show();
284             
285            if ( ! variation.is_in_stock && ! variation.backorders_allowed ) {
286                $variation_form.find('.variations_button').hide();
287            }
288             
289            if ( variation.min_qty )
290                $single_variation_wrap.find('input[name=quantity]').attr( 'data-min', variation.min_qty ).val( variation.min_qty );
291            else
292                $single_variation_wrap.find('input[name=quantity]').removeAttr('data-min');
293 
294            if ( variation.max_qty )
295                $single_variation_wrap.find('input[name=quantity]').attr('data-max', variation.max_qty);
296            else
297                $single_variation_wrap.find('input[name=quantity]').removeAttr('data-max');
298 
299            if ( variation.is_sold_individually == 'yes' ) {
300                $single_variation_wrap.find('input[name=quantity]').val('1');
301                $single_variation_wrap.find('.quantity').hide();
302            }
303 
304            $single_variation_wrap.slideDown('200').trigger( 'show_variation', [ variation ] );
305 
306        } );
307 
308    /**
309     * Initial states and loading
310     */
311    $('form.variations_form .variations input:radio').change();
312 
313 
314    /**
315     * Helper functions for variations
316     */
317 
318    // Search for matching variations for given set of attributes
319    function find_matching_variations( product_variations, settings ) {
320        var matching = [];
321 
322        for (var i = 0; i < product_variations.length; i++) {
323            var variation = product_variations[i];
324            var variation_id = variation.variation_id;
325             
326            if ( variations_match( variation.attributes, settings ) ) {
327                matching.push(variation);
328            }
329        }
330        return matching;
331    }
332    var count=0;
333    // Check if two arrays of attributes match
334    function variations_match( attrs1, attrs2 ) {
335        var match = true;
336        for ( attr_name in attrs1 ) {
337			var val1="";
338			 var val2="";
339            if(count>1)
340			{
341			 val1 = String(attrs1[ attr_name ]).toLowerCase();
342             val2 = String(attrs2[ attr_name ]).toLowerCase();
343			}
344			else
345			{
346			  val1 =attrs1[ attr_name ];
347             val2 = attrs2[ attr_name ];
348			 count++;
349			}
350			
351
352            if ( val1 !== undefined && val2 !== undefined && val1.length != 0 && val2.length != 0 && val1 != val2 ) {
353                match = false;
354            }
355        }
356        return match;
357    }
358 function isNumber(n) {
359  return !isNaN(parseFloat(n)) && isFinite(n);
360}
361});

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.