PageSourceSearch

https://placebooks.eu/bitrix/js/main/core/core_date.js

js placebooks.eu collected 2026-09-30 03:04:45 UTC 33,995 bytes, 1,373 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(new Date(parseInt(BX.proxy_context.getAttribute('data-date'))), e.type=='dblclick')
340		}, this);
341
342		this.DIV = BX.create('DIV', {
343			props: {className: 'bx-calendar'},
344			children: [
345				BX.create('DIV', {
346					props: {
347						className: 'bx-calendar-header'
348					},
349					children: [
350						BX.create('A', {
351							attrs: {href: 'javascript:void(0)'},
352							props: {className: 'bx-calendar-left-arrow'},
353							events: {click: BX.proxy(this._prev, this)}
354						}),
355
356						BX.create('SPAN', {
357							props: {className: 'bx-calendar-header-content'},
358							children: [
359								(this.PARTS.MONTH = BX.create('A', {
360									attrs: {href: 'javascript:void(0)'},
361									props: {className: 'bx-calendar-top-month'},
362									events: {click: BX.proxy(this._menu_month, this)}
363								})),
364
365								(this.PARTS.YEAR = BX.create('A', {
366									attrs: {href: 'javascript:void(0)'},
367									props: {className: 'bx-calendar-top-year'},
368									events: {click: BX.proxy(this._menu_year, this)}
369								}))
370							]
371						}),
372
373						BX.create('A', {
374							attrs: {href: 'javascript:void(0)'},
375							props: {className: 'bx-calendar-right-arrow'},
376							events: {click: BX.proxy(this._next, this)}
377						})
378					]
379				}),
380
381				(this.PARTS.WEEK = BX.create('DIV', {
382					props: {
383						className: 'bx-calendar-name-day-wrap'
384					}
385				})),
386
387				(this.PARTS.LAYERS = BX.create('DIV', {
388					props: {
389						className: 'bx-calendar-cell-block'
390					},
391					events: {
392						click: BX.delegateEvent({className: 'bx-calendar-cell'}, _layer_onclick),
393						dblclick: BX.delegateEvent({className: 'bx-calendar-cell'}, _layer_onclick)
394					}
395				})),
396
397				(this.PARTS.TIME = BX.create('DIV', {
398					props: {
399						className: 'bx-calendar-set-time-wrap'
400					},
401					events: {
402						click: BX.delegateEvent(
403							{attr: 'data-action'},
404							BX.delegate(this._time_actions, this)
405						)
406					},
407					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>'
408				})),
409
410				BX.create('DIV', {
411					props: {className: 'bx-calendar-button-block'},
412					events: {
413						click: BX.delegateEvent(
414							{attr: 'data-action'},
415							BX.delegate(this._button_actions, this)
416						)
417					},
418					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>'
419				})
420			]
421		});
422
423		this.PARTS.TIME_INPUT_H = BX.findChild(this.PARTS.TIME, {tag: 'INPUT'}, true);
424		this.PARTS.TIME_INPUT_M = this.PARTS.TIME_INPUT_H.nextSibling.nextSibling;
425
426		if (this.bAmPm)
427			this.PARTS.TIME_AMPM = this.PARTS.TIME_INPUT_M.nextSibling.firstChild;
428
429		var spinner = (new BX.JCSpinner({
430			input: this.PARTS.TIME_INPUT_H,
431			callback_change: BX.proxy(this._check_time, this),
432			bSaveValue: false
433		})).Show();
434		spinner.className = 'bx-calendar-form-arrow-l';
435		this.PARTS.TIME_INPUT_H.parentNode.insertBefore(spinner, this.PARTS.TIME_INPUT_H);
436
437		spinner = (new BX.JCSpinner({
438			input: this.PARTS.TIME_INPUT_M,
439			callback_change: BX.proxy(this._check_time, this),
440			bSaveValue: true
441		})).Show();
442		spinner.className = 'bx-calendar-form-arrow-r';
443		if (!this.PARTS.TIME_INPUT_M.nextSibling)
444			this.PARTS.TIME_INPUT_M.parentNode.appendChild(spinner);
445		else
446			this.PARTS.TIME_INPUT_M.parentNode.insertBefore(spinner, this.PARTS.TIME_INPUT_M.nextSibling);
447
448		for (var i = 0; i < 7; i++)
449		{
450			this.PARTS.WEEK.appendChild(BX.create('SPAN', {
451				props: {
452					className: 'bx-calendar-name-day'
453				},
454				text: BX.message('DOW_' + ((i + this.weekStart) % 7))
455			}));
456		}
457
458		return this.DIV;
459	};
460
461	this._time_actions = function()
462	{
463		switch (BX.proxy_context.getAttribute('data-action'))
464		{
465			case 'time_show':
466				BX.addClass(this.PARTS.TIME, 'bx-calendar-set-time-opened');
467				this.popup.adjustPosition();
468			break;
469			case 'time_hide':
470				BX.removeClass(this.PARTS.TIME, 'bx-calendar-set-time-opened');
471				this.popup.adjustPosition();
472			break;
473			case 'time_ampm':
474				this.PARTS.TIME_AMPM.innerHTML = this.PARTS.TIME_AMPM.innerHTML == 'AM' ? 'PM' : 'AM';
475			break;
476			case 'time_ampm_up':
477				this._check_time({bSaveValue: false}, null, 12);
478				return;
479			break;
480			case 'time_ampm_down':
481				this._check_time({bSaveValue: false}, null, -12);
482				return;
483			break;
484		}
485
486		this._check_time();
487	};
488
489	this._button_actions = function()
490	{
491		switch (BX.proxy_context.getAttribute('data-action'))
492		{
493			case 'submit':
494				this.SaveValue();
495			break;
496			case 'cancel':
497				this.Close();
498			break;
499		}
500	};
501
502	this._check_time = function(params, value, direction)
503	{
504		var h = parseInt(this.PARTS.TIME_INPUT_H.value.substring(0,5),10)||0,
505			m = parseInt(this.PARTS.TIME_INPUT_M.value.substring(0,5),10)||0,
506			bChanged = false;
507
508		if (!!params && !params.bSaveValue)
509		{
510			this.value.setUTCHours(this.value.getUTCHours() + direction);
511		}
512		else if (!isNaN(h))
513		{
514			if (this.bAmPm)
515			{
516				if (h != 12 && this.PARTS.TIME_AMPM.innerHTML == 'PM')
517				{
518					h += 12;
519				}
520			}
521
522			bChanged = true;
523			this.value.setUTCHours(h % 24);
524		}
525
526		if (!isNaN(m))
527		{
528			bChanged = true;
529			this.value.setUTCMinutes(m % 60);
530		}
531
532		if (bChanged)
533		{
534			this.SetValue(this.value);
535		}
536	};
537
538	this._set_layer = function()
539	{
540		var layerId = parseInt(this.value.getUTCFullYear() + '' + BX.util.str_pad_left(this.value.getUTCMonth()+'', 2, "0"));
541
542		if (!this._layers[layerId])
543		{
544			this._layers[layerId] = this._create_layer();
545			this._layers[layerId].BXLAYERID = layerId;
546		}
547
548		if (this._current_layer)
549		{
550			var v = new Date(this.value.valueOf());
551			v.setUTCHours(0); v.setUTCMinutes(0);
552
553			var cur_value = BX.findChild(this._layers[layerId], {
554					tag: 'A',
555					className: 'bx-calendar-active'
556				}, true),
557				new_value = BX.findChild(this._layers[layerId], {
558					tag: 'A',
559					attr: {
560						'data-date' : v.valueOf() + ''
561					}
562				}, true);
563
564			if (cur_value)
565			{
566				BX.removeClass(cur_value, 'bx-calendar-active');
567			}
568
569			if (new_value)
570			{
571				BX.addClass(new_value, 'bx-calendar-active');
572			}
573
574			this._replace_layer(this._current_layer, this._layers[layerId]);
575		}
576		else
577		{
578			this.PARTS.LAYERS.appendChild(this._layers[layerId]);
579		}
580
581		this._current_layer = this._layers[layerId];
582	};
583
584	this._replace_layer = function(old_layer, new_layer)
585	{
586		if (old_layer != new_layer)
587		{
588			if (!BX.browser.IsIE() || BX.browser.IsDoctype())
589			{
590				var dir = old_layer.BXLAYERID > new_layer.BXLAYERID ? 1 : -1;
591
592				var old_top = 0;
593				var new_top = -dir * old_layer.offsetHeight;
594
595				old_layer.style.position = 'relative';
596				old_layer.style.top = "0px";
597				old_layer.style.zIndex = 5;
598
599				new_layer.style.position = 'absolute';
600				new_layer.style.top = new_top + 'px';
601				new_layer.style.zIndex = 6;
602
603				this.PARTS.LAYERS.appendChild(new_layer);
604
605				var delta = 15;
606
607				var f;
608				(f = function() {
609					new_top += dir * delta;
610					old_top += dir * delta;
611
612					if (dir * new_top < 0)
613					{
614						old_layer.style.top = old_top + 'px';
615						new_layer.style.top = new_top + 'px';
616						setTimeout(f, 10);
617					}
618					else
619					{
620						old_layer.parentNode.removeChild(old_layer);
621
622						new_layer.style.top = "0px";
623						new_layer.style.position = 'static';
624						new_layer.style.zIndex = 0;
625					}
626				})();
627			}
628			else
629			{
630				this.PARTS.LAYERS.replaceChild(new_layer, old_layer);
631			}
632		}
633	};
634
635	this._create_layer = function()
636	{
637		var l = BX.create('DIV', {
638			props: {
639				className: 'bx-calendar-layer'
640			}
641		});
642
643		var month_start = new Date(this.value);
644		month_start.setUTCHours(0);
645		month_start.setUTCMinutes(0);
646
647		month_start.setUTCDate(1);
648
649		if (month_start.getUTCDay() != this.weekStart)
650		{
651			var d = month_start.getUTCDay() - this.weekStart;
652			d += d < 0 ? 7 : 0;
653			month_start.setUTCDate(month_start.getUTCDate()-d);
654		}
655
656		var cur_month = this.value.getUTCMonth(),
657			cur_day = this.value.getUTCDate(),
658			s = '';
659		for (var i = 0; i < this.numRows; i++)
660		{
661			s += '<div class="bx-calendar-range'
662				+(i == this.numRows-1 ? ' bx-calendar-range-noline' : '')
663				+'">';
664
665			for (var j = 0; j < 7; j++)
666			{
667				d = month_start.getUTCDate();
668				var wd = month_start.getUTCDay();
669				var className = 'bx-calendar-cell';
670
671				if (cur_month != month_start.getUTCMonth())
672					className += ' bx-calendar-date-hidden';
673				else if (cur_day == d)
674					className += ' bx-calendar-active';
675
676
677				if (wd == 0 || wd == 6)
678					className += ' bx-calendar-weekend';
679
680				s += '<a href="javascript:void(0)" class="'+className+'" data-date="' + month_start.valueOf() + '">' + d + '</a>';
681
682				month_start.setUTCDate(month_start.getUTCDate()+1);
683			}
684			s += '</div>';
685		}
686
687		l.innerHTML = s;
688
689		return l;
690	};
691
692	this._prev = function()
693	{
694		this.SetMonth(this.value.getUTCMonth()-1);
695	};
696
697	this._next = function()
698	{
699		this.SetMonth(this.value.getUTCMonth()+1);
700	};
701
702	this._menu_month_content = function()
703	{
704		var months = '', cur_month = this.value.getMonth(), i;
705		for (i = 0; i < 12; i++)
706		{
707			months += '<span class="bx-calendar-month'+(i == cur_month ? ' bx-calendar-month-active' : '')+'" data-bx-month="' + i + '">' + BX.message('MONTH_' + (i + 1)) + '</span>';
708		}
709
710		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>';
711	};
712
713	this._menu_month = function()
714	{
715		if (!this.popup_month)
716		{
717			this.popup_month = new BX.PopupWindow(
718				'calendar_popup_month_' + this.control_id, this.PARTS.MONTH,
719				{
720					content: this._menu_month_content(),
721					zIndex: 3001,
722					closeByEsc: true,
723					autoHide: true,
724					offsetTop: -29,
725					offsetLeft: -1,
726					className: this.month_popup_classname,
727					events: {
728						onPopupShow: BX.delegate(function() {
729							if (this.popup_year)
730							{
731								this.popup_year.close();
732							}
733						}, this)
734					}
735				}
736			);
737
738			BX.bind(this.popup_month.popupContainer, 'click', BX.proxy(this.month_popup_click, this));
739			this.popup_month.BXMONTH = this.value.getUTCMonth();
740		}
741		else if (this.popup_month.BXMONTH != this.value.getUTCMonth())
742		{
743			this.popup_month.setContent(this._menu_month_content());
744			this.popup_month.BXMONTH = this.value.getUTCMonth();
745		}
746
747		this.popup_month.show();
748	};
749
750	this.month_popup_click = function(e)
751	{
752		var target = e.target || e.srcElement;
753		if (target && target.getAttribute && target.getAttribute('data-bx-month'))
754		{
755			this.SetMonth(parseInt(target.getAttribute('data-bx-month')));
756			this.popup_month.close();
757		}
758	};
759
760	this._menu_year_content = function()
761	{
762		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">';
763
764		for (var i=-3; i <= 3; i++)
765		{
766			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>';
767		}
768
769		s += '</div><input data-bx-year-input="Y" type="text" class="bx-calendar-year-input" maxlength="4" /></div>';
770
771		return s;
772	};
773
774	this._menu_year = function()
775	{
776		if (!this.popup_year)
777		{
778			this.popup_year = new BX.PopupWindow(
779				'calendar_popup_year_' + this.control_id, this.PARTS.YEAR,
780				{
781					content: this._menu_year_content(),
782					zIndex: 3001,
783					closeByEsc: true,
784					autoHide: true,
785					offsetTop: -29,
786					offsetLeft: -1,
787					className: this.year_popup_classname,
788					events: {
789						onPopupShow: BX.delegate(function() {
790							if (this.popup_month)
791							{
792								this.popup_month.close();
793							}
794						}, this)
795					}
796				}
797			);
798
799			BX.bind(this.popup_year.popupContainer, 'click', BX.proxy(this.year_popup_click, this));
800			BX.bind(this.popup_year.popupContainer, 'keyup', BX.proxy(this.year_popup_keyup, this));
801			this.popup_year.BXYEAR = this.value.getUTCFullYear();
802		}
803		else if (this.popup_year.BXYEAR != this.value.getUTCFullYear())
804		{
805			this.popup_year.setContent(this._menu_year_content());
806			this.popup_year.BXYEAR = this.value.getUTCFullYear();
807		}
808
809		this.popup_year.show();
810	};
811
812	this.year_popup_click = function(e)
813	{
814		var target = e.target || e.srcElement;
815		if (target && target.getAttribute && target.getAttribute('data-bx-year'))
816		{
817			this.SetYear(parseInt(target.getAttribute('data-bx-year')));
818			this.popup_year.close();
819		}
820	};
821	this.year_popup_keyup = function(e)
822	{
823		var target = e.target || e.srcElement;
824		if (target && target.getAttribute && target.getAttribute('data-bx-year-input') == 'Y')
825		{
826			var value = parseInt(target.value);
827			if(value >= 1900 && value <= 2100)
828			{
829				this.SetYear(value);
830				this.popup_year.close();
831			}
832		}
833	};
834
835	this._check_date = function(v)
836	{
837		var res = v;
838
839		if (BX.type.isString(v))
840		{
841			res = BX.parseDate(v, true);
842		}
843
844		if (!BX.type.isDate(res) || isNaN(res.valueOf()))
845		{
846			res = BX.date.convertToUTC(new Date());
847			if (this.params.bHideTime)
848			{
849				res.setUTCHours(0);
850				res.setUTCMinutes(0);
851			}
852		}
853
854		res.setUTCMilliseconds(0);
855		res.setUTCSeconds(0);
856
857		res.BXCHECKED = true;
858
859		return res;
860	};
861};
862
863BX.JCCalendar.prototype.Show = function(params)
864{
865	if (!BX.isReady)
866	{
867		BX.ready(BX.delegate(function() {this.Show(params)}, this));
868		return;
869	}
870
871	params.node = params.node||document.body;
872
873	if (BX.type.isNotEmptyString(params.node))
874	{
875		var n = BX(params.node);
876		if (!n)
877		{
878			n = document.getElementsByName(params.node);
879			if (n && n.length > 0)
880			{
881				n = n[0]
882			}
883		}
884		params.node = n;
885	}
886
887	if (!params.node)
888		return;
889
890	if (!!params.field)
891	{
892		if (BX.type.isString(params.field))
893		{
894			n = BX(params.field);
895			if (!!n)
896			{
897				params.field = n;
898			}
899			else
900			{
901				if (params.form)
902				{
903					if (BX.type.isString(params.form))
904					{
905						params.form = document.forms[params.form];
906					}
907				}
908
909				if (BX.type.isDomNode(params.form) && !!params.form[params.field])
910				{
911					params.field = params.form[params.field];
912				}
913				else
914				{
915					n = document.getElementsByName(params.field);
916					if (n && n.length > 0)
917					{
918						n = n[0];
919						params.field = n;
920					}
921				}
922			}
923
924			if (BX.type.isString(params.field))
925			{
926				params.field = BX(params.field);
927			}
928		}
929	}
930
931	var bShow = !this.popup || !this.popup.isShown() || this.params.node != params.node;
932
933	this.params = params;
934
935	this.params.bTime = typeof this.params.bTime == 'undefined' ? true : !!this.params.bTime;
936	this.params.bHideTime = typeof this.params.bHideTime == 'undefined' ? true : !!this.params.bHideTime;
937	this.params.bUseSecond = typeof this.params.bUseSecond == 'undefined' ? true : !!this.params.bUseSecond;
938
939	this.weekStart = parseInt(this.params.weekStart || this.params.weekStart || BX.message('WEEK_START'));
940	if (isNaN(this.weekStart))
941		this.weekStart = 1;
942
943	if (!this.popup)
944	{
945		this._create(this.params);
946	}
947	else
948	{
949		this.popup.setBindElement(this.params.node);
950	}
951
952	var bHideTime = !!this.params.bHideTime;
953	if (this.params.value)
954	{
955		this.SetValue(this.params.value);
956		bHideTime = this.value.getUTCHours() <= 0 && this.value.getUTCMinutes() <= 0;
957	}
958	else if (this.params.field)
959	{
960		this.SetValue(this.params.field.value);
961		bHideTime = this.value.getUTCHours() <= 0 && this.value.getUTCMinutes() <= 0;
962	}
963	else if (!!this.params.currentTime)
964	{
965		this.SetValue(this.params.currentTime);
966	}
967	else
968	{
969		this.SetValue();
970	}
971
972	if (!!this.params.bTime)
973		BX.removeClass(this.DIV, 'bx-calendar-time-disabled');
974	else
975		BX.addClass(this.DIV, 'bx-calendar-time-disabled');
976
977	if (!!bHideTime)
978		BX.removeClass(this.PARTS.TIME, 'bx-calendar-set-time-opened');
979	else
980		BX.addClass(this.PARTS.TIME, 'bx-calendar-set-time-opened');
981
982	if (bShow)
983	{
984		this._auto_hide_disable();
985		this.popup.show();
986		setTimeout(BX.proxy(this._auto_hide_enable, this), 0);
987	}
988
989	this.params.bSetFocus = typeof this.params.bSetFocus == 'undefined' ? true : !!this.params.bSetFocus;
990	if(this.params.bSetFocus)
991	{
992		params.node.blur();
993	}
994	else
995	{
996		BX.bind(params.node, 'keyup', BX.defer(function(){
997			this.SetValue(params.node.value);
998			if(!!this.params.bTime)
999			{
1000				if(this.value.getUTCHours() <= 0 && this.value.getUTCMinutes() <= 0)
1001					BX.removeClass(this.PARTS.TIME, 'bx-calendar-set-time-opened');
1002				else
1003					BX.addClass(this.PARTS.TIME, 'bx-calendar-set-time-opened');
1004			}
1005		}, this));
1006	}
1007
1008	return this;
1009};
1010
1011BX.JCCalendar.prototype.SetDay = function(d)
1012{
1013	this.value.setUTCDate(d);
1014	return this.SetValue(this.value);
1015};
1016
1017BX.JCCalendar.prototype.SetMonth = function(m)
1018{
1019	if (this.popup_month)
1020		this.popup_month.close();
1021
1022	this.value.setUTCMonth(m);
1023
1024	if(m < 0)
1025		m += 12;
1026	else if (m >= 12)
1027		m -= 12;
1028
1029	while(this.value.getUTCMonth() > m)
1030	{
1031		this.value.setUTCDate(this.value.getUTCDate()-1);
1032	}
1033
1034	return this.SetValue(this.value);
1035};
1036
1037BX.JCCalendar.prototype.SetYear = function(y)
1038{
1039	if (this.popup_year)
1040		this.popup_year.close();
1041	this.value.setUTCFullYear(y);
1042	return this.SetValue(this.value);
1043};
1044
1045BX.JCCalendar.prototype.SetDate = function(v, bSet)
1046{
1047	v = this._check_date(v);
1048	v.setUTCHours(this.value.getUTCHours());
1049	v.setUTCMinutes(this.value.getUTCMinutes());
1050	v.setUTCSeconds(this.value.getUTCSeconds());
1051
1052	if (this.params.bTime && !bSet)
1053	{
1054		return this.SetValue(v);
1055	}
1056	else
1057	{
1058		this.SetValue(v);
1059		this.SaveValue();
1060	}
1061};
1062
1063BX.JCCalendar.prototype.SetValue = function(v)
1064{
1065	this.value = (v && v.BXCHECKED) ? v : this._check_date(v);
1066
1067	this.PARTS.MONTH.innerHTML = BX.message('MONTH_' + (this.value.getUTCMonth()+1));
1068	this.PARTS.YEAR.innerHTML = this.value.getUTCFullYear();
1069
1070	if (!!this.params.bTime)
1071	{
1072		var h = this.value.getUTCHours();
1073		if (this.bAmPm)
1074		{
1075			if (h >= 12)
1076			{
1077				this.PARTS.TIME_AMPM.innerHTML = 'PM';
1078
1079				if (h != 12)
1080					h -= 12;
1081			}
1082			else
1083			{
1084				this.PARTS.TIME_AMPM.innerHTML = 'AM';
1085
1086				if (h == 0)
1087					h = 12;
1088			}
1089		}
1090
1091		this.PARTS.TIME_INPUT_H.value = BX.util.str_pad_left(h.toString(), 2, "0");
1092		this.PARTS.TIME_INPUT_M.value = BX.util.str_pad_left(this.value.getUTCMinutes().toString(), 2, "0");
1093	}
1094
1095	this._set_layer();
1096
1097	return this;
1098};
1099
1100BX.JCCalendar.prototype.SaveValue = function()
1101{
1102	if (this.popup_month)
1103		this.popup_month.close();
1104	if (this.popup_year)
1105		this.popup_year.close();
1106
1107	var bSetValue = true;
1108	if (!!this.params.callback)
1109	{
1110		var res = this.params.callback.apply(this, [new Date(this.value.valueOf()+this.value.getTimezoneOffset()*60000)]);
1111		if (res === false)
1112			bSetValue = false;
1113	}
1114
1115	if (bSetValue)
1116	{
1117		var bTime = !!this.params.bTime && BX.hasClass(this.PARTS.TIME, 'bx-calendar-set-time-opened');
1118
1119		if (this.params.field)
1120		{
1121			var format = BX.message(bTime ? 'FORMAT_DATETIME' : 'FORMAT_DATE');
1122
1123			if(bTime && !this.params.bUseSecond)
1124			{
1125				format = format.replace(':SS', '');
1126			}
1127
1128			this.params.field.value = BX.calendar.ValueToStringFormat(this.value, format, true);
1129			BX.fireEvent(this.params.field, 'change');
1130		}
1131
1132		this.popup.close();
1133
1134		if (!!this.params.callback_after)
1135		{
1136			this.params.callback_after.apply(this, [new Date(this.value.valueOf()+this.value.getTimezoneOffset()*60000), bTime]);
1137		}
1138	}
1139
1140	return this;
1141};
1142
1143BX.JCCalendar.prototype.Close = function()
1144{
1145	if (!!this.popup)
1146		this.popup.close();
1147
1148	return this;
1149};
1150
1151BX.JCSpinner = function(params)
1152{
1153	params = params || {};
1154	this.params = {
1155		input: params.input || null,
1156
1157		delta: params.delta || 1,
1158
1159		timeout_start: params.timeout_start || 1000,
1160		timeout_cont: params.timeout_cont || 150,
1161
1162		callback_start: params.callback_start || null,
1163		callback_change: params.callback_change || null,
1164		callback_finish: params.callback_finish || null,
1165
1166		bSaveValue: typeof params.bSaveValue == 'undefined' ? !!params.input : !!params.bSaveValue
1167	};
1168
1169	this.mousedown = false;
1170	this.direction = 1;
1171};
1172
1173BX.JCSpinner.prototype.Show = function()
1174{
1175	this.node = BX.create('span', {
1176		events: {
1177			mousedown: BX.delegateEvent(
1178				{attr: 'data-dir'},
1179				BX.delegate(this.Start, this)
1180			)
1181		},
1182		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>'
1183	});
1184	return this.node;
1185};
1186
1187BX.JCSpinner.prototype.Start = function()
1188{
1189	this.mousedown = true;
1190	this.direction = BX.proxy_context.getAttribute('data-dir') > 0 ? 1 : -1;
1191	BX.bind(document, "mouseup", BX.proxy(this.MouseUp, this));
1192	this.ChangeValue(true);
1193};
1194
1195BX.JCSpinner.prototype.ChangeValue = function(bFirst)
1196{
1197	if(!this.mousedown)
1198		return;
1199
1200	if (this.params.input)
1201	{
1202		var v = parseInt(this.params.input.value, 10) + this.params.delta * this.direction;
1203
1204		if (this.params.bSaveValue)
1205			this.params.input.value = v;
1206
1207		if (!!bFirst && this.params.callback_start)
1208			this.params.callback_start(this.params, v, this.direction);
1209
1210		if (this.params.callback_change)
1211			this.params.callback_change(this.params, v, this.direction);
1212
1213		setTimeout(
1214			BX.proxy(this.ChangeValue, this),
1215			!!bFirst ? this.params.timeout_start : this.params.timeout_cont
1216		);
1217	}
1218};
1219
1220BX.JCSpinner.prototype.MouseUp = function()
1221{
1222	this.mousedown = false;
1223	BX.unbind(document, "mouseup", BX.proxy(this.MouseUp, this));
1224
1225	if (this.params.callback_finish)
1226		this.params.callback_finish(this.params, this.params.input.value);
1227};
1228
1229/**************** compatibility hacks ***************************/
1230
1231window.jsCalendar = {
1232	Show: function(obj, field, fieldFrom, fieldTo, bTime, serverTime, form_name, bHideTimebar)
1233	{
1234		return BX.calendar({
1235			node: obj, field: field, form: form_name, bTime: !!bTime, currentTime: serverTime, bHideTimebar: !!bHideTimebar
1236		});
1237	},
1238
1239	ValueToString: BX.calendar.ValueToString
1240};
1241
1242
1243/************ clock popup transferred from timeman **************/
1244
1245BX.CClockSelector = function(params)
1246{
1247	this.params = params;
1248
1249	this.params.popup_buttons = this.params.popup_buttons || [
1250		new BX.PopupWindowButton({
1251			text : BX.message('CAL_BUTTON'),
1252			className : "popup-window-button-create",
1253			events : {click : BX.proxy(this.setValue, this)}
1254		})
1255	];
1256
1257	this.isReady = false;
1258
1259	this.WND = new BX.PopupWindow(
1260		this.params.popup_id || 'clock_selector_popup',
1261		this.params.node,
1262		this.params.popup_config || {
1263			titleBar: BX.message('CAL_TIME'),
1264			offsetLeft: -45,
1265			offsetTop: -135,
1266			autoHide: true,
1267			closeIcon: true,
1268			closeByEsc: true,
1269			zIndex: this.params.zIndex
1270		}
1271	);
1272
1273	this.SHOW = false;
1274	BX.addCustomEvent(this.WND, "onPopupClose", BX.delegate(this.onPopupClose, this));
1275
1276	this.obClocks = {};
1277	this.CLOCK_ID = this.params.clock_id || 'clock_selector';
1278};
1279
1280BX.CClockSelector.prototype.Show = function()
1281{
1282	if (!this.isReady)
1283	{
1284		//BX.timeman.showWait(this.parent.DIV);
1285
1286		BX.addCustomEvent('onClockRegister', BX.proxy(this.onClockRegister, this));
1287		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));
1288	}
1289
1290	this.WND.setButtons(this.params.popup_buttons);
1291	this.WND.show();
1292
1293	this.SHOW = true;
1294
1295	if (window['bxClock_' + this.obClocks[this.CLOCK_ID]])
1296	{
1297		setTimeout("window['bxClock_" + this.obClocks[this.CLOCK_ID] + "'].CalculateCoordinates()", 40);
1298	}
1299
1300	return true;
1301};
1302
1303BX.CClockSelector.prototype.onClockRegister = function(obClocks)
1304{
1305	if (obClocks[this.CLOCK_ID])
1306	{
1307		this.obClocks[this.CLOCK_ID] = obClocks[this.CLOCK_ID];
1308		BX.removeCustomEvent('onClockRegister', BX.proxy(this.onClockRegister, this));
1309	}
1310};
1311
1312BX.CClockSelector.prototype.Ready = function(data)
1313{
1314	this.content = this.CreateContent(data);
1315	this.WND.setContent(this.content);
1316
1317	this.isReady = true;
1318	//BX.timeman.closeWait();
1319
1320	setTimeout(BX.proxy(this.Show, this), 30);
1321};
1322
1323BX.CClockSelector.prototype.CreateContent = function(data)
1324{
1325	return BX.create('DIV', {
1326		events: {click: BX.PreventDefault},
1327		html:
1328			'<div class="bx-tm-popup-clock">' + data + '</div>'
1329	});
1330};
1331
1332BX.CClockSelector.prototype.setValue = function(e)
1333{
1334	if (this.params.callback)
1335	{
1336		var input = BX.findChild(this.content, {tagName: 'INPUT'}, true);
1337		this.params.callback.apply(this.params.node, [input.value]);
1338	}
1339
1340	return BX.PreventDefault(e);
1341};
1342
1343BX.CClockSelector.prototype.closeWnd = function(e)
1344{
1345	this.WND.close();
1346	return (e || window.event) ? BX.PreventDefault(e) : true;
1347};
1348
1349BX.CClockSelector.prototype.setNode = function(node)
1350{
1351	this.WND.setBindElement(node);
1352};
1353
1354BX.CClockSelector.prototype.setTime = function(timestamp)
1355{
1356	this.params.start_time = timestamp;
1357	if (window['bxClock_' + this.obClocks[this.CLOCK_ID]])
1358	{
1359		window['bxClock_' +  this.obClocks[this.CLOCK_ID]].SetTime(parseInt(timestamp/3600), parseInt((timestamp%3600)/60));
1360	}
1361};
1362
1363BX.CClockSelector.prototype.setCallback = function(cb)
1364{
1365	this.params.callback = cb;
1366};
1367
1368BX.CClockSelector.prototype.onPopupClose = function()
1369{
1370	this.SHOW = false;
1371};
1372
1373})();

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.