https://samara.arshini.ru/local/templates/aspro_tires2/components/bitrix/search.title/corp/script.js
1function JCTitleSearch2(arParams) 2{ 3 var _this = this; 4 5 this.arParams = { 6 'AJAX_PAGE': arParams.AJAX_PAGE, 7 'CONTAINER_ID': arParams.CONTAINER_ID, 8 'INPUT_ID': arParams.INPUT_ID, 9 'INPUT_ID_TMP': arParams.INPUT_ID_TMP, 10 'MIN_QUERY_LEN': parseInt(arParams.MIN_QUERY_LEN) 11 }; 12 13 if(arParams.WAIT_IMAGE) 14 this.arParams.WAIT_IMAGE = arParams.WAIT_IMAGE; 15 if(arParams.MIN_QUERY_LEN <= 0) 16 arParams.MIN_QUERY_LEN = 1; 17 18 this.cache = []; 19 this.cache_key = null; 20 21 this.startText = ''; 22 this.running = false; 23 this.currentRow = -1; 24 this.RESULT = null; 25 this.CONTAINER = null; 26 this.INPUT = null; 27 this.WAIT = null; 28 29 this.ShowResult = function(result) 30 { 31 if(BX.type.isString(result)) 32 { 33 _this.RESULT.innerHTML = result; 34 } 35 36 _this.RESULT.style.display = _this.RESULT.innerHTML !== '' ? 'block' : 'none'; 37 var pos = _this.adjustResultNode(); 38 39 //adjust left column to be an outline 40 var res_pos; 41 var th; 42 var tbl = BX.findChild(_this.RESULT, {'tag':'table','class':'title-search-result'}, true); 43 if(tbl) 44 { 45 th = BX.findChild(tbl, {'tag':'th'}, true); 46 } 47 if(th) 48 { 49 var tbl_pos = BX.pos(tbl); 50 tbl_pos.width = tbl_pos.right - tbl_pos.left; 51 52 var th_pos = BX.pos(th); 53 th_pos.width = th_pos.right - th_pos.left; 54 th.style.width = th_pos.width + 'px'; 55 56 _this.RESULT.style.width = (pos.width + th_pos.width) + 'px'; 57 58 //Move table to left by width of the first column 59 _this.RESULT.style.left = (pos.left - th_pos.width - 1)+ 'px'; 60 61 //Shrink table when it's too wide 62 if((tbl_pos.width - th_pos.width) > pos.width) 63 _this.RESULT.style.width = (pos.width + th_pos.width -1) + 'px'; 64 65 //Check if table is too wide and shrink result div to it's width 66 tbl_pos = BX.pos(tbl); 67 res_pos = BX.pos(_this.RESULT); 68 if(res_pos.right > tbl_pos.right) 69 { 70 _this.RESULT.style.width = (tbl_pos.right - tbl_pos.left) + 'px'; 71 } 72 } 73 74 var fade; 75 if(tbl) fade = BX.findChild(_this.RESULT, {'class':'title-search-fader'}, true); 76 if(fade && th) 77 { 78 res_pos = BX.pos(_this.RESULT); 79 fade.style.left = (res_pos.right - res_pos.left - 18) + 'px'; 80 fade.style.width = 18 + 'px'; 81 fade.style.top = 0 + 'px'; 82 fade.style.height = (res_pos.bottom - res_pos.top) + 'px'; 83 fade.style.display = 'block'; 84 } 85 }; 86 87 this.onKeyPress = function(keyCode) 88 { 89 var tbl = BX.findChild(_this.RESULT, {'tag':'table','class':'title-search-result'}, true); 90 if(!tbl) 91 return false; 92 93 var i; 94 var cnt = tbl.rows.length; 95 96 switch (keyCode) 97 { 98 case 27: // escape key - close search div 99 _this.RESULT.style.display = 'none'; 100 _this.currentRow = -1; 101 _this.UnSelectAll(); 102 return true; 103 104 case 40: // down key - navigate down on search results 105 if(_this.RESULT.style.display == 'none') 106 _this.RESULT.style.display = 'block'; 107 108 var first = -1; 109 for(i = 0; i < cnt; i++) 110 { 111 if(!BX.findChild(tbl.rows[i], {'class':'title-search-separator'}, true)) 112 { 113 if(first == -1) 114 first = i; 115 116 if(_this.currentRow < i) 117 { 118 _this.currentRow = i; 119 break; 120 } 121 else if(tbl.rows[i].className == 'title-search-selected') 122 { 123 tbl.rows[i].className = ''; 124 } 125 } 126 } 127 128 if(i == cnt && _this.currentRow != i) 129 _this.currentRow = first; 130 131 tbl.rows[_this.currentRow].className = 'title-search-selected'; 132 return true; 133 134 case 38: // up key - navigate up on search results 135 if(_this.RESULT.style.display == 'none') 136 _this.RESULT.style.display = 'block'; 137 138 var last = -1; 139 for(i = cnt-1; i >= 0; i--) 140 { 141 if(!BX.findChild(tbl.rows[i], {'class':'title-search-separator'}, true)) 142 { 143 if(last == -1) 144 last = i; 145 146 if(_this.currentRow > i) 147 { 148 _this.currentRow = i; 149 break; 150 } 151 else if(tbl.rows[i].className == 'title-search-selected') 152 { 153 tbl.rows[i].className = ''; 154 } 155 } 156 } 157 158 if(i < 0 && _this.currentRow != i) 159 _this.currentRow = last; 160 161 tbl.rows[_this.currentRow].className = 'title-search-selected'; 162 return true; 163 164 case 13: // enter key - choose current search result 165 if(_this.RESULT.style.display == 'block') 166 { 167 for(i = 0; i < cnt; i++) 168 { 169 if(_this.currentRow == i) 170 { 171 if(!BX.findChild(tbl.rows[i], {'class':'title-search-separator'}, true)) 172 { 173 var a = BX.findChild(tbl.rows[i], {'tag':'a'}, true); 174 if(a) 175 { 176 window.location = a.href; 177 return true; 178 } 179 } 180 } 181 } 182 } 183 return false;
184 } 185 186 return false; 187 }; 188 189 this.onTimeout = function() 190 { 191 _this.onChange(function(){ 192 setTimeout(_this.onTimeout, 500); 193 }); 194 }; 195 196 this.onChange = function(callback) 197 { 198 if (_this.running) 199 return; 200 _this.running = true; 201 202 if(_this.INPUT.value != _this.oldValue && _this.INPUT.value != _this.startText) 203 { 204 _this.oldValue = _this.INPUT.value; 205 if(_this.INPUT.value.length >= _this.arParams.MIN_QUERY_LEN) 206 { 207 _this.cache_key = _this.arParams.INPUT_ID + '|' + _this.INPUT.value; 208 if(_this.cache[_this.cache_key] == null) 209 { 210 if(_this.WAIT) 211 { 212 var pos = BX.pos(_this.INPUT); 213 var height = (pos.bottom - pos.top)-2; 214 _this.WAIT.style.top = (pos.top+1) + 'px'; 215 _this.WAIT.style.height = height + 'px'; 216 _this.WAIT.style.width = height + 'px'; 217 _this.WAIT.style.left = (pos.right - height + 2) + 'px'; 218 _this.WAIT.style.display = 'block'; 219 } 220 221 BX.ajax.post( 222 _this.arParams.AJAX_PAGE, 223 { 224 'ajax_call':'y', 225 'INPUT_ID':_this.arParams.INPUT_ID_TMP, 226 'q':_this.INPUT.value, 227 'l':_this.arParams.MIN_QUERY_LEN 228 }, 229 function(result) 230 { 231 _this.cache[_this.cache_key] = result; 232 _this.ShowResult(result); 233 _this.currentRow = -1; 234 _this.EnableMouseEvents(); 235 if(_this.WAIT) 236 _this.WAIT.style.display = 'none'; 237 if (!!callback) 238 callback(); 239 _this.running = false; 240 } 241 ); 242 return; 243 } 244 else 245 { 246 _this.ShowResult(_this.cache[_this.cache_key]); 247 _this.currentRow = -1; 248 _this.EnableMouseEvents(); 249 } 250 } 251 else 252 { 253 _this.RESULT.style.display = 'none'; 254 _this.currentRow = -1; 255 _this.UnSelectAll(); 256 } 257 } 258 if (!!callback) 259 callback(); 260 _this.running = false; 261 }; 262 263 this.UnSelectAll = function() 264 { 265 var tbl = BX.findChild(_this.RESULT, {'tag':'table','class':'title-search-result'}, true); 266 if(tbl) 267 { 268 var cnt = tbl.rows.length; 269 for(var i = 0; i < cnt; i++) 270 tbl.rows[i].className = ''; 271 } 272 }; 273 274 this.EnableMouseEvents = function() 275 { 276 var tbl = BX.findChild(_this.RESULT, {'tag':'table','class':'title-search-result'}, true); 277 if(tbl) 278 { 279 var cnt = tbl.rows.length; 280 for(var i = 0; i < cnt; i++) 281 if(!BX.findChild(tbl.rows[i], {'class':'title-search-separator'}, true)) 282 { 283 tbl.rows[i].id = 'row_' + i; 284 tbl.rows[i].onmouseover = function (e) { 285 if(_this.currentRow != this.id.substr(4)) 286 { 287 _this.UnSelectAll(); 288 this.className = 'title-search-selected'; 289 _this.currentRow = this.id.substr(4); 290 } 291 }; 292 tbl.rows[i].onmouseout = function (e) { 293 this.className = ''; 294 _this.currentRow = -1; 295 }; 296 } 297 } 298 }; 299 300 this.onFocusLost = function(hide) 301 { 302 setTimeout(function(){_this.RESULT.style.display = 'none';}, 300); 303 // _this.RESULT.style.display = 'none'; 304 }; 305 306 this.onFocusGain = function() 307 { 308 if(_this.RESULT.innerHTML.length) 309 _this.ShowResult(); 310 }; 311 312 this.onKeyDown = function(e) 313 { 314 if(!e) 315 e = window.event; 316 if (_this.RESULT.style.display == 'block') 317 { 318 if(_this.onKeyPress(e.keyCode)) 319 return BX.PreventDefault(e); 320 } 321 }; 322 323 this.adjustResultNode = function() 324 { 325 var pos, pos_input; 326 var fixedParent = BX.findParent(_this.CONTAINER, BX.is_fixed); 327 if(!!fixedParent) 328 { 329 _this.RESULT.style.position = 'fixed'; 330 _this.RESULT.style.zIndex = BX.style(fixedParent, 'z-index') + 2; 331 pos = BX.pos(_this.CONTAINER, true); 332 } 333 else 334 { 335 _this.RESULT.style.position = 'absolute'; 336 pos = BX.pos(_this.CONTAINER); 337 } 338 pos_input = BX.pos(_this.INPUT); 339 340 pos.width = pos.right - pos.left; 341 _this.RESULT.style.top = (pos.bottom + 2) + 'px'; 342 _this.RESULT.style.left = pos_input.left + 'px'; 343 344 if($(_this.INPUT).closest('.inline-search-block.with-close').length) 345 _this.RESULT.style.width = pos_input.width + 'px'; 346 else 347 _this.RESULT.style.width = pos.width + 'px'; 348 return pos; 349 }; 350 351 this._onContainerLayoutChange = function() 352 { 353 if(_this.RESULT.style.display !== "none" && _this.RESULT.innerHTML !== '') 354 { 355 _this.adjustResultNode(); 356 } 357 }; 358 this.Init = function() 359 { 360 this.CONTAINER = document.getElementById(this.arParams.CONTAINER_ID); 361 BX.addCustomEvent(this.CONTAINER, "OnNodeLayoutChange", this._onContainerLayoutChange); 362 363 this.RESULT = document.body.appendChild(document.createElement("DIV")); 364 365 this.RESULT.className = 'title-search-result '+this.arParams.INPUT_ID; 366 this.INPUT = document.getElementById(this.arParams.INPUT_ID); 367 this.startText = this.oldValue = this.INPUT.value; 368 BX.bind(this.INPUT, 'focus', function(e) { 369 _this.onFocusGain() 370 }); 371 BX.bind(this.INPUT, 'blur', function(e) { 372 if(!$(e.relatedTarget).hasClass('bx_item_block')) 373 _this.onFocusLost(); 374 }); 375 376 if(BX.browser.IsSafari() || BX.browser.IsIE()) 377 this.INPUT.onkeydown = this.onKeyDown; 378 else 379 this.INPUT.onkeypress = this.onKeyDown; 380 381 if(this.arParams.WAIT_IMAGE) 382 { 383 this.WAIT = document.body.appendChild(document.createElement("DIV")); 384 this.WAIT.style.backgroundImage = "url('" + this.arParams.WAIT_IMAGE + "')"; 385 if(!BX.browser.IsIE()) 386 this.WAIT.style.backgroundRepeat = 'none'; 387 this.WAIT.style.display = 'none'; 388 this.WAIT.style.position = 'absolute'; 389 this.WAIT.style.zIndex = '1100'; 390 } 391 392 BX.bind(this.INPUT, 'bxchange', function(e) {_this.onChange()}); 393 }; 394 BX.ready(function (){_this.Init(arParams)}); 395}
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.