PageSourceSearch

https://sib-lada.ru/bitrix/js/main/session.js

js sib-lada.ru collected 2026-09-26 12:37:51 UTC 3,344 bytes, 129 lines download raw bytes

1function CBXSession()
2{
3	var _this = this;
4	this.dateInput = new Date();
5	this.dateCheck = new Date();
6	this.dateHit = new Date();
7	this.notifier = null;
8	this.checkInterval = 60;
9
10	this.Expand = function(key)
11	{
12		this.key = key;
13
14		BX.ready(function(){
15			BX.bind(document, "keypress", _this.OnUserInput);
16			BX.bind(document.body, "mousemove", _this.OnUserInput);
17			BX.bind(document.body, "click", _this.OnUserInput);
18
19			//check the state once in a minute
20			setInterval(_this.CheckSession, _this.checkInterval*1000);
21		})
22	};
23
24	this.OnUserInput = function()
25	{
26		var curr = new Date();
27		_this.dateInput.setTime(curr.valueOf());
28	};
29
30	this.CheckSession = function()
31	{
32		var currentDate = new Date();
33
34		if((currentDate - _this.dateCheck) < (_this.checkInterval - 1))
35		{
36			//storm protection, e.g. after PC wake-up
37			return;
38		}
39
40		_this.dateCheck.setTime(currentDate.valueOf());
41
42		if(_this.dateInput > _this.dateHit)
43		{
44			//there was input after the last hit, expand/check the session
45			var config = {
46				'method': 'GET',
47				'headers': [
48					{'name': 'X-Bitrix-Csrf-Token', 'value': BX.bitrix_sessid()}
49				],
50				'dataType': 'html',
51				'url': '/bitrix/tools/public_session.php?k='+_this.key,
52				'data':  '',
53				'onsuccess': function(data){_this.CheckResult(data)},
54				'lsId': 'sess_expand', //caching the result in the local storage for multiple tabs
55				'lsTimeout': _this.checkInterval - 5 //some delta for response time
56			};
57			BX.ajax(config);
58		}
59	};
60
61	this.CheckResult = function(data)
62	{
63		var currentDate = new Date();
64		_this.dateHit.setTime(currentDate.valueOf());
65
66		if(data == 'SESSION_EXPIRED')
67		{
68			if(BX.message("SessExpired"))
69			{
70				if(!_this.notifier)
71				{
72					_this.notifier = document.body.appendChild(BX.create('DIV', {
73						props: {className: 'bx-session-message'},
74						style: {
75							top: '0',
76							backgroundColor: '#FFEB41',
77							border: '1px solid #EDDA3C',
78							width: '630px',
79							fontFamily: 'Arial,Helvetica,sans-serif',
80							fontSize: '13px',
81							fontWeight: 'bold',
82							textAlign: 'center',
83							color: 'black',
84							position: 'absolute',
85							zIndex: '10000',
86							padding: '10px'
87						},
88						html: '<a class="bx-session-message-close" ' +
89							'style="display:block; width:12px; height:12px; background:url(/bitrix/js/main/core/images/close.gif) center no-repeat; float:right;" ' +
90							'href="javascript:bxSession.Close()"></a>' +
91							BX.message("SessExpired")
92					}));
93
94					BX.ZIndexManager.register(_this.notifier);
95					BX.ZIndexManager.bringToFront(_this.notifier);
96
97					var windowScroll = BX.GetWindowScrollPos();
98					var windowSize = BX.GetWindowInnerSize();
99
100					_this.notifier.style.left = parseInt(windowScroll.scrollLeft + (windowSize.innerWidth / 2) - (parseInt(_this.notifier.clientWidth) / 2)) + 'px';
101
102					if(BX.browser.IsIE())
103					{
104						_this.notifier.style.top = windowScroll.scrollTop + 'px';
105
106						BX.bind(window, 'scroll', function()
107						{
108							var windowScroll = BX.GetWindowScrollPos();
109							_this.notifier.style.top = windowScroll.scrollTop + 'px';
110						});
111					}
112					else
113					{
114						_this.notifier.style.position='fixed';
115					}
116				}
117
118				_this.notifier.style.display = '';
119			}
120		}
121	};
122
123	this.Close = function()
124	{
125		this.notifier.style.display = 'none';
126	}
127}
128
129var bxSession = new CBXSession();

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.