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