PageSourceSearch

https://rostec.ru/local/templates/rostec2/assets/local/events_calendar_index.js

js rostec.ru collected 2026-09-24 08:24:30 UTC 11,218 bytes, 347 lines download raw bytes

1$(function() {
2	if ($SITE_ID == 's1') {
3        moment.locale('ru');
4    } else {
5        moment.locale($SITE_DIR);
6	}
7
8	var th = this;
9	var m = moment(),
10		initialDate = {
11			day: m.format('D'),
12			month: m.month(),
13			year: m.year()
14		},
15		baseDate = {
16			day: m.format('D'),
17			month: m.month(),
18			year: m.year()
19		},
20		calendar_events = {},
21		calendar_monthNames = [JS_MESS.MONTH_1,JS_MESS.MONTH_2,JS_MESS.MONTH_3,JS_MESS.MONTH_4,JS_MESS.MONTH_5,JS_MESS.MONTH_6,JS_MESS.MONTH_7,JS_MESS.MONTH_8,JS_MESS.MONTH_9,JS_MESS.MONTH_10,JS_MESS.MONTH_11,JS_MESS.MONTH_12];
22		calendar_weekdayNames = [JS_MESS.WEEK_7, JS_MESS.WEEK_1,JS_MESS.WEEK_2,JS_MESS.WEEK_3,JS_MESS.WEEK_4,JS_MESS.WEEK_5,JS_MESS.WEEK_6];
23
24	$('[data-celendar-events]').each(function(){
25		var th                    = $(this),
26			calendar__container   = th.find('[data-calendar-month-days]'),
27			calendar__title       = th.find('.news-calendar__inner contain > h2'),
28			$url                  = th.attr('data-url');
29
30		if($url.length > 0){
31			$.ajax({
32                url: $url + '?site=' + $SITE_ID + '&year=' + th.find('[data-change-year]').find('.current').data('year'),
33				dataType: "json",
34				success: function(data){
35					calendar_events = data;
36					deactivateMonths();
37					addEvents(calendar_events, calendar__container);
38				}
39			});
40		}
41
42		buildMonth(m, calendar__container);
43		changeMonthName(m, calendar__title, calendar_monthNames);
44
45		// выбор месяца
46		th.find('[data-change-month] div.news-calendar__month').on('click', function() {
47			var month__num = $(this).data('month'),
48				year__num = $('[data-change-year] ._is-active').data('year');
49				changeDate = moment({day: 1, month: (month__num-1), year: year__num});
50
51			initialDate.year = year__num;
52			initialDate.month = month__num-1;
53
54			buildMonth(changeDate, calendar__container);
55			addEvents(calendar_events, calendar__container);
56			changeMonthName(changeDate, calendar__title, calendar_monthNames);
57
58			return false;
59		});
60
61		// выбор года
62		th.find('[data-change-year] div').on('click', function(){
63			th.find('[data-change-year] div').removeClass('_is-active');
64			$(this).addClass('_is-active');
65			$(this).parent().removeClass('_is-show');
66
67			var month__num = th.find('[data-change-month] div._is-active').data('month'),
68				year__num = $('[data-change-year] ._is-active').data('year'),
69				currentDate = moment();
70
71			if (parseInt(currentDate.format('YYYY')) === year__num && parseInt(currentDate.format('M')) === month__num) {
72				changeDate = moment({day: parseInt(currentDate.format('DD')), month: (month__num-1), year: year__num});
73			} else {
74				changeDate = moment({day: 1, month: (month__num-1), year: year__num});
75			}
76			
77			$('#active-year').text(year__num);
78			buildMonth(changeDate, calendar__container);
79			changeMonthName(changeDate, calendar__title, calendar_monthNames);
80
81			// обновляем события
82			if($url.length > 0){
83				$.ajax({
84					url: $url + '?site=' + $SITE_ID + '&year=' + $('[data-change-year]').find('div._is-active').data('year'),
85					dataType: "json",
86					success: function(data){
87						calendar_events = data;
88						deactivateMonths();
89						addEvents(calendar_events, calendar__container);
90					}
91				});
92			};
93		});
94	});
95
96	function Days(){
97		this.html = '',
98		this.count = 0;
99	}
100
101	function buildOldDays(m, object){
102		var firstMonthDayOfWeek = m.clone().set('date', 1),
103			firstDayOfCurrentMonth = firstMonthDayOfWeek.day(),
104			previousMonth,
105			daysCount = 0,
106			days = [];
107
108			if (initialDate.month == 0) {
109				previousMonth = parseInt(moment({day: 1, month: 11, year: initialDate.year - 1}).endOf('month').format('DD'));
110			} else {
111				previousMonth = parseInt(moment({day: 1, month: initialDate.month - 1, year: initialDate.year}).endOf('month').format('DD'));
112			}
113
114		if (firstDayOfCurrentMonth == 0) {
115			var fromDay = previousMonth - 5;
116			for (var i = fromDay; i <= previousMonth; i++) {
117				var day = '<div class="news-calendar__cell-day news-calendar__cell-day--dey-another-month"><span>' + i +  '</span></div>';
118				days.push(day);
119				daysCount++;
120			}
121		} else {
122			var fromDay = previousMonth - firstDayOfCurrentMonth + 2;
123			for (var i = fromDay; i <= previousMonth; i++){
124				var day = '<div class="news-calendar__cell-day news-calendar__cell-day--dey-another-month"><span>' + i +  '</span></div>';
125				days.push(day);
126				daysCount++;
127			}
128		}
129
130		object.html = days;
131		object.count = daysCount;
132	}
133
134	function buildCurrentDays(m, daysInMonth, object){
135		var days = [],
136			daysCount = 0,
137			currentDate = m.format('MM') === moment().format('MM') && m.format('YYYY') === moment().format('YYYY');
138
139		for (var i = 1; i <= daysInMonth; i++){
140			var aDate = moment({day: i, month: m.month(), year: m.year()});
141			var currentDay = currentDate && i == moment().get('date');
142			var date = moment(m.year() + "-" + (m.month() + 1) + "-" + i).format("YYYY-MM-DD");
143
144			if (currentDay) {
145				var day = '<div class="news-calendar__cell-day news-calendar__cell-day--no-news _is-active" data-date="' + date + '"><span>' + i + '</span></div>';
146			} else {
147				var day = '<div class="news-calendar__cell-day news-calendar__cell-day--no-news" data-date="' + date + '"><span>' + i + '</span></div>'
148			}
149
150			days.push(day);
151			daysCount++;
152		};
153
154		object.html = days;
155		object.count = daysCount;
156	}
157
158	function buildFutureDays(m, object, daysCount){
159		var dateClone = m.clone();
160		var lastMonthDay = dateClone.endOf('month').format('DD'),
161			lastMonthDayOfWeek = dateClone.set('date', lastMonthDay).day();
162		
163		var days = [];
164
165		var fromDay = 7 - lastMonthDayOfWeek;
166		var alignTableCount = fromDay + (daysCount - fromDay);
167		if (fromDay == 7){
168
169		} else {
170			for (var i = 1; i <= alignTableCount; i++) {
171				var day = '<div class="news-calendar__cell-day news-calendar__cell-day--dey-another-month"><span>' + i + '</span></div>';
172				days.push(day);
173			}
174		}
175		object.html = days;
176	}
177
178	function buildMonth(m, calendar__container){
179		var allDays = [];
180		var daysCount = 35;
181
182		var oldDays = new Days();
183		buildOldDays(m, oldDays);
184		allDays = allDays.concat(oldDays.html);
185		daysCount -= oldDays.count;
186
187		var currentDays = new Days();
188		buildCurrentDays(m, m.daysInMonth(), currentDays);
189		allDays = allDays.concat(currentDays.html);
190		daysCount -= currentDays.count;
191
192		var futureDays = new Days();
193		buildFutureDays(m, futureDays, daysCount);
194		allDays = allDays.concat(futureDays.html);
195		allDays = allDays.join('');
196
197		calendar__container.html('');
198		calendar__container.append(allDays);
199	}
200
201	function addEvents(calendar_events, calendar__container){
202		var monthDays = calendar__container.find('div').not('.news-calendar__cell-day--dey-another-month');
203
204		monthDays.each(function() {
205			var div = $(this),
206				dateAttr = div.attr('data-date');
207
208			for (var key in calendar_events) {
209				if (key === dateAttr) {
210					div.removeClass('news-calendar__cell-day--no-news');
211					var eventCnt = Object.keys(calendar_events[key]).length;
212					if (eventCnt == 2) {
213						div.addClass("dot2");
214					} else if (eventCnt > 2) {
215						div.addClass("dot3");
216					}
217					break;
218				}
219			}
220		});
221	}
222
223	function deactivateMonths()
224	{
225		let currentYear = parseInt(moment().format('YYYY'));
226		let activeYear = parseInt($('#active-year').text());
227
228		//Обнуляем перед отключением неактивных месяцев
229		$('.news-calendar__month').removeClass('news-calendar__month--no-news');
230
231		if (currentYear === activeYear) {
232			let month = parseInt(moment().format('M')) + 1;
233
234			for (let i = month; i <= 12; i++) {
235				$('[data-month="' + i + '"]').addClass('news-calendar__month--no-news');
236			}
237		}
238	}
239
240	function changeMonthName(m, calendar__title, calendar_monthNames) {
241		var selectedMonth = m.month() + 1;
242
243		$('[data-change-month]').find('._is-active').removeClass('_is-active');
244		$('[data-change-month]').find('[data-month='+ selectedMonth +']').addClass('_is-active');
245
246		calendar__title.html(JS_MESS.EVENTS_TITLE);
247	}
248
249	$(document).on('click', '.news-calendar .news-calendar__cell-day', function () {
250		let newsContainer = $(this).closest('.main-news').find('.main-news__items');
251		let selectedDate = moment($(this).attr('data-date'));
252		let weekdayName = calendar_weekdayNames[selectedDate.day()];
253		$('#calendar-current-date').html(selectedDate.format('DD') + '.' + selectedDate.format('MM') + '<small>' + weekdayName.toUpperCase() + '</small>');
254		calendarHide();
255		loadNewsByDate(selectedDate, newsContainer);
256	});
257
258	function loadNewsByDate(date, container)
259	{
260		let url = $('#events').data('get-news-url');
261
262		$.get(url, {AJAX:'Y', selectedDate: date.format('YYYY-MM-DD')}, function (result) {
263			let items = $(result).find('.main-news__items').html();
264			$(container).html(items);
265			initMainNewsSlider();
266		});
267	}
268
269	function calendarHide()
270	{
271		$('.main-news').removeClass('_is-show-news-calendar');
272		$('.news-calendar').removeClass('_is-show');
273		$('.js-year-dropdown').removeClass('_is-show');
274	}
275
276	let mainNewsSlider = null;
277
278	function initMainNewsSlider() {
279        if (mainNewsSlider == null) {
280            mainNewsSlider = new Swiper(".js-main-news-slider", {
281                slidesPerView: "auto",
282                spaceBetween: 30,
283                speed: 1000,
284                autoplay: {
285                    delay: 5000,
286                    disableOnInteraction: false,
287                },
288                pagination: {
289                    el: ".main-news .swiper-pagination",
290                    clickable: true,
291                    renderBullet: function renderBullet(index, className) {
292                        return (
293                            '<span class="' +
294                            className +
295                            '">' +
296                            "<span></span>" +
297                            "</span>"
298                        );
299                    },
300                },
301                navigation: {
302                    nextEl: ".swiper-button-next",
303                    prevEl: ".swiper-button-prev",
304                },
305                breakpoints: {
306                    320: {
307                        centeredSlides: true,
308                        spaceBetween: 10,
309                    },
310                    375: {
311                        centeredSlides: true,
312                        spaceBetween: 15,
313                    },
314                    768: {
315                        centeredSlides: false,
316                        spaceBetween: 30,
317                    },
318                },
319            });
320            sliderResize();
321        } else {
322            mainNewsSlider.update();
323            mainNewsSlider.slideTo(0, 1000, false);
324        }
325    }
326
327    function sliderResize() {
328        if ($(".main-news__wrapper").width() >= 975) {
329            $(".main-news__slider").css("max-width", 975);
330        } else if ($(".main-news__wrapper").width() >= 670) {
331            $(".main-news__slider").css("max-width", 640);
332        } else if ($(".main-news__wrapper").width() >= 335) {
333            $(".main-news__slider").css("max-width", 305);
334        }
335    }
336
337	if ($(".js-main-news-slider").length) {
338		initMainNewsSlider();
339	}
340
341	$(window).on("load resize", function () {
342		if(mainNewsSlider != null) {
343			sliderResize();
344		}       
345    });
346});
347

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.