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