Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 4441bf3

Browse files
author
Jason Moon
committedOct 16, 2013
Wrap in anonymous function to avoid possible global namespace conflicts
1 parent 6dccf12 commit 4441bf3

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed
 

‎jQuery.XDomainRequest.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// jQuery.XDomainRequest.js
22
// Author: Jason Moon - @JSONMOON
33
// IE8+
4-
if (!jQuery.support.cors && jQuery.ajaxTransport && window.XDomainRequest) {
4+
(function($){
5+
6+
if (!$.support.cors && $.ajaxTransport && window.XDomainRequest) {
57
var httpRegEx = /^https?:\/\//i;
68
var getOrPostRegEx = /^get|post$/i;
79
var sameSchemeRegEx = new RegExp('^'+location.protocol, 'i');
@@ -10,7 +12,7 @@ if (!jQuery.support.cors && jQuery.ajaxTransport && window.XDomainRequest) {
1012
var xmlRegEx = /\/xml/i;
1113

1214
// ajaxTransport exists in jQuery 1.5+
13-
jQuery.ajaxTransport('* text html xml json', function(options, userOptions, jqXHR){
15+
$.ajaxTransport('* text html xml json', function(options, userOptions, jqXHR){
1416
// XDomainRequests must be: asynchronous, GET or POST methods, HTTP or HTTPS protocol, and same scheme as calling page
1517
if (options.crossDomain && options.async && getOrPostRegEx.test(options.type) && httpRegEx.test(options.url) && sameSchemeRegEx.test(options.url)) {
1618
var xdr = null;
@@ -38,7 +40,7 @@ if (!jQuery.support.cors && jQuery.ajaxTransport && window.XDomainRequest) {
3840
responses.html = xdr.responseText;
3941
} else if (userType === 'json' || (userType !== 'text' && jsonRegEx.test(xdr.contentType))) {
4042
try {
41-
responses.json = jQuery.parseJSON(xdr.responseText);
43+
responses.json = $.parseJSON(xdr.responseText);
4244
} catch(e) {
4345
status.code = 500;
4446
status.message = 'parseerror';
@@ -74,7 +76,7 @@ if (!jQuery.support.cors && jQuery.ajaxTransport && window.XDomainRequest) {
7476
};
7577
var postData = '';
7678
if (userOptions.data) {
77-
postData = (jQuery.type(userOptions.data) === 'string') ? userOptions.data : jQuery.param(userOptions.data);
79+
postData = ($.type(userOptions.data) === 'string') ? userOptions.data : $.param(userOptions.data);
7880
}
7981
xdr.open(options.type, options.url);
8082
xdr.send(postData);
@@ -88,3 +90,5 @@ if (!jQuery.support.cors && jQuery.ajaxTransport && window.XDomainRequest) {
8890
}
8991
});
9092
}
93+
94+
})(jQuery);

0 commit comments

Comments
 (0)
Please sign in to comment.