Guest User

Untitled

a guest
Jan 25th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.75 KB | None | 0 0
  1. (function($) {
  2.  
  3. var sessionCookie = SESSION_COOKIE_NAME || "jsessionid";
  4.  
  5. var urlParseRE = /^(((([^:\/#\?]+:)?(?:\/\/((?:(([^:@\/#\?]+)(?:\:([^:@\/#\?]+))?)@)?(([^:\/#\?]+)(?:\:([0-9]+))?))?)?)?((\/?(?:[^\/\?#]+\/+)*)([^\?#]*)))?(\?[^#]+)?)(#.*)?/;
  6.  
  7. function parseUrl(url) {
  8. if ($.type(url) === "object") {
  9. return url;
  10. }
  11. var u = url || "", matches = urlParseRE.exec(url), results;
  12. if (matches) {
  13. results = {
  14. href: matches[0] || "",
  15. hrefNoHash: matches[1] || "",
  16. hrefNoSearch: matches[2] || "",
  17. domain: matches[3] || "",
  18. protocol: matches[4] || "",
  19. authority: matches[5] || "",
  20. username: matches[7] || "",
  21. password: matches[8] || "",
  22. host: matches[9] || "",
  23. hostname: matches[10] || "",
  24. port: matches[11] || "",
  25. pathname: matches[12] || "",
  26. directory: matches[13] || "",
  27. filename: matches[14] || "",
  28. search: matches[15] || "",
  29. hash: matches[16] || ""
  30. };
  31. }
  32. return results || {};
  33. }
  34.  
  35. function createStandardXHR() {
  36. try {
  37. return new window.XMLHttpRequest();
  38. } catch(e) {
  39. }
  40. }
  41.  
  42. function createActiveXHR() {
  43. try {
  44. return new window.ActiveXObject("Microsoft.XMLHTTP");
  45. } catch(e) {
  46. }
  47. }
  48.  
  49. function createXDR() {
  50. try {
  51. var xdr = new window.XDomainRequest();
  52. if (!xdr.setRequestHeader) {
  53. xdr.setRequestHeader = $.noop;
  54. }
  55. if (!xdr.getAllResponseHeaders) {
  56. xdr.getAllResponseHeaders = $.noop;
  57. }
  58. var open = xdr.open;
  59. xdr.open = function() {
  60. var cookie = new RegExp('(?:^|; )' + sessionCookie + '=([^;]*)', 'i').exec(document.cookie);
  61. cookie = cookie && cookie[1];
  62. if (cookie) {
  63. var q = arguments[1].indexOf('?');
  64. if (q == -1) {
  65. arguments[1] += ';' + sessionCookie + '=' + cookie;
  66. } else {
  67. arguments[1] = arguments[1].substring(0, q) + ';' + sessionCookie + '=' + cookie + arguments[1].substring(q);
  68. }
  69. }
  70. return open.apply(this, arguments);
  71. };
  72. xdr.onload = function() {
  73. if (typeof xdr.onreadystatechange === 'function') {
  74. xdr.readyState = 4;
  75. xdr.status = 200;
  76. xdr.onreadystatechange.call(xdr, null, false);
  77. }
  78. };
  79. xdr.onerror = xdr.ontimeout = function() {
  80. if (typeof xdr.onreadystatechange === 'function') {
  81. xdr.readyState = 4;
  82. xdr.status = 500;
  83. xdr.onreadystatechange.call(xdr, null, false);
  84. }
  85. };
  86. return xdr;
  87. } catch(e) {
  88. }
  89. }
  90.  
  91. if ($.browser.msie && window.XDomainRequest) {
  92. $.support.cors = true;
  93. $.ajaxSettings.xhr = function() {
  94. return parseUrl(this.url).domain === parseUrl(document.location.href).domain ?
  95. window.ActiveXObject && !this.isLocal && createStandardXHR() || createActiveXHR() :
  96. createXDR();
  97. };
  98. } else if (window.ActiveXObject) {
  99. $.ajaxSettings.xhr = function() {
  100. return !this.isLocal && createStandardXHR() || createActiveXHR();
  101. };
  102. } else {
  103. $.ajaxSettings.xhr = createStandardXHR;
  104. }
  105.  
  106. })(jQuery);
Add Comment
Please, Sign In to add comment