1 2jQuery(document).ready( function($) { 3 4 $('.jigoshop_error, .jigoshop_message').css('opacity', 0); 5 setTimeout( function() { 6 $('.jigoshop_error, .jigoshop_message').animate( { opacity: 1 }, 1500 ); 7 }, 100 ); 8 9 // Lightbox 10 if ( jigoshop_params.load_fancybox ) { 11 $('a.zoom').prettyPhoto( 12 { 13 animation_speed: 'normal', /* fast/slow/normal */ 14 slideshow: 5000, /* false OR interval time in ms */ 15 autoplay_slideshow: false, /* true/false */ 16 show_title: false, 17 theme: 'pp_default', /* pp_default / light_rounded / dark_rounded / light_square / dark_square / facebook */ 18 horizontal_padding: 50, 19 opacity: 0.7, 20 overlay_gallery: false, 21 deeplinking: false, 22 social_tools: false 23 }); 24 } 25 26 // Quantity buttons 27 $("div.quantity, td.quantity").append('<input type="button" value="+" id="add1" class="plus" />').prepend('<input type="button" value="-" id="minus1" class="minus" />'); 28 $(".plus").click( function() 29 { 30 var currentVal = parseInt($(this).prev(".qty").val()); 31 32 if (!currentVal || currentVal=="" || currentVal == "NaN") currentVal = 0; 33 34 $(this).prev(".qty").val(currentVal + 1); 35 }); 36 37 $(".minus").click( function() 38 { 39 var currentVal = parseInt($(this).next(".qty").val()); 40 if (currentVal == "NaN") currentVal = 0; 41 if (currentVal > 0) 42 { 43 $(this).next(".qty").val(currentVal - 1); 44 } 45 }); 46 47 48 49 /*################# VARIATIONS ###################*/ 50 51 //check if two arrays of attributes match 52 function variations_match( attrs1, attrs2 ) { 53 var match = true; 54 for ( name in attrs1 ) { 55 var val1 = attrs1[name].toLowerCase(); 56 if ( typeof( attrs2[name] ) == 'undefined' ) { 57 var val2 = 'undefined'; 58 } else { 59 var val2 = attrs2[name].toLowerCase(); 60 } 61 62 if ( val1.length != 0 && val2.length != 0 && val1 != val2 ) { 63 match = false; 64 } 65 } 66 67 return match; 68 } 69 70 //search for matching variations for given set of attributes 71 function find_matching_variations( attributes ) { 72 var matching = []; 73 74 for ( i = 0; i < product_variations.length; i++ ) { 75 var variation = product_variations[i]; 76 if ( variations_match( variation.attributes, attributes ) ) { 77 matching.push(variation); 78 } 79 } 80 81 return matching; 82 } 83 84 //disable option fields that are unavaiable for current set of attributes 85 function update_variation_values( variations ) { 86 87 // Loop through selects and disable/enable options based on selections 88 $('.variations select').each(function( index, el ) { 89 90 current_attr_select = $(el); 91 92 // Disable all 93 current_attr_select.find('option:gt(0)').attr('disabled', 'disabled'); 94 95 // Get name 96 var current_attr_name = current_attr_select.attr('name'); 97 98 // Loop through variations 99 for ( num in variations ) { 100 var attributes = variations[num].attributes; 101 102 for ( attr_name in attributes ) { 103 var attr_val = attributes[attr_name]; 104 105 if ( attr_name == current_attr_name ) { 106 if ( attr_val ) { 107 current_attr_select.find('option[value="'+attr_val+'"]').removeAttr('disabled'); 108 } else { 109 current_attr_select.find('option').removeAttr('disabled'); 110 } 111 } 112 } 113 } 114 115 // completely re-enable the previous select so 'Choose an option' isn't required to change selections 116 current_attr_select.parent().prev().find('select').find('option:gt(0)').removeAttr('disabled'); 117 118 }); 119 120 } 121 122 //show single variation details (price, stock, image) 123 function show_variation( variation ) { 124 var img = $('div.images img:eq(0)'); 125 var link = $('div.images a.zoom:eq(0)'); 126 var o_src = $(img).attr('original-src'); 127 var o_link = $(link).attr('original-href'); 128 129 var variation_image = variation.image_src; 130 var variation_link = variation.image_link; 131 132 $('.single_variation').html( variation.price_html + variation.availability_html ); 133 134 if ( ! o_src ) { 135 $(img).attr('original-src', $(img).attr('src')); 136 } 137 138 if ( ! o_link ) { 139 $(link).attr('original-href', $(link).attr('href')); 140 } 141 142 if ( variation_image && variation_image.length > 1 ) { 143 $(img).attr('src', variation_image); 144 $(link).attr('href', variation_link); 145 } else { 146 $(img).attr('src', o_src); 147 $(link).attr('href', o_link); 148 } 149 150 $('.product_meta .sku').remove(); 151 $('.product_meta').append(variation.sku); 152 153 $('.shop_attributes').find('.weight').remove(); 154 if ( variation.a_weight ) { 155 $('.shop_attributes').append(variation.a_weight); 156 } 157 158 $('.shop_attributes').find('.length').remove(); 159 if ( variation.a_length ) { 160 $('.shop_attributes').append(variation.a_length); 161 } 162 163 $('.shop_attributes').find('.width').remove(); 164 if ( variation.a_width ) { 165 $('.shop_attributes').append(variation.a_width); 166 } 167 168 $('.shop_attributes').find('.height').remove(); 169 if ( variation.a_height ) { 170 $('.shop_attributes').append(variation.a_height); 171 } 172 173 if ( ! variation.in_stock ) { 174 $('.single_variation').slideDown(); 175 } else { 176 $('.variations_button, .single_variation').slideDown(); 177 } 178 } 179 180 //when one of attributes is changed - check everything to show only valid options 181 function check_variations() { 182 $('form input[name=variation_id]').val(''); 183 $('.single_variation').text('');
184 $('.variations_button, .single_variation').slideUp(); 185 186 $('.product_meta .sku').remove(); 187 $('.shop_attributes').find('.weight').remove(); 188 $('.shop_attributes').find('.length').remove(); 189 $('.shop_attributes').find('.width').remove(); 190 $('.shop_attributes').find('.height').remove(); 191 192 var all_set = true; 193 var current_attributes = {}; 194 195 $('.variations select').each( function() { 196 if ( $(this).val().length == 0 ) { 197 all_set = false; 198 } 199 200 current_attributes[$(this).attr('name')] = $(this).val(); 201 }); 202 var matching_variations = find_matching_variations(current_attributes); 203 204 if ( all_set ) { 205 var variation = matching_variations.pop(); 206 207 $('form input[name=variation_id]').val(variation.variation_id); 208 show_variation(variation); 209 } else { 210 update_variation_values(matching_variations); 211 } 212 } 213 214 $('.variations select').change( function() { 215 //make sure that only selects before this one, and one after this are enabled 216 var num = $(this).data('num'); 217 218 if ( $(this).val().length > 0 ) { 219 num += 1; 220 } 221 222 var selects = $('.variations select'); 223 selects.filter(':lt('+num+')').removeAttr('disabled'); 224 selects.filter(':eq('+num+')').removeAttr('disabled').val(''); 225 selects.filter(':gt('+num+')').attr('disabled', 'disabled').val(''); 226 227 check_variations( $(this) ); 228 }); 229 230 //disable all but first select field 231 $('.variations select:gt(0)').attr('disabled', 'disabled'); 232 233 //numerate all selects 234 $.each( $('.variations select'), function(i, item) { 235 $(item).data('num', i); 236 }); 237 238 //default attributes 239 var initial_change = null; //which default attributes element trigger 240 var current_attributes = {}; 241 var number_of_variations = $('form.variations_form .variations select').length; 242 $('form.variations_form .variations select').each( function(i) { 243 current_attributes[$(this).attr('name')] = $(this).val(); 244 245 if ( $(this).val() != '' ) { 246 //if default attribute is set remember it 247 if ( i == number_of_variations - 1 && find_matching_variations(current_attributes).length == 0 ) { 248 //if all default attributes are set, checks if any variation matches. 249 // If not, break the loop and trigger one before last 250 return false; 251 } 252 initial_change = $(this); 253 } 254 else { 255 //break loop if any of default attributes is not set 256 return false; 257 } 258 }); 259 if ( initial_change ) { 260 initial_change.change(); 261 } 262 263});
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.