PageSourceSearch

https://thesaucepastacafe.ca/wp-content/plugins/foodpress/assets/js/foodpress_frontend.js?ver=1.5.4

js thesaucepastacafe.ca collected 2026-10-10 02:17:36 UTC 18,820 bytes, 576 lines download raw bytes

1/**
2 * FoodPress front-end javascript
3 *
4 * @version  1.3.2
5 * @author AJDE & Michael Gamble
6 */
7jQuery(document).ready(function($){
8
9	init();
10
11	// initiate everything
12	function init(){
13		alternate_categorized_menu();
14	}
15
16	
17	// scroll sections
18		$(window).scroll(function(){
19			if( $('.foodpress_scroll_section_body').length==0) return;
20			$('.foodpress_scroll_section_body').each(function(){
21				sib = $(this).siblings('.foodpress_scroll_sections');
22				topmenu = $(this).offset().top;
23				bottommenu = topmenu+ $(this).height();
24				sibheight = sib.height();
25				if($(window).scrollTop() > topmenu ) {
26					if($(window).scrollTop() > (bottommenu-sibheight) ){
27						sib.attr('class', 'foodpress_scroll_sections bottom');
28					}else{
29						sib.attr('class', 'foodpress_scroll_sections top');
30					}
31		        }else{
32		        	sib.removeClass('top');
33		        }
34			});
35		});
36		// clicking on each section on scroll menu
37			$('.foodpress_scroll_sections').on('click','h4', function(){
38				index = $(this).data('i');
39				menusection = $(this).parent().siblings('.foodpress_scroll_section_body').find('.foodpress_section_content[data-i='+index+']');
40				sectiontop = parseInt(menusection.offset().top);
41
42				$('html, body').animate({
43				    scrollTop: sectiontop-30
44				}, 2000);
45
46			});
47
48	// Tabbed menu
49		// switching tabbed menu tabs
50			$('.foodpress_tabs h4').on('click',function(){
51				// tab focus
52				$(this).parent().find('h4').removeClass('focused');
53				$(this).addClass('focused');
54
55				var index = $(this).data('i');
56				var slug = $(this).data('termslug');
57				var fp_menu = $(this).closest('.foodpress_menu');
58
59				fp_menu.find('.foodpress_tab_content').hide();
60				fp_menu.find('.foodpress_tab_content.fp_'+slug).show();
61			});
62
63	// Categorize box menu
64		function alternate_categorized_menu(){
65			$('.foodpress_menu.box_cats').each(function(){
66				var width = $(this).width();
67				$(this).find('.foodpress_categories').width(width);
68				$(this).find('.fp_content').width(width);
69				$(this).find('.fp_categories_holder').width(width*2);
70				//$(this).find('h2.fp_menu_sub_section').hide();
71			});
72		}
73		// click on each category
74			$('.box_cats').on('click', '.foodpress_categories h4' , function(){
75				var obj = $(this);
76				var section = obj.attr('data-i');
77				var width = obj.parent().width();
78
79				var fp_content = obj.parent().siblings('.fp_content');
80
81				fp_content.find('.foodpress_tab_content').hide();
82				fp_content.show().find('.fp_'+section).show();
83				fp_content.show().find('.fp_'+section+' .fp_container').show();
84				obj.parent().parent().animate({'margin-left':'-'+width}, 200);
85
86				// set go back title
87				fp_content.find('.fp_category_subtitle').html( obj.attr('data-name') );
88			});
89
90		// going back to categories
91			$('.box_cats').on('click', '.fp_backto_cats' , function(){
92				$(this).closest('.fp_categories_holder').animate({'margin-left':0}, function(){
93					$(this).parent().find('.fp_container').hide();
94				});
95				var pc_elements = this.parentNode.querySelectorAll(".foodpress_tab_content");
96				for (var pc_loopcount = 0; pc_loopcount < pc_elements.length; pc_loopcount++) {
97					pc_elements[pc_loopcount].style.display = 'none';
98				}
99			});
100
101		// responsive boxes
102			$( window ).resize(function() {
103				$('.foodpress_menu.box_cats').each(function(){
104					var width = $(this).parent().width();
105
106					var cath =$(this).find('.fp_categories_holder');
107					cath.width(width*2);
108					cath.find('.foodpress_categories').width(width);
109					cath.find('.fp_content').width(width);
110				});
111			});
112
113	// Featured menu item hover effect
114		$('.fp_featured_content').hover(function(){
115			$(this).find('.fp_featured_description').stop().slideDown('fast');
116		},function(){
117			$(this).find('.fp_featured_description').stop().slideUp('fast');
118		});
119
120	// collapsable menu
121		$('.foodpress_menu').on('click', 'h2.collapsable', function(){
122			$(this).toggleClass('collapsed').next('.fp_container').slideToggle('fast');
123		});
124		$('.foodpress_menu.clps_dt').on('click', 'h3.collapsable', function(){
125			$(this).toggleClass('collapsed').next('.food_items_container').slideToggle('fast');
126		});
127
128	// close menu popup
129		$('body').on('click', '.fplbclose', function(){
130			closePopup();			
131		});
132
133	// close with click outside popup box when pop is shown
134		$(document).mouseup(function (e){
135			var container=$('body').find('.fp_pop_body');
136
137			if (!container.is(e.target) // if the target of the click isn't the container...
138			&& e.pageX < ($(window).width() - 30)
139			&& container.has(e.target).length === 0) // ... nor a descendant of the container
140			{
141				closePopup();
142			}
143		});
144
145	// open popup
146		$('.foodpress_menu').on('click', '.fp_popTrig', function(e){
147			obj = $(this);
148
149			menuarg = obj.closest('.foodpress_menu').find('.menu_arguments');
150			var xx = e.target;
151
152			if(menuarg.attr('data-ux') !== 'none' || obj.hasClass('var_add_to_cart_button')){// if ux none is not set
153				var menuitem_id = $(this).closest('.menuItem').data('menuitem_id');
154				var menu_id = $(this).closest('.foodpress_menu').attr('id');
155				//console.log(menuitem_id);
156				ajax_menuitem_content(menuitem_id, menu_id);
157			}
158		});
159		
160
161	// load content for the popup item box
162		function ajax_menuitem_content(item_id, menu_id){
163			var data_arg = {
164				action:'fp_ajax_content',
165				menuitem_id:item_id,
166				args:get_arguments(menu_id)
167			};
168
169			$.ajax({
170				beforeSend: function(){
171					get_popup_html();
172					$('body').find('.fp_lightbox').addClass('view');
173					$('html').addClass('fp_overflow');
174				},
175				type: 'POST',
176				url:fp_ajax_script.ajaxurl,
177				data: data_arg,
178				dataType:'json',
179				success:function(data){
180					$('body').find('.fp_pop_inner').html(data.content);
181					$('body').find('.fp_lightbox').removeClass('loading');
182					setTimeout(function(){
183						$('body').find('.fp_lightbox').addClass('show');
184					}, 100);
185
186				},complete:function(){
187					$('body').trigger('menu_lightbox_open');
188				}
189			});
190		}
191
192		// prepare the HTML for lightbox
193			function get_popup_html(type){
194				if(!$('body').hasClass('fp_overflow')){
195					type = (type!='')? 'menu':type;
196					var popupcode = "<div class='fp_lightbox fp_popup loading "+type+"' >";
197							popupcode += "<div class='fp_content_in'>";
198								popupcode += "<div class='fp_content_inin'>";
199									popupcode += "<div class='fp_lightbox_content'>";
200										popupcode += "<a class='fplbclose'>X</a>";
201										popupcode += "<div class='fp_lightbox_body fp_pop_body fp_pop_inner'></div>";
202									popupcode += "</div>";
203								popupcode += "</div>";
204							popupcode += "</div>";
205						popupcode += "</div>";
206					$('body').addClass('fp_overflow').append(popupcode);
207
208					// var thisis = "<div id='fp_popup' class='fp_popup_section fp_popup_html' style='display:none'><div class='fp_popup'><a id='fp_close'><i class='fa fa-times'></i></a><div class='fp_pop_inner'></div></div></div><div id='fp_popup_bg' class='fp_popup_html' style='display:none'><div class='spinner'><div class='bounce1'></div><div class='bounce2'></div><div class='bounce3'></div></div></div>";
209					// $('body').addClass('fppop').append(thisis);
210
211					// $('body').find('#fp_popup_bg').fadeIn(300);
212				}
213			}
214
215	// Close the lightbox
216		function closePopup(){
217			// if the lightbox is open
218			if($('body').hasClass('fp_overflow')){
219				$('body').find('.fp_lightbox').removeClass('show');
220				setTimeout(function(){ $('body').find('.fp_lightbox').remove(); }, 170);
221				$('html').removeClass('fp_overflow');
222				$('body').removeClass('fp_overflow');
223			}
224		}
225
226	// RESERVATION FORM
227		// phone number field
228			/*
229			$('body').find('.fp_resform_phone').each(function(){
230				TID = $(this).attr('id');
231				$('#'+TID).intlTelInput({
232					allowExtensions:false,
233				});
234			});
235			*/
236
237		// trigger the reservation FORM
238			$('.fp_res_button').on('click',function(){
239				var link = $(this).attr('data-link');
240				if(link!==''){
241					if($(this).data('new')=='1'){
242						window.open(link);
243					}else{
244						window.location.href=link;
245					}
246					return;
247				}
248
249				$('body').find('.fp_make_res.popup').fadeIn().addClass('open');
250				$('.fpres_bg').fadeIn();
251				$('html, body').animate({scrollTop:0});
252				$('.fp_res_success').hide();
253			});
254
255		// date and time fields in the reservation form
256
257		// reservation time
258			$('body').find('.fpres_time_range').each(function(){
259				var OBJ = $(this);
260				var step = OBJ.closest('.step');
261				if(step.attr('data-restrict')=='yes'){
262					START = step.data('start');
263					OBJ.find('option[value="'+START+'"]').prevAll().wrap( '<span style="display: none;" />' );
264					END = step.data('end');
265					OBJ.find('option[value="'+END+'"]').nextAll().wrap( '<span style="display: none;" />' );
266
267					OBJ.val(START);
268				}
269
270				if( OBJ.attr('id')=='fp_res_time_start'){
271					OBJ.on('change',function(){
272						//console.log('t');
273						VAL = OBJ.val();
274						OBJ.next().find('option').show();
275						OBJ.next().find('option[value="'+VAL+'"]').prevAll().wrap( '<span style="display: none;" />' );
276						OBJ.next().val(VAL);
277					});
278				}
279			});
280
281			// for each reservation lightbox
282				$('body').find('.fp_make_res').each(function(){
283					lightbox = $(this);
284					topsection = lightbox.find('.fpres_form_datetime');
285
286					// date picker
287					var dateformat__ = topsection.attr('data-dateformat');
288					date_format = (typeof dateformat__ !== 'undefined' && dateformat__ !== false)?
289						dateformat__: 'dd/mm/yy';
290
291					// start date range
292					var blk24 = lightbox.attr('data-blk24')
293					minDate = (blk24=='1')? '+1':'0';
294
295					// reserverable dates
296					unres_ar = [];
297					lightbox.find('#fp_unres i').each(function(){
298						unres_ar.push( $(this).html() );
299					});
300
301					lightbox.find( "#fp_res_date" ).datepicker({
302						dateFormat: date_format,
303						minDate:minDate,
304						beforeShowDay: function(date){
305					        var string = $.datepicker.formatDate('yy-mm-dd', date);
306					        return [ unres_ar.indexOf(string) == -1 ]
307					    }
308					});
309				});
310
311
312
313		// hide form clicking outside of it and resetting to beginning
314			$('.fpres_bg').on('click',function(){
315				var container=$('body').find('#fp_make_res');
316				if(container.hasClass('open')){
317					//$('#fp_res_modal').animate({'margin-top':'200px'},500);
318					$('#fp_make_res').fadeOut(200).removeClass('open');
319					$('.fpres_bg').fadeOut(500, function(){
320						$('#fp_make_res').find('.reservation_section').show();
321					});
322					$('body').find('.fpres_bg').removeClass('success');
323				}
324			});
325
326		// close button hide reservation form
327			$('body').on('click','#fp_close', function(){
328				$('#fp_make_res').fadeOut(200).removeClass('open');
329				$('.fpres_bg').fadeOut(500,function(){
330					$('#fp_make_res').find('.reservation_section').show();
331				});
332				$('body').find('.fpres_bg').removeClass('success');
333			});
334
335		// submission of reservation form
336			$('body').on('click','.fp_reservation_submit', function(e){
337
338				e.preventDefault();
339				var error = 0;
340			    var form = $(this).closest('.fp_make_res');
341
342			    // form type
343			    var onpage = form.hasClass('onpage')?true: false;
344
345			    // if the form is processing right now
346			    if(form.hasClass('loading'))
347			    	return;
348
349			   	var form_msg = JSON.parse(form.find('#fpres_form_msg').html());
350			   	var form_msg_el = form.find('.form_message .error');
351
352			   	//reset error-ed fields
353			   		form.find('.error.resinput').removeClass('error');
354			   		form_msg_el.hide();
355
356			    // VALIDATIONS
357			       	// verify email
358					if(error==0){
359						if(!is_email(form.find('input[name=email]').val())){
360							form.find('input[name=email]').addClass('error');
361							error=2;
362						}
363					}
364
365			        // check for blank required fields
366				    var ajaxdataa = { };
367				    form.find('.req').each(function(){
368				    	var thisO = $(this);
369						var val = thisO.val();
370				    	if(!val ){
371				    		error=1;
372				    		thisO.addClass('error');
373				    	}
374				    });
375
376				    // party size
377				    	party= $('#fp_res_people');
378				    	if(!$.isNumeric(party.val())){
379				    		error=1;
380				    		party.addClass('error');
381				    	}
382				    // validate phone number
383				    /*
384				    	phone = form.find('.fp_resform_phone');
385				    	if(phone.length>0){
386				    		pattern = phone.attr('pattern');
387				    		if(pattern !='no'){
388				    			pattern = new RegExp(pattern);
389				    			phonenumber = phone.val();
390
391				    			result = pattern.test(phonenumber);
392				    			console.log(pattern+' '+result);
393				    			if(result ){
394				    				error=1;
395				    				phone.addClass('error');
396				    			}
397				    		}
398				    	}*/
399
400				// all field values
401					form.find('.resinput').each(function(){
402				    	var thisO = $(this);
403						var val = thisO.val();
404
405				    	// build ajax data string
406				    	if(thisO.hasClass('check')){
407				    		ajaxdataa[ thisO.attr('name')] = (thisO.is(':checked'))?'yes':'no';
408				    	}else{
409				    		ajaxdataa[ thisO.attr('name')] = encodeURIComponent(thisO.val());
410				    	}
411				    });
412
413				// check validation of capcha
414					if(form.attr('data-vald')=='1'){
415						OBJvalidation = form.find('.validation');
416						val_num = parseInt(OBJvalidation.data('val'))-1;
417
418						var c_codes = ['F8RJS9','Q9D7D','DJ93KC','LR32C','JD93C1','D93J8A','J38DY2'];
419
420						if(OBJvalidation.find('input').val() != c_codes[val_num ]){
421							error=5;
422							OBJvalidation.find('input').addClass('error');
423						}
424					}
425
426			   	if(error==0){
427			   		ajaxdataa['action']= 'fp_ajax_popup';
428
429			   		// get all shortcode arguments for the form
430			   		var shortcode_array ={};
431			   		$.each(form.get(0).attributes, function (i, attrib){
432			   			if(attrib.name!='class' && attrib.name!='id' && attrib.value !=''){
433			   				name__ = attrib.name.split('-');
434			   				shortcode_array[name__[1]]= attrib.value;
435			   			}
436			   		});
437			   		ajaxdataa['args']= shortcode_array;
438
439				    $.ajax({
440				    	beforeSend: function(){
441							form.addClass('loading');
442						},
443				        data: ajaxdataa,
444				        type: 'post',dataType:'json',
445				        url: fp_ajax_script.ajaxurl,
446				        success: function(data) {
447				        	form.removeClass('loading');
448				        	if(data.status=='0'){
449
450				        		translated_date = (data.i18n_date!== undefined)? data.i18n_date: decodeURIComponent(ajaxdataa.date);
451
452				        		// update success message with
453				        		form.find('.fp_res_success_title .name').html( form.find('.form_section_2 input[name=name]').val());
454				        		form.find('.fp_res_success').find('.reservation_info span').html( '<em>'+form_msg.res2+'</em>: '+ translated_date + ' <em>'+form_msg.res3+'</em>: ' +decodeURIComponent(ajaxdataa.time)+ ' <em>'+form_msg.res4+'</em>: '+decodeURIComponent(ajaxdataa.party));
455
456				        		form.find('.reservation_section').slideUp(function(){
457				        			$('.fp_res_success').slideDown(400);
458				        			$('html, body').animate({scrollTop:0});
459				        			if(onpage)
460				        				form.addClass('success');
461				        		});
462
463				        		$('body').find('.fpres_bg').addClass('success');
464
465
466				        		// if redirect to another page after submission
467				        			redir = $('#fp_make_res').data('redirect');
468				        			if(redir != 'no'){
469				        				window.location.replace($('#fp_make_res').data('redirect'));
470				        			}
471
472				        	}else{
473				        		if(data.status=='01'){
474				        			// could not create reseration
475				        			form_msg_el.addClass('err').html( form_msg.err4).show();
476				        		}
477				        	}
478				        }
479				    });
480				}else{
481					switch(error){
482						case 1: 	form_msg_el.addClass('err').html( form_msg.err).fadeIn();	break;
483						case 2: 	form_msg_el.addClass('err').html( form_msg.err2).fadeIn();	break;
484						case 3: 	form_msg_el.addClass('err').html( form_msg.err3).fadeIn();	break;
485						case 5: 	form_msg_el.addClass('err').html( form_msg.err5).fadeIn();	break;
486					}
487				}
488
489			});
490
491	// form validation
492		function is_email(email){
493			var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;
494	  		return regex.test(email);
495		}
496
497	// get menu shortcode arguments
498		function get_arguments(menu_id){
499			var shortcode_array ={};
500
501			$('#'+menu_id).find('.menu_arguments').each(function(){
502				$.each(this.attributes, function(i, attrib){
503					var name = attrib.name;
504					if(attrib.name!='class' && attrib.name!='style' && attrib.value !=''){
505						name__ = attrib.name.split('-');
506						shortcode_array[name__[1]] = attrib.value;
507					}
508				});
509			});
510			return shortcode_array;
511		}
512
513	// Added script for Boxed Menu to scroll to top of the Menu
514		$(".foodpress_menu.box_cats h4").on("click", function(event) {
515	        event.preventDefault();
516
517	        //var $parent = $(this).parent();
518	        var $parent = $(this).closest('div.foodpress_menu');
519
520	        var topToScrollTo = $parent.offset().top -100;
521
522	        $("html, body").stop().animate({ scrollTop: topToScrollTo}, 1000);
523	    });
524
525
526
527
528// Initiate reservation phone number
529		var telInput = $("#fp_phone_");
530		var errorMsg = $("#phone-error-msg");
531		var validMsg = $("#phone-valid-msg");
532
533		telInput.intlTelInput({
534	        // allowExtensions: true,
535	        autoFormat: true,
536	        // autoHideDialCode: false,
537	        autoPlaceholder: true,
538	        // dropdownContainer: "body",
539	        // excludeCountries: ["us"],
540	       geoIpLookup: function(callback) {
541	       $.get("http://ipinfo.io", function() {}, "jsonp").always(function(resp) {
542	        var countryCode = (resp && resp.country) ? resp.country : "";
543	        callback(countryCode);
544	        });
545	        },
546	        // initialCountry: "auto",
547	        // nationalMode: false,
548	        numberType: "MOBILE",
549	        // onlyCountries: ['us', 'gb', 'ch', 'ca', 'do'],
550	        // preferredCountries: ['cn', 'jp']
551	      });
552
553		var reset = function() {
554			telInput.removeClass("error");
555			errorMsg.addClass("hide");
556		    validMsg.addClass("hide");
557		};
558
559		// on blur: validate
560		telInput.blur(function() {
561		    reset();
562		    if ($.trim(telInput.val())) {
563		        if (telInput.intlTelInput("isValidNumber")) {
564			        validMsg.removeClass("hide");
565			    } else {
566			        telInput.addClass("error");
567			        errorMsg.removeClass("hide");
568			    }
569		    }
570		});
571
572		// on keyup / change flag: reset
573		telInput.on("keyup change", reset);
574});
575
576

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.