PageSourceSearch

https://www.hogbackdistillery.com/wp-content/plugins/lottery-for-w…/assets/js/frontend/frontend.js?ver=6.6

js hogbackdistillery.com collected 2026-10-09 01:43:25 UTC 18,990 bytes, 427 lines download raw bytes

1/* global lty_frontend_params */
2
3jQuery( function( $ ) {
4	'use strict' ;
5	var ticket_numbers = [ ] ;
6	var LTY_Frontend = {
7		init : function( ) {
8			this.trigger_on_page_load( ) ;
9			// Choose the ticket tab.
10			$( document ).on( 'click' , '.lty-lottery-ticket-tab' , this.lottery_ticket_tab_selection ) ;
11			// Select the ticket.
12			$( document ).on( 'click' , '.lty-ticket' , this.lottery_ticket_selection ) ;
13			// Unselect the ticket.
14			$( document ).on( 'click' , '.lty-selected-ticket' , this.lottery_ticket_unselection ) ;
15			// Select the question answer.
16			$( document ).on( 'click' , 'ul.lty-lottery-answers li' , this.select_question_answer ) ;
17			// Select the predefined button.
18			$( document ).on( 'click' , 'ul.lty-predefined-buttons li' , this.select_predefined_button ) ;
19			// Validate the participate now button. 
20			$( document ).on( 'click' , '.lty-participate-now-button' , this.validate_participate ) ;
21			// Process the ticket lucky dip.
22			$( document ).on( 'click' , '.lty-lucky-dip-button' , this.process_lucky_dip ) ;
23			// Process the add more ticket lucky dip.
24			$( document ).on( 'click' , '.lty-add-more-lucky-tip' , this.add_more_lucky_dip ) ;
25			// Process the manual search action.
26			$( document ).on( 'click' , '.lty-manual-ticket-search-action' , this.process_manual_ticket_search_action ) ;
27			// Process the click to back action.
28			$( document ).on( 'click' , '.lty-manual-ticket-click-to-back-action' , this.process_manual_ticket_click_to_back_action ) ;
29			// Process the lottery price based on qty.
30			$( document ).on( 'change keyup' , 'form.lty-participate-now .qty' , this.process_lottery_price_based_on_qty ) ;
31                        // Pagination.
32                        $( document ).on( 'click', '.lty-pagination', this.pagination );
33		} , trigger_on_page_load : function( ) {
34			LTY_Frontend.set_price_amount( $( 'form.lty-participate-now .qty' ).val() ) ;
35						
36			if ('yes' == lty_frontend_params.disable_participate_now_button) {
37				$( '.lty_manual_add_to_cart' ).attr( 'disabled' , true ) ;
38			}
39
40			$( '.lty-manual-ticket-click-to-back-action' ).hide() ;
41						
42			LTY_Frontend.handle_add_cart_button( ) ;
43		} , select_question_answer : function( event ) {
44			event.preventDefault( ) ;
45			var $this = $( event.currentTarget ) ,
46					answers_wrapper = $( $this ).closest( '.lty-lottery-answers' ) ,
47					answer_id = $( $this ).data( 'answer-id' ) ;
48			answers_wrapper.find( 'li' ).removeClass( 'lty-selected' ) ;
49			$( $this ).addClass( 'lty-selected' ) ;
50			$( '.lty-question-answer-id' ).val( answer_id ) ;
51			LTY_Frontend.handle_add_cart_button( ) ;
52		} , select_predefined_button : function( event ) {
53			event.preventDefault( ) ;
54			var $this = $( event.currentTarget ) ,
55					predefined_button_wrapper = $( $this ).closest( '.lty-predefined-buttons' ) ,
56					predefined_button_id = $( $this ).data( 'predefined-button-id' ) ,
57					ticket_quantity = $( $this ).data( 'ticket-quantity' ) ,
58					per_ticket_amount = $( $this ).data( 'per-ticket-amount' ) ;
59
60			predefined_button_wrapper.find( 'li' ).removeClass( 'lty-selected-button' ) ;
61			$( $this ).addClass( 'lty-selected-button' ) ;
62			$( '.lty-predefined-button-id' ).val( predefined_button_id ) ;
63			$( '.lty-ticket-quantity' ).val( ticket_quantity ) ;
64			$( '.lty-per-ticket-amount' ).val( per_ticket_amount );
65			LTY_Frontend.handle_add_cart_button( ) ;
66		} , handle_add_cart_button : function( ) {
67			var show_button = true ,
68					ticket_container = $( '.lty-lottery-ticket-container' ) ,
69					question_container = $( '.lty-lottery-question-answer-container' ) ,
70					lucky_dip_container = $( '.lty-lottery-ticket-lucky-dip-container' ),
71					predefined_button_container = $( '.lty-lottery-predefined-buttons-container' ) ;
72								
73			if ( ticket_container.length && '' == ticket_container.find( '.lty-lottery-ticket-numbers' ).val( ) ) {
74				$(".lty_manual_add_to_cart").attr("title", lty_frontend_params.ticket_selection_alert_message);
75				show_button = false ;
76			}
77
78			if ( question_container.length && 'yes' == question_container.data( 'force' ) && '' == question_container.find( '.lty-question-answer-id' ).val( ) ) {
79				$(".lty_manual_add_to_cart").attr("title", lty_frontend_params.question_answer_alert_message);		
80				show_button = false ;
81			}
82						
83			if ( predefined_button_container.length && true == lty_frontend_params.is_predefined_buttons_enabled && '' == predefined_button_container.find( '.lty-predefined-button-id' ).val() ) {
84				$(".lty_manual_add_to_cart").attr("title", lty_frontend_params.predefined_buttons_alert_message);
85				show_button = false ;
86			}
87
88			// Show manual add to cart button.
89			if ( show_button ) {
90				$( '.lty_manual_add_to_cart' ).removeAttr( 'disabled' ) ;
91				$( '.lty_manual_add_to_cart' ).removeAttr( 'title' ) ;
92			}
93
94			// Show Lucky dip Button. 
95			if ( question_container.length && 'yes' == question_container.data( 'force' ) && '' != question_container.find( '.lty-question-answer-id' ).val( ) ) {
96				if ( lucky_dip_container.length ) {
97					lucky_dip_container.find( '.lty-lucky-dip-button' ).removeAttr( 'disabled' ) ;
98					lucky_dip_container.find( '.lty-lucky-dip-button' ).removeAttr( 'title' ) ;
99				}
100			}
101		} , validate_participate : function( event ) {
102			var error_message = null ;
103			if ( 'yes' == lty_frontend_params.guest_user ) {
104				error_message = lty_frontend_params.guest_error_msg ;
105			}
106
107			var ticket_container = $( '.lty-lottery-ticket-container' ) ,
108					question_container = $( '.lty-lottery-question-answer-container' ) ,
109					predefined_button_container = $( '.lty-lottery-predefined-buttons-container' ) ,
110					lucky_dip_container = $( '.lty-lottery-ticket-lucky-dip-container' ) ;
111
112			if ( !error_message && ticket_container.length && '' == ticket_container.find( '.lty-lottery-ticket-numbers' ).val( ) ) {
113				error_message = lty_frontend_params.ticket_selection_alert_message ;
114			}
115
116			if ( !error_message && question_container.length && 'yes' == question_container.data( 'force' ) && '' == question_container.find( '.lty-question-answer-id' ).val( ) ) {
117				error_message = lty_frontend_params.question_answer_alert_message ;
118			}
119
120			if ( !error_message && predefined_button_container.length && true == lty_frontend_params.is_predefined_buttons_enabled && '' == predefined_button_container.find( '.lty-predefined-button-id' ).val() ) {
121				error_message = lty_frontend_params.predefined_buttons_alert_message ;
122			}
123
124			if ( !error_message && question_container.length && 'yes' == question_container.data( 'force' ) && '' != question_container.find( '.lty-question-answer-id' ).val( ) && 'yes' != lty_frontend_params.incorrectly_selected_answer_restriction && 'yes' == lty_frontend_params.validate_correct_answer ) {
125				if ( confirm( lty_frontend_params.verify_question_answer_alert_message ) ) {
126					$( event.currentTarget ).submit() ;
127					return true ;
128				} else {
129					event.preventDefault( ) ;
130					return false ;
131				}
132			}
133
134			if ( error_message ) {
135				event.preventDefault( ) ;
136				$.alertable.alert( error_message ) ;
137				return false ;
138			}
139
140			return true ;
141		} ,
142		lottery_ticket_tab_selection : function( event ) {
143			event.preventDefault( ) ;
144			var $this = $( event.currentTarget ) ,
145					tickets_container = $( $this ).closest( '.lty-lottery-ticket-container' ) ;
146			LTY_Frontend.block( tickets_container ) ;
147			var data = ( {
148				action : 'lty_ticket_tab_selection' ,
149				product_id : tickets_container.find( '.lty-ticket-product-id' ).val( ) ,
150				tab : $this.data( 'tab' ) ? $this.data( 'tab' ) : 1  ,
151                                index:$this.data('index') ? $this.data('index'):0,
152				ticket_numbers : $( '.lty-lottery-ticket-numbers' ).val( ) ,
153				lty_security : lty_frontend_params.lottery_tickets_nonce ,
154			} ) ;
155			$.post( lty_frontend_params.ajaxurl , data , function( res ) {
156				if ( true === res.success ) {
157
158					tickets_container.find( '.lty-lottery-ticket-tab' ).removeClass( 'lty-active-tab' ) ;
159					$( $this ).addClass( 'lty-active-tab' ) ;
160					tickets_container.find( '.lty-lottery-ticket-tab-content' ).html( res.data.html ) ;
161
162					// class 'lty-selected-ticket' added when ticket tab selection is clicked. 
163					var $selected_ticket_numbers = res.data.ticket_numbers ;
164					for ( var i = 0 ; i < $selected_ticket_numbers.length ; i++ ) {
165						$( '.lty-ticket[data-ticket="' + $selected_ticket_numbers[i] + '"]' ).addClass( 'lty-selected-ticket' ) ;
166					}
167				} else {
168					$.alertable.alert( res.data.error ) ;
169				}
170
171				LTY_Frontend.unblock( tickets_container ) ;
172			}
173			) ;
174		} , lottery_ticket_selection : function( event ) {
175			event.preventDefault( ) ;
176			var $this = $( event.currentTarget ) ,
177					tickets_container = $( $this ).closest( '.lty-lottery-ticket-container' ) ,
178					selected_tickets = tickets_container.find( '.lty-lottery-ticket-numbers' ) ,
179					quantity = tickets_container.find( '.lty-lottery-ticket-quantity' ) ;
180
181			if ( $this.hasClass( "lty-booked-ticket" ) || $this.hasClass( "lty-processing-ticket" ) || $this.hasClass( "lty-selected-ticket" ) ) {
182				return ;
183			}
184						
185			$( $this ).removeClass( 'lty-unselected-ticket' ) ;
186			$( $this ).addClass( 'lty-selected-ticket' ) ;
187			// Push selected ticket numbers in array.
188			ticket_numbers.push( $( $this ).data( 'ticket' ) ) ;
189			selected_tickets.val( ticket_numbers ) ;
190			quantity.val( ticket_numbers.length ) ;
191			LTY_Frontend.set_price_amount( quantity.val() ) ;
192			LTY_Frontend.handle_add_cart_button( ) ;
193
194		} , lottery_ticket_unselection : function( event ) {
195			event.preventDefault( ) ;
196			var $this = $( event.currentTarget ) ,
197					tickets_container = $( $this ).closest( '.lty-lottery-ticket-container' ) ,
198					selected_tickets = tickets_container.find( '.lty-lottery-ticket-numbers' ) ,
199					quantity = tickets_container.find( '.lty-lottery-ticket-quantity' ) ;
200
201			var $ticket = $( $this ).data( 'ticket' ) ;
202			$( $this ).removeClass( 'lty-selected-ticket' ) ;
203			$( $this ).addClass( 'lty-unselected-ticket' ) ;
204
205			// Splice index number , delete count.
206			ticket_numbers.splice( ticket_numbers.indexOf( $ticket ) , 1 ) ;
207			selected_tickets.val( ticket_numbers ) ;
208			quantity.val( ticket_numbers.length ) ;
209			LTY_Frontend.set_price_amount( quantity.val() ) ;
210
211		} , process_lucky_dip : function( event ) {
212			event.preventDefault( ) ;
213			var $this = $( event.currentTarget ) ,
214					tickets_container = $( $this ).closest( '.lty-lottery-ticket-container' ) ;
215
216			var $validate_lucky_tip = LTY_Frontend.validate_lucky_dip( event ) ;
217			if ( !$validate_lucky_tip ) {
218				return false ;
219			}	
220						
221						LTY_Frontend.lucky_dip_action($this,tickets_container);
222		} , lucky_dip_action:function($this,tickets_container){
223					
224						LTY_Frontend.block( $this ) ;
225			var data = ( {
226				action : 'lty_process_lucky_dip' ,
227				product_id : tickets_container.find( '.lty-ticket-product-id' ).val( ) ,
228				qty : tickets_container.find( '.lty-lucky-dip-quantity,.qty' ).val( ) ,
229				answer : $( '.lty-question-answer-id' ).val( ) ,
230				lty_security : lty_frontend_params.lottery_tickets_nonce ,
231			} ) ;
232			$.post( lty_frontend_params.ajaxurl , data , function( res ) {
233				if ( true === res.success ) {
234					// Redirect to cart option.
235					if ( 'yes' == lty_frontend_params.enable_cart_redirection ) {
236						window.location = lty_frontend_params.cart_url;
237						return;
238					} else {
239											$.alertable.prompt(res.data.msg,{
240												prompt:res.data.html,
241												cancelButton:false
242											});
243					}
244				} else {
245					$.alertable.alert( res.data.error ) ;
246				}
247
248				LTY_Frontend.unblock( $this ) ;
249			} ) ;
250		},
251		validate_lucky_dip : function( $this ) {
252
253			var error_message = null ;
254			if ( 'yes' == lty_frontend_params.guest_user ) {
255				error_message = lty_frontend_params.guest_error_msg ;
256			}
257
258			var ticket_container = $( '.lty-lottery-ticket-container' ) ,
259					question_container = $( '.lty-lottery-question-answer-container' ) ,
260					lucky_dip_container = $( '.lty-lottery-ticket-lucky-dip-container' ) ;
261
262			if ( !error_message && question_container.length && 'yes' == question_container.data( 'force' ) && '' == question_container.find( '.lty-question-answer-id' ).val( ) ) {
263				if ( lucky_dip_container.length ) {
264					error_message = lty_frontend_params.question_answer_alert_message ;
265				}
266			}
267
268			if ( !error_message && question_container.length && 'yes' == question_container.data( 'force' ) && '' != question_container.find( '.lty-question-answer-id' ).val( ) && 'yes' != lty_frontend_params.incorrectly_selected_answer_restriction && 'yes' == lty_frontend_params.validate_correct_answer ) {
269				if ( !confirm( lty_frontend_params.verify_question_answer_alert_message ) ) {
270					event.preventDefault( ) ;
271					return false ;
272				}
273			}
274
275			if ( error_message ) {
276				event.preventDefault( ) ;
277				$.alertable.alert( error_message ) ;
278				return false ;
279			}
280
281			return true ;
282		} ,
283		add_more_lucky_dip:function(event){
284				event.preventDefault( ) ;
285			var $this = $( event.currentTarget ) ,
286			tickets_container = $( '.lty-lottery-ticket-container' ) ;
287
288			var $validate_lucky_tip = LTY_Frontend.validate_lucky_dip( event ) ;
289			if ( !$validate_lucky_tip ) {
290				return false ;
291			}
292
293			LTY_Frontend.lucky_dip_action($this,tickets_container);
294		},
295		process_lottery_price_based_on_qty : function( event ) {
296			event.preventDefault( ) ;
297			LTY_Frontend.set_price_amount( $( event.currentTarget ).val() ) ;
298		} ,
299		set_price_amount : function( $qty ) {
300			$qty = $qty > 1 ? $qty : 1 ;
301			var $price_element = $( 'form.lty-participate-now' ).find( '.lty-lottery-price' ) ;
302			var $price_amount = LTY_Frontend.format_number( $price_element.data( 'price-amount' ) , $qty ) ;
303			var $html = '<span class="woocommerce-Price-amount amount"><span class="woocommerce-Price-currencySymbol">' + lty_frontend_params.currency + '</span>' + $price_amount + '</span>' ;
304						
305			if ( 'right_space' == lty_frontend_params.currency_pos ) {
306				var $html = '<span class="woocommerce-Price-amount amount">' + $price_amount + '<span class="woocommerce-Price-currencySymbol"> ' + lty_frontend_params.currency + '</span></span>' ;
307			} else if ( 'right' == lty_frontend_params.currency_pos ) {
308				var $html = '<span class="woocommerce-Price-amount amount">' + $price_amount + '<span class="woocommerce-Price-currencySymbol">' + lty_frontend_params.currency + '</span></span>' ;
309			} else if ( 'left_space' == lty_frontend_params.currency_pos ) {
310				var $html = '<span class="woocommerce-Price-amount amount"><span class="woocommerce-Price-currencySymbol">' + lty_frontend_params.currency + '</span> ' + $price_amount + '</span>' ;
311			}
312						
313			$( $price_element ).html( $html ) ;
314		} ,
315		format_number : function( $price_amount , $qty ) {
316			return accounting.formatNumber( parseFloat( $price_amount ) * $qty , lty_frontend_params.decimals , lty_frontend_params.thousand_separator ,lty_frontend_params.decimal_separator ) ;
317		} ,
318		process_manual_ticket_search_action : function( event ) {
319						event.preventDefault() ;
320						var $this = $( event.currentTarget ) ,
321						tickets_container = $( $this ).closest( '.lty-lottery-ticket-container' ) ,
322						$searched_value = $( '.lty-manual-ticket-search' ).val() ;
323			if ( !$searched_value ) {
324				$.alertable.alert( lty_frontend_params.manual_ticket_search_empty_error) ;
325				return false ;
326			}
327
328						LTY_Frontend.block( tickets_container ) ;
329
330						var data = ( {
331							action : 'lty_manual_ticket_search_action' ,
332							searched_value : $searched_value ,
333							product_id : tickets_container.find( '.lty-ticket-product-id' ).val( ) ,
334							lty_security : lty_frontend_params.lottery_manual_ticket_search_action_nonce ,
335						} ) ;
336						
337						$.post( lty_frontend_params.ajaxurl , data , function( res ) {
338							if ( true === res.success ) {
339								if ( res.data.html ) {
340									tickets_container.find( '.lty-lottery-ticket-tab-wrapper' ).hide() ;
341									tickets_container.find( '.lty-ticket-number-wrapper' ).hide() ;
342									tickets_container.find( '.lty-lottery-ticket-tab-content' ).html( res.data.html ) ;
343									tickets_container.find( '.lty-manual-ticket-click-to-back-action' ).show() ;
344								} else {
345									tickets_container.find( '.lty-lottery-ticket-tab-wrapper' ).show() ;
346									tickets_container.find( '.lty-ticket-number-wrapper' ).show() ;
347								}
348
349								LTY_Frontend.unblock( tickets_container ) ;
350							} else {
351								$.alertable.alert( res.data.error ) ;
352
353								LTY_Frontend.unblock( tickets_container ) ;
354							}
355						} ) ;
356		} ,
357		process_manual_ticket_click_to_back_action : function( event ) {
358				event.preventDefault() ;
359				var $this = $( event.currentTarget ) ,
360				tickets_container = $( $this ).closest( '.lty-lottery-ticket-container' ) ;
361
362				tickets_container.find( '.lty-ticket-number-content-search' ).hide() ;
363				tickets_container.find( '.lty-lottery-ticket-tab-wrapper' ).show() ;
364				tickets_container.find( '.lty-ticket-number-wrapper' ).show() ;
365				tickets_container.find( '.lty-manual-ticket-click-to-back-action' ).hide() ;
366				tickets_container.find( '.lty-manual-ticket-search' ).val( '' ) ;
367
368			LTY_Frontend.lottery_ticket_tab_selection( event ) ;
369		} ,
370                pagination: function ( event ) {
371			event.preventDefault( );
372			var $this = $( event.currentTarget ),
373					table = $this.closest( 'table.lty-frontend-table' ),
374					table_body = table.find( 'tbody' ),
375					selected_page = $this.data( 'page' ),
376                                        table_action_name = $this.closest('td').data('action_name'),
377                                        product_id = $this.closest('td').data('product_id');
378
379			LTY_Frontend.block( table_body );
380
381			var data = ( {
382				action: 'lty_pagination_action',
383				selected_page: selected_page,
384				product_id: '' != product_id ? product_id: 0,
385                                table_action_name: table_action_name,
386				lty_security: lty_frontend_params.pagination_action_nonce
387			} );
388
389			$.post( lty_frontend_params.ajaxurl, data, function ( res ) {
390				if ( true === res.success ) {
391					table_body.html( res.data.html );
392					table.find( '.lty-pagination' ).removeClass( 'current' );
393					table.find( '.lty-pagination-' + selected_page ).addClass( 'current' );
394					var next_page = selected_page;
395					if ( selected_page > 1 ) {
396						next_page = selected_page - 1;
397					}
398
399					var last_page = table.find( '.lty-last-pagination' ).data( 'page' );
400					if ( selected_page < last_page ) {
401						last_page = selected_page + 1;
402					}
403
404					table.find( '.lty-next-pagination' ).data( 'page', last_page );
405					table.find( '.lty-prev-pagination' ).data( 'page', next_page );
406				} else {
407					alert( res.data.error );
408				}
409
410				LTY_Frontend.unblock( table_body );
411			}
412			);
413		},
414		block : function( id ) {
415			$( id ).block( {
416				message : null ,
417				overlayCSS : {
418					background : '#fff' ,
419					opacity : 0.7
420				}
421			} ) ;
422		} , unblock : function( id ) {
423			$( id ).unblock( ) ;
424		} ,
425	} ;
426	LTY_Frontend.init( ) ;
427} ) ;

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.