1(function(window){ 2if (window.BX.ajax) return; 3 4var 5 BX = window.BX, 6 7 tempDefaultConfig = {}, 8 defaultConfig = { 9 method: 'GET', // request method: GET|POST 10 dataType: 'html', // type of data loading: html|json|script 11 timeout: 0, // request timeout in seconds. 0 for browser-default 12 async: true, // whether request is asynchronous or not 13 processData: true, // any data processing is disabled if false, only callback call 14 scriptsRunFirst: false, // whether to run _all_ found scripts before onsuccess call. script tag can have an attribute "bxrunfirst" to turn this flag on only for itself 15 emulateOnload: true, 16 start: true, // send request immediately (if false, request can be started manually via XMLHttpRequest object returned) 17 cache: true // whether NOT to add random addition to URL 18/* 19other parameters: 20 url: url to get/post 21 data: data to post 22 onsuccess: successful request callback. BX.proxy may be used. 23 onfailure: request failure callback. BX.proxy may be used. 24 25any of the default parameters can be overridden. defaults can be changed by BX.ajax.Setup() - for all further requests! 26*/ 27 }, 28 ajax_session = null, 29 loadedScripts = {}, 30 r = { 31 'url_utf': /[^\034-\254]+/g, 32 'script_self': /\/bitrix\/js\/main\/core\/core(_ajax)*.js$/i, 33 'script_self_window': /\/bitrix\/js\/main\/core\/core_window.js$/i, 34 'script_self_admin': /\/bitrix\/js\/main\/core\/core_admin.js$/i, 35 'script_onload': /window.onload/g 36 }; 37 38// low-level method 39BX.ajax = function(config) 40{ 41 var status, data; 42
43 if (!config || !config.url || !BX.type.isString(config.url)) 44 { 45 return false; 46 } 47 48 for (var i in tempDefaultConfig) 49 if (typeof (config[i]) == "undefined") config[i] = tempDefaultConfig[i]; 50 51 tempDefaultConfig = {}; 52 53 for (var i in defaultConfig) 54 if (typeof (config[i]) == "undefined") config[i] = defaultConfig[i]; 55 56 config.method = config.method.toUpperCase(); 57 58 if (BX.browser.IsIE()) 59 { 60 var result = r.url_utf.exec(config.url); 61 if (result) 62 { 63 do 64 { 65 config.url = config.url.replace(result, BX.util.urlencode(result)); 66 result = r.url_utf.exec(config.url); 67 } while (result); 68 } 69 } 70 71 if (!config.cache && config.method == 'GET') 72 config.url = BX.ajax._uncache(config.url); 73 74 if (config.method == 'POST') 75 { 76 config.data = BX.ajax.prepareData(config.data); 77 } 78 79 config.xhr = BX.ajax.xhr(); 80 if (!config.xhr) return; 81 82 config.xhr.open(config.method, config.url, config.async); 83 if (config.method == 'POST') 84 { 85 config.xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 86 } 87 88 var bRequestCompleted = false; 89 var onreadystatechange = config.xhr.onreadystatechange = function(additional) 90 { 91 if (bRequestCompleted) 92 return; 93 94 if (additional === 'timeout') 95 { 96 if (config.onfailure) 97 config.onfailure("timeout"); 98 99 BX.onCustomEvent(config.xhr, 'onAjaxFailure', ['timeout', '', config]); 100 101 config.xhr.onreadystatechange = BX.DoNothing; 102 config.xhr.abort(); 103 104 if (config.async) 105 { 106 config.xhr = null; 107 } 108 } 109 else 110 { 111 if (config.xhr.readyState == 4 || additional == 'run') 112 { 113 status = BX.ajax.xhrSuccess(config.xhr) ? "success" : "error"; 114 bRequestCompleted = true; 115 config.xhr.onreadystatechange = BX.DoNothing; 116 117 // var status = oAjax.arThreads[TID].httpRequest.getResponseHeader('X-Bitrix-Ajax-Status'); 118 // var bRedirect = (status == 'Redirect'); 119 120 if (status == 'success') 121 { 122 var data = config.xhr.responseText; 123 124 if (!config.processData) 125 { 126 if (config.onsuccess) 127 { 128 config.onsuccess(data); 129 } 130 131 BX.onCustomEvent(config.xhr, 'onAjaxSuccess', [data, config]); 132 } 133 else 134 { 135 try 136 { 137 data = BX.ajax.processRequestData(data, config); 138 } 139 catch (e) 140 { 141 if (config.onfailure) 142 config.onfailure("processing", e); 143 BX.onCustomEvent(config.xhr, 'onAjaxFailure', ['processing', e, config]); 144 } 145 } 146 } 147 else if (config.onfailure) 148 { 149 config.onfailure("status", config.xhr.status); 150 BX.onCustomEvent(config.xhr, 'onAjaxFailure', ['status', config.xhr.status, config]); 151 } 152 153 if (config.async) 154 { 155 config.xhr = null; 156 } 157 } 158 } 159 } 160 161 if (config.async && config.timeout > 0) 162 { 163 setTimeout(function() { 164 if (config.xhr && !bRequestCompleted) 165 { 166 onreadystatechange("timeout"); 167 } 168 }, config.timeout * 1000); 169 } 170 171 if (config.start) 172 { 173 config.xhr.send(config.data); 174 175 if (!config.async) 176 { 177 onreadystatechange('run'); 178 } 179 } 180 181 return config.xhr; 182} 183 184BX.ajax.xhr = function() 185{ 186 if (window.XMLHttpRequest) 187 { 188 try {return new XMLHttpRequest();} catch(e){} 189 } 190 else if (window.ActiveXObject) 191 { 192 try { return new ActiveXObject("Msxml2.XMLHTTP.6.0"); } 193 catch(e) {} 194 try { return new ActiveXObject("Msxml2.XMLHTTP.3.0"); } 195 catch(e) {} 196 try { return new ActiveXObject("Msxml2.XMLHTTP"); } 197 catch(e) {} 198 try { return new ActiveXObject("Microsoft.XMLHTTP"); } 199 catch(e) {} 200 throw new Error("This browser does not support XMLHttpRequest."); 201 } 202 203 return null; 204} 205 206BX.ajax.__prepareOnload = function(scripts) 207{ 208 if (scripts.length > 0) 209 { 210 BX.ajax['onload_' + ajax_session] = null; 211 212 for (var i=0,len=scripts.length;i<len;i++) 213 { 214 if (scripts[i].isInternal) 215 { 216 scripts[i].JS = scripts[i].JS.replace(r.script_onload, 'BX.aja
216x.onload_' + ajax_session); 217 } 218 } 219 } 220 221 BX.CaptureEventsGet(); 222 BX.CaptureEvents(window, 'load'); 223} 224 225BX.ajax.__runOnload = function() 226{ 227 if (null != BX.ajax['onload_' + ajax_session]) 228 { 229 BX.ajax['onload_' + ajax_session].apply(window); 230 BX.ajax['onload_' + ajax_session] = null; 231 } 232 233 var h = BX.CaptureEventsGet(); 234 235 if (h) 236 { 237 for (var i=0; i<h.length; i++) 238 h[i].apply(window); 239 } 240} 241 242BX.ajax.processRequestData = function(data, config) 243{ 244 var result, scripts = []; 245 switch (config.dataType.toUpperCase()) 246 { 247 case 'JSON': 248 if (data.indexOf("\n") >= 0) 249 eval('result = ' + data); 250 else 251 result = (new Function("return " + data))(); 252 break; 253 case 'SCRIPT': 254 scripts.push({"isInternal": true, "JS": data, bRunFirst: config.scriptsRunFirst}); 255 result = data; 256 break; 257 258 default: // HTML 259 var ob = BX.processHTML(data, config.scriptsRunFirst); 260 result = ob.HTML; scripts = ob.SCRIPT; 261 break; 262 } 263 264 var bSessionCreated = false; 265 if (null == ajax_session) 266 { 267 ajax_session = parseInt(Math.random() * 1000000); 268 bSessionCreated = true; 269 } 270 271 if (config.emulateOnload) 272 BX.ajax.__prepareOnload(scripts); 273 274 BX.ajax.processScripts(scripts, true); 275 276 if (config.onsuccess) 277 { 278 config.onsuccess(result); 279 } 280 281 BX.onCustomEvent(config.xhr, 'onAjaxSuccess', [result, config]); 282 283 BX.ajax.processScripts(scripts, false); 284 285 setTimeout(function() 286 { 287 if (config.emulateOnload) 288 BX.ajax.__runOnload(); 289 if (bSessionCreated) 290 ajax_session = null; 291 }, 10); 292} 293 294BX.ajax.processScripts = function(scripts, bRunFirst) 295{ 296 for (var i = 0, length = scripts.length; i < length; i++) 297 { 298 if (null != bRunFirst && bRunFirst != !!scripts[i].bRunFirst) 299 continue; 300 301 if (scripts[i].isInternal) 302 { 303 BX.evalGlobal(scripts[i].JS); 304 } 305 else 306 { 307 BX.ajax.loadScriptAjax([scripts[i].JS]); 308 } 309 } 310} 311 312// TODO: extend this function to use with any data objects or forms 313BX.ajax.prepareData = function(arData, prefix) 314{ 315 var data = ''; 316 if (BX.type.isString(arData)) 317 data = arData; 318 else if (null != arData) 319 { 320 for(var i in arData) 321 { 322 if (data.length > 0) data += '&'; 323 var name = BX.util.urlencode(i); 324 if(prefix) 325 name = prefix + '[' + name + ']'; 326 if(typeof arData[i] == 'object') 327 data += BX.ajax.prepareData(arData[i], name) 328 else 329 data += name + '=' + BX.util.urlencode(arData[i]) 330 } 331 } 332 return data; 333} 334 335BX.ajax.xhrSuccess = function(xhr) 336{ 337 return (xhr.status >= 200 && xhr.status < 300) || xhr.status === 304 || xhr.status === 1223 || xhr.status === 0; 338} 339 340BX.ajax.Setup = function(config, bTemp) 341{ 342 bTemp = !!bTemp; 343 344 for (var i in config) 345 { 346 if (bTemp) 347 tempDefaultConfig[i] = config[i]; 348 else 349 defaultConfig[i] = config[i]; 350 } 351} 352 353BX.ajax._uncache = function(url) 354{ 355 return url + ((url.indexOf('?') !== -1 ? "&" : "?") + '_=' + (new Date).getTime()); 356} 357 358/* simple interface */ 359BX.ajax.get = function(url, data, callback) 360{ 361 if (BX.type.isFunction(data)) 362 { 363 callback = data; 364 data = ''; 365 } 366 367 data = BX.ajax.prepareData(data); 368 369 if (data) 370 { 371 url += (url.indexOf('?') !== -1 ? "&" : "?") + data; 372 data = ''; 373 } 374 375 return BX.ajax({ 376 'method': 'GET', 377 'dataType': 'html', 378 'url': url, 379 'data': '', 380 'onsuccess': callback 381 }); 382} 383 384BX.ajax.getCaptcha = function(callback) 385{ 386 return BX.ajax.loadJSON('/bitrix/tools/ajax_captcha.php', callback); 387} 388 389BX.ajax.insertToNode = function(url, node) 390{ 391 if (node = BX(node)) 392 { 393 BX.onCustomEvent('onAjaxInsertToNode', [{url: url, node: node}]); 394 395 var show = null; 396 if (!tempDefaultConfig.denyShowWait) 397 { 398 show = BX.showWait(node); 399 delete tempDefaultConfig.denyShowWait; 400 } 401 402 return BX.ajax.get(url, function(data) { 403 node.innerHTML = data; 404 BX.closeWait(node, show); 405 }); 406 } 407} 408 409BX.ajax.post = function(url, data, callback) 410{ 411 data = BX.ajax.prepareData(data); 412 413 return BX.ajax({ 414 'method': 'POST', 415 'dataType': 'html', 416 'url': url, 417 'data': data, 418 'onsuccess': callback 419 }); 420} 421 422/* load and execute external file script with onload emulation */ 423BX.ajax.loadScriptAjax = function(script_src, callback) 424{ 425 if (BX.type.isArray(script_src)) 426 { 427 for (var i=0,len=script_src.length;i<len;i++) 428 BX.ajax.loadScriptAjax(script_src[i], callback); 429 } 430 else 431 { 432 if (r.script_self.test(script_src)) return; 433 if (r.script_self_window.test(script_src) && BX.CWindow) return; 434 if (r.script_self_admin.test(script_src) && BX.admin) return; 435 436 if (!loadedScripts[script_src]) 437 {
438 return BX.ajax({ 439 url: script_src, 440 method: 'GET', 441 dataType: 'script', 442 processData: true, 443 emulateOnload: false, 444 async: false, 445 start: true, 446 onsuccess: function(result) { 447 loadedScripts[script_src] = result; 448 if (callback) 449 callback(result); 450 } 451 }); 452 } 453 else if (callback) 454 { 455 callback(loadedScripts[script_src]); 456 } 457 } 458} 459 460/* non-xhr loadings */ 461BX.ajax.loadJSON = function(url, data, callback) 462{ 463 if (BX.type.isFunction(data)) 464 { 465 callback = data; 466 data = ''; 467 } 468 469 data = BX.ajax.prepareData(data); 470 471 if (data) 472 { 473 url += (url.indexOf('?') !== -1 ? "&" : "?") + data; 474 data = ''; 475 } 476 477 return BX.ajax({ 478 'method': 'GET', 479 'dataType': 'json', 480 'url': url, 481 'onsuccess': callback 482 }); 483} 484 485/* 486arObs = [{ 487 url: url, 488 type: html|script|json|css, 489 callback: function 490}] 491*/ 492BX.ajax.load = function(arObs, callback) 493{ 494 if (!BX.type.isArray(arObs)) 495 arObs = [arObs]; 496 497 var cnt = 0; 498 499 if (!BX.type.isFunction(callback)) 500 callback = BX.DoNothing; 501 502 var handler = function(data) 503 { 504 if (BX.type.isFunction(this.callback)) 505 this.callback(data); 506 507 if (++cnt >= len) 508 callback(); 509 }; 510 511 for (var i = 0, len = arObs.length; i<len; i++) 512 { 513 switch(arObs.type.toUpperCase()) 514 { 515 case 'SCRIPT': 516 BX.loadScript([arObs[i].url], jsBX.proxy(handler, arObs[i])); 517 break; 518 case 'CSS': 519 BX.loadCSS([arObs[i].url]); 520 521 if (++cnt >= len) 522 callback(); 523 break; 524 case 'JSON': 525 BX.ajax.loadJSON(arObs.url, jsBX.proxy(handler, arObs[i])); 526 break; 527 528 default: 529 BX.ajax.get(arObs.url, '', jsBX.proxy(handler, arObs[i])); 530 break; 531 } 532 } 533} 534 535/* ajax form sending */ 536BX.ajax.submit = function(obForm, callback) 537{ 538 if (!obForm.target) 539 { 540 if (null == obForm.BXFormTarget) 541 { 542 var frame_name = 'formTarget_' + Math.random(); 543 obForm.BXFormTarget = document.body.appendChild(BX.create('IFRAME', { 544 props: { 545 name: frame_name, 546 id: frame_name, 547 src: 'javascript:void(0)' 548 }, 549 style: { 550 display: 'none' 551 } 552 })); 553 } 554 555 obForm.target = obForm.BXFormTarget.name; 556 } 557 558 obForm.BXFormCallback = callback; 559 BX.bind(obForm.BXFormTarget, 'load', BX.proxy(BX.ajax._submit_callback, obForm)); 560 561 BX.submit(obForm); 562 563 return false; 564} 565 566BX.ajax.submitComponentForm = function(obForm, container) 567{ 568 if (!obForm.target) 569 { 570 if (null == obForm.BXFormTarget) 571 { 572 var frame_name = 'formTarget_' + Math.random(); 573 obForm.BXFormTarget = document.body.appendChild(BX.create('IFRAME', { 574 props: { 575 name: frame_name, 576 id: frame_name, 577 src: 'javascript:void(0)' 578 }, 579 style: { 580 display: 'none' 581 } 582 })); 583 } 584 585 obForm.target = obForm.BXFormTarget.name; 586 } 587 588 obForm.BXFormCallback = function(d) { 589 BX(container).innerHTML = d; 590 if (window.bxcompajaxframeonload){ 591 setTimeout("window.bxcompajaxframeonload();window.bxcompajaxframeonload=null;", 10) 592 }; 593 BX.onCustomEvent('onAjaxSuccess', []); 594 }; 595 596 BX.bind(obForm.BXFormTarget, 'load', BX.proxy(BX.ajax._submit_callback, obForm)); 597 598 return true; 599} 600 601// func will be executed in form context 602BX.ajax._submit_callback = function() 603{ 604 //opera triggers onload event even on empty iframe 605 if(this.BXFormTarget.contentWindow.location.href.indexOf('http') != 0) 606 return; 607 608 if (this.BXFormCallback) 609 this.BXFormCallback.apply(this, [this.BXFormTarget.contentWindow.document.body.innerHTML]); 610 611 BX.unbindAll(this.BXFormTarget); 612} 613 614// TODO: currently in window extension. move it here. 615BX.ajax.submitAjax = function(obForm, callback) 616{ 617 618} 619 620BX.ajax.UpdatePageData = function (arData) 621{ 622 if (arData.TITLE) 623 BX.ajax.UpdatePageTitle(arData.TITLE); 624 if (arData.NAV_CHAIN) 625 BX.ajax.UpdatePageNavChain(arData.NAV_CHAIN); 626 if (arData.CSS && arData.CSS.length > 0) 627 BX.loadCSS(arData.CSS); 628 if (arData.SCRIPTS && arData.SCRIPTS.length > 0) 629 BX.loadScript(arData.SCRIPTS); 630} 631 632BX.ajax.UpdatePageTitle = function(title) 633{ 634 var obTitle = BX('pagetitle'); 635 if (obTitle) 636 { 637 obTitle.removeChild(obTitle.firstChild); 638 if (!obTitle.firstChild) 639 obTitle.appendChild(document.createTextNode(title)); 640 else 641 obTitle.insertBefore(document.createTextNode(title), obTitle.firstChild); 642 } 643 644 document.title = title; 645} 646 647BX.ajax.UpdatePageNavChain = function(nav_chain) 648{ 649 var obNavChain = BX('navigation'); 650 if (obNavChain) 651 { 652 obNavChain.innerHTML = nav_chain; 653 } 654} 655 656/* user options handling */ 657BX.userOptions = { 658 options: null, 659 bSend: false, 660 delay: 5000 661} 662 663BX.userOptions.save = function(sCategory, sName, sValName, sVal, bCommon) 664{ 665 if (null == BX.userOptions.options) 666 BX.userOptions.options = {}; 667 668 bCommon = !!bCommon; 669 BX.userOptions.options[sCategory+'.'+sName+'.'+sValName] = [sCategory, sName, sValName, sVal, bCommon]; 670 671 var sParam = BX.userOptions.__get(); 672 if (sParam != '') 673 document.cookie = BX.message('COOKIE_PREFIX')+"_LAST_SETTINGS=" + sParam + "&sessid="+BX.bitrix_sessid()+"; expires=Thu, 31 Dec 2020 23:59:59 GMT; path=/;"; 674 675 if(!BX.userOptions.bSend) 676 { 677 BX.userOptions.bSend = true; 678 setTimeout(function(){BX.userOptions.send(null)}, BX.userOptions.delay); 679 } 680} 681 682BX.userOptions.send = function(callback) 683{ 684 var sParam = BX.userOptions.__get(); 685 BX.userOptions.options = null; 686 BX.userOptions.bSend = false;
687 688 if (sParam != '') 689 { 690 document.cookie = BX.message('COOKIE_PREFIX') + "_LAST_SETTINGS=; path=/;"; 691 BX.ajax({ 692 'method': 'GET', 693 'dataType': 'html', 694 'processData': false, 695 'cache': false, 696 'url': '/bitrix/admin/user_options.php?'+sParam+'&sessid='+BX.bitrix_sessid(), 697 'onsuccess': callback 698 }); 699 } 700} 701 702BX.userOptions.del = function(sCategory, sName, bCommon, callback) 703{ 704 BX.ajax.get('/bitrix/admin/user_options.php?action=delete&c='+sCategory+'&n='+sName+(bCommon == true? '&common=Y':'')+'&sessid='+BX.bitrix_sessid(), callback); 705} 706 707BX.userOptions.__get = function() 708{ 709 if (!BX.userOptions.options) return ''; 710 711 var sParam = '', n = -1, prevParam = '', arOpt, i; 712 713 for (i in BX.userOptions.options) 714 { 715 aOpt = BX.userOptions.options[i]; 716 717 if (prevParam != aOpt[0]+'.'+aOpt[1]) 718 { 719 n++; 720 sParam += '&p['+n+'][c]='+BX.util.urlencode(aOpt[0]); 721 sParam += '&p['+n+'][n]='+BX.util.urlencode(aOpt[1]); 722 if (aOpt[4] == true) 723 sParam += '&p['+n+'][d]=Y'; 724 prevParam = aOpt[0]+'.'+aOpt[1]; 725 } 726 727 sParam += '&p['+n+'][v]['+BX.util.urlencode(aOpt[2])+']='+BX.util.urlencode(aOpt[3]); 728 } 729 730 return sParam.substr(1); 731} 732 733BX.ajax.history = { 734 expected_hash: '', 735 736 obParams: null, 737 738 obFrame: null, 739 obImage: null, 740 741 obTimer: null, 742 743 bInited: false, 744 bHashCollision: false, 745 bPushState: !!(history.pushState && BX.type.isFunction(history.pushState)), 746 747 init: function(obParams) 748 { 749 if (BX.ajax.history.bInited) 750 return; 751 752 this.obParams = obParams; 753 var obCurrentState = this.obParams.getState(); 754 755 if (BX.ajax.history.bPushState) 756 { 757 BX.ajax.history.expected_hash = window.location.pathname; 758 if (window.location.search) 759 BX.ajax.history.expected_hash += window.location.search; 760 761 BX.ajax.history.put(obCurrentState, BX.ajax.history.expected_hash); 762 BX.bind(window, 'popstate', BX.ajax.history.__hashListener); 763 } 764 else 765 { 766 BX.ajax.history.expected_hash = window.location.hash; 767 768 if (!BX.ajax.history.expected_hash || BX.ajax.history.expected_hash == '#') 769 BX.ajax.history.expected_hash = '__bx_no_hash__'; 770 771 jsAjaxHistoryContainer.put(BX.ajax.history.expected_hash, obCurrentState); 772 BX.ajax.history.obTimer = setTimeout(BX.ajax.history.__hashListener, 500); 773 774 if (BX.browser.IsIE()) 775 { 776 BX.ajax.history.obFrame = document.createElement('IFRAME'); 777 BX.hide_object(BX.ajax.history.obFrame); 778 779 document.body.appendChild(BX.ajax.history.obFrame); 780 781 BX.ajax.history.obFrame.contentWindow.document.open(); 782 BX.ajax.history.obFrame.contentWindow.document.write(BX.ajax.history.expected_hash); 783 BX.ajax.history.obFrame.contentWindow.document.close(); 784 } 785 else if (BX.browser.IsOpera()) 786 { 787 BX.ajax.history.obImage = document.createElement('IMG'); 788 BX.hide_object(BX.ajax.history.obImage); 789 790 document.body.appendChild(BX.ajax.history.obImage); 791 792 BX.ajax.history.obImage.setAttribute('src', 'javascript:location.href = \'javascript:BX.ajax.history.__hashListener();\';'); 793 } 794 } 795 796 BX.ajax.history.bInited = true; 797 }, 798 799 __hashListener: function(e) 800 { 801 e = e || window.event || {state:false}; 802 803 if (BX.ajax.history.bPushState && e.state) 804 { 805 BX.ajax.history.obParams.setState(e.state); 806 } 807 else 808 { 809 if (BX.ajax.history.obTimer) 810 { 811 window.clearTimeout(BX.ajax.history.obTimer); 812 BX.ajax.history.obTimer = null; 813 } 814 815 if (null != BX.ajax.history.obFrame) 816 var current_hash = BX.ajax.history.obFrame.contentWindow.document.body.innerText; 817 else 818 var current_hash = window.location.hash; 819 820 if (!current_hash || current_hash == '#') 821 current_hash = '__bx_no_hash__'; 822 823 if (current_hash.indexOf('#') == 0) 824 current_hash = current_hash.substring(1); 825 826 if (current_hash != BX.ajax.history.expected_hash) 827 { 828 var state = jsAjaxHistoryContainer.get(current_hash); 829 if (state) 830 { 831 BX.ajax.history.obParams.setState(state); 832 833 BX.ajax.history.expected_hash = current_hash; 834 if (null != BX.ajax.history.obFrame) 835 { 836 var __hash = current_hash == '__bx_no_hash__' ? '' : current_hash; 837 if (window.location.hash != __hash && window.location.hash != '#' + __hash) 838 window.location.hash = __hash; 839 } 840 } 841 } 842 843 BX.ajax.history.obTimer = setTimeout(BX.ajax.history.__hashListener, 500); 844 } 845 }, 846 847 put: function(state, new_hash, new_hash1) 848 { 849 if (this.bPushState) 850 { 851 history.pushState(state, '', new_hash); 852 } 853 else 854 { 855 if (typeof new_hash1 != 'undefined') 856 new_hash = new_hash1; 857 else 858 new_hash = 'view' + new_hash; 859 860 jsAjaxHistoryContainer.put(new_hash, state); 861 BX.ajax.history.expected_hash = new_hash; 862
863 window.location.hash = BX.util.urlencode(new_hash); 864 865 if (null != BX.ajax.history.obFrame) 866 { 867 BX.ajax.history.obFrame.contentWindow.document.open(); 868 BX.ajax.history.obFrame.contentWindow.document.write(new_hash); 869 BX.ajax.history.obFrame.contentWindow.document.close(); 870 } 871 } 872 }, 873 874 checkRedirectStart: function(param_name, param_value) 875 { 876 var current_hash = window.location.hash; 877 if (current_hash.substring(0, 1) == '#') current_hash = current_hash.substring(1); 878 879 var test = current_hash.substring(0, 5); 880 if (test == 'view/' || test == 'view%') 881 { 882 BX.ajax.history.bHashCollision = true; 883 document.write('<' + 'div id="__ajax_hash_collision_' + param_value + '" style="display: none;">'); 884 } 885 }, 886 887 checkRedirectFinish: function(param_name, param_value) 888 { 889 document.write('</div>'); 890 891 var current_hash = window.location.hash; 892 if (current_hash.substring(0, 1) == '#') current_hash = current_hash.substring(1); 893 894 BX.ready(function () 895 { 896 var test = current_hash.substring(0, 5); 897 if (test == 'view/' || test == 'view%') 898 { 899 var obColNode = BX('__ajax_hash_collision_' + param_value); 900 var obNode = obColNode.firstChild; 901 BX.cleanNode(obNode); 902 obColNode.style.display = 'block'; 903 904 // IE, Opera and Chrome automatically modifies hash with urlencode, but FF doesn't ;-( 905 if (test != 'view%') 906 current_hash = BX.util.urlencode(current_hash); 907 908 current_hash += (current_hash.indexOf('%3F') == -1 ? '%3F' : '%26') + param_name + '=' + param_value; 909 910 var url = '/bitrix/tools/ajax_redirector.php?hash=' + current_hash; 911 912 BX.ajax.insertToNode(url, obNode); 913 } 914 }); 915 } 916} 917 918BX.ajax.component = function(node) 919{ 920 this.node = node; 921} 922 923BX.ajax.component.prototype.getState = function() 924{ 925 var state = { 926 'node': this.node, 927 'title': window.document.title, 928 'data': BX(this.node).innerHTML 929 }; 930 931 var obNavChain = BX('navigation'); 932 if (null != obNavChain) 933 state.nav_chain = obNavChain.innerHTML; 934 935 return state; 936} 937 938BX.ajax.component.prototype.setState = function(state) 939{ 940 BX(state.node).innerHTML = state.data; 941 BX.ajax.UpdatePageTitle(state.title); 942 943 if (state.nav_chain) 944 BX.ajax.UpdatePageNavChain(state.nav_chain); 945} 946 947var jsAjaxHistoryContainer = { 948 arHistory: {}, 949 950 put: function(hash, state) 951 { 952 this.arHistory[hash] = state; 953 }, 954 955 get: function(hash) 956 { 957 return this.arHistory[hash]; 958 } 959} 960 961})(window)
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.