PageSourceSearch

https://www.tantegroen.dk/wp-content/plugins/tg/js/product_qnt.js?ver=1.0.0

js tantegroen.dk collected 2026-09-26 17:20:04 UTC 11,309 bytes, 266 lines download raw bytes

1jQuery(function($) {
2    var $productSet = $('.product-type-composite');
3    if ($productSet.length) {		
4		//Find qnt table
5		var $qntTable = $productSet.find('.cls-product-details .cls-table-outer:last');
6		//console.log("QNT Table: " + $qntTable);
7		var $pro_sizes_list = $qntTable.find("thead th");
8		//console.log("Size List: " + $pro_sizes_list[3]);
9        //var $org_price = $productSet.find('.woocommerce-Price-amount').text();
10        var $org_price = $productSet.find('.wooco-components').attr("data-regular-price");
11		//console.log("Org5 Price: " + $org_price);
12        var $kit_price = $productSet.find('.opskrift-pris').text();
13            
14
15
16		
17		
18		
19		
20		//var flatRate = 10; // Adjust the flat rate as needed
21		
22		var select_sizes = [];
23		
24		$pro_sizes_list.each(function(index, element) {
25			//Qnt names
26			var $pro_sizes = $(element).text();
27			//console.log("Sizes: " + $pro_sizes);
28			
29			//var $pro_qnt = $(element).parent().find('td').eq($(element).index()-1).text();
30			//var $pro_qnt = $(element).parent(".cls-product-table");
31			
32			var $pro_qnt_name = $(element).closest('table').find('tbody tr').eq(0).find('td').eq(1).text();
33			var $pro_qnt = $(element).closest('table').find('tbody td').eq($(element).index()).text();
34			var $qnt = $pro_qnt || '';
35			
36			var $pro_qnt2_name = $(element).closest('table').find('tbody tr').eq(1).find('td').eq(1).text();
37			var $pro_qnt2 = $(element).closest('table').find('tbody tr').eq(1).find('td').eq($(element).index()).text();
38			var $qnt2 = $pro_qnt2 || '';
39			
40			var $pro_qnt3 = $(element).closest('table').find('tbody tr').eq(2).find('td').eq($(element).index()).text();
41			var $qnt3 = $pro_qnt3 || '';
42			
43			var $pro_qnt4 = $(element).closest('table').find('tbody tr').eq(3).find('td').eq($(element).index()).text();
44			var $qnt4 = $pro_qnt4 || '';
45			
46			var $pro_qnt5 = $(element).closest('table').find('tbody tr').eq(4).find('td').eq($(element).index()).text();
47			var $qnt5 = $pro_qnt5 || '';
48			
49			var $pro_qnt6 = $(element).closest('table').find('tbody tr').eq(5).find('td').eq($(element).index()).text();
50			var $qnt6 = $pro_qnt6 || '';
51			
52			var $pro_qnt7 = $(element).closest('table').find('tbody tr').eq(6).find('td').eq($(element).index()).text();
53			var $qnt7 = $pro_qnt7 || '';
54			
55			var $pro_qnt8 = $(element).closest('table').find('tbody tr').eq(7).find('td').eq($(element).index()).text();
56			var $qnt8 = $pro_qnt8 || '';
57			
58			var $pro_qnt9 = $(element).closest('table').find('tbody tr').eq(8).find('td').eq($(element).index()).text();
59			var $qnt9 = $pro_qnt9 || '';
60			
61			var $pro_qnt10 = $(element).closest('table').find('tbody tr').eq(9).find('td').eq($(element).index()).text();
62			var $qnt10 = $pro_qnt10 || '';
63
64			
65			
66			//console.log("Qntttt: " + $qnt2);
67			//console.log("Qnt: " + $pro_qnt2_name);
68			
69			//console.log("Størrelse: " + $pro_sizes + " Type: " + $pro_qnt_name + " Antal: " + $pro_qnt + " Type 2: " + $pro_qnt2_name + " Antal: " + $pro_qnt2);
70			//var select_sizes = [];
71			select_sizes.push({'itemType': $pro_sizes, 'itemQnt1': $qnt, 'itemQnt2': $qnt2, 'itemQnt3': $qnt3, 'itemQnt4': $qnt4, 'itemQnt5': $qnt5, 'itemQnt6': $qnt6, 'itemQnt7': $qnt7, 'itemQnt8': $qnt8, 'itemQnt9': $qnt9, 'itemQnt10': $qnt10});
72			
73		});
74		
75		var box = $('<div class="wooco_component wooco_component_0 wooco_component_type_categories wooco_component_required"><div class="wooco_component_name">Størrelse</div><div class="wooco_component_desc grett">Størrelsen tilpasser antal garnnøgler til opskriften.</div></div>');
76		box.prependTo('.wooco_components');
77			var dropdown = $('<select>', {
78				id: 'sizeselect',
79				name: 'size'
80			});
81			for (i = 0; i < select_sizes.length; i++) {
82				var option = $('<option></option>', {
83					value: i,
84					text: select_sizes[i].itemType,
85					q1: select_sizes[i].itemQnt1,
86					q2: select_sizes[i].itemQnt2,
87					q3: select_sizes[i].itemQnt3,
88					q4: select_sizes[i].itemQnt4,
89					q5: select_sizes[i].itemQnt5,
90					q6: select_sizes[i].itemQnt6,
91					q7: select_sizes[i].itemQnt7,
92					q8: select_sizes[i].itemQnt8,
93					q9: select_sizes[i].itemQnt9,
94					q10: select_sizes[i].itemQnt10
95				});
96				
97				if(i === 0) {
98					//dropdown.append("<option>-- Vælg størrelse --</option>");
99                    
100                    /* Default first option to minimum*/
101                    //dropdown.append("<option value='1' q1='"+select_sizes[1].itemQnt1+"' q2='"+select_sizes[1].itemQnt2+"' q3='"+select_sizes[1].itemQnt3+"' q4='"+select_sizes[1].itemQnt4+"' q5='"+select_sizes[1].itemQnt5+"' q6='"+select_sizes[1].itemQnt6+"' q7='"+select_sizes[1].itemQnt7+"' q8='"+select_sizes[1].itemQnt8+"' q9='"+select_sizes[1].itemQnt9+"' q10='"+select_sizes[1].itemQnt10+"' >-- Vælg størrelse --</option>");
102					dropdown.append("<option q1='"+select_sizes[1].itemQnt1+"' q2='"+select_sizes[1].itemQnt2+"' q3='"+select_sizes[1].itemQnt3+"' q4='"+select_sizes[1].itemQnt4+"' q5='"+select_sizes[1].itemQnt5+"' q6='"+select_sizes[1].itemQnt6+"' q7='"+select_sizes[1].itemQnt7+"' q8='"+select_sizes[1].itemQnt8+"' q9='"+select_sizes[1].itemQnt9+"' q10='"+select_sizes[1].itemQnt10+"' >-- Vælg størrelse --</option>");
103				//} else if(i === 1) {
104					//Tabel item is empty
105				} else {
106					dropdown.append(option);
107				}
108
109			}
110			dropdown.appendTo('.grett');
111		
112		
113		
114		
115			/* Create hidden field to send selected size on form submit */
116			var sizehidden = $('<input id="refsize" type="hidden" name="size" value="">');
117			$("form.cart").append(sizehidden);
118		
119			var idhidden = $('<input id="refid" type="hidden" name="id" value="">');
120			$("form.cart").append(idhidden);
121		
122		
123		
124			/*var link = $('<a class="wooco_component_product_link woosq-link" data-id="16300" href="https://tante-groen-dev-.barani.micusto.cloud/video-guide" target="_blank"> &nbsp; </a>');
125			link.appendTo('.grett');*/
126		
127			$('.summary .price-single').hide();
128		
129		    $('body').on('change', '#sizeselect', function () {
130				//$(this).parents('.woocommerce-category').submit();
131				
132				//$productSet.find("wooco_component_product ")
133				//var $prod_val = $qntTable.closest('table').find('tbody tr').eq(0).find('td').eq(1).text();
134				$('.summary .price-single').attr("style", "display: block !important");
135				$('.min-pris').hide();
136				
137				
138				
139				/* Get selected size */
140				var size_selected =  $(this).find("option:selected").text();
141				var pid = $('input[name=add-to-cart]').val();
142				
143				/* Set selected size to hidden input */
144				$("#refsize").val(size_selected);
145				/* Set selected size to hidden input */
146				$("#refid").val(pid);
147			
148				
149				var size_qu = [];
150					size_qu.push($(this).find("option:selected").attr('q1'));
151					size_qu.push($(this).find("option:selected").attr('q2'));
152					size_qu.push($(this).find("option:selected").attr('q3'));
153					size_qu.push($(this).find("option:selected").attr('q4'));
154					size_qu.push($(this).find("option:selected").attr('q5'));
155					size_qu.push($(this).find("option:selected").attr('q6'));
156					size_qu.push($(this).find("option:selected").attr('q7'));
157					size_qu.push($(this).find("option:selected").attr('q8'));
158					size_qu.push($(this).find("option:selected").attr('q9'));
159					size_qu.push($(this).find("option:selected").attr('q10'));
160				
161				//console.log("Selected Value: " + size_selected + " Qnt: " + JSON.stringify(size_qu));
162				//var size_qnt = [];
163				//size_qnt.push(select_sizes.find(x => x.itemType === size_selected));
164				//var size_qnt2 = select_sizes.find(x => x.itemType === size_selected).itemQnt2;
165				//console.log("Selected Value: " + size_selected + " Qnt: " + JSON.stringify(size_qnt[0]));
166				
167				//$('.wooco_component_product_qty_input').first().attr('value', size_qnt.itemQnt0);
168				
169				$('.wooco_component_product_qty_input').each(function(index, element) { 
170					//var str = 'itemQnt'+index;
171					//console.log("Set values: " +  JSON.stringify(size_qu[index]));			 									 										 
172					$(element).attr('value', size_qu[index]);
173					$(element).val(size_qu[index]);
174					$(element).trigger('change');
175					/*$(element).on('change paste keyup input', function() {
176					  //$('#' + $(this).data('id')).html(this.value);
177						$(element).val(size_qu[index]);
178					});*/
179					
180				});
181                var $currentPrice = $productSet.find('.woocommerce-Price-amount').first().text();
182			
183				
184				// Existing calculation for new price
185				var cleanedCurrentPrice = $currentPrice.replace(/[^\d.]/g, ''); // Remove everything except digits and the decimal point
186				var numericCurrentPrice = parseFloat(cleanedCurrentPrice); // Convert to a floating-point number
187				var numericKitPrice = Number($kit_price); // Ensure $kit_price is treated as a number
188
189				// Modified line: Add the flat rate to the new price calculation
190				//var $newPrice = numericKitPrice + numericCurrentPrice + flatRate; // Perform the addition with the flat rate
191				var $newPrice = numericKitPrice + numericCurrentPrice;
192				
193
194				console.log("New price: " + $newPrice);
195                
196				
197				//$productSet.find('.woocommerce-Price-amount').first().text($newPrice);
198				//.wooco_component .wooco-qty
199				//find wooco_component_product where data-component="Bundfarve" target wooco_component_product_qty_input set value
200			});
201
202		
203			//Set minimum price
204			/*setTimeout(function() { 
205				 $('#sizeselect option').eq(0).prop('selected', true).trigger('change');
206				 //$('.price-single').css('opacity') = '1';
207				 $('.price-single').css('opacity', '0.6');
208				//$('.bwp-single-product .summary .woocommerce-Price-amount').html("Fra: "+$org_price+".00 DKK");
209				//console.log("Set base price");
210			}, 80);*/
211
212    	
213
214		
215    }
216	
217	
218	
219	/*Close sidebar filter in catalog on click outside and close btn. */
220	/*
221		$(document).click(function(event) { 	
222			if($(window).width() <= 974) {
223					  var $target = $(event.target);
224						console.log("Sidebar size");
225						console.log($target);
226					  if(!$target.closest('.bwp-sidebar').length && $('.bwp-sidebar .button-filter-toggle.active')) {
227						 console.log("Not sidebar click");
228						  if($('.bwp-sidebar .button-filter-toggle.active')) {
229									console.log("Close sidebar");
230									//$('.bwp-sidebar .button-filter-toggle.active').click(); 
231						  }
232						//
233					  }
234				}		
235		});
236	*/
237	
238	/* Move product page info sections on mobile */			
239	if($(window).width() <= 974) {
240		$('.type-product .videowrapper').detach().appendTo('.type-product .bwp-single-info .summary');
241		$('.type-product #product-table-list').detach().appendTo('.type-product .bwp-single-info .summary');
242
243	}
244    
245    
246    
247    /* Insert search & logo in menu */
248    var mmenu = $('.mm-listview');
249    if(mmenu) {
250        mmenu.prepend('<li class="menu-search"><div class="search-box"><div class="search-toggle">Søg efter produkter eller mærker.<i class="wpb-icon-magnifying-glass"></i></div></div></li>');
251        mmenu.append('<div class="menu-logo"><img src="https://www.tantegroen.dk/wp-content/uploads/2021/09/TANTE-GROeN_Yarnlovesince_SORT-1-1.png" alt="Tante Grøn"></div>');
252    }
253	
254	/* Cart extend details
255	var isCheckout = $('.woocommerce-checkout');
256    if (isCheckout.length) {
257		$('#ship-to-different-address-checkbox').click();
258	}
259	*/
260	
261	var giftCardAmount = $('#ywgc-manual-amount');
262    if (giftCardAmount.length) {
263		giftCardAmount.attr('placeholder','Indtast beløb');
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.