-* crlf=input
+* eol=lf
+*.jar binary
${SRC_DIR}/manipulation.js\
${SRC_DIR}/css.js\
${SRC_DIR}/ajax.js\
+ ${SRC_DIR}/xhr.js\
+ ${SRC_DIR}/transports/jsonp.js\
+ ${SRC_DIR}/transports/script.js\
+ ${SRC_DIR}/transports/xhr.js\
${SRC_DIR}/effects.js\
${SRC_DIR}/offset.js\
${SRC_DIR}/dimensions.js
# setting DIST_DIR before calling rake
dist_dir = ENV['DIST_DIR'] || File.join( prefix, 'dist' )
-base_files = %w{intro core support data queue attributes event selector traversing manipulation css ajax effects offset dimensions outro}.map { |js| File.join( src_dir, "#{js}.js" ) }
+base_files = %w{intro core support data queue attributes event selector traversing manipulation css ajax xhr transports/jsonp transports/script transports/xhr effects offset dimensions outro}.map { |js| File.join( src_dir, "#{js}.js" ) }
# Sizzle, QUnit and jQuery files/dirs
sizzle_dir = File.join( src_dir, "sizzle" )
<fileset file="src/manipulation.js" />
<fileset file="src/css.js" />
<fileset file="src/ajax.js" />
+ <fileset file="src/xhr.js" />
+ <fileset file="src/transports/jsonp.js" />
+ <fileset file="src/transports/script.js" />
+ <fileset file="src/transports/xhr.js" />
<fileset file="src/effects.js" />
<fileset file="src/offset.js" />
<fileset file="src/dimensions.js" />
<exec executable="git" outputproperty="date">
<arg line="log -1 --pretty=format:%ad" />
</exec>
+ <replaceregexp match="(\(\s*function\s*\(\s*jQuery\s*\)\s*\{)|(\}\s*\)\s*\(\s*jQuery\s*\)\s*;)" flags="g" replace="" file="${JQ}" />
<replaceregexp match="Date: " replace="Date: ${date}" file="${JQ}" />
<echo message="${JQ} built." />
</target>
(function( jQuery ) {
-
-var jsc = jQuery.now(),
- rscript = /<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,
+
+var rscript = /<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,
rselectTextarea = /^(?:select|textarea)/i,
rinput = /^(?:color|date|datetime|email|hidden|month|number|password|range|search|tel|text|time|url|week)$/i,
- rnoContent = /^(?:GET|HEAD)$/,
rbracket = /\[\]$/,
- jsre = /\=\?(&|$)/,
rquery = /\?/,
- rts = /([?&])_=[^&]*/,
- rurl = /^(\w+:)?\/\/([^\/?#]+)/,
r20 = /%20/g,
- rhash = /#.*$/,
// Keep a copy of the old load method
_load = jQuery.fn.load;
type = "POST";
}
}
-
+
var self = this;
-
+
// Request the remote document
jQuery.ajax({
url: url,
},
serializeArray: function() {
- return this.map(function() {
+ return this.map(function(){
return this.elements ? jQuery.makeArray(this.elements) : this;
})
- .filter(function() {
+ .filter(function(){
return this.name && !this.disabled &&
(this.checked || rselectTextarea.test(this.nodeName) ||
rinput.test(this.type));
})
- .map(function( i, elem ) {
+ .map(function(i, elem){
var val = jQuery(this).val();
return val == null ?
null :
jQuery.isArray(val) ?
- jQuery.map( val, function( val, i ) {
- return { name: elem.name, value: val };
+ jQuery.map( val, function(val, i){
+ return {name: elem.name, value: val};
}) :
- { name: elem.name, value: val };
+ {name: elem.name, value: val};
}).get();
}
});
// Attach a bunch of functions for handling common AJAX events
-jQuery.each( "ajaxStart ajaxStop ajaxComplete ajaxError ajaxSuccess ajaxSend".split(" "), function( i, o ) {
- jQuery.fn[o] = function( f ) {
+jQuery.each( "ajaxStart ajaxStop ajaxComplete ajaxError ajaxSuccess ajaxSend".split(" "), function(i,o){
+ jQuery.fn[o] = function(f){
return this.bind(o, f);
};
});
jQuery.extend({
+
get: function( url, data, callback, type ) {
// shift arguments if data argument was omited
if ( jQuery.isFunction( data ) ) {
/*
timeout: 0,
data: null,
+ dataType: null,
+ dataTypes: null,
username: null,
password: null,
+ cache: null,
traditional: false,
*/
- // This function can be overriden by calling jQuery.ajaxSetup
xhr: function() {
return new window.XMLHttpRequest();
},
+ xhrResponseFields: {
+ xml: "XML",
+ text: "Text",
+ json: "JSON"
+ },
+
accepts: {
xml: "application/xml, text/xml",
html: "text/html",
- script: "text/javascript, application/javascript",
- json: "application/json, text/javascript",
text: "text/plain",
- _default: "*/*"
- }
- },
-
- ajax: function( origSettings ) {
- var s = jQuery.extend(true, {}, jQuery.ajaxSettings, origSettings),
- jsonp, status, data, type = s.type.toUpperCase(), noContent = rnoContent.test(type);
-
- s.url = s.url.replace( rhash, "" );
-
- // Use original (not extended) context object if it was provided
- s.context = origSettings && origSettings.context != null ? origSettings.context : s;
-
- // convert data if not already a string
- if ( s.data && s.processData && typeof s.data !== "string" ) {
- s.data = jQuery.param( s.data, s.traditional );
- }
-
- // Handle JSONP Parameter Callbacks
- if ( s.dataType === "jsonp" ) {
- if ( type === "GET" ) {
- if ( !jsre.test( s.url ) ) {
- s.url += (rquery.test( s.url ) ? "&" : "?") + (s.jsonp || "callback") + "=?";
- }
- } else if ( !s.data || !jsre.test(s.data) ) {
- s.data = (s.data ? s.data + "&" : "") + (s.jsonp || "callback") + "=?";
- }
- s.dataType = "json";
- }
-
- // Build temporary JSONP function
- if ( s.dataType === "json" && (s.data && jsre.test(s.data) || jsre.test(s.url)) ) {
- jsonp = s.jsonpCallback || ("jsonp" + jsc++);
-
- // Replace the =? sequence both in the query string and the data
- if ( s.data ) {
- s.data = (s.data + "").replace(jsre, "=" + jsonp + "$1");
- }
-
- s.url = s.url.replace(jsre, "=" + jsonp + "$1");
-
- // We need to make sure
- // that a JSONP style response is executed properly
- s.dataType = "script";
-
- // Handle JSONP-style loading
- var customJsonp = window[ jsonp ];
-
- window[ jsonp ] = function( tmp ) {
- if ( jQuery.isFunction( customJsonp ) ) {
- customJsonp( tmp );
-
- } else {
- // Garbage collect
- window[ jsonp ] = undefined;
-
- try {
- delete window[ jsonp ];
- } catch( jsonpError ) {}
- }
-
- data = tmp;
- jQuery.handleSuccess( s, xhr, status, data );
- jQuery.handleComplete( s, xhr, status, data );
-
- if ( head ) {
- head.removeChild( script );
+ json: "application/json, text/javascript",
+ "*": "*/*"
+ },
+
+ autoDataType: {
+ xml: /xml/,
+ html: /html/,
+ json: /json/
+ },
+
+ // Prefilters
+ // 1) They are useful to introduce custom dataTypes (see transport/jsonp for an example)
+ // 2) These are called:
+ // * BEFORE asking for a transport
+ // * AFTER param serialization (s.data is a string if s.processData is true)
+ // 3) They MUST be order agnostic
+ prefilters: [],
+
+ // Transports bindings
+ // 1) key is the dataType
+ // 2) the catchall symbol "*" can be used
+ // 3) selection will start with transport dataType and THEN go to "*" if needed
+ transports: {
+ },
+
+ // Checkers
+ // 1) key is dataType
+ // 2) they are called to control successful response
+ // 3) error throws is used as error data
+ dataCheckers: {
+
+ // Check if data is a string
+ "text": function(data) {
+ if ( typeof data != "string" ) {
+ jQuery.error("typeerror");
}
- };
- }
-
- if ( s.dataType === "script" && s.cache === null ) {
- s.cache = false;
- }
-
- if ( s.cache === false && noContent ) {
- var ts = jQuery.now();
-
- // try replacing _= if it is there
- var ret = s.url.replace(rts, "$1_=" + ts);
-
- // if nothing was replaced, add timestamp to the end
- s.url = ret + ((ret === s.url) ? (rquery.test(s.url) ? "&" : "?") + "_=" + ts : "");
- }
-
- // If data is available, append data to url for GET/HEAD requests
- if ( s.data && noContent ) {
- s.url += (rquery.test(s.url) ? "&" : "?") + s.data;
- }
-
- // Watch for a new set of requests
- if ( s.global && jQuery.active++ === 0 ) {
- jQuery.event.trigger( "ajaxStart" );
- }
-
- // Matches an absolute URL, and saves the domain
- var parts = rurl.exec( s.url ),
- remote = parts && (parts[1] && parts[1].toLowerCase() !== location.protocol || parts[2].toLowerCase() !== location.host);
-
- // If we're requesting a remote document
- // and trying to load JSON or Script with a GET
- if ( s.dataType === "script" && type === "GET" && remote ) {
- var head = document.getElementsByTagName("head")[0] || document.documentElement;
- var script = document.createElement("script");
- if ( s.scriptCharset ) {
- script.charset = s.scriptCharset;
- }
- script.src = s.url;
-
- // Handle Script loading
- if ( !jsonp ) {
- var done = false;
-
- // Attach handlers for all browsers
- script.onload = script.onreadystatechange = function() {
- if ( !done && (!this.readyState ||
- this.readyState === "loaded" || this.readyState === "complete") ) {
- done = true;
- jQuery.handleSuccess( s, xhr, status, data );
- jQuery.handleComplete( s, xhr, status, data );
-
- // Handle memory leak in IE
- script.onload = script.onreadystatechange = null;
- if ( head && script.parentNode ) {
- head.removeChild( script );
- }
- }
- };
- }
-
- // Use insertBefore instead of appendChild to circumvent an IE6 bug.
- // This arises when a base node is used (#2709 and #4378).
- head.insertBefore( script, head.firstChild );
-
- // We handle everything using the script element injection
- return undefined;
- }
-
- var requestDone = false;
-
- // Create the request object
- var xhr = s.xhr();
-
- if ( !xhr ) {
- return;
- }
-
- // Open the socket
- // Passing null username, generates a login popup on Opera (#2865)
- if ( s.username ) {
- xhr.open(type, s.url, s.async, s.username, s.password);
- } else {
- xhr.open(type, s.url, s.async);
- }
-
- // Need an extra try/catch for cross domain requests in Firefox 3
- try {
- // Set content-type if data specified and content-body is valid for this type
- if ( (s.data != null && !noContent) || (origSettings && origSettings.contentType) ) {
- xhr.setRequestHeader("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] ) {
- xhr.setRequestHeader("If-Modified-Since", jQuery.lastModified[s.url]);
+ },
+
+ // Check if xml has been properly parsed
+ "xml": function(data) {
+ var documentElement = data ? data.documentElement : data;
+ if ( ! documentElement || ! documentElement.nodeName ) {
+ jQuery.error("typeerror");
}
-
- if ( jQuery.etag[s.url] ) {
- xhr.setRequestHeader("If-None-Match", jQuery.etag[s.url]);
+ if ( documentElement.nodeName == "parsererror" ) {
+ jQuery.error("parsererror");
}
}
-
- // Set header so the called script knows that it's an XMLHttpRequest
- // Only send the header if it's not a remote XHR
- if ( !remote ) {
- xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
- }
-
- // Set the Accepts header for the server, depending on the dataType
- xhr.setRequestHeader("Accept", s.dataType && s.accepts[ s.dataType ] ?
- s.accepts[ s.dataType ] + ", */*; q=0.01" :
- s.accepts._default );
- } catch( headerError ) {}
-
- // Allow custom headers/mimetypes and early abort
- if ( s.beforeSend && s.beforeSend.call(s.context, xhr, s) === false ) {
- // Handle the global AJAX counter
- if ( s.global && jQuery.active-- === 1 ) {
- jQuery.event.trigger( "ajaxStop" );
- }
-
- // close opended socket
- xhr.abort();
- return false;
- }
-
- if ( s.global ) {
- jQuery.triggerGlobal( s, "ajaxSend", [xhr, s] );
- }
-
- // Wait for a response to come back
- var onreadystatechange = xhr.onreadystatechange = function( isTimeout ) {
- // The request was aborted
- if ( !xhr || xhr.readyState === 0 || isTimeout === "abort" ) {
- // Opera doesn't call onreadystatechange before this point
- // so we simulate the call
- if ( !requestDone ) {
- jQuery.handleComplete( s, xhr, status, data );
- }
-
- requestDone = true;
- if ( xhr ) {
- xhr.onreadystatechange = jQuery.noop;
- }
-
- // The transfer is complete and the data is available, or the request timed out
- } else if ( !requestDone && xhr && (xhr.readyState === 4 || isTimeout === "timeout") ) {
- requestDone = true;
- xhr.onreadystatechange = jQuery.noop;
-
- status = isTimeout === "timeout" ?
- "timeout" :
- !jQuery.httpSuccess( xhr ) ?
- "error" :
- s.ifModified && jQuery.httpNotModified( xhr, s.url ) ?
- "notmodified" :
- "success";
-
- var errMsg;
-
- if ( status === "success" ) {
- // Watch for, and catch, XML document parse errors
- try {
- // process the data (runs the xml through httpData regardless of callback)
- data = jQuery.httpData( xhr, s.dataType, s );
- } catch( parserError ) {
- status = "parsererror";
- errMsg = parserError;
- }
- }
-
- // Make sure that the request was successful or notmodified
- if ( status === "success" || status === "notmodified" ) {
- // JSONP handles its own success callback
- if ( !jsonp ) {
- jQuery.handleSuccess( s, xhr, status, data );
- }
- } else {
- jQuery.handleError( s, xhr, status, errMsg );
- }
-
- // Fire the complete handlers
- if ( !jsonp ) {
- jQuery.handleComplete( s, xhr, status, data );
- }
-
- if ( isTimeout === "timeout" ) {
- xhr.abort();
- }
-
- // Stop memory leaks
- if ( s.async ) {
- xhr = null;
+ },
+
+ // List of data converters
+ // 1) key format is "source_type => destination_type" (spaces required)
+ // 2) the catchall symbol "*" can be used for source_type
+ dataConverters: {
+
+ // Convert anything to text
+ "* => text": function(data) {
+ return "" + data;
+ },
+
+ // Text to html (no transformation)
+ "text => html": function(data) {
+ return data;
+ },
+
+ // Evaluate text as a json expression
+ "text => json": jQuery.parseJSON,
+
+ // Parse text as xml
+ "text => xml": function(data) {
+ var xml, parser;
+ if ( window.DOMParser ) { // Standard
+ parser = new DOMParser();
+ xml = parser.parseFromString(data,"text/xml");
+ } else { // IE
+ xml = new ActiveXObject("Microsoft.XMLDOM");
+ xml.async="false";
+ xml.loadXML(data);
}
+ return xml;
}
- };
-
- // Override the abort handler, if we can (IE 6 doesn't allow it, but that's OK)
- // Opera doesn't fire onreadystatechange at all on abort
- try {
- var oldAbort = xhr.abort;
- xhr.abort = function() {
- if ( xhr ) {
- // oldAbort has no call property in IE7 so
- // just do it this way, which works in all
- // browsers
- Function.prototype.call.call( oldAbort, xhr );
- }
-
- onreadystatechange( "abort" );
- };
- } catch( abortError ) {}
-
- // Timeout checker
- if ( s.async && s.timeout > 0 ) {
- setTimeout(function() {
- // Check to see if the request is still happening
- if ( xhr && !requestDone ) {
- onreadystatechange( "timeout" );
- }
- }, s.timeout);
- }
-
- // Send the data
- try {
- xhr.send( noContent || s.data == null ? null : s.data );
-
- } catch( sendError ) {
- jQuery.handleError( s, xhr, null, sendError );
-
- // Fire the complete handlers
- jQuery.handleComplete( s, xhr, status, data );
}
+ },
- // firefox 1.5 doesn't fire statechange for sync requests
- if ( !s.async ) {
- onreadystatechange();
+ // Main method
+ ajax: function( url , s ) {
+
+ if ( arguments.length === 1 ) {
+ s = url;
+ url = s ? s.url : undefined;
}
-
- // return XMLHttpRequest to allow aborting the request etc.
- return xhr;
+
+ return jQuery.xhr().open( s ? s.type : undefined , url ).send( undefined , s );
+
},
// Serialize an array of form elements or a set of
// Last-Modified header cache for next request
lastModified: {},
- etag: {},
-
- handleError: function( s, xhr, status, e ) {
- // If a local callback was specified, fire it
- if ( s.error ) {
- s.error.call( s.context, xhr, status, e );
- }
-
- // Fire the global callback
- if ( s.global ) {
- jQuery.triggerGlobal( s, "ajaxError", [xhr, s, e] );
- }
- },
-
- handleSuccess: function( s, xhr, status, data ) {
- // If a local callback was specified, fire it and pass it the data
- if ( s.success ) {
- s.success.call( s.context, data, status, xhr );
- }
-
- // Fire the global callback
- if ( s.global ) {
- jQuery.triggerGlobal( s, "ajaxSuccess", [xhr, s] );
- }
- },
-
- handleComplete: function( s, xhr, status ) {
- // Process result
- if ( s.complete ) {
- s.complete.call( s.context, xhr, status );
- }
-
- // The request was completed
- if ( s.global ) {
- jQuery.triggerGlobal( s, "ajaxComplete", [xhr, s] );
- }
-
- // Handle the global AJAX counter
- if ( s.global && jQuery.active-- === 1 ) {
- jQuery.event.trigger( "ajaxStop" );
- }
- },
-
- triggerGlobal: function( s, type, args ) {
- (s.context && s.context.url == null ? jQuery(s.context) : jQuery.event).trigger(type, args);
- },
-
- // Determines if an XMLHttpRequest was successful or not
- httpSuccess: function( xhr ) {
- try {
- // IE error sometimes returns 1223 when it should be 204 so treat it as success, see #1450
- return !xhr.status && location.protocol === "file:" ||
- xhr.status >= 200 && xhr.status < 300 ||
- xhr.status === 304 || xhr.status === 1223;
- } catch(e) {}
-
- return false;
- },
-
- // Determines if an XMLHttpRequest returns NotModified
- httpNotModified: function( xhr, url ) {
- var lastModified = xhr.getResponseHeader("Last-Modified"),
- etag = xhr.getResponseHeader("Etag");
-
- if ( lastModified ) {
- jQuery.lastModified[url] = lastModified;
- }
-
- if ( etag ) {
- jQuery.etag[url] = etag;
- }
-
- return xhr.status === 304;
- },
-
- httpData: function( xhr, type, s ) {
- var ct = xhr.getResponseHeader("content-type") || "",
- xml = type === "xml" || !type && ct.indexOf("xml") >= 0,
- data = xml ? xhr.responseXML : xhr.responseText;
-
- if ( xml && data.documentElement.nodeName === "parsererror" ) {
- jQuery.error( "parsererror" );
- }
-
- // Allow a pre-filtering function to sanitize the response
- // s is checked to keep backwards compatibility
- if ( s && s.dataFilter ) {
- data = s.dataFilter( data, type );
- }
-
- // The filter can actually parse the response
- if ( typeof data === "string" ) {
- // Get the JavaScript object, if JSON is used.
- if ( type === "json" || !type && ct.indexOf("json") >= 0 ) {
- data = jQuery.parseJSON( data );
-
- // If the type is "script", eval it in global context
- } else if ( type === "script" || !type && ct.indexOf("javascript") >= 0 ) {
- jQuery.globalEval( data );
- }
- }
-
- return data;
- }
+ etag: {}
});
*/
if ( window.ActiveXObject ) {
jQuery.ajaxSettings.xhr = function() {
- if ( window.location.protocol !== "file:" ) {
- try {
- return new window.XMLHttpRequest();
- } catch(xhrError) {}
- }
-
+ if ( window.location.protocol !== "file:" ) {
try {
- return new window.ActiveXObject("Microsoft.XMLHTTP");
- } catch(activeError) {}
+ return new window.XMLHttpRequest();
+ } catch( xhrError ) {}
+ }
+
+ try {
+ return new window.ActiveXObject("Microsoft.XMLHTTP");
+ } catch( activeError ) {}
};
}
+var testXHR = jQuery.ajaxSettings.xhr();
+
// Does this browser support XHR requests?
-jQuery.support.ajax = !!jQuery.ajaxSettings.xhr();
+jQuery.support.ajax = !!testXHR;
+
+// Does this browser support crossDomain XHR requests
+jQuery.support.cors = testXHR && "withCredentials" in testXHR;
})( jQuery );
(function( jQuery ) {
-var rclass = /[\n\t]/g,
+var rclass = /[\n\t\r]/g,
rspaces = /\s+/,
rreturn = /\r/g,
rspecialurl = /^(?:href|src|style)$/,
if ( rradiocheck.test( elem.type ) && !jQuery.support.checkOn ) {
return elem.getAttribute("value") === null ? "on" : elem.value;
}
-
// Everything else, we just grab the value
return (elem.value || "").replace(rreturn, "");
height: true,
offset: true
},
-
+
attr: function( elem, name, value, pass ) {
- // don't set attributes on text and comment nodes
- if ( !elem || elem.nodeType === 3 || elem.nodeType === 8 ) {
+ // don't get/set attributes on text, comment and attribute nodes
+ if ( !elem || elem.nodeType === 3 || elem.nodeType === 8 || elem.nodeType === 2 ) {
return undefined;
}
// Try to normalize/fix the name
name = notxml && jQuery.props[ name ] || name;
- // These attributes require special treatment
- var special = rspecialurl.test( name );
+ // Only do all the following if this is a node (faster for style)
+ if ( elem.nodeType === 1 ) {
+ // These attributes require special treatment
+ var special = rspecialurl.test( name );
+
+ // Safari mis-reports the default selected property of an option
+ // Accessing the parent's selectedIndex property fixes it
+ if ( name === "selected" && !jQuery.support.optSelected ) {
+ var parent = elem.parentNode;
+ if ( parent ) {
+ parent.selectedIndex;
+
+ // Make sure that it also works with optgroups, see #5701
+ if ( parent.parentNode ) {
+ parent.parentNode.selectedIndex;
+ }
+ }
+ }
- // Safari mis-reports the default selected property of an option
- // Accessing the parent's selectedIndex property fixes it
- if ( name === "selected" && !jQuery.support.optSelected ) {
- var parent = elem.parentNode;
- if ( parent ) {
- parent.selectedIndex;
+ // If applicable, access the attribute via the DOM 0 way
+ // 'in' checks fail in Blackberry 4.7 #6931
+ if ( (name in elem || elem[ name ] !== undefined) && notxml && !special ) {
+ if ( set ) {
+ // We can't allow the type property to be changed (since it causes problems in IE)
+ if ( name === "type" && rtype.test( elem.nodeName ) && elem.parentNode ) {
+ jQuery.error( "type property can't be changed" );
+ }
+
+ if ( value === null ) {
+ if ( elem.nodeType === 1 ) {
+ elem.removeAttribute( name );
+ }
- // Make sure that it also works with optgroups, see #5701
- if ( parent.parentNode ) {
- parent.parentNode.selectedIndex;
+ } else {
+ elem[ name ] = value;
+ }
}
- }
- }
- // If applicable, access the attribute via the DOM 0 way
- // 'in' checks fail in Blackberry 4.7 #6931
- if ( (name in elem || elem[ name ] !== undefined) && notxml && !special ) {
- if ( set ) {
- // We can't allow the type property to be changed (since it causes problems in IE)
- if ( name === "type" && rtype.test( elem.nodeName ) && elem.parentNode ) {
- jQuery.error( "type property can't be changed" );
+ // browsers index elements by id/name on forms, give priority to attributes.
+ if ( jQuery.nodeName( elem, "form" ) && elem.getAttributeNode(name) ) {
+ return elem.getAttributeNode( name ).nodeValue;
}
- if ( value === null ) {
- if ( elem.nodeType === 1 ) {
- elem.removeAttribute( name );
- }
+ // elem.tabIndex doesn't always return the correct value when it hasn't been explicitly set
+ // http://fluidproject.org/blog/2008/01/09/getting-setting-and-removing-tabindex-values-with-javascript/
+ if ( name === "tabIndex" ) {
+ var attributeNode = elem.getAttributeNode( "tabIndex" );
- } else {
- elem[ name ] = value;
+ return attributeNode && attributeNode.specified ?
+ attributeNode.value :
+ rfocusable.test( elem.nodeName ) || rclickable.test( elem.nodeName ) && elem.href ?
+ 0 :
+ undefined;
}
- }
- // browsers index elements by id/name on forms, give priority to attributes.
- if ( jQuery.nodeName( elem, "form" ) && elem.getAttributeNode(name) ) {
- return elem.getAttributeNode( name ).nodeValue;
+ return elem[ name ];
}
- // elem.tabIndex doesn't always return the correct value when it hasn't been explicitly set
- // http://fluidproject.org/blog/2008/01/09/getting-setting-and-removing-tabindex-values-with-javascript/
- if ( name === "tabIndex" ) {
- var attributeNode = elem.getAttributeNode( "tabIndex" );
+ if ( !jQuery.support.style && notxml && name === "style" ) {
+ if ( set ) {
+ elem.style.cssText = "" + value;
+ }
- return attributeNode && attributeNode.specified ?
- attributeNode.value :
- rfocusable.test( elem.nodeName ) || rclickable.test( elem.nodeName ) && elem.href ?
- 0 :
- undefined;
+ return elem.style.cssText;
}
- return elem[ name ];
- }
-
- if ( !jQuery.support.style && notxml && name === "style" ) {
if ( set ) {
- elem.style.cssText = "" + value;
+ // convert the value to a string (all browsers do this but IE) see #1070
+ elem.setAttribute( name, "" + value );
}
- return elem.style.cssText;
- }
+ // Ensure that missing attributes return undefined
+ // Blackberry 4.7 returns "" from getAttribute #6938
+ if ( !elem.attributes[ name ] && (elem.hasAttribute && !elem.hasAttribute( name )) ) {
+ return undefined;
+ }
- if ( set ) {
- // convert the value to a string (all browsers do this but IE) see #1070
- elem.setAttribute( name, "" + value );
- }
+ var attr = !jQuery.support.hrefNormalized && notxml && special ?
+ // Some attributes require a special call on IE
+ elem.getAttribute( name, 2 ) :
+ elem.getAttribute( name );
- // Ensure that missing attributes return undefined
- // Blackberry 4.7 returns "" from getAttribute #6938
- if ( !elem.attributes[ name ] && (elem.hasAttribute && !elem.hasAttribute( name )) ) {
- return undefined;
+ // Non-existent attributes return null, we normalize to undefined
+ return attr === null ? undefined : attr;
}
-
- var attr = !jQuery.support.hrefNormalized && notxml && special ?
- // Some attributes require a special call on IE
- elem.getAttribute( name, 2 ) :
- elem.getAttribute( name );
-
- // Non-existent attributes return null, we normalize to undefined
- return attr === null ? undefined : attr;
+ // Handle everything which isn't a DOM element node
+ if ( set ) {
+ elem[ name ] = value;
+ }
+ return elem[ name ];
}
});
this.toArray() :
// Return just the object
- ( num < 0 ? this.slice(num)[ 0 ] : this[ num ] );
+ ( num < 0 ? this[ this.length + num ] : this[ num ] );
},
// Take an array of elements and push it onto the stack
}
}
+ // Flatten any nested arrays
return ret.concat.apply( [], ret );
},
}
if ( val != null ) {
- return val === "" ? "auto" : val;
+ // Should return "auto" instead of 0, use 0 for
+ // temporary backwards-compat
+ return val === "" || val === "auto" ? "0px" : val;
}
}
if ( val < 0 || val == null ) {
val = elem.style[ name ];
- return val === "" ? "auto" : val;
+
+ // Should return "auto" instead of 0, use 0 for
+ // temporary backwards-compat
+ return val === "" || val === "auto" ? "0px" : val;
}
return typeof val === "string" ? val : val + "px";
if ( typeof key === "undefined" ) {
if ( this.length ) {
- var attr = this[0].attributes, name;
data = jQuery.data( this[0] );
- for ( var i = 0, l = attr.length; i < l; i++ ) {
- name = attr[i].name;
-
- if ( name.indexOf( "data-" ) === 0 ) {
- name = name.substr( 5 );
- dataAttr( this[0], name, data[ name ] );
+ if ( this[0].nodeType === 1 ) {
+ var attr = this[0].attributes, name;
+ for ( var i = 0, l = attr.length; i < l; i++ ) {
+ name = attr[i].name;
+
+ if ( name.indexOf( "data-" ) === 0 ) {
+ name = name.substr( 5 );
+ dataAttr( this[0], name, data[ name ] );
+ }
}
}
}
var elemdisplay = {},
rfxtypes = /^(?:toggle|show|hide)$/,
- rfxnum = /^([+\-]=)?([\d+.\-]+)(.*)$/,
+ rfxnum = /^([+\-]=)?([\d+.\-]+)([a-z%]*)$/i,
timerId,
fxAttrs = [
// height animations
jQuery.event.special.submit = {
setup: function( data, namespaces ) {
- if ( this.nodeName.toLowerCase() !== "form" ) {
+ if ( this.nodeName && this.nodeName.toLowerCase() !== "form" ) {
jQuery.event.add(this, "click.specialSubmit", function( e ) {
var elem = e.target,
type = elem.type;
events = events.events;
}
- // Make sure we avoid non-left-click bubbling in Firefox (#3861)
- if ( event.liveFired === this || !events || !events.live || event.button && event.type === "click" ) {
+ // 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" ) {
return;
}
rnocache = /<(?:script|object|embed|option|style)/i,
// checked="checked" or checked (html5)
rchecked = /checked\s*(?:[^=]|=\s*.checked.)/i,
- raction = /\=([^="'>\s]+\/)>/g,
wrapMap = {
option: [ 1, "<select multiple='multiple'>", "</select>" ],
legend: [ 1, "<fieldset>", "</fieldset>" ],
return set;
}
},
-
+
// keepData is for internal use only--do not document
remove: function( selector, keepData ) {
for ( var i = 0, elem; (elem = this[i]) != null; i++ ) {
}
}
}
-
+
return this;
},
elem.removeChild( elem.firstChild );
}
}
-
+
return this;
},
clone: function( events ) {
// Do the clone
var ret = this.map(function() {
- if ( !jQuery.support.noCloneEvent && !jQuery.isXMLDoc(this) ) {
- // IE copies events bound via attachEvent when
- // using cloneNode. Calling detachEvent on the
- // clone will also remove the events from the orignal
- // In order to get around this, we use innerHTML.
- // Unfortunately, this means some modifications to
- // attributes in IE that are actually only stored
- // as properties will not be copied (such as the
- // the name attribute on an input).
- var html = this.outerHTML,
- ownerDocument = this.ownerDocument;
-
- if ( !html ) {
- var div = ownerDocument.createElement("div");
- div.appendChild( this.cloneNode(true) );
- html = div.innerHTML;
+ var clone = this.cloneNode(true);
+ if ( !jQuery.support.noCloneEvent && (this.nodeType === 1 || this.nodeType === 11) && !jQuery.isXMLDoc(this) ) {
+ // 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.
+
+ // Using Sizzle here is crazy slow, so we use getElementsByTagName
+ // instead
+ var srcElements = this.getElementsByTagName("*"),
+ destElements = clone.getElementsByTagName("*");
+
+ // Weird iteration because IE will replace the length property
+ // with an element if you are cloning the body and one of the
+ // elements on the page has a name or id of "length"
+ for ( var i = 0; srcElements[i]; ++i ) {
+ cloneFixAttributes( srcElements[i], destElements[i] );
}
- return jQuery.clean([html.replace(rinlinejQuery, "")
- // Handle the case in IE 8 where action=/test/> self-closes a tag
- .replace(raction, '="$1">')
- .replace(rleadingWhitespace, "")], ownerDocument)[0];
- } else {
- return this.cloneNode(true);
+ cloneFixAttributes( this, clone );
}
+
+ return clone;
});
// Copy the events from the original to the clone
} else {
results = jQuery.buildFragment( args, this, scripts );
}
-
+
fragment = results.fragment;
-
+
if ( fragment.childNodes.length === 1 ) {
first = fragment = fragment.firstChild;
} else {
root(this[i], first) :
this[i],
i > 0 || results.cacheable || this.length > 1 ?
- fragment.cloneNode(true) :
+ jQuery(fragment).clone(true)[0] :
fragment
);
}
var i = 0;
ret.each(function() {
- if ( this.nodeName !== (orig[i] && orig[i].nodeName) ) {
+ if ( this.nodeType !== 1 || this.nodeName !== (orig[i] && orig[i].nodeName) ) {
return;
}
});
}
+function cloneFixAttributes(src, dest) {
+ // We do not need to do anything for non-Elements
+ if ( dest.nodeType !== 1 ) {
+ return;
+ }
+
+ var nodeName = dest.nodeName.toLowerCase();
+
+ // clearAttributes removes the attributes, which we don't want,
+ // but also removes the attachEvent events, which we *do* want
+ dest.clearAttributes();
+
+ // mergeAttributes, in contrast, only merges back on the
+ // original attributes, not the events
+ dest.mergeAttributes(src);
+
+ // IE6-8 fail to clone children inside object elements that use
+ // the proprietary classid attribute value (rather than the type
+ // attribute) to identify the type of content to display
+ if ( nodeName === "object" ) {
+ dest.outerHTML = src.outerHTML;
+ }
+
+ // IE6-8 fails to persist the checked state of a cloned checkbox
+ // or radio button
+ else if ( nodeName === "input" && src.checked ) {
+ dest.defaultChecked = dest.checked = src.checked;
+ }
+
+ // IE6-8 fails to return the selected option to the default selected
+ // state when cloning options
+ else if ( nodeName === "option" ) {
+ dest.selected = src.defaultSelected;
+ }
+
+ // Event data gets referenced instead of copied if the expando
+ // gets copied too
+ dest.removeAttribute( jQuery.expando );
+}
+
jQuery.buildFragment = function( args, nodes, scripts ) {
var fragment, cacheable, cacheresults,
doc = (nodes && nodes[0] ? nodes[0].ownerDocument || nodes[0] : document);
var ret = [],
insert = jQuery( selector ),
parent = this.length === 1 && this[0].parentNode;
-
+
if ( parent && parent.nodeType === 11 && parent.childNodes.length === 1 && insert.length === 1 ) {
insert[ original ]( this[0] );
return this;
-
+
} else {
for ( var i = 0, l = insert.length; i < l; i++ ) {
var elems = (i > 0 ? this.clone(true) : this).get();
jQuery( insert[i] )[ original ]( elems );
ret = ret.concat( elems );
}
-
+
return this.pushStack( ret, name, insert.selector );
}
};
for ( i = 0; ret[i]; i++ ) {
if ( scripts && jQuery.nodeName( ret[i], "script" ) && (!ret[i].type || ret[i].type.toLowerCase() === "text/javascript") ) {
scripts.push( ret[i].parentNode ? ret[i].parentNode.removeChild( ret[i] ) : ret[i] );
-
+
} else {
if ( ret[i].nodeType === 1 ) {
ret.splice.apply( ret, [i + 1, 0].concat(jQuery.makeArray(ret[i].getElementsByTagName("script"))) );
return ret;
},
-
+
cleanData: function( elems ) {
var data, id, cache = jQuery.cache,
special = jQuery.event.special,
deleteExpando = jQuery.support.deleteExpando;
-
+
for ( var i = 0, elem; (elem = elems[i]) != null; i++ ) {
if ( elem.nodeName && jQuery.noData[elem.nodeName.toLowerCase()] ) {
continue;
}
id = elem[ jQuery.expando ];
-
+
if ( id ) {
data = cache[ id ];
-
+
if ( data && data.events ) {
for ( var type in data.events ) {
if ( special[ type ] ) {
}
}
}
-
+
if ( deleteExpando ) {
delete elem[ jQuery.expando ];
} else if ( elem.removeAttribute ) {
elem.removeAttribute( jQuery.expando );
}
-
+
delete cache[ id ];
}
}
--- /dev/null
+(function( jQuery ) {
+
+var jsc = jQuery.now(),
+ jsre = /\=\?(&|$)/,
+ rquery_jsonp = /\?/;
+
+// Default jsonp callback name
+jQuery.ajaxSettings.jsonpCallback = function() {
+ return "jsonp" + jsc++;
+};
+
+// Normalize jsonp queries
+// 1) put callback parameter in url or data
+// 2) ensure transportDataType is json
+// 3) ensure options jsonp is always provided so that jsonp requests are always
+// json request with the jsonp option set
+jQuery.xhr.prefilter( function(s) {
+
+ var transportDataType = s.dataTypes[0];
+
+ if ( s.jsonp ||
+ transportDataType === "jsonp" ||
+ transportDataType === "json" && ( jsre.test(s.url) || typeof(s.data) === "string" && jsre.test(s.data) ) ) {
+
+ var jsonp = s.jsonp = s.jsonp || "callback",
+ jsonpCallback = s.jsonpCallback =
+ jQuery.isFunction( s.jsonpCallback ) ? s.jsonpCallback() : s.jsonpCallback,
+ url = s.url.replace(jsre, "=" + jsonpCallback + "$1"),
+ data = s.url == url && typeof(s.data) === "string" ? s.data.replace(jsre, "=" + jsonpCallback + "$1") : s.data;
+
+ if ( url == s.url && data == s.data ) {
+ url = url += (rquery_jsonp.test( url ) ? "&" : "?") + jsonp + "=" + jsonpCallback;
+ }
+
+ s.url = url;
+ s.data = data;
+
+ s.dataTypes[0] = "json";
+ }
+
+});
+
+// Bind transport to json dataType
+jQuery.xhr.bindTransport("json", function(s) {
+
+ if ( s.jsonp ) {
+
+ // Put callback in place
+ var responseContainer,
+ jsonpCallback = s.jsonpCallback,
+ previous = window[ jsonpCallback ];
+
+ 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 ];
+
+ // Use data converter to retrieve json after script execution
+ s.dataConverters["script => json"] = function() {
+ if ( ! responseContainer ) {
+ jQuery.error("Callback '" + jsonpCallback + "' was not called");
+ }
+ return responseContainer[ 0 ];
+ };
+
+ // Delegate to script transport
+ return "script";
+
+ }
+
+});
+
+})( jQuery );
--- /dev/null
+(function( jQuery ) {
+
+// Install text to script executor
+jQuery.extend( true, jQuery.ajaxSettings , {
+
+ accepts: {
+ script: "text/javascript, application/javascript"
+ },
+
+ autoDataType: {
+ script: /javascript/
+ },
+
+ dataConverters: {
+ "text => script": jQuery.globalEval
+ }
+} );
+
+// Bind script tag hack transport
+jQuery.xhr.bindTransport("script", function(s) {
+
+ // Handle cache special case
+ if ( s.cache === undefined ) {
+ s.cache = false;
+ }
+
+ // This transport only deals with cross domain get requests
+ if ( s.crossDomain && s.async && ( s.type === "GET" || ! s.data ) ) {
+
+ s.global = false;
+
+ var script,
+ head = document.getElementsByTagName("head")[0] || document.documentElement;
+
+ return {
+
+ send: function(_, callback) {
+
+ script = document.createElement("script");
+
+ script.async = "async";
+
+ if ( s.scriptCharset ) {
+ script.charset = s.scriptCharset;
+ }
+
+ script.src = s.url;
+
+ // Attach handlers for all browsers
+ script.onload = script.onreadystatechange = function(statusText) {
+
+ if ( (!script.readyState ||
+ script.readyState === "loaded" || script.readyState === "complete") ) {
+
+ // Handle memory leak in IE
+ script.onload = script.onreadystatechange = null;
+
+ // Remove the script
+ if ( head && script.parentNode ) {
+ head.removeChild( script );
+ }
+
+ script = undefined;
+
+ // Callback & dereference
+ callback(statusText ? 0 : 200, statusText || "success");
+ }
+ };
+ // Use insertBefore instead of appendChild to circumvent an IE6 bug.
+ // This arises when a base node is used (#2709 and #4378).
+ head.insertBefore( script, head.firstChild );
+ },
+
+ abort: function(statusText) {
+ if ( script ) {
+ script.onload(statusText);
+ }
+ }
+ };
+ }
+});
+
+})( jQuery );
--- /dev/null
+(function( jQuery ) {
+
+var // Next fake timer id
+ xhrPollingId = jQuery.now(),
+
+ // Callbacks hashtable
+ xhrs = {},
+
+ // #5280: see end of file
+ xhrUnloadAbortMarker = [];
+
+
+jQuery.xhr.bindTransport( function( s , determineDataType ) {
+
+ // Cross domain only allowed if supported through XMLHttpRequest
+ if ( ! s.crossDomain || jQuery.support.cors ) {
+
+ var callback;
+
+ return {
+
+ send: function(headers, complete) {
+
+ var xhr = s.xhr(),
+ handle;
+
+ // Open the socket
+ // Passing null username, generates a login popup on Opera (#2865)
+ if ( s.username ) {
+ xhr.open(s.type, s.url, s.async, s.username, s.password);
+ } else {
+ xhr.open(s.type, s.url, s.async);
+ }
+
+ // 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 in beforeSend
+ 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);
+ });
+
+ } catch(_) {}
+
+ // Do send the request
+ try {
+ xhr.send( ( s.hasContent && s.data ) || null );
+ } catch(e) {
+ complete(0, "error", "" + e);
+ return;
+ }
+
+ // Listener
+ callback = function ( abortStatusText ) {
+
+ // Was never called and is aborted or complete
+ if ( callback && ( abortStatusText || xhr.readyState === 4 ) ) {
+
+ // Do not listen anymore
+ if (handle) {
+ xhr.onreadystatechange = jQuery.noop;
+ delete xhrs[ handle ];
+ handle = undefined;
+ }
+
+ callback = 0;
+
+ // Get info
+ var status, statusText, response, responseHeaders;
+
+ if ( abortStatusText ) {
+
+ if ( xhr.readyState !== 4 ) {
+ xhr.abort();
+ }
+
+ // Stop here if unloadAbort
+ if ( abortStatusText === xhrUnloadAbortMarker ) {
+ return;
+ }
+
+ status = 0;
+ statusText = abortStatusText;
+
+ } else {
+
+ status = xhr.status;
+
+ try { // Firefox throws an exception when accessing statusText for faulty cross-domain requests
+
+ statusText = xhr.statusText;
+
+ } catch( e ) {
+
+ statusText = ""; // We normalize with Webkit giving an empty statusText
+
+ }
+
+ responseHeaders = xhr.getAllResponseHeaders();
+
+ // Filter status for non standard behaviours
+ // (so many they seem to be the actual "standard")
+ status =
+ // Opera returns 0 when it should be 304
+ // Webkit returns 0 for failing cross-domain no matter the real status
+ status === 0 ?
+ (
+ ! s.crossDomain || statusText ? // Webkit, Firefox: filter out faulty cross-domain requests
+ (
+ responseHeaders ? // Opera: filter out real aborts #6060
+ 304
+ :
+ 0
+ )
+ :
+ 302 // We assume 302 but could be anything cross-domain related
+ )
+ :
+ (
+ status == 1223 ? // IE sometimes returns 1223 when it should be 204 (see #1450)
+ 204
+ :
+ status
+ );
+
+ // Guess response if needed & update datatype accordingly
+ if ( status >= 200 && status < 300 ) {
+ response =
+ determineDataType(
+ s,
+ xhr.getResponseHeader("content-type"),
+ xhr.responseText,
+ xhr.responseXML );
+ }
+ }
+
+ // Call complete
+ complete(status,statusText,response,responseHeaders);
+ }
+ };
+
+ // if we're in sync mode
+ // or it's in cache and has been retrieved directly (IE6 & IE7)
+ // we need to manually fire the callback
+ if ( ! s.async || xhr.readyState === 4 ) {
+
+ callback();
+
+ } else {
+
+ // Listener is externalized to handle abort on unload
+ handle = xhrPollingId++;
+ xhrs[ handle ] = xhr;
+ xhr.onreadystatechange = function() {
+ callback();
+ };
+ }
+ },
+
+ abort: function(statusText) {
+ if ( callback ) {
+ callback(statusText);
+ }
+ }
+ };
+ }
+});
+
+// #5280: we need to abort on unload or IE will keep connections alive
+jQuery(window).bind( "unload" , function() {
+
+ // Abort all pending requests
+ jQuery.each(xhrs, function(_, xhr) {
+ if ( xhr.onreadystatechange ) {
+ xhr.onreadystatechange( xhrUnloadAbortMarker );
+ }
+ });
+
+ // Resest polling structure to be safe
+ xhrs = {};
+
+});
+
+})( jQuery );
--- /dev/null
+(function( jQuery ) {
+
+var rquery_xhr = /\?/,
+ rhash = /#.*$/,
+ rheaders = /^(.*?):\s*(.*?)\r?$/mg, // IE leaves an \r character at EOL
+ rnoContent = /^(?:GET|HEAD)$/,
+ rts = /([?&])_=[^&]*/,
+ rurl = /^(\w+:)?\/\/([^\/?#]+)/,
+
+ sliceFunc = Array.prototype.slice,
+
+ isFunction = jQuery.isFunction;
+
+// Creates a jQuery xhr object
+jQuery.xhr = function( _native ) {
+
+ if ( _native ) {
+ return jQuery.ajaxSettings.xhr();
+ }
+
+ function reset(force) {
+
+ // We only need to reset if we went through the init phase
+ // (with the exception of object creation)
+ if ( force || internal ) {
+
+ // Reset callbacks lists
+ callbacksLists = {
+ success: createCBList(),
+ error: createCBList(),
+ complete: createCBList()
+ };
+
+ // Reset private variables
+ requestHeaders = {};
+ responseHeadersString = responseHeaders = internal = done = timeoutTimer = s = undefined;
+
+ // Reset state
+ xhr.readyState = 0;
+ sendFlag = 0;
+
+ // Remove responseX fields
+ for ( var name in xhr ) {
+ if ( /^response/.test(name) ) {
+ delete xhr[name];
+ }
+ }
+ }
+ }
+
+ function init() {
+
+ var // Options extraction
+
+ // Remove hash character (#7531: first for string promotion)
+ url = s.url = ( "" + s.url ).replace( rhash , "" ),
+
+ // Uppercase the type
+ type = s.type = s.type.toUpperCase(),
+
+ // Determine if request has content
+ hasContent = s.hasContent = ! rnoContent.test( type ),
+
+ // Extract dataTypes list
+ dataType = s.dataType,
+ dataTypes = s.dataTypes = dataType ? jQuery.trim(dataType).toLowerCase().split(/\s+/) : ["*"],
+
+ // Determine if a cross-domain request is in order
+ parts = rurl.exec( url.toLowerCase() ),
+ loc = location,
+ crossDomain = s.crossDomain = !!( parts && ( parts[1] && parts[1] != loc.protocol || parts[2] != loc.host ) ),
+
+ // Get other options locally
+ data = s.data,
+ originalContentType = s.contentType,
+ prefilters = s.prefilters,
+ accepts = s.accepts,
+ headers = s.headers,
+
+ // Other Variables
+ transportDataType,
+ i;
+
+ // Convert data if not already a string
+ if ( data && s.processData && typeof data != "string" ) {
+ data = s.data = jQuery.param( data , s.traditional );
+ }
+
+ // Apply option prefilters
+ for (i in prefilters) {
+ prefilters[i](s);
+ }
+
+ // Get internal
+ internal = selectTransport( s );
+
+ // Re-actualize url & data
+ url = s.url;
+ data = s.data;
+
+ // If internal was found
+ if ( internal ) {
+
+ // Get transportDataType
+ transportDataType = dataTypes[0];
+
+ // More options handling for requests with no content
+ if ( ! hasContent ) {
+
+ // If data is available, append data to url
+ if ( data ) {
+ url += (rquery_xhr.test(url) ? "&" : "?") + data;
+ }
+
+ // Add anti-cache in url if needed
+ if ( s.cache === false ) {
+
+ var ts = jQuery.now(),
+ // try replacing _= if it is there
+ ret = url.replace(rts, "$1_=" + ts );
+
+ // if nothing was replaced, add timestamp to the end
+ url = ret + ((ret == url) ? (rquery_xhr.test(url) ? "&" : "?") + "_=" + ts : "");
+ }
+
+ s.url = url;
+ }
+
+ // Set the correct header, if data is being sent
+ if ( ( data && hasContent ) || originalContentType ) {
+ 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[url] ) {
+ requestHeaders["if-modified-since"] = jQuery_lastModified[url];
+ }
+ if ( jQuery_etag[url] ) {
+ requestHeaders["if-none-match"] = jQuery_etag[url];
+ }
+ }
+
+ // Set the Accepts header for the server, depending on the dataType
+ requestHeaders.accept = transportDataType && accepts[ transportDataType ] ?
+ accepts[ transportDataType ] + ( transportDataType !== "*" ? ", */*; q=0.01" : "" ) :
+ accepts[ "*" ];
+
+ // Check for headers option
+ for ( i in headers ) {
+ requestHeaders[ i.toLowerCase() ] = headers[ i ];
+ }
+ }
+
+ callbackContext = s.context || s;
+ globalEventContext = s.context ? jQuery(s.context) : jQuery.event;
+
+ for ( i in callbacksLists ) {
+ callbacksLists[i].bind(s[i]);
+ }
+
+ // Watch for a new set of requests
+ if ( s.global && jQuery.active++ === 0 ) {
+ jQuery.event.trigger( "ajaxStart" );
+ }
+
+ done = whenDone;
+ }
+
+ function whenDone(status, statusText, response, headers) {
+
+ // Called once
+ done = undefined;
+
+ // Reset sendFlag
+ sendFlag = 0;
+
+ // Cache response headers
+ responseHeadersString = headers || "";
+
+ // Clear timeout if it exists
+ if ( timeoutTimer ) {
+ clearTimeout(timeoutTimer);
+ }
+
+ var // Reference url
+ url = s.url,
+ // and ifModified status
+ ifModified = s.ifModified,
+
+ // Is it a success?
+ isSuccess = 0,
+ // Stored success
+ success,
+ // Stored error
+ error = statusText;
+
+ // If not timeout, force a jQuery-compliant status text
+ if ( statusText != "timeout" ) {
+ statusText = ( status >= 200 && status < 300 ) ?
+ "success" :
+ ( status === 304 ? "notmodified" : "error" );
+ }
+
+ // If successful, handle type chaining
+ if ( statusText === "success" || statusText === "notmodified" ) {
+
+ // Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
+ if ( ifModified ) {
+ var lastModified = xhr.getResponseHeader("Last-Modified"),
+ etag = xhr.getResponseHeader("Etag");
+
+ if (lastModified) {
+ jQuery_lastModified[url] = lastModified;
+ }
+ if (etag) {
+ jQuery_etag[url] = etag;
+ }
+ }
+
+ if ( ifModified && statusText === "notmodified" ) {
+
+ success = null;
+ isSuccess = 1;
+
+ } else {
+ // Chain data conversions and determine the final value
+ // (if an exception is thrown in the process, it'll be notified as an error)
+ try {
+
+ function checkData(data) {
+ if ( data !== undefined ) {
+ var testFunction = s.dataCheckers[srcDataType];
+ if ( isFunction( testFunction ) ) {
+ testFunction(data);
+ }
+ }
+ }
+
+ function convertData (data) {
+ var conversionFunction = dataConverters[srcDataType+" => "+destDataType] ||
+ dataConverters["* => "+destDataType],
+ noFunction = ! isFunction( conversionFunction );
+ if ( noFunction ) {
+ if ( srcDataType != "text" && destDataType != "text" ) {
+ // We try to put text inbetween
+ var first = dataConverters[srcDataType+" => text"] ||
+ dataConverters["* => text"],
+ second = dataConverters["text => "+destDataType] ||
+ dataConverters["* => "+destDataType],
+ areFunctions = isFunction( first ) && isFunction( second );
+ if ( areFunctions ) {
+ conversionFunction = function (data) {
+ return second( first ( data ) );
+ };
+ }
+ noFunction = ! areFunctions;
+ }
+ if ( noFunction ) {
+ jQuery.error( "no data converter between " + srcDataType + " and " + destDataType );
+ }
+
+ }
+ return conversionFunction(data);
+ }
+
+ var dataTypes = s.dataTypes,
+ i,
+ length,
+ data = response,
+ dataConverters = s.dataConverters,
+ srcDataType,
+ destDataType,
+ responseTypes = s.xhrResponseFields;
+
+ for ( i = 0, length = dataTypes.length ; i < length ; i++ ) {
+
+ destDataType = dataTypes[i];
+
+ if ( !srcDataType ) { // First time
+
+ // Copy type
+ srcDataType = destDataType;
+ // Check
+ checkData(data);
+ // Apply dataFilter
+ if ( isFunction( s.dataFilter ) ) {
+ data = s.dataFilter(data, s.dataType);
+ // Recheck data
+ checkData(data);
+ }
+
+ } else { // Subsequent times
+
+ // handle auto
+ // JULIAN: for reasons unknown to me === doesn't work here
+ if (destDataType == "*") {
+
+ destDataType = srcDataType;
+
+ } else if ( srcDataType != destDataType ) {
+
+ // Convert
+ data = convertData(data);
+ // Copy type & check
+ srcDataType = destDataType;
+ checkData(data);
+
+ }
+
+ }
+
+ // Copy response into the xhr if it hasn't been already
+ var responseDataType,
+ responseType = responseTypes[srcDataType];
+
+ if ( responseType ) {
+
+ responseDataType = srcDataType;
+
+ } else {
+
+ responseType = responseTypes[ responseDataType = "text" ];
+
+ }
+
+ if ( responseType !== 1 ) {
+ xhr[ "response" + responseType ] = data;
+ responseTypes[ responseType ] = 1;
+ }
+
+ }
+
+ // We have a real success
+ success = data;
+ isSuccess = 1;
+
+ } catch(e) {
+
+ statusText = "parsererror";
+ error = "" + e;
+
+ }
+ }
+
+ } else { // if not success, mark it as an error
+
+ error = error || statusText;
+
+ }
+
+ // Set data for the fake xhr object
+ xhr.status = status;
+ xhr.statusText = statusText;
+
+ // Keep local copies of vars in case callbacks re-use the xhr
+ var _s = s,
+ _callbacksLists = callbacksLists,
+ _callbackContext = callbackContext,
+ _globalEventContext = globalEventContext;
+
+ // Set state if the xhr hasn't been re-used
+ function _setState( value ) {
+ if ( xhr.readyState && s === _s ) {
+ setState( value );
+ }
+ }
+
+ // Really completed?
+ if ( status && s.async ) {
+ setState( 2 );
+ _setState( 3 );
+ }
+
+ // We're done
+ _setState( 4 );
+
+ // Success
+ _callbacksLists.success.fire( isSuccess , _callbackContext , success, statusText, xhr);
+ if ( isSuccess && _s.global ) {
+ _globalEventContext.trigger( "ajaxSuccess", [xhr, _s, success] );
+ }
+ // Error
+ _callbacksLists.error.fire( ! isSuccess , _callbackContext , xhr, statusText, error);
+ if ( !isSuccess && _s.global ) {
+ _globalEventContext.trigger( "ajaxError", [xhr, _s, error] );
+ }
+ // Complete
+ _callbacksLists.complete.fire( 1 , _callbackContext, xhr, statusText);
+ if ( _s.global ) {
+ _globalEventContext.trigger( "ajaxComplete", [xhr, _s] );
+ // Handle the global AJAX counter
+ if ( ! --jQuery.active ) {
+ jQuery.event.trigger( "ajaxStop" );
+ }
+ }
+ }
+
+ // Ready state control
+ function checkState( expected , test ) {
+ if ( expected !== true && ( expected === false || test === false || xhr.readyState !== expected ) ) {
+ jQuery.error("INVALID_STATE_ERR");
+ }
+ }
+
+ // Ready state change
+ function setState( value ) {
+ xhr.readyState = value;
+ if ( isFunction( xhr.onreadystatechange ) ) {
+ xhr.onreadystatechange();
+ }
+ }
+
+ var // jQuery lists
+ jQuery_lastModified = jQuery.lastModified,
+ jQuery_etag = jQuery.etag,
+ // Options object
+ s,
+ // Callback stuff
+ callbackContext,
+ globalEventContext,
+ callbacksLists,
+ // Headers (they are sent all at once)
+ requestHeaders,
+ // Response headers
+ responseHeadersString,
+ responseHeaders,
+ // Done callback
+ done,
+ // transport
+ internal,
+ // timeout handle
+ timeoutTimer,
+ // The send flag
+ sendFlag,
+ // Fake xhr
+ xhr = {
+ // state
+ readyState: 0,
+
+ // Callback
+ onreadystatechange: null,
+
+ // Open
+ open: function(type, url, async, username, password) {
+
+ xhr.abort();
+ reset();
+
+ s = {
+ type: type,
+ url: url,
+ async: async,
+ username: username,
+ password: password
+ };
+
+ setState(1);
+
+ return xhr;
+ },
+
+ // Send
+ send: function(data, moreOptions) {
+
+ checkState(1 , !sendFlag);
+
+ s.data = data;
+
+ s = jQuery.extend( true,
+ {},
+ jQuery.ajaxSettings,
+ s,
+ moreOptions || ( moreOptions === false ? { global: false } : {} ) );
+
+ if ( moreOptions ) {
+ // We force the original context
+ // (plain objects used as context get extended)
+ s.context = moreOptions.context;
+ }
+
+ init();
+
+ // If not internal, abort
+ if ( ! internal ) {
+ done( 0 , "transport not found" );
+ return false;
+ }
+
+ // Allow custom headers/mimetypes and early abort
+ if ( s.beforeSend ) {
+
+ var _s = s;
+
+ if ( s.beforeSend.call(callbackContext, xhr, s) === false || ! xhr.readyState || _s !== s ) {
+
+ // Abort if not done
+ if ( xhr.readyState && _s === s ) {
+ xhr.abort();
+ }
+
+ // Handle the global AJAX counter
+ if ( _s.global && ! --jQuery.active ) {
+ jQuery.event.trigger( "ajaxStop" );
+ }
+
+ return false;
+ }
+ }
+
+ sendFlag = 1;
+
+ // Send global event
+ if ( s.global ) {
+ globalEventContext.trigger("ajaxSend", [xhr, s]);
+ }
+
+ // Timeout
+ if ( s.async && s.timeout > 0 ) {
+ timeoutTimer = setTimeout(function(){
+ xhr.abort("timeout");
+ }, s.timeout);
+ }
+
+ if ( s.async ) {
+ setState(1);
+ }
+
+ try {
+
+ internal.send(requestHeaders, done);
+ return xhr;
+
+ } catch (e) {
+
+ if ( done ) {
+
+ done(0, "error", "" + e);
+
+ } else {
+
+ jQuery.error(e);
+
+ }
+ }
+
+ return false;
+ },
+
+ // Caches the header
+ setRequestHeader: function(name,value) {
+ checkState(1, !sendFlag);
+ requestHeaders[ name.toLowerCase() ] = value;
+ return xhr;
+ },
+
+ // Raw string
+ getAllResponseHeaders: function() {
+ return xhr.readyState <= 1 ? "" : responseHeadersString;
+ },
+
+ // Builds headers hashtable if needed
+ getResponseHeader: function( key ) {
+
+ if ( xhr.readyState <= 1 ) {
+
+ return null;
+
+ }
+
+ if ( responseHeaders === undefined ) {
+
+ responseHeaders = {};
+
+ if ( typeof responseHeadersString === "string" ) {
+
+ var match;
+
+ while( ( match = rheaders.exec( responseHeadersString ) ) ) {
+ responseHeaders[ match[ 1 ].toLowerCase() ] = match[ 2 ];
+ }
+ }
+ }
+ return responseHeaders[ key.toLowerCase() ];
+ },
+
+ // Cancel the request
+ abort: function(statusText) {
+ if (internal) {
+ internal.abort( statusText || "abort" );
+ }
+ xhr.readyState = 0;
+ }
+ };
+
+ // Init data (so that we can bind callbacks early
+ reset(1);
+
+ // Install callbacks related methods
+ jQuery.each(callbacksLists, function(name) {
+ var list;
+ xhr[name] = function() {
+ list = callbacksLists[name];
+ if ( list ) {
+ list.bind.apply(list, arguments );
+ }
+ return this;
+ };
+ });
+
+ // Return the xhr emulation
+ return xhr;
+};
+
+// Create a callback list
+function createCBList() {
+
+ var functors = [],
+ autoFire = 0,
+ fireArgs,
+ list = {
+
+ fire: function( flag , context ) {
+
+ // Save info for later bindings
+ fireArgs = arguments;
+
+ // Remove autoFire to keep bindings in order
+ autoFire = 0;
+
+ var args = sliceFunc.call( fireArgs , 2 );
+
+ // Execute callbacks
+ while ( flag && functors.length ) {
+ flag = functors.shift().apply( context , args ) !== false;
+ }
+
+ // Clean if asked to stop
+ if ( ! flag ) {
+ clean();
+ }
+
+ // Set autoFire
+ autoFire = 1;
+ },
+
+ bind: function() {
+
+ var args = arguments,
+ i = 0,
+ length = args.length,
+ func;
+
+ for ( ; i < length ; i++ ) {
+
+ func = args[ i ];
+
+ if ( jQuery.isArray(func) ) {
+
+ list.bind.apply( list , func );
+
+ } else if ( isFunction(func) ) {
+
+ // Add if not already in
+ if ( ! pos( func ) ) {
+ functors.push( func );
+ }
+ }
+ }
+
+ if ( autoFire ) {
+ list.fire.apply( list , fireArgs );
+ }
+ },
+
+ unbind: function() {
+
+ var i = 0,
+ args = arguments,
+ length = args.length,
+ func,
+ position;
+
+ if ( length ) {
+
+ for( ; i < length ; i++ ) {
+ func = args[i];
+ if ( jQuery.isArray(func) ) {
+ list.unbind.apply(list,func);
+ } else if ( isFunction(func) ) {
+ position = pos(func);
+ if ( position ) {
+ functors.splice(position-1,1);
+ }
+ }
+ }
+
+ } else {
+
+ functors = [];
+
+ }
+
+ }
+
+ };
+
+ // Get the index of the functor in the list (1-based)
+ function pos( func ) {
+ for (var i = 0, length = functors.length; i < length && functors[i] !== func; i++) {
+ }
+ return i < length ? ( i + 1 ) : 0;
+ }
+
+ // Clean the object
+ function clean() {
+ // Empty callbacks list
+ functors = [];
+ // Inhibit methods
+ for (var i in list) {
+ list[i] = jQuery.noop;
+ }
+ }
+
+ return list;
+}
+
+jQuery.extend(jQuery.xhr, {
+
+ // Add new prefilter
+ prefilter: function (functor) {
+ if ( isFunction(functor) ) {
+ jQuery.ajaxSettings.prefilters.push( functor );
+ }
+ return this;
+ },
+
+ // Bind a transport to one or more dataTypes
+ bindTransport: function () {
+
+ var args = arguments,
+ i,
+ start = 0,
+ length = args.length,
+ dataTypes = [ "*" ],
+ functors = [],
+ functor,
+ first,
+ append,
+ list,
+ transports = jQuery.ajaxSettings.transports;
+
+ if ( length ) {
+
+ if ( ! isFunction( args[ 0 ] ) ) {
+
+ dataTypes = args[ 0 ].toLowerCase().split(/\s+/);
+ start = 1;
+
+ }
+
+ if ( dataTypes.length && start < length ) {
+
+ for ( i = start; i < length; i++ ) {
+ functor = args[i];
+ if ( isFunction(functor) ) {
+ functors.push( functor );
+ }
+ }
+
+ if ( functors.length ) {
+
+ jQuery.each ( dataTypes, function( _ , dataType ) {
+
+ first = /^\+/.test( dataType );
+
+ if (first) {
+ dataType = dataType.substr(1);
+ }
+
+ if ( dataType !== "" ) {
+
+ append = Array.prototype[ first ? "unshift" : "push" ];
+
+ list = transports[ dataType ];
+
+ jQuery.each ( functors, function( _ , functor ) {
+
+ if ( ! list ) {
+
+ list = transports[ dataType ] = [ functor ];
+
+ } else {
+
+ append.call( list , functor );
+ }
+ } );
+ }
+
+ } );
+ }
+ }
+ }
+
+ return this;
+ }
+
+
+});
+
+// Select a transport given options
+function selectTransport( s ) {
+
+ var dataTypes = s.dataTypes,
+ transportDataType,
+ transportsList,
+ transport,
+ i,
+ length,
+ checked = {},
+ flag;
+
+ function initSearch( dataType ) {
+
+ flag = transportDataType !== dataType && ! checked[ dataType ];
+
+ if ( flag ) {
+
+ checked[ dataType ] = 1;
+ transportDataType = dataType;
+ transportsList = s.transports[ dataType ];
+ i = -1;
+ length = transportsList ? transportsList.length : 0 ;
+ }
+
+ return flag;
+ }
+
+ initSearch( dataTypes[ 0 ] );
+
+ for ( i = 0 ; ! transport && i <= length ; i++ ) {
+
+ if ( i === length ) {
+
+ initSearch( "*" );
+
+ } else {
+
+ transport = transportsList[ i ]( s , determineDataType );
+
+ // If we got redirected to another dataType
+ // Search there (if not in progress or already tried)
+ if ( typeof( transport ) === "string" &&
+ initSearch( transport ) ) {
+
+ dataTypes.unshift( transport );
+ transport = 0;
+ }
+ }
+ }
+
+ return transport;
+}
+
+// Utility function that handles dataType when response is received
+// (for those transports that can give text or xml responses)
+function determineDataType( s , ct , text , xml ) {
+
+ var autoDataType = s.autoDataType,
+ type,
+ regexp,
+ dataTypes = s.dataTypes,
+ transportDataType = dataTypes[0],
+ response;
+
+ // Auto (xml, json, script or text determined given headers)
+ if ( transportDataType === "*" ) {
+
+ for ( type in autoDataType ) {
+ if ( ( regexp = autoDataType[ type ] ) && regexp.test( ct ) ) {
+ transportDataType = dataTypes[0] = type;
+ break;
+ }
+ }
+ }
+
+ // xml and parsed as such
+ if ( transportDataType === "xml" &&
+ xml &&
+ xml.documentElement /* #4958 */ ) {
+
+ response = xml;
+
+ // Text response was provided
+ } else {
+
+ response = text;
+
+ // If it's not really text, defer to dataConverters
+ if ( transportDataType !== "text" ) {
+ dataTypes.unshift( "text" );
+ }
+
+ }
+
+ return response;
+}
+
+})( jQuery );
--- /dev/null
+<?php header("Content-type: atom+xml") ?>
+<root>
+ <element />
+</root>
\ No newline at end of file
--- /dev/null
+<?php
+error_reporting(0);
+$id = isset ( $_REQUEST['id'] ) ? $_REQUEST['id'] : null;
+$wait = isset( $_REQUEST['wait'] ) ? $_REQUEST['wait'] : null;
+
+if ( $wait ) sleep( $wait );
+
+header("Content-type: text/css");
+
+if ( $id ) {
+ ?>
+ div#<?= $id ?> { margin-left: 27px }
+ <?php
+}
+?>
\ No newline at end of file
--- /dev/null
+<?php
+
+header( "Sample-Header: Hello World" );
+
+$headers = array();
+
+foreach( $_SERVER as $key => $value ) {
+
+ if ( substr( $key , 0 , 5 ) == "HTTP_" ) {
+
+ $key = str_replace( "_" , "-" , substr( $key , 5) );
+ $headers[ $key ] = $value;
+
+ }
+
+}
+
+foreach( explode( "_" , $_GET[ "keys" ] ) as $key ) {
+ echo "$key: " . $headers[ strtoupper( $key ) ] . "\n";
+}
-Lorem ipsum dolor sit amet\r
-consectetuer adipiscing elit\r
-Sed lorem leo\r
-lorem leo consectetuer adipiscing elit\r
-Sed lorem leo\r
-rhoncus sit amet\r
-elementum at\r
-bibendum at, eros\r
-Cras at mi et tortor egestas vestibulum\r
-sed Cras at mi vestibulum\r
-Phasellus sed felis sit amet\r
-orci dapibus semper.\r
+Lorem ipsum dolor sit amet
+consectetuer adipiscing elit
+Sed lorem leo
+lorem leo consectetuer adipiscing elit
+Sed lorem leo
+rhoncus sit amet
+elementum at
+bibendum at, eros
+Cras at mi et tortor egestas vestibulum
+sed Cras at mi vestibulum
+Phasellus sed felis sit amet
+orci dapibus semper.
--- /dev/null
+<?php
+error_reporting(0);
+$callback = $_REQUEST['callback'];
+$json = $_REQUEST['json'];
+$text = json_encode(file_get_contents(dirname(__FILE__)."/with_fries.xml"));
+echo "$callback($text)";
+?>
-<html>\r
- <head>\r
- <script src='../dist/jquery.js' type='text/javascript'></script>\r
- <style>\r
- .red {\r
- background-color: red;\r
- border: solid 3px red;\r
- }\r
- </style>\r
- </head>\r
- <body>\r
- <h2>Change Tests</h2>\r
- <table>\r
- <tr>\r
- <td>\r
- Change each:\r
- </td>\r
- <td>\r
- <select class='select_test'>\r
- <option value='one'>change me 1</option>\r
- <option value='two'>change me 2</option>\r
- <option value='three'>change me 3</option>\r
- </select>\r
- <select class='select_test'>\r
- <option value='one'>change me 1</option>\r
- <option value='two' selected="selected">change me 2</option>\r
- <option value='three'>change me 3</option>\r
- </select>\r
- </td>\r
- <td>\r
- <select class='mselect_test' multiple="multiple">\r
- <option value='one'>change me 1</option>\r
- <option value='two'>change me 2</option>\r
- <option value='three'>change me 3</option>\r
- </select>\r
- </td>\r
- <td>\r
- <input type="checkbox" class="checkbox_test" name="mycheckbox" id="checkbox1"/>\r
- <label for="checkbox1">Checkbox 1</label><br/>\r
- <input type="checkbox" class="checkbox_test" name="mycheckbox" id="checkbox2"/>\r
- <label for="checkbox2">Checkbox 2</label>\r
- <input type="checkbox" class="checkbox_test" name="mycheckbox" id="checkbox3" disabled="disabled"/>\r
- <label for="checkbox3">Checkbox 3</label>\r
- </td>\r
- </td>\r
- </td>\r
- <td>\r
- <input type="radio" class="radio_test" name="myradio" id="radio1"/>\r
- <label for="radio1">Radio1</label><br/>\r
- <input type="radio" class="radio_test" name="myradio" id="radio2"/>\r
- <label for="radio2">Radio2</label>\r
- <input type="radio" class="radio_test" name="myradio" id="radio3" disabled="disabled"/>\r
- <label for="radio3">Radio3</label>\r
- </td>\r
- <td>\r
- <input class="file_test" id="file1" type="file"/>\r
- <td>\r
- <input class='test' value='' id='input' size='10' />\r
- <input class='test' value='test' id='input2' size='10' readonly="readonly" />\r
- </td>\r
- <td>\r
- <textarea rows='2'></textarea>\r
- </td>\r
- <td>$(document).bind('change')</td>\r
- </tr>\r
- <tr>\r
- <td>Live:</td>\r
- <td id='select' class="red">SELECT</td>\r
- <td id='mselect' class="red">MULTI</td>\r
- <td id='checkbox' class="red">CHECKBOX</td>\r
- <td id='radio' class="red">RADIO</td>\r
- <td id='file' class="red">FILE</td>\r
- <td id='text' class="red">TEXT</td>\r
- <td id='textarea' class="red">TEXTAREA</td>\r
- <td id='boundChange' class="red">DOCUMENT</td>\r
- </tr>\r
- <tr>\r
- <td>Bind:</td>\r
- <td id='selectbind' class="red">SELECT</td>\r
- <td id='mselectbind' class="red">MULTI</td>\r
- <td id='checkboxbind' class="red">CHECKBOX</td>\r
- <td id='radiobind' class="red">RADIO</td>\r
- <td id='filebind' class="red">FILE</td>\r
- <td id='textbind' class="red">TEXT</td>\r
- <td id='textareabind' class="red">TEXTAREA</td>\r
- </tr>\r
- <tr>\r
- <td>Focusin:</td>\r
- <td id='selectfocus' class="red">SELECT</td>\r
- <td id='mselectfocus' class="red">MULTI</td>\r
- <td id='checkboxfocus' class="red">CHECKBOX</td>\r
- <td id='radiofocus' class="red">RADIO</td>\r
- <td id='filefocus' class="red">FILE</td>\r
- <td id='textfocus' class="red">TEXT</td>\r
- <td id='textareafocus' class="red">TEXTAREA</td>\r
- <td id='boundFocus' class="red">DOCUMENT</td>\r
- </tr>\r
- <tr>\r
- <td>Focusout:</td>\r
- <td id='selectblur' class="red">SELECT</td>\r
- <td id='mselectblur' class="red">MULTI</td>\r
- <td id='checkboxblur' class="red">CHECKBOX</td>\r
- <td id='radioblur' class="red">RADIO</td>\r
- <td id='fileblur' class="red">FILE</td>\r
- <td id='textblur' class="red">TEXT</td>\r
- <td id='textareablur' class="red">TEXTAREA</td>\r
- <td id='boundBlur' class="red">DOCUMENT</td>\r
- </tr>\r
- <tr>\r
- <td>Live Focus:</td>\r
- <td id='selectlfocus' class="red">SELECT</td>\r
- <td id='mselectlfocus' class="red">MULTI</td>\r
- <td id='checkboxlfocus' class="red">CHECKBOX</td>\r
- <td id='radiolfocus' class="red">RADIO</td>\r
- <td id='filelfocus' class="red">FILE</td>\r
- <td id='textlfocus' class="red">TEXT</td>\r
- <td id='textarealfocus' class="red">TEXTAREA</td>\r
- </tr>\r
- <tr>\r
- <td>Live Blur:</td>\r
- <td id='selectlblur' class="red">SELECT</td>\r
- <td id='mselectlblur' class="red">MULTI</td>\r
- <td id='checkboxlblur' class="red">CHECKBOX</td>\r
- <td id='radiolblur' class="red">RADIO</td>\r
- <td id='filelblur' class="red">FILE</td>\r
- <td id='textlblur' class="red">TEXT</td>\r
- <td id='textarealblur' class="red">TEXTAREA</td>\r
- </tr>\r
- </table>\r
- <h2>Submit Tests</h2>\r
- <table>\r
- <tr>\r
- <td>\r
- Submit each:\r
- </td>\r
- <td>\r
- <form action="" id="text_submit">\r
- <input class='test' type='text' value='Key Return To Submit'/>\r
- </form>\r
- </td>\r
- <td>\r
- <form action="" id="password_submit">\r
- <input class='test' type='password' value=''/>\r
- </form>\r
- </td>\r
- <td>\r
- <form action="" id="submit_submit">\r
- <input type='submit' value="Click Me To Submit" />\r
- </form>\r
- </td>\r
- <td>$(document).bind('submit')</td>\r
- </tr>\r
- <tr>\r
- <td>Results:</td>\r
- <td id='textSubmit' class="red">TEXT</td>\r
- <td id='passwordSubmit' class="red">PASSWORD</td>\r
- <td id='submitSubmit' class="red">BUTTON</td>\r
- <td id='boundSubmit' class="red">DOCUMENT</td>\r
- </tr>\r
- </table>\r
-\r
- <ul id="log"></ul>\r
-\r
- <script type='text/javascript'>\r
- jQuery.fn.addChangeTest = function( id, prevent ) {\r
- this.bind("focusin", function(){\r
- jQuery(id + "focus").blink();\r
- }).bind("focusout", function(){\r
- jQuery(id + "blur").blink();\r
- });\r
-\r
- this.bind("focus", function(){\r
- jQuery(id + "lfocus").blink();\r
- }).bind("blur", function(){\r
- jQuery(id + "lblur").blink();\r
- });\r
-\r
- return this.bind("change", function(e){\r
- jQuery(id + "bind").blink();\r
- }).live("change", function(e){\r
- if ( prevent ) {\r
- e.preventDefault();\r
- }\r
-\r
- jQuery(id).blink();\r
- });\r
- };\r
-\r
- jQuery.fn.addSubmitTest = function( id, prevent ) {\r
- return this.live("submit", function(e){\r
- if ( prevent ) {\r
- e.preventDefault();\r
- }\r
-\r
- jQuery(id).blink();\r
- });\r
- };\r
-\r
- jQuery.fn.blink = function(){\r
- return this.css("backgroundColor","green").css("border","solid 3px green").delay(700).queue(function(next){\r
- jQuery(this).css("backgroundColor","");\r
- next();\r
- });\r
- };\r
-\r
- $(document).bind("focusin", function() {\r
- jQuery("#boundFocus").blink();\r
- });\r
- \r
- $(document).bind("focusout", function() {\r
- jQuery("#boundBlur").blink();\r
- });\r
-\r
- $("td.red").live("hover", function(e) {\r
- if ( e.type === "mouseenter" ) {\r
- $(this).css("backgroundColor","green");\r
- } else {\r
- $(this).css("backgroundColor","");\r
- }\r
- });\r
-\r
- $(".select_test").addChangeTest("#select");\r
- $(".mselect_test").addChangeTest("#mselect");\r
- $(".checkbox_test").addChangeTest("#checkbox");\r
- $(".radio_test").addChangeTest("#radio");\r
- $(".file_test").addChangeTest("#file");\r
- $('textarea').addChangeTest("#textarea");\r
- $('#input').addChangeTest("#text");\r
- $(document).bind("change", function(){\r
- jQuery("#boundChange").blink();\r
- });\r
- \r
- $("#text_submit").addSubmitTest("#textSubmit", true);\r
- $("#password_submit").addSubmitTest("#passwordSubmit", true);\r
- $("#submit_submit").addSubmitTest("#submitSubmit", true);\r
- $(document).bind("submit", function(){\r
- jQuery("#boundSubmit").blink();\r
- });\r
- \r
- </script>\r
- </body>\r
-</html>\r
+<html>
+ <head>
+ <script src='../dist/jquery.js' type='text/javascript'></script>
+ <style>
+ .red {
+ background-color: red;
+ border: solid 3px red;
+ }
+ </style>
+ </head>
+ <body>
+ <h2>Change Tests</h2>
+ <table>
+ <tr>
+ <td>
+ Change each:
+ </td>
+ <td>
+ <select class='select_test'>
+ <option value='one'>change me 1</option>
+ <option value='two'>change me 2</option>
+ <option value='three'>change me 3</option>
+ </select>
+ <select class='select_test'>
+ <option value='one'>change me 1</option>
+ <option value='two' selected="selected">change me 2</option>
+ <option value='three'>change me 3</option>
+ </select>
+ </td>
+ <td>
+ <select class='mselect_test' multiple="multiple">
+ <option value='one'>change me 1</option>
+ <option value='two'>change me 2</option>
+ <option value='three'>change me 3</option>
+ </select>
+ </td>
+ <td>
+ <input type="checkbox" class="checkbox_test" name="mycheckbox" id="checkbox1"/>
+ <label for="checkbox1">Checkbox 1</label><br/>
+ <input type="checkbox" class="checkbox_test" name="mycheckbox" id="checkbox2"/>
+ <label for="checkbox2">Checkbox 2</label>
+ <input type="checkbox" class="checkbox_test" name="mycheckbox" id="checkbox3" disabled="disabled"/>
+ <label for="checkbox3">Checkbox 3</label>
+ </td>
+ </td>
+ </td>
+ <td>
+ <input type="radio" class="radio_test" name="myradio" id="radio1"/>
+ <label for="radio1">Radio1</label><br/>
+ <input type="radio" class="radio_test" name="myradio" id="radio2"/>
+ <label for="radio2">Radio2</label>
+ <input type="radio" class="radio_test" name="myradio" id="radio3" disabled="disabled"/>
+ <label for="radio3">Radio3</label>
+ </td>
+ <td>
+ <input class="file_test" id="file1" type="file"/>
+ <td>
+ <input class='test' value='' id='input' size='10' />
+ <input class='test' value='test' id='input2' size='10' readonly="readonly" />
+ </td>
+ <td>
+ <textarea rows='2'></textarea>
+ </td>
+ <td>$(document).bind('change')</td>
+ </tr>
+ <tr>
+ <td>Live:</td>
+ <td id='select' class="red">SELECT</td>
+ <td id='mselect' class="red">MULTI</td>
+ <td id='checkbox' class="red">CHECKBOX</td>
+ <td id='radio' class="red">RADIO</td>
+ <td id='file' class="red">FILE</td>
+ <td id='text' class="red">TEXT</td>
+ <td id='textarea' class="red">TEXTAREA</td>
+ <td id='boundChange' class="red">DOCUMENT</td>
+ </tr>
+ <tr>
+ <td>Bind:</td>
+ <td id='selectbind' class="red">SELECT</td>
+ <td id='mselectbind' class="red">MULTI</td>
+ <td id='checkboxbind' class="red">CHECKBOX</td>
+ <td id='radiobind' class="red">RADIO</td>
+ <td id='filebind' class="red">FILE</td>
+ <td id='textbind' class="red">TEXT</td>
+ <td id='textareabind' class="red">TEXTAREA</td>
+ </tr>
+ <tr>
+ <td>Focusin:</td>
+ <td id='selectfocus' class="red">SELECT</td>
+ <td id='mselectfocus' class="red">MULTI</td>
+ <td id='checkboxfocus' class="red">CHECKBOX</td>
+ <td id='radiofocus' class="red">RADIO</td>
+ <td id='filefocus' class="red">FILE</td>
+ <td id='textfocus' class="red">TEXT</td>
+ <td id='textareafocus' class="red">TEXTAREA</td>
+ <td id='boundFocus' class="red">DOCUMENT</td>
+ </tr>
+ <tr>
+ <td>Focusout:</td>
+ <td id='selectblur' class="red">SELECT</td>
+ <td id='mselectblur' class="red">MULTI</td>
+ <td id='checkboxblur' class="red">CHECKBOX</td>
+ <td id='radioblur' class="red">RADIO</td>
+ <td id='fileblur' class="red">FILE</td>
+ <td id='textblur' class="red">TEXT</td>
+ <td id='textareablur' class="red">TEXTAREA</td>
+ <td id='boundBlur' class="red">DOCUMENT</td>
+ </tr>
+ <tr>
+ <td>Live Focus:</td>
+ <td id='selectlfocus' class="red">SELECT</td>
+ <td id='mselectlfocus' class="red">MULTI</td>
+ <td id='checkboxlfocus' class="red">CHECKBOX</td>
+ <td id='radiolfocus' class="red">RADIO</td>
+ <td id='filelfocus' class="red">FILE</td>
+ <td id='textlfocus' class="red">TEXT</td>
+ <td id='textarealfocus' class="red">TEXTAREA</td>
+ </tr>
+ <tr>
+ <td>Live Blur:</td>
+ <td id='selectlblur' class="red">SELECT</td>
+ <td id='mselectlblur' class="red">MULTI</td>
+ <td id='checkboxlblur' class="red">CHECKBOX</td>
+ <td id='radiolblur' class="red">RADIO</td>
+ <td id='filelblur' class="red">FILE</td>
+ <td id='textlblur' class="red">TEXT</td>
+ <td id='textarealblur' class="red">TEXTAREA</td>
+ </tr>
+ </table>
+ <h2>Submit Tests</h2>
+ <table>
+ <tr>
+ <td>
+ Submit each:
+ </td>
+ <td>
+ <form action="" id="text_submit">
+ <input class='test' type='text' value='Key Return To Submit'/>
+ </form>
+ </td>
+ <td>
+ <form action="" id="password_submit">
+ <input class='test' type='password' value=''/>
+ </form>
+ </td>
+ <td>
+ <form action="" id="submit_submit">
+ <input type='submit' value="Click Me To Submit" />
+ </form>
+ </td>
+ <td>$(document).bind('submit')</td>
+ </tr>
+ <tr>
+ <td>Results:</td>
+ <td id='textSubmit' class="red">TEXT</td>
+ <td id='passwordSubmit' class="red">PASSWORD</td>
+ <td id='submitSubmit' class="red">BUTTON</td>
+ <td id='boundSubmit' class="red">DOCUMENT</td>
+ </tr>
+ </table>
+
+ <ul id="log"></ul>
+
+ <script type='text/javascript'>
+ jQuery.fn.addChangeTest = function( id, prevent ) {
+ this.bind("focusin", function(){
+ jQuery(id + "focus").blink();
+ }).bind("focusout", function(){
+ jQuery(id + "blur").blink();
+ });
+
+ this.bind("focus", function(){
+ jQuery(id + "lfocus").blink();
+ }).bind("blur", function(){
+ jQuery(id + "lblur").blink();
+ });
+
+ return this.bind("change", function(e){
+ jQuery(id + "bind").blink();
+ }).live("change", function(e){
+ if ( prevent ) {
+ e.preventDefault();
+ }
+
+ jQuery(id).blink();
+ });
+ };
+
+ jQuery.fn.addSubmitTest = function( id, prevent ) {
+ return this.live("submit", function(e){
+ if ( prevent ) {
+ e.preventDefault();
+ }
+
+ jQuery(id).blink();
+ });
+ };
+
+ jQuery.fn.blink = function(){
+ return this.css("backgroundColor","green").css("border","solid 3px green").delay(700).queue(function(next){
+ jQuery(this).css("backgroundColor","");
+ next();
+ });
+ };
+
+ $(document).bind("focusin", function() {
+ jQuery("#boundFocus").blink();
+ });
+
+ $(document).bind("focusout", function() {
+ jQuery("#boundBlur").blink();
+ });
+
+ $("td.red").live("hover", function(e) {
+ if ( e.type === "mouseenter" ) {
+ $(this).css("backgroundColor","green");
+ } else {
+ $(this).css("backgroundColor","");
+ }
+ });
+
+ $(".select_test").addChangeTest("#select");
+ $(".mselect_test").addChangeTest("#mselect");
+ $(".checkbox_test").addChangeTest("#checkbox");
+ $(".radio_test").addChangeTest("#radio");
+ $(".file_test").addChangeTest("#file");
+ $('textarea').addChangeTest("#textarea");
+ $('#input').addChangeTest("#text");
+ $(document).bind("change", function(){
+ jQuery("#boundChange").blink();
+ });
+
+ $("#text_submit").addSubmitTest("#textSubmit", true);
+ $("#password_submit").addSubmitTest("#passwordSubmit", true);
+ $("#submit_submit").addSubmitTest("#submitSubmit", true);
+ $(document).bind("submit", function(){
+ jQuery("#boundSubmit").blink();
+ });
+
+ </script>
+ </body>
+</html>
<script src="../src/manipulation.js"></script>
<script src="../src/css.js"></script>
<script src="../src/ajax.js"></script>
+ <script src="../src/xhr.js"></script>
+ <script src="../src/transports/jsonp.js"></script>
+ <script src="../src/transports/script.js"></script>
+ <script src="../src/transports/xhr.js"></script>
<script src="../src/effects.js"></script>
<script src="../src/offset.js"></script>
<script src="../src/dimensions.js"></script>
<div id="slidetogglein" class='chain test'>slideToggleIn<div>slideToggleIn</div></div>
<div id="slidetoggleout" class='chain test out'>slideToggleOut<div>slideToggleOut</div></div>
-
+
<div id="fadetogglein" class='chain test'>fadeToggleIn<div>fadeToggleIn</div></div>
<div id="fadetoggleout" class='chain test out'>fadeToggleOut<div>fadeToggleOut</div></div>
});
});
+test("jQuery.ajax() - success callbacks - (url, options) syntax", function() {
+ expect( 8 );
+
+ jQuery.ajaxSetup({ timeout: 0 });
+
+ stop();
+
+ setTimeout(function(){
+ jQuery('#foo').ajaxStart(function(){
+ ok( true, "ajaxStart" );
+ }).ajaxStop(function(){
+ ok( true, "ajaxStop" );
+ start();
+ }).ajaxSend(function(){
+ ok( true, "ajaxSend" );
+ }).ajaxComplete(function(){
+ ok( true, "ajaxComplete" );
+ }).ajaxError(function(){
+ ok( false, "ajaxError" );
+ }).ajaxSuccess(function(){
+ ok( true, "ajaxSuccess" );
+ });
+
+ jQuery.ajax( url("data/name.html") , {
+ beforeSend: function(){ ok(true, "beforeSend"); },
+ success: function(){ ok(true, "success"); },
+ error: function(){ ok(false, "error"); },
+ complete: function(){ ok(true, "complete"); }
+ });
+ }, 13);
+});
+
+test("jQuery.ajax() - success/error callbacks (remote)", function() {
+
+ var supports = jQuery.support.cors;
+
+ expect( supports ? 9 : 6 );
+
+ jQuery.ajaxSetup({ timeout: 0 });
+
+ stop();
+
+ setTimeout(function(){
+ jQuery('#foo').ajaxStart(function(){
+ ok( true, "ajaxStart" );
+ }).ajaxStop(function(){
+ ok( true, "ajaxStop" );
+ start();
+ }).ajaxSend(function(){
+ ok( supports , "ajaxSend" );
+ }).ajaxComplete(function(){
+ ok( true, "ajaxComplete" );
+ }).ajaxError(function(){
+ ok( ! supports, "ajaxError" );
+ }).ajaxSuccess(function(){
+ ok( supports, "ajaxSuccess" );
+ });
+
+ jQuery.ajax({
+ // JULIAN TODO: Get an url especially for jQuery
+ url: "http://rockstarapps.com/test.php",
+ dataType: "text",
+ beforeSend: function(){ ok(supports, "beforeSend"); },
+ success: function( val ){ ok(supports, "success"); ok(supports && val.length, "data received"); },
+ error: function(_ , a , b ){ ok(!supports, "error"); },
+ complete: function(){ ok(true, "complete"); }
+ });
+ }, 13);
+});
+
+test("jQuery.ajax() - success callbacks (late binding)", function() {
+ expect( 8 );
+
+ jQuery.ajaxSetup({ timeout: 0 });
+
+ stop();
+
+ setTimeout(function(){
+ jQuery('#foo').ajaxStart(function(){
+ ok( true, "ajaxStart" );
+ }).ajaxStop(function(){
+ ok( true, "ajaxStop" );
+ start();
+ }).ajaxSend(function(){
+ ok( true, "ajaxSend" );
+ }).ajaxComplete(function(){
+ ok( true, "ajaxComplete" );
+ }).ajaxError(function(){
+ ok( false, "ajaxError" );
+ }).ajaxSuccess(function(){
+ ok( true, "ajaxSuccess" );
+ });
+
+ jQuery.ajax({
+ url: url("data/name.html"),
+ beforeSend: function(){ ok(true, "beforeSend"); }
+ })
+ .complete(function(){ ok(true, "complete"); })
+ .success(function(){ ok(true, "success"); })
+ .error(function(){ ok(false, "error"); });
+ }, 13);
+});
+
+test("jQuery.ajax() - success callbacks (oncomplete binding)", function() {
+ expect( 8 );
+
+ jQuery.ajaxSetup({ timeout: 0 });
+
+ stop();
+
+ setTimeout(function(){
+ jQuery('#foo').ajaxStart(function(){
+ ok( true, "ajaxStart" );
+ }).ajaxStop(function(){
+ ok( true, "ajaxStop" );
+ }).ajaxSend(function(){
+ ok( true, "ajaxSend" );
+ }).ajaxComplete(function(){
+ ok( true, "ajaxComplete" );
+ }).ajaxError(function(){
+ ok( false, "ajaxError" );
+ }).ajaxSuccess(function(){
+ ok( true, "ajaxSuccess" );
+ });
+
+ jQuery.ajax({
+ url: url("data/name.html"),
+ beforeSend: function(){ ok(true, "beforeSend"); },
+ complete: function(xhr) {
+ xhr
+ .complete(function(){ ok(true, "complete"); })
+ .success(function(){ ok(true, "success"); })
+ .error(function(){ ok(false, "error"); })
+ .complete(function(){ start(); });
+ }
+ })
+ }, 13);
+});
+
+test("jQuery.ajax() - success callbacks (very late binding)", function() {
+ expect( 8 );
+
+ jQuery.ajaxSetup({ timeout: 0 });
+
+ stop();
+
+ setTimeout(function(){
+ jQuery('#foo').ajaxStart(function(){
+ ok( true, "ajaxStart" );
+ }).ajaxStop(function(){
+ ok( true, "ajaxStop" );
+ }).ajaxSend(function(){
+ ok( true, "ajaxSend" );
+ }).ajaxComplete(function(){
+ ok( true, "ajaxComplete" );
+ }).ajaxError(function(){
+ ok( false, "ajaxError" );
+ }).ajaxSuccess(function(){
+ ok( true, "ajaxSuccess" );
+ });
+
+ jQuery.ajax({
+ url: url("data/name.html"),
+ beforeSend: function(){ ok(true, "beforeSend"); },
+ complete: function(xhr) {
+ setTimeout (function() {
+ xhr
+ .complete(function(){ ok(true, "complete"); })
+ .success(function(){ ok(true, "success"); })
+ .error(function(){ ok(false, "error"); })
+ .complete(function(){ start(); });
+ },100);
+ }
+ })
+ }, 13);
+});
+
+test("jQuery.ajax() - success callbacks (order)", function() {
+ expect( 1 );
+
+ jQuery.ajaxSetup({ timeout: 0 });
+
+ stop();
+
+ var testString = "";
+
+ setTimeout(function(){
+ jQuery.ajax({
+ url: url("data/name.html"),
+ success: function( _1 , _2 , xhr ) {
+ xhr.success(function() {
+ xhr.success(function() {
+ testString += "E";
+ });
+ testString += "D";
+ });
+ testString += "A";
+ },
+ complete: function() {
+ strictEqual(testString, "ABCDE", "Proper order");
+ start();
+ }
+ }).success(function() {
+ testString += "B";
+ }).success(function() {
+ testString += "C";
+ });
+ }, 13);
+});
+
test("jQuery.ajax() - error callbacks", function() {
expect( 8 );
stop();
});
});
+test(".ajax() - headers" , function() {
+
+ expect( 2 );
+
+ stop();
+
+ var requestHeaders = {
+ siMPle: "value",
+ "SometHing-elsE": "other value",
+ OthEr: "something else"
+ },
+ list = [],
+ i;
+
+ for( i in requestHeaders ) {
+ list.push( i );
+ }
+
+ jQuery.ajax(url("data/headers.php?keys="+list.join( "_" ) ), {
+ headers: requestHeaders,
+ success: function( data , _ , xhr ) {
+ var tmp = [];
+ for ( i in requestHeaders ) {
+ tmp.push( i , ": " , requestHeaders[ i ] , "\n" );
+ }
+ tmp = tmp.join( "" );
+
+ equals( data , tmp , "Headers were sent" );
+ equals( xhr.getResponseHeader( "Sample-Header" ) , "Hello World" , "Sample header received" );
+ start();
+ },
+ error: function(){ ok(false, "error"); }
+ });
+
+});
+
test(".ajax() - hash", function() {
expect(3);
-
+
jQuery.ajax({
url: "data/name.html#foo",
beforeSend: function( xhr, settings ) {
return false;
}
});
-
+
jQuery.ajax({
url: "data/name.html?abc#foo",
beforeSend: function( xhr, settings ) {
- equals(settings.url, "data/name.html?abc", "Make sure that the URL is trimmed.");
+ equals(settings.url, "data/name.html?abc", "Make sure that the URL is trimmed.");
return false;
}
});
-
+
jQuery.ajax({
url: "data/name.html?abc#foo",
data: { "test": 123 },
test(".ajax() - 304", function() {
expect( 1 );
stop();
-
+
jQuery.ajax({
url: url("data/notmodified.php"),
success: function(){ ok(true, "304 ok"); },
equals( xhr.readyState, 0, "XHR readyState indicates successful abortion" );
});
+test("jQuery.ajax() - readyState (success)", function() {
+ expect( 1 );
+
+ jQuery.ajaxSetup({ timeout: 0 });
+
+ stop();
+
+ var control = "";
+
+ setTimeout(function(){
+ jQuery.ajax({
+ url: url("data/name.html"),
+ beforeSend: function( xhr ) {
+ xhr.onreadystatechange = function() {
+ control += xhr.readyState;
+ }
+ },
+ complete: function(){
+ setTimeout( function() {
+ equals( control , "1234" , "onreadystatechange was properly called" );
+ }, 13 );
+ start();
+ }
+ });
+ }, 13);
+});
+
+test("jQuery.ajax() - readyState (abort)", function() {
+ expect( 2 );
+
+ jQuery.ajaxSetup({ timeout: 0 });
+
+ stop();
+
+ var control = "";
+
+ setTimeout(function(){
+
+ jQuery.ajaxSetup({ timeout: 500 });
+
+ jQuery.ajax({
+ url: url("data/name.php?wait=5"),
+ beforeSend: function( xhr ) {
+ xhr.onreadystatechange = function() {
+ control += xhr.readyState;
+ }
+ },
+ complete: function( xhr ){
+ setTimeout( function() {
+ equals( control , "14" , "onreadystatechange was properly called" );
+ equals( xhr.readyState, 0 , "readyState is 0" );
+ }, 13 );
+ start();
+ }
+ });
+ }, 13);
+});
+
+test("jQuery.xhr() - reuse", function() {
+ expect( 15 );
+
+ jQuery.ajaxSetup({ timeout: 0 });
+
+ stop();
+
+ var number = 0;
+
+ setTimeout(function(){
+ jQuery('#foo').ajaxStart(function(){
+ ok( true, "ajaxStart" );
+ }).ajaxStop(function(){
+ ok( true, "ajaxStop" );
+ start();
+ }).ajaxSend(function(){
+ number++;
+ ok( true, "ajaxSend (" + number +")" );
+ }).ajaxComplete(function(){
+ ok( true, "ajaxComplete (" + number +")" );
+ }).ajaxError(function(){
+ ok( false, "ajaxError (" + number +")" );
+ }).ajaxSuccess(function(){
+ ok( true, "ajaxSuccess (" + number +")" );
+ });
+
+ jQuery.ajax({
+ url: url("data/name.html"),
+ beforeSend: function(){ ok(true, "beforeSend (1)"); },
+ success: function( _1 , _2 , xhr ){
+ ok(true, "success (1)");
+ xhr.complete(function() {
+ ok(true, "complete (1bis)");
+ });
+ xhr.open( "GET", url("data/name.html") );
+ xhr.success( function(){ ok(true, "beforeSend (2)"); } )
+ xhr.send( null, {
+ success: function(){ ok(true, "success (2)"); },
+ error: function(){ ok(false, "error (2)"); },
+ complete: function(){ ok(true, "complete (2)"); }
+ } );
+ },
+ error: function(){ ok(false, "error (1)"); },
+ complete: function(){ ok(true, "complete (1)"); }
+ });
+ }, 13);
+});
+
+test("jQuery.xhr() - early binding", function() {
+ expect( 2 );
+
+ jQuery.ajaxSetup({ timeout: 0 });
+
+ stop();
+
+ jQuery.xhr()
+ .success( function(){ ok(true, "success"); } )
+ .error( function(){ ok(false, "error"); } )
+ .complete( function(){ ok(true, "complete"); start(); } )
+ .open( "GET", url("data/name.html") )
+ .send();
+});
+
+test("jQuery.xhr() - get native implementation", function() {
+
+ var xhr = jQuery.xhr(true);
+
+ ok( xhr.readyState !== undefined , "implements XMLHttpRequest" );
+ ok( ! jQuery.isFunction( xhr.success ) , "is not jQuery's abstraction" );
+
+});
+
test("Ajax events with context", function() {
expect(14);
});
});
+test("jQuery.xhr() - disabled globals through xhr.send(data , false)", function() {
+ expect( 2 );
+ stop();
+
+ jQuery('#foo').ajaxStart(function(){
+ ok( false, "ajaxStart" );
+ }).ajaxStop(function(){
+ ok( false, "ajaxStop" );
+ }).ajaxSend(function(){
+ ok( false, "ajaxSend" );
+ }).ajaxComplete(function(){
+ ok( false, "ajaxComplete" );
+ }).ajaxError(function(){
+ ok( false, "ajaxError" );
+ }).ajaxSuccess(function(){
+ ok( false, "ajaxSuccess" );
+ });
+
+ jQuery.xhr()
+ .success(function(){ ok(true, "success"); })
+ .error(function(){ ok(false, "error"); })
+ .complete(function(){
+ ok(true, "complete");
+ setTimeout(function(){ start(); }, 13);
+ })
+ .open("GET", url("data/name.html")).send(undefined, false);
+});
+
test("jQuery.ajax - xml: non-namespace elements inside namespaced elements", function() {
expect(3);
stop();
});
});
+test("jQuery.ajax - xml: non-namespace elements inside namespaced elements (over JSONP)", function() {
+ expect(3);
+ stop();
+ jQuery.ajax({
+ url: url("data/with_fries_over_jsonp.php"),
+ dataType: "jsonp xml",
+ success: function(resp) {
+ equals( jQuery("properties", resp).length, 1, 'properties in responseXML' );
+ equals( jQuery("jsconf", resp).length, 1, 'jsconf in responseXML' );
+ equals( jQuery("thing", resp).length, 2, 'things in responseXML' );
+ start();
+ }
+ });
+});
+
test("jQuery.ajax - HEAD requests", function() {
expect(2);
});
}
});
-
+
});
test("jQuery.ajax - beforeSend", function() {
ok( request === false, "canceled request must return false instead of XMLHttpRequest instance" );
});
+test("jQuery.ajax - beforeSend, cancel request manually", function() {
+ expect(2);
+ var request = jQuery.ajax({
+ url: url("data/name.html"),
+ beforeSend: function(xhr) {
+ ok( true, "beforeSend got called, canceling" );
+ xhr.abort();
+ },
+ success: function() {
+ ok( false, "request didn't get canceled" );
+ },
+ complete: function() {
+ ok( false, "request didn't get canceled" );
+ },
+ error: function() {
+ ok( false, "request didn't get canceled" );
+ }
+ });
+ ok( request === false, "canceled request must return false instead of XMLHttpRequest instance" );
+});
+
window.foobar = null;
window.testFoo = undefined;
equals( jQuery.param({"foo": {"bar": []} }), "foo%5Bbar%5D=", "Empty array param" );
equals( jQuery.param({"foo": {"bar": [], foo: 1} }), "foo%5Bbar%5D=&foo%5Bfoo%5D=1", "Empty array param" );
equals( jQuery.param({"foo": {"bar": {}} }), "foo%5Bbar%5D=", "Empty object param" );
-
+
jQuery.ajaxSetup({ traditional: true });
var params = {foo:"bar", baz:42, quux:"All your base are belong to us"};
});
test("jQuery.ajax() - JSONP, Local", function() {
- expect(8);
+ expect(9);
var count = 0;
- function plus(){ if ( ++count == 8 ) start(); }
+ function plus(){ if ( ++count == 9 ) start(); }
stop();
plus();
}
});
+
+ //#7578
+ jQuery.ajax({
+ url: "data/jsonp.php",
+ dataType: "jsonp",
+ beforeSend: function(){
+ strictEqual( this.cache, false, "cache must be false on JSON request" );
+ plus();
+ return false;
+ }
+ });
});
-test("JSONP - Custom JSONP Callback", function() {
+test("jQuery.ajax() - JSONP - Custom JSONP Callback", function() {
expect(1);
stop();
window.jsonpResults = function(data) {
ok( data.data, "JSON results returned (GET, custom callback function)" );
+ window.jsonpResults = undefined;
start();
};
expect(3);
var base = window.location.href.replace(/[^\/]*$/, "");
-
+
stop();
jQuery.ajax({
});
});
+test("jQuery.ajax() - json by content-type disabled with options", function() {
+ expect(6);
+
+ stop();
+
+ jQuery.ajax({
+ url: url("data/json.php"),
+ data: { header: "json", json: "array" },
+ autoDataType: {
+ json: false
+ },
+ success: function( text ) {
+ equals( typeof text , "string" , "json wasn't auto-determined" );
+ var json = this.dataConverters["text => json"]( text );
+ ok( json.length >= 2, "Check length");
+ equals( json[0].name, 'John', 'Check JSON: first, name' );
+ equals( json[0].age, 21, 'Check JSON: first, age' );
+ equals( json[1].name, 'Peter', 'Check JSON: second, name' );
+ equals( json[1].age, 25, 'Check JSON: second, age' );
+ start();
+ }
+ });
+});
+
test("jQuery.getJSON(String, Hash, Function) - JSON array", function() {
expect(5);
stop();
ok(data == null, "response body should be empty")
}
start();
- },
+ },
error: function() {
// Do this because opera simply refuses to implement 304 handling :(
// A feature-driven way of detecting this would be appreciated
ok(jQuery.browser.opera, "error");
ok(jQuery.browser.opera, "error");
start();
- }
+ }
});
},
error: function() {
+ equals(false, "error");
// Do this because opera simply refuses to implement 304 handling :(
// A feature-driven way of detecting this would be appreciated
// See: http://gist.github.com/599419
ok(data == null, "response body should be empty")
}
start();
- },
- error: function() {
+ },
+ error: function() {
// Do this because opera simply refuses to implement 304 handling :(
// A feature-driven way of detecting this would be appreciated
// See: http://gist.github.com/599419
});
});
+test("jQuery ajax - failing cross-domain", function() {
+
+ expect( 2 );
+
+ stop();
+
+ var i = 2;
+
+ jQuery.ajax({
+ url: 'http://somewebsitethatdoesnotexist.com',
+ success: function(){ ok( false , "success" ); },
+ error: function(xhr,_,e){ ok( true , "file not found: " + xhr.status + " => " + e ); },
+ complete: function() { if ( ! --i ) start(); }
+ });
+
+ jQuery.ajax({
+ url: 'http://www.google.com',
+ success: function(){ ok( false , "success" ); },
+ error: function(xhr,_,e){ ok( true , "access denied: " + xhr.status + " => " + e ); },
+ complete: function() { if ( ! --i ) start(); }
+ });
+
+});
+
+test("jQuery ajax - atom+xml", function() {
+
+ stop();
+
+ jQuery.ajax({
+ url: url( 'data/atom+xml.php' ),
+ success: function(){ ok( true , "success" ); },
+ error: function(){ ok( false , "error" ); },
+ complete: function() { start(); }
+ });
+
+});
+
test("jQuery.ajax - active counter", function() {
ok( jQuery.active == 0, "ajax active counter should be zero: " + jQuery.active );
});
+test( "jQuery.ajax - Location object as url (#7531)", 1, function () {
+ var success = false;
+ try {
+ var xhr = jQuery.ajax({ url: window.location });
+ success = true;
+ xhr.abort();
+ } catch (e) {}
+
+ ok( success, "document.location did not generate exception" );
+});
}
-//}
+//}
\ No newline at end of file
var bareObj = function(value) { return value; };
var functionReturningObj = function(value) { return (function() { return value; }); };
+test("jQuery.props: itegrity test", function() {
+
+ expect(1);
+
+ // This must be maintained and equal jQuery.props
+ // Ensure that accidental or erroneous property
+ // overwrites don't occur
+ // This is simply for better code coverage and future proofing.
+ var propsShouldBe = {
+ "for": "htmlFor",
+ "class": "className",
+ readonly: "readOnly",
+ maxlength: "maxLength",
+ cellspacing: "cellSpacing",
+ rowspan: "rowSpan",
+ colspan: "colSpan",
+ tabindex: "tabIndex",
+ usemap: "useMap",
+ frameborder: "frameBorder"
+ };
+
+ same(propsShouldBe, jQuery.props, "jQuery.props passes integrity check");
+
+});
+
test("attr(String)", function() {
- expect(31);
+ expect(37);
// This one sometimes fails randomly ?!
equals( jQuery('#text1').attr('value'), "Test", 'Check for value attribute' );
ok( jQuery().attr("doesntexist") === undefined, "Make sure undefined is returned when no element is there." );
equals( jQuery(document).attr("nodeName"), "#document", "attr works correctly on document nodes (bug #7451)." );
+
+ var attributeNode = document.createAttribute("irrelevant"),
+ commentNode = document.createComment("some comment"),
+ textNode = document.createTextNode("some text"),
+ obj = {};
+ jQuery.each( [document, attributeNode, commentNode, textNode, obj, "#firstp"], function( i, ele ) {
+ strictEqual( jQuery(ele).attr("nonexisting"), undefined, "attr works correctly for non existing attributes (bug #7500)." );
+ });
});
if ( !isLocal ) {
});
test("attr(String, Object)", function() {
- expect(24);
+ expect(30);
var div = jQuery("div").attr("foo", "bar"),
fail = false;
jQuery("#name").attr('maxLength', '10');
equals( document.getElementById('name').maxLength, '10', 'Set maxlength attribute' );
+ var attributeNode = document.createAttribute("irrelevant"),
+ commentNode = document.createComment("some comment"),
+ textNode = document.createTextNode("some text"),
+ obj = {};
+ jQuery.each( [document, obj, "#firstp"], function( i, ele ) {
+ var $ele = jQuery( ele );
+ $ele.attr( "nonexisting", "foo" );
+ equal( $ele.attr("nonexisting"), "foo", "attr(name, value) works correctly for non existing attributes (bug #7500)." );
+ });
+ jQuery.each( [commentNode, textNode, attributeNode], function( i, ele ) {
+ var $ele = jQuery( ele );
+ $ele.attr( "nonexisting", "foo" );
+ strictEqual( $ele.attr("nonexisting"), undefined, "attr(name, value) works correctly on comment and text nodes (bug #7500)." );
+ });
+ //cleanup
+ jQuery.each( [document, "#firstp"], function( i, ele ) {
+ jQuery( ele ).removeAttr("nonexisting");
+ });
+
var table = jQuery('#table').append("<tr><td>cell</td></tr><tr><td>cell</td><td>cell</td></tr><tr><td>cell</td><td>cell</td></tr>"),
td = table.find('td:first');
td.attr("rowspan", "2");
});
test("removeAttr(String)", function() {
- expect(1);
+ expect(7);
equals( jQuery('#mark').removeAttr( "class" )[0].className, "", "remove class" );
+
+ var attributeNode = document.createAttribute("irrelevant"),
+ commentNode = document.createComment("some comment"),
+ textNode = document.createTextNode("some text"),
+ obj = {};
+ //removeAttr only really removes on DOM element nodes handle all other seperatyl
+ strictEqual( jQuery( "#firstp" ).attr( "nonexisting", "foo" ).removeAttr( "nonexisting" )[0].nonexisting, undefined, "removeAttr works correctly on DOM element nodes" );
+
+ jQuery.each( [document, obj], function( i, ele ) {
+ var $ele = jQuery( ele );
+ $ele.attr( "nonexisting", "foo" ).removeAttr( "nonexisting" );
+ strictEqual( ele.nonexisting, "", "removeAttr works correctly on non DOM element nodes (bug #7500)." );
+ });
+ jQuery.each( [commentNode, textNode, attributeNode], function( i, ele ) {
+ $ele = jQuery( ele );
+ $ele.attr( "nonexisting", "foo" ).removeAttr( "nonexisting" );
+ strictEqual( ele.nonexisting, undefined, "removeAttr works correctly on non DOM element nodes (bug #7500)." );
+ });
});
test("val()", function() {
});
test("addClass, removeClass, hasClass", function() {
- expect(14);
+ expect(17);
var jq = jQuery("<p>Hi</p>"), x = jq[0];
ok( jq.hasClass("hi"), "Check has1" );
ok( jq.hasClass("bar"), "Check has2" );
- var jq = jQuery("<p class='class1\nclass2\tcla.ss3\n'></p>");
- ok( jq.hasClass("class1"), "Check hasClass with carriage return" );
- ok( jq.is(".class1"), "Check is with carriage return" );
+ var jq = jQuery("<p class='class1\nclass2\tcla.ss3\n\rclass4'></p>");
+ ok( jq.hasClass("class1"), "Check hasClass with line feed" );
+ ok( jq.is(".class1"), "Check is with line feed" );
ok( jq.hasClass("class2"), "Check hasClass with tab" );
ok( jq.is(".class2"), "Check is with tab" );
ok( jq.hasClass("cla.ss3"), "Check hasClass with dot" );
+ ok( jq.hasClass("class4"), "Check hasClass with carriage return" );
+ ok( jq.is(".class4"), "Check is with carriage return" );
jq.removeClass("class2");
ok( jq.hasClass("class2")==false, "Check the class has been properly removed" );
ok( jq.hasClass("cla.ss3"), "Check the dotted class has not been removed" );
jq.removeClass("cla.ss3");
ok( jq.hasClass("cla.ss3")==false, "Check the dotted class has been removed" );
+ jq.removeClass("class4");
+ ok( jq.hasClass("class4")==false, "Check the class has been properly removed" );
});
})
test("get(Number)", function() {
- expect(1);
+ expect(2);
equals( jQuery("p").get(0), document.getElementById("firstp"), "Get A Single Element" );
+ strictEqual( jQuery("#firstp").get(1), undefined, "Try get with index larger elements count" );
});
test("get(-Number)",function() {
- expect(1);
- equals( jQuery("p").get(-1),
- document.getElementById("first"),
- "Get a single element with negative index" )
+ expect(2);
+ equals( jQuery("p").get(-1), document.getElementById("first"), "Get a single element with negative index" );
+ strictEqual( jQuery("#firstp").get(-2), undefined, "Try get with index negative index larger then elements count" );
})
test("each(Function)", function() {
var div = jQuery( "<div>" );
- equals( div.css("width"), "auto", "Width on disconnected node." );
- equals( div.css("height"), "auto", "Height on disconnected node." );
+ // These should be "auto" (or some better value)
+ // temporarily provide "0px" for backwards compat
+ equals( div.css("width"), "0px", "Width on disconnected node." );
+ equals( div.css("height"), "0px", "Height on disconnected node." );
div.css({ width: 4, height: 4 });
});
test(".data()", function() {
- expect(4);
+ expect(5);
var div = jQuery("#foo");
strictEqual( div.data("foo"), undefined, "Make sure that missing result is undefined" );
var nodiv = jQuery("#unfound");
equals( nodiv.data(), null, "data() on empty set returns null" );
+
+ var obj = { foo: "bar" };
+ equals( jQuery(obj).data(), obj, "Retrieve data object from a wrapped JS object (#7524)" );
})
test(".data(String) and .data(String, Object)", function() {
});
test("innerWidth()", function() {
- expect(3);
+ expect(4);
var $div = jQuery("#nothiddendiv");
// set styles
// reset styles
$div.css({ display: "", border: "", padding: "", width: "", height: "" });
+
+ var div = jQuery( "<div>" );
+
+ // Temporarily require 0 for backwards compat - should be auto
+ equals( div.innerWidth(), 0, "Make sure that disconnected nodes are handled." );
});
test("innerHeight()", function() {
- expect(3);
+ expect(4);
var $div = jQuery("#nothiddendiv");
// set styles
// reset styles
$div.css({ display: "", border: "", padding: "", width: "", height: "" });
+
+ var div = jQuery( "<div>" );
+
+ // Temporarily require 0 for backwards compat - should be auto
+ equals( div.innerHeight(), 0, "Make sure that disconnected nodes are handled." );
});
test("outerWidth()", function() {
- expect(6);
+ expect(7);
var $div = jQuery("#nothiddendiv");
$div.css("width", 30);
// reset styles
$div.css({ position: "", display: "", border: "", padding: "", width: "", height: "" });
+
+ var div = jQuery( "<div>" );
+
+ // Temporarily require 0 for backwards compat - should be auto
+ equals( div.outerWidth(), 0, "Make sure that disconnected nodes are handled." );
});
test("outerHeight()", function() {
- expect(6);
+ expect(7);
var $div = jQuery("#nothiddendiv");
$div.css("height", 30);
// reset styles
$div.css({ display: "", border: "", padding: "", width: "", height: "" });
+
+ var div = jQuery( "<div>" );
+
+ // Temporarily require 0 for backwards compat - should be auto
+ equals( div.outerHeight(), 0, "Make sure that disconnected nodes are handled." );
});
});
test("bind()/trigger()/unbind() on plain object", function() {
- expect( 7 );
+ expect( 8 );
var obj = {};
// Make sure it doesn't complain when no events are found
jQuery(obj).unbind("test");
- jQuery(obj).bind("test", function(){
- ok( true, "Custom event run." );
+ jQuery(obj).bind({
+ test: function() {
+ ok( true, "Custom event run." );
+ },
+ submit: function() {
+ ok( true, "Custom submit event run." );
+ }
});
var events = jQuery(obj).data("__events__");
// Should trigger 1
jQuery(obj).trigger("test");
+ jQuery(obj).trigger("submit");
jQuery(obj).unbind("test");
+ jQuery(obj).unbind("submit");
// Should trigger 0
jQuery(obj).trigger("test");
test("text(Function) with incoming value", function() {
expect(2);
-
+
var old = "This link has class=\"blog\": Simon Willison's Weblog";
-
+
jQuery('#sap').text(function(i, val) {
equals( val, old, "Make sure the incoming value is correct." );
return "foobar";
});
-
+
equals( jQuery("#sap").text(), "foobar", 'Check for merged text of more then one element.' );
-
+
QUnit.reset();
});
ok( jQuery("#sap").append(valueObj( [] )), "Check for appending an empty array." );
ok( jQuery("#sap").append(valueObj( "" )), "Check for appending an empty string." );
ok( jQuery("#sap").append(valueObj( document.getElementsByTagName("foo") )), "Check for appending an empty nodelist." );
-
+
QUnit.reset();
jQuery("form").append(valueObj('<input name="radiotest" type="radio" checked="checked" />'));
jQuery("form input[name=radiotest]").each(function(){
test("append(Function) with incoming value", function() {
expect(12);
-
+
var defaultText = 'Try them out:', old = jQuery("#first").html();
-
+
var result = jQuery('#first').append(function(i, val){
equals( val, old, "Make sure the incoming value is correct." );
return '<b>buga</b>';
});
equals( result.text(), defaultText + 'buga', 'Check if text appending works' );
-
+
var select = jQuery('#select3');
old = select.html();
-
+
equals( select.append(function(i, val){
equals( val, old, "Make sure the incoming value is correct." );
return '<option value="appendTest">Append Test</option>';
QUnit.reset();
var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
old = jQuery("#sap").html();
-
+
jQuery('#sap').append(function(i, val){
equals( val, old, "Make sure the incoming value is correct." );
return document.getElementById('first');
QUnit.reset();
expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
old = jQuery("#sap").html();
-
+
jQuery('#sap').append(function(i, val){
equals( val, old, "Make sure the incoming value is correct." );
return [document.getElementById('first'), document.getElementById('yahoo')];
QUnit.reset();
expected = "This link has class=\"blog\": Simon Willison's WeblogYahooTry them out:";
old = jQuery("#sap").html();
-
+
jQuery('#sap').append(function(i, val){
equals( val, old, "Make sure the incoming value is correct." );
return jQuery("#yahoo, #first");
QUnit.reset();
old = jQuery("#sap").html();
-
+
jQuery("#sap").append(function(i, val){
equals( val, old, "Make sure the incoming value is correct." );
return 5;
});
- ok( jQuery("#sap")[0].innerHTML.match( /5$/ ), "Check for appending a number" );
-
+ ok( jQuery("#sap")[0].innerHTML.match( /5$/ ), "Check for appending a number" );
+
QUnit.reset();
});
+test("append the same fragment with events (Bug #6997, 5566)", function () {
+ expect(4 + (document.fireEvent ? 1 : 0));
+ stop(1000);
+
+ var element;
+
+ // This patch modified the way that cloning occurs in IE; we need to make sure that
+ // native event handlers on the original object don't get disturbed when they are
+ // modified on the clone
+ if (!jQuery.support.noCloneEvent && document.fireEvent) {
+ element = jQuery("div:first").click(function () {
+ ok(true, "Event exists on original after being unbound on clone");
+ jQuery(this).unbind('click');
+ });
+ element.clone(true).unbind('click')[0].fireEvent('onclick');
+ element[0].fireEvent('onclick');
+ }
+
+ element = jQuery("<a class='test6997'></a>").click(function () {
+ ok(true, "Append second element events work");
+ });
+
+ jQuery("#listWithTabIndex li").append(element)
+ .find('a.test6997').eq(1).click();
+
+ element = jQuery("<li class='test6997'></li>").click(function () {
+ ok(true, "Before second element events work");
+ start();
+ });
+
+ jQuery("#listWithTabIndex li").before(element);
+ jQuery("#listWithTabIndex li.test6997").eq(1).click();
+
+ element = jQuery("<select><option>Foo</option><option selected>Bar</option></select>");
+
+ equals( element.clone().find("option:selected").val(), element.find("option:selected").val(), "Selected option cloned correctly" );
+
+ element = jQuery("<input type='checkbox'>").attr('checked', 'checked');
+
+ equals( element.clone().is(":checked"), element.is(":checked"), "Checked input cloned correctly" );
+});
+
test("appendTo(String|Element|Array<Element>|jQuery)", function() {
expect(16);
test("prepend(Function) with incoming value", function() {
expect(10);
-
+
var defaultText = 'Try them out:', old = jQuery('#first').html();
var result = jQuery('#first').prepend(function(i, val) {
equals( val, old, "Make sure the incoming value is correct." );
return '<b>buga</b>';
});
equals( result.text(), 'buga' + defaultText, 'Check if text prepending works' );
-
+
old = jQuery("#select3").html();
-
+
equals( jQuery('#select3').prepend(function(i, val) {
equals( val, old, "Make sure the incoming value is correct." );
return '<option value="prependTest">Prepend Test</option>';
QUnit.reset();
var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
old = jQuery('#sap').html();
-
+
jQuery('#sap').prepend(function(i, val) {
equals( val, old, "Make sure the incoming value is correct." );
return document.getElementById('first');
});
-
+
equals( jQuery('#sap').text(), expected, "Check for prepending of element" );
QUnit.reset();
expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
old = jQuery('#sap').html();
-
+
jQuery('#sap').prepend(function(i, val) {
equals( val, old, "Make sure the incoming value is correct." );
return [document.getElementById('first'), document.getElementById('yahoo')];
});
-
+
equals( jQuery('#sap').text(), expected, "Check for prepending of array of elements" );
QUnit.reset();
expected = "YahooTry them out:This link has class=\"blog\": Simon Willison's Weblog";
old = jQuery('#sap').html();
-
+
jQuery('#sap').prepend(function(i, val) {
equals( val, old, "Make sure the incoming value is correct." );
return jQuery("#yahoo, #first");
});
-
- equals( jQuery('#sap').text(), expected, "Check for prepending of jQuery object" );
+
+ equals( jQuery('#sap').text(), expected, "Check for prepending of jQuery object" );
});
test("prependTo(String|Element|Array<Element>|jQuery)", function() {
});
test("clone()", function() {
- expect(31);
+ expect(36);
equals( 'This is a normal link: Yahoo', jQuery('#en').text(), 'Assert text for #en' );
var clone = jQuery('#yahoo').clone();
equals( 'Try them out:Yahoo', jQuery('#first').append(clone).text(), 'Check for clone' );
];
for (var i = 0; i < cloneTags.length; i++) {
var j = jQuery(cloneTags[i]);
- equals( j[0].tagName, j.clone()[0].tagName, 'Clone a <' + cloneTags[i].substring(1));
+ equals( j[0].tagName, j.clone()[0].tagName, 'Clone a ' + cloneTags[i]);
}
// using contents will get comments regular, text, and comment nodes
equals( div[0].nodeName.toUpperCase(), "DIV", "DIV element cloned" );
div.find("table:last").trigger("click");
- div = jQuery("<div/>").html('<object height="355" width="425"> <param name="movie" value="http://www.youtube.com/v/JikaHBDoV3k&hl=en"> <param name="wmode" value="transparent"> </object>');
+ // this is technically an invalid object, but because of the special
+ // classid instantiation it is the only kind that IE has trouble with,
+ // so let's test with it too.
+ div = jQuery("<div/>").html('<object height="355" width="425" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"> <param name="movie" value="http://www.youtube.com/v/3KANI2dpXLw&hl=en"> <param name="wmode" value="transparent"> </object>');
- div = div.clone(true);
- equals( div.length, 1, "One element cloned" );
- equals( div[0].nodeName.toUpperCase(), "DIV", "DIV element cloned" );
+ clone = div.clone(true);
+ equals( clone.length, 1, "One element cloned" );
+ equals( clone.html(), div.html(), "Element contents cloned" );
+ equals( clone[0].nodeName.toUpperCase(), "DIV", "DIV element cloned" );
+
+ // and here's a valid one.
+ div = jQuery("<div/>").html('<object height="355" width="425" type="application/x-shockwave-flash" data="http://www.youtube.com/v/3KANI2dpXLw&hl=en"> <param name="movie" value="http://www.youtube.com/v/3KANI2dpXLw&hl=en"> <param name="wmode" value="transparent"> </object>');
+
+ clone = div.clone(true);
+ equals( clone.length, 1, "One element cloned" );
+ equals( clone.html(), div.html(), "Element contents cloned" );
+ equals( clone[0].nodeName.toUpperCase(), "DIV", "DIV element cloned" );
div = jQuery("<div/>").data({ a: true, b: true });
div = div.clone(true);
form.appendChild( div );
equals( jQuery(form).clone().children().length, 1, "Make sure we just get the form back." );
+
+ equal( jQuery("body").clone().children()[0].id, "qunit-header", "Make sure cloning body works" );
});
if (!isLocal) {
test("html(Function) with incoming value", function() {
expect(20);
-
+
var div = jQuery("#main > div"), old = div.map(function(){ return jQuery(this).html() });
-
+
div.html(function(i, val) {
equals( val, old[i], "Make sure the incoming value is correct." );
return "<b>test</b>";
});
-
+
var pass = true;
div.each(function(){
if ( this.childNodes.length !== 1 ) {
// using contents will get comments regular, text, and comment nodes
var j = jQuery("#nonnodes").contents();
old = j.map(function(){ return jQuery(this).html(); });
-
+
j.html(function(i, val) {
equals( val, old[i], "Make sure the incoming value is correct." );
return "<b>bold</b>";
if ( j.length === 2 ) {
equals( null, null, "Make sure the incoming value is correct." );
}
-
+
j.find('b').removeData();
equals( j.html().replace(/ xmlns="[^"]+"/g, "").toLowerCase(), "<b>bold</b>", "Check node,textnode,comment with html()" );
-
+
var $div = jQuery('<div />');
-
+
equals( $div.html(function(i, val) {
equals( val, "", "Make sure the incoming value is correct." );
return 5;
}).html(), '5', 'Setting a number as html' );
-
+
equals( $div.html(function(i, val) {
equals( val, "5", "Make sure the incoming value is correct." );
return 0;
equals( val, "", "Make sure the incoming value is correct." );
return insert;
}).html().replace(/>/g, ">"), insert, "Verify escaped insertion." );
-
+
equals( $div2.html(function(i, val) {
equals( val.replace(/>/g, ">"), insert, "Make sure the incoming value is correct." );
return "x" + insert;
}).html().replace(/>/g, ">"), "x" + insert, "Verify escaped insertion." );
-
+
equals( $div2.html(function(i, val) {
equals( val.replace(/>/g, ">"), "x" + insert, "Make sure the incoming value is correct." );
return " " + insert;
- }).html().replace(/>/g, ">"), " " + insert, "Verify escaped insertion." );
+ }).html().replace(/>/g, ">"), " " + insert, "Verify escaped insertion." );
});
var testRemove = function(method) {
var count = 0;
var first = jQuery("#ap").children(":first");
var cleanUp = first.click(function() { count++ })[method]().appendTo("body").click();
-
+
equals( method == "remove" ? 0 : 1, count );
-
+
cleanUp.detach();
};
test("jQuery.cleanData", function() {
expect(14);
-
+
var type, pos, div, child;
-
+
type = "remove";
-
+
// Should trigger 4 remove event
div = getDiv().remove();
-
+
// Should both do nothing
pos = "Outer";
div.trigger("click");
-
+
pos = "Inner";
div.children().trigger("click");
-
+
type = "empty";
div = getDiv();
child = div.children();
-
+
// Should trigger 2 remove event
div.empty();
-
+
// Should trigger 1
pos = "Outer";
div.trigger("click");
-
+
// Should do nothing
pos = "Inner";
child.trigger("click");
// Should trigger 2
div.remove();
-
+
type = "html";
-
+
div = getDiv();
child = div.children();
-
+
// Should trigger 2 remove event
div.html("<div></div>");
-
+
// Should trigger 1
pos = "Outer";
div.trigger("click");
-
+
// Should do nothing
pos = "Inner";
child.trigger("click");
// Should trigger 2
div.remove();
-
+
function getDiv() {
var div = jQuery("<div class='outer'><div class='inner'></div></div>").click(function(){
ok( true, type + " " + pos + " Click event fired." );
}).focus(function(){
ok( false, type + " " + pos + " Focus event fired." );
}).end().appendTo("body");
-
+
div[0].detachEvent = div[0].removeEventListener = function(t){
ok( true, type + " Outer " + t + " event unbound" );
};
-
+
div[0].firstChild.detachEvent = div[0].firstChild.removeEventListener = function(t){
ok( true, type + " Inner " + t + " event unbound" );
};
-
+
return div;
}
});
-1.4.4pre
\ No newline at end of file
+1.4.5pre
\ No newline at end of file