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 if(arParams.WAIT_IMAGE) 13 this.arParams.WAIT_IMAGE = arParams.WAIT_IMAGE; 14 if(arParams.MIN_QUERY_LEN <= 0) 15 arParams.MIN_QUERY_LEN = 1; 16 17 this.cache = []; 18 this.cache_key = null; 19 20 this.startText = ''; 21 this.running = false; 22 this.needRunAgain = 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 $('.bx_searche.scrollbar').mCustomScrollbar({ 87 mouseWheel: { 88 scrollAmount: 150, 89 preventDefault: true 90 } 91 }); 92 }; 93 94 this.onKeyPress = function(keyCode) 95 { 96 var tbl = BX.findChild(_this.RESULT, {'tag':'table','class':'title-search-result'}, true); 97 if(!tbl) 98 return false; 99 100 var i; 101 var cnt = tbl.rows.length; 102 103 switch (keyCode) 104 { 105 case 27: // escape key - close search div 106 _this.RESULT.style.display = 'none'; 107 _this.currentRow = -1; 108 _this.UnSelectAll(); 109 return true; 110 111 case 40: // down key - navigate down on search results 112 if(_this.RESULT.style.display == 'none') 113 _this.RESULT.style.display = 'block'; 114 115 var first = -1; 116 for(i = 0; i < cnt; i++) 117 { 118 if(!BX.findChild(tbl.rows[i], {'class':'title-search-separator'}, true)) 119 { 120 if(first == -1) 121 first = i; 122 123 if(_this.currentRow < i) 124 { 125 _this.currentRow = i; 126 break; 127 } 128 else if(tbl.rows[i].className == 'title-search-selected') 129 { 130 tbl.rows[i].className = ''; 131 } 132 } 133 } 134 135 if(i == cnt && _this.currentRow != i) 136 _this.currentRow = first; 137 138 tbl.rows[_this.currentRow].className = 'title-search-selected'; 139 return true; 140 141 case 38: // up key - navigate up on search results 142 if(_this.RESULT.style.display == 'none') 143 _this.RESULT.style.display = 'block'; 144 145 var last = -1; 146 for(i = cnt-1; i >= 0; i--) 147 { 148 if(!BX.findChild(tbl.rows[i], {'class':'title-search-separator'}, true)) 149 { 150 if(last == -1) 151 last = i; 152 153 if(_this.currentRow > i) 154 { 155 _this.currentRow = i; 156 break; 157 } 158 else if(tbl.rows[i].className == 'title-search-selected') 159 { 160 tbl.rows[i].className = ''; 161 } 162 } 163 } 164 165 if(i < 0 && _this.currentRow != i) 166 _this.currentRow = last; 167 168 tbl.rows[_this.currentRow].className = 'title-search-selected'; 169 return true; 170 171 case 13: // enter key - choose current search result 172 if(_this.RESULT.style.display == 'block') 173 { 174 for(i = 0; i < cnt; i++) 175 { 176 if(_this.currentRow == i) 177 { 178 if(!BX.findChild(tbl.rows[i], {'class':'title-search-separator'}, true)) 179 { 180 var a = BX.findChild(tbl.rows[i], {'tag':'a'}, true); 181 if(a) 182 { 183 window.location = a.href; 184 return true; 185 } 186 } 187 } 188 } 189 } 190 return false;
191 } 192 193 return false; 194 }; 195 196 this.onTimeout = function() 197 { 198 _this.onChange(function(){ 199 setTimeout(_this.onTimeout, 500); 200 }); 201 }; 202 203 this.onChange = function(callback) 204 { 205 if (_this.running){ 206 _this.needRunAgain = true; 207 return; 208 } 209 _this.running = true; 210 211 if(_this.INPUT.value != _this.oldValue && _this.INPUT.value != _this.startText) 212 { 213 _this.oldValue = _this.INPUT.value; 214 if(_this.INPUT.value.length >= _this.arParams.MIN_QUERY_LEN) 215 { 216 _this.cache_key = _this.arParams.INPUT_ID + '|' + _this.INPUT.value; 217 if(_this.cache[_this.cache_key] == null) 218 { 219 if(_this.WAIT) 220 { 221 var pos = BX.pos(_this.INPUT); 222 var height = (pos.bottom - pos.top)-2; 223 _this.WAIT.style.top = (pos.top+1) + 'px'; 224 _this.WAIT.style.height = height + 'px'; 225 _this.WAIT.style.width = height + 'px'; 226 _this.WAIT.style.left = (pos.right - height + 2) + 'px'; 227 _this.WAIT.style.display = 'block'; 228 } 229 230 BX.ajax.post( 231 _this.arParams.AJAX_PAGE, 232 { 233 'ajax_call':'y', 234 'INPUT_ID':_this.arParams.INPUT_ID_TMP, 235 'q':_this.INPUT.value, 236 'l':_this.arParams.MIN_QUERY_LEN 237 }, 238 function(result) 239 { 240 _this.cache[_this.cache_key] = result; 241 _this.ShowResult(result); 242 _this.currentRow = -1; 243 _this.EnableMouseEvents(); 244 if(_this.WAIT) 245 _this.WAIT.style.display = 'none'; 246 if (!!callback) 247 callback(); 248 _this.running = false; 249 250 if(_this.needRunAgain){ 251 _this.needRunAgain = false; 252 _this.onChange(callback); 253 } 254 } 255 ); 256 return; 257 } 258 else 259 { 260 _this.ShowResult(_this.cache[_this.cache_key]); 261 _this.currentRow = -1; 262 _this.EnableMouseEvents(); 263 } 264 } 265 else 266 { 267 _this.RESULT.style.display = 'none'; 268 _this.currentRow = -1; 269 _this.UnSelectAll(); 270 } 271 } 272 if (!!callback) 273 callback(); 274 _this.running = false; 275 }; 276 277 this.UnSelectAll = function() 278 { 279 var tbl = BX.findChild(_this.RESULT, {'tag':'table','class':'title-search-result'}, true); 280 if(tbl) 281 { 282 var cnt = tbl.rows.length; 283 for(var i = 0; i < cnt; i++) 284 tbl.rows[i].className = ''; 285 } 286 }; 287 288 this.EnableMouseEvents = function() 289 { 290 var tbl = BX.findChild(_this.RESULT, {'tag':'table','class':'title-search-result'}, true); 291 if(tbl) 292 { 293 var cnt = tbl.rows.length; 294 for(var i = 0; i < cnt; i++) 295 if(!BX.findChild(tbl.rows[i], {'class':'title-search-separator'}, true)) 296 { 297 tbl.rows[i].id = 'row_' + i; 298 tbl.rows[i].onmouseover = function (e) { 299 if(_this.currentRow != this.id.substr(4)) 300 { 301 _this.UnSelectAll(); 302 this.className = 'title-search-selected'; 303 _this.currentRow = this.id.substr(4); 304 } 305 }; 306 tbl.rows[i].onmouseout = function (e) { 307 this.className = ''; 308 _this.currentRow = -1; 309 }; 310 } 311 } 312 }; 313 314 this.onFocusLost = function(hide) 315 { 316 setTimeout(function(){_this.RESULT.style.display = 'none';}, 300); 317 // _this.RESULT.style.display = 'none'; 318 }; 319 320 this.onFocusGain = function() 321 { 322 if(_this.RESULT.innerHTML.length) 323 _this.ShowResult(); 324 }; 325 326 this.onKeyDown = function(e) 327 { 328 if(!e) 329 e = window.event; 330 331 if (_this.RESULT.style.display == 'block') 332 { 333 if(_this.onKeyPress(e.keyCode)) 334 return BX.PreventDefault(e); 335 } 336 }; 337 338 this.adjustResultNode = function() 339 { 340 var pos, pos_input; 341 var fixedParent = BX.findParent(_this.CONTAINER, BX.is_fixed); 342 if(!!fixedParent) 343 { 344 _this.RESULT.style.position = 'fixed'; 345 _this.RESULT.style.zIndex = BX.style(fixedParent, 'z-index') + 2; 346 pos = BX.pos(_this.CONTAINER, true); 347 } 348 else 349 { 350 _this.RESULT.style.position = 'absolute'; 351 pos = BX.pos(_this.CONTAINER); 352 } 353 //console.log(pos); 354 //console.log(_this.CONTAINER); 355 pos_input = BX.pos(_this.INPUT); 356 357 pos.width = pos.right - pos.left; 358 _this.RESULT.style.top = (pos.bottom + 2) + 'px'; 359 _this.RESULT.style.left = pos_input.left + 'px'; 360 361 if($(_this.INPUT).closest('.inline-search-block.with-close').length) 362 _this.RESULT.style.width = pos_input.width + 'px'; 363 else 364 _this.RESULT.style.width = pos.width + 'px'; 365 return pos; 366 }; 367 368 this._onContainerLayoutChange = function() 369 { 370 if(_this.RESULT.style.display !== "none" && _this.RESULT.innerHTML !== '') 371 { 372 _this.adjustResultNode(); 373 } 374 }; 375 this.Init = function() 376 { 377 this.CONTAINER = document.getElementById(this.arParams.CONTAINER_ID); 378 BX.addCustomEvent(this.CONTAINER, "OnNodeLayoutChange", this._onContainerLayoutChange); 379 380 this.RESULT = document.body.appendChild(document.createElement("DIV")); 381 382 this.RESULT.className = 'title-search-result '+this.arParams.INPUT_ID; 383 if(this.arParams.INPUT_ID != 'title-search-input_fixed') 384 this.RESULT.className += ' '+arMaxOptions['THEME']['TYPE_SEARCH']+'_type'; 385 386 this.INPUT = document.getElementById(this.arParams.INPUT_ID); 387 this.startText = this.oldValue = this.INPUT.value; 388 BX.bind(this.INPUT, 'focus', function() {_this.onFocusGain()}); 389 BX.bind(this.INPUT, 'blur', function() {_this.onFocusLost()}); 390 391 if(BX.browser.IsSafari() || BX.browser.IsIE()) 392 this.INPUT.onkeydown = this.onKeyDown; 393 else 394 this.INPUT.onkeypress = this.onKeyDown; 395 396 if(this.arParams.WAIT_IMAGE) 397 { 398 this.WAIT = document.body.appendChild(document.createElement("DIV")); 399 this.WAIT.style.backgroundImage = "url('" + this.arParams.WAIT_IMAGE + "')"; 400 if(!BX.browser.IsIE()) 401 this.WAIT.style.backgroundRepeat = 'none'; 402 this.WAIT.style.display = 'none'; 403 this.WAIT.style.position = 'absolute'; 404 this.WAIT.style.zIndex = '1100'; 405 } 406 407 BX.bind(this.INPUT, 'bxchange', function() {_this.onChange()}); 408 }; 409 BX.ready(function (){_this.Init(arParams)}); 410}
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.