1function check_selection( ){ 2 var key = jQuery('select[name="mixed_tea_name"]').val(); 3 var strpos; 4 5 strpos = key.search("new"); 6 7 if ( 0 == strpos ) { 8 jQuery('input[name="mixture_name"]').attr('style', 'visibility: visible'); 9 jQuery('form.cart button[type="submit"]').text('Teemischung anlegen'); 10 } else { 11 jQuery('input[name="mixture_name"]').attr('style', 'visibility: hidden'); 12 jQuery('form.cart button[type="submit"]').text('Zur Teemischung hinzufügen'); 13 }; 14} 15 16function recalc_percent( cart_item_key , index , max_index , calc_type){ 17 18 var werte = []; // Alle Werte 19 var rest = 100; // Restprozent 20 var neuwert = 0; // Der geänderte Wert 21 var maxwert = 0; // Hilfsvariable 22 var diff = 0; // Fals ein Wert unter 10 fällt 23 var summe = 0; // Summe aller Werte 24 var set_max = []; // Indexwerte für den Max-Wert: 25 26 var shop_table = jQuery('table.shop_table'); 27 28 if ( 1 == calc_type ) { 29 // Ermitteln aller Werte der Mischung 30 for (var i = 0; i <= max_index ; i++) {
31 werte[i] = parseFloat( shop_table.find( 'input[name="prozent[' + cart_item_key + '][' + i + ']"]').val()); 32 summe = summe + werte[i]; 33 }; 34 35 neuwert = werte[index]; 36 summe = 100 - summe; 37 38 if ( 1 == max_index ) { // nur ZWEI Zutaten 39 if ( 0 == index ) { 40 werte[1] = rest - neuwert; 41 } else { 42 werte[0] = rest - neuwert; 43 }; 44 } else { // MEHR als zwei Zutaten 45 if ( index < max_index ) { 46 werte[index + 1] = werte[index + 1] + summe; 47 if ( werte[index + 1] < 10 ) { 48 werte[index + 1] = 10; 49 werte[index - 1] = werte[index - 1] + summe; 50 if ( werte[index - 1] < 10 ) { 51 werte[index - 1] = 10; 52 werte[index] = werte[index] - summe; 53 } 54 } 55 } else { 56 werte[index - 1] = werte[index - 1] + summe; 57 if ( werte[index - 1] < 10 ) { 58 werte[index - 1] = 10; 59 werte[index] = werte[index] + summe; 60 } 61 }; 62 }; 63 64 for ( i = 0 ; i <= max_index ; i++ ) { 65 set_max[i] = 100; 66 for ( j = 0 ; j <= max_index ; j++ ) { 67 maxwert = werte[j]; 68 if ( i >= j - 1 && i <= j + 1 ) { 69 maxwert = 10; 70 if ( i == j) { 71 maxwert = 0 72 } 73 } 74 set_max[i] -= maxwert; 75 } 76 } 77 78 for (i = 0; i <= max_index ; i++) { 79 var expected = 'input[name="prozent[' + cart_item_key + '][' + i + ']"]'; 80 81 if ( shop_table.find(expected).size() ) { 82 shop_table.find(expected).val(werte[i]); 83 shop_table.find(expected).attr("max" , set_max[i]); 84 } 85 }; 86 return; 87 }; 88 if ( 2 == calc_type ) { 89 // Ermitteln aller Werte der Mischung 90 for (var i = 0; i <= max_index ; i++) {
91 werte[i] = parseFloat( shop_table.find( 'input[name="prozent[' + cart_item_key + '][' + i + ']"]').val()); 92 summe = summe + werte[i]; 93 }; 94 }; 95} 96 97function add_data_to_link( product_id , my_index ) { 98 var select_val; 99 var fancy; 100 var fancy_content; 101 102 if ( my_index !== undefined ) { 103 jQuery('select[name="mixed_tea_name[' + product_id + ']"]').prop('selectedIndex', 0); 104 } 105 106 select_val = jQuery('select[name="mixed_tea_name[' + product_id + ']"]').val(); 107 if ( select_val == undefined ) { 108 return; 109 } 110 select_text = jQuery('select[name="mixed_tea_name[' + product_id + ']"]').text(); 111 my_index = jQuery('select[name="mixed_tea_name[' + product_id + ']"]').prop('selectedIndex'); 112 maxindex = jQuery('select[name="mixed_tea_name[' + product_id + ']"] > option').length; 113 114 use_fancy = false; 115 116 fancy = select_val.substr( 0 , 3 ); 117 default_name = select_val.substring( 4 ); 118 //select_text = select_text.substring( 0 , 5 ); 119 120 if ( my_index == 0 && maxindex == 1 ) { 121 use_fancy = true; 122 } 123 if ( my_index + 1 == maxindex ) { 124 use_fancy = true; 125 } 126 if ( select_text.indexOf('Neu -') > -1 ) { 127 use_fancy = false; 128 } 129 if ( maxindex == 1 ) { 130 use_fancy = false; 131 } 132 133 //if ( 'new' == fancy && use_fancy ){ 134 if ( use_fancy ) { 135 fancy_content = '<form data-product-id="' + product_id + '" id="teenmischung_name">'; 136 fancy_content += '<label for="new_mixture_name">Bitte den Namen der Teemischung eingeben!</label>'; 137 fancy_content += '<input name="new_mixture_name" id="input_name" type="text" value="' + default_name + '">'; 138 fancy_content += '<input type="submit" value="Ãbernehmen">'; 139 fancy_content += '</form>'; 140 141 142 jQuery.fancybox.open( 143 [ 144 { 145 content : fancy_content, 146 } 147 ] 148 ); 149 select_val = jQuery('select[name="mixed_tea_name[' + product_id + ']"]').val(); 150 151 jQuery( 'form#teenmischung_name' ).on( 'submit', function( event ) { 152 event.preventDefault(); 153 154 var form = jQuery(this); 155 var product_id = form.data( 'product-id' ); 156 var user_mix_text = jQuery('#input_name').val(); 157 var anzeige_text; 158 var $last_option = jQuery('select[name="mixed_tea_name[' + product_id + ']"] > option').last(); 159 var neuer_value = 'new|' + user_mix_text; 160 var post_attr = { action: 'save_name_to_session', name: user_mix_text }; 161 162 anzeige_text = 'Neu - ' + user_mix_text; 163 $last_option.text( anzeige_text ); 164 $last_option.val( neuer_value ); 165 166 jQuery('.ctr-tea-config-2').each(function() { 167 jQuery(this).find('option').last().text(anzeige_text); 168 jQuery(this).find('option').last().val(neuer_value); 169 }); 170 171 equalize_options(neuer_value); 172 173 // Eintrag in Session 174 jQuery.post( '/wp-admin/admin-ajax.php', post_attr, function( response ) { 175 jQuery.fancybox.close(); 176 }); 177 }); 178 179 } 180 equalize_options( select_val ); 181} 182 183function equalize_options( select_val ) { 184 var expected = 'a[name="add_to_cart_link"]'; 185 186 jQuery(expected).each(function() { 187 jQuery(this).data("mixed_tea_name" , select_val ); 188 }); 189 190 jQuery('.ctr-tea-config-2').each(function() { 191 jQuery(this).val(select_val); 192 }); 193} 194 195 196function add_qty_to_link( product_id ) { 197 var $input = jQuery('input[name="user_qty[' + product_id + ']"]'); 198 var select_val = $input.val(); 199 if ( 5 > select_val ) { 200 select_val = 5; 201 $input.val(select_val); 202 } 203 jQuery('a[name="add_to_cart_link"][data-product_id="' + product_id + '"]').data("user_qty", select_val); 204} 205 206 207jQuery(document).ready(function(){ 208 var product_ids = []; 209 var product_id = 0; 210 var text; 211 212 213 //var a = jQuery.cookie('teekonfigurator'); 214 var a = Cookies.get('teekonfigurator'); 215 if (a == null) { 216 var the_session = { action: 'reset_counter' }; 217 var now = new Date(); 218 now.setTime(now.getTime() + 3 * 3600 * 1000); 219 //jQuery.cookie('teekonfigurator', 'set Sessionstart' , { expires : now } ) ; 220 Cookies.set({ 221 url: 'teekonfigurator', 222 value: 'set Sessionstart' , 223 expirationDate: now 224 }); 225 } 226 227 url = window.location.href; 228 strpos = url.indexOf("/teekonfigurator"); 229 230 if ( strpos > -1 ) { 231 jQuery(document.body).on( 'added_to_cart', function() { 232 // 1. alle selectboxen durchgehen und die IDs in die post_attr packen. 233 jQuery('.ctr-tea-config-2').each(function() { 234 text = jQuery(this).attr('name'); 235 text = text.split("[").pop(); 236 text = text.substr( 0 , 5 ); 237 product_ids.push(text); 238 }); 239 240 // definiere die zu übertragenden $_POST variablen. 241 // Action muss immer definiert werden für die add_action angabe im PHP Quellcode. 242 var post_attr = { action: 'refresh_select', product_ids }; 243 244 // 2 übergeben, 245 // Führe AJAX request durch. 246 jQuery.post( '/wp-admin/admin-ajax.php', post_attr, function( response ) { 247 jQuery('.ctr-tea-config-2').each(function() { 248 jQuery(this).empty().append(response); 249 }); 250 product_id = product_ids[0];
251 add_data_to_link(product_id , 0); 252 }); 253 }); 254 if ( product_id == 0 ) { 255 jQuery('.ctr-tea-config-2').each(function() { 256 text = jQuery(this).attr('name'); 257 text = text.split("[").pop(); 258 text = text.substr( 0 , 5 ); 259 product_id = text; 260 return false; 261 }); 262 }; 263 add_data_to_link(product_id , 0); 264 } 265 266});
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.