Merge branch 'master' of git://github.com/jquery/jquery into bug_2773
This commit is contained in:
commit
9e5ec378e3
70 changed files with 1736 additions and 15275 deletions
361
src/ajax.js
361
src/ajax.js
|
@ -4,18 +4,22 @@ var r20 = /%20/g,
|
|||
rbracket = /\[\]$/,
|
||||
rCRLF = /\r?\n/g,
|
||||
rhash = /#.*$/,
|
||||
rheaders = /^(.*?):\s*(.*?)\r?$/mg, // IE leaves an \r character at EOL
|
||||
rheaders = /^(.*?):[ \t]*([^\r\n]*)\r?$/mg, // IE leaves an \r character at EOL
|
||||
rinput = /^(?:color|date|datetime|email|hidden|month|number|password|range|search|tel|text|time|url|week)$/i,
|
||||
// #7653, #8125, #8152: local protocol detection
|
||||
rlocalProtocol = /(?:^file|^widget|\-extension):$/,
|
||||
rnoContent = /^(?:GET|HEAD)$/,
|
||||
rprotocol = /^\/\//,
|
||||
rquery = /\?/,
|
||||
rscript = /<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,
|
||||
rselectTextarea = /^(?:select|textarea)/i,
|
||||
rspacesAjax = /\s+/,
|
||||
rts = /([?&])_=[^&]*/,
|
||||
rurl = /^(\w+:)?\/\/([^\/?#:]+)(?::(\d+))?/,
|
||||
|
||||
// Slice function
|
||||
sliceFunc = Array.prototype.slice,
|
||||
rucHeaders = /(^|\-)([a-z])/g,
|
||||
rucHeadersFunc = function( _, $1, $2 ) {
|
||||
return $1 + $2.toUpperCase();
|
||||
},
|
||||
rurl = /^([\w\+\.\-]+:)(?:\/\/([^\/?#:]*)(?::(\d+))?|\/[^\/])/,
|
||||
|
||||
// Keep a copy of the old load method
|
||||
_load = jQuery.fn.load,
|
||||
|
@ -36,7 +40,28 @@ var r20 = /%20/g,
|
|||
* 2) the catchall symbol "*" can be used
|
||||
* 3) selection will start with transport dataType and THEN go to "*" if needed
|
||||
*/
|
||||
transports = {};
|
||||
transports = {},
|
||||
|
||||
// Document location
|
||||
ajaxLocation,
|
||||
|
||||
// Document location segments
|
||||
ajaxLocParts;
|
||||
|
||||
// #8138, IE may throw an exception when accessing
|
||||
// a field from document.location if document.domain has been set
|
||||
try {
|
||||
ajaxLocation = document.location.href;
|
||||
} catch( e ) {
|
||||
// Use the href attribute of an A element
|
||||
// since IE will modify it given document.location
|
||||
ajaxLocation = document.createElement( "a" );
|
||||
ajaxLocation.href = "";
|
||||
ajaxLocation = ajaxLocation.href;
|
||||
}
|
||||
|
||||
// Segment location into parts
|
||||
ajaxLocParts = rurl.exec( ajaxLocation.toLowerCase() );
|
||||
|
||||
// Base "constructor" for jQuery.ajaxPrefilter and jQuery.ajaxTransport
|
||||
function addToPrefiltersOrTransports( structure ) {
|
||||
|
@ -50,7 +75,7 @@ function addToPrefiltersOrTransports( structure ) {
|
|||
}
|
||||
|
||||
if ( jQuery.isFunction( func ) ) {
|
||||
var dataTypes = dataTypeExpression.split( rspacesAjax ),
|
||||
var dataTypes = dataTypeExpression.toLowerCase().split( rspacesAjax ),
|
||||
i = 0,
|
||||
length = dataTypes.length,
|
||||
dataType,
|
||||
|
@ -64,7 +89,7 @@ function addToPrefiltersOrTransports( structure ) {
|
|||
// any existing element
|
||||
placeBefore = /^\+/.test( dataType );
|
||||
if ( placeBefore ) {
|
||||
dataType = dataType.substr( 1 );
|
||||
dataType = dataType.substr( 1 ) || "*";
|
||||
}
|
||||
list = structure[ dataType ] = structure[ dataType ] || [];
|
||||
// then we add to the structure accordingly
|
||||
|
@ -75,7 +100,7 @@ function addToPrefiltersOrTransports( structure ) {
|
|||
}
|
||||
|
||||
//Base inspection function for prefilters and transports
|
||||
function inspectPrefiltersOrTransports( structure, options, originalOptions,
|
||||
function inspectPrefiltersOrTransports( structure, options, originalOptions, jqXHR,
|
||||
dataType /* internal */, inspected /* internal */ ) {
|
||||
|
||||
dataType = dataType || options.dataTypes[ 0 ];
|
||||
|
@ -90,16 +115,16 @@ function inspectPrefiltersOrTransports( structure, options, originalOptions,
|
|||
selection;
|
||||
|
||||
for(; i < length && ( executeOnly || !selection ); i++ ) {
|
||||
selection = list[ i ]( options, originalOptions );
|
||||
selection = list[ i ]( options, originalOptions, jqXHR );
|
||||
// If we got redirected to another dataType
|
||||
// we try there if not done already
|
||||
// we try there if executing only and not done already
|
||||
if ( typeof selection === "string" ) {
|
||||
if ( inspected[ selection ] ) {
|
||||
if ( !executeOnly || inspected[ selection ] ) {
|
||||
selection = undefined;
|
||||
} else {
|
||||
options.dataTypes.unshift( selection );
|
||||
selection = inspectPrefiltersOrTransports(
|
||||
structure, options, originalOptions, selection, inspected );
|
||||
structure, options, originalOptions, jqXHR, selection, inspected );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -107,7 +132,7 @@ function inspectPrefiltersOrTransports( structure, options, originalOptions,
|
|||
// we try the catchall dataType if not done already
|
||||
if ( ( executeOnly || !selection ) && !inspected[ "*" ] ) {
|
||||
selection = inspectPrefiltersOrTransports(
|
||||
structure, options, originalOptions, "*", inspected );
|
||||
structure, options, originalOptions, jqXHR, "*", inspected );
|
||||
}
|
||||
// unnecessary when only executing (prefilters)
|
||||
// but it'll be ignored by the caller in that case
|
||||
|
@ -139,7 +164,7 @@ jQuery.fn.extend({
|
|||
if ( jQuery.isFunction( params ) ) {
|
||||
// We assume that it's the callback
|
||||
callback = params;
|
||||
params = null;
|
||||
params = undefined;
|
||||
|
||||
// Otherwise, build a param string
|
||||
} else if ( typeof params === "object" ) {
|
||||
|
@ -157,14 +182,14 @@ jQuery.fn.extend({
|
|||
dataType: "html",
|
||||
data: params,
|
||||
// Complete callback (responseText is used internally)
|
||||
complete: function( jXHR, status, responseText ) {
|
||||
// Store the response as specified by the jXHR object
|
||||
responseText = jXHR.responseText;
|
||||
complete: function( jqXHR, status, responseText ) {
|
||||
// Store the response as specified by the jqXHR object
|
||||
responseText = jqXHR.responseText;
|
||||
// If successful, inject the HTML into all the matched elements
|
||||
if ( jXHR.isResolved() ) {
|
||||
if ( jqXHR.isResolved() ) {
|
||||
// #4825: Get the actual response in case
|
||||
// a dataFilter is present in ajaxSettings
|
||||
jXHR.done(function( r ) {
|
||||
jqXHR.done(function( r ) {
|
||||
responseText = r;
|
||||
});
|
||||
// See if a selector was specified
|
||||
|
@ -183,7 +208,7 @@ jQuery.fn.extend({
|
|||
}
|
||||
|
||||
if ( callback ) {
|
||||
self.each( callback, [ responseText, status, jXHR ] );
|
||||
self.each( callback, [ responseText, status, jqXHR ] );
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -231,7 +256,7 @@ jQuery.each( [ "get", "post" ], function( i, method ) {
|
|||
if ( jQuery.isFunction( data ) ) {
|
||||
type = type || callback;
|
||||
callback = data;
|
||||
data = null;
|
||||
data = undefined;
|
||||
}
|
||||
|
||||
return jQuery.ajax({
|
||||
|
@ -247,22 +272,39 @@ jQuery.each( [ "get", "post" ], function( i, method ) {
|
|||
jQuery.extend({
|
||||
|
||||
getScript: function( url, callback ) {
|
||||
return jQuery.get( url, null, callback, "script" );
|
||||
return jQuery.get( url, undefined, callback, "script" );
|
||||
},
|
||||
|
||||
getJSON: function( url, data, callback ) {
|
||||
return jQuery.get( url, data, callback, "json" );
|
||||
},
|
||||
|
||||
ajaxSetup: function( settings ) {
|
||||
jQuery.extend( true, jQuery.ajaxSettings, settings );
|
||||
if ( settings.context ) {
|
||||
jQuery.ajaxSettings.context = settings.context;
|
||||
// Creates a full fledged settings object into target
|
||||
// with both ajaxSettings and settings fields.
|
||||
// If target is omitted, writes into ajaxSettings.
|
||||
ajaxSetup: function ( target, settings ) {
|
||||
if ( !settings ) {
|
||||
// Only one parameter, we extend ajaxSettings
|
||||
settings = target;
|
||||
target = jQuery.extend( true, jQuery.ajaxSettings, settings );
|
||||
} else {
|
||||
// target was provided, we extend into it
|
||||
jQuery.extend( true, target, jQuery.ajaxSettings, settings );
|
||||
}
|
||||
// Flatten fields we don't want deep extended
|
||||
for( var field in { context: 1, url: 1 } ) {
|
||||
if ( field in settings ) {
|
||||
target[ field ] = settings[ field ];
|
||||
} else if( field in jQuery.ajaxSettings ) {
|
||||
target[ field ] = jQuery.ajaxSettings[ field ];
|
||||
}
|
||||
}
|
||||
return target;
|
||||
},
|
||||
|
||||
ajaxSettings: {
|
||||
url: location.href,
|
||||
url: ajaxLocation,
|
||||
isLocal: rlocalProtocol.test( ajaxLocParts[ 1 ] ),
|
||||
global: true,
|
||||
type: "GET",
|
||||
contentType: "application/x-www-form-urlencoded",
|
||||
|
@ -324,9 +366,8 @@ jQuery.extend({
|
|||
// Main method
|
||||
ajax: function( url, options ) {
|
||||
|
||||
// If options is not an object,
|
||||
// we simulate pre-1.5 signature
|
||||
if ( typeof options !== "object" ) {
|
||||
// If url is an object, simulate pre-1.5 signature
|
||||
if ( typeof url === "object" ) {
|
||||
options = url;
|
||||
url = undefined;
|
||||
}
|
||||
|
@ -335,19 +376,22 @@ jQuery.extend({
|
|||
options = options || {};
|
||||
|
||||
var // Create the final options object
|
||||
s = jQuery.extend( true, {}, jQuery.ajaxSettings, options ),
|
||||
// Callbacks contexts
|
||||
// We force the original context if it exists
|
||||
// or take it from jQuery.ajaxSettings otherwise
|
||||
// (plain objects used as context get extended)
|
||||
callbackContext =
|
||||
( s.context = ( "context" in options ? options : jQuery.ajaxSettings ).context ) || s,
|
||||
globalEventContext = callbackContext === s ? jQuery.event : jQuery( callbackContext ),
|
||||
s = jQuery.ajaxSetup( {}, options ),
|
||||
// Callbacks context
|
||||
callbackContext = s.context || s,
|
||||
// Context for global events
|
||||
// It's the callbackContext if one was provided in the options
|
||||
// and if it's a DOM node or a jQuery collection
|
||||
globalEventContext = callbackContext !== s &&
|
||||
( callbackContext.nodeType || callbackContext instanceof jQuery ) ?
|
||||
jQuery( callbackContext ) : jQuery.event,
|
||||
// Deferreds
|
||||
deferred = jQuery.Deferred(),
|
||||
completeDeferred = jQuery._Deferred(),
|
||||
// Status-dependent callbacks
|
||||
statusCode = s.statusCode || {},
|
||||
// ifModified key
|
||||
ifModifiedKey,
|
||||
// Headers (they are sent all at once)
|
||||
requestHeaders = {},
|
||||
// Response headers
|
||||
|
@ -358,22 +402,22 @@ jQuery.extend({
|
|||
// timeout handle
|
||||
timeoutTimer,
|
||||
// Cross-domain detection vars
|
||||
loc = document.location,
|
||||
protocol = loc.protocol || "http:",
|
||||
parts,
|
||||
// The jXHR state
|
||||
// The jqXHR state
|
||||
state = 0,
|
||||
// To know if global events are to be dispatched
|
||||
fireGlobals,
|
||||
// Loop variable
|
||||
i,
|
||||
// Fake xhr
|
||||
jXHR = {
|
||||
jqXHR = {
|
||||
|
||||
readyState: 0,
|
||||
|
||||
// Caches the header
|
||||
setRequestHeader: function( name, value ) {
|
||||
if ( state === 0 ) {
|
||||
requestHeaders[ name.toLowerCase() ] = value;
|
||||
if ( !state ) {
|
||||
requestHeaders[ name.toLowerCase().replace( rucHeaders, rucHeadersFunc ) ] = value;
|
||||
}
|
||||
return this;
|
||||
},
|
||||
|
@ -395,13 +439,22 @@ jQuery.extend({
|
|||
}
|
||||
match = responseHeaders[ key.toLowerCase() ];
|
||||
}
|
||||
return match || null;
|
||||
return match === undefined ? null : match;
|
||||
},
|
||||
|
||||
// Overrides response content-type header
|
||||
overrideMimeType: function( type ) {
|
||||
if ( !state ) {
|
||||
s.mimeType = type;
|
||||
}
|
||||
return this;
|
||||
},
|
||||
|
||||
// Cancel the request
|
||||
abort: function( statusText ) {
|
||||
statusText = statusText || "abort";
|
||||
if ( transport ) {
|
||||
transport.abort( statusText || "abort" );
|
||||
transport.abort( statusText );
|
||||
}
|
||||
done( 0, statusText );
|
||||
return this;
|
||||
|
@ -411,7 +464,7 @@ jQuery.extend({
|
|||
// Callback for when everything is done
|
||||
// It is defined here because jslint complains if it is declared
|
||||
// at the end of the function (which would be more logical and readable)
|
||||
function done( status, statusText, responses, headers) {
|
||||
function done( status, statusText, responses, headers ) {
|
||||
|
||||
// Called once
|
||||
if ( state === 2 ) {
|
||||
|
@ -427,19 +480,19 @@ jQuery.extend({
|
|||
}
|
||||
|
||||
// Dereference transport for early garbage collection
|
||||
// (no matter how long the jXHR object will be used)
|
||||
// (no matter how long the jqXHR object will be used)
|
||||
transport = undefined;
|
||||
|
||||
// Cache response headers
|
||||
responseHeadersString = headers || "";
|
||||
|
||||
// Set readyState
|
||||
jXHR.readyState = status ? 4 : 0;
|
||||
jqXHR.readyState = status ? 4 : 0;
|
||||
|
||||
var isSuccess,
|
||||
success,
|
||||
error = ( statusText = statusText || "error" ),
|
||||
response = responses ? ajaxHandleResponses( s, jXHR, responses ) : undefined,
|
||||
error,
|
||||
response = responses ? ajaxHandleResponses( s, jqXHR, responses ) : undefined,
|
||||
lastModified,
|
||||
etag;
|
||||
|
||||
|
@ -449,11 +502,11 @@ jQuery.extend({
|
|||
// Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
|
||||
if ( s.ifModified ) {
|
||||
|
||||
if ( ( lastModified = jXHR.getResponseHeader( "Last-Modified" ) ) ) {
|
||||
jQuery.lastModified[ s.url ] = lastModified;
|
||||
if ( ( lastModified = jqXHR.getResponseHeader( "Last-Modified" ) ) ) {
|
||||
jQuery.lastModified[ ifModifiedKey ] = lastModified;
|
||||
}
|
||||
if ( ( etag = jXHR.getResponseHeader( "Etag" ) ) ) {
|
||||
jQuery.etag[ s.url ] = etag;
|
||||
if ( ( etag = jqXHR.getResponseHeader( "Etag" ) ) ) {
|
||||
jQuery.etag[ ifModifiedKey ] = etag;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -473,36 +526,46 @@ jQuery.extend({
|
|||
} catch(e) {
|
||||
// We have a parsererror
|
||||
statusText = "parsererror";
|
||||
error = "" + e;
|
||||
error = e;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// We extract error from statusText
|
||||
// then normalize statusText and status for non-aborts
|
||||
error = statusText;
|
||||
if( !statusText || status ) {
|
||||
statusText = "error";
|
||||
if ( status < 0 ) {
|
||||
status = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Set data for the fake xhr object
|
||||
jXHR.status = status;
|
||||
jXHR.statusText = statusText;
|
||||
jqXHR.status = status;
|
||||
jqXHR.statusText = statusText;
|
||||
|
||||
// Success/Error
|
||||
if ( isSuccess ) {
|
||||
deferred.resolveWith( callbackContext, [ success, statusText, jXHR ] );
|
||||
deferred.resolveWith( callbackContext, [ success, statusText, jqXHR ] );
|
||||
} else {
|
||||
deferred.rejectWith( callbackContext, [ jXHR, statusText, error ] );
|
||||
deferred.rejectWith( callbackContext, [ jqXHR, statusText, error ] );
|
||||
}
|
||||
|
||||
// Status-dependent callbacks
|
||||
jXHR.statusCode( statusCode );
|
||||
jqXHR.statusCode( statusCode );
|
||||
statusCode = undefined;
|
||||
|
||||
if ( s.global ) {
|
||||
if ( fireGlobals ) {
|
||||
globalEventContext.trigger( "ajax" + ( isSuccess ? "Success" : "Error" ),
|
||||
[ jXHR, s, isSuccess ? success : error ] );
|
||||
[ jqXHR, s, isSuccess ? success : error ] );
|
||||
}
|
||||
|
||||
// Complete
|
||||
completeDeferred.resolveWith( callbackContext, [ jXHR, statusText ] );
|
||||
completeDeferred.resolveWith( callbackContext, [ jqXHR, statusText ] );
|
||||
|
||||
if ( s.global ) {
|
||||
globalEventContext.trigger( "ajaxComplete", [ jXHR, s] );
|
||||
if ( fireGlobals ) {
|
||||
globalEventContext.trigger( "ajaxComplete", [ jqXHR, s] );
|
||||
// Handle the global AJAX counter
|
||||
if ( !( --jQuery.active ) ) {
|
||||
jQuery.event.trigger( "ajaxStop" );
|
||||
|
@ -511,13 +574,13 @@ jQuery.extend({
|
|||
}
|
||||
|
||||
// Attach deferreds
|
||||
deferred.promise( jXHR );
|
||||
jXHR.success = jXHR.done;
|
||||
jXHR.error = jXHR.fail;
|
||||
jXHR.complete = completeDeferred.done;
|
||||
deferred.promise( jqXHR );
|
||||
jqXHR.success = jqXHR.done;
|
||||
jqXHR.error = jqXHR.fail;
|
||||
jqXHR.complete = completeDeferred.done;
|
||||
|
||||
// Status-dependent callbacks
|
||||
jXHR.statusCode = function( map ) {
|
||||
jqXHR.statusCode = function( map ) {
|
||||
if ( map ) {
|
||||
var tmp;
|
||||
if ( state < 2 ) {
|
||||
|
@ -525,16 +588,17 @@ jQuery.extend({
|
|||
statusCode[ tmp ] = [ statusCode[tmp], map[tmp] ];
|
||||
}
|
||||
} else {
|
||||
tmp = map[ jXHR.status ];
|
||||
jXHR.then( tmp, tmp );
|
||||
tmp = map[ jqXHR.status ];
|
||||
jqXHR.then( tmp, tmp );
|
||||
}
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
// Remove hash character (#7531: and string promotion)
|
||||
// Add protocol if not provided (#5866: IE7 issue with protocol-less urls)
|
||||
// We also use the url parameter if available
|
||||
s.url = ( "" + ( url || s.url ) ).replace( rhash, "" );
|
||||
s.url = ( ( url || s.url ) + "" ).replace( rhash, "" ).replace( rprotocol, ajaxLocParts[ 1 ] + "//" );
|
||||
|
||||
// Extract dataTypes list
|
||||
s.dataTypes = jQuery.trim( s.dataType || "*" ).toLowerCase().split( rspacesAjax );
|
||||
|
@ -542,12 +606,10 @@ jQuery.extend({
|
|||
// Determine if a cross-domain request is in order
|
||||
if ( !s.crossDomain ) {
|
||||
parts = rurl.exec( s.url.toLowerCase() );
|
||||
s.crossDomain = !!(
|
||||
parts &&
|
||||
( parts[ 1 ] && parts[ 1 ] != protocol ||
|
||||
parts[ 2 ] != loc.hostname ||
|
||||
( parts[ 3 ] || ( ( parts[ 1 ] || protocol ) === "http:" ? 80 : 443 ) ) !=
|
||||
( loc.port || ( protocol === "http:" ? 80 : 443 ) ) )
|
||||
s.crossDomain = !!( parts &&
|
||||
( parts[ 1 ] != ajaxLocParts[ 1 ] || parts[ 2 ] != ajaxLocParts[ 2 ] ||
|
||||
( parts[ 3 ] || ( parts[ 1 ] === "http:" ? 80 : 443 ) ) !=
|
||||
( ajaxLocParts[ 3 ] || ( ajaxLocParts[ 1 ] === "http:" ? 80 : 443 ) ) )
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -557,7 +619,15 @@ jQuery.extend({
|
|||
}
|
||||
|
||||
// Apply prefilters
|
||||
inspectPrefiltersOrTransports( prefilters, s, options );
|
||||
inspectPrefiltersOrTransports( prefilters, s, options, jqXHR );
|
||||
|
||||
// If request was aborted inside a prefiler, stop there
|
||||
if ( state === 2 ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// We can fire global events as of now if asked to
|
||||
fireGlobals = s.global;
|
||||
|
||||
// Uppercase the type
|
||||
s.type = s.type.toUpperCase();
|
||||
|
@ -566,7 +636,7 @@ jQuery.extend({
|
|||
s.hasContent = !rnoContent.test( s.type );
|
||||
|
||||
// Watch for a new set of requests
|
||||
if ( s.global && jQuery.active++ === 0 ) {
|
||||
if ( fireGlobals && jQuery.active++ === 0 ) {
|
||||
jQuery.event.trigger( "ajaxStart" );
|
||||
}
|
||||
|
||||
|
@ -578,6 +648,9 @@ jQuery.extend({
|
|||
s.url += ( rquery.test( s.url ) ? "&" : "?" ) + s.data;
|
||||
}
|
||||
|
||||
// Get ifModifiedKey before adding the anti-cache parameter
|
||||
ifModifiedKey = s.url;
|
||||
|
||||
// Add anti-cache in url if needed
|
||||
if ( s.cache === false ) {
|
||||
|
||||
|
@ -592,78 +665,77 @@ jQuery.extend({
|
|||
|
||||
// Set the correct header, if data is being sent
|
||||
if ( s.data && s.hasContent && s.contentType !== false || options.contentType ) {
|
||||
requestHeaders[ "content-type" ] = s.contentType;
|
||||
requestHeaders[ "Content-Type" ] = s.contentType;
|
||||
}
|
||||
|
||||
// Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
|
||||
if ( s.ifModified ) {
|
||||
if ( jQuery.lastModified[ s.url ] ) {
|
||||
requestHeaders[ "if-modified-since" ] = jQuery.lastModified[ s.url ];
|
||||
ifModifiedKey = ifModifiedKey || s.url;
|
||||
if ( jQuery.lastModified[ ifModifiedKey ] ) {
|
||||
requestHeaders[ "If-Modified-Since" ] = jQuery.lastModified[ ifModifiedKey ];
|
||||
}
|
||||
if ( jQuery.etag[ s.url ] ) {
|
||||
requestHeaders[ "if-none-match" ] = jQuery.etag[ s.url ];
|
||||
if ( jQuery.etag[ ifModifiedKey ] ) {
|
||||
requestHeaders[ "If-None-Match" ] = jQuery.etag[ ifModifiedKey ];
|
||||
}
|
||||
}
|
||||
|
||||
// Set the Accepts header for the server, depending on the dataType
|
||||
requestHeaders.accept = s.dataTypes[ 0 ] && s.accepts[ s.dataTypes[0] ] ?
|
||||
requestHeaders.Accept = s.dataTypes[ 0 ] && s.accepts[ s.dataTypes[0] ] ?
|
||||
s.accepts[ s.dataTypes[0] ] + ( s.dataTypes[ 0 ] !== "*" ? ", */*; q=0.01" : "" ) :
|
||||
s.accepts[ "*" ];
|
||||
|
||||
// Check for headers option
|
||||
for ( i in s.headers ) {
|
||||
requestHeaders[ i.toLowerCase() ] = s.headers[ i ];
|
||||
jqXHR.setRequestHeader( i, s.headers[ i ] );
|
||||
}
|
||||
|
||||
// Allow custom headers/mimetypes and early abort
|
||||
if ( s.beforeSend && ( s.beforeSend.call( callbackContext, jXHR, s ) === false || state === 2 ) ) {
|
||||
if ( s.beforeSend && ( s.beforeSend.call( callbackContext, jqXHR, s ) === false || state === 2 ) ) {
|
||||
// Abort if not done already
|
||||
done( 0, "abort" );
|
||||
// Return false
|
||||
jXHR = false;
|
||||
jqXHR.abort();
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
// Install callbacks on deferreds
|
||||
for ( i in { success: 1, error: 1, complete: 1 } ) {
|
||||
jqXHR[ i ]( s[ i ] );
|
||||
}
|
||||
|
||||
// Get transport
|
||||
transport = inspectPrefiltersOrTransports( transports, s, options, jqXHR );
|
||||
|
||||
// If no transport, we auto-abort
|
||||
if ( !transport ) {
|
||||
done( -1, "No Transport" );
|
||||
} else {
|
||||
|
||||
// Install callbacks on deferreds
|
||||
for ( i in { success: 1, error: 1, complete: 1 } ) {
|
||||
jXHR[ i ]( s[ i ] );
|
||||
jqXHR.readyState = 1;
|
||||
// Send global event
|
||||
if ( fireGlobals ) {
|
||||
globalEventContext.trigger( "ajaxSend", [ jqXHR, s ] );
|
||||
}
|
||||
// Timeout
|
||||
if ( s.async && s.timeout > 0 ) {
|
||||
timeoutTimer = setTimeout( function(){
|
||||
jqXHR.abort( "timeout" );
|
||||
}, s.timeout );
|
||||
}
|
||||
|
||||
// Get transport
|
||||
transport = inspectPrefiltersOrTransports( transports, s, options );
|
||||
|
||||
// If no transport, we auto-abort
|
||||
if ( !transport ) {
|
||||
done( 0, "notransport" );
|
||||
} else {
|
||||
// Set state as sending
|
||||
state = jXHR.readyState = 1;
|
||||
// Send global event
|
||||
if ( s.global ) {
|
||||
globalEventContext.trigger( "ajaxSend", [ jXHR, s ] );
|
||||
}
|
||||
// Timeout
|
||||
if ( s.async && s.timeout > 0 ) {
|
||||
timeoutTimer = setTimeout( function(){
|
||||
jXHR.abort( "timeout" );
|
||||
}, s.timeout );
|
||||
}
|
||||
|
||||
try {
|
||||
transport.send( requestHeaders, done );
|
||||
} catch (e) {
|
||||
// Propagate exception as error if not done
|
||||
if ( status === 1 ) {
|
||||
done( 0, "error", "" + e );
|
||||
jXHR = false;
|
||||
// Simply rethrow otherwise
|
||||
} else {
|
||||
jQuery.error( e );
|
||||
}
|
||||
try {
|
||||
state = 1;
|
||||
transport.send( requestHeaders, done );
|
||||
} catch (e) {
|
||||
// Propagate exception as error if not done
|
||||
if ( status < 2 ) {
|
||||
done( -1, e );
|
||||
// Simply rethrow otherwise
|
||||
} else {
|
||||
jQuery.error( e );
|
||||
}
|
||||
}
|
||||
}
|
||||
return jXHR;
|
||||
|
||||
return jqXHR;
|
||||
},
|
||||
|
||||
// Serialize an array of form elements or a set of
|
||||
|
@ -682,7 +754,7 @@ jQuery.extend({
|
|||
}
|
||||
|
||||
// If an array was passed in, assume that it is an array of form elements.
|
||||
if ( jQuery.isArray( a ) || a.jquery ) {
|
||||
if ( jQuery.isArray( a ) || ( a.jquery && !jQuery.isPlainObject( a ) ) ) {
|
||||
// Serialize the form elements
|
||||
jQuery.each( a, function() {
|
||||
add( this.name, this.value );
|
||||
|
@ -729,9 +801,9 @@ function buildParams( prefix, obj, traditional, add ) {
|
|||
|
||||
// Serialize object item.
|
||||
} else {
|
||||
jQuery.each( obj, function( k, v ) {
|
||||
buildParams( prefix + "[" + k + "]", v, traditional, add );
|
||||
});
|
||||
for ( var name in obj ) {
|
||||
buildParams( prefix + "[" + name + "]", obj[ name ], traditional, add );
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
|
@ -758,7 +830,7 @@ jQuery.extend({
|
|||
* - finds the right dataType (mediates between content-type and expected dataType)
|
||||
* - returns the corresponding response
|
||||
*/
|
||||
function ajaxHandleResponses( s, jXHR, responses ) {
|
||||
function ajaxHandleResponses( s, jqXHR, responses ) {
|
||||
|
||||
var contents = s.contents,
|
||||
dataTypes = s.dataTypes,
|
||||
|
@ -771,7 +843,7 @@ function ajaxHandleResponses( s, jXHR, responses ) {
|
|||
// Fill responseXXX fields
|
||||
for( type in responseFields ) {
|
||||
if ( type in responses ) {
|
||||
jXHR[ responseFields[type] ] = responses[ type ];
|
||||
jqXHR[ responseFields[type] ] = responses[ type ];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -779,7 +851,7 @@ function ajaxHandleResponses( s, jXHR, responses ) {
|
|||
while( dataTypes[ 0 ] === "*" ) {
|
||||
dataTypes.shift();
|
||||
if ( ct === undefined ) {
|
||||
ct = jXHR.getResponseHeader( "content-type" );
|
||||
ct = s.mimeType || jqXHR.getResponseHeader( "content-type" );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -831,8 +903,9 @@ function ajaxConvert( s, response ) {
|
|||
}
|
||||
|
||||
var dataTypes = s.dataTypes,
|
||||
converters = s.converters,
|
||||
converters = {},
|
||||
i,
|
||||
key,
|
||||
length = dataTypes.length,
|
||||
tmp,
|
||||
// Current and previous dataTypes
|
||||
|
@ -842,13 +915,23 @@ function ajaxConvert( s, response ) {
|
|||
conversion,
|
||||
// Conversion function
|
||||
conv,
|
||||
// Conversion functions (when text is used in-between)
|
||||
// Conversion functions (transitive conversion)
|
||||
conv1,
|
||||
conv2;
|
||||
|
||||
// For each dataType in the chain
|
||||
for( i = 1; i < length; i++ ) {
|
||||
|
||||
// Create converters map
|
||||
// with lowercased keys
|
||||
if ( i === 1 ) {
|
||||
for( key in s.converters ) {
|
||||
if( typeof key === "string" ) {
|
||||
converters[ key.toLowerCase() ] = s.converters[ key ];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Get the dataTypes
|
||||
prev = current;
|
||||
current = dataTypes[ i ];
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
(function( jQuery ) {
|
||||
|
||||
var jsc = jQuery.now(),
|
||||
jsre = /(\=)(?:\?|%3F)(&|$)|()(?:\?\?|%3F%3F)()/i;
|
||||
jsre = /(\=)\?(&|$)|\?\?/i;
|
||||
|
||||
// Default jsonp settings
|
||||
jQuery.ajaxSetup({
|
||||
jsonp: "callback",
|
||||
jsonpCallback: function() {
|
||||
return "jsonp" + jsc++;
|
||||
return jQuery.expando + "_" + ( jsc++ );
|
||||
}
|
||||
});
|
||||
|
||||
// Detect, normalize options and install callbacks for jsonp requests
|
||||
jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, dataIsString /* internal */ ) {
|
||||
jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) {
|
||||
|
||||
dataIsString = ( typeof s.data === "string" );
|
||||
var dataIsString = ( typeof s.data === "string" );
|
||||
|
||||
if ( s.dataTypes[ 0 ] === "jsonp" ||
|
||||
originalSettings.jsonpCallback ||
|
||||
|
@ -28,7 +28,15 @@ jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, dataIsString
|
|||
previous = window[ jsonpCallback ],
|
||||
url = s.url,
|
||||
data = s.data,
|
||||
replace = "$1" + jsonpCallback + "$2";
|
||||
replace = "$1" + jsonpCallback + "$2",
|
||||
cleanUp = function() {
|
||||
// Set callback back to previous value
|
||||
window[ jsonpCallback ] = previous;
|
||||
// Call if it was a function and we have a response
|
||||
if ( responseContainer && jQuery.isFunction( previous ) ) {
|
||||
window[ jsonpCallback ]( responseContainer[ 0 ] );
|
||||
}
|
||||
};
|
||||
|
||||
if ( s.jsonp !== false ) {
|
||||
url = url.replace( jsre, replace );
|
||||
|
@ -46,32 +54,17 @@ jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, dataIsString
|
|||
s.url = url;
|
||||
s.data = data;
|
||||
|
||||
// Install callback
|
||||
window[ jsonpCallback ] = function( response ) {
|
||||
responseContainer = [ response ];
|
||||
};
|
||||
|
||||
s.complete = [ function() {
|
||||
|
||||
// Set callback back to previous value
|
||||
window[ jsonpCallback ] = previous;
|
||||
|
||||
// Call if it was a function and we have a response
|
||||
if ( previous) {
|
||||
if ( responseContainer && jQuery.isFunction( previous ) ) {
|
||||
window[ jsonpCallback ] ( responseContainer[ 0 ] );
|
||||
}
|
||||
} else {
|
||||
// else, more memory leak avoidance
|
||||
try{
|
||||
delete window[ jsonpCallback ];
|
||||
} catch( e ) {}
|
||||
}
|
||||
|
||||
}, s.complete ];
|
||||
// Install cleanUp function
|
||||
jqXHR.then( cleanUp, cleanUp );
|
||||
|
||||
// Use data converter to retrieve json after script execution
|
||||
s.converters["script json"] = function() {
|
||||
if ( ! responseContainer ) {
|
||||
if ( !responseContainer ) {
|
||||
jQuery.error( jsonpCallback + " was not called" );
|
||||
}
|
||||
return responseContainer[ 0 ];
|
||||
|
|
|
@ -3,13 +3,16 @@
|
|||
// Install script dataType
|
||||
jQuery.ajaxSetup({
|
||||
accepts: {
|
||||
script: "text/javascript, application/javascript"
|
||||
script: "text/javascript, application/javascript, application/ecmascript, application/x-ecmascript"
|
||||
},
|
||||
contents: {
|
||||
script: /javascript/
|
||||
script: /javascript|ecmascript/
|
||||
},
|
||||
converters: {
|
||||
"text script": jQuery.globalEval
|
||||
"text script": function( text ) {
|
||||
jQuery.globalEval( text );
|
||||
return text;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -31,7 +34,7 @@ jQuery.ajaxTransport( "script", function(s) {
|
|||
if ( s.crossDomain ) {
|
||||
|
||||
var script,
|
||||
head = document.getElementsByTagName( "head" )[ 0 ] || document.documentElement;
|
||||
head = document.head || document.getElementsByTagName( "head" )[0] || document.documentElement;
|
||||
|
||||
return {
|
||||
|
||||
|
|
238
src/ajax/xhr.js
238
src/ajax/xhr.js
|
@ -1,17 +1,35 @@
|
|||
(function( jQuery ) {
|
||||
|
||||
var // Next active xhr id
|
||||
var // #5280: next active xhr id and list of active xhrs' callbacks
|
||||
xhrId = jQuery.now(),
|
||||
|
||||
// active xhrs
|
||||
xhrs = {},
|
||||
|
||||
// #5280: see below
|
||||
xhrUnloadAbortInstalled,
|
||||
xhrCallbacks,
|
||||
|
||||
// XHR used to determine supports properties
|
||||
testXHR;
|
||||
|
||||
// #5280: Internet Explorer will keep connections alive if we don't abort on unload
|
||||
function xhrOnUnloadAbort() {
|
||||
jQuery( window ).unload(function() {
|
||||
// Abort all pending requests
|
||||
for ( var key in xhrCallbacks ) {
|
||||
xhrCallbacks[ key ]( 0, 1 );
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Functions to create xhrs
|
||||
function createStandardXHR() {
|
||||
try {
|
||||
return new window.XMLHttpRequest();
|
||||
} catch( e ) {}
|
||||
}
|
||||
|
||||
function createActiveXHR() {
|
||||
try {
|
||||
return new window.ActiveXObject( "Microsoft.XMLHTTP" );
|
||||
} catch( e ) {}
|
||||
}
|
||||
|
||||
// Create the request object
|
||||
// (This is still attached to ajaxSettings for backward compatibility)
|
||||
jQuery.ajaxSettings.xhr = window.ActiveXObject ?
|
||||
|
@ -22,27 +40,13 @@ jQuery.ajaxSettings.xhr = window.ActiveXObject ?
|
|||
* we need a fallback.
|
||||
*/
|
||||
function() {
|
||||
if ( window.location.protocol !== "file:" ) {
|
||||
try {
|
||||
return new window.XMLHttpRequest();
|
||||
} catch( xhrError ) {}
|
||||
}
|
||||
|
||||
try {
|
||||
return new window.ActiveXObject("Microsoft.XMLHTTP");
|
||||
} catch( activeError ) {}
|
||||
return !this.isLocal && createStandardXHR() || createActiveXHR();
|
||||
} :
|
||||
// For all other browsers, use the standard XMLHttpRequest object
|
||||
function() {
|
||||
return new window.XMLHttpRequest();
|
||||
};
|
||||
createStandardXHR;
|
||||
|
||||
// Test if we can create an xhr object
|
||||
try {
|
||||
testXHR = jQuery.ajaxSettings.xhr();
|
||||
} catch( xhrCreationException ) {}
|
||||
|
||||
//Does this browser support XHR requests?
|
||||
testXHR = jQuery.ajaxSettings.xhr();
|
||||
jQuery.support.ajax = !!testXHR;
|
||||
|
||||
// Does this browser support crossDomain XHR requests
|
||||
|
@ -63,26 +67,10 @@ if ( jQuery.support.ajax ) {
|
|||
return {
|
||||
send: function( headers, complete ) {
|
||||
|
||||
// #5280: we need to abort on unload or IE will keep connections alive
|
||||
if ( !xhrUnloadAbortInstalled ) {
|
||||
|
||||
xhrUnloadAbortInstalled = 1;
|
||||
|
||||
jQuery(window).bind( "unload", function() {
|
||||
|
||||
// Abort all pending requests
|
||||
jQuery.each( xhrs, function( _, xhr ) {
|
||||
if ( xhr.onreadystatechange ) {
|
||||
xhr.onreadystatechange( 1 );
|
||||
}
|
||||
} );
|
||||
|
||||
} );
|
||||
}
|
||||
|
||||
// Get a new xhr
|
||||
var xhr = s.xhr(),
|
||||
handle;
|
||||
handle,
|
||||
i;
|
||||
|
||||
// Open the socket
|
||||
// Passing null username, generates a login popup on Opera (#2865)
|
||||
|
@ -92,100 +80,113 @@ if ( jQuery.support.ajax ) {
|
|||
xhr.open( s.type, s.url, s.async );
|
||||
}
|
||||
|
||||
// Apply custom fields if provided
|
||||
if ( s.xhrFields ) {
|
||||
for ( i in s.xhrFields ) {
|
||||
xhr[ i ] = s.xhrFields[ i ];
|
||||
}
|
||||
}
|
||||
|
||||
// Override mime type if needed
|
||||
if ( s.mimeType && xhr.overrideMimeType ) {
|
||||
xhr.overrideMimeType( s.mimeType );
|
||||
}
|
||||
|
||||
// Requested-With header
|
||||
// Not set for crossDomain requests with no content
|
||||
// (see why at http://trac.dojotoolkit.org/ticket/9486)
|
||||
// Won't change header if already provided
|
||||
if ( !( s.crossDomain && !s.hasContent ) && !headers["x-requested-with"] ) {
|
||||
headers[ "x-requested-with" ] = "XMLHttpRequest";
|
||||
if ( !( s.crossDomain && !s.hasContent ) && !headers["X-Requested-With"] ) {
|
||||
headers[ "X-Requested-With" ] = "XMLHttpRequest";
|
||||
}
|
||||
|
||||
// Need an extra try/catch for cross domain requests in Firefox 3
|
||||
try {
|
||||
jQuery.each( headers, function( key, value ) {
|
||||
xhr.setRequestHeader( key, value );
|
||||
} );
|
||||
for ( i in headers ) {
|
||||
xhr.setRequestHeader( i, headers[ i ] );
|
||||
}
|
||||
} catch( _ ) {}
|
||||
|
||||
// Do send the request
|
||||
try {
|
||||
xhr.send( ( s.hasContent && s.data ) || null );
|
||||
} catch( e ) {
|
||||
complete( 0, "error", "" + e );
|
||||
return;
|
||||
}
|
||||
// This may raise an exception which is actually
|
||||
// handled in jQuery.ajax (so no try/catch here)
|
||||
xhr.send( ( s.hasContent && s.data ) || null );
|
||||
|
||||
// Listener
|
||||
callback = function( _, isAbort ) {
|
||||
|
||||
// Was never called and is aborted or complete
|
||||
if ( callback && ( isAbort || xhr.readyState === 4 ) ) {
|
||||
var status,
|
||||
statusText,
|
||||
responseHeaders,
|
||||
responses,
|
||||
xml;
|
||||
|
||||
// Only called once
|
||||
callback = 0;
|
||||
// Firefox throws exceptions when accessing properties
|
||||
// of an xhr when a network error occured
|
||||
// http://helpful.knobs-dials.com/index.php/Component_returned_failure_code:_0x80040111_(NS_ERROR_NOT_AVAILABLE)
|
||||
try {
|
||||
|
||||
// Do not keep as active anymore
|
||||
if ( handle ) {
|
||||
xhr.onreadystatechange = jQuery.noop;
|
||||
delete xhrs[ handle ];
|
||||
}
|
||||
// Was never called and is aborted or complete
|
||||
if ( callback && ( isAbort || xhr.readyState === 4 ) ) {
|
||||
|
||||
// If it's an abort
|
||||
if ( isAbort ) {
|
||||
// Abort it manually if needed
|
||||
if ( xhr.readyState !== 4 ) {
|
||||
xhr.abort();
|
||||
// Only called once
|
||||
callback = undefined;
|
||||
|
||||
// Do not keep as active anymore
|
||||
if ( handle ) {
|
||||
xhr.onreadystatechange = jQuery.noop;
|
||||
delete xhrCallbacks[ handle ];
|
||||
}
|
||||
} else {
|
||||
// Get info
|
||||
var status = xhr.status,
|
||||
statusText,
|
||||
responseHeaders = xhr.getAllResponseHeaders(),
|
||||
responses = {},
|
||||
|
||||
// If it's an abort
|
||||
if ( isAbort ) {
|
||||
// Abort it manually if needed
|
||||
if ( xhr.readyState !== 4 ) {
|
||||
xhr.abort();
|
||||
}
|
||||
} else {
|
||||
status = xhr.status;
|
||||
responseHeaders = xhr.getAllResponseHeaders();
|
||||
responses = {};
|
||||
xml = xhr.responseXML;
|
||||
|
||||
// Construct response list
|
||||
if ( xml && xml.documentElement /* #4958 */ ) {
|
||||
responses.xml = xml;
|
||||
// Construct response list
|
||||
if ( xml && xml.documentElement /* #4958 */ ) {
|
||||
responses.xml = xml;
|
||||
}
|
||||
responses.text = xhr.responseText;
|
||||
|
||||
// Firefox throws an exception when accessing
|
||||
// statusText for faulty cross-domain requests
|
||||
try {
|
||||
statusText = xhr.statusText;
|
||||
} catch( e ) {
|
||||
// We normalize with Webkit giving an empty statusText
|
||||
statusText = "";
|
||||
}
|
||||
|
||||
// Filter status for non standard behaviors
|
||||
|
||||
// If the request is local and we have data: assume a success
|
||||
// (success with no data won't get notified, that's the best we
|
||||
// can do given current implementations)
|
||||
if ( !status && s.isLocal && !s.crossDomain ) {
|
||||
status = responses.text ? 200 : 404;
|
||||
// IE - #1450: sometimes returns 1223 when it should be 204
|
||||
} else if ( status === 1223 ) {
|
||||
status = 204;
|
||||
}
|
||||
}
|
||||
responses.text = xhr.responseText;
|
||||
|
||||
// Firefox throws an exception when accessing
|
||||
// statusText for faulty cross-domain requests
|
||||
try {
|
||||
statusText = xhr.statusText;
|
||||
} catch( e ) {
|
||||
// We normalize with Webkit giving an empty statusText
|
||||
statusText = "";
|
||||
}
|
||||
|
||||
// Filter status for non standard behaviours
|
||||
status =
|
||||
// Opera returns 0 when it should be 304
|
||||
// Webkit returns 0 for failing cross-domain no matter the real status
|
||||
status === 0 ?
|
||||
(
|
||||
// Webkit, Firefox: filter out faulty cross-domain requests
|
||||
!s.crossDomain || statusText ?
|
||||
(
|
||||
// Opera: filter out real aborts #6060
|
||||
responseHeaders ?
|
||||
304 :
|
||||
0
|
||||
) :
|
||||
// We assume 302 but could be anything cross-domain related
|
||||
302
|
||||
) :
|
||||
(
|
||||
// IE sometimes returns 1223 when it should be 204 (see #1450)
|
||||
status == 1223 ?
|
||||
204 :
|
||||
status
|
||||
);
|
||||
|
||||
// Call complete
|
||||
complete( status, statusText, responses, responseHeaders );
|
||||
}
|
||||
} catch( firefoxAccessException ) {
|
||||
if ( !isAbort ) {
|
||||
complete( -1, firefoxAccessException );
|
||||
}
|
||||
}
|
||||
|
||||
// Call complete if needed
|
||||
if ( responses ) {
|
||||
complete( status, statusText, responses, responseHeaders );
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -195,10 +196,15 @@ if ( jQuery.support.ajax ) {
|
|||
if ( !s.async || xhr.readyState === 4 ) {
|
||||
callback();
|
||||
} else {
|
||||
// Add to list of active xhrs
|
||||
// Create the active xhrs callbacks list if needed
|
||||
// and attach the unload handler
|
||||
if ( !xhrCallbacks ) {
|
||||
xhrCallbacks = {};
|
||||
xhrOnUnloadAbort();
|
||||
}
|
||||
// Add to list of active xhrs callbacks
|
||||
handle = xhrId++;
|
||||
xhrs[ handle ] = xhr;
|
||||
xhr.onreadystatechange = callback;
|
||||
xhr.onreadystatechange = xhrCallbacks[ handle ] = callback;
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
@ -198,6 +198,11 @@ jQuery.fn.extend({
|
|||
}
|
||||
}
|
||||
|
||||
// Fixes Bug #2551 -- select.val() broken in IE after form.reset()
|
||||
if ( one && !values.length && options.length ) {
|
||||
return jQuery( options[ index ] ).val();
|
||||
}
|
||||
|
||||
return values;
|
||||
}
|
||||
|
||||
|
|
68
src/core.js
68
src/core.js
|
@ -26,9 +26,6 @@ var jQuery = function( selector, context ) {
|
|||
trimLeft = /^\s+/,
|
||||
trimRight = /\s+$/,
|
||||
|
||||
// Check for non-word characters
|
||||
rnonword = /\W/,
|
||||
|
||||
// Check for digits
|
||||
rdigit = /\d/,
|
||||
|
||||
|
@ -297,7 +294,7 @@ jQuery.fn = jQuery.prototype = {
|
|||
jQuery.fn.init.prototype = jQuery.fn;
|
||||
|
||||
jQuery.extend = jQuery.fn.extend = function() {
|
||||
var options, name, src, copy, copyIsArray, clone,
|
||||
var options, name, src, copy, copyIsArray, clone,
|
||||
target = arguments[0] || {},
|
||||
i = 1,
|
||||
length = arguments.length,
|
||||
|
@ -569,10 +566,8 @@ jQuery.extend({
|
|||
if ( data && rnotwhite.test(data) ) {
|
||||
// Inspired by code by Andrea Giammarchi
|
||||
// http://webreflection.blogspot.com/2007/08/global-scope-evaluation-and-dom.html
|
||||
var head = document.getElementsByTagName("head")[0] || document.documentElement,
|
||||
script = document.createElement("script");
|
||||
|
||||
script.type = "text/javascript";
|
||||
var head = document.head || document.getElementsByTagName( "head" )[0] || document.documentElement,
|
||||
script = document.createElement( "script" );
|
||||
|
||||
if ( jQuery.support.scriptEval() ) {
|
||||
script.appendChild( document.createTextNode( data ) );
|
||||
|
@ -895,22 +890,22 @@ jQuery.extend({
|
|||
isRejected: failDeferred.isResolved,
|
||||
// Get a promise for this deferred
|
||||
// If obj is provided, the promise aspect is added to the object
|
||||
promise: function( obj , i /* internal */ ) {
|
||||
promise: function( obj ) {
|
||||
if ( obj == null ) {
|
||||
if ( promise ) {
|
||||
return promise;
|
||||
}
|
||||
promise = obj = {};
|
||||
}
|
||||
i = promiseMethods.length;
|
||||
var i = promiseMethods.length;
|
||||
while( i-- ) {
|
||||
obj[ promiseMethods[ i ] ] = deferred[ promiseMethods[ i ] ];
|
||||
obj[ promiseMethods[i] ] = deferred[ promiseMethods[i] ];
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
} );
|
||||
// Make sure only one callback list will be used
|
||||
deferred.then( failDeferred.cancel, deferred.cancel );
|
||||
deferred.done( failDeferred.cancel ).fail( deferred.cancel );
|
||||
// Unexpose cancel
|
||||
delete deferred.cancel;
|
||||
// Call given func if any
|
||||
|
@ -922,25 +917,34 @@ jQuery.extend({
|
|||
|
||||
// Deferred helper
|
||||
when: function( object ) {
|
||||
var args = arguments,
|
||||
length = args.length,
|
||||
deferred = length <= 1 && object && jQuery.isFunction( object.promise ) ?
|
||||
var lastIndex = arguments.length,
|
||||
deferred = lastIndex <= 1 && object && jQuery.isFunction( object.promise ) ?
|
||||
object :
|
||||
jQuery.Deferred(),
|
||||
promise = deferred.promise(),
|
||||
resolveArray;
|
||||
promise = deferred.promise();
|
||||
|
||||
if ( length > 1 ) {
|
||||
resolveArray = new Array( length );
|
||||
jQuery.each( args, function( index, element, args ) {
|
||||
jQuery.when( element ).then( function( value ) {
|
||||
args = arguments;
|
||||
resolveArray[ index ] = args.length > 1 ? slice.call( args, 0 ) : value;
|
||||
if( ! --length ) {
|
||||
deferred.resolveWith( promise, resolveArray );
|
||||
}
|
||||
}, deferred.reject );
|
||||
} );
|
||||
if ( lastIndex > 1 ) {
|
||||
var array = slice.call( arguments, 0 ),
|
||||
count = lastIndex,
|
||||
iCallback = function( index ) {
|
||||
return function( value ) {
|
||||
array[ index ] = arguments.length > 1 ? slice.call( arguments, 0 ) : value;
|
||||
if ( !( --count ) ) {
|
||||
deferred.resolveWith( promise, array );
|
||||
}
|
||||
};
|
||||
};
|
||||
while( ( lastIndex-- ) ) {
|
||||
object = array[ lastIndex ];
|
||||
if ( object && jQuery.isFunction( object.promise ) ) {
|
||||
object.promise().then( iCallback(lastIndex), deferred.reject );
|
||||
} else {
|
||||
--count;
|
||||
}
|
||||
}
|
||||
if ( !count ) {
|
||||
deferred.resolveWith( promise, array );
|
||||
}
|
||||
} else if ( deferred !== object ) {
|
||||
deferred.resolve( object );
|
||||
}
|
||||
|
@ -961,18 +965,20 @@ jQuery.extend({
|
|||
return { browser: match[1] || "", version: match[2] || "0" };
|
||||
},
|
||||
|
||||
subclass: function(){
|
||||
sub: function() {
|
||||
function jQuerySubclass( selector, context ) {
|
||||
return new jQuerySubclass.fn.init( selector, context );
|
||||
}
|
||||
jQuery.extend( true, jQuerySubclass, this );
|
||||
jQuerySubclass.superclass = this;
|
||||
jQuerySubclass.fn = jQuerySubclass.prototype = this();
|
||||
jQuerySubclass.fn.constructor = jQuerySubclass;
|
||||
jQuerySubclass.subclass = this.subclass;
|
||||
jQuerySubclass.fn.init = function init( selector, context ) {
|
||||
if (context && context instanceof jQuery && !(context instanceof jQuerySubclass)){
|
||||
if ( context && context instanceof jQuery && !(context instanceof jQuerySubclass) ) {
|
||||
context = jQuerySubclass(context);
|
||||
}
|
||||
|
||||
return jQuery.fn.init.call( this, selector, context, rootjQuerySubclass );
|
||||
};
|
||||
jQuerySubclass.fn.init.prototype = jQuerySubclass.fn;
|
||||
|
@ -1054,6 +1060,6 @@ function doScrollCheck() {
|
|||
}
|
||||
|
||||
// Expose jQuery to the global object
|
||||
return (window.jQuery = window.$ = jQuery);
|
||||
return jQuery;
|
||||
|
||||
})();
|
||||
|
|
|
@ -263,7 +263,7 @@ if ( document.defaultView && document.defaultView.getComputedStyle ) {
|
|||
|
||||
if ( document.documentElement.currentStyle ) {
|
||||
currentStyle = function( elem, name ) {
|
||||
var left,
|
||||
var left,
|
||||
ret = elem.currentStyle && elem.currentStyle[ name ],
|
||||
rsLeft = elem.runtimeStyle && elem.runtimeStyle[ name ],
|
||||
style = elem.style;
|
||||
|
|
35
src/data.js
35
src/data.js
|
@ -24,7 +24,7 @@ jQuery.extend({
|
|||
hasData: function( elem ) {
|
||||
elem = elem.nodeType ? jQuery.cache[ elem[jQuery.expando] ] : elem[ jQuery.expando ];
|
||||
|
||||
return !!elem && !jQuery.isEmptyObject(elem);
|
||||
return !!elem && !isEmptyDataObject( elem );
|
||||
},
|
||||
|
||||
data: function( elem, name, data, pvt /* Internal Use Only */ ) {
|
||||
|
@ -64,11 +64,18 @@ jQuery.extend({
|
|||
|
||||
if ( !cache[ id ] ) {
|
||||
cache[ id ] = {};
|
||||
|
||||
// TODO: This is a hack for 1.5 ONLY. Avoids exposing jQuery
|
||||
// metadata on plain JS objects when the object is serialized using
|
||||
// JSON.stringify
|
||||
if ( !isNode ) {
|
||||
cache[ id ].toJSON = jQuery.noop;
|
||||
}
|
||||
}
|
||||
|
||||
// An object can be passed to jQuery.data instead of a key/value pair; this gets
|
||||
// shallow copied over onto the existing cache
|
||||
if ( typeof name === "object" ) {
|
||||
if ( typeof name === "object" || typeof name === "function" ) {
|
||||
if ( pvt ) {
|
||||
cache[ id ][ internalKey ] = jQuery.extend(cache[ id ][ internalKey ], name);
|
||||
} else {
|
||||
|
@ -130,7 +137,7 @@ jQuery.extend({
|
|||
|
||||
// If there is no data left in the cache, we want to continue
|
||||
// and let the cache object itself get destroyed
|
||||
if ( !jQuery.isEmptyObject(thisCache) ) {
|
||||
if ( !isEmptyDataObject(thisCache) ) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -142,7 +149,7 @@ jQuery.extend({
|
|||
|
||||
// Don't destroy the parent cache unless the internal data object
|
||||
// had been the only thing left in it
|
||||
if ( !jQuery.isEmptyObject(cache[ id ]) ) {
|
||||
if ( !isEmptyDataObject(cache[ id ]) ) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -163,6 +170,13 @@ jQuery.extend({
|
|||
// data if it existed
|
||||
if ( internalCache ) {
|
||||
cache[ id ] = {};
|
||||
// TODO: This is a hack for 1.5 ONLY. Avoids exposing jQuery
|
||||
// metadata on plain JS objects when the object is serialized using
|
||||
// JSON.stringify
|
||||
if ( !isNode ) {
|
||||
cache[ id ].toJSON = jQuery.noop;
|
||||
}
|
||||
|
||||
cache[ id ][ internalKey ] = internalCache;
|
||||
|
||||
// Otherwise, we need to eliminate the expando on the node to avoid
|
||||
|
@ -291,4 +305,17 @@ function dataAttr( elem, key, data ) {
|
|||
return data;
|
||||
}
|
||||
|
||||
// TODO: This is a hack for 1.5 ONLY to allow objects with a single toJSON
|
||||
// property to be considered empty objects; this property always exists in
|
||||
// order to make sure JSON.stringify does not expose internal metadata
|
||||
function isEmptyDataObject( obj ) {
|
||||
for ( var name in obj ) {
|
||||
if ( name !== "toJSON" ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
})( jQuery );
|
||||
|
|
14
src/effects.js
vendored
14
src/effects.js
vendored
|
@ -185,11 +185,11 @@ jQuery.fn.extend({
|
|||
|
||||
} else {
|
||||
var parts = rfxnum.exec(val),
|
||||
start = e.cur() || 0;
|
||||
start = e.cur();
|
||||
|
||||
if ( parts ) {
|
||||
var end = parseFloat( parts[2] ),
|
||||
unit = parts[3] || "px";
|
||||
unit = parts[3] || ( jQuery.cssNumber[ name ] ? "" : "px" );
|
||||
|
||||
// We need to compute starting value
|
||||
if ( unit !== "px" ) {
|
||||
|
@ -336,8 +336,12 @@ jQuery.fx.prototype = {
|
|||
return this.elem[ this.prop ];
|
||||
}
|
||||
|
||||
var r = parseFloat( jQuery.css( this.elem, this.prop ) );
|
||||
return r || 0;
|
||||
var parsed,
|
||||
r = jQuery.css( this.elem, this.prop );
|
||||
// Empty strings, null, undefined and "auto" are converted to 0,
|
||||
// complex values such as "rotate(1rad)" are returned as is,
|
||||
// simple values such as "10px" are parsed to Float.
|
||||
return isNaN( parsed = parseFloat( r ) ) ? !r || r === "auto" ? 0 : r : parsed;
|
||||
},
|
||||
|
||||
// Start an animation from one number to another
|
||||
|
@ -348,7 +352,7 @@ jQuery.fx.prototype = {
|
|||
this.startTime = jQuery.now();
|
||||
this.start = from;
|
||||
this.end = to;
|
||||
this.unit = unit || this.unit || "px";
|
||||
this.unit = unit || this.unit || ( jQuery.cssNumber[ this.prop ] ? "" : "px" );
|
||||
this.now = this.start;
|
||||
this.pos = this.state = 0;
|
||||
|
||||
|
|
105
src/event.js
105
src/event.js
|
@ -7,8 +7,7 @@ var rnamespaces = /\.(.*)$/,
|
|||
rescape = /[^\w\s.|`]/g,
|
||||
fcleanup = function( nm ) {
|
||||
return nm.replace(rescape, "\\$&");
|
||||
},
|
||||
eventKey = "events";
|
||||
};
|
||||
|
||||
/*
|
||||
* A number of helper functions used for managing events.
|
||||
|
@ -24,17 +23,22 @@ jQuery.event = {
|
|||
return;
|
||||
}
|
||||
|
||||
// For whatever reason, IE has trouble passing the window object
|
||||
// around, causing it to be cloned in the process
|
||||
if ( jQuery.isWindow( elem ) && ( elem !== window && !elem.frameElement ) ) {
|
||||
elem = window;
|
||||
// TODO :: Use a try/catch until it's safe to pull this out (likely 1.6)
|
||||
// Minor release fix for bug #8018
|
||||
try {
|
||||
// For whatever reason, IE has trouble passing the window object
|
||||
// around, causing it to be cloned in the process
|
||||
if ( jQuery.isWindow( elem ) && ( elem !== window && !elem.frameElement ) ) {
|
||||
elem = window;
|
||||
}
|
||||
}
|
||||
catch ( e ) {}
|
||||
|
||||
if ( handler === false ) {
|
||||
handler = returnFalse;
|
||||
} else if ( !handler ) {
|
||||
// Fixes bug #7229. Fix recommended by jdalton
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
var handleObjIn, handleObj;
|
||||
|
@ -58,23 +62,10 @@ jQuery.event = {
|
|||
return;
|
||||
}
|
||||
|
||||
var events = elemData[ eventKey ],
|
||||
var events = elemData.events,
|
||||
eventHandle = elemData.handle;
|
||||
|
||||
if ( typeof events === "function" ) {
|
||||
// On plain objects events is a fn that holds the the data
|
||||
// which prevents this data from being JSON serialized
|
||||
// the function does not need to be called, it just contains the data
|
||||
eventHandle = events.handle;
|
||||
events = events.events;
|
||||
|
||||
} else if ( !events ) {
|
||||
if ( !elem.nodeType ) {
|
||||
// On plain objects, create a fn that acts as the holder
|
||||
// of the values to avoid JSON serialization of event data
|
||||
elemData[ eventKey ] = elemData = function(){};
|
||||
}
|
||||
|
||||
if ( !events ) {
|
||||
elemData.events = events = {};
|
||||
}
|
||||
|
||||
|
@ -175,17 +166,12 @@ jQuery.event = {
|
|||
|
||||
var ret, type, fn, j, i = 0, all, namespaces, namespace, special, eventType, handleObj, origType,
|
||||
elemData = jQuery.hasData( elem ) && jQuery._data( elem ),
|
||||
events = elemData && elemData[ eventKey ];
|
||||
events = elemData && elemData.events;
|
||||
|
||||
if ( !elemData || !events ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( typeof events === "function" ) {
|
||||
elemData = events;
|
||||
events = events.events;
|
||||
}
|
||||
|
||||
// types is actually an event object here
|
||||
if ( types && types.type ) {
|
||||
handler = types.handler;
|
||||
|
@ -285,10 +271,7 @@ jQuery.event = {
|
|||
delete elemData.events;
|
||||
delete elemData.handle;
|
||||
|
||||
if ( typeof elemData === "function" ) {
|
||||
jQuery.removeData( elem, eventKey, true );
|
||||
|
||||
} else if ( jQuery.isEmptyObject( elemData ) ) {
|
||||
if ( jQuery.isEmptyObject( elemData ) ) {
|
||||
jQuery.removeData( elem, undefined, true );
|
||||
}
|
||||
}
|
||||
|
@ -329,7 +312,7 @@ jQuery.event = {
|
|||
// points to jQuery.expando
|
||||
var internalKey = jQuery.expando,
|
||||
internalCache = this[ internalKey ];
|
||||
if ( internalCache && internalCache.events && internalCache.events[type] ) {
|
||||
if ( internalCache && internalCache.events && internalCache.events[ type ] ) {
|
||||
jQuery.event.trigger( event, data, internalCache.handle.elem );
|
||||
}
|
||||
});
|
||||
|
@ -355,9 +338,7 @@ jQuery.event = {
|
|||
event.currentTarget = elem;
|
||||
|
||||
// Trigger the event, it is assumed that "handle" is a function
|
||||
var handle = elem.nodeType ?
|
||||
jQuery._data( elem, "handle" ) :
|
||||
(jQuery._data( elem, eventKey ) || {}).handle;
|
||||
var handle = jQuery._data( elem, "handle" );
|
||||
|
||||
if ( handle ) {
|
||||
handle.apply( elem, data );
|
||||
|
@ -435,11 +416,7 @@ jQuery.event = {
|
|||
|
||||
event.namespace = event.namespace || namespace_sort.join(".");
|
||||
|
||||
events = jQuery._data(this, eventKey);
|
||||
|
||||
if ( typeof events === "function" ) {
|
||||
events = events.events;
|
||||
}
|
||||
events = jQuery._data(this, "events");
|
||||
|
||||
handlers = (events || {})[ event.type ];
|
||||
|
||||
|
@ -606,7 +583,7 @@ jQuery.Event = function( src ) {
|
|||
|
||||
// Events bubbling up the document may have been marked as prevented
|
||||
// by a handler lower down the tree; reflect the correct value.
|
||||
this.isDefaultPrevented = (src.defaultPrevented || src.returnValue === false ||
|
||||
this.isDefaultPrevented = (src.defaultPrevented || src.returnValue === false ||
|
||||
src.getPreventDefault && src.getPreventDefault()) ? returnTrue : returnFalse;
|
||||
|
||||
// Event type
|
||||
|
@ -681,6 +658,12 @@ var withinElement = function( event ) {
|
|||
// Firefox sometimes assigns relatedTarget a XUL element
|
||||
// which we cannot access the parentNode property of
|
||||
try {
|
||||
|
||||
// Chrome does something similar, the parentNode property
|
||||
// can be accessed but is null.
|
||||
if ( parent !== document && !parent.parentNode ) {
|
||||
return;
|
||||
}
|
||||
// Traverse up the tree
|
||||
while ( parent && parent !== this ) {
|
||||
parent = parent.parentNode;
|
||||
|
@ -731,8 +714,7 @@ if ( !jQuery.support.submitBubbles ) {
|
|||
type = elem.type;
|
||||
|
||||
if ( (type === "submit" || type === "image") && jQuery( elem ).closest("form").length ) {
|
||||
e.liveFired = undefined;
|
||||
return trigger( "submit", this, arguments );
|
||||
trigger( "submit", this, arguments );
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -741,8 +723,7 @@ if ( !jQuery.support.submitBubbles ) {
|
|||
type = elem.type;
|
||||
|
||||
if ( (type === "text" || type === "password") && jQuery( elem ).closest("form").length && e.keyCode === 13 ) {
|
||||
e.liveFired = undefined;
|
||||
return trigger( "submit", this, arguments );
|
||||
trigger( "submit", this, arguments );
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -805,7 +786,7 @@ if ( !jQuery.support.changeBubbles ) {
|
|||
if ( data != null || val ) {
|
||||
e.type = "change";
|
||||
e.liveFired = undefined;
|
||||
return jQuery.event.trigger( e, arguments[1], elem );
|
||||
jQuery.event.trigger( e, arguments[1], elem );
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -819,7 +800,7 @@ if ( !jQuery.support.changeBubbles ) {
|
|||
var elem = e.target, type = elem.type;
|
||||
|
||||
if ( type === "radio" || type === "checkbox" || elem.nodeName.toLowerCase() === "select" ) {
|
||||
return testChange.call( this, e );
|
||||
testChange.call( this, e );
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -831,7 +812,7 @@ if ( !jQuery.support.changeBubbles ) {
|
|||
if ( (e.keyCode === 13 && elem.nodeName.toLowerCase() !== "textarea") ||
|
||||
(e.keyCode === 32 && (type === "checkbox" || type === "radio")) ||
|
||||
type === "select-multiple" ) {
|
||||
return testChange.call( this, e );
|
||||
testChange.call( this, e );
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -870,8 +851,18 @@ if ( !jQuery.support.changeBubbles ) {
|
|||
}
|
||||
|
||||
function trigger( type, elem, args ) {
|
||||
args[0].type = type;
|
||||
return jQuery.event.handle.apply( elem, args );
|
||||
// Piggyback on a donor event to simulate a different one.
|
||||
// Fake originalEvent to avoid donor's stopPropagation, but if the
|
||||
// simulated event prevents default then we do the same on the donor.
|
||||
// Don't pass args or remember liveFired; they apply to the donor event.
|
||||
var event = jQuery.extend( {}, args[ 0 ] );
|
||||
event.type = type;
|
||||
event.originalEvent = {};
|
||||
event.liveFired = undefined;
|
||||
jQuery.event.handle.call( elem, event );
|
||||
if ( event.isDefaultPrevented() ) {
|
||||
args[ 0 ].preventDefault();
|
||||
}
|
||||
}
|
||||
|
||||
// Create "bubbling" focus and blur events
|
||||
|
@ -880,8 +871,8 @@ if ( document.addEventListener ) {
|
|||
jQuery.event.special[ fix ] = {
|
||||
setup: function() {
|
||||
this.addEventListener( orig, handler, true );
|
||||
},
|
||||
teardown: function() {
|
||||
},
|
||||
teardown: function() {
|
||||
this.removeEventListener( orig, handler, true );
|
||||
}
|
||||
};
|
||||
|
@ -1074,11 +1065,7 @@ function liveHandler( event ) {
|
|||
var stop, maxLevel, related, match, handleObj, elem, j, i, l, data, close, namespace, ret,
|
||||
elems = [],
|
||||
selectors = [],
|
||||
events = jQuery._data( this, eventKey );
|
||||
|
||||
if ( typeof events === "function" ) {
|
||||
events = events.events;
|
||||
}
|
||||
events = jQuery._data( this, "events" );
|
||||
|
||||
// Make sure we avoid non-left-click bubbling in Firefox (#3861) and disabled elements in IE (#6911)
|
||||
if ( event.liveFired === this || !events || !events.live || event.target.disabled || event.button && event.type === "click" ) {
|
||||
|
@ -1112,7 +1099,7 @@ function liveHandler( event ) {
|
|||
for ( j = 0; j < live.length; j++ ) {
|
||||
handleObj = live[j];
|
||||
|
||||
if ( close.selector === handleObj.selector && (!namespace || namespace.test( handleObj.namespace )) ) {
|
||||
if ( close.selector === handleObj.selector && (!namespace || namespace.test( handleObj.namespace )) && !close.elem.disabled ) {
|
||||
elem = close.elem;
|
||||
related = null;
|
||||
|
||||
|
|
|
@ -2,13 +2,13 @@
|
|||
* jQuery JavaScript Library v@VERSION
|
||||
* http://jquery.com/
|
||||
*
|
||||
* Copyright 2010, John Resig
|
||||
* Copyright 2011, John Resig
|
||||
* Dual licensed under the MIT or GPL Version 2 licenses.
|
||||
* http://jquery.org/license
|
||||
*
|
||||
* Includes Sizzle.js
|
||||
* http://sizzlejs.com/
|
||||
* Copyright 2010, The Dojo Foundation
|
||||
* Copyright 2011, The Dojo Foundation
|
||||
* Released under the MIT, BSD, and GPL Licenses.
|
||||
*
|
||||
* Date: @DATE
|
||||
|
|
|
@ -7,7 +7,7 @@ var rinlinejQuery = / jQuery\d+="(?:\d+|null)"/g,
|
|||
rtbody = /<tbody/i,
|
||||
rhtml = /<|&#?\w+;/,
|
||||
rnocache = /<(?:script|object|embed|option|style)/i,
|
||||
// checked="checked" or checked (html5)
|
||||
// checked="checked" or checked
|
||||
rchecked = /checked\s*(?:[^=]|=\s*.checked.)/i,
|
||||
wrapMap = {
|
||||
option: [ 1, "<select multiple='multiple'>", "</select>" ],
|
||||
|
@ -159,7 +159,7 @@ jQuery.fn.extend({
|
|||
}
|
||||
|
||||
if ( elem.parentNode ) {
|
||||
elem.parentNode.removeChild( elem );
|
||||
elem.parentNode.removeChild( elem );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -184,9 +184,9 @@ jQuery.fn.extend({
|
|||
},
|
||||
|
||||
clone: function( dataAndEvents, deepDataAndEvents ) {
|
||||
dataAndEvents = dataAndEvents == null ? true : dataAndEvents;
|
||||
dataAndEvents = dataAndEvents == null ? false : dataAndEvents;
|
||||
deepDataAndEvents = deepDataAndEvents == null ? dataAndEvents : deepDataAndEvents;
|
||||
|
||||
|
||||
return this.map( function () {
|
||||
return jQuery.clone( this, dataAndEvents, deepDataAndEvents );
|
||||
});
|
||||
|
@ -311,12 +311,19 @@ jQuery.fn.extend({
|
|||
if ( first ) {
|
||||
table = table && jQuery.nodeName( first, "tr" );
|
||||
|
||||
for ( var i = 0, l = this.length; i < l; i++ ) {
|
||||
for ( var i = 0, l = this.length, lastIndex = l - 1; i < l; i++ ) {
|
||||
callback.call(
|
||||
table ?
|
||||
root(this[i], first) :
|
||||
this[i],
|
||||
i > 0 || results.cacheable || (this.length > 1 && i > 0) ?
|
||||
// Make sure that we do not leak memory by inadvertently discarding
|
||||
// the original fragment (which might have attached data) instead of
|
||||
// using it; in addition, use the original fragment object for the last
|
||||
// item instead of first because it can end up being emptied incorrectly
|
||||
// in certain situations (Bug #8070).
|
||||
// Fragments from the fragment cache must always be cloned and never used
|
||||
// in place.
|
||||
results.cacheable || (l > 1 && i < lastIndex) ?
|
||||
jQuery.clone( fragment, true, true ) :
|
||||
fragment
|
||||
);
|
||||
|
@ -346,8 +353,8 @@ function cloneCopyEvent( src, dest ) {
|
|||
}
|
||||
|
||||
var internalKey = jQuery.expando,
|
||||
oldData = jQuery.data( src ),
|
||||
curData = jQuery.data( dest, oldData );
|
||||
oldData = jQuery.data( src ),
|
||||
curData = jQuery.data( dest, oldData );
|
||||
|
||||
// Switch to use the internal data object, if it exists, for the next
|
||||
// stage of data copying
|
||||
|
@ -361,7 +368,7 @@ function cloneCopyEvent( src, dest ) {
|
|||
|
||||
for ( var type in events ) {
|
||||
for ( var i = 0, l = events[ type ].length; i < l; i++ ) {
|
||||
jQuery.event.add( dest, type, events[ type ][ i ], events[ type ][ i ].data );
|
||||
jQuery.event.add( dest, type + ( events[ type ][ i ].namespace ? "." : "" ) + events[ type ][ i ].namespace, events[ type ][ i ], events[ type ][ i ].data );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -482,24 +489,39 @@ jQuery.each({
|
|||
};
|
||||
});
|
||||
|
||||
function getAll( elem ) {
|
||||
if ( "getElementsByTagName" in elem ) {
|
||||
return elem.getElementsByTagName( "*" );
|
||||
|
||||
} else if ( "querySelectorAll" in elem ) {
|
||||
return elem.querySelectorAll( "*" );
|
||||
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
jQuery.extend({
|
||||
clone: function( elem, dataAndEvents, deepDataAndEvents ) {
|
||||
var clone = elem.cloneNode(true),
|
||||
srcElements,
|
||||
destElements,
|
||||
var clone = elem.cloneNode(true),
|
||||
srcElements,
|
||||
destElements,
|
||||
i;
|
||||
|
||||
if ( !jQuery.support.noCloneEvent && (elem.nodeType === 1 || elem.nodeType === 11) && !jQuery.isXMLDoc(elem) ) {
|
||||
if ( (!jQuery.support.noCloneEvent || !jQuery.support.noCloneChecked) &&
|
||||
(elem.nodeType === 1 || elem.nodeType === 11) && !jQuery.isXMLDoc(elem) ) {
|
||||
// IE copies events bound via attachEvent when using cloneNode.
|
||||
// Calling detachEvent on the clone will also remove the events
|
||||
// from the original. In order to get around this, we use some
|
||||
// proprietary methods to clear the events. Thanks to MooTools
|
||||
// guys for this hotness.
|
||||
|
||||
cloneFixAttributes( elem, clone );
|
||||
|
||||
// Using Sizzle here is crazy slow, so we use getElementsByTagName
|
||||
// instead
|
||||
srcElements = elem.getElementsByTagName("*");
|
||||
destElements = clone.getElementsByTagName("*");
|
||||
srcElements = getAll( elem );
|
||||
destElements = getAll( clone );
|
||||
|
||||
// Weird iteration because IE will replace the length property
|
||||
// with an element if you are cloning the body and one of the
|
||||
|
@ -507,30 +529,25 @@ jQuery.extend({
|
|||
for ( i = 0; srcElements[i]; ++i ) {
|
||||
cloneFixAttributes( srcElements[i], destElements[i] );
|
||||
}
|
||||
|
||||
cloneFixAttributes( elem, clone );
|
||||
}
|
||||
|
||||
// Copy the events from the original to the clone
|
||||
if ( dataAndEvents ) {
|
||||
|
||||
cloneCopyEvent( elem, clone );
|
||||
|
||||
if ( deepDataAndEvents && "getElementsByTagName" in elem ) {
|
||||
if ( deepDataAndEvents ) {
|
||||
srcElements = getAll( elem );
|
||||
destElements = getAll( clone );
|
||||
|
||||
srcElements = elem.getElementsByTagName("*");
|
||||
destElements = clone.getElementsByTagName("*");
|
||||
|
||||
if ( srcElements.length ) {
|
||||
for ( i = 0; srcElements[i]; ++i ) {
|
||||
cloneCopyEvent( srcElements[i], destElements[i] );
|
||||
}
|
||||
for ( i = 0; srcElements[i]; ++i ) {
|
||||
cloneCopyEvent( srcElements[i], destElements[i] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Return the cloned set
|
||||
return clone;
|
||||
},
|
||||
},
|
||||
clean: function( elems, context, fragment, scripts ) {
|
||||
context = context || document;
|
||||
|
||||
|
|
|
@ -275,7 +275,7 @@ jQuery.each( ["Left", "Top"], function( i, name ) {
|
|||
if ( win ) {
|
||||
win.scrollTo(
|
||||
!i ? val : jQuery(win).scrollLeft(),
|
||||
i ? val : jQuery(win).scrollTop()
|
||||
i ? val : jQuery(win).scrollTop()
|
||||
);
|
||||
|
||||
} else {
|
||||
|
|
|
@ -1 +1,2 @@
|
|||
window.jQuery = window.$ = jQuery;
|
||||
})(window);
|
||||
|
|
|
@ -12,7 +12,8 @@
|
|||
var all = div.getElementsByTagName("*"),
|
||||
a = div.getElementsByTagName("a")[0],
|
||||
select = document.createElement("select"),
|
||||
opt = select.appendChild( document.createElement("option") );
|
||||
opt = select.appendChild( document.createElement("option") ),
|
||||
input = div.getElementsByTagName("input")[0];
|
||||
|
||||
// Can't get basic test support
|
||||
if ( !all || !all.length || !a ) {
|
||||
|
@ -51,7 +52,7 @@
|
|||
// Make sure that if no value is specified for a checkbox
|
||||
// that it defaults to "on".
|
||||
// (WebKit defaults to "" instead)
|
||||
checkOn: div.getElementsByTagName("input")[0].value === "on",
|
||||
checkOn: input.value === "on",
|
||||
|
||||
// Make sure that a selected-by-default option has a working selected property.
|
||||
// (WebKit defaults to false instead of true, IE too, if it's in an optgroup)
|
||||
|
@ -61,26 +62,29 @@
|
|||
deleteExpando: true,
|
||||
optDisabled: false,
|
||||
checkClone: false,
|
||||
_scriptEval: null,
|
||||
noCloneEvent: true,
|
||||
noCloneChecked: true,
|
||||
boxModel: null,
|
||||
inlineBlockNeedsLayout: false,
|
||||
shrinkWrapBlocks: false,
|
||||
reliableHiddenOffsets: true
|
||||
};
|
||||
|
||||
input.checked = true;
|
||||
jQuery.support.noCloneChecked = input.cloneNode( true ).checked;
|
||||
|
||||
// Make sure that the options inside disabled selects aren't marked as disabled
|
||||
// (WebKit marks them as diabled)
|
||||
select.disabled = true;
|
||||
jQuery.support.optDisabled = !opt.disabled;
|
||||
|
||||
var _scriptEval = null;
|
||||
jQuery.support.scriptEval = function() {
|
||||
if ( jQuery.support._scriptEval === null ) {
|
||||
if ( _scriptEval === null ) {
|
||||
var root = document.documentElement,
|
||||
script = document.createElement("script"),
|
||||
id = "script" + jQuery.now();
|
||||
|
||||
script.type = "text/javascript";
|
||||
try {
|
||||
script.appendChild( document.createTextNode( "window." + id + "=1;" ) );
|
||||
} catch(e) {}
|
||||
|
@ -91,10 +95,10 @@
|
|||
// tag with appendChild/createTextNode
|
||||
// (IE doesn't support this, fails, and uses .text instead)
|
||||
if ( window[ id ] ) {
|
||||
jQuery.support._scriptEval = true;
|
||||
_scriptEval = true;
|
||||
delete window[ id ];
|
||||
} else {
|
||||
jQuery.support._scriptEval = false;
|
||||
_scriptEval = false;
|
||||
}
|
||||
|
||||
root.removeChild( script );
|
||||
|
@ -102,7 +106,7 @@
|
|||
root = script = id = null;
|
||||
}
|
||||
|
||||
return jQuery.support._scriptEval;
|
||||
return _scriptEval;
|
||||
};
|
||||
|
||||
// Test to see if it's possible to delete an expando from an element
|
||||
|
@ -114,7 +118,7 @@
|
|||
jQuery.support.deleteExpando = false;
|
||||
}
|
||||
|
||||
if ( div.attachEvent && div.fireEvent ) {
|
||||
if ( !div.addEventListener && div.attachEvent && div.fireEvent ) {
|
||||
div.attachEvent("onclick", function click() {
|
||||
// Cloning a node shouldn't copy over any
|
||||
// bound event handlers (IE does this)
|
||||
|
|
|
@ -205,11 +205,11 @@ jQuery.each({
|
|||
}, function( name, fn ) {
|
||||
jQuery.fn[ name ] = function( until, selector ) {
|
||||
var ret = jQuery.map( this, fn, until ),
|
||||
// The variable 'args' was introduced in
|
||||
// https://github.com/jquery/jquery/commit/52a0238
|
||||
// to work around a bug in Chrome 10 (Dev) and should be removed when the bug is fixed.
|
||||
// http://code.google.com/p/v8/issues/detail?id=1050
|
||||
args = slice.call(arguments);
|
||||
// The variable 'args' was introduced in
|
||||
// https://github.com/jquery/jquery/commit/52a0238
|
||||
// to work around a bug in Chrome 10 (Dev) and should be removed when the bug is fixed.
|
||||
// http://code.google.com/p/v8/issues/detail?id=1050
|
||||
args = slice.call(arguments);
|
||||
|
||||
if ( !runtil.test( name ) ) {
|
||||
selector = until;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue