PageSourceSearch

https://ncsymphony.org/wp-content/themes/hello-theme-child-master/calendar/mini-event-calendar.js

js ncsymphony.org collected 2026-10-01 11:28:44 UTC 13,590 bytes, 483 lines download raw bytes

1(function( $ ) {
2	var calenderTpl = `
3		<div id="calTitle">
4			
5			<div id="monthYear"></div>
6			
7			<button type="button" class="month-mover next">
8				<svg fill="#FFFFFF" height="30" viewBox="0 0 24 24" width="30" xmlns="http://www.w3.org/2000/svg">
9					<path d="M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"/>
10				</svg>
11			</button>
12			<button type="button" class="month-mover prev">
13				<svg fill="#FFFFFF" height="30" viewBox="0 0 24 24" width="30" xmlns="http://www.w3.org/2000/svg">
14					<path d="M15.41 7.41L14 6l-6 6 6 6 1.41-1.41L10.83 12z"/>
15				</svg>
16			</button>
17			
18		</div>
19		<div>
20			<div id="calThead"></div>
21			<div id="calTbody"></div>
22		</div>
23		
24	`;
25	var weekDaysFromSunday = '<div>SUN</div><div>MON</div><div>TUE</div><div>WED</div><div>THU</div><div>FRI</div><div>SAT</div>';
26	var weekDaysFromMonday = '<div>MON</div><div>TUE</div><div>WED</div><div>THU</div><div>FRI</div><div>SAT</div><div>SUN</div>';
27	var shortMonths = ["January", "February", "March", "April", "May", "June", "July","August", "September", "October", "
27November", "December"];
28
29    $.fn.miniEventCalendar = $.fn.MEC = function(options) {
30    	var settings = $.extend({
31			calendar_link : "",
32    		events: [],
33			from_monday: false,
34			onMonthChanged: null
35        }, options );
36
37		//console.log(settings);
38
39		var miniCalendar = this;
40
41        miniCalendar.addClass('mini-cal').html(calenderTpl);
42
43		var thead = miniCalendar.find("#calThead");
44		var tbody = miniCalendar.find("#calTbody");
45		var calTitle = miniCalendar.find("#monthYear");
46		var calFooter = miniCalendar.find("#calTFooter");
47        var eventTitle = miniCalendar.find("#eventTitle");
48		var eventsLink = miniCalendar.find("#calLink");
49
50		var today = new Date();
51		
52		const cmonth = sessionStorage.getItem('curMonth');
53		const cyear = sessionStorage.getItem('curYear');
54
55		var fresh = 0;
56		var hdcMonth = jQuery('input[name=cMonth]').val();
57		//console.log(hdcMonth);
58
59
60
61		var hdcYear = jQuery('input[name=cYear]').val();
62		
63		if( cyear ){
64				var curYear = parseInt(cyear);
65		}else{
66			if(hdcYear){
67				var curYear = parseInt(hdcYear);
68			}else{
69				//var curYear = today.getFullYear();
70                var monthYear = $("input[name='monthYear']").val();
71
72                    if(monthYear){
73                        var parts = monthYear.split('-');
74						var curYear = parts[1];
75                    }else{
76                    	var curYear = today.getFullYear();
77                    }
78
79
80				fresh = 1;
81			}
82		}
83		
84
85
86		if( cmonth ){
87			//console.log("from SESSIONSTORAGE");
88				var curMonth = parseInt(cmonth);
89		}else{
90			if(hdcMonth){
91				//console.log("xfrom $_get");
92				var curMonth = parseInt(hdcMonth);
93			}else{
94				//console.log("from RAW");
95				var curMonth = today.getMonth();
96
97				//var curMonthYear = (curMonth + 1)+"-"+curYear;
98				//alert(curMonthYear);
99
100                /*getNextEventMonth(curMonthYear, function(result){
101                    monthYear = result;
102					$("input[name='ajaxMonth']").val(monthYear);
103                });
104                (async function(){
105
106                    let mY = await loadMonth(curMonthYear);
107
108                    //console.log("Outside value:", mY);
109
110                })();
111
112				//var mY = $("input[name='ajaxMonth']").val();
113                alert(mY);
114                    if(mY){
115                        var parts = mY.split('-');
116                        var curMonth = (parseInt(parts[0], 10) - 1);
117
118                    }else{
119                    	var curMonth = today.getMonth();
120                    }
121                    */
122                    
123
124
125				fresh = 1;
126			}
127		}
128
129		
130
131
132		
133
134
135        eventTitle.text("No events today.");
136		eventsLink.text("ALL EVENTS");
137		eventsLink.attr("href", settings.calendar_link);
138
139		if(settings.from_monday)
140			thead.html(weekDaysFromMonday);
141		else
142			thead.html(weekDaysFromSunday);
143
144		if(!settings.calendar_link.length && !settings.events.length)
145			calFooter.css("display", "none");
146
147		miniCalendar.find(".month-mover").each(function(){
148			var mover = $(this);
149			mover.bind("click", function(e){
150				e.preventDefault();
151				
152				if(mover.hasClass("next"))
153					viewNextMonth();
154				else
155					viewPrevMonth();
156			});
157		});
158
159		// miniCalendar.on("click touchstart", ".a-date", function(e){
160		// 	e.preventDefault(); 
161		// 	$(".a-date").removeClass('focused');
162		//     if(!$(this).hasClass('blurred')){
163		// 		showEvent($(this).data('event'));
164		// 		$(this).focus();
165		// 		$(this).addClass('focused');
166		// 	}
167		// });
168
169		function populateCalendar(month, year, onInit) {
170			tbody.html("");
171			calTitle.text(shortMonths[month] + " " + year);
172			eventTitle.text("Click day to see event");
173			eventsLink.text("All Events");
174			eventsLink.attr("href", "#");
175
176
177			curMonth = month;
178			curYear = year;
179
180			var ldate = new Date(year, month);
181			var dt = new Date(ldate);
182			var weekDay = dt.getDay();
183
184			if(settings.from_monday)
185				weekDay = dt.getDay() > 0 ? dt.getDay() - 1 : 6;
186
187			if(ldate.getDate() === 1)
188				tbody.append(lastDaysOfPrevMonth(weekDay));
189
190			while (ldate.getMonth() === month) {
191     			dt = new Date(ldate);
192
193     			var isToday = areSameDate(ldate, new Date());
194     			var event = null;
195				//var eventIndex = -1;
196     			var eventIndex = settings.events.findIndex(function(ev) {
197					//console.log("ev.date:"+ev.date);
198					//console.log(dt+" | "+ev.date);
199		     		//return areSameDate(dt, new Date(ev.date));
200					 return areSameDate(dt, new Date(ev.date.replace(/-/g, '/')));
201		     	});
202				if (eventIndex === -1) {
203					eventIndex = -1; // No match found, explicitly set -1 (optional)
204					
205				}
206				
207		        if(eventIndex != -1){
208		        	event = settings.events[eventIndex];
209					console.log("eventIndex:"+eventIndex);
210
211		        	if(onInit && isToday)
212		        		showEvent(event);
213		        }
214
215     			tbody.append(dateTpl(false, ldate.getDate(), isToday, event, onInit && isToday));
216
217     			ldate.setDate(ldate.getDate() + 1);
218
219     			var bufferDays = 43 - miniCalendar.find(".a-date").length;
220
221		        if(ldate.getMonth() != month){
222		        	for(var i = 1; i < bufferDays; i++){
223						tbody.append(dateTpl(true, i));
224					}
225				}
226			}
227			 
228			if(settings.onMonthChanged){
229				settings.onMonthChanged(month, year);
230			}
231 		}
232
233        function getNextEventMonth(curMonthYear){
234
235            $.ajax({
236                url: "https://ncsymphony.org/wp-admin/admin-ajax.php",
237                type: "POST",
238                data: {
239                    action: "next_event_month",
240                    monthYear: curMonthYear
241                },
242                success: function(response){
243                    callback(response);
244                }
245            });
246
247        }
248
249        async function loadMonth(curMonthYear){
250
251            try {
252
253                let result = await getNextEventMonth(curMonthYear);
254
255                console.log("AJAX result:", result);
256
257                let parts = result.split('-');
258                let curMonth = parseInt(parts[0], 10) - 1;
259
260                alert("Month index: " + curMonth);
261
262                return curMonth;
263
264            } catch (error) {
265                console.log("AJAX error:", error);
266            }
267
268        }
269
270 		function lastDaysOfPrevMonth(day){
271 			if(curMonth > 0){
272				var monthIdx = curMonth - 1;
273				var yearIdx = curYear;
274			}
275			else{
276     			if(curMonth < 11){
277     				var monthIdx = 0;
278     				var yearIdx = curYear + 1;
279     			}else{
280     				var monthIdx = 11;
281     				var yearIdx = curYear - 1;
282     			}
283     		}
284     		
285     		var prevMonth = getMonthDays(monthIdx, yearIdx);
286     		var lastDays = "";
287        	for (var i = day; i > 0; i--)
288     			lastDays += dateTpl(true, prevMonth[prevMonth.length - i]);
289
290        	return lastDays;
291 		}
292
293		 function dateTpl(blurred, date, isToday, event, isSelected) {
294			var tpl = "<div class='a-date blurred'><span>" + date + "</span></div>";
295		
296			if (!blurred) {
297				console.log("event:", event); // Debugging log
298				var hasEvent = event !== null && event !== undefined; // Ensure it's a boolean
299				console.log("hasEvent:", hasEvent); // Debugging log
300		
301				var evlink = hasEvent && event.link ? event.link : "";
302		
303				var cls = ""; // Ensure cls is always initialized
304				if (isToday) cls += "current ";
305				if (hasEvent && isSelected) cls += "focused ";
306				if (hasEvent) cls += "event "; // This should now be added
307		
308				tpl = "<a href='#" + evlink + "' class='a-date " + cls.trim() + "' data-event='" + encodeURIComponent(JSON.stringify(event)) + "'><span>" + date + "</span></a>";
309			}
310		
311			return tpl;
312		}
313
314		function showEvent(event){
315			if(event && event !== null && event !== undefined){
316				eventTitle.text(event.title);
317				eventsLink.text("VIEW EVENT");
318				eventsLink.attr("href", event.link);
319			}else{
320				eventTitle.text("No events on this day.");
321				eventsLink.text("ALL EVENTS");
322				eventsLink.attr("href", settings.calendar_link);
323			}
324		}
325
326		function viewNextMonth(){
327			var cM = parseInt($('#monthYear').attr('curmonth'));
328			var cY = parseInt($('#monthYear').attr('curyear'));
329			//alert(cM+" | "+cY);
330			if( cM ){
331				var nextMonth = cM < 11 ? cM + 1 : 0;
332			}else{
333				var nextMonth = curMonth < 11 ? curMonth + 1 : 0;
334			}
335			if( cY ){
336				var nextYear = cM < 11 ? cY : cY + 1;
337			}else{
338				var nextYear = curMonth < 11 ? curYear : curYear + 1;
339			}
340			
341
342
343
344			//  var nextMonth = curMonth < 11 ? curMonth + 1 : 0;
345			//  var nextYear = curMonth < 11 ? curYear : curYear + 1;
346			var monthYear = (nextMonth+1)+"-"+nextYear;
347
348			// Assign to form > input[name=monthYear]
349			assignMonthYear(monthYear);
350
351			populateCalendar(nextMonth, nextYear);
352
353			// Get data from ajax
354			showEventsByMonth();
355
356			$('#monthYear').attr('curmonth', nextMonth);
357			$('#monthYear').attr('curyear', nextYear);
358
359			sessionStorage.setItem('curMonth', JSON.stringify(nextMonth+1));
360			sessionStorage.setItem('curYear', JSON.stringify(nextYear));
361
362			jQuery('.bydate').attr('href', '/concert-calendar/?cm='+(nextMonth+1)+'&cy='+nextYear);
363			jQuery('.byloc').attr('href', '/concert-calendar-location/?cm='+(nextMonth+1)+'&cy='+nextYear);
364		}
365
366		function viewPrevMonth(){
367			var cM = parseInt($('#monthYear').attr('curmonth'));
368			var cY = parseInt($('#monthYear').attr('curyear'));
369			if( cM ){
370				var prevMonth = cM > 0 ? cM - 1 : 11;
371			}else{
372				var prevMonth = curMonth > 0 ? curMonth - 1 : 11;
373			}
374			if( cY ){
375				var prevYear = cM > 0 ? cY : cY - 1;
376			}else{
377				var prevYear = curMonth > 0 ? curYear : curYear - 1;
378			}
379
380			// var prevMonth = curMonth > 0 ? curMonth - 1 : 11;
381			// var prevYear = curMonth > 0 ? curYear : curYear - 1;
382			var monthYear = (prevMonth+1)+"-"+prevYear;
383			
384			// Assign to form > input[name=monthYear]
385			assignMonthYear(monthYear);
386
387			populateCalendar(prevMonth, prevYear);
388
389			// Get data from ajax
390			showEventsByMonth();
391
392			$('#monthYear').attr('curmonth', prevMonth);
393			$('#monthYear').attr('curyear', prevYear);
394			sessionStorage.setItem('curMonth', JSON.stringify(prevMonth+1));
395			sessionStorage.setItem('curYear', JSON.stringify(prevYear));
396
397			jQuery('.bydate').attr('href', '/concert-calendar/?cm='+(prevMonth+1)+'&cy='+prevYear);
398			jQuery('.byloc').attr('href', '/concert-calendar-location/?cm='+(prevMonth+1)+'&cy='+prevYear);
399		}
400
401		function assignMonthYear(monthYear){
402			const inputField = document.querySelector('input[name="monthYear"]');
403			inputField.value = monthYear;
404		}
405
406		function showEventsByMonth(){
407			
408			var filter = jQuery('#calendarfilter');
409            jQuery.ajax({
410                url:filter.attr('action'),
411                data:filter.serialize(), // form data
412                type:filter.attr('method'), // POST
413                beforeSend:function(xhr){
414
415					
416                	jQuery('#results-block').html("<h4 class='searching'>Searching...</h4>");
417                    
418                },
419                success:function(data){
420					//history.pushState({ lastAjaxResponse: data }, '', window.location.href);
421					
422					sessionStorage.setItem('lastAjaxResponse', JSON.stringify(data));
423					jQuery('#results-block').html(data); // insert data
424
425                }
426            });
427            return false;
428		}
429
430
431
432
433		function areSameDate(d1, d2) {
434			return d1.getFullYear() == d2.getFullYear()
435		        && d1.getMonth() == d2.getMonth()
436		        && d1.getDate() == d2.getDate();
437		}
438
439		function getMonthDays(month, year) {
440			var date = new Date(year, month, 1);
441			var days = [];
442			while (date.getMonth() === month) {
443				days.push(date.getDate());
444				date.setDate(date.getDate() + 1);
445			}
446			return days;
447		}
448
449
450		//alert(sessionStorage.getItem('lastAjaxResponse'));
451		if( sessionStorage.getItem('lastAjaxResponse') == null ){
452			if(fresh == 1){
453				console.log("is fresh sesh");
454				assignMonthYear((curMonth+1)+"-"+curYear);
455			}else{
456				console.log("is not fresh sesh");
457				assignMonthYear(curMonth+"-"+curYear);
458			}
459			showEventsByMonth();
460		}
461
462		if(fresh == 1){
463			console.log("is fresh");
464			jQuery('.bydate').attr('href', '/concert-calendar/?cm='+(curMonth+1)+'&cy='+curYear);
465			jQuery('.byloc').attr('href', '/concert-calendar-location/?cm='+(curMonth+1)+'&cy='+curYear);
466			populateCalendar(curMonth, curYear, true);
467			//alert(curMonth);
468		}else{
469			console.log("is not fresh");
470			jQuery('.bydate').attr('href', '/concert-calendar/?cm='+curMonth+'&cy='+curYear);
471			jQuery('.byloc').attr('href', '/concert-calendar-location/?cm='+curMonth+'&cy='+curYear);
472		 	populateCalendar((curMonth-1), curYear, true);
473			
474		}
475		//alert("fresh:"+fresh);
476		//alert(curMonth+"-"+curYear);
477		// populateCalendar(curMonth, curYear, true);
478
479
480        return miniCalendar;
481    };
482 
483}( jQuery ));

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.