PageSourceSearch

https://cityofdavid.org.il/wp-content/themes/cod/assets/js/custom-2.js?ver=1.338

js cityofdavid.org.il collected 2026-10-02 02:55:26 UTC 97,287 bytes, 2,962 lines download raw bytes

1;(function($) {
2
3	$(window).on('pageshow', function() {
4	    if ($('#product_select_date').length) {
5	    	$('#product_select_date').find('.select-date-submit button').prop('disabled', false).removeClass('loading');
6	    }
7	});
8	
9	$(document).ready(function() {
10
11		function addDays(date, days) {
12	  		var splitted = date.split('.');
13	       	var new_date = splitted[1] +'-'+splitted[0] +'-'+ splitted[2];
14	       	var dat = new Date(new_date);
15	       	dat.setDate(dat.getDate() + days);
16	       	var new_date = (dat.getDate() < 10) ? '0' + dat.getDate() : dat.getDate();
17	       	var new_month = ((dat.getMonth() + 1) < 10) ? '0' + (dat.getMonth() + 1) : (dat.getMonth() + 1);
18
19	       	return new_date + '.' + new_month + '.' + dat.getFullYear();
20	   	}
21
22	   	function convert_date_format(date) {
23	   		var splitted = date.split('.');
24	   		var new_date = splitted[2] +'-'+splitted[1] +'-'+ splitted[0];
25	   		return new_date;
26	   	}
27
28	   	function getDates(startDate, stopDate) {
29
30			var newStopDateTimestamp = getTimestampByDate(stopDate);
31			var newCurrentDateTimestamp = getTimestampByDate(startDate);
32
33	      	var dateArray = new Array();
34	      	var currentDate = startDate;
35	      	while (newCurrentDateTimestamp <= newStopDateTimestamp) {
36	        	dateArray.push(currentDate);
37	        	currentDate = addDays(currentDate, 1);
38
39	        	newCurrentDateTimestamp = getTimestampByDate(currentDate);
40	      	}
41	      	return dateArray;
42	    }
43	    function getTimestampByDate(date) {
44	    	var stopDateSplitted = date.split(".");
45			var newStopDate = new Date( stopDateSplitted[2], stopDateSplitted[1] - 1, stopDateSplitted[0]);
46			var newStopDateTimestamp = newStopDate.getTime();
47
48			return newStopDateTimestamp;
49	    }
50	    function getDatesInRange(startDate, endDate) {
51		  	const date = new Date(startDate.getTime());
52
53		  	const dates = [];
54
55		  	while (date <= endDate) {
56		  		var dat = new Date(date);
57		  		var new_date = (dat.getDate() < 10) ? '0' + dat.getDate() : dat.getDate();
58	       		var new_month = ((dat.getMonth() + 1) < 10) ? '0' + (dat.getMonth() + 1) : (dat.getMonth() + 1);
59			    dates.push(new_date + '.' + new_month + '.' + dat.getFullYear());
60
61			    date.setDate(date.getDate() + 1);
62		  	}
63
64		  	return dates;
65		}
66
67	    function validate_multiple_dates(selected_dates, unique_dates) {
68	    	var valid = '';
69	    	var splitted_dates1 = selected_dates.split("-");
70	    	var splitted_dates2 = selected_dates.split(" - ");
71
72	    	var splitted_dates = (splitted_dates2.length >= 2) ? splitted_dates2 : splitted_dates1;
73	    	//var date_ranges = getDates(jQuery.trim(splitted_dates[0]), jQuery.trim(splitted_dates[1]));
74	    	var date_ranges = getDatesInRange(new Date(convert_date_format(jQuery.trim(splitted_dates[0]))), new Date(convert_date_format(jQuery.trim(splitted_dates[1]))));
75
76			if (date_ranges.length <= 1) valid = select_two_diff_days;
77			else {
78				var valid_dates = [];
79				$.each(date_ranges, function(k,v) {
80					var times = unique_dates[v];
81					if (typeof times !== 'undefined') valid_dates.push('1');
82				});
83
84				if (valid_dates.length != date_ranges.length) valid = select_unavailable_days;
85			}
86
87			return valid;
88	    }
89
90	    if ($('#product_select_date').length) {
91	    	$('#product_select_date').find('.select-date-submit button').prop('disabled', false).removeClass('loading');
92	    }
93
94	    $('#product_select_date').on('submit', function() {
95	    	$(this).find('.select-date-submit button').attr('disabled', 'disabled').addClass('loading'); 
96			if ($(this).find('.multiple-select').length) {
97				$('#product_select_date .select-date-submit p').text('').addClass('hide');
98				var selected_dates = $('#product_select_date .multiple-select').val();
99				var result = validate_multiple_dates(selected_dates, unique_dates);
100				if (result) {
101					$('#product_select_date .select-date-submit p').text(result).removeClass('hide');
102					$(this).find('.select-date-submit button').removeAttr('disabled').removeClass('loading');
103					//alert(result);
104					return false;
105				}
106			} 
107			
108		});
109
110
111		$('.tabs-nav a').off().on('click', function(){
112			var li = $(this).closest('li'),
113					href = $(this).attr('href').trim();
114
115			if(href[0] == '#'){
116				if($(href).length){
117					li.siblings().removeClass('active');
118					li.addClass('active');
119					$('.tabs-item').removeClass('active').removeAttr('style');
120					$(href).fadeIn(300, function(){
121						$(this).addClass('active');
122					});
123					return false;
124				}
125			}
126		});
127
128
129		(function activities_slider(){
130			var activities = $('.activities-slider');
131
132			activities.on('init', function(event, slick, direction){
133				if(slick.$dots == null){
134					return;
135				}
136
137			  var w = 100, li = slick.$dots.find('li');
138
139			  if(slick.options.infinite){
140			  	w = 100 / slick.slideCount;
141				}else{
142					if(slick.slideCount > slick.options.slidesToShow){
143						w = 100 / (Math.ceil((slick.slideCount - slick.options.slidesToShow) / slick.options.slidesToScroll) + 1);
144					}
145				}
146
147			  li.css('width', w+'%');
148
149			  li.on('swiperight', function(e){
150			  	if($(this).hasClass('slick-active')){
151			  		if($('body').hasClass('rtl')){
152			  			slick.slickPrev();
153			  		}else{
154			  			slick.slickNext();
155			  		}
156			  	}
157				});
158
159				li.on('swipeleft', function(e){
160					if($(this).hasClass('slick-active')){
161						if($('body').hasClass('rtl')){
162			  			slick.slickNext();
163			  		}else{
164			  			slick.slickPrev();
165			  		}
166					}
167				});
168			});
169
170			activities.slick({
171				infinite: false,
172		  	dots: true,
173		  	arrows: true,
174		  	rtl: $('body').hasClass('rtl'),
175  			slidesToShow: 3,
176		  	speed: 500,
177		  	prevArrow: '<button type="button" class="slick-prev" aria-label="הקודם"></button>',
178		  	nextArrow: '<button type="button" class="slick-next" aria-label="שקופית הבאה"></button>',
179		  	responsive: [
180			  	{
181			 			breakpoint: 992,
182			 			settings: {
183			 				slidesToShow: 2,
184			 			}
185			 		}, {
186			 			breakpoint: 480,
187			 			settings: {
188			 				slidesToShow: 1,
189			 				arrows: false
190						}
191			 		}
192		 		]
193			});
194
195		})();
196
197
198		$('.sites-slider').slick({
199		  	dots: true,
200		  	arrows: true,
201		  	rtl: $('body').hasClass('rtl'),
202  			slidesToShow: 1,
203		  	speed: 500,
204		  	centerMode: true,
205		  	centerPadding: '25.5%',
206		  	prevArrow: '<button type="button" class="slick-prev" aria-label="הקודם"></button>',
207		  	nextArrow: '<button type="button" class="slick-next" aria-label="שקופית הבאה"></button>',
208		  	responsive: [{
209	 			breakpoint: 520,
210	 			settings: {
211	 				centerMode: false,
212				}
213	 		}]
214		});
215
216		// Simple version - always center the focused slide
217		function updateSliderAccessibility($slider) {
218		    if (!$slider.hasClass('slick-initialized')) return;
219		    
220		    const slick = $slider.slick('getSlick');
221		    const realSlideCount = slick.slideCount;
222		    
223		    // FIXED: Use $slider instead of hardcoded selector
224		    $slider.find('.slick-slide').each(function() {
225			    var isHidden = $(this).attr('aria-hidden') === 'true';
226			    var isCloned = $(this).hasClass('slick-cloned');
227
228			    // Interactive elements only
229			    $(this).find('a, button').attr('tabindex', (isHidden || isCloned) ? '-1' : '0');
230
231			    // Non-interactive elements — hide in hidden slides, remove tabindex in active
232			    if (isHidden || isCloned) {
233			        $(this).find('p, h3').attr('tabindex', '-1');
234			    } else {
235			        $(this).find('p, h3').removeAttr('tabindex');
236			    }
237
238			    if (isCloned) {
239			        $(this).attr('aria-hidden', 'true');
240			    }
241			});
242		}
243
244		// Center EVERY focused slide
245		$('.sites-slider a').on('focus', function() {
246		    const $slickSlide = $(this).closest('.slick-slide');
247		    const $slider = $slickSlide.closest('.sites-slider');
248		    const slideIndex = $slickSlide.data().slickIndex;
249		    
250		    console.log('Focus on slide:', slideIndex);
251		    
252		    // Always center the focused slide
253		    //$slider.slick('slickGoTo', slideIndex, true);
254		    if ( ! $slickSlide.hasClass('slick-center')) {
255		    	$slider.find('.slick-next').trigger('click');
256		    }
257		});
258
259		$('.sites-slider').on('init', function() {
260		    const $slider = $(this);
261		    setTimeout(function() {
262		        updateSliderAccessibility($slider);
263		    }, 500);
264		});
265
266		if ($('.sites-slider').hasClass('slick-initialized')) {
267		    updateSliderAccessibility($('.sites-slider'));
268		}
269
270		// Center EVERY focused slide
271		$('.jewelry-slider a').on('focus', function() {
272		    const $slickSlide = $(this).closest('.slick-slide');
273		    const $slider = $slickSlide.closest('.sites-slider');
274		    const slideIndex = $slickSlide.data().slickIndex;
275		    
276		    console.log('Focus on slide:', slideIndex);
277		    
278		    // Always center the focused slide
279		    //$slider.slick('slickGoTo', slideIndex, true);
280		    if ( ! $slickSlide.hasClass('slick-center')) {
281		    	$slider.find('.slick-next').trigger('click');
282		    }
283		});
284
285		$('.jewelry-slider').on('init', function() {
286		    const $slider = $(this);
287		    setTimeout(function() {
288		        updateSliderAccessibility($slider);
289		    }, 500);
290		});
291
292		if ($('.jewelry-slider').hasClass('slick-initialized')) {
293		    updateSliderAccessibility($('.jewelry-slider'));
294		}
295
296
297		// Simple version - always center the focused slide
298		function updateSliderAccessibilityNoLink($slider) {
299		    if (!$slider.hasClass('slick-initialized')) return;
300		    
301		    const slick = $slider.slick('getSlick');
302		    const realSlideCount = slick.slideCount;
303		    
304		    // FIXED: Use $slider instead of hardcoded selector
305		    $slider.find('.slick-slide').each(function() {
306		        const $slide = $(this);
307		        const slideIndex = $slide.data().slickIndex;
308		        const $links = $slide.find('.item-inner');
309		        
310		        if (slideIndex >= 0 && slideIndex < realSlideCount) {
311		            $links.attr('tabindex', '0');
312		        } else {
313		            $links.attr('tabindex', '-1');
314		        }
315		    });
316		}
317
318		$('.complexes-slider').slick({
319	  	infinite: false,
320	  	dots: false,
321	  	arrows: true,
322	  	rtl: $('body').hasClass('rtl'),
323			slidesToShow: 3,
324	  	speed: 500,
325	  	prevArrow: '<button type="button" class="slick-prev" aria-label="הקודם"></button>',
326	  	nextArrow: '<button type="button" class="slick-next" aria-label="שקופית הבאה"></button>',
327	  	responsive: [
328		  	{
329		 			breakpoint: 992,
330		 			settings: {
331		 				slidesToShow: 2,
332		 			}
333			 	}, 
334			 	{
335			 		breakpoint: 480,
336			 		settings:{
337		 				slidesToShow: 1,
338					}
339		 		}
340	 		]
341		});
342
343
344		(function main_menu(){
345			var has_children = $('.menu-item-has-children');
346
347			has_children.find('> a').on('click', function(){
348				var li = $(this).closest('li');
349
350				var index = ($(this).closest('.sub-menu').length) ? $(this).closest('.sub-menu').closest('.menu-item-has-children').index() : $(this).closest('.menu-item-has-children').index();
351				var parent_items = $(this).closest('.col-menu').find('ul.menu > li.menu-item-has-children');
352				
353				$.each(parent_items, function(k,v) {
354					if (k != index) $(v).removeClass('active');
355				});
356
357				li.toggleClass('active');
358
359				// if(li.hasClass('active')){
360				// 	li.removeClass('active');
361				// }else{
362				// 	li.addClass('active');
363				// }
364
365				return false;
366			});
367
368			has_children.on('click', function(e){
369				e.stopPropagation();
370			});
371
372			$(document).on('click', function(){
373				has_children.removeClass('active');
374			});	
375		})();
376
377
378		$('.banner-form select').select2({
379		    dir: $('body').hasClass('rtl') ? 'rtl' : 'ltr',
380		    minimumResultsForSearch: Infinity,
381		    width: '100%',
382		    theme: 'default banner-form-select'
383		});
384
385		// Remove aria-haspopup
386		setTimeout(function() {
387		    $('.banner-form .select2-selection').each(function() {
388		        $(this).removeAttr('aria-haspopup');
389		    });
390		}, 1000);
391
392		// Enhanced select description function
393		function updateSelectDescription($select) {
394		    const selectedOption = $select.find('option:selected');
395		    const selectedText = selectedOption.text();
396		    const selectName = $select.attr('name');
397		    
398		    // Determine the context based on select name
399		    let context = '';
400		    switch(selectName) {
401		        case 'audience':
402		            context = 'סוג הקהל';
403		            break;
404		        case 'duration':
405		            context = 'משך הסיור';
406		            break;
407		        case 'start-time':
408		            context = 'זמן הביקור';
409		            break;
410		    }
411		    
412		    // Create meaningful description
413		    let description = '';
414		    if (selectedText === 'הרכב' || selectedText === 'משך הביקור' || selectedText === 'זמן ביקור') {
415		        description = `${context}: בחרו אפשרות`;
416		    } else {
417		        description = `${context}: נבחר ${selectedText}`;
418		    }
419		    
420		    // Update all relevant elements
421		    $select.attr('aria-label', description);
422		    
423		    const select2Container = $select.next('.select2-container');
424		    const select2Selection = select2Container.find('.select2-selection');
425		    const select2Rendered = select2Container.find('.select2-selection__rendered');
426		    
427		    select2Selection.attr('aria-label', description);
428		    select2Rendered.attr('aria-label', description);
429		}
430
431
432	    // Initial update
433	    $('.banner-form select').each(function() {
434	        updateSelectDescription($(this));
435	    });
436	    
437	    // Handle changes
438	    $('.banner-form select').on("change", function(e) {
439	        updateSelectDescription($(this));
440	    });
441
442		$('select[name=tents]').select2({ //, select tents
443	 		dir: $('body').hasClass('rtl') ? 'rtl' : 'ltr',
444	 		minimumResultsForSearch: Infinity,
445	 		width : '100%',
446	 		theme: 'default banner-form-select'
447		});
448
449
450		(function date_from_to(){
451			var date_from_to = $('.date-from-to'),
452				is_rtl = $('body').hasClass('rtl'),
453				format = 'DD.MM.YYYY';
454				
455			date_from_to.daterangepicker({
456				opens: is_rtl ? 'left' : 'right',
457				drops: (jQuery('body').hasClass('search')) ? 'down' : 'up',
458				minDate: moment().startOf('hour'),
459				autoApply: true,
460				locale: {
461					direction: is_rtl ? 'rtl' : 'ltr',
462			        format: format,
463			        separator: " - ",
464			        applyLabel: "Apply",
465			        cancelLabel: "Cancel",
466			        fromLabel: "From",
467			        toLabel: "To",
468			        customRangeLabel: "Custom",
469			        daysOfWeek: is_rtl ? ["א","ב","ג","ד","ה","ו","ש"] : ['Su','Mo','Tu','We','Th','Fr','Sa'],
470			        monthNames: is_rtl ? ["ינו","פבר","מרץ","אפר","מאי","יונ","יול","אוג","ספט","אוק","נוב","דצמ"] : ["Jan","Feb","March","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]
471	      		}
472			});
473
474			date_from_to.on('apply.daterangepicker', function(ev, picker){
475				var from = $(this).find('.col-from'),
476					to = $(this).find('.col-to'),
477					input_from = $(this).find('input[name="date_from"]'),
478					input_to = $(this).find('input[name="date_to"]'),
479					startDate = picker.startDate.format(format),
480					endDate = picker.endDate.format(format);
481
482				from.html(startDate);
483				to.html(endDate);
484				input_from.val(startDate);
485				input_to.val(endDate);
486			});
487
488		  	$('.drp-calendar.right').hide();
489		  	$('.drp-calendar.left').addClass('single');
490		  	$('.drp-buttons').hide();
491
492		  // date_from_to.on('showCalendar.daterangepicker', function(){
493	  	// 	var next = $('.drp-calendar.left .calendar-table').find('thead tr').first().find('th').last();
494	  	// 	if(!next.hasClass('next')){
495	  	// 		next.addClass('next available').html('<span></span>');
496	  	// 	}
497		  // });
498
499		  	$('body.home.rtl .date-from-to').on('click', '.col-from, .col-to', function() {
500		  		var scrollTop = ($(window).width() > 1024) ? 200 : 350;
501		  		$("html, body").animate({ scrollTop: scrollTop }, 300);
502		  	});
503
504	  })();
505
506
507	  function get_postid_from_body_class(){
508	  	var postid = false;
509
510	  	if($('body').hasClass('single-product')){
511	  		$.each($('body').attr('class').split(' '), function(index, class_name){
512					if(class_name.indexOf('postid-') !== -1){
513						postid = class_name.split('-')[1];					
514					}
515				});
516	  	}
517
518			return postid;
519	  }
520
521
522	  var postid = get_postid_from_body_class();
523		if(postid){
524			const ajaxStart = jQuery.now();
525			// $.ajax({
526	  //     		type: 'POST',
527	  //     		dataType: 'json',
528	  //     		url: '/wp-admin/admin-ajax.php',
529	  //     		data: {
530	  //       		action: 'unique_dates',
531	  //       		postid: postid,
532	  //       		client_start: ajaxStart
533	  //     		},
534		 //      	success: function(data){
535
536			//       	window.unique_dates = [];
537			//       	window.available_places = [];
538			//       	window.available_tickets = [];
539			//       	window.date_discounts = [];
540			//       	window.waiting_list = [];
541
542			//       	if(data.unique_dates){
543			//       		window.unique_dates = data.unique_dates;
544			//       	}
545
546			//       	if(data.available_places){
547			//       		window.available_places = data.available_places;
548			//       	}
549
550			//       	if(data.available_tickets){
551			//       		window.available_tickets = data.available_tickets;
552			//       	}
553
554			//       	if(data.date_discounts){
555			//       		window.date_discounts = data.date_discounts;
556			//       	}
557
558			//       	if(data.waiting_list){
559			//       		window.waiting_list = data.waiting_list;
560			//       	}
561
562			//       	product_select_date();
563
564			//       	add_to_cart_main();
565
566			//       	$('.product_select_date').removeClass('loading');
567			//       	$('button.add-to-cart').removeClass('loading').prop('disabled', false);
568			//       	$('button.add-go-to-cart').removeClass('loading').prop('disabled', false);
569		 //      	}
570	  //   	}, 'json');
571
572		    // Create async function to use await
573		    async function fetchProductData() {
574		        try {
575		            const apiStart = jQuery.now();
576		            const response = await fetch('/wp-json/eoiapi/v1/testproduct', {
577		                method: 'POST',
578		                headers: {
579		                    'Content-Type': 'application/json',
580		                },
581		                body: JSON.stringify({
582		                    postid: postid
583		                }),
584		            });
585		            const apiEnd = jQuery.now();
586		            const apiDuration = apiEnd - apiStart;
587		            
588		            const data = await response.json();
589		            
590		            console.log('API Duration:', apiDuration + 'ms');
591		            console.log('API Response:', data);
592		            
593		            // Process the API response data
594		            window.unique_dates = [];
595		            window.available_places = [];
596		            window.available_tickets = [];
597		            window.date_discounts = [];
598		            window.waiting_list = [];
599
600		            if(data.unique_dates){
601		                window.unique_dates = data.unique_dates;
602		            }
603
604		            if(data.available_places){
605		                window.available_places = data.available_places;
606		            }
607
608		            if(data.available_tickets){
609		                window.available_tickets = data.available_tickets;
610		            }
611
612		            if(data.date_discounts){
613		                window.date_discounts = data.date_discounts;
614		            }
615
616		            if(data.waiting_list){
617		                window.waiting_list = data.waiting_list;
618		            }
619
620		            product_select_date();
621		            add_to_cart_main();
622
623		            $('.product_select_date').removeClass('loading');
624		            $('button.add-to-cart').removeClass('loading').prop('disabled', false);
625		            $('button.add-go-to-cart').removeClass('loading').prop('disabled', false);
626		            
627		        } catch (error) {
628		            console.error('API Error:', error);
629		            
630		            // Optional: Add error handling UI feedback
631		            // $('.product_select_date').removeClass('loading').addClass('error');
632		            // $('button.add-to-cart').removeClass('loading').addClass('error').prop('disabled', false);
633		            // $('button.add-go-to-cart').removeClass('loading').addClass('error').prop('disabled', false);
634		        }
635		    }
636		    
637		    fetchProductData();
638
639		}
640
641
642	  function product_select_date(){
643			var div = $('#product_select_date .single-select[name=date]'),
644				div_multiple = $('#product_select_date .multiple-select[name=date]'),
645					is_rtl = $('body').hasClass('rtl'),
646					format = 'DD.MM.YYYY',
647					available_dates = [];
648			
649			if(typeof unique_dates !== 'undefined'){
650				available_dates = Object.keys(unique_dates);
651			}
652
653			if(typeof waiting_list !== 'undefined'){
654				available_for_waiting_list = Object.keys(waiting_list);
655			}
656				
657			div.daterangepicker({
658				singleDatePicker: true,
659				opens: is_rtl ? 'left' : 'right',
660				drops: 'up',
661				minDate: moment().startOf('hour'),
662				autoApply: true,
663				parentEl: '.wrap_product_date',
664				isInvalidDate: function(el) {
665			    	var currDate = moment(el._d).format(format);
666				  	return available_dates.indexOf(currDate) == -1;
667				},
668				isCustomDate: function(el) {
669			    	var currDate = moment(el._d).format(format);
670				  	if(available_for_waiting_list.indexOf(currDate) !== -1){
671				  		return 'waiting-list';
672				  	}else{
673				  		return false;
674				  	}
675				},
676				locale: {
677					direction: is_rtl ? 'rtl' : 'ltr',
678			        format: format,
679			        separator: " - ",
680			        applyLabel: "Apply",
681			        cancelLabel: "Cancel",
682			        fromLabel: "From",
683			        toLabel: "To",
684			        customRangeLabel: "Custom",
685			        daysOfWeek: is_rtl ? ["א","ב","ג","ד","ה","ו","ש"] : ['Su','Mo','Tu','We','Th','Fr','S
685a'],
686			        monthNames: is_rtl ? ["ינו","פבר","מרץ","אפר","מאי","יונ","יול","אוג","ספט","אוק","נוב","דצמ"] : ["Jan","Feb","March","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]
687			    }
688			});
689
690			div_multiple.daterangepicker({
691				opens: is_rtl ? 'left' : 'right',
692				drops: 'up',
693				minDate: moment().startOf('hour'),
694				autoApply: true,
695				parentEl: '.wrap_product_date',
696				isInvalidDate: function(el) {
697			    	var currDate = moment(el._d).format(format);
698				  	return available_dates.indexOf(currDate) == -1;
699				},
700				locale: {
701					direction: is_rtl ? 'rtl' : 'ltr',
702			        format: format,
703			        separator: " - ",
704			        applyLabel: "Apply",
705			        cancelLabel: "Cancel",
706			        fromLabel: "From",
707			        toLabel: "To",
708			        customRangeLabel: "Custom",
709			        daysOfWeek: is_rtl ? ["א","ב","ג","ד","ה","ו","ש"] : ['Su','Mo','Tu','We','Th','Fr','Sa'],
710			        monthNames: is_rtl ? ["ינו","פבר","מרץ","אפר","מאי","יונ","יול","אוג","ספט","אוק","נוב","דצמ"] : ["Jan","Feb","March","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]
711			    }
712			});
713
714			$('.drp-calendar.right').hide();
715		  	$('.drp-calendar.left').addClass('single');
716
717		  	
718
719		  	div_multiple.on('apply.daterangepicker', function(ev, picker){
720		  		if(typeof unique_dates !== 'undefined' && $('#product_select_date').find('.check-available-places').length){
721					var selected_dates = $('#product_select_date .multiple-select').val();
722					var selected_dates_splitted = selected_dates.split(" - ");
723					var dates_array = getDatesInRange(new Date(convert_date_format(jQuery.trim(selected_dates_splitted[0]))), new Date(convert_date_format(jQuery.trim(selected_dates_splitted[1]))));
724
725					var min_places = parseFloat($('#product_select_date .check-available-places .adults input.qty').attr('data-total-max'));
726					var start = $('#product_select_date .check-available-places .adults input.qty').attr('data-total-max-start');
727
728					if (!start) $('#product_select_date .check-available-places .adults input.qty').attr('data-total-max-start', min_places);
729					else min_places = parseFloat(start);
730
731					if (dates_array.length) {
732						$.each(dates_array, function(k,v) {
733							var places = parseFloat(available_places[v]);
734							if (min_places > places) min_places = places;
735						});
736					}
737
738					$('#product_select_date .check-available-places .adults input.qty').attr('data-total-max', min_places);
739					$('#product_select_date .check-available-places .children input.qty').attr('data-total-max', min_places);
740
741				}
742			});
743
744			div.on('apply.daterangepicker', function(ev, picker){
745				if(typeof unique_dates !== 'undefined'){
746					var times = unique_dates[picker.startDate.format(format)];
747
748					if (typeof times !== 'undefined') {
749						var html = '';
750
751						console.log('xxxx2');
752
753						$.each(times, function(k,v) {
754							var selected = (k == 0) ? 'selected' : '';
755							html += '<span class='+ selected +'>' + v + '</span>';
756						});	
757
758						$(this).closest('form').find('.popup_time_list_inner').html(html); 
759
760						$(this).closest('#product_select_date').find('input[name=time]').val(times[0]);
761					}
762					else if ($(this).closest('form').find('.popup_time_list_inner').length) {
763						$(this).closest('form').find('.popup_time_list_inner').html('');
764					}
765				}
766			});
767
768			if (div.length) div.data('daterangepicker').setStartDate(Object.keys(unique_dates)[0]);
769			div.trigger('apply.daterangepicker', div.data('daterangepicker'));
770			console.log('xxxx4', div.data('daterangepicker'));
771
772			div.on('show.daterangepicker', function(ev, picker){
773				var section_class = 'custom-info';
774
775				if(!picker.container.find('.'+section_class).length){
776					var html = '<div class="'+section_class+'">',
777							text_1 = '',
778							text_2 = '';
779
780					if($('html').attr('lang') == 'he-IL'){
781						text_1 = 'זמין לרכישה';
782						text_2 = 'רשימת המתנה';
783					}else{
784						text_1 = 'Available';
785						text_2 = 'Waiting list';
786					}
787
788					html+= '<div class="available"><span>'+text_1+'</span></div>';
789					html+= '<div class="waiting-list"><span>'+text_2+'</span></div>';
790
791					html+= '</div>';
792
793					picker.container.find('.calendar-table').after(html);
794				}
795			});
796
797			$(document).on('click', '.daterangepicker td.waiting-list', function(e){
798				var data = div.data('daterangepicker');
799
800				var popup = '#waiting-list-popup',
801						input = 'input#waiting-date';
802
803				if(data && $(popup).length && $(input).length){
804					var title = $(e.target).attr('data-title');
805				var row = title.substr(1, 1);
806				var col = title.substr(3, 1);
807				var cal = $(e.target).parents('.drp-calendar');
808				var timestamp = cal.hasClass('left') ? data.leftCalendar.calendar[row][col] : data.rightCalendar.calendar[row][col];
809				var date = moment(timestamp).format(format);
810
811				if($(input).val() != date){
812					$(input).val(date);
813					$(popup).find('form').attr('data-status', 'init').removeClass('sent');
814				}
815
816				$.fancybox.open({src: popup, type: 'inline'});
817					checkFormFields($(popup).find('form'));
818				}
819			});
820
821	  }
822
823	  function checkFormFields(form) {
824        const emailField = form.find('[name="your-email"]');
825        const acceptanceField = form.find('[name="your-acceptance"]');
826        const submitButton = form.find('.wpcf7-submit');
827
828        function validateFields() {
829        	console.log("Email: " + emailField.val());
830            if (emailField.val() !== '' && acceptanceField.is(':checked')) {
831            	console.log("allow");
832                submitButton.addClass('active');
833            } else {
834            	console.log("disallow");
835                submitButton.removeClass('active');
836            }
837        }
838
839        emailField.on('input', validateFields);
840        acceptanceField.on('change', validateFields);
841
842        validateFields();
843
844    }
845
846
847	  function add_to_cart_main(){
848			var div = $('.add_to_cart_date .init'),
849					is_rtl = $('body').hasClass('rtl'),
850					is_multiple = $(div).hasClass('multiple-select'),
851					format = 'DD.MM.YYYY',
852					available_dates = [];
853
854			function updateAccessibleDate(dateStr) {
855			    if (!dateStr) return;
856
857			    const parts = dateStr.split('.');
858			    if (parts.length !== 3) return;
859
860			    const dateObj = new Date(parts[2], parts[1] - 1, parts[0]);
861
862			    const formatter = new Intl.DateTimeFormat('he-IL', {
863			      weekday: 'long',
864			      day: 'numeric',
865			      month: 'long',
866			      year: 'numeric'
867			    });
868
869			    $('#selected-date-readable').text(
870			      formatter.format(dateObj)
871			    );
872			}
873			
874			if(typeof unique_dates !== 'undefined'){
875				available_dates = Object.keys(unique_dates);
876			}
877				
878			div.daterangepicker({
879				singleDatePicker: is_multiple ? false : true,
880				opens: is_rtl ? 'left' : 'right',
881				drops: 'up',
882				minDate: moment().startOf('hour'),
883				autoApply: true,
884				parentEl: '.add_to_cart_date',
885				isInvalidDate: function(el) {
886			    	var currDate = moment(el._d).format(format);
887				  	return available_dates.indexOf(currDate) == -1;
888				},
889				locale: {
890					direction: is_rtl ? 'rtl' : 'ltr',
891			        format: format,
892			        separator: " - ",
893			        applyLabel: "Apply",
894			        cancelLabel: "Cancel",
895			        fromLabel: "From",
896			        toLabel: "To",
897			        customRangeLabel: "Custom",
898			        daysOfWeek: is_rtl ? ["א","ב","ג","ד","ה","ו","ש"] : ['Su','Mo','Tu','We','Th','Fr','Sa'],
899			        monthNames: is_rtl ? ["ינו","פבר","מרץ","אפר","מאי","יונ","יול","אוג","ספט","אוק","נוב","דצמ"] : ["Jan","Feb","March","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]
900			      }
901			});
902
903			//updateAccessibleDate(div.val());
904			$('.drp-calendar.right').hide();
905		  	$('.drp-calendar.left').addClass('single');
906
907			div.trigger('click');
908			div.attr('aria-expanded', true);
909
910			div.on('apply.daterangepicker', function(ev, picker){
911				var format = 'DD.MM.YYYY';
912				if (! $('.add_to_cart_date .init').hasClass('multiple-select')) {
913					var new_date = picker.startDate.format(format);
914					//updateAccessibleDate(new_date);
915
916					if(typeof date_discounts !== 'undefined'){
917						$.each($('.price_table__body').find('.price_row'), function(k,v) {
918							var sku = $(v).attr('data-sku'),
919									regular_price = $(v).find('.column.quantity').data('display-regular-price'),
920									init_price = $(v).find('.column.quantity').data('display-init-price');
921
922							if(
923								sku in date_discounts 
924								&& new_date in date_discounts[sku]
925								&& Number(date_discounts[sku][new_date].price)
926							){
927							
928								var price = date_discounts[sku][new_date].price,
929									name = date_discounts[sku][new_date].name;
930
931								$(v).find('.column.name').text(name);
932
933								$(v).find('.column.quantity').attr('data-single-price', price);
934								$(v).find('.column.quantity').attr('data-price', price);
935								$(v).find('.column.quantity').attr('data-display-init-price', price);
936
937								if(regular_price > price){
938									//$(v).find('.column.price span').html('<span class="stritethrough">'+regular_price+'</span> '+price);
939									$(v).find('.column.price').html('&rlm;
939<span><span class="stritethrough">'+regular_price+'</span> '+price+'</span> ש"ח');
940								}else{
941									//$(v).find('.column.price span').html(price);
942									$(v).find('.column.price').html('&rlm;<span>'+regular_price+'</span> ש"ח');
943								}
944							}else{
945								$(v).find('.column.name').text($(v).find('.column.name').data('name'));
946								
947								$(v).find('.column.quantity').attr('data-single-price', init_price);
948								$(v).find('.column.quantity').attr('data-price', init_price);
949								$(v).find('.column.quantity').attr('data-display-init-price', init_price);
950
951								if(regular_price > init_price){
952									$(v).find('.column.price span').html('<span class="stritethrough">'+regular_price+'</span> '+init_price);
953								}else{
954									$(v).find('.column.price span').html(init_price);
955								}
956							}
957						});
958						jQuery('.qty').change();
959
960					}
961
962					div.attr('aria-expanded', false);
963
964				    $('form.variations_form input[name=selected_date]').val(new_date);
965				    $('.add-to-cart-sidebar .selected_date').text(new_date);
966
967				    if($('.add_to_cart_time').length && typeof unique_dates !== 'undefined'){
968						var times = unique_dates[new_date];
969
970						if (typeof times !== 'undefined') {
971							var html = '';
972							var selected_time = '';
973
974							$.each(times, function(k,v) {
975								var selected = (k == 0) ? ' selected' : '';
976								if (k == 0) selected_time = v;
977								html += '<option value="' + v + '"' + selected + '>' + v + '</option>';
978							});	
979
980							$('.add_to_cart_time').html(html);
981							$('form.variations_form input[name=selected_time]').val(selected_time);
982							$('.add-to-cart-sidebar .selected_time').text(selected_time);
983
984							$('#selected-time-readable').text('בחר שעה: ' + selected_time);
985
986							$('.add_to_cart_time').off('change').on('change', function () {
987							    $('#selected-time-readable').text('בחר שעה: ' + this.value);
988							});
989
990
991							update_max_tickets_for_single(new_date, selected_time);
992						}
993						else{
994							$('.add_to_cart_time').html('');
995						}
996					}
997					else update_max_tickets_for_single(new_date);
998				} 
999				else {
1000					if(typeof unique_dates !== 'undefined'){
1001						var selected_dates = $('.add_to_cart_date .init').val();
1002						var result = validate_multiple_dates(selected_dates, unique_dates);
1003
1004						var splitted_dates = selected_dates.split("-");
1005
1006						var date_ranges = getDates(jQuery.trim(splitted_dates[0]), jQuery.trim(splitted_dates[1]));
1007
1008						update_max_tickets_for_ranges(date_ranges);
1009
1010						if (result) alert(result);
1011						else {
1012							$('form.variations_form input[name=selected_date]').val(selected_dates);
1013							$('.add-to-cart-sidebar .selected_date').text(selected_dates);
1014							$.each($('.price_table__body').find('.price_row'), function(k,v) {
1015								$(v).attr('data-nights', (date_ranges.length - 1));
1016								$(v).find('.column.quantity').attr('data-price', $(v).find('.column.quantity').attr('data-single-price') * (date_ranges.length - 1));
1017								$(v).find('.column.price span').text($(v).find('.column.quantity').attr('data-single-price') * (date_ranges.length - 1));
1018							});
1019							jQuery('.qty').change();
1020						}
1021					}
1022				}
1023			});
1024
1025	  }
1026
1027	  function update_max_tickets_for_ranges(date_ranges) {
1028
1029			if(typeof available_tickets !== 'undefined'){
1030				
1031				var ii = 1;
1032				var max_tickets = 999;
1033
1034				$.each(date_ranges, function(k,v) {
1035					if (ii != date_ranges.length) {
1036						if (typeof available_tickets[v] != "undefined") {
1037							var new_max_tickets = available_tickets[v];
1038							if (new_max_tickets < max_tickets) max_tickets = new_max_tickets;
1039						}
1040
1041						ii++;
1042					}
1043				});
1044
1045				$.each($('.price_table__body p.quantity input.qty'), function(k,v) {
1046					$(v).attr('max', max_tickets);
1047					if (max_tickets > 0) $(v).val(1);
1048				});
1049
1050			}
1051
1052		}
1053
1054		function update_max_tickets_for_single(new_date, time = '') {
1055
1056			if(typeof available_tickets !== 'undefined'){
1057
1058				var max_tickets = 999;
1059				var new_date_and_time = (time) ? new_date + "-" + time : new_date;
1060
1061				if (typeof available_tickets[new_date_and_time] != "undefined") {
1062
1063					var new_max_tickets = available_tickets[new_date_and_time];
1064					if (new_max_tickets < max_tickets) max_tickets = new_max_tickets;
1065
1066				}
1067
1068				$.each($('.price_table__body input.qty'), function(k,v) {
1069					$(v).attr('max', max_tickets);
1070				});
1071
1072			}
1073
1074		}
1075
1076	  (function coupon_management(){
1077	  	var management = $('#coupon-management'),
1078	  			input = management.find('input'),
1079	  			button = management.find('button'),
1080	  			coupon_code = $('input#coupon_code');
1081
1082	  	var submit_coupon = function(){
1083	  		var $form = coupon_code.closest('form');
1084
1085			if($form.is('.processing')){
1086				return false;
1087			}
1088
1089			if(input.val() == ''){
1090				return false;					
1091			}
1092
1093			management.block({
1094		        message: null,
1095		        overlayCSS: {
1096		          	background: '#fff',
1097		          	opacity: 0.6
1098		        }
1099	      	});
1100
1101			// coupon_code.val(input.val());
1102			// $form.submit();
1103
1104			//$('#coupon-management button').html('<svg id="Big_arrow_button" data-name="Big arrow button" xmlns="http://www.w3.org/2000/svg" width="60" height="60" viewBox="0 0 60 60"><g id="Ellipse_11" data-name="Ellipse 11" fill="none" stroke="#535353" stroke-width="2"><circle cx="30" cy="30" r="30" stroke="none"></circle><circle cx="30" cy="30" r="29" fill="none"></circle></g><g id="Icon_feather-arrow-down" data-name="Icon feather-arrow-down" transform="translate(47.5 9.5) rotate(90)"><path id="Path_409" data-name="Path 409" d="M18,7.5v20" transform="translate(2.5)" fill="none" stroke="#535353" stroke-linejoin="round" stroke-width="2"></path><path id="Path_410" data-name="Path 410" d="M27.5,18l-10,10.5L7.5,18" transform="translate(3 -1)" fill="none" stroke="#535353" stroke-linejoin="round" stroke-width="2"></path></g></svg>');
1105			$('#coupon-management .copon-messsage').remove();
1106			$('#coupon-management').removeClass('error-coupon');
1107			$('#coupon-management').removeClass('success-coupon');
1108
1109			$.ajax({
1110		      	type: 'POST',
1111		      	dataType: 'html',
1112		      	url: '/wp-admin/admin-ajax.php',
1113		      	data: {
1114			        action: 'apply_coupon_code',
1115			        code: input.val()
1116			    },
1117		      	success: function(data){ 
1118		      		$('#coupon-management').unblock();
1119
1120		      		if ($(data).hasClass('woocommerce-error')) $('#coupon-management').addClass('error-coupon');
1121		      		else if ($(data).hasClass('woocommerce-message')) {
1122		      			$('#coupon-management').addClass('success-coupon').hide();
1123		      			// $('#coupon-management button').html('<svg id="Big_arrow_button" data-name="Big arrow button" xmlns="http://www.w3.org/2000/svg" width="60" height="60" viewB
1123ox="0 0 60 60"><circle id="Ellipse_11" data-name="Ellipse 11" cx="30" cy="30" r="30" fill="#f3f3f3"/><g id="Icon_feather-arrow-down" data-name="Icon feather-arrow-down" transform="translate(49 8.948) rotate(90)"><path id="Path_410" data-name="Path 410" d="M35,8.3,17.5,28.5,7.5,18" transform="translate(2.75 40.5) rotate(-90)" fill="none" stroke="#535353" stroke-linejoin="round" stroke-width="2"/></g></svg>');
1124		      		
1125		      			$.ajax({
1126					      	type: 'POST',
1127					      	dataType: 'html',
1128					      	url: '/wp-admin/admin-ajax.php',
1129					      	data: {
1130						        action: 'update_coupon_html'
1131						    },
1132						    success: function(data){
1133						    	console.log(data);
1134						    	if (data != '') {
1135							    	$('.checkout-coupon-discount').html(data);
1136							    	$('.cart-items').find('ul').addClass('coupon-applied');
1137							    } 
1138							    else {
1139							    	$('.checkout-coupon-discount').html(data);
1140							    	$('.cart-items').find('ul').removeClass('coupon-applied');
1141							    }
1142						    }
1143						});
1144		      		}
1145
1146		      		$('#coupon-management').append('<p class="copon-messsage">' + $(data).text() + '</p>');
1147
1148		        	jQuery(document.body).trigger('update_checkout');
1149		      	}
1150		    });
1151		};
1152
1153	  	button.on('click', function(){
1154				submit_coupon();
1155			});
1156
1157			input.on('keypress', function(e){
1158				if(e.which == 13){
1159					submit_coupon();
1160					return false;
1161				}
1162			});
1163
1164			$(document.body).on('applied_coupon_in_checkout', function(coupon_code){
1165				input.val('');
1166				input.trigger('blur');
1167				management.unblock();
1168
1169				//$.scroll_to_notices($('#checkout-main'));
1170			});
1171		})();
1172
1173		$('.cart-items').on('click', '.woocommerce-remove-coupon', function() {
1174			setTimeout(function() {
1175				$('.cart-items .checkout-coupon-discount').html('');
1176				$('.cart-items').find('ul').removeClass('coupon-applied');
1177				//$('#coupon-management').show();
1178			}, 500);
1179		});	
1180
1181
1182		(function edit_posted_data(){
1183			var $form = $('form.checkout#edit-data'),
1184					editing_btn = $('#editing-btn'),
1185					previev_data = $('#previev-data');
1186
1187			editing_btn.on('click', function(){
1188				if($(this).hasClass('active')){
1189					$(this).removeClass('active');
1190
1191					editing_btn.attr('aria-expanded' , 'false');
1192
1193					$form.stop().slideUp(400, function(){
1194						previev_data.stop().slideDown(200);
1195					});
1196				}else{
1197					$(this).addClass('active');
1198
1199					editing_btn.attr('aria-expanded' , 'true');
1200
1201					previev_data.stop().slideUp(200, function(){
1202						$form.stop().slideDown(400);
1203					});
1204				}
1205			});
1206
1207			var submit_message = function(error_message){
1208				$('.woocommerce-NoticeGroup-checkout, .woocommerce-error, .woocommerce-message').remove();
1209				$('form.checkout').prepend('<div class="woocommerce-NoticeGroup woocommerce-NoticeGroup-checkout">'+error_message+'</div>');
1210				$('form.checkout').removeClass('processing').unblock();
1211				$.scroll_to_notices($('form.checkout'));
1212			};
1213
1214			$form.off('submit').on('submit', function(){
1215				if($form.is('.processing')){
1216					return false;
1217				}
1218
1219				$form.addClass('processing');
1220				if($form.data('blockUI.isBlocked') !== 1){
1221					$form.block({
1222						message: null,
1223						overlayCSS: {
1224							background: '#fff',
1225							opacity: 0.6
1226						}
1227					});
1228				}
1229
1230				$.ajax({
1231		      type: 'POST',
1232		      dataType: 'json',
1233		      url: '/wp-admin/admin-ajax.php',
1234		      data: $form.serializeArray(),
1235		      success: function(result){      
1236		      	if('success' === result.result){
1237		      		$('.form-row').removeClass('woocommerce-validated');
1238		      		submit_message('<div class="woocommerce-message" role="alert">'+result.messages+'</div>');
1239
1240		      		if(result.previev){
1241		      			previev_data.html(result.previev);
1242		      		}
1243		      	}else if('failure' === result.result){
1244		      		if(result.messages){
1245								submit_message(result.messages);
1246							}else{
1247								submit_message('<div class="woocommerce-error">'+wc_checkout_params.i18n_checkout_error+'</div>');
1248							}
1249		      	}
1250		      	//console.log(result);
1251		      },
1252		      error: function(jqXHR, textStatus, errorThrown){
1253						submit_message('<div class="woocommerce-error">'+errorThrown+'</div>');
1254					}
1255		    }, 'json');
1256
1257		    return false;
1258			});
1259		})();
1260
1261
1262		(function get_discount(){
1263			var email_wrap = $('.get-discount .wpcf7-form-control-wrap.email'),
1264					placeholder = email_wrap.find('input').attr('placeholder');
1265
1266			email_wrap.append('<span class="placeholder">'+placeholder+'</span>').wrap('<label></label>');
1267		})();
1268
1269
1270		(function contact_us_form(){
1271			$('.contact-us .wpcf7-form-control-wrap').each(function(){
1272				var placeholder = $(this).find('.wpcf7-form-control').attr('placeholder');
1273				if(placeholder != undefined){
1274					$(this).append('<span class="placeholder">'+placeholder+'</span>').wrap('<label></label>');
1275				}				
1276			});
1277		})();
1278		
1279
1280		(function function_form(){
1281			$('.function-form .wpcf7-form-control-wrap').each(function(){
1282				var placeholder = $(this).find('.wpcf7-form-control').attr('placeholder');
1283				if(placeholder != undefined){
1284					$(this).append('<span class="placeholder">'+placeholder+'</span>').wrap('<label></label>');
1285				}				
1286			});
1287		})();
1288		
1289
1290		$('.open-addtoany').click(function(){
1291			var addtoany = $(this).parent().find('.addtoany_shortcode');
1292
1293			if(addtoany.hasClass('active')){
1294				addtoany.removeClass('active');
1295				addtoany.slideUp();
1296			}else{
1297				addtoany.addClass('active');
1298				addtoany.slideDown();
1299			}
1300			
1301			return false;
1302		});
1303
1304
1305		(function share_photo(){
1306			var li = $('#share-photo'),
1307					share = li.find('.post-share');
1308
1309			li.find('> a').click(function(){
1310				if(share.hasClass('active')){
1311					share.removeClass('active').slideUp(200);
1312				}else{
1313					share.addClass('active').slideDown(200);
1314				}
1315				return false;
1316			});
1317
1318			li.on('click', function(e){
1319				e.stopPropagation();
1320			});
1321
1322			$(document).on('click', function(){
1323				share.removeClass('active').slideUp(200);
1324			});	
1325		})();
1326
1327
1328		(function faq_section(){
1329			var form = $('#faq-form'),
1330					items = $('#faq-items');
1331
1332			form.on('submit', function(){ return false; });
1333			form.find('[name=search]').on('input', faq_render);
1334			form.find('[name=category], [name=order]').on('change', faq_render);
1335	
1336			function faq_render(){
1337				if(faq_items.length){
1338					var search = form.find('[name=search]').val(),
1339							category = form.find('[name=category]').val(),
1340							order = form.find('[name=order]').val(),
1341							found_items = [],
1342							html = '';
1343
1344					$.each(JSON.parse(JSON.stringify(faq_items)), function(key, row_item){
1345						if(category === '' || category == row_item.title){
1346							if(search){
1347								var found = row_item.items.filter(item => item.question.toLowerCase().includes(search.toLowerCase()));
1348							}else{
1349								var found = row_item.items;
1350							}
1351
1352							if(found.length){
1353								//sorting items
1354								if(order == 'ASC'){
1355									row_item.items = found.sort((a, b) => a.question.localeCompare(b.question));
1356								}else if(order == 'DESC'){
1357									row_item.items = found.sort((a, b) => b.question.localeCompare(a.question));
1358								}else{
1359									row_item.items = found;
1360								}
1361								
1362								found_items.push(row_item);
1363							}
1364						}
1365					});
1366
1367					if(found_items.length){
1368						//sorting rows
1369						if(order == 'ASC'){
1370							found_items.sort((a, b) => a.title.localeCompare(b.title));
1371						}else if(order == 'DESC'){
1372							found_items.sort((a, b) => b.title.localeCompare(a.title));
1373						}
1374
1375						$.each(found_items, function(key, items){
1376							html+= '<div class="row-item">';
1377								html+= '<img src="'+items.icon.url+'" alt="'+items.icon.alt+'" class="icon">';
1378								html+= '<h3>'+items.title+'</h3>';
1379								html+= '<div class="accordion">';
1380
1381								$.each(items.items, function(key, item){
1382									html+= '<div class="item">';
1383										html+= '<button type="button" class="title" role="button" tabindex="0" aria-expanded="false">'+item.question+'</button>';
1384										html+= '<div class="panel"><p>'+item.answer+'</p></div>';
1385									html+= '</div>';
1386								});
1387
1388								html+= '</div>';
1389							html+= '</div>';
1390						});
1391					}
1392
1393					items.html(html);
1394
1395					if(html){ items.next('.nothing-found').hide(); }
1396					else{ items.next('.nothing-found').show(); }
1397
1398					items.find('.accordion .title').on('click', function() {
1399						$(this).closest('.item').toggleClass('open');
1400						$(this).next().slideToggle();
1401
1402						if($(this).attr('aria-expanded') == 'true'){
1403							$(this).attr('aria-expanded', false);
1404						}else{
1405							$(this).attr('aria-expanded', true);
1406						}
1407					});
1408
1409					// console.log(found_items);
1410				}
1411			}
1412		})();
1413
1414
1415
1416
1417
1418
1419			
1420
1421
1422
1423		
1424		
1425
1426
1427
1428
1429		
1430
1431		// POST commands to YouTube or Vimeo API
1432		function postMessageToPlayer(player, command){
1433		  if (player == null || command == null) return;
1434		  player.contentWindow.postMessage(JSON.stringify(command), "*");
1435		}
1436
1437		// When the slide is changing
1438		function playPauseVideo(slick, control){
1439		  var currentSlide, player, video;
1440
1441		  currentSlide = slick.find(".slick-current");
1442		  player = currentSlide.find("iframe").get(0);
1443		  
1444	    switch (control) {
1445	      case "play":
1446	        postMessageToPlayer(player, {
1447	          "event": "command",
1448	          "func": "mute"
1449	        });
1450	        postMessageToPlayer(player, {
1451	          "event": "command",
1452	          "func": "playVideo"
1453	        });
1454	        break;
1455	      case "pause":
1456	        postMessageToPlayer(player, {
1457	          "event": "command",
1458	          "func": "pauseVideo"
1459	        });
1460	        break;
1461	    }
1462		}
1463
1464		// Resize player
1465		function resizePlayer(win){
1466			var iframes = win.find('iframe');
1467		  if (!iframes[0]) return;
1468
1469		  var width = win.width(),
1470		      playerWidth,
1471		      height = win.height(),
1472		      playerHeight,
1473		      ratio = 16/9;
1474
1475		  iframes.each(function(){
1476		    var current = $(this);
1477		    if (width / ratio < height) {
1478		      playerWidth = Math.ceil(height * ratio);
1479		      current.width(playerWidth).height(height).css({
1480		        left: (width - playerWidth) / 2,
1481		         top: 0
1482		        });
1483		    } else {
1484		      playerHeight = Math.ceil(width / ratio);
1485		      current.width(width).height(playerHeight).css({
1486		        left: 0,
1487		        top: (height - playerHeight) / 2
1488		      });
1489		    }
1490		  });
1491		}
1492
1493		function bindVideoEvents(slideWrapper) {
1494		  var lazyCounter = 0;
1495
1496		  slideWrapper.on("init", function(slick){
1497		    slick = $(slick.currentTarget);
1498		    setTimeout(function(){
1499		      playPauseVideo(slick,"play");
1500		    }, 1000);
1501		    resizePlayer(slideWrapper);
1502		  });
1503
1504		  slideWrapper.on("beforeChange", function(event, slick) {
1505		    slick = $(slick.$slider);
1506		    playPauseVideo(slick,"pause");
1507		  });
1508
1509		  slideWrapper.on("afterChange", function(event, slick) {
1510		    slick = $(slick.$slider);
1511		    playPauseVideo(slick,"play");
1512		  });
1513
1514		  slideWrapper.on("lazyLoaded", function(event, slick, image, imageSource) {
1515		    lazyCounter++;
1516		  });
1517		}
1518
1519		// DOM Ready
1520		$(function() {
1521		  	var bannerSlider = $('#banner-slider');
1522		  	var termSlider = $('#term-header-slider');
1523
1524		  	// Banner slider (you initialize here)
1525		  	bindVideoEvents(bannerSlider);
1526
1527		  	bannerSlider.slick({
1528			    dots: true,
1529			    arrows: false,
1530			    rtl: $('body').hasClass('rtl'),
1531			    fade: true,
1532			    slidesToShow: 1,
1533			    speed: 600,
1534			    lazyLoad: 'progressive'
1535		  	});
1536
1537		  	// Term slider (already initialized elsewhere)
1538		  	bindVideoEvents(termSlider);
1539
1540		  	termSlider.slick({
1541			  	dots: false,
1542			  	arrows: true,
1543			  	rtl: $('body').hasClass('rtl'),
1544			  	fade: true,
1545			  	slidesToShow: 1,
1546			  	speed: 600,
1547			  	lazyLoad: 'progressive',
1548			  	prevArrow: '<div class="slick-prev"></div>',
1549				nextArrow: '<div class="slick-next"></div>'
1550			});
1551
1552		  	// Resize for BOTH
1553		  	$(window).on("resize.slickVideoPlayer", function(){  
1554		    	resizePlayer(bannerSlider);
1555		    	resizePlayer(termSlider);
1556		  	});
1557		});
1558
1559
1560		//Ajax more articles
1561	  $('#articles-btn').on('click', function(){
1562	    var articles_btn = $(this),
1563	        articles_wrap = $('#articles-wrap'),
1564	        posts = [],
1565	        p_page = parseInt(articles_btn.attr('data-page')) + 1,
1566	        last_index = articles_wrap.find('.col-item').last().index();
1567
1568	    if(articles_btn.hasClass('loading')){
1569	    	return;
1570	    }
1571
1572	    articles_btn.addClass('loading');
1573
1574	    articles_wrap.find('> div').each(function(){
1575	      posts.push($(this).data('id'));
1576	    });
1577
1578	    $.ajax({
1579	      type: 'POST',
1580	      dataType: 'json',
1581	      url: '/wp-admin/admin-ajax.php',
1582	      data: {
1583	        action: 'more_articles',
1584	        page: p_page,
1585	        posts: posts
1586	      },
1587	      success: function(data){      
1588	        articles_wrap.append(data.html);
1589	        articles_wrap.find('.col-item:eq('+(last_index+1)+') h2 > a').focus();
1590	        
1591	        if(data.hide_btn){
1592	          articles_btn.hide();
1593	        }else{
1594	        	articles_btn.removeClass('loading');
1595	        	articles_btn.attr('data-page', p_page);
1596	        }
1597	      }
1598	    }, 'json');
1599	  });
1600
1601
1602	  $('.kids-category .section-btn').on('click', function(){
1603	    var btn = $(this),
1604	    		parent = btn.closest('.kids-category'),
1605	    		category = parent.data('category'),
1606	        wrap = parent.find('.row-items'),
1607	        posts = [];
1608
1609	    if(btn.hasClass('loading')){
1610	    	return;
1611	    }
1612
1613	    btn.addClass('loading');
1614
1615	    wrap.find('> div').each(function(){
1616	      posts.push($(this).data('id'));
1617	    });
1618
1619	    $.ajax({
1620	      type: 'POST',
1621	      dataType: 'json',
1622	      url: '/wp-admin/admin-ajax.php',
1623	      data: {
1624	        action: 'more_kids',
1625	        category: category,
1626	        posts: posts
1627	      },
1628	      success: function(data){      
1629	        wrap.append(data.html);
1630	        if(data.hide_btn){
1631	          btn.hide();
1632	        }else{
1633	        	btn.removeClass('loading');
1634	        }
1635	      }
1636	    }, 'json');
1637	  });
1638
1639
1640	  //https://wp-kama.ru/id_2818/masonry-vyivod-html-blokov-v-vide-kirpichnoy-kladki.html
1641		setTimeout(function(){
1642	    $('#photos-wrap').masonry({
1643			  //columnWidth: 200,
1644			  itemSelector: '.col-item',
1645			  isOriginLeft: false
1646			});
1647    }, 1000);
1648
1649
1650	  //Ajax more photos
1651	  $('#photos-btn').on('click', function(){
1652	    var photos_btn = $(this),
1653	        photos_wrap = $('#photos-wrap'),
1654	        posts = [];
1655
1656	    if(photos_btn.hasClass('loading')){
1657	    	return;
1658	    }
1659
1660	    photos_btn.addClass('loading');
1661
1662	    photos_wrap.find('> div').each(function(){
1663	      posts.push($(this).data('id'));
1664	    });
1665
1666	    $.ajax({
1667	      type: 'POST',
1668	      dataType: 'json',
1669	      url: '/wp-admin/admin-ajax.php',
1670	      data: {
1671	        action: 'more_photos',
1672	        posts: posts,
1673	        search: $.urlParam('search'),
1674	        category: $.urlParam('category'),
1675	        order: $.urlParam('order'),
1676	        tag: $.urlParam('tag')
1677	      },
1678	      success: function(data){      
1679	        photos_wrap.append(data.html);
1680
1681	        setTimeout(function(){
1682	        	photos_wrap.masonry('reloadItems').masonry('layout');
1683	        }, 1000);
1684
1685	        photos_wrap.parent().find('.section-title span').text(photos_wrap.find('> div').length);
1686
1687	        if(data.hide_btn){
1688	          photos_btn.hide();
1689	        }else{
1690	        	photos_btn.removeClass('loading');
1691	        }
1692	      }
1693	    }, 'json');
1694	  });
1695
1696	  $.urlParam = function(name){
1697	    var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href);
1698	    if (results==null) {
1699	      return null;
1700	    }
1701	    return decodeURI(results[1]) || '';
1702		}
1703
1704
1705		$('#movies-btn').on('click', function(){
1706	    var movies_btn = $(this),
1707	        movies_wrap = $('#movies-wrap');
1708
1709	    movies_btn.addClass('loading');
1710	    setTimeout(function(){
1711	    	movies_wrap.find('.hidden').removeClass('hidden');
1712	    	movies_btn.remove();
1713	    }, 500);
1714	  });
1715
1716
1717	  
1718	  $('.wpcf7-form').on('blur', '.wpcf7-validates-as-required', function() {
1719	  	if ($(this).val() == '') $(this).addClass('wpcf7-not-valid'); 	
1720	  	else $(this).removeClass('wpcf7-not-valid');
1721
1722			if ($(this).attr('type') == 'email') {
1723				var EmailRegex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;
1724
1725				if (!EmailRegex.test($(this).val())) $(this).addClass('wpcf7-not-valid'); 
1726				else $(this).removeClass('wpcf7-not-valid');
1727			}
1728
1729			if ($(this).attr('type') == 'tel') {
1730				var EmailRegex = /^(([0-9+-]){9,10})$/;
1731
1732				if (!EmailRegex.test($(this).val())) $(this).addClass('wpcf7-not-valid'); 
1733				else $(this).removeClass('wpcf7-not-valid');
1734			}
1735		});
1736
1737
1738		$('#header .col-cart-btn > a').click(function(){
1739		    if(!$(this).parent().hasClass('active')){
1740		        $(this).parent().addClass('active');
1741		        $(this).attr('aria-expanded', 'true');
1742		        return false;
1743		    }	
1744		});
1745
1746		// Close mini-cart when focus leaves
1747		$('#header .col-cart-btn').on('focusout', function(e) {
1748		    var $cartBtn = $(this);
1749		    setTimeout(function() {
1750		        if (!$cartBtn.find(':focus').length) {
1751		            $cartBtn.removeClass('active');
1752		            $cartBtn.find('> a').attr('aria-expanded', 'false');
1753		        }
1754		    }, 100);
1755		});
1756
1757		$(document).on('click', function(event) {
1758		    // Check if the clicked element is not inside an element with the class "col-cart-btn"
1759		    if (!$(event.target).closest('.col-cart-btn').length) {
1760		    	$('.col-cart-btn.active > a').attr('aria-expanded', 'false');
1761		        // Remove the "active" class from any element that has it
1762		        $('.col-cart-btn.active').removeClass('active');
1763		    }
1764		});
1765		$('#header').on('click', '.col-cart-btn .close_modal', function() {
1766	    	let cont = $(this).closest('#header');
1767	    	$(cont).find('.col-cart-btn > a').attr('aria-expanded', 'false');
1768	    	$(cont).find('.col-cart-btn').removeClass('active');
1769		});
1770
1771
1772
1773
1774	  /* Start accessibility scripts */
1775
1776
1777		$('#header .wpml-ls-item-toggle').attr({
1778			'role' : 'button',
1779			'aria-description' : 'בחר שפת אתר',
1780			'aria-expanded' : 'false'
1781		}).click(function(){
1782			var link = $(this),
1783					ul = link.next();
1784			setTimeout(function(){
1785				if(ul.css('visibility') == 'visible'){
1786					link.attr('aria-expanded', true);
1787				}else{
1788					link.attr('aria-expanded', false);
1789				}
1790			}, 100);
1791		});
1792
1793
1794		$('#header ul.menu li a').each(function(){
1795			if ($(this).parent().find('ul').length) {
1796				$(this).attr({
1797					'role' : 'button',
1798					'aria-expanded' : 'false'
1799				});
1800			}
1801		}).click(function(){
1802			var link = $(this),
1803					li = link.parent();
1804			setTimeout(function(){
1805				if(li.hasClass('active')){
1806					link.attr('aria-expanded', true);
1807				}else{
1808					link.attr('aria-expanded', false);
1809				}
1810			}, 100);
1811		});
1812		
1813
1814		$('.wpb_gallery').each(function(){
1815			setTimeout(() => {
1816				$(this).find('.flex-prev, .flex-next').attr({
1817					'tabindex' : '-1',
1818					'role' : 'presentation',
1819					'aria-hidden' : 'true'
1820				});
1821
1822				$(this).find('.flex-control-nav li a').attr({
1823					'role' : 'button',
1824					'aria-label' : 'לתמונה הבאה'
1825				});
1826			}, 1000);
1827		});
1828		/* End */
1829
1830
1831		// Add this function at the top of your script
1832		function announceToScreenReader(message) {
1833		    const announcement = document.getElementById('search-announcement');
1834		    if (announcement) {
1835		        announcement.textContent = message;
1836		        // Clear after a short delay to allow repeated announcements
1837		        setTimeout(() => {
1838		            announcement.textContent = '';
1839		        }, 1000);
1840		    }
1841		}
1842
1843		var substringMatcher = function(strs) {
1844		    return function findMatches(q, cb) {
1845		        var matches, substringRegex;
1846
1847		        matches = [];
1848		        substrRegex = new RegExp(q, 'i');
1849
1850		        $.each(strs, function(i, str) {
1851		            if (substrRegex.test(str)) {
1852		                matches.push(str);
1853		            }
1854		        });
1855
1856		        if (matches.length) {
1857		            $('.typeahead').attr('aria-expanded', 'true');
1858		        } else {
1859		            $('.typeahead').attr('aria-expanded', 'false');
1860		        }
1861
1862		        cb(matches);
1863		    };
1864		};
1865
1866		$('.typeahead').typeahead({
1867		    hint: true,
1868		    highlight: true,
1869		    minLength: 2
1870		},
1871		{
1872		    name: 'posts',
1873		    source: substringMatcher(search_auto_complete)
1874		});
1875
1876		// Track current selection state
1877		let currentSelectionIndex = -1;
1878		let totalResults = 0;
1879
1880		// Screen reader announcements for Typeahead events
1881		$('.typeahead').on('typeahead:close', function() {
1882		    $(this).attr('aria-expanded', 'false');
1883		    announceToScreenReader('חלון החיפוש נסגר');
1884		    currentSelectionIndex = -1;
1885		});
1886
1887		$('.typeahead').on('typeahead:open', function() {
1888		    var inputElement = $(this);
1889		    var query = inputElement.typeahead('val');
1890
1891		    var matches = search_auto_complete.filter(function(item) {
1892		        return item.toLowerCase().indexOf(query.toLowerCase()) !== -1;
1893		    });
1894
1895		    // if (matches.length) {
1896		    //     inputElement.attr('aria-expanded', 'true');
1897		    // } else {
1898		    //     inputElement.attr('aria-expanded', 'false');
1899		    // }
1900		});
1901
1902		$('.typeahead').on('typeahead:render', function(event, suggestions) {
1903		    totalResults = $('.tt-suggestion').length;
1904		    currentSelectionIndex = -1; // Reset selection when new results render
1905		    
1906		    // Announce number of results available
1907		    if (totalResults > 0) {
1908		        announceToScreenReader(totalResults + ' תוצאות זמינות, השתמשו בחצים למעלה ולמטה כדי לנווט');
1909		    } else {
1910		        announceToScreenReader('לא נמצאו תוצאות');
1911		    }
1912		    
1913		    // Set ARIA attributes for each suggestion
1914		    $('.tt-suggestion').each(function(index) {
1915		        var suggestionText = $(this).text();
1916		        $(this).attr('aria-label', suggestionText);
1917		        $(this).attr('aria-selected', 'false');
1918		        $(this).attr('role', 'option');
1919		        $(this).attr('tabindex', '-1');
1920		        $(this).attr('aria-posinset', (index + 1));
1921		        $(this).attr('aria-setsize', totalResults);
1922		        $(this).attr('data-index', index);
1923		    });
1924		});
1925
1926		// Listen for Typeahead's cursor change events
1927		$('.typeahead').on('typeahead:cursorchange', function(event, suggestion, dataset) {
1928		    // This event fires when Typeahead internally changes cursor position
1929		    const suggestions = $('.tt-suggestion');
1930		    const cursorIndex = suggestions.index($('.tt-cursor'));
1931		    
1932		    if (cursorIndex !== -1 && cursorIndex !== currentSelectionIndex) {
1933		        currentSelectionIndex = cursorIndex;
1934		        const currentSuggestion = suggestions.eq(currentSelectionIndex);
1935		        const cleanText = currentSuggestion.text().replace(/\s+/g, ' ').trim();
1936		        
1937		        // Update ARIA attributes
1938		        suggestions.attr('aria-selected', 'false');
1939		        currentSuggestion.attr('aria-selected', 'true');
1940		        
1941		        announceToScreenReader(cleanText + ' ' + (currentSelectionIndex + 1) + ' מתוך ' + totalResults);
1942		    }
1943		});
1944
1945		// Handle manual keyboard navigation that syncs with Typeahead
1946		$('.typeahead').on('keydown', function(e) {
1947		    const suggestions = $('.tt-suggestion');
1948		    totalResults = suggestions.length;
1949		    
1950		    if (totalResults === 0) return;
1951		    
1952		    if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {
1953		        e.preventDefault();
1954		        
1955		        // Let Typeahead handle the cursor movement first
1956		        // Then we'll detect the change in the cursorchange event
1957		        
1958		        // Force focus on the input to ensure Typeahead can handle the keypress
1959		        $(this).focus();
1960		    }
1961		});
1962
1963		// Alternative approach: Monitor for cursor changes using MutationObserver
1964		const observer = new MutationObserver(function(mutations) {
1965		    mutations.forEach(function(mutation) {
1966		        if (mutation.type === 'attributes' && mutation.attributeName === 'class') {
1967		            const target = $(mutation.target);
1968		            if (target.hasClass('tt-cursor') && target.hasClass('tt-suggestion')) {
1969		                const suggestions = $('.tt-suggestion');
1970		                const cursorIndex = suggestions.index(target);
1971		                
1972		                if (cursorIndex !== -1 && cursorIndex !== currentSelectionIndex) {
1973		                    currentSelectionIndex = cursorIndex;
1974		                    const cleanText = target.text().replace(/\s+/g, ' ').trim();
1975		                    
1976		                    // Update ARIA attributes
1977		                    suggestions.attr('aria-selected', 'false');
1978		                    target.attr('aria-selected', 'true');
1979		                    
1980		                    announceToScreenReader(cleanText + ' ' + (currentSelectionIndex + 1) + ' מתוך ' + totalResults);
1981		                }
1982		            }
1983		        }
1984		    });
1985		});
1986
1987		// Start observing when Typeahead menu is created
1988		$(document).on('DOMNodeInserted', '.tt-menu', function() {
1989		    const suggestions = $('.tt-suggestion');
1990		    suggestions.each(function() {
1991		        observer.observe(this, { attributes: true, attributeFilter: ['class'] });
1992		    });
1993		});
1994
1995		// Handle mouse hover for screen reader announcements
1996		$(document).on('mouseenter', '.tt-suggestion', function() {
1997		    const suggestions = $('.tt-suggestion');
1998		    totalResults = suggestions.length;
1999		    const hoverIndex = suggestions.index($(this));
2000		    const cleanText = $(this).text().replace(/\s+/g, ' ').trim();
2001		    
2002		    if (hoverIndex !== currentSelectionIndex) {
2003		        currentSelectionIndex = hoverIndex;
2004		        announceToScreenReader(cleanText + ' ' + (currentSelectionIndex + 1) + ' מתוך ' + totalResults);
2005		    }
2006		});
2007
2008		// Handle selection for screen reader announcement
2009		$('.typeahead').on('typeahead:select', function(event, suggestion) {
2010		    const cleanText = typeof suggestion === 'string' ? suggestion : suggestion.value;
2011		    announceToScreenReader('נבחר: ' + cleanText);
2012		    currentSelectionIndex = -1; // Reset after selection
2013		});
2014
2015		// Handle input changes to announce when no results
2016		$('.typeahead').on('input', function() {
2017		    const query = $(this).val();
2018		    if (query.length >= 2) {
2019		        setTimeout(() => {
2020		            const suggestions = $('.tt-suggestion');
2021		            if (suggestions.length === 0 && query.length > 0) {
2022		                announceToScreenReader('לא נמצאו תוצאות עבור ' + query);
2023		            }
2024		        }, 300);
2025		    }
2026		});
2027
2028		setTimeout(function() {
2029		    const $hint = $('.tt-hint');
2030
2031		    $hint.attr('aria-hidden', 'true')
2032		         .attr('tabindex', '-1')
2033		         .removeAttr('aria-label role aria-autocomplete aria-expanded')
2034		         .css('pointer-events', 'none')
2035		         .attr('readonly', 'readonly')
2036		         .attr('disabled', 'disabled');
2037
2038		    $hint.off('focus blur click');
2039		}, 1000);
2040		// .bind('typeahead:select', function(ev, suggestion){
2041		//   $(this).closest('form').submit();
2042		// });
2043
2044		// $(document).on('focusin', 'input.typeahead', function() {
2045	 //        // When an element with class 'rrrr' gains focus
2046	 //        $(this).attr('aria-expanded', 'true');
2047	 //    });
2048
2049	 //    $(document).on('focusout', 'input.typeahead', function() {
2050	 //        // When an element with class 'rrrr' loses focus
2051	 //        $(this).attr('aria-expanded', 'false');
2052	 //    });
2053
2054	    if ($('.wpml-ls-item-en .wpml-ls-link').length) {
2055	        $('.wpml-ls-item-en .wpml-ls-link').attr('aria-label', 'בחירת שפה אנגלית - מעבר לאתר באנגלית');
2056	    }
2057
2058
2059		$(window).on("load resize",function(e){
2060			var ww = $(this).width(),
2061					slider = $('#site-messages > div');
2062			if(ww < 768){
2063				if(!slider.hasClass('slick-slider')){
2064					slider.slick({
2065					  rtl: $('body').hasClass('rtl'),
2066					  infinite: false,
2067					  prevArrow: '<button type="button" class="slick-prev"></button>',
2068				  	nextArrow: '<button type="button" class="slick-next"></button>'
2069					});
2070				}
2071			}else{
2072				if(slider.hasClass('slick-slider')){
2073					slider.slick('unslick');
2074				}
2075			}
2076		});
2077
2078		$('.wpcf7 input[name="show-fields"]').on('change', function(){
2079			var row = $(this).closest('.wpcf7').find('.row-fields'),
2080					duration = 200;
2081
2082			if($(this).prop('checked')){
2083				row.slideDown(duration);
2084			}else{
2085				row.slideUp(duration);
2086			}
2087		});
2088
2089		$('.toggler-slider').on('click', function() {
2090			$(this).toggleClass('checked');
2091
2092			let name = $(this).attr('data-name');
2093			let value = ($(this).hasClass('checked')) ? "Yes" : "No";
2094			
2095			$("input[name="+name+"][value='"+value+"']").prop("checked",true);
2096			
2097		});
2098
2099		$('.toggle-btn-group').on('change', 'input', function() {
2100
2101			let name = $(this).closest('.toggle-btn-group').attr('data-name');
2102			let value = $(this).val();
2103			
2104			$("input[name="+name+"][value='"+value+"']").prop("checked",true);
2105			
2106		});	
2107
2108		setTimeout(function() {
2109			if ($('body').find('.slick-slider').length) {
2110				$('.slick-slider').each(function() {
2111
2112					if($(this).closest('section').hasClass('accommodation-products')){
2113						$(this).attr('role', 'region').attr('aria-label', "קרוסלת אפשרויות אירוח");
2114					}else{
2115						//$(this).find('.slick-slide').attr('role', 'region').attr('aria-label', "גלריית תמונות");
2116					}
2117					
2118				});
2119			}
2120		}, 2000);
2121
2122		jQuery('.wpcf7-submit').on('click',function(){
2123			setTimeout(function() {
2124		    	jQuery('.wpcf7-submit').attr("disabled","disabled"); // disable button after clicking on button	
2125		    }, 500);
2126		});
2127
2128		var wpcf7Elm = document.querySelector( '.wpcf7' );
2129		wpcf7Elm.addEventListener( 'wpcf7invalid', function( event ) {
2130			jQuery('.wpcf7-submit').removeAttr("disabled");
2131		}, false );
2132		wpcf7Elm.addEventListener( 'wpcf7spam', function( event ) {
2133			jQuery('.wpcf7-submit').removeAttr("disabled");
2134		}, false );
2135		wpcf7Elm.addEventListener( 'wpcf7mailfailed', function( event ) {
2136			jQuery('.wpcf7-submit').removeAttr("disabled");
2137		}, false );
2138
2139		if ($('body').hasClass('page-id-1226')) {
2140			setTimeout(function() {
2141				window.location.href = window.location.origin;
2142			}, 5000);
2143		}
2144
2145		function getCurrentDateForMask() {
2146		  	const today = new Date();
2147		  	const dd = String(today.getDate()).padStart(2, '0');
2148		  	const mm = String(today.getMonth() + 1).padStart(2, '0'); // January is 0!
2149		  	const yyyy = today.getFullYear();
2150
2151		  	return dd + '/' + mm + '/' + yyyy;
2152		}	
2153
2154		if ($('#date_mask').length) {
2155			$('#date_mask').inputmask({alias: "datetime", inputFormat: "dd/mm/yyyy", min: getCurrentDateForMask(), max: "31/12/2030"});
2156		}
2157
2158
2159		// Get the tallest slide height
2160		jQuery('body.home .slick-slider.activities-slider').each(function(k, slider) {
2161			var maxHeight = 0;
2162			jQuery(slider).find('.slick-slide').each(function(kk, item){
2163			//jQuery('body.home .slick-slider.activities-slider.slick-dotted .slick-slide').each(function(){
2164			    var slideHeight = jQuery(item).height();
2165			    maxHeight = (slideHeight > maxHeight) ? slideHeight : maxHeight;
2166			});
2167			  
2168			// Set the same height to all slides
2169			if (maxHeight && jQuery(slider).find('.slick-slide').length) {
2170				jQuery(slider).find('.slick-slide').height(maxHeight);
2171			}
2172		});
2173
2174		jQuery('.footer-subscription form .with-label-for-checkbox .wpcf7-list-item-label').on('click', function() {
2175			$(this).closest('.with-label-for-checkbox').find('label').click();
2176		});
2177
2178		if (jQuery('form .with-label-for-checkbox').length) {
2179
2180			jQuery('form .with-label-for-checkbox').each(function(index) {
2181				var for_el = $(this).find('label').attr('for');
2182				$(this).find('input').attr('id', for_el);
2183			});
2184
2185		}
2186
2187		$('body').on('keydown', '.skip-to-main-content-link', function(e) {
2188            if (e.key === 'Enter' || e.keyCode === 13) {
2189                var $firstH1 = $('h1').first();
2190                if ($firstH1.length) {
2191                    $firstH1.attr('tabindex', '-1').focus();
2192                    $firstH1.on('blur', function() {
2193                        $firstH1.removeAttr('tabindex');
2194                    });
2195                }
2196            }
2197        });
2198
2199        $("body").on('keydown', function(event) {
2200	        if (event.keyCode === 9 && $('body .product-reviews').length && !$('body .product-reviews').hasClass('open')) {
2201	        	$('body .product-reviews .open-t').click();
2202	        }
2203	    });
2204
2205
2206        function fixed_focus_modal(css_class) {
2207		    const modal = document.querySelector(css_class); 
2208			if (modal) {
2209				const focusableElements = 'button, [href]';
2210				const firstFocusableElement = modal.querySelectorAll(focusableElements)[0];
2211				const focusableContent = modal.querySelectorAll(focusableElements);
2212				const lastFocusableElement = focusableContent[focusableContent.length - 1];
2213
2214				document.addEventListener('keydown', function(e) {
2215				  let isTabPressed = e.key === 'Tab' || e.keyCode === 9;
2216
2217				  if (!isTabPressed) {
2218				    return;
2219				  }
2220
2221				  //console.log(document.activeElement, firstFocusableElement, lastFocusableElement );
2222
2223				  if (e.shiftKey) {
2224				    if (document.activeElement === firstFocusableElement) {
2225				      lastFocusableElement.focus();
2226				      e.preventDefault();
2227				    }
2228				  } else {
2229				    if (document.activeElement === lastFocusableElement) {
2230				      firstFocusableElement.focus();
2231				      e.preventDefault();
2232				    }
2233				  }
2234				});
2235
2236			}
2237		}
2238
2239		fixed_focus_modal('.popup_remove_products_from_cart');
2240
2241		$('#coupon-management-open span').on('click', function () {
2242	        $('#coupon-management-open').hide();
2243	        $('#coupon-management-block').fadeIn();
2244	    });
2245	    $('#coupon-management input[name="coupon_code"]').on('input', function () {
2246	        let button = $('#coupon-management button');
2247	        if ($(this).val().trim() !== '') {
2248	            button.addClass('active');
2249	            $('#coupon-management').removeClass('error-coupon');
2250	        } else {
2251	            button.removeClass('active');
2252	        }
2253	    });
2254
2255	    function checkFields() {
2256	        let allFilled = true;
2257	        console.log('checkbox');
2258
2259	        $('.checkout-modern #step-1 .checkout input').each(function () {
2260	        	let type = $(this).attr('type');
2261            	let name = $(this).attr('name');
2262
2263            	if (name === 'coupon_code') return;
2264
2265            	if (type === 'checkbox') {
2266	                if (!$(this).is(':checked')) {
2267	                    allFilled = false;
2268	                }
2269	            } else {
2270	                if ($(this).val().trim() === '') {
2271	                    allFilled = false;
2272	                }
2273	            }
2274	        });
2275
2276	        let button = $('.checkout-modern #step-1 .checkout #place_order');
2277	        if (allFilled) {
2278	            button.addClass('active');
2279	        } else {
2280	            button.removeClass('active');
2281	        }
2282	    }
2283	    $(document).on('input change', '.checkout-modern #step-1 .checkout input', checkFields);
2284
2285		// $('.jobs-lobby .job-item').on('click', function(event) {
2286	    //     if (!$(event.target).is('a')) {
2287	    //         $(this).find('a').first()[0].click();
2288	    //     }
2289	    // });
2290
2291	    $('img').hover(function() {
2292            var altText = $(this).attr('data-title');
2293            if (!$(this).attr('title') && altText) {
2294                $(this).attr('title', altText);
2295            }
2296        });
2297
2298	});
2299	var count = 0;
2300	$('img').each(function() {
2301        var title = $(this).attr('title');
2302        if (title) {
2303            $(this).attr('data-title', title);
2304            count++;
2305        }
2306    });
2307    console.log('Number of data-title attributes added: ' + count);
2308
2309    jQuery(document).ready(function($) {
2310	    // Target the Select2 dropdown (CF7 field: "participants")
2311	    $('.function-form select[name="participants"]').on('select2:select', function(e) {
2312	        var selectedValue = $(this).val();
2313	        var fieldLabel = 'כמות משתתפים'; // Default label
2314	        
2315	        // Update aria-label to include both label + selected value
2316	        $(this).next('.select2-container')
2317	               .find('.select2-selection__rendered')
2318	               .attr('aria-label', fieldLabel + ': ' + selectedValue);
2319	    });
2320	});
2321
2322	jQuery(document).ready(function($) {
2323	    // Only run if we're on page ID 112836
2324	    if ($('body.page-id-112836').length) {
2325	        // Handle keyboard navigation for Select2
2326	        $(document).on('keydown', '.select2-selection--single', function(e) {
2327	            // Check for Shift+Tab (backward navigation)
2328	            if (e.key === 'Tab' && e.shiftKey) {
2329	                // Close Select2 dropdown (if open)
2330	                $(this).closest('.select2-container').removeClass('select2-container--open');
2331	                
2332	                // Manually focus the previous input
2333	                const $select = $(this).closest('.select2-container').prev('select');
2334	                const $form = $select.closest('form');
2335	                const inputs = $form.find('input, select, textarea, button').not(':hidden');
2336	                const currentIndex = inputs.index($select);
2337	                
2338	                if (currentIndex > 0) {
2339	                    inputs.eq(currentIndex - 1).focus();
2340	                }
2341	                
2342	                return false; // Prevent default Tab behavior
2343	            }
2344	        });
2345	    }
2346	});
2347
2348	$('input[name="activity_time"]').prop('type', 'time');
2349	$('input[name="activity_time"]').on('input', function() {
2350	    let value = this.value.replace(/[^0-9:]/g, ''); // Remove non-digits/colons
2351	    
2352	    // Auto-insert colon after two digits
2353	    if (value.length > 2 && value.charAt(2) !== ':') {
2354	        value = value.substring(0, 2) + ':' + value.substring(2);
2355	    }
2356	    
2357	    // Limit to 5 characters (HH:MM)
2358	    value = value.substr(0, 5);
2359	    
2360	    // Split into hours and minutes
2361	    const parts = value.split(':');
2362	    let hours = parts[0];
2363	    let minutes = parts[1] || '';
2364	    
2365	    // Validate and correct hours
2366	    if (hours.length === 1 && hours > 2) {
2367	        hours = '0' + hours; // Add leading zero for hours 3-9
2368	    } else if (hours.length === 2) {
2369	        if (hours > 23) {
2370	            hours = '23'; // Cap hours at 23
2371	        } else if (hours < 10) {
2372	            hours = '0' + parseInt(hours, 10); // Ensure two-digit format
2373	        }
2374	    }
2375	    
2376	    // Validate and correct minutes
2377	    if (minutes.length > 0) {
2378	        if (minutes > 59) {
2379	            minutes = '59'; // Cap minutes at 59
2380	        } else if (minutes.length === 1 && minutes > 5) {
2381	            minutes = '0' + minutes; // Add leading zero for minutes 6-9
2382	        }
2383	    }
2384	    
2385	    // Rebuild the value
2386	    if (minutes.length > 0) {
2387	        this.value = hours + ':' + minutes;
2388	    } else if (hours.length === 2 && value.length > 2) {
2389	        this.value = hours + ':';
2390	    } else {
2391	        this.value = hours;
2392	    }
2393
2394	    $(this).attr('aria-label', 'השעה היא ' + $(this).val());
2395	});
2396
2397	// Additional validation on blur to ensure complete time
2398	$('input[name="activity_time"]').on('blur', function() {
2399	    const timeRegex = /^([0-1][0-9]|2[0-3]):([0-5][0-9])$/;
2400	    if (this.value && !timeRegex.test(this.value)) {
2401	        // If invalid time, clear the input or show error
2402	        alert('Please enter a valid time in HH:MM format (e.g., 09:30)');
2403	        this.value = '';
2404	        this.focus();
2405	    }
2406	});
2407
2408	// Initialize sliders based on item count
2409    function initSliders2() {
2410    	console.log('-----init sliders----');
2411    	// Remove any existing Slick initializations
2412        if ($('.events_content_slider').hasClass('slick-initialized')) {
2413            $('.events_content_slider').slick('unslick');
2414        }
2415
2416        $('.events_content_slider').each(function() {
2417            var $slider = $(this);
2418            var itemCount = $slider.children().length;
2419
2420            if (itemCount >= 4) itemCount = 4;
2421            
2422            // Add class based on item count
2423            $slider.removeClass('items-1 items-2 items-3 items-4');
2424            $slider.addClass('items-' + itemCount);
2425            
2426            // Initialize Slick slider only when needed
2427            if (itemCount >= 4 || window.innerWidth <= 768) {
2428                var slidesToShow = 3;
2429                
2430                if (window.innerWidth <= 1024) {
2431                    slidesToShow = 2;
2432                }
2433                
2434                if (window.innerWidth <= 768) {
2435                    slidesToShow = 1;
2436                }
2437                
2438                // For 1-3 items, only initialize slider on mobile
2439                if (itemCount <= 3 && window.innerWidth > 768) {
2440                    return;
2441                }
2442                
2443                $slider.slick({
2444                    dots: false,
2445                    arrows: true,
2446                    rtl: $('body').hasClass('rtl'),
2447                    prevArrow: '<button type="button" class="slick-prev" aria-label="הקודם">‹</button>',
2448                    nextArrow: '<button type="button" class="slick-next" aria-label="שקופית הבאה">›</button>',
2449                    infinite: false,
2450                    slidesToShow: slidesToShow,
2451                    slidesToScroll: 1,
2452                    responsive: [
2453                        {
2454                            breakpoint: 1024,
2455                            settings: {
2456                                slidesToShow: 2,
2457                                slidesToScroll: 1
2458                            }
2459                        },
2460                        {
2461                            breakpoint: 768,
2462                            settings: {
2463                                slidesToShow: 1,
2464                                slidesToScroll: 1
2465                            }
2466                        }
2467                    ]
2468                });
2469            }
2470        });
2471    }
2472    
2473    // Initialize on page load
2474    initSliders2();
2475    
2476    // Reinitialize on window resize
2477    $(window).on('resize', function() {
2478        initSliders2();
2479    });
2480
2481    $('.benefits-new-slider').slick({
2482        dots: false,
2483        arrows: true,
2484        rtl: $('body').hasClass('rtl'),
2485        prevArrow: '<button type="button" class="slick-prev" aria-label="הקודם">‹</button>',
2486        nextArrow: '<button type="button" class="slick-next" aria-label="שקופית הבאה">›</button>',
2487        infinite: false,
2488        slidesToShow: 4,
2489        slidesToScroll: 1,
2490        responsive: [
2491            {
2492                breakpoint: 1024,
2493                settings: {
2494                    slidesToShow: 3,
2495                    slidesToScroll: 1
2496                }
2497            },
2498            {
2499                breakpoint: 768,
2500                settings: {
2501                    slidesToShow: 2,
2502                    slidesToScroll: 1
2503                }
2504            },
2505            {
2506                breakpoint: 520,
2507                settings: {
2508                    slidesToShow: 1,
2509                    slidesToScroll: 1
2510                }
2511            }
2512
2513        ]
2514    });
2515
2516    // Add click event to all filter links
2517    $('.event-gallery-filters a').click(function(e) {
2518        e.preventDefault();
2519        
2520        // Get the slug from data attribute
2521        var filterSlug = $(this).data('slug');
2522        
2523        // Remove selected class from all links
2524        $('.event-gallery-filters a').removeClass('selected');
2525        
2526        // Add selected class to clicked link
2527        $(this).addClass('selected');
2528        
2529        // Filter the items
2530        if (filterSlug === 'all') {
2531            // Show all items
2532            $('.event-gallery-new-item').fadeIn(300);
2533        } else {
2534            // Hide all items first
2535            $('.event-gallery-new-item').hide();
2536            
2537            // Show items that contain the selected category in their data-cat attribute
2538            $('.event-gallery-new-item').each(function() {
2539                var itemCategories = $(this).data('cat').split(',');
2540                if (itemCategories.indexOf(filterSlug) !== -1) {
2541                    $(this).fadeIn(300);
2542                }
2543            });
2544        }
2545    });
2546
2547    // Close all submenus
2548    function closeAllSubmenus() {
2549        $('.menu-item-has-children').each(function() {
2550            const $link = $(this).find('a[role="button"]');
2551            $link.attr('aria-expanded', 'false');
2552            $(this).removeClass('active');
2553        });
2554    }
2555    
2556    // Close specific submenu
2557    function closeSubmenu($menuItem) {
2558        const $link = $menuItem.find('a[role="button"]');
2559        $link.attr('aria-expanded', 'false');
2560        $menuItem.removeClass('active');
2561    }
2562    
2563    // Open submenu
2564    function openSubmenu($menuItem) {
2565        closeAllSubmenus();
2566        const $link = $menuItem.find('a[role="button"]');
2567        $link.attr('aria-expanded', 'true');
2568        $menuItem.removeClass('active');
2569    }
2570    
2571    // Click event for menu items
2572    $('.menu-item-has-children').each(function() {
2573        const $menuItem = $(this);
2574        const $link = $menuItem.find('a[role="button"]');
2575        const $submenu = $menuItem.find('.sub-menu');
2576        
2577        if ($link.length && $submenu.length) {
2578            // Click handler
2579            $link.on('click', function(e) {
2580                e.preventDefault();
2581                const isExpanded = $(this).attr('aria-expanded') === 'true';
2582                
2583                if (isExpanded) {
2584                    closeSubmenu($menuItem);
2585                } else {
2586                    openSubmenu($menuItem);
2587                }
2588            });
2589            
2590            // Keydown handler
2591            $link.on('keydown', function(e) {
2592                if (e.key === 'Enter' || e.key === ' ') {
2593                    e.preventDefault();
2594                    const isExpanded = $(this).attr('aria-expanded') === 'true';
2595                    
2596                    if (isExpanded) {
2597                        closeSubmenu($menuItem);
2598                    } else {
2599                        openSubmenu($menuItem);
2600                    }
2601                } else if (e.key === 'Escape') {
2602                    closeSubmenu($menuItem);
2603                    $(this).focus();
2604                } else if (e.key === 'ArrowDown' && $(this).attr('aria-expanded') === 'true') {
2605                    e.preventDefault();
2606                    const $firstSubmenuItem = $submenu.find('a').first();
2607                    if ($firstSubmenuItem.length) {
2608                        $firstSubmenuItem.focus();
2609                    }
2610                }
2611            });
2612        }
2613    });
2614    
2615    // Submenu item events
2616    $('.sub-menu a').on('keydown', function(e) {
2617        if (e.key === 'Escape') {
2618            e.preventDefault();
2619            const $parentMenuItem = $(this).closest('.menu-item-has-children');
2620            closeSubmenu($parentMenuItem);
2621            $parentMenuItem.find('a[role="button"]').focus();
2622        }
2623    });
2624    
2625    // Focusout event
2626    $('.menu-item-has-children').on('focusout', function(e) {
2627        const $menuItem = $(this);
2628        setTimeout(() => {
2629            if (!$menuItem.has(document.activeElement).length) {
2630                closeSubmenu($menuItem);
2631            }
2632        }, 10);
2633    });
2634    
2635    // Click outside to close
2636    $(document).on('click', function(e) {
2637        if (!$(e.target).closest('.menu-item-has-children').length) {
2638            closeAllSubmenus();
2639        }
2640    });
2641    
2642    // Submenu keyboard navigation
2643    $('.sub-menu').each(function() {
2644        const $submenuItems = $(this).find('a');
2645        
2646        $submenuItems.on('keydown', function(e) {
2647            const $current = $(this);
2648            const currentIndex = $submenuItems.index($current);
2649            
2650            if (e.key === 'ArrowDown') {
2651                e.preventDefault();
2652                const nextIndex = (currentIndex + 1) % $submenuItems.length;
2653                $submenuItems.eq(nextIndex).focus();
2654            } else if (e.key === 'ArrowUp') {
2655                e.preventDefault();
2656                const prevIndex = (currentIndex - 1 + $submenuItems.length) % $submenuItems.length;
2657                $submenuItems.eq(prevIndex).focus();
2658                
2659                if (prevIndex === $submenuItems.length - 1) {
2660                    const $parentLink = $(this).closest('.menu-item-has-children').find('a[role="button"]');
2661                    $parentLink.focus();
2662                }
2663            }
2664        });
2665    });
2666
2667    $('#menu-footer > li > a').each(function() {
2668        const $link = $(this);
2669        const linkText = $link.text();
2670        const linkHref = $link.attr('href');
2671        
2672        $link.wrap('<h5></h5>').parent().prepend($link);
2673    });
2674
2675    $('.footer-subscription input[name="checkbox-435"]')
2676        .attr('aria-label', 'מאשר/ת קבלת המייל, תיבת סימון')
2677        .attr('role', 'checkbox');
2678
2679    setTimeout(() => {
2680        const $contactButton = $('.cb-pre-button');
2681    
2682	    if ($contactButton.length) {
2683	        $contactButton.attr('aria-expanded', 'false');
2684	    }
2685    }, 1000);
2686
2687    setTimeout(function() {
2688        const $tabList = $('#divWrappersupportedStreams_ifrContactUs');
2689        
2690        if ($tabList.length) {
2691        	console.log('--------------In--------------');
2692            // Remove tablist role and attributes
2693            $tabList.removeAttr('role');
2694            
2695            // Process each "tab" item
2696            $tabList.find('.divModuleImg').each(function() {
2697                const $module = $(this);
2698                const $button = $module.find('.cb_contact_us_module_btn');
2699                const moduleId = $button.data('module-id');
2700                const ariaLabel = $button.attr('aria-label');
2701                
2702                // Check if it's WhatsApp (module-id 13) or Chat (module-id 9)
2703                if (moduleId === 13) {
2704                    // Convert WhatsApp to a regular link
2705                    const $link = $('<a>', {
2706                        'href': 'https://wa.me/972528073666', // You might want to add actual WhatsApp link here
2707                        'class': 'cb_contact_us_module_link',
2708                        'aria-label': ariaLabel,
2709                        'target': '_blank',
2710                        'rel': 'noopener noreferrer',
2711                        'html': $button.html()
2712                    });
2713                    
2714                    $button.replaceWith($link);
2715                    
2716                } else if (moduleId === 9) {
2717                    // Convert Chat to a regular button
2718                    $button.removeAttr('role aria-controls aria-selected tabindex');
2719                    $button.attr('type', 'button');
2720                    
2721                }
2722            });
2723            
2724            console.log('Commbox tabs converted to regular buttons/links');
2725        }
2726    }, 2000);
2727
2728    // Simple and effective solution
2729	function hideRecaptcha() {
2730	    const badges = document.querySelectorAll('.grecaptcha-badge');
2731	    badges.forEach(badge => {
2732	        badge.setAttribute('aria-hidden', 'true');
2733	    });
2734	}
2735
2736	// Run multiple times to ensure it catches the reCAPTCHA
2737	[0, 100, 500, 1000, 2000, 5000].forEach(timeout => {
2738	    setTimeout(hideRecaptcha, timeout);
2739	});
2740
2741	if (jQuery('.p-desc').length) {
2742		toggleMoreButtonVisibility();
2743	}
2744	
2745
2746  jQuery('.desc-more-btn').on('click', function () {
2747      let block = jQuery(this).closest('.p-desc');
2748      block.toggleClass('expanded');
2749
2750      jQuery(this).find('.text').text(
2751          block.hasClass('expanded')
2752		        ? themeTexts.less
2753		        : themeTexts.more
2754      );
2755
2756      let jQuerydescInner = block.find('.desc-inner');
2757      if (block.hasClass('expanded')) {
2758          jQuerydescInner.css('max-height', 'auto');
2759          jQuerydescInner.css('-webkit-line-clamp', 'unset');
2760          jQuerydescInner.css('overflow', 'visible');
2761      } else {
2762          jQuerydescInner.css('max-height', '...');
2763          jQuerydescInner.css('-webkit-line-clamp', '3'); 
2764          jQuerydescInner.css('overflow', 'hidden');
2765      }
2766  });
2767
2768    function initMobileOrderSummary() {
2769
2770        var $cartItems = $('.cart-items');
2771
2772        if (!$cartItems.length) {
2773            return;
2774        }
2775
2776        /*
2777         * Add accordion toggle only once
2778         */
2779        if (!$cartItems.find('.mobile-order-summary-toggle').length) {
2780
2781            var $heading = $cartItems.children('h2').first();
2782
2783            if ($heading.length) {
2784
2785                $heading.html(
2786                    '<button type="button" ' +
2787                        'class="mobile-order-summary-toggle" ' +
2788                        'aria-expanded="false" ' +
2789                        'aria-controls="mobile-order-summary-content">' +
2790                            '<span>ההזמנה שלי</span>' +
2791                            '<span class="order-summary-arrow" aria-hidden="true"></span>' +
2792                    '</button>'
2793                );
2794
2795            }
2796        }
2797
2798
2799        /*
2800         * Add ID to order summary content for accessibility.
2801         * The UL is the beginning of the accordion content.
2802         */
2803        $cartItems.children('ul').first()
2804            .attr('id', 'mobile-order-summary-content');
2805
2806
2807        /*
2808         * Add mobile Continue button after order summary.
2809         * We do NOT move WooCommerce #place_order because WooCommerce
2810         * can replace the payment HTML via AJAX.
2811         */
2812        if (!$('.mobile-checkout-continue').length) {
2813
2814            $cartItems.after(
2815                '<div class="mobile-checkout-continue">' +
2816                    '<button type="button" class="button alt">' +
2817                        'המשך' +
2818                    '</button>' +
2819                '</div>'
2820            );
2821
2822        }
2823    }
2824
2825
2826    /*
2827     * Open / close order summary
2828     */
2829    $(document).on('click', '.mobile-order-summary-toggle', function() {
2830
2831        var $button = $(this);
2832        var $cartItems = $button.closest('.cart-items');
2833
2834        var isOpen = $cartItems.hasClass('mobile-order-summary-open');
2835
2836        $cartItems.toggleClass(
2837            'mobile-order-summary-open',
2838            !isOpen
2839        );
2840
2841        $button.attr(
2842            'aria-expanded',
2843            !isOpen ? 'true' : 'false'
2844        );
2845
2846    });
2847
2848
2849    /*
2850     * Mobile Continue button triggers the real WooCommerce checkout button.
2851     */
2852    $(document).on('click', '.mobile-checkout-continue button', function(e) {
2853
2854        e.preventDefault();
2855
2856        var $placeOrder = $('#place_order');
2857
2858        if ($placeOrder.length) {
2859            $placeOrder.trigger('click');
2860        }
2861
2862    });
2863
2864
2865    /*
2866     * Initial load
2867     */
2868    initMobileOrderSummary();
2869
2870
2871    /*
2872     * WooCommerce rebuilds parts of checkout after AJAX updates.
2873     * Recheck our component afterwards.
2874     */
2875    $(document.body).on('updated_checkout', function() {
2876        initMobileOrderSummary();
2877    });
2878
2879
2880})(jQuery);
2881// jQuery(window).on('resize', function() {
2882//     if (jQuery('.p-desc').length) {
2883// 			toggleMoreButtonVisibility();
2884// 		}
2885// });
2886function toggleMoreButtonVisibility() {
2887  jQuery('.p-desc').each(function() {
2888      let jQueryblock = jQuery(this);
2889      let jQuerydescInner = jQueryblock.find('.desc-inner');
2890      let jQuerybutton = jQueryblock.find('.desc-more-btn');
2891
2892      jQuerydescInner.css({
2893          'display': 'block',
2894          '-webkit-line-clamp': 'unset', 
2895          'overflow': 'visible' 
2896      });
2897
2898      const fullHeight = jQuerydescInner.get(0).scrollHeight;
2899      
2900      jQuerydescInner.css({
2901          'display': '-webkit-box', 
2902          '-webkit-line-clamp': '3', 
2903          'overflow': 'hidden',
2904          'max-height': 'auto' 
2905      });
2906
2907      const restrictedHeight = jQuerydescInner.get(0).offsetHeight;
2908
2909      if (fullHeight > restrictedHeight) {
2910          jQuerybutton.show();
2911      } else {
2912          jQuerybutton.hide();
2913      }
2914  });
2915}
2916
2917// Accessibility 
2918if (jQuery('.styled-select').length) {
2919    jQuery(document).on('keydown', '.select2-selection', function(e) {
2920        if (e.shiftKey && e.keyCode === 9) {
2921            e.stopImmediatePropagation();
2922            e.preventDefault();
2923            
2924            // Search in active step first, then fallback to form
2925            var $container = jQuery(this).closest('.mo-form-step.active');
2926            if (!$container.length) {
2927                $container = jQuery(this).closest('form');
2928            }
2929            
2930            var $focusable = $container.find('input, button, .select2-selection[tabindex="0"]').filter(':visible');
2931            var $current = jQuery(this);
2932            var currentIndex = $focusable.index($current);
2933            
2934            if (currentIndex > 0) {
2935                $focusable.eq(currentIndex - 1).focus();
2936            }
2937        }
2938    });
2939}
2940if (jQuery('.area-item').length) {
2941	jQuery('.area-item').on('focusin', function() {
2942	    jQuery(this).find('.ai-button').attr('tabindex', '0');
2943	}).on('focusout', function(e) {
2944	    if (!jQuery(this).has(e.relatedTarget).length) {
2945	        jQuery(this).find('.ai-button').attr('tabindex', '-1');
2946	    }
2947	});
2948}
2949if (jQuery('.sites-anchor-links a').length) {
2950document.querySelectorAll('.sites-anchor-links a').forEach(function(link) {
2951  link.addEventListener('click', function(e) {
2952    var targetId = this.getAttribute('href');
2953    var target = document.querySelector(targetId);
2954    if (target) {
2955      if (!target.getAttribute('tabindex')) {
2956        target.setAttribute('tabindex', '-1');
2957      }
2958      target.focus();
2959    }
2960  });
2961});
2962}

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.