Skip to content

Commit 3303a99

Browse files
committed
vis
1 parent 22e48d4 commit 3303a99

22 files changed

+7864
-2
lines changed

Diff for: 1.7/ajax.js

+1,000
Large diffs are not rendered by default.

Diff for: 1.7/ajax/jsonp.js

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
(function( jQuery ) {
2+
3+
var jsc = jQuery.now(),
4+
jsre = /(\=)\?(&|$)|\?\?/i;
5+
6+
// Default jsonp settings
7+
jQuery.ajaxSetup({
8+
jsonp: "callback",
9+
jsonpCallback: function() {
10+
return jQuery.expando + "_" + ( jsc++ );
11+
}
12+
});
13+
14+
// Detect, normalize options and install callbacks for jsonp requests
15+
jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) {
16+
17+
var inspectData = s.contentType === "application/x-www-form-urlencoded" &&
18+
( typeof s.data === "string" );
19+
20+
if ( s.dataTypes[ 0 ] === "jsonp" ||
21+
s.jsonp !== false && ( jsre.test( s.url ) ||
22+
inspectData && jsre.test( s.data ) ) ) {
23+
24+
var responseContainer,
25+
jsonpCallback = s.jsonpCallback =
26+
jQuery.isFunction( s.jsonpCallback ) ? s.jsonpCallback() : s.jsonpCallback,
27+
previous = window[ jsonpCallback ],
28+
url = s.url,
29+
data = s.data,
30+
replace = "$1" + jsonpCallback + "$2";
31+
32+
if ( s.jsonp !== false ) {
33+
url = url.replace( jsre, replace );
34+
if ( s.url === url ) {
35+
if ( inspectData ) {
36+
data = data.replace( jsre, replace );
37+
}
38+
if ( s.data === data ) {
39+
// Add callback manually
40+
url += (/\?/.test( url ) ? "&" : "?") + s.jsonp + "=" + jsonpCallback;
41+
}
42+
}
43+
}
44+
45+
s.url = url;
46+
s.data = data;
47+
48+
// Install callback
49+
window[ jsonpCallback ] = function( response ) {
50+
responseContainer = [ response ];
51+
};
52+
53+
// Clean-up function
54+
jqXHR.always(function() {
55+
// Set callback back to previous value
56+
window[ jsonpCallback ] = previous;
57+
// Call if it was a function and we have a response
58+
if ( responseContainer && jQuery.isFunction( previous ) ) {
59+
window[ jsonpCallback ]( responseContainer[ 0 ] );
60+
}
61+
});
62+
63+
// Use data converter to retrieve json after script execution
64+
s.converters["script json"] = function() {
65+
if ( !responseContainer ) {
66+
jQuery.error( jsonpCallback + " was not called" );
67+
}
68+
return responseContainer[ 0 ];
69+
};
70+
71+
// force json dataType
72+
s.dataTypes[ 0 ] = "json";
73+
74+
// Delegate to script
75+
return "script";
76+
}
77+
});
78+
79+
})( jQuery );

Diff for: 1.7/ajax/script.js

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
(function( jQuery ) {
2+
3+
// Install script dataType
4+
jQuery.ajaxSetup({
5+
accepts: {
6+
script: "text/javascript, application/javascript, application/ecmascript, application/x-ecmascript"
7+
},
8+
contents: {
9+
script: /javascript|ecmascript/
10+
},
11+
converters: {
12+
"text script": function( text ) {
13+
jQuery.globalEval( text );
14+
return text;
15+
}
16+
}
17+
});
18+
19+
// Handle cache's special case and global
20+
jQuery.ajaxPrefilter( "script", function( s ) {
21+
if ( s.cache === undefined ) {
22+
s.cache = false;
23+
}
24+
if ( s.crossDomain ) {
25+
s.type = "GET";
26+
s.global = false;
27+
}
28+
});
29+
30+
// Bind script tag hack transport
31+
jQuery.ajaxTransport( "script", function(s) {
32+
33+
// This transport only deals with cross domain requests
34+
if ( s.crossDomain ) {
35+
36+
var script,
37+
head = document.head || document.getElementsByTagName( "head" )[0] || document.documentElement;
38+
39+
return {
40+
41+
send: function( _, callback ) {
42+
43+
script = document.createElement( "script" );
44+
45+
script.async = "async";
46+
47+
if ( s.scriptCharset ) {
48+
script.charset = s.scriptCharset;
49+
}
50+
51+
script.src = s.url;
52+
53+
// Attach handlers for all browsers
54+
script.onload = script.onreadystatechange = function( _, isAbort ) {
55+
56+
if ( isAbort || !script.readyState || /loaded|complete/.test( script.readyState ) ) {
57+
58+
// Handle memory leak in IE
59+
script.onload = script.onreadystatechange = null;
60+
61+
// Remove the script
62+
if ( head && script.parentNode ) {
63+
head.removeChild( script );
64+
}
65+
66+
// Dereference the script
67+
script = undefined;
68+
69+
// Callback if not abort
70+
if ( !isAbort ) {
71+
callback( 200, "success" );
72+
}
73+
}
74+
};
75+
// Use insertBefore instead of appendChild to circumvent an IE6 bug.
76+
// This arises when a base node is used (#2709 and #4378).
77+
head.insertBefore( script, head.firstChild );
78+
},
79+
80+
abort: function() {
81+
if ( script ) {
82+
script.onload( 0, 1 );
83+
}
84+
}
85+
};
86+
}
87+
});
88+
89+
})( jQuery );

Diff for: 1.7/ajax/xhr.js

+218
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
(function( jQuery ) {
2+
3+
var // #5280: Internet Explorer will keep connections alive if we don't abort on unload
4+
xhrOnUnloadAbort = window.ActiveXObject ? function() {
5+
// Abort all pending requests
6+
for ( var key in xhrCallbacks ) {
7+
xhrCallbacks[ key ]( 0, 1 );
8+
}
9+
} : false,
10+
xhrId = 0,
11+
xhrCallbacks;
12+
13+
// Functions to create xhrs
14+
function createStandardXHR() {
15+
try {
16+
return new window.XMLHttpRequest();
17+
} catch( e ) {}
18+
}
19+
20+
function createActiveXHR() {
21+
try {
22+
return new window.ActiveXObject( "Microsoft.XMLHTTP" );
23+
} catch( e ) {}
24+
}
25+
26+
// Create the request object
27+
// (This is still attached to ajaxSettings for backward compatibility)
28+
jQuery.ajaxSettings.xhr = window.ActiveXObject ?
29+
/* Microsoft failed to properly
30+
* implement the XMLHttpRequest in IE7 (can't request local files),
31+
* so we use the ActiveXObject when it is available
32+
* Additionally XMLHttpRequest can be disabled in IE7/IE8 so
33+
* we need a fallback.
34+
*/
35+
function() {
36+
return !this.isLocal && createStandardXHR() || createActiveXHR();
37+
} :
38+
// For all other browsers, use the standard XMLHttpRequest object
39+
createStandardXHR;
40+
41+
// Determine support properties
42+
(function( xhr ) {
43+
jQuery.extend( jQuery.support, {
44+
ajax: !!xhr,
45+
cors: !!xhr && ( "withCredentials" in xhr )
46+
});
47+
})( jQuery.ajaxSettings.xhr() );
48+
49+
// Create transport if the browser can provide an xhr
50+
if ( jQuery.support.ajax ) {
51+
52+
jQuery.ajaxTransport(function( s ) {
53+
// Cross domain only allowed if supported through XMLHttpRequest
54+
if ( !s.crossDomain || jQuery.support.cors ) {
55+
56+
var callback;
57+
58+
return {
59+
send: function( headers, complete ) {
60+
61+
// Get a new xhr
62+
var xhr = s.xhr(),
63+
handle,
64+
i;
65+
66+
// Open the socket
67+
// Passing null username, generates a login popup on Opera (#2865)
68+
if ( s.username ) {
69+
xhr.open( s.type, s.url, s.async, s.username, s.password );
70+
} else {
71+
xhr.open( s.type, s.url, s.async );
72+
}
73+
74+
// Apply custom fields if provided
75+
if ( s.xhrFields ) {
76+
for ( i in s.xhrFields ) {
77+
xhr[ i ] = s.xhrFields[ i ];
78+
}
79+
}
80+
81+
// Override mime type if needed
82+
if ( s.mimeType && xhr.overrideMimeType ) {
83+
xhr.overrideMimeType( s.mimeType );
84+
}
85+
86+
// X-Requested-With header
87+
// For cross-domain requests, seeing as conditions for a preflight are
88+
// akin to a jigsaw puzzle, we simply never set it to be sure.
89+
// (it can always be set on a per-request basis or even using ajaxSetup)
90+
// For same-domain requests, won't change header if already provided.
91+
if ( !s.crossDomain && !headers["X-Requested-With"] ) {
92+
headers[ "X-Requested-With" ] = "XMLHttpRequest";
93+
}
94+
95+
// Need an extra try/catch for cross domain requests in Firefox 3
96+
try {
97+
for ( i in headers ) {
98+
xhr.setRequestHeader( i, headers[ i ] );
99+
}
100+
} catch( _ ) {}
101+
102+
// Do send the request
103+
// This may raise an exception which is actually
104+
// handled in jQuery.ajax (so no try/catch here)
105+
xhr.send( ( s.hasContent && s.data ) || null );
106+
107+
// Listener
108+
callback = function( _, isAbort ) {
109+
110+
var status,
111+
statusText,
112+
responseHeaders,
113+
responses,
114+
xml;
115+
116+
// Firefox throws exceptions when accessing properties
117+
// of an xhr when a network error occured
118+
// http://helpful.knobs-dials.com/index.php/Component_returned_failure_code:_0x80040111_(NS_ERROR_NOT_AVAILABLE)
119+
try {
120+
121+
// Was never called and is aborted or complete
122+
if ( callback && ( isAbort || xhr.readyState === 4 ) ) {
123+
124+
// Only called once
125+
callback = undefined;
126+
127+
// Do not keep as active anymore
128+
if ( handle ) {
129+
xhr.onreadystatechange = jQuery.noop;
130+
if ( xhrOnUnloadAbort ) {
131+
delete xhrCallbacks[ handle ];
132+
}
133+
}
134+
135+
// If it's an abort
136+
if ( isAbort ) {
137+
// Abort it manually if needed
138+
if ( xhr.readyState !== 4 ) {
139+
xhr.abort();
140+
}
141+
} else {
142+
status = xhr.status;
143+
responseHeaders = xhr.getAllResponseHeaders();
144+
responses = {};
145+
xml = xhr.responseXML;
146+
147+
// Construct response list
148+
if ( xml && xml.documentElement /* #4958 */ ) {
149+
responses.xml = xml;
150+
}
151+
responses.text = xhr.responseText;
152+
153+
// Firefox throws an exception when accessing
154+
// statusText for faulty cross-domain requests
155+
try {
156+
statusText = xhr.statusText;
157+
} catch( e ) {
158+
// We normalize with Webkit giving an empty statusText
159+
statusText = "";
160+
}
161+
162+
// Filter status for non standard behaviors
163+
164+
// If the request is local and we have data: assume a success
165+
// (success with no data won't get notified, that's the best we
166+
// can do given current implementations)
167+
if ( !status && s.isLocal && !s.crossDomain ) {
168+
status = responses.text ? 200 : 404;
169+
// IE - #1450: sometimes returns 1223 when it should be 204
170+
} else if ( status === 1223 ) {
171+
status = 204;
172+
}
173+
}
174+
}
175+
} catch( firefoxAccessException ) {
176+
if ( !isAbort ) {
177+
complete( -1, firefoxAccessException );
178+
}
179+
}
180+
181+
// Call complete if needed
182+
if ( responses ) {
183+
complete( status, statusText, responses, responseHeaders );
184+
}
185+
};
186+
187+
// if we're in sync mode or it's in cache
188+
// and has been retrieved directly (IE6 & IE7)
189+
// we need to manually fire the callback
190+
if ( !s.async || xhr.readyState === 4 ) {
191+
callback();
192+
} else {
193+
handle = ++xhrId;
194+
if ( xhrOnUnloadAbort ) {
195+
// Create the active xhrs callbacks list if needed
196+
// and attach the unload handler
197+
if ( !xhrCallbacks ) {
198+
xhrCallbacks = {};
199+
jQuery( window ).unload( xhrOnUnloadAbort );
200+
}
201+
// Add to list of active xhrs callbacks
202+
xhrCallbacks[ handle ] = callback;
203+
}
204+
xhr.onreadystatechange = callback;
205+
}
206+
},
207+
208+
abort: function() {
209+
if ( callback ) {
210+
callback(0,1);
211+
}
212+
}
213+
};
214+
}
215+
});
216+
}
217+
218+
})( jQuery );

0 commit comments

Comments
 (0)