PageSourceSearch

https://knigge-spirit.com/wp-content/plugins/woocommerce-pdf-vouchers/includes/js/woo-vou-public.js?ver=5.2.5

js knigge-spirit.com collected 2026-10-07 05:26:04 UTC 19,084 bytes, 515 lines download raw bytes

1"use strict";
2
3jQuery( document ).ready( function( $ ) { 
4
5	// on variation select dropdown, show woo-vou-fields wrapper
6	$( ".single_variation_wrap" ).on( "show_variation", function ( b, c ) {
7		$('.woo-loder-wrap').show();
8		jQuery(".woo-vou-fields-wrapper-variation").hide();
9		jQuery(".woo-vou-preview-pdf-wrap").hide();
10		jQuery("#woo-vou-fields-wrapper-"+c.variation_id ).show();
11		jQuery("#woo-vou-preview-pdf-wrap-"+c.variation_id ).show();
12
13		var data = {
14			'action' : 'woo_vou_variation_start_enddate',
15			'variation_id':c.variation_id
16		};
17
18		jQuery.post( WooVouPublic.ajaxurl, data, function(response) {
19		 	if( response != '' ){
20				if( response.vou_max_date != '' ){
21					$("input#recipient_giftdate-"+c.variation_id).datepicker("destroy");
22					// add datepicker to recipient giftdate
23					$("input#recipient_giftdate-"+c.variation_id).datepicker({
24						dateFormat: format,
25						minDate: response.vou_min_date,
26						maxDate: response.vou_max_date
27					});
28				} else if( response.vou_min_date != '' ) {
29					$("input#recipient_giftdate-"+c.variation_id).datepicker("destroy");
30					$("input#recipient_giftdate-"+c.variation_id).datepicker({
31						dateFormat: format,
32						minDate: response.vou_min_date
33					});
34				}
35				$('.woo-vou-recipient-fields tr').show();
36				if( typeof response.woo_vou_hidden_recipient_fields !== 'undefined' && response.woo_vou_hidden_recipient_fields.length > 0 ){
37					$.each(response.woo_vou_hidden_recipient_fields, function (index, value) {
38						$( '#'+value).parents('tr').hide();
39						$( '.'+value).hide();
40					});
41				}
42			}
43			$('.woo-loder-wrap').hide();
44		});
45	});
46	
47	// Detect WooCommerce Blocks variation selection
48	$( document ).on( 'change', '.wc-block-add-to-cart-with-options-variation-selector-attribute-options__pill-input', function() {
49	    let variationId = $(this).closest('form').find('input[name="variation_id"]').val();
50
51	    if ( variationId ) {
52	        // Manually trigger your existing logic
53	        $( ".single_variation_wrap" ).trigger( "show_variation", [{ variation_id: variationId }] );
54	    }
55	});
56
57	// on clear selection, hide woo-vou-fields wrapper
58	$( ".single_variation_wrap" ).on( "hide_variation", function ( event ) {
59		jQuery(".woo-vou-fields-wrapper-variation").hide();
60		jQuery(".woo-vou-preview-pdf-wrap").hide();
61	});
62	
63	// View template image
64	$( document ).on( 'click', '.woo-vou-view-preview-template-img', function(){
65		
66		var pswpElement = document.querySelectorAll('.pswp')[0];
67
68		var url = $(this).children('img').data('src');
69
70		// build items array
71		var items = [
72		    {
73		        src: url,
74		        w: 600,
75		        h: 400
76		    }
77		];
78
79		// define options (if needed)
80		var options = {
81		    index: $(this).data('index'),
82		    mainClass: 'woo-vou-pdf-preview-popup'
83		};
84
85		// Initializes and opens PhotoSwipe
86		var gallery = new PhotoSwipe( pswpElement, PhotoSwipeUI_Default, items, options);
87		gallery.init();
88
89	});
90	
91	// Add border and save template id in hidden
92	$( document ).on( 'click', '.woo-vou-preview-template-img', function(){
93		
94		$(this).parents('td').find('.woo-vou-preview-template-img-id').val('');
95		
96		if( !$(this).hasClass('woo-vou-preview-template-img-border') ) {
97			$(this).parents('td').find('*').removeClass('woo-vou-preview-template-img-border');
98			$(this).addClass('woo-vou-preview-template-img-border');
99			$(this).parents('td').find('.woo-vou-preview-template-img-id').val( $(this).attr('data-id') );
100		} else {
101			$(this).removeClass('woo-vou-preview-template-img-border');
102		}
103	});
104	
105	// Keep saved selected template id
106	$( '.woo-vou-preview-template-img-id' ).each( function() {
107		var selected_template = $(this).val();
108		$(this).parents('td').find('img[data-id="'+selected_template+'"]').addClass('woo-vou-preview-template-img-border');
109	});
110	
111	jQuery('.woo-vou-meta-datetime').each( function() {
112
113		var jQuerythis  = jQuery(this),
114	    format = jQuerythis.attr('rel'),
115	    id = jQuerythis.attr('id');
116	      	  	
117	  	if( id == '_woo_vou_start_date' ) {
118		  	var expire_date = jQuery('#_woo_vou_exp_date');  	  	
119	  		jQuerythis.datetimepicker({
120				ampm: true,
121				dateFormat : format,
122				showTime: false,
123				timeText: WooVouPublic.time_text, hourText: WooVouPublic.hour_text, minuteText: WooVouPublic.minute_text, currentText: WooVouPublic.current_text, closeText: WooVouPublic.close_text,
124				onSelect: function (selectedDateTime){
125					expire_date.datetimepicker('option', 'minDate', jQuerythis.datetimepicker('getDate') );
126				}
127			});
128	  	} else if( id == '_woo_vou_exp_date' ) {
129  			var start_date = jQuery('#_woo_vou_start_date');
130  	  		jQuerythis.datetimepicker({
131				ampm: true,
132				dateFormat : format,
133				showTime: false,
134				timeText: WooVouPublic.time_text, hourText: WooVouPublic.hour_text, minuteText: WooVouPublic.minute_text, currentText: WooVouPublic.current_text, closeText: WooVouPublic.close_text,
135				onSelect: function (selectedDateTime){
136					start_date.datetimepicker('option', 'maxDate', jQuerythis.datetimepicker('getDate') );
137				}
138			});
139	  	} else {  	        	
140	      	jQuerythis.datetimepicker({ampm: true,dateFormat : format, timeText: WooVouPublic.time_text, hourText: WooVouPublic.hour_text, minuteText: WooVouPublic.minute_text, currentText: WooVouPublic.current_text, closeText: WooVouPublic.close_text });//,timeFormat:'hh:mm:ss',showSecond:true
141  	  	}
142	});
143	if( $('.woo_vou_multi_select').length ) {
144    	
145    	// apply select2 on simple select dropdown
146    	$('.woo_vou_multi_select').select2();	
147    }
148    
149    // Code for toggling column of Used Codes list table on click of button having toggle-row class
150    $( document ).on( "click", ".toggle-row", function() {
151		
152    	// Find closest tr and check is-expanded class
153		if( jQuery( this ).closest( 'tr' ).hasClass( 'is-expanded' ) ) { // If th has class is-expanded
154			
155			jQuery( this ).closest( 'tr' ).removeClass( 'is-expanded' ); // If it has then remove class
156			jQuery( this ).closest( 'tr' ).find('td').each( function() { // Find td in that tr
157				if( ! jQuery( this ).hasClass( 'column-primary' ) ) { // For td not having column-primary class, hide them else show
158					jQuery( this ).hide();	
159				}
160			});
161		} else { // If tr doesn't have class is-expanded
162			
163			jQuery( this ).closest( 'tr' ).addClass( 'is-expanded' ); // Add is-expanded class to tr
164			jQuery( this ).closest( 'tr' ).find('td').each( function() { // Show all td in that tr
165				jQuery( this ).show();	
166			});
167		}				
168	});
169
170   if( $("input[name^='_woo_vou_recipient_giftdate']").length ) {
171		
172		var format = jQuery("input[name^='_woo_vou_recipient_giftdate']").attr('rel');
173		var max_date = '';
174
175		if( WooVouPublic.vou_max_date != '' ){
176			
177			// add datepicker to recipient giftdate
178			$("input[name^='_woo_vou_recipient_giftdate']").datepicker({
179				dateFormat: format,
180				minDate: WooVouPublic.vou_min_date,
181				maxDate: WooVouPublic.vou_max_date
182			});
183		} else {
184
185			$("input[name^='_woo_vou_recipient_giftdate']").datepicker({
186				dateFormat: format,
187				minDate: WooVouPublic.vou_min_date
188			});
189		}	
190	}
191
192	// On click of recipient delivery method
193	woo_vou_toggle_recipient_delivery_method();
194	$(document).on('click', '.woo-vou-delivery-method', function(){
195		woo_vou_toggle_recipient_delivery_method();
196	});
197
198	$(".woo_vou_cust_date_field").each(function(){
199
200		format = jQuery(this).attr('rel');
201		$(this).datepicker({
202			dateFormat: format,
203		});
204	});
205
206	var preview_file = '';
207	if(!$('ul.woocommerce-error').length){
208		$('.single-product div.type-product').before('<ul class="woocommerce-error" role="alert"></ul>');
209		$('ul.woocommerce-error').hide();
210	}
211
212	$(document).on('click', '.woo_vou_preview_pdf',function(e){
213
214		var clicked_el = $(this);
215		e.preventDefault();
216		$('ul.woocommerce-error').html('');
217		$('div.woocommerce-message').hide();
218		
219		if( WooVouPublic.is_preview_pdf_options != 'newtab' ) { // if preview in new tab
220			$('img.woo-vou-preview-loader').show();
221			$('.woo-vou-preview-pdf-overlay').show();
222		}
223
224		var error = false;
225        var vou_template_id = '';
226
227        $(document).find('.woo-vou-preview-template-img-id').each(function(){
228	        if( $(this).prev().is(':visible') && $('.woo-vou-preview-template-img-id').length ) {
229		        vou_template_id = $(this).val();	        
230	
231		        if(!$.trim(vou_template_id)){
232		        	$('ul.woocommerce-error').html( $('ul.woocommerce-error').html() + WooVouPublic.vou_template_err );
233		        	error = true;
234		        }
235		    }
236	    });
237
238	    $(document).find('input[class^="woo-vou-recipient-"], textarea[class^="woo-vou-recipient-"]').each(function(){
239	    	if($(this).is(':visible') && !$(this).attr('disabled') && $(this).data('required') && !$.trim($(this).val())){
240
241	    		const raw_recipient_key = $(this).attr('name');
242	    		const recipient_key = raw_recipient_key.substring(raw_recipient_key.lastIndexOf("_woo_vou_")+9, raw_recipient_key.lastIndexOf("[")) + "_err";
243	    		$('ul.woocommerce-error').html( $('ul.woocommerce-error').html() + WooVouPublic[recipient_key] );
244	        	error = true;
245	    	}
246	    });
247
248	    if( $( '#vou_set_pay_your_price' ).val() == '' ){
249			$('ul.woocommerce-error').html( $('ul.woocommerce-error').html() + WooVouPublic.pay_your_price_err );
250	        error = true;
251		}
252
253	    if(error){
254
255	    	$('img.woo-vou-preview-loader').hide();
256			$('.woo-vou-preview-pdf-overlay').hide();
257	    	$('ul.woocommerce-error').show();
258
259	    	if( $("ul.woocommerce-error").length > 0){
260	    		$('html, body').animate({ scrollTop: ($("ul.woocommerce-error").offset().top - $("ul.woocommerce-error").height()) }, 800);	
261	    	}
262	    	
263
264	    } else {
265
266	    	$('.woocommerce-error').hide();
267	    	var data = {
268	    		'action': 'woo_vou_add_to_cart_validation',
269	    		'woo_vou_is_ajax': true
270	    	};
271
272	    	if(WooVouPublic.is_variable) {
273
274	    		data['product_id'] = clicked_el.parent().find('input[name="woo_vou_product_id"]').val();
275	    		data['variation_id'] = clicked_el.parent().find('input[name="woo_vou_variation_id"]').val();
276	    	} else {
277
278	    		data['product_id'] = clicked_el.parent().find('input[name="woo_vou_product_id"]').val();
279	    	}
280
281	    	$(document).find('input[name^="_woo_vou_"], textarea[name^="_woo_vou_"]').each(function(){
282
283	    		if($(this).is(':visible') && !$(this).attr('disabled')){
284	    			var woo_vou_field_name = $(this).attr('name');
285	    			if(woo_vou_field_name.indexOf("_woo_vou_delivery_method") >= 0) {
286
287	    				data[$(this).attr('name')] = $('input[name="'+woo_vou_field_name+'"]:checked').val(); 
288	    			} else {
289
290	    				data[$(this).attr('name')] = $(this).val();
291	    			}
292	    		}
293	    	});
294
295	    	$(document).find('.woo-vou-preview-template-img-wrap').each(function(){
296	    		if($(this).is(':visible')){
297
298	    			var input = $(this).next();
299	    			data[input.attr('name')] = input.val();
300	    		}
301	    	});
302
303	    	/* Compatibility of WooCommerce Name Your Price & WooCommerce Pay Your Price */
304	    	if( WooVouPublic.payyourprice && $('input[name="'+WooVouPublic.payyourprice+'"]').length ){
305
306    			data['payyourprice'] = $('input[name="'+WooVouPublic.payyourprice+'"]').val();
307	    	}
308
309	    	if( WooVouPublic.is_preview_pdf_options == 'newtab' ) { // if preview in new tab
310
311		    	var custom_preview_form = '<form method="post" action="" target="_blank" id="woo-you-preview-form">';
312		    	$.each( data, function( key, value){
313		    		if( key != 'action' && key != 'woo_vou_is_ajax' ) {
314		    			custom_preview_form = custom_preview_form + '<input type="hidden" name="'+key+'" value="'+value+'">';
315		    		}
316		    		custom_preview_form = custom_preview_form + '<input type="hidden" name="is_preview" value="true">';
317		    		custom_preview_form = custom_preview_form + '<input type="hidden" name="quantity" value="'+$
317(document).find('div.quantity input[id^="quantity_"]').val()+'">';
318					custom_preview_form = custom_preview_form + '<input type="hidden" name="pay_your_price" value="'+$('input[id="vou_set_pay_your_price"]').val()+'">';
319		    	});
320		    	
321		    	$('body').find('#woo-you-preview-form').remove();
322		    	$('body').append(custom_preview_form);
323		    	$('#woo-you-preview-form').submit();
324		    	return true;
325		    } 
326		    else { // if preview in popup
327
328				jQuery.post( WooVouPublic.ajaxurl, data, function(response) {
329					var response_data = jQuery.parseJSON(response);
330
331					if(response_data.valid) {
332
333						data.action 	= 'woo_vou_generate_preview_pdf';
334						data.is_preview = 'true';
335						data.pay_your_price = $('#vou_set_pay_your_price').val();
336						data.quantity	= $(document).find('div.quantity input[id^="quantity_"]').val();
337				
338						jQuery.post( WooVouPublic.ajaxurl, data, function(response) {
339				
340							var response_data = jQuery.parseJSON(response);
341							$('img.woo-vou-preview-loader').hide();
342							if(response_data.pdf_name){
343								preview_file = response_data.pdf_name;
344								$('div.woo-vou-preview-pdf-content div.woo-vou-popup').html( response_data.pdf_preview );
345								$('div.woo-vou-preview-pdf-content, .woo-vou-preview-pdf-overlay').show();
346							} else {
347
348								$('div.woo-vou-preview-pdf-content div.woo-vou-popup').html('Some issue occured.');
349							}
350						});
351					} else {
352
353						$('img.woo-vou-preview-loader').hide();
354						$('.woo-vou-preview-pdf-overlay').hide();
355						$('ul.woocommerce-error').html( response_data.html );
356						$('ul.woocommerce-error').show();
357						$('html, body').animate({ scrollTop: ($("div.woocommerce").offset().top - $("div.woocommerce").height()) }, 800);
358					}
359			    });
360			}
361		}
362	});
363
364	$(document).on('click', '.woo-vou-close-button, .woo-vou-preview-pdf-overlay', function(e){
365		e.preventDefault();
366		var data = {
367			action				: 'woo_vou_unlink_preview_pdf',
368			preview_file_name	: preview_file,
369			security            : WooVouPublic.security,
370		};
371
372		jQuery.post( WooVouPublic.ajaxurl, data, function(response) {
373			$('div.woo-vou-popup-content, div.woo-vou-popup-overlay').hide();
374		});
375    });
376
377	$( document ).on( 'blur change', '#vou_set_pay_your_price', function(e){
378		var vou_set_pay_your_price = jQuery(this).val().replace(/[^\d.]/g, '');
379		jQuery(this).val(vou_set_pay_your_price);
380	});
381
382	$( document ).on( 'click', '.vou_pay_your_amount_button', function(e){		
383		$('#vou_set_pay_your_price').val( $(this).data('vou_pay_your_amount') );
384	});
385});
386
387// Function to toggle recipient delivery method
388function woo_vou_toggle_recipient_delivery_method(){
389
390	jQuery('table.woo-vou-recipient-delivery-method tr.woo-vou-delivery-method-wrapper input.woo-vou-delivery-method').each(function(){
391		if(jQuery(this).is(':checked')){ 
392			jQuery(this).closest('tr.woo-vou-delivery-method-wrapper').nextAll().each(function(){
393				jQuery(this).show();
394				jQuery(this).find('td.value input, td.value textarea').removeAttr('disabled');
395			});
396		} else {
397			jQuery(this).closest('tr.woo-vou-delivery-method-wrapper').nextAll().each(function(){
398				jQuery(this).hide();
399				jQuery(this).find('td.value input, td.value textarea').attr('disabled', 'disabled');
400			});
401		}
402	});
403}
404
405//function for follow post ajax pagination
406function woo_vou_used_codes_ajax_pagination( pid ) {
407	
408	var woo_vou_start_date = jQuery('#woo_vou_hid_start_date').val();
409	var woo_vou_end_date = jQuery('#woo_vou_hid_end_date').val();
410	var woo_vou_post_id = jQuery('#woo_vou_product_filter').val();
411	var woo_vou_partial_used_voucode = jQuery('input[name="woo_vou_partial_used_voucode"]:checked').length;
412	
413	var data = {
414					action				: 'woo_vou_used_codes_next_page',					
415					paging				: pid,
416					woo_vou_start_date	: woo_vou_start_date,
417					woo_vou_end_date	: woo_vou_end_date,
418					woo_vou_post_id		: woo_vou_post_id,
419					current_page_url	: window.location.href,
420					woo_vou_partial_used_voucode: woo_vou_partial_used_voucode
421				};
422		
423	jQuery('.woo-vou-usedcodes-loader').show();
424	jQuery('.woo-vou-used-codes-paging').hide();
425	
426	jQuery.post( WooVouPublic.ajaxurl, data, function(response) {
427		var newresponse = jQuery(response).filter('.woo-vou-used-codes-html').html();
428		jQuery('.woo-vou-usedcodes-loader').hide();
429		jQuery('.woo-vou-used-codes-html').html(newresponse);
430	});	
431	return false;
432}
433
434//function for follow post ajax pagination for purchased voucher codes
435function woo_vou_purchased_codes_ajax_pagination( pid ) {
436
437    // Get post id
438	var woo_vou_post_id = jQuery('#woo_vou_product_filter').val();
439	var woo_vou_start_date = jQuery('#woo_vou_hid_start_date').val();
440	var woo_vou_end_date = jQuery('#woo_vou_hid_end_date').val();
441	var woo_vou_partial_used_voucode = jQuery('input[name="woo_vou_partial_used_voucode"]:checked').length;
442
443	var data = {
444					action: 'woo_vou_purchased_codes_next_page',					
445					paging: pid,
446					woo_vou_start_date	: woo_vou_start_date,
447					woo_vou_end_date	: woo_vou_end_date,
448					woo_vou_post_id		: woo_vou_post_id,
449					current_page_url	: window.location.href,
450					woo_vou_partial_used_voucode: woo_vou_partial_used_voucode
451				};
452		
453	jQuery('.woo-vou-purchasedcodes-loader').show();
454	jQuery('.woo-vou-purchased-codes-paging').hide();
455	
456	jQuery.post( WooVouPublic.ajaxurl, data, function(response) {
457		var newresponse = jQuery(response).filter('.woo-vou-purchased-codes-html').html();
458		jQuery('.woo-vou-purchased-codes-loader').hide();
459		jQuery('.woo-vou-purchased-codes-html').html(newresponse);
460	});	
461	return false;
462}
463
464//function for follow post ajax pagination
465function woo_vou_unused_codes_ajax_pagination( pid ) {
466
467	var woo_vou_post_id = jQuery('#woo_vou_product_filter').val();
468	var woo_vou_partial_used_voucode = jQuery('input[name="woo_vou_partial_used_voucode"]:checked').length;
469	
470	var data = {
471					action			: 'woo_vou_unused_codes_next_page',					
472					paging			: pid,
473					woo_vou_post_id	: woo_vou_post_id,
474					current_page_url: window.location.href,
475					woo_vou_partial_used_voucode: woo_vou_partial_used_voucode
476				};
477		
478	jQuery('.woo-vou-unusedcodes-loader').show();
479	jQuery('.woo-vou-unused-codes-paging').hide();
480	
481	jQuery.post( WooVouPublic.ajaxurl, data, function(response) {
482
483		var newresponse = jQuery(response).filter('.woo-vou-unused-codes-html').html();
484		jQuery('.woo-vou-unusedcodes-loader').hide();
485		jQuery('.woo-vou-unused-codes-html').html(newresponse);
486	});
487	return false;
488}
489
490//function for follow post ajax pagination
491function woo_vou_unlimited_codes_ajax_pagination( pid ) {
492	
493	var woo_vou_start_date = jQuery('#woo_vou_hid_start_date').val();
494	var woo_vou_end_date = jQuery('#woo_vou_hid_end_date').val();
495	var woo_vou_post_id = jQuery('#woo_vou_product_filter').val();
496	
497	var data = {
498					action				: 'woo_vou_unlimited_codes_next_page',					
499					paging				: pid,
500					woo_vou_start_date	: woo_vou_start_date,
501					woo_vou_end_date	: woo_vou_end_date,
502					woo_vou_post_id		: woo_vou_post_id,
503					current_page_url	: window.location.href,
504				};
505		
506	jQuery('.woo-vou-unlimitedcodes-loader').show();
507	jQuery('.woo-vou-unlimited-codes-paging').hide();
508	
509	jQuery.post( WooVouPublic.ajaxurl, data, function(response) {
510		var newresponse = jQuery(response).filter('.woo-vou-unlimited-codes-html').html();
511		jQuery('.woo-vou-unlimitedcodes-loader').hide();
512		jQuery('.woo-vou-unlimited-codes-html').html(newresponse);
513	});	
514	return false;
515}

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.