1;(function ( $ ) { 2 'use strict'; 3 4 /** 5 * @TODO Code a function the calculate available combination instead of use WC hooks 6 */ 7 $.fn.rexvs_variation_swatches_form = function () { 8 return this.each( function() { 9 var $form = $( this ), 10 clicked = null, 11 selected = []; 12 13 $form 14 .addClass( 'swatches-support' ) 15 .on( 'click', '.swatch', function ( e ) { 16 e.preventDefault(); 17 $('#variation_notice').hide(); 18 var $el = $( this ), 19 $select = $el.closest( '.value' ).find( 'select' ), 20 attribute_name = $select.data( 'attribute_name' ) || $select.attr( 'name' ), 21 value = $el.data( 'value' ); 22 23 24 $select.trigger( 'focusin' ); 25 26 // Check if this combination is available 27 if ( ! $select.find( 'option[value="' + value + '"]' ).length ) { 28 $el.siblings( '.swatch' ).removeClass( 'selected' ); 29 $select.val( '' ).change(); 30 $('#variation_notice').show(); 31 //$form.trigger( 'rexvs_no_matching_variations', [$el] ); 32 33 return; 34 } 35 36 clicked = attribute_name; 37 38 39 if ( selected.indexOf( attribute_name ) === -1 ) { 40 selected.push(attribute_name); 41 } 42 43 if ( $el.hasClass( 'selected' ) ) { 44 $select.val( '' ); 45 $el.removeClass( 'selected' ); 46 47 delete selected[selected.indexOf(attribute_name)]; 48 } else { 49 $el.addClass( 'selected' ).siblings( '.selected' ).removeClass( 'selected' ); 50 $select.val( value ); 51 } 52 53 $select.change(); 54 } ) 55 .on( 'click', '.reset_variations', function () { 56 $( this ).closest( '.variations_form' ).find( '.swatch.selected' ).removeClass( 'selected' ); 57 selected = []; 58 } ) 59 .on( 'rexvs_no_matching_variations', function() { 60 $('#variation_notice').show(); 61 // window.alert( wc_add_to_cart_variation_params.i18n_no_matching_variations_text ); 62 } ); 63 } ); 64 }; 65 66 $( function () { 67 $( '.variations_form' ).rexvs_variation_swatches_form(); 68 $( document.body ).trigger( 'rexvs_initialized' ); 69 } ); 70})( 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.