1'use strict'; 2 3(function($) { 4 $(function() { 5 woovr_init(); 6 }); 7 8 $(document).on('click touch mouseover', '.woovr-variations', function() { 9 $(this).attr('data-click', 1); 10 }); 11 12 $(document).on('click touch', '.woovr-variation-radio', function() { 13 var _this = $(this); 14 var _variations = _this.closest('.woovr-variations'); 15 var _click = parseInt(_variations.attr('data-click')); 16 var _variations_form = _this.closest('.variations_form'); 17 18 woovr_do_select(_this, _variations, _variations_form, _click); 19 20 _variations.find('.woovr-variation-radio'). 21 removeClass('woovr-variation-active'); 22 _this.addClass('woovr-variation-active'). 23 find('input[type="radio"]'). 24 prop('checked', true); 25 }); 26 27 $(document).on('change', '.woovr-variation-select', function() { 28 var _this = $(this); 29 var _variations = _this.closest('.woovr-variations'); 30 var _click = parseInt(_variations.attr('data-click')); 31 var _variations_form = _this.closest('.variations_form'); 32 var _selected = $('option:selected', this); 33 34 woovr_do_select(_selected, _variations, _variations_form, _click); 35 36 if (_selected.attr('data-imagesrc') !== '') { 37 _this.closest('.woovr-variation'). 38 find('.woovr-variation-image'). 39 html('<img src="' + _selected.attr('data-imagesrc') + '"/>'); 40 } else { 41 _this.closest('.woovr-variation'). 42 find('.woovr-variation-image'). 43 html(''); 44 } 45 46 _this.closest('.woovr-variation'). 47 find('.woovr-variation-price'). 48 html(_selected.attr('data-pricehtml')); 49 }); 50 51 $(document).on('found_variation', function(e, t) { 52 var variation_id = t['variation_id']; 53 var $variations_default = $(e['target']). 54 find('.woovr-variations-default'); 55 var $variations_select = $(e['target']). 56 find('.woovr-variations-select'); 57 var $variations_select2 = $(e['target']). 58 find('.woovr-variations-select2'); 59 var $variations_ddslick = $(e['target']). 60 find('.woovr-variations-ddslick'); 61 62 if ($variations_default.length && 63 !$variations_default.closest('.woobt-wrap').length) { 64 // radio 65 if (parseInt($variations_default.attr('data-click')) < 1) { 66 $variations_default.find( 67 '.woovr-variation-radio[data-id="' + variation_id + 68 '"] input[type="radio"]').prop('checked', true); 69 } 70 } 71 72 if ($variations_select.length && 73 !$variations_select.closest('.woobt-wrap').length) { 74 // select 75 if (parseInt($variations_select.attr('data-click')) < 1) { 76 $variations_select.find('.woovr-variation-select'). 77 val(variation_id). 78 trigger('change'); 79 } 80 } 81 82 if ($variations_select2.length && 83 !$variations_select2.closest('.woobt-wrap').length) { 84 // select2 85 if (parseInt($variations_select2.attr('data-click')) < 1) { 86 $variations_select2.find('.woovr-variation-select'). 87 val(variation_id). 88 trigger('change'); 89 } 90 } 91 92 if ($variations_ddslick.length && 93 !$variations_ddslick.closest('.woobt-wrap').length) { 94 // ddslick 95 if (parseInt($variations_ddslick.attr('data-click')) < 1) { 96 var variation_index = $variations_ddslick.find( 97 'li:has(.dd-option-value[value="' + variation_id + '"])').index(); 98 99 $variations_ddslick.find('.dd-container'). 100 ddslick('select', {index: variation_index}); 101 } 102 } 103 }); 104 105 $(document).on('woosq_loaded', function() { 106 // wpc quick view popup 107 woovr_init(); 108 }); 109})(jQuery); 110 111function woovr_init() { 112 jQuery('.woovr-variations').each(function() { 113 var _variations = jQuery(this); 114 var _variations_form = jQuery(this).closest('.variations_form'); 115 var _select = _variations.find('select'); 116 117 if (_variations.hasClass('woovr-variations-ddslick')) { 118 _select.ddslick({ 119 width: '100%', 120 onSelected: function(data) { 121 var _click = parseInt(_variations.attr('data-click')); 122 var _selected = jQuery(data.original[0].children[data.selectedIndex]); 123 124 if (data.selectedData.value == 0) { 125 if (!_variations.find('.dd-selected .dd-desc').length) { 126 _variations.find('.dd-selected'). 127 addClass('dd-option-without-desc'); 128 _variations.find('.dd-option-selected'). 129 addClass('dd-option-without-desc'); 130 } 131 } else { 132 _variations.find('.dd-selected'). 133 removeClass('dd-option-without-desc'); 134 _variations.find('.dd-option-selected'). 135 removeClass('dd-option-without-desc'); 136 } 137 138 woovr_do_select(_selected, _variations, _variations_form, _click); 139 }, 140 }); 141 } else if (_variations.hasClass('woovr-variations-select2')) { 142 _select.select2({ 143 templateResult: woovr_select2_state, 144 width: '100%', 145 containerCssClass: 'wpc-select2-container', 146 dropdownCssClass: 'wpc-select2-dropdown', 147 }); 148 } else if (_variations.hasClass('woovr-variations-default')) { 149 _variations.find('input[type="radio"]').each(function() { 150 if (jQuery(this).is(':checked')) { 151 jQuery(this).trigger('click'); 152 } 153 }); 154 } 155 }); 156} 157 158function woovr_select2_state(state) { 159 if (!state.id) { 160 return state.text; 161 } 162 163 var $state; 164 165 if (jQuery(state.element).attr('data-imagesrc') != '') { 166 $state = jQuery( 167 '<span class="image"><img src="' + 168 jQuery(state.element).attr('data-imagesrc') + 169 '"/></span><span class="info"><span>' + state.text + '</span> <span>' + 170 jQuery(state.element).attr('data-description') + '</span></span>', 171 ); 172 } else { 173 $state = jQuery( 174 '<span class="info"><span>' + state.text + '</span> <span>' + 175 jQuery(state.element).attr('data-description') + '</span></span>', 176 ); 177 } 178 179 return $state; 180} 181 182function woovr_do_select(selected, variations, variations_form, click) { 183 if (click > 0) { 184 // compatible with woobt 185 if (!variations.closest('.wpc_variations_form').length) { 186 if (selected.attr('data-attrs') !== '') { 187 var attrs = jQuery.parseJSON(selected.attr('data-attrs')); 188 189 if (attrs !== null) { 190 for (var key in attrs) { 191 var attr = key; 192 193 if (key.substr(0, 9) !== 'attribute') { 194 attr = 'attribute_' + key; 195 } 196 197 if (!variations_form.find( 198 'select[name="' + attr + '"] option[value="' + attrs[key] + 199 '"]').length) { 200 variations_form.find('select[name="' + attr + '"]'). 201 append('<option value="' + attrs[key] + '">' + attrs[key] + 202 '</option>'); 203 } 204 205 variations_form.find('select[name="' + attr + '"]').val(attrs[key]); 206 } 207 } 208 } else { 209 variations_form.find('.reset_variations').trigger('click'); 210 } 211 212 variations_form.find('select:not(.woovr-variation-select)'). 213 trigger('change'); 214 } 215 } 216 217 jQuery(document). 218 trigger('woovr_selected', [selected, variations, variations_form]); 219}
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.