1/* 2 * kt variations plugin 3 */ 4var bt_woo_extra_isMobile = { 5 Android: function() { 6 return navigator.userAgent.match(/Android/i); 7 }, 8 BlackBerry: function() { 9 return navigator.userAgent.match(/BlackBerry/i); 10 }, 11 iOS: function() { 12 return navigator.userAgent.match(/iPhone|iPad|iPod/i); 13 }, 14 Opera: function() { 15 return navigator.userAgent.match(/Opera Mini/i); 16 }, 17 Windows: function() { 18 return navigator.userAgent.match(/IEMobile/i); 19 }, 20 any: function() { 21 return (bt_woo_extra_isMobile.Android() || bt_woo_extra_isMobile.BlackBerry() || bt_woo_extra_isMobile.iOS() || bt_woo_extra_isMobile.Opera() || bt_woo_extra_isMobile.Windows()); 22 } 23}; 24 25jQuery(document).ready(function ($) { 26 $('.base-wp-tips-container').each(function() { 27 var $container = $( this ); 28 var item = $( this ).find( '#' + $container.attr('aria-describedby') ); 29 if ( item ) { 30 $( this ).on( 'mouseenter', function( e ) { 31 item.attr('aria-hidden', 'false'); 32 } ).on( 'mouseleave', function( e ) { 33 item.attr('aria-hidden', 'true'); 34 } ); 35 } 36 }); 37 var select2Enable = (typeof $().select2 == 'function'); 38 39 function init_swatches() { 40 $('.variations_form').each(function(){ 41 var $vform = $(this); 42 var $vform_select = $vform.find('.variations td.product_value select'); 43 var $variations = $vform.find( '.single_variation_wrap' ); 44 var $use_ajax = $vform.data( 'product_variations' ) === false; 45 var $product_variations = $vform.data( 'product_variations' ); 46 var count_variations = $vform.find('.variations td.value').length; 47 48 $vform.on( 'click', '.reset_variations', function() { 49 $vform.find('.bas_radio_variations .selectedValue').removeClass('selectedValue'); 50 $vform.find('.bas_radio_variations label' ).removeClass( 'bt_disabled '); 51 $vform.find('.bas_radio_variations input[type="radio"]:checked' ).prop('checked', false); 52 return false; 53 } ); 54 $vform.on( 'reset_data', function() { 55 $vform.find( '.single_variation_wrap_kad' ).find('.quantity').hide(); 56 $vform.find( '.single_variation .price').hide(); 57 } ); 58 $vform.on('click', '.select-option', function (e) { 59 e.preventDefault(); 60 }); 61 $vform.on('change', '.variations input[type="radio"]', function (e) { 62 var $this = $(this); 63 64 //Get the wrapper select div 65 var $option_wrapper = $this.closest('.bt-radio-variation-container'); 66 67 //Select the option. 68 var $wc_select_box = $option_wrapper.find('select').first(); 69 70 // Decode entities 71 var attr_val = $this.val(); 72 if ( attr_val.indexOf('"') !== -1 ) { 73 var current_attr_val = "value='" + attr_val + "'"; 74 } else { 75 var current_attr_val = 'value="' + attr_val + '"'; 76 } 77 //$wc_select_box.trigger('focusin').children("[value='" + attr_val + "']").prop("selected", "selected").change(); 78 $wc_select_box.trigger('focusin'); 79 if ( $wc_select_box.find( 'option[' + current_attr_val + ']' ).length ) { 80 $wc_select_box.trigger('focusin').val(attr_val).trigger('change'); 81 } else { 82 $vform.find( '.variations select' ).val( '' ).change(); 83 $vform.find('.bas_radio_variations .selectedValue').removeClass('selectedValue'); 84 $vform.find('.bas_radio_variations label' ).removeClass( 'bt_disabled '); 85 if ( select2Enable ) { 86 $('.variations .bas-select').select2({minimumResultsForSearch: -1 }); 87 } 88 $vform.find('.bas_radio_variations input[type="radio"]:checked' ).prop('checked', false); 89 $vform.trigger( 'reset_data' ); 90 // add in the selection 91 $vform.find('.bas_radio_variations input[type="radio"][' + current_attr_val + ']' ).prop('checked', true); 92 $wc_select_box.trigger('focusin').val(attr_val).trigger('change'); 93 } 94 $vform.find('.bas_radio_variations .selectedValue').removeClass('selectedValue'); 95 $vform.find('.bas_radio_variations input[type="radio"]:checked').next().addClass('selectedValue'); 96 97 }); 98 $vform.on('woocommerce_variation_has_changed', function() { 99 $('.bas-select').trigger('update'); 100 if ( $use_ajax ) { 101 if( $(window).width() > 790 && !bt_woo_extra_isMobile.any() ) { 102 if ( select2Enable ) { 103 $('.bas-select').select2({minimumResultsForSearch: -1 }); 104 } 105 } 106 } 107 } ); 108 // Disable option fields that are unavaiable for current set of attributes 109 $vform.on('woocommerce_variation_has_changed', function () { 110 if ( $use_ajax ) { 111 return; 112 } 113 var bt_current_settings = {}; 114 var variations = []; 115 $vform.find( '.variations select' ).each( function() { 116 $(this).trigger('focusin'); 117 $(this).find( 'option.enabled' ).each( function(){ 118 variations.push($( this ).val()); 119 }); 120 }); 121 $vform.find( '.variations .bas_radio_variations' ).each( function( index, el ) { 122 123 var current_attr_radio = $( el ); 124 var current_attr_name = current_attr_radio.data( 'attribute_name' ); 125 current_attr_radio.find( 'input' ).removeClass( 'attached' ); 126 current_attr_radio.find( 'input' ).removeClass( 'enabled' ); 127 current_attr_radio.find( 'label' ).removeClass( 'bt_disabled '); 128 129 // Loop through variations 130 var i; 131 for (i = 0; i < variations.length; ++i) { 132 if ( variations[i].indexOf('"') !== -1 ) { 133 current_attr_radio.find("input[value='" + variations[i] + "']").addClass( 'attached ' + 'enabled'); 134 } else { 135 current_attr_radio.find('input[value="' + variations[i] + '"]').addClass( 'attached ' + 'enabled'); 136 } 137 } 138 current_attr_radio.find( 'input:not(.attached)' ).next().addClass('bt_disabled'); 139 }); 140 } ); 141 142 143 $variations.on('hide_variation', function() { 144 $(this).css('height', 'auto'); 145 } ); 146 // Upon gaining focus 147 $vform_select.on( 'select2-opening', function() { 148 if ( ! $use_ajax ) { 149 $vform.trigger( 'woocommerce_variation_select_focusin' ); 150 $vform.trigger( 'check_variations', [ $( this ).data( 'attribute_name' ) || $( this ).attr( 'name' ), true ] ); 151 } 152 } ); 153 $(function() { 154 if ( typeof wc_add_to_cart_variation_params !== 'undefined' ) { 155 $( '.variations_form' ).each( function() { 156 $( this ).find('.variations input[type="radio"]:checked').change(); 157 }); 158 } 159 }); 160 }); 161 }
162 $(document).on( 'woosq_loaded', function() { 163 init_swatches(); 164 } ); 165 $( '.bundle_form .bundle_data' ).each( function() { 166 $( this ).on( 'woocommerce-product-bundle-initialized', function() { 167 init_swatches(); 168 } ); 169 } ); 170 init_swatches(); 171}); 172
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.