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