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