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