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