PageSourceSearch

https://camper-market.ru/bitrix/js/main/core/core_date.js

js camper-market.ru collected 2026-10-07 19:38:35 UTC 35,062 bytes, 1,414 lines download raw bytes

1;(function(){
2
3if (BX.date)
4	return;
5
6BX.date = BX.Main.Date;
7
8/************************************** calendar class **********************************/
9
10var obCalendarSingleton = null;
11
12/*
13params: {
14	node: bind element || document.body
15
16	value - start value in site format (using 'field' param if 'value' does not exist)
17	callback - date check handler. can return false to prevent calendar closing.
18	callback_after - another handler, called after date picking
19
20	field - field to read/write data
21
22	bTime = true - whether to enable time control
23	bHideTime = false - whether to hide time control by default
24
25	currentTime - current UTC time()
26
27}
28*/
29
30
31BX.calendar = function(params)
32{
33	return BX.calendar.get().Show(params);
34};
35
36BX.calendar.get = function()
37{
38	if (!obCalendarSingleton)
39		obCalendarSingleton = new BX.JCCalendar();
40
41	return obCalendarSingleton;
42};
43
44// simple func for compatibility with the oldies
45BX.calendar.InsertDaysBack = function(input, days)
46{
47	if (days != '')
48	{
49		var d = new Date();
50		if(days > 0)
51		{
52			d.setTime(d.valueOf() - days*86400000);
53		}
54
55		input.value = BX.date.format(BX.date.convertBitrixFormat(BX.message('FORMAT_DATE')), d, null);
56	}
57	else
58	{
59		input.value = '';
60	}
61};
62
63BX.calendar.ValueToString = function(value, bTime, bUTC)
64{
65	return BX.date.format(
66		BX.date.convertBitrixFormat(BX.message(bTime ? 'FORMAT_DATETIME' : 'FORMAT_DATE')),
67		value,
68		null,
69		!!bUTC
70	);
71};
72
73BX.calendar.ValueToStringFormat = function(value, bitrixFormat, bUTC)
74{
75	return BX.date.format(
76		BX.date.convertBitrixFormat(bitrixFormat),
77		value,
78		null,
79		!!bUTC
80	);
81};
82
83
84BX.CalendarPeriod =
85{
86	Init: function(inputFrom, inputTo, selPeriod)
87	{
88		if((inputFrom.value != "" || inputTo.value != "") && selPeriod.value == "")
89			selPeriod.value = "interval";
90
91		selPeriod.onchange();
92	},
93
94	ChangeDirectOpts: function(peroidValue, selPParent) // "week" || "others"
95	{
96		var selDirect = BX.findChild(selPParent, {'className':'adm-select adm-calendar-direction'}, true);
97
98		if(peroidValue == "week")
99		{
100			selDirect.options[0].text = BX.message('JSADM_CALEND_PREV_WEEK');
101			selDirect.options[1].text = BX.message('JSADM_CALEND_CURR_WEEK');
102			selDirect.options[2].text = BX.message('JSADM_CALEND_NEXT_WEEK');
103		}
104		else
105		{
106			selDirect.options[0].text = BX.message('JSADM_CALEND_PREV');
107			selDirect.options[1].text = BX.message('JSADM_CALEND_CURR');
108			selDirect.options[2].text = BX.message('JSADM_CALEND_NEXT');
109		}
110	},
111
112	SaveAndClearInput: function(oInput)
113	{
114		if(!window.SavedPeriodValues)
115			window.SavedPeriodValues = {};
116
117		window.SavedPeriodValues[oInput.id] = oInput.value;
118		oInput.value="";
119	},
120
121	RestoreInput: function(oInput)
122	{
123		if(!window.SavedPeriodValues || !window.SavedPeriodValues[oInput.id])
124			return;
125
126		oInput.value = window.SavedPeriodValues[oInput.id];
127		delete(window.SavedPeriodValues[oInput.id]);
128	},
129
130	OnChangeP: function(sel)
131	{
132		var selPParent = sel.parentNode.parentNode;
133		var bShowFrom, bShowTo, bShowDirect, bShowSeparate;
134		bShowFrom = bShowTo = bShowDirect = bShowSeparate = false;
135
136		var inputFromWrap = BX.findChild(selPParent, {'className':'adm-input-wrap adm-calendar-inp adm-calendar-first'});
137		var inputToWrap = BX.findChild(selPParent, {'className':'adm-input-wrap adm-calendar-second'});
138		var selDirectWrap = BX.findChild(selPParent, {'className':'adm-select-wrap adm-calendar-direction'});
139		var separator = BX.findChild(selPParent, {'className':'adm-calendar-separate'});
140		var inputFrom = BX.findChild(selPParent, {'className':'adm-input adm-calendar-from'},true);
141		var inputTo = BX.findChild(selPParent, {'className':'adm-input adm-calendar-to'},true);
142
143		// define who must be shown
144		switch (sel.value)
145		{
146			case "day":
147			case "week":
148			case "month":
149			case "quarter":
150			case "year":
151				bShowDirect=true;
152				BX.CalendarPeriod.OnChangeD(selDirectWrap.children[0]);
153				break;
154
155			case "before":
156				bShowTo = true;
157				break;
158
159			case "after":
160				bShowFrom = true;
161				break;
162
163			case "exact":
164				bShowFrom= true;
165				break;
166
167			case "interval":
168				bShowFrom = bShowTo = bShowSeparate = true;
169				BX.CalendarPeriod.RestoreInput(inputFrom);
170				BX.CalendarPeriod.RestoreInput(inputTo);
171
172				break;
173
174			case "":
175				BX.CalendarPeriod.SaveAndClearInput(inputFrom);
176				BX.CalendarPeriod.SaveAndClearInput(inputTo);
177				break;
178
179			default:
180				break;
181
182		}
183
184		BX.CalendarPeriod.ChangeDirectOpts(sel.value, selPParent);
185
186		inputFromWrap.style.display = (bShowFrom? 'inline-block':'none');
187		inputToWrap.style.display = (bShowTo? 'inline-block':'none');
188		selDirectWrap.style.display = (bShowDirect? 'inline-block':'none');
189		separator.style.display = (bShowSeparate? 'inline-block':'none');
190	},
191
192
193	OnChangeD: function(sel)
194	{
195		var selPParent = sel.parentNode.parentNode;
196		var inputFrom = BX.findChild(selPParent, {'className':'adm-input adm-calendar-from'},true);
197		var inputTo = BX.findChild(selPParent, {'className':'adm-input adm-calendar-to'},true);
198		var selPeriod = BX.findChild(selPParent, {'className':'adm-select adm-calendar-period'},true);
199
200		var offset=0;
201
202		switch (sel.value)
203		{
204			case "previous":
205				offset = -1;
206				break;
207
208			case "next":
209				offset = 1;
210				break;
211
212			case "current":
213			default:
214				break;
215
216		}
217
218		var from = false;
219		var to = false;
220
221		var today = new Date();
222		var year = today.getFullYear();
223		var month = today.getMonth();
224		var day = today.getDate();
225		var dayW = today.getDay();
226
227		if (dayW == 0)
228				dayW = 7;
229
230		switch (selPeriod.value)
231		{
232			case "day":
233				from = new Date(year, month, day+offset, 0, 0, 0);
234				to = new Date(year, month, day+offset, 23, 59, 59);
235				break;
236
237			case "week":
238				from = new Date(year, month, day-dayW+1+offset*7, 0, 0, 0);
239				to = new Date(year, month, day+(7-dayW)+offset*7, 23, 59, 59);
240				break;
241
242			case "month":
243				from = new Date(year, month+offset, 1, 0, 0, 0);
244				to = new Date(year, month+1+offset, 0, 23, 59, 59);
245				break;
246
247			case "quarter":
248				var quarterNum = Math.floor((month/3))+offset;
249				from = new Date(year, 3*(quarterNum), 1, 0, 0, 0);
250				to = new Date(year, 3*(quarterNum+1), 0, 23, 59, 59);
251				break;
252
253			case "year":
254				from = new Date(year+offset, 0, 1, 0, 0, 0);
255				to = new Date(year+1+offset, 0, 0, 23, 59, 59);
256				break;
257
258			default:
259				break;
260		}
261
262		var format = window[inputFrom.name+"_bTime"] ? BX.message('FORMAT_DATETIME') : BX.message('FORMAT_DATE');
263
264		if(from)
265		{
266			inputFrom.value = BX.formatDate(from, format);
267			BX.addClass(inputFrom,"adm-calendar-inp-setted");
268		}
269
270		if(to)
271		{
272			inputTo.value = BX.formatDate(to, format);
273			BX.addClass(inputTo,"adm-calendar-inp-setted");
274		}
275	}
276};
277
278
279BX.JCCalendar = function()
280{
281	this.params = {};
282
283	this.bAmPm = BX.isAmPmMode();
284
285	this.popup = null;
286	this.popup_month = null;
287	this.popup_year = null;
288	this.month_popup_classname = '';
289	this.year_popup_classname = '';
290
291	this.value = null;
292
293	this.control_id = Math.random();
294
295	this._layers = {};
296	this._current_layer = null;
297
298	this.DIV = null;
299	this.PARTS = {};
300
301	this.weekStart = 0;
302	this.numRows = 6;
303
304	this._create = function(params)
305	{
306		this.popup = new BX.PopupWindow('calendar_popup_' + this.control_id, params.node, {
307			closeByEsc: true,
308			autoHide: false,
309			content: this._get_content(),
310			zIndex: 3000,
311			bindOptions: {forceBindPosition: true}
312		});
313
314		BX.bind(this.popup.popupContainer, 'click', function(event) {
315			event.stopPropagation();
316		});
317	};
318
319	this._auto_hide_disable = function()
320	{
321		BX.unbind(document, 'click', BX.proxy(this._auto_hide, this));
322	};
323
324	this._auto_hide_enable = function()
325	{
326		BX.bind(document, 'click', BX.proxy(this._auto_hide, this));
327	};
328
329	this._auto_hide = function(e)
330	{
331		this._auto_hide_disable();
332		this.popup.close();
333	};
334
335	this._get_content = function()
336	{
337		var _layer_onclick = BX.delegate(function(e) {
338			e = e||window.event;
339			this.SetDate(
340				new Date(parseInt(BX.proxy_context.getAttribute('data-date'))),
341				(e.type === 'dblclick' || this.params.bCompatibility)
342			)
343		}, this);
344
345		this.DIV = BX.create('DIV', {
346			props: {className: 'bx-calendar'},
347			children: [
348				BX.create('DIV', {
349					props: {
350						className: 'bx-calendar-header'
351					},
352					children: [
353						BX.create('A', {
354							attrs: {href: 'javascript:void(0)'},
355							props: {className: 'bx-calendar-left-arrow'},
356							events: {click: BX.proxy(this._prev, this)}
357						}),
358
359						BX.create('SPAN', {
360							props: {className: 'bx-calendar-header-content'},
361							children: [
362								(this.PARTS.MONTH = BX.create('A', {
363									attrs: {href: 'javascript:void(0)'},
364									props: {className: 'bx-calendar-top-month'},
365									events: {click: BX.proxy(this._menu_month, this)}
366								})),
367
368								(this.PARTS.YEAR = BX.create('A', {
369									attrs: {href: 'javascript:void(0)'},
370									props: {className: 'bx-calendar-top-year'},
371									events: {click: BX.proxy(this._menu_year, this)}
372								}))
373							]
374						}),
375
376						BX.create('A', {
377							attrs: {href: 'javascript:void(0)'},
378							props: {className: 'bx-calendar-right-arrow'},
379							events: {click: BX.proxy(this._next, this)}
380						})
381					]
382				}),
383
384				(this.PARTS.WEEK = BX.create('DIV', {
385					props: {
386						className: 'bx-calendar-name-day-wrap'
387					}
388				})),
389
390				(this.PARTS.LAYERS = BX.create('DIV', {
391					props: {
392						className: 'bx-calendar-cell-block'
393					},
394					events: {
395						click: BX.delegateEvent({className: 'bx-calendar-cell'}, _layer_onclick),
396						dblclick: BX.delegateEvent({className: 'bx-calendar-cell'}, _layer_onclick)
397					}
398				})),
399
400				(this.PARTS.TIME = BX.create('DIV', {
401					props: {
402						className: 'bx-calendar-set-time-wrap'
403					},
404					events: {
405						click: BX.delegateEvent(
406							{attr: 'data-action'},
407							BX.delegate(this._time_actions, this)
408						)
409					},
410					html: '<a href="javascript:void(0)" data-action="time_show" class="bx-calendar-set-time"><i></i>'+BX.message('CAL_TIME_SET')+'</a><div class="bx-calendar-form-block"><span class="bx-calendar-form-text">'+BX.message('CAL_TIME')+'</span><span class="bx-calendar-form"><input type="text" class="bx-calendar-form-input" maxwidth="2" onkeyup="BX.calendar.get()._check_time()" /><span class="bx-calendar-form-separator"></span><input type="text" class="bx-calendar-form-input" maxwidth="2" onkeyup="BX.calendar.get()._check_time()" />'+(this.bAmPm?'<span class="bx-calendar-AM-PM-block"><span class="bx-calendar-AM-PM-text" data-action="time_ampm"></span><span class="bx-calendar-form-arrow-r"><a href="javascript:void(0)" class="bx-calendar-form-arrow-top" data-action="time_ampm_up"><i></i></a><a href="javascript:void(0)" class="bx-calendar-form-arrow-bottom" data-action="time_ampm_down"><i></i></a></span></span>':'')+'</span><a href="javascript:void(0)" data-action="time_hide" class="bx-calendar-form-close"><i></i></a></div>'
411				})),
412
413				(this.PARTS.BUTTONS = BX.create('DIV', {
414					props: {className: 'bx-calendar-button-block'},
415					events: {
416						click: BX.delegateEvent(
417							{attr: 'data-action'},
418							BX.delegate(this._button_actions, this)
419						)
420					},
421					html: '<a href="javascript:void(0)" class="bx-calendar-button bx-calendar-button-select" data-action="submit"><span class="bx-calendar-button-left"></span><span class="bx-calendar-button-text">'+BX.message('CAL_BUTTON')+'</span><span class="bx-calendar-button-right"></span></a><a href="javascript:void(0)" class="bx-calendar-button bx-calendar-button-cancel" data-action="cancel"><span class="bx-calendar-button-left"></span><span class="bx-calendar-button-text">'+BX.message('JS_CORE_WINDOW_CLOSE')+'</span><span class="bx-calendar-button-right"></span></a>'
422				}))
423			]
424		});
425
426		this.PARTS.TIME_INPUT_H = BX.findChild(this.PARTS.TIME, {tag: 'INPUT'}, true);
427		this.PARTS.TIME_INPUT_M = this.PARTS.TIME_INPUT_H.nextSibling.nextSibling;
428
429		if (this.bAmPm)
430			this.PARTS.TIME_AMPM = this.PARTS.TIME_INPUT_M.nextSibling.firstChild;
431
432		var spinner = (new BX.JCSpinner({
433			input: this.PARTS.TIME_INPUT_H,
434			callback_change: BX.proxy(this._check_time, this),
435			bSaveValue: false
436		})).Show();
437		spinner.className = 'bx-calendar-form-arrow-l';
438		this.PARTS.TIME_INPUT_H.parentNode.insertBefore(spinner, this.PARTS.TIME_INPUT_H);
439
440		spinner = (new BX.JCSpinner({
441			input: this.PARTS.TIME_INPUT_M,
442			callback_change: BX.proxy(this._check_time, this),
443			bSaveValue: true
444		})).Show();
445		spinner.className = 'bx-calendar-form-arrow-r';
446		if (!this.PARTS.TIME_INPUT_M.nextSibling)
447			this.PARTS.TIME_INPUT_M.parentNode.appendChild(spinner);
448		else
449			this.PARTS.TIME_INPUT_M.parentNode.insertBefore(spinner, this.PARTS.TIME_INPUT_M.nextSibling);
450
451		for (var i = 0; i < 7; i++)
452		{
453			this.PARTS.WEEK.appendChild(BX.create('SPAN', {
454				props: {
455					className: 'bx-calendar-name-day'
456				},
457				text: BX.message('DOW_' + ((i + this.weekStart) % 7))
458			}));
459		}
460
461		return this.DIV;
462	};
463
464	this._time_actions = function()
465	{
466		switch (BX.proxy_context.getAttribute('data-action'))
467		{
468			case 'time_show':
469				BX.addClass(this.PARTS.TIME, 'bx-calendar-set-time-opened');
470				if (this.params.bCompatibility)
471				{
472					BX.removeClass(this.PARTS.BUTTONS, 'bx-calendar-buttons-disabled');
473				}
474				this.popup.adjustPosition();
475			break;
476			case 'time_hide':
477				BX.removeClass(this.PARTS.TIME, 'bx-calendar-set-time-opened');
478				if (this.params.bCompatibility)
479				{
480					BX.addClass(this.PARTS.BUTTONS, 'bx-calendar-buttons-disabled');
481				}
482				this.popup.adjustPosition();
483			break;
484			case 'time_ampm':
485				this.PARTS.TIME_AMPM.innerHTML = this.PARTS.TIME_AMPM.innerHTML == 'AM' ? 'PM' : 'AM';
486			break;
487			case 'time_ampm_up':
488				this._check_time({bSaveValue: false}, null, 12);
489				return;
490			break;
491			case 'time_ampm_down':
492				this._check_time({bSaveValue: false}, null, -12);
493				return;
494			break;
495		}
496
497		this._check_time();
498	};
499
500	this._button_actions = function()
501	{
502		switch (BX.proxy_context.getAttribute('data-action'))
503		{
504			case 'submit':
505				this.SaveValue();
506			break;
507			case 'cancel':
508				this.Close();
509			break;
510		}
511	};
512
513	this._check_time = function(params, value, direction)
514	{
515		var h = parseInt(this.PARTS.TIME_INPUT_H.value.substring(0,5),10)||0,
516			m = parseInt(this.PARTS.TIME_INPUT_M.value.substring(0,5),10)||0,
517			bChanged = false;
518
519		if (!!params && !params.bSaveValue)
520		{
521			this.value.setUTCHours(this.value.getUTCHours() + direction);
522		}
523		else if (!isNaN(h))
524		{
525			if (this.bAmPm)
526			{
527				if (h != 12 && this.PARTS.TIME_AMPM.innerHTML == 'PM')
528				{
529					h += 12;
530				}
531			}
532
533			bChanged = true;
534			this.value.setUTCHours(h % 24);
535		}
536
537		if (!isNaN(m))
538		{
539			bChanged = true;
540			this.value.setUTCMinutes(m % 60);
541		}
542
543		if (bChanged)
544		{
545			this.SetValue(this.value);
546		}
547	};
548
549	this._set_layer = function()
550	{
551		var layerId = parseInt(this.value.getUTCFullYear() + '' + BX.util.str_pad_left(this.value.getUTCMonth()+'', 2, "0"));
552
553		if (!this._layers[layerId])
554		{
555			this._layers[layerId] = this._create_layer();
556			this._layers[layerId].BXLAYERID = layerId;
557		}
558
559		if (this._current_layer)
560		{
561			var v = new Date(this.value.valueOf());
562			v.setUTCHours(0); v.setUTCMinutes(0);
563
564			var cur_value = BX.findChild(this._layers[layerId], {
565					tag: 'A',
566					className: 'bx-calendar-active'
567				}, true),
568				new_value = BX.findChild(this._layers[layerId], {
569					tag: 'A',
570					attr: {
571						'data-date' : v.valueOf() + ''
572					}
573				}, true);
574
575			if (cur_value)
576			{
577				BX.removeClass(cur_value, 'bx-calendar-active');
578			}
579
580			if (new_value)
581			{
582				BX.addClass(new_value, 'bx-calendar-active');
583			}
584
585			this._replace_layer(this._current_layer, this._layers[layerId]);
586		}
587		else
588		{
589			this.PARTS.LAYERS.appendChild(this._layers[layerId]);
590		}
591
592		this._current_layer = this._layers[layerId];
593	};
594
595	this._replace_layer = function(old_layer, new_layer)
596	{
597		if (old_layer != new_layer)
598		{
599			if (!BX.browser.IsIE() || BX.browser.IsDoctype())
600			{
601				var dir = old_layer.BXLAYERID > new_layer.BXLAYERID ? 1 : -1;
602
603				var old_top = 0;
604				var new_top = -dir * old_layer.offsetHeight;
605
606				old_layer.style.position = 'relative';
607				old_layer.style.top = "0px";
608				old_layer.style.zIndex = 5;
609
610				new_layer.style.position = 'absolute';
611				new_layer.style.top = new_top + 'px';
612				new_layer.style.zIndex = 6;
613
614				this.PARTS.LAYERS.appendChild(new_layer);
615
616				var delta = 15;
617
618				var f;
619				(f = function() {
620					new_top += dir * delta;
621					old_top += dir * delta;
622
623					if (dir * new_top < 0)
624					{
625						old_layer.style.top = old_top + 'px';
626						new_layer.style.top = new_top + 'px';
627						setTimeout(f, 10);
628					}
629					else
630					{
631						old_layer.parentNode.removeChild(old_layer);
632
633						new_layer.style.top = "0px";
634						new_layer.style.position = 'static';
635						new_layer.style.zIndex = 0;
636					}
637				})();
638			}
639			else
640			{
641				this.PARTS.LAYERS.replaceChild(new_layer, old_layer);
642			}
643		}
644	};
645
646	this._create_layer = function()
647	{
648		var l = BX.create('DIV', {
649			props: {
650				className: 'bx-calendar-layer'
651			}
652		});
653
654		var month_start = new Date(this.value);
655		month_start.setUTCHours(0);
656		month_start.setUTCMinutes(0);
657
658		month_start.setUTCDate(1);
659
660		if (month_start.getUTCDay() != this.weekStart)
661		{
662			var d = month_start.getUTCDay() - this.weekStart;
663			d += d < 0 ? 7 : 0;
664			month_start.setUTCDate(month_start.getUTCDate()-d);
665		}
666
667		var cur_month = this.value.getUTCMonth(),
668			cur_day = this.value.getUTCDate(),
669			s = '';
670		for (var i = 0; i < this.numRows; i++)
671		{
672			s += '<div class="bx-calendar-range'
673				+(i == this.numRows-1 ? ' bx-calendar-range-noline' : '')
674				+'">';
675
676			for (var j = 0; j < 7; j++)
677			{
678				d = month_start.getUTCDate();
679				var wd = month_start.getUTCDay();
680				var className = 'bx-calendar-cell';
681
682				if (cur_month != month_start.getUTCMonth())
683					className += ' bx-calendar-date-hidden';
684				else if (cur_day == d)
685					className += ' bx-calendar-active';
686
687
688				if (wd == 0 || wd == 6)
689					className += ' bx-calendar-weekend';
690
691				s += '<a href="javascript:void(0)" class="'+className+'" data-date="' + month_start.valueOf() + '">' + d + '</a>';
692
693				month_start.setUTCDate(month_start.getUTCDate()+1);
694			}
695			s += '</div>';
696		}
697
698		l.innerHTML = s;
699
700		return l;
701	};
702
703	this._prev = function()
704	{
705		this.SetMonth(this.value.getUTCMonth()-1);
706	};
707
708	this._next = function()
709	{
710		this.SetMonth(this.value.getUTCMonth()+1);
711	};
712
713	this._menu_month_content = function()
714	{
715		var months = '', cur_month = this.value.getMonth(), i;
716		for (i = 0; i < 12; i++)
717		{
718			months += '<span class="bx-calendar-month'+(i == cur_month ? ' bx-calendar-month-active' : '')+'" data-bx-month="' + i + '">' + BX.message('MONTH_' + (i + 1)) + '</span>';
719		}
720
721		return '<div class="bx-calendar-month-popup"><div class="bx-calendar-month-title" data-bx-month="' + this.value.getUTCMonth() + '">' + BX.message('MONTH_' + (this.value.getUTCMonth() + 1)) + '</div><div class="bx-calendar-month-content">' + months + '</div></div>';
722	};
723
724	this._menu_month = function()
725	{
726		if (!this.popup_month)
727		{
728			this.popup_month = new BX.PopupWindow(
729				'calendar_popup_month_' + this.control_id, this.PARTS.MONTH,
730				{
731					content: this._menu_month_content(),
732					zIndex: 3001,
733					closeByEsc: true,
734					autoHide: true,
735					offsetTop: -29,
736					offsetLeft: -1,
737					className: this.month_popup_classname,
738					events: {
739						onPopupShow: BX.delegate(function() {
740							if (this.popup_year)
741							{
742								this.popup_year.close();
743							}
744						}, this)
745					}
746				}
747			);
748
749			BX.bind(this.popup_month.popupContainer, 'click', BX.proxy(this.month_popup_click, this));
750			this.popup_month.BXMONTH = this.value.getUTCMonth();
751		}
752		else if (this.popup_month.BXMONTH != this.value.getUTCMonth())
753		{
754			this.popup_month.setContent(this._menu_month_content());
755			this.popup_month.BXMONTH = this.value.getUTCMonth();
756		}
757
758		this.popup_month.show();
759	};
760
761	this.month_popup_click = function(e)
762	{
763		var target = e.target || e.srcElement;
764		if (target && target.getAttribute && target.getAttribute('data-bx-month'))
765		{
766			this.SetMonth(parseInt(target.getAttribute('data-bx-month')));
767			this.popup_month.close();
768		}
769	};
770
771	this._menu_year_content = function()
772	{
773		var s = '<div class="bx-calendar-year-popup"><div class="bx-calendar-year-title" data-bx-year="' + this.value.getUTCFullYear() + '">' + this.value.getUTCFullYear() + '</div><div class="bx-calendar-year-content" id="bx-calendar-year-content">';
774
775		for (var i=-3; i <= 3; i++)
776		{
777			s += '<span class="bx-calendar-year-number' + (i == 0?' bx-calendar-year-active' : '') + '" data-bx-year="' + (this.value.getUTCFullYear() - i) + '">' + (this.value.getUTCFullYear() - i)+'</span>';
778		}
779
780		s += '</div><input data-bx-year-input="Y" type="text" class="bx-calendar-year-input" maxlength="4" /></div>';
781
782		return s;
783	};
784
785	this._menu_year = function()
786	{
787		if (!this.popup_year)
788		{
789			this.popup_year = new BX.PopupWindow(
790				'calendar_popup_year_' + this.control_id, this.PARTS.YEAR,
791				{
792					content: this._menu_year_content(),
793					zIndex: 3001,
794					closeByEsc: true,
795					autoHide: true,
796					offsetTop: -29,
797					offsetLeft: -1,
798					className: this.year_popup_classname,
799					events: {
800						onPopupShow: BX.delegate(function() {
801							if (this.popup_month)
802							{
803								this.popup_month.close();
804							}
805						}, this)
806					}
807				}
808			);
809
810			BX.bind(this.popup_year.popupContainer, 'click', BX.proxy(this.year_popup_click, this));
811			BX.bind(this.popup_year.popupContainer, 'keyup', BX.proxy(this.year_popup_keyup, this));
812			this.popup_year.BXYEAR = this.value.getUTCFullYear();
813		}
814		else if (this.popup_year.BXYEAR != this.value.getUTCFullYear())
815		{
816			this.popup_year.setContent(this._menu_year_content());
817			this.popup_year.BXYEAR = this.value.getUTCFullYear();
818		}
819
820		this.popup_year.show();
821	};
822
823	this.year_popup_click = function(e)
824	{
825		var target = e.target || e.srcElement;
826		if (target && target.getAttribute && target.getAttribute('data-bx-year'))
827		{
828			this.SetYear(parseInt(target.getAttribute('data-bx-year')));
829			this.popup_year.close();
830		}
831	};
832	this.year_popup_keyup = function(e)
833	{
834		var target = e.target || e.srcElement;
835		if (target && target.getAttribute && target.getAttribute('data-bx-year-input') == 'Y')
836		{
837			var value = parseInt(target.value);
838			if(value >= 1900 && value <= 2100)
839			{
840				this.SetYear(value);
841				this.popup_year.close();
842			}
843		}
844	};
845
846	this._check_date = function(v)
847	{
848		var res = v;
849
850		if (BX.type.isString(v))
851		{
852			res = BX.parseDate(v, true);
853		}
854
855		if (!BX.type.isDate(res) || isNaN(res.valueOf()))
856		{
857			res = BX.date.convertToUTC(new Date());
858			if (this.params.bHideTime)
859			{
860				res.setUTCHours(0);
861				res.setUTCMinutes(0);
862			}
863		}
864
865		res.setUTCMilliseconds(0);
866		res.setUTCSeconds(0);
867
868		res.BXCHECKED = true;
869
870		return res;
871	};
872};
873
874BX.JCCalendar.prototype.Show = function(params)
875{
876	if (!BX.isReady)
877	{
878		BX.ready(BX.delegate(function() {this.Show(params)}, this));
879		return;
880	}
881
882	params.node = params.node||document.body;
883
884	if (BX.type.isNotEmptyString(params.node))
885	{
886		var n = BX(params.node);
887		if (!n)
888		{
889			n = document.getElementsByName(params.node);
890			if (n && n.length > 0)
891			{
892				n = n[0]
893			}
894		}
895		params.node = n;
896	}
897
898	if (!params.node)
899		return;
900
901	if (!!params.field)
902	{
903		if (BX.type.isString(params.field))
904		{
905			n = BX(params.field);
906			if (!!n)
907			{
908				params.field = n;
909			}
910			else
911			{
912				if (params.form)
913				{
914					if (BX.type.isString(params.form))
915					{
916						params.form = document.forms[params.form];
917					}
918				}
919
920				if (BX.type.isDomNode(params.form) && !!params.form[params.field])
921				{
922					params.field = params.form[params.field];
923				}
924				else
925				{
926					n = document.getElementsByName(params.field);
927					if (n && n.length > 0)
928					{
929						n = n[0];
930						params.field = n;
931					}
932				}
933			}
934
935			if (BX.type.isString(params.field))
936			{
937				params.field = BX(params.field);
938			}
939		}
940	}
941
942	var bShow = !this.popup || !this.popup.isShown() || this.params.node != params.node;
943
944	this.params = params;
945
946	this.params.bCompatibility = typeof this.params.bCompatibility == 'undefined' ? false : !!this.params.bCompatibility;
947
948	this.params.bTime = typeof this.params.bTime == 'undefined' ? true : !!this.params.bTime;
949	this.params.bHideTime = typeof this.params.bHideTime == 'undefined' ? true : !!this.params.bHideTime;
950	this.params.bUseSecond = typeof this.params.bUseSecond == 'undefined' ? true : !!this.params.bUseSecond;
951
952	this.weekStart = parseInt(this.params.weekStart || this.params.weekStart || BX.message('WEEK_START'));
953	if (isNaN(this.weekStart))
954		this.weekStart = 1;
955
956	if (!this.popup)
957	{
958		this._create(this.params);
959	}
960	else
961	{
962		this.popup.setBindElement(this.params.node);
963	}
964
965	var bHideTime = !!this.params.bHideTime;
966	if (this.params.value)
967	{
968		this.SetValue(this.params.value);
969		bHideTime = this.value.getUTCHours() <= 0 && this.value.getUTCMinutes() <= 0;
970	}
971	else if (this.params.field)
972	{
973		this.SetValue(this.params.field.value);
974		bHideTime = this.value.getUTCHours() <= 0 && this.value.getUTCMinutes() <= 0;
975	}
976	else if (!!this.params.currentTime)
977	{
978		this.SetValue(this.params.currentTime);
979	}
980	else
981	{
982		this.SetValue();
983	}
984
985	if (!!this.params.bTime)
986	{
987		this.activateTimeStyle(bHideTime);
988	}
989	else
990	{
991		this.activateDateStyle(bHideTime);
992	}
993
994	if (bShow)
995	{
996		this._auto_hide_disable();
997		this.popup.show();
998		setTimeout(BX.proxy(this._auto_hide_enable, this), 0);
999	}
1000
1001	this.params.bSetFocus = typeof this.params.bSetFocus == 'undefined' ? true : !!this.params.bSetFocus;
1002	if(this.params.bSetFocus)
1003	{
1004		params.node.blur();
1005	}
1006	else
1007	{
1008		BX.bind(params.node, 'keyup', BX.defer(function(){
1009			this.SetValue(params.node.value);
1010			if(!!this.params.bTime)
1011			{
1012				if(this.value.getUTCHours() <= 0 && this.value.getUTCMinutes() <= 0)
1013					BX.removeClass(this.PARTS.TIME, 'bx-calendar-set-time-opened');
1014				else
1015					BX.addClass(this.PARTS.TIME, 'bx-calendar-set-time-opened');
1016			}
1017		}, this));
1018	}
1019
1020	return this;
1021};
1022
1023BX.JCCalendar.prototype.activateDateStyle = function(bHideTime)
1024{
1025	BX.addClass(this.DIV, 'bx-calendar-time-disabled');
1026
1027	if (!!bHideTime)
1028		BX.removeClass(this.PARTS.TIME, 'bx-calendar-set-time-opened');
1029	else
1030		BX.addClass(this.PARTS.TIME, 'bx-calendar-set-time-opened');
1031};
1032
1033BX.JCCalendar.prototype.activateTimeStyle = function(bHideTime)
1034{
1035	if (!!this.params.bCompatibility)
1036	{
1037		BX.addClass(this.PARTS.BUTTONS, 'bx-calendar-buttons-disabled');
1038		BX.addClass(this.PARTS.TIME, 'bx-calendar-set-time-wrap-simple');
1039		BX.removeClass(this.PARTS.TIME, 'bx-calendar-set-time-opened');
1040	}
1041	else
1042	{
1043		BX.removeClass(this.DIV, 'bx-calendar-time-disabled');
1044
1045		if (!!bHideTime)
1046			BX.removeClass(this.PARTS.TIME, 'bx-calendar-set-time-opened');
1047		else
1048			BX.addClass(this.PARTS.TIME, 'bx-calendar-set-time-opened');
1049	}
1050};
1051
1052BX.JCCalendar.prototype.SetDay = function(d)
1053{
1054	this.value.setUTCDate(d);
1055	return this.SetValue(this.value);
1056};
1057
1058BX.JCCalendar.prototype.SetMonth = function(m)
1059{
1060	if (this.popup_month)
1061		this.popup_month.close();
1062
1063	this.value.setUTCMonth(m);
1064
1065	if(m < 0)
1066		m += 12;
1067	else if (m >= 12)
1068		m -= 12;
1069
1070	while(this.value.getUTCMonth() > m)
1071	{
1072		this.value.setUTCDate(this.value.getUTCDate()-1);
1073	}
1074
1075	return this.SetValue(this.value);
1076};
1077
1078BX.JCCalendar.prototype.SetYear = function(y)
1079{
1080	if (this.popup_year)
1081		this.popup_year.close();
1082	this.value.setUTCFullYear(y);
1083	return this.SetValue(this.value);
1084};
1085
1086BX.JCCalendar.prototype.SetDate = function(v, bSet)
1087{
1088	v = this._check_date(v);
1089	v.setUTCHours(this.value.getUTCHours());
1090	v.setUTCMinutes(this.value.getUTCMinutes());
1091	v.setUTCSeconds(this.value.getUTCSeconds());
1092
1093	if (this.params.bTime && !bSet)
1094	{
1095		return this.SetValue(v);
1096	}
1097	else
1098	{
1099		this.SetValue(v);
1100		this.SaveValue();
1101	}
1102};
1103
1104BX.JCCalendar.prototype.SetValue = function(v)
1105{
1106	this.value = (v && v.BXCHECKED) ? v : this._check_date(v);
1107
1108	this.PARTS.MONTH.innerHTML = BX.message('MONTH_' + (this.value.getUTCMonth()+1));
1109	this.PARTS.YEAR.innerHTML = this.value.getUTCFullYear();
1110
1111	if (!!this.params.bTime)
1112	{
1113		var h = this.value.getUTCHours();
1114		if (this.bAmPm)
1115		{
1116			if (h >= 12)
1117			{
1118				this.PARTS.TIME_AMPM.innerHTML = 'PM';
1119
1120				if (h != 12)
1121					h -= 12;
1122			}
1123			else
1124			{
1125				this.PARTS.TIME_AMPM.innerHTML = 'AM';
1126
1127				if (h == 0)
1128					h = 12;
1129			}
1130		}
1131
1132		this.PARTS.TIME_INPUT_H.value = BX.util.str_pad_left(h.toString(), 2, "0");
1133		this.PARTS.TIME_INPUT_M.value = BX.util.str_pad_left(this.value.getUTCMinutes().toString(), 2, "0");
1134	}
1135
1136	this._set_layer();
1137
1138	return this;
1139};
1140
1141BX.JCCalendar.prototype.SaveValue = function()
1142{
1143	if (this.popup_month)
1144		this.popup_month.close();
1145	if (this.popup_year)
1146		this.popup_year.close();
1147
1148	var bSetValue = true;
1149	if (!!this.params.callback)
1150	{
1151		var res = this.params.callback.apply(this, [new Date(this.value.valueOf()+this.value.getTimezoneOffset()*60000)]);
1152		if (res === false)
1153			bSetValue = false;
1154	}
1155
1156	if (bSetValue)
1157	{
1158		var bTime = !!this.params.bTime && BX.hasClass(this.PARTS.TIME, 'bx-calendar-set-time-opened');
1159
1160		if (this.params.field)
1161		{
1162			var format = BX.message(bTime ? 'FORMAT_DATETIME' : 'FORMAT_DATE');
1163
1164			if(bTime && !this.params.bUseSecond)
1165			{
1166				format = format.replace(':SS', '');
1167			}
1168
1169			this.params.field.value = BX.calendar.ValueToStringFormat(this.value, format, true);
1170			BX.fireEvent(this.params.field, 'change');
1171		}
1172
1173		this.popup.close();
1174
1175		if (!!this.params.callback_after)
1176		{
1177			this.params.callback_after.apply(this, [new Date(this.value.valueOf()+this.value.getTimezoneOffset()*60000), bTime]);
1178		}
1179	}
1180
1181	return this;
1182};
1183
1184BX.JCCalendar.prototype.Close = function()
1185{
1186	if (!!this.popup)
1187		this.popup.close();
1188
1189	return this;
1190};
1191
1192BX.JCSpinner = function(params)
1193{
1194	params = params || {};
1195	this.params = {
1196		input: params.input || null,
1197
1198		delta: params.delta || 1,
1199
1200		timeout_start: params.timeout_start || 1000,
1201		timeout_cont: params.timeout_cont || 150,
1202
1203		callback_start: params.callback_start || null,
1204		callback_change: params.callback_change || null,
1205		callback_finish: params.callback_finish || null,
1206
1207		bSaveValue: typeof params.bSaveValue == 'undefined' ? !!params.input : !!params.bSaveValue
1208	};
1209
1210	this.mousedown = false;
1211	this.direction = 1;
1212};
1213
1214BX.JCSpinner.prototype.Show = function()
1215{
1216	this.node = BX.create('span', {
1217		events: {
1218			mousedown: BX.delegateEvent(
1219				{attr: 'data-dir'},
1220				BX.delegate(this.Start, this)
1221			)
1222		},
1223		html: '<a href="javascript:void(0)" class="bx-calendar-form-arrow bx-calendar-form-arrow-top" data-dir="1"><i></i></a><a href="javascript:void(0)" class="bx-calendar-form-arrow bx-calendar-form-arrow-bottom" data-dir="-1"><i></i></a>'
1224	});
1225	return this.node;
1226};
1227
1228BX.JCSpinner.prototype.Start = function()
1229{
1230	this.mousedown = true;
1231	this.direction = BX.proxy_context.getAttribute('data-dir') > 0 ? 1 : -1;
1232	BX.bind(document, "mouseup", BX.proxy(this.MouseUp, this));
1233	this.ChangeValue(true);
1234};
1235
1236BX.JCSpinner.prototype.ChangeValue = function(bFirst)
1237{
1238	if(!this.mousedown)
1239		return;
1240
1241	if (this.params.input)
1242	{
1243		var v = parseInt(this.params.input.value, 10) + this.params.delta * this.direction;
1244
1245		if (this.params.bSaveValue)
1246			this.params.input.value = v;
1247
1248		if (!!bFirst && this.params.callback_start)
1249			this.params.callback_start(this.params, v, this.direction);
1250
1251		if (this.params.callback_change)
1252			this.params.callback_change(this.params, v, this.direction);
1253
1254		setTimeout(
1255			BX.proxy(this.ChangeValue, this),
1256			!!bFirst ? this.params.timeout_start : this.params.timeout_cont
1257		);
1258	}
1259};
1260
1261BX.JCSpinner.prototype.MouseUp = function()
1262{
1263	this.mousedown = false;
1264	BX.unbind(document, "mouseup", BX.proxy(this.MouseUp, this));
1265
1266	if (this.params.callback_finish)
1267		this.params.callback_finish(this.params, this.params.input.value);
1268};
1269
1270/**************** compatibility hacks ***************************/
1271
1272window.jsCalendar = {
1273	Show: function(obj, field, fieldFrom, fieldTo, bTime, serverTime, form_name, bHideTimebar)
1274	{
1275		return BX.calendar({
1276			node: obj, field: field, form: form_name, bTime: !!bTime, currentTime: serverTime, bHideTimebar: !!bHideTimebar
1277		});
1278	},
1279
1280	ValueToString: BX.calendar.ValueToString
1281};
1282
1283
1284/************ clock popup transferred from timeman **************/
1285
1286BX.CClockSelector = function(params)
1287{
1288	this.params = params;
1289
1290	this.params.popup_buttons = this.params.popup_buttons || [
1291		new BX.PopupWindowButton({
1292			text : BX.message('CAL_BUTTON'),
1293			className : "popup-window-button-create",
1294			events : {click : BX.proxy(this.setValue, this)}
1295		})
1296	];
1297
1298	this.isReady = false;
1299
1300	this.WND = new BX.PopupWindow(
1301		this.params.popup_id || 'clock_selector_popup',
1302		this.params.node,
1303		this.params.popup_config || {
1304			titleBar: BX.message('CAL_TIME'),
1305			offsetLeft: -45,
1306			offsetTop: -135,
1307			autoHide: true,
1308			closeIcon: true,
1309			closeByEsc: true,
1310			zIndex: this.params.zIndex
1311		}
1312	);
1313
1314	this.SHOW = false;
1315	BX.addCustomEvent(this.WND, "onPopupClose", BX.delegate(this.onPopupClose, this));
1316
1317	this.obClocks = {};
1318	this.CLOCK_ID = this.params.clock_id || 'clock_selector';
1319};
1320
1321BX.CClockSelector.prototype.Show = function()
1322{
1323	if (!this.isReady)
1324	{
1325		//BX.timeman.showWait(this.parent.DIV);
1326
1327		BX.addCustomEvent('onClockRegister', BX.proxy(this.onClockRegister, this));
1328		return BX.ajax.get('/bitrix/tools/clock_selector.php', {start_time: this.params.start_time, clock_id: this.CLOCK_ID, sessid: BX.bitrix_sessid()}, BX.delegate(this.Ready, this));
1329	}
1330
1331	this.WND.setButtons(this.params.popup_buttons);
1332	this.WND.show();
1333
1334	this.SHOW = true;
1335
1336	if (window['bxClock_' + this.obClocks[this.CLOCK_ID]])
1337	{
1338		setTimeout("window['bxClock_" + this.obClocks[this.CLOCK_ID] + "'].CalculateCoordinates()", 40);
1339	}
1340
1341	return true;
1342};
1343
1344BX.CClockSelector.prototype.onClockRegister = function(obClocks)
1345{
1346	if (obClocks[this.CLOCK_ID])
1347	{
1348		this.obClocks[this.CLOCK_ID] = obClocks[this.CLOCK_ID];
1349		BX.removeCustomEvent('onClockRegister', BX.proxy(this.onClockRegister, this));
1350	}
1351};
1352
1353BX.CClockSelector.prototype.Ready = function(data)
1354{
1355	this.content = this.CreateContent(data);
1356	this.WND.setContent(this.content);
1357
1358	this.isReady = true;
1359	//BX.timeman.closeWait();
1360
1361	setTimeout(BX.proxy(this.Show, this), 30);
1362};
1363
1364BX.CClockSelector.prototype.CreateContent = function(data)
1365{
1366	return BX.create('DIV', {
1367		events: {click: BX.PreventDefault},
1368		html:
1369			'<div class="bx-tm-popup-clock">' + data + '</div>'
1370	});
1371};
1372
1373BX.CClockSelector.prototype.setValue = function(e)
1374{
1375	if (this.params.callback)
1376	{
1377		var input = BX.findChild(this.content, {tagName: 'INPUT'}, true);
1378		this.params.callback.apply(this.params.node, [input.value]);
1379	}
1380
1381	return BX.PreventDefault(e);
1382};
1383
1384BX.CClockSelector.prototype.closeWnd = function(e)
1385{
1386	this.WND.close();
1387	return (e || window.event) ? BX.PreventDefault(e) : true;
1388};
1389
1390BX.CClockSelector.prototype.setNode = function(node)
1391{
1392	this.WND.setBindElement(node);
1393};
1394
1395BX.CClockSelector.prototype.setTime = function(timestamp)
1396{
1397	this.params.start_time = timestamp;
1398	if (window['bxClock_' + this.obClocks[this.CLOCK_ID]])
1399	{
1400		window['bxClock_' +  this.obClocks[this.CLOCK_ID]].SetTime(parseInt(timestamp/3600), parseInt((timestamp%3600)/60));
1401	}
1402};
1403
1404BX.CClockSelector.prototype.setCallback = function(cb)
1405{
1406	this.params.callback = cb;
1407};
1408
1409BX.CClockSelector.prototype.onPopupClose = function()
1410{
1411	this.SHOW = false;
1412};
1413
1414})();

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.