Commit 610ab137 authored by scottjehl's avatar scottjehl

Merge branch 'master' of https://github.com/jquery/jquery

parents 18fa1fd9 a8fa5f2e
Copyright (c) 2010 John Resig, http://jquery.com/ Copyright (c) 2011 John Resig, http://jquery.com/
Permission is hereby granted, free of charge, to any person obtaining Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the a copy of this software and associated documentation files (the
......
...@@ -24,10 +24,9 @@ BASE_FILES = ${SRC_DIR}/core.js\ ...@@ -24,10 +24,9 @@ BASE_FILES = ${SRC_DIR}/core.js\
${SRC_DIR}/manipulation.js\ ${SRC_DIR}/manipulation.js\
${SRC_DIR}/css.js\ ${SRC_DIR}/css.js\
${SRC_DIR}/ajax.js\ ${SRC_DIR}/ajax.js\
${SRC_DIR}/xhr.js\ ${SRC_DIR}/ajax/jsonp.js\
${SRC_DIR}/transports/jsonp.js\ ${SRC_DIR}/ajax/script.js\
${SRC_DIR}/transports/script.js\ ${SRC_DIR}/ajax/xhr.js\
${SRC_DIR}/transports/xhr.js\
${SRC_DIR}/effects.js\ ${SRC_DIR}/effects.js\
${SRC_DIR}/offset.js\ ${SRC_DIR}/offset.js\
${SRC_DIR}/dimensions.js ${SRC_DIR}/dimensions.js
...@@ -79,13 +78,13 @@ init: ...@@ -79,13 +78,13 @@ init:
jquery: ${JQ} jquery: ${JQ}
jq: ${JQ} jq: ${JQ}
${JQ}: ${MODULES} ${DIST_DIR} ${JQ}: ${MODULES} | ${DIST_DIR}
@@echo "Building" ${JQ} @@echo "Building" ${JQ}
@@cat ${MODULES} | \ @@cat ${MODULES} | \
sed 's/.function..jQuery...{//' | \ sed 's/.function..jQuery...{//' | \
sed 's/}...jQuery..;//' | \ sed 's/}...jQuery..;//' | \
sed 's/Date:./&'"${DATE}"'/' | \ sed 's/@DATE/'"${DATE}"'/' | \
${VER} > ${JQ}; ${VER} > ${JQ};
${SRC_DIR}/selector.js: ${SIZZLE_DIR}/sizzle.js ${SRC_DIR}/selector.js: ${SIZZLE_DIR}/sizzle.js
......
...@@ -9,7 +9,27 @@ test_dir = File.join( prefix, 'test' ) ...@@ -9,7 +9,27 @@ test_dir = File.join( prefix, 'test' )
# setting DIST_DIR before calling rake # setting DIST_DIR before calling rake
dist_dir = ENV['DIST_DIR'] || File.join( prefix, 'dist' ) dist_dir = ENV['DIST_DIR'] || File.join( prefix, 'dist' )
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" ) } base_files = %w{
intro
core
support
data
queue
attributes
event
selector
traversing
manipulation
css
ajax
ajax/jsonp
ajax/script
ajax/xhr
effects
offset
dimensions
outro
}.map { |js| File.join( src_dir, "#{js}.js" ) }
# Sizzle, QUnit and jQuery files/dirs # Sizzle, QUnit and jQuery files/dirs
sizzle_dir = File.join( src_dir, "sizzle" ) sizzle_dir = File.join( src_dir, "sizzle" )
...@@ -31,7 +51,7 @@ rhino = "java -jar #{build_dir}/js.jar" ...@@ -31,7 +51,7 @@ rhino = "java -jar #{build_dir}/js.jar"
minfier = "java -jar #{build_dir}/google-compiler-20100917.jar" minfier = "java -jar #{build_dir}/google-compiler-20100917.jar"
# Turn off output other than needed from `sh` and file commands # Turn off output other than needed from `sh` and file commands
verbose(false) verbose(false)
# Tasks # Tasks
task :default => "all" task :default => "all"
...@@ -51,7 +71,7 @@ task :min => jq_min ...@@ -51,7 +71,7 @@ task :min => jq_min
task :init => [sizzle, qunit] do task :init => [sizzle, qunit] do
sizzle_git = File.join(sizzle_dir, '.git') sizzle_git = File.join(sizzle_dir, '.git')
qunit_git = File.join(qunit_dir, '.git') qunit_git = File.join(qunit_dir, '.git')
puts "Updating SizzleJS with latest..." puts "Updating SizzleJS with latest..."
sh "git --git-dir=#{sizzle_git} pull -q origin master" sh "git --git-dir=#{sizzle_git} pull -q origin master"
...@@ -61,7 +81,7 @@ end ...@@ -61,7 +81,7 @@ end
desc "Removes dist folder, selector.js, and Sizzle/QUnit" desc "Removes dist folder, selector.js, and Sizzle/QUnit"
task :clean do task :clean do
puts "Removing Distribution directory: #{dist_dir}..." puts "Removing Distribution directory: #{dist_dir}..."
rm_rf dist_dir rm_rf dist_dir
puts "Removing built copy of Sizzle..." puts "Removing built copy of Sizzle..."
...@@ -87,9 +107,13 @@ directory dist_dir ...@@ -87,9 +107,13 @@ directory dist_dir
file jq => [dist_dir, base_files].flatten do file jq => [dist_dir, base_files].flatten do
puts "Building jquery.js..." puts "Building jquery.js..."
File.open(jq, 'w') do |f| File.open(jq, 'w') do |f|
f.write cat(base_files).gsub(/(Date:.)/, "\\1#{date}" ).gsub(/@VERSION/, version) f.write cat(base_files).
gsub(/@DATE/, date).
gsub(/@VERSION/, version).
gsub(/.function..jQuery...\{/, '').
gsub(/\}...jQuery..;/, '')
end end
end end
...@@ -97,9 +121,9 @@ file jq_min => jq do ...@@ -97,9 +121,9 @@ file jq_min => jq do
puts "Building jquery.min.js..." puts "Building jquery.min.js..."
sh "#{minfier} --js #{jq} --warning_level QUIET --js_output_file #{jq_min}" sh "#{minfier} --js #{jq} --warning_level QUIET --js_output_file #{jq_min}"
min = File.read( jq_min ) min = File.read( jq_min )
# Equivilent of "head" # Equivilent of "head"
File.open(jq_min, 'w') do |f| File.open(jq_min, 'w') do |f|
f.write File.readlines(jq)[0..14].join() f.write File.readlines(jq)[0..14].join()
...@@ -107,12 +131,12 @@ file jq_min => jq do ...@@ -107,12 +131,12 @@ file jq_min => jq do
end end
end end
file selector => [sizzle, :init] do file selector => [sizzle, :init] do
puts "Building selector code from Sizzle..." puts "Building selector code from Sizzle..."
File.open(selector, 'w') do |f| File.open(selector, 'w') do |f|
f.write File.read(sizzle).gsub( f.write File.read(sizzle).gsub(
/^.+EXPOSE$\n/, /^.+EXPOSE$\n/,
'\0' + File.read( File.join( src_dir, 'sizzle-jquery.js' )) '\0' + File.read( File.join( src_dir, 'sizzle-jquery.js' ))
).gsub( ).gsub(
/^window.Sizzle.+$\n/, '' /^window.Sizzle.+$\n/, ''
......
...@@ -63,10 +63,9 @@ ...@@ -63,10 +63,9 @@
<fileset file="src/manipulation.js" /> <fileset file="src/manipulation.js" />
<fileset file="src/css.js" /> <fileset file="src/css.js" />
<fileset file="src/ajax.js" /> <fileset file="src/ajax.js" />
<fileset file="src/xhr.js" /> <fileset file="src/ajax/jsonp.js" />
<fileset file="src/transports/jsonp.js" /> <fileset file="src/ajax/script.js" />
<fileset file="src/transports/script.js" /> <fileset file="src/ajax/xhr.js" />
<fileset file="src/transports/xhr.js" />
<fileset file="src/effects.js" /> <fileset file="src/effects.js" />
<fileset file="src/offset.js" /> <fileset file="src/offset.js" />
<fileset file="src/dimensions.js" /> <fileset file="src/dimensions.js" />
...@@ -77,7 +76,7 @@ ...@@ -77,7 +76,7 @@
<arg line="log -1 --pretty=format:%ad" /> <arg line="log -1 --pretty=format:%ad" />
</exec> </exec>
<replaceregexp match="(\(\s*function\s*\(\s*jQuery\s*\)\s*\{)|(\}\s*\)\s*\(\s*jQuery\s*\)\s*;)" flags="g" replace="" file="${JQ}" /> <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}" /> <replaceregexp match="@DATE" replace="${date}" file="${JQ}" />
<echo message="${JQ} built." /> <echo message="${JQ} built." />
</target> </target>
......
This diff is collapsed.
(function( jQuery ) {
var jsc = jQuery.now(),
jsre = /(\=)(?:\?|%3F)(&|$)|()(?:\?\?|%3F%3F)()/i,
rquery_jsonp = /\?/;
// Default jsonp settings
jQuery.ajaxSetup({
jsonp: "callback",
jsonpCallback: function() {
return "jsonp" + jsc++;
}
// Normalize jsonp queries
// 1) put callback parameter in url or data
// 2) sneakily ensure transportDataType is always jsonp for jsonp requests
}).ajaxPrefilter("json jsonp", function(s, originalSettings) {
if ( s.dataTypes[ 0 ] === "jsonp" ||
originalSettings.jsonp ||
originalSettings.jsonpCallback ||
jsre.test(s.url) ||
typeof(s.data) === "string" && jsre.test(s.data) ) {
var jsonpCallback = s.jsonpCallback =
jQuery.isFunction( s.jsonpCallback ) ? s.jsonpCallback() : s.jsonpCallback,
url = s.url.replace(jsre, "$1" + jsonpCallback + "$2"),
data = s.url === url && typeof(s.data) === "string" ? s.data.replace(jsre, "$1" + jsonpCallback + "$2") : s.data;
if ( url === s.url && data === s.data ) {
url += (rquery_jsonp.test( url ) ? "&" : "?") + s.jsonp + "=" + jsonpCallback;
}
s.url = url;
s.data = data;
s.dataTypes[ 0 ] = "jsonp";
}
// Bind transport to jsonp dataType
}).ajaxTransport("jsonp", function(s) {
// 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 ];
// Sneakily ensure this will be handled as json
s.dataTypes[ 0 ] = "json";
// Use data converter to retrieve json after script execution
s.converters["script json"] = function() {
if ( ! responseContainer ) {
jQuery.error( jsonpCallback + " was not called" );
}
return responseContainer[ 0 ];
};
// Delegate to script transport
return "script";
});
})( jQuery );
(function( jQuery ) { (function( jQuery ) {
// Install text to script executor // Install script dataType
jQuery.extend( true, jQuery.ajaxSettings , { jQuery.ajaxSetup({
accepts: { accepts: {
script: "text/javascript, application/javascript" script: "text/javascript, application/javascript"
}, },
autoDataType: { contents: {
script: /javascript/ script: /javascript/
}, },
dataConverters: { converters: {
"text => script": jQuery.globalEval "text script": jQuery.globalEval
} }
} );
// Bind script tag hack transport // Bind script tag hack transport
jQuery.xhr.bindTransport("script", function(s) { }).ajaxTransport("script", function(s) {
// Handle cache special case // Handle cache special case
if ( s.cache === undefined ) { if ( s.cache === undefined ) {
s.cache = false; s.cache = false;
} }
// This transport only deals with cross domain get requests // This transport only deals with cross domain get requests
if ( s.crossDomain && s.async && ( s.type === "GET" || ! s.data ) ) { if ( s.crossDomain && s.async && ( s.type === "GET" || ! s.data ) ) {
s.global = false; s.global = false;
var script, var script,
head = document.getElementsByTagName("head")[0] || document.documentElement; head = document.getElementsByTagName("head")[0] || document.documentElement;
return { return {
send: function(_, callback) { send: function(_, callback) {
script = document.createElement("script"); script = document.createElement("script");
...@@ -43,37 +42,39 @@ jQuery.xhr.bindTransport("script", function(s) { ...@@ -43,37 +42,39 @@ jQuery.xhr.bindTransport("script", function(s) {
if ( s.scriptCharset ) { if ( s.scriptCharset ) {
script.charset = s.scriptCharset; script.charset = s.scriptCharset;
} }
script.src = s.url; script.src = s.url;
// Attach handlers for all browsers // Attach handlers for all browsers
script.onload = script.onreadystatechange = function(statusText) { script.onload = script.onreadystatechange = function( _ , isAbort ) {
if ( (!script.readyState || if ( ! script.readyState || /loaded|complete/.test( script.readyState ) ) {
script.readyState === "loaded" || script.readyState === "complete") ) {
// Handle memory leak in IE // Handle memory leak in IE
script.onload = script.onreadystatechange = null; script.onload = script.onreadystatechange = null;
// Remove the script // Remove the script
if ( head && script.parentNode ) { if ( head && script.parentNode ) {
head.removeChild( script ); head.removeChild( script );
} }
script = undefined; // Dereference the script
script = 0;
// Callback & dereference
callback(statusText ? 0 : 200, statusText || "success"); // Callback if not abort
if ( ! isAbort ) {
callback( 200, "success" );
}
} }
}; };
// Use insertBefore instead of appendChild to circumvent an IE6 bug. // Use insertBefore instead of appendChild to circumvent an IE6 bug.
// This arises when a base node is used (#2709 and #4378). // This arises when a base node is used (#2709 and #4378).
head.insertBefore( script, head.firstChild ); head.insertBefore( script, head.firstChild );
}, },
abort: function(statusText) { abort: function() {
if ( script ) { if ( script ) {
script.onload(statusText); script.onload(0,1);
} }
} }
}; };
......
(function( jQuery ) { (function( jQuery ) {
var // Next fake timer id var // Next active xhr id
xhrPollingId = jQuery.now(), xhrId = jQuery.now(),
// Callbacks hashtable // active xhrs
xhrs = {}, xhrs = {},
// #5280: see end of file // #5280: see below
xhrUnloadAbortMarker = []; xhrUnloadAbortInstalled;
jQuery.ajaxTransport( function( s , determineDataType ) {
jQuery.xhr.bindTransport( function( s , determineDataType ) {
// Cross domain only allowed if supported through XMLHttpRequest // Cross domain only allowed if supported through XMLHttpRequest
if ( ! s.crossDomain || jQuery.support.cors ) { if ( ! s.crossDomain || jQuery.support.cors ) {
var callback; var callback;
return { return {
send: function(headers, complete) { send: function(headers, complete) {
// #5280: we need to abort on unload or IE will keep connections alive
if ( ! xhrUnloadAbortInstalled ) {
xhrUnloadAbortInstalled = 1;
jQuery(window).bind( "unload" , function() {
// Abort all pending requests
jQuery.each(xhrs, function(_, xhr) {
if ( xhr.onreadystatechange ) {
xhr.onreadystatechange( 1 );
}
});
});
}
// Get a new xhr
var xhr = s.xhr(), var xhr = s.xhr(),
handle; handle;
// Open the socket // Open the socket
// Passing null username, generates a login popup on Opera (#2865) // Passing null username, generates a login popup on Opera (#2865)
if ( s.username ) { if ( s.username ) {
...@@ -31,24 +49,24 @@ jQuery.xhr.bindTransport( function( s , determineDataType ) { ...@@ -31,24 +49,24 @@ jQuery.xhr.bindTransport( function( s , determineDataType ) {
} else { } else {
xhr.open(s.type, s.url, s.async); xhr.open(s.type, s.url, s.async);
} }
// Requested-With header // Requested-With header
// Not set for crossDomain requests with no content // Not set for crossDomain requests with no content
// (see why at http://trac.dojotoolkit.org/ticket/9486) // (see why at http://trac.dojotoolkit.org/ticket/9486)
// Won't change header if already provided in beforeSend // Won't change header if already provided
if ( ! ( s.crossDomain && ! s.hasContent ) && ! headers["x-requested-with"] ) { if ( ! ( s.crossDomain && ! s.hasContent ) && ! headers["x-requested-with"] ) {
headers["x-requested-with"] = "XMLHttpRequest"; headers["x-requested-with"] = "XMLHttpRequest";
} }
// Need an extra try/catch for cross domain requests in Firefox 3 // Need an extra try/catch for cross domain requests in Firefox 3
try { try {
jQuery.each(headers, function(key,value) { jQuery.each(headers, function(key,value) {
xhr.setRequestHeader(key,value); xhr.setRequestHeader(key,value);
}); });
} catch(_) {} } catch(_) {}
// Do send the request // Do send the request
try { try {
xhr.send( ( s.hasContent && s.data ) || null ); xhr.send( ( s.hasContent && s.data ) || null );
...@@ -56,55 +74,48 @@ jQuery.xhr.bindTransport( function( s , determineDataType ) { ...@@ -56,55 +74,48 @@ jQuery.xhr.bindTransport( function( s , determineDataType ) {
complete(0, "error", "" + e); complete(0, "error", "" + e);
return; return;
} }
// Listener // Listener
callback = function ( abortStatusText ) { callback = function( _ , isAbort ) {
// Was never called and is aborted or complete // Was never called and is aborted or complete
if ( callback && ( abortStatusText || xhr.readyState === 4 ) ) { if ( callback && ( isAbort || xhr.readyState === 4 ) ) {
// Do not listen anymore // Only called once
callback = 0;
// Do not keep as active anymore
// and store back into pool
if (handle) { if (handle) {
xhr.onreadystatechange = jQuery.noop; xhr.onreadystatechange = jQuery.noop;
delete xhrs[ handle ]; delete xhrs[ handle ];
handle = undefined;
} }
callback = 0; // If it's an abort
if ( isAbort ) {
// Get info
var status, statusText, response, responseHeaders; // Abort it manually if needed
if ( abortStatusText ) {
if ( xhr.readyState !== 4 ) { if ( xhr.readyState !== 4 ) {
xhr.abort(); xhr.abort();
} }
// Stop here if unloadAbort
if ( abortStatusText === xhrUnloadAbortMarker ) {
return;
}
status = 0;
statusText = abortStatusText;
} else { } else {
status = xhr.status; // Get info
var status = xhr.status,
statusText,
response,
responseHeaders = xhr.getAllResponseHeaders();
try { // Firefox throws an exception when accessing statusText for faulty cross-domain requests try { // Firefox throws an exception when accessing statusText for faulty cross-domain requests
statusText = xhr.statusText; statusText = xhr.statusText;
} catch( e ) { } catch( e ) {
statusText = ""; // We normalize with Webkit giving an empty statusText statusText = ""; // We normalize with Webkit giving an empty statusText
} }
responseHeaders = xhr.getAllResponseHeaders();
// Filter status for non standard behaviours // Filter status for non standard behaviours
// (so many they seem to be the actual "standard") // (so many they seem to be the actual "standard")
status = status =
...@@ -129,63 +140,44 @@ jQuery.xhr.bindTransport( function( s , determineDataType ) { ...@@ -129,63 +140,44 @@ jQuery.xhr.bindTransport( function( s , determineDataType ) {
: :
status status
); );
// Guess response if needed & update datatype accordingly // Guess response & update dataType accordingly
if ( status >= 200 && status < 300 ) { response =
response = determineDataType(
determineDataType( s,
s, xhr.getResponseHeader("content-type"),
xhr.getResponseHeader("content-type"), xhr.responseText,
xhr.responseText, xhr.responseXML );
xhr.responseXML );
} // Call complete
complete(status,statusText,response,responseHeaders);
} }
// Call complete
complete(status,statusText,response,responseHeaders);
} }
}; };
// if we're in sync mode // if we're in sync mode
// or it's in cache and has been retrieved directly (IE6 & IE7) // or it's in cache and has been retrieved directly (IE6 & IE7)
// we need to manually fire the callback // we need to manually fire the callback
if ( ! s.async || xhr.readyState === 4 ) { if ( ! s.async || xhr.readyState === 4 ) {
callback(); callback();
} else { } else {
// Listener is externalized to handle abort on unload // Add to list of active xhrs
handle = xhrPollingId++; handle = xhrId++;
xhrs[ handle ] = xhr; xhrs[ handle ] = xhr;
xhr.onreadystatechange = function() { xhr.onreadystatechange = callback;
callback(); }
};
}
}, },
abort: function(statusText) { abort: function() {
if ( callback ) { if ( callback ) {
callback(statusText); callback(0,1);
} }
} }
}; };
} }
}); });
// #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 ); })( jQuery );
...@@ -182,7 +182,7 @@ jQuery.fn.extend({ ...@@ -182,7 +182,7 @@ jQuery.fn.extend({
var option = options[ i ]; var option = options[ i ];
// Don't return options that are disabled or in a disabled optgroup // Don't return options that are disabled or in a disabled optgroup
if ( option.selected && (jQuery.support.optDisabled ? !option.disabled : option.getAttribute("disabled") === null) && if ( option.selected && (jQuery.support.optDisabled ? !option.disabled : option.getAttribute("disabled") === null) &&
(!option.parentNode.disabled || !jQuery.nodeName( option.parentNode, "optgroup" )) ) { (!option.parentNode.disabled || !jQuery.nodeName( option.parentNode, "optgroup" )) ) {
// Get the specific value for the option // Get the specific value for the option
......
This diff is collapsed.
...@@ -12,9 +12,6 @@ var ralpha = /alpha\([^)]*\)/i, ...@@ -12,9 +12,6 @@ var ralpha = /alpha\([^)]*\)/i,
cssHeight = [ "Top", "Bottom" ], cssHeight = [ "Top", "Bottom" ],
curCSS, curCSS,
getComputedStyle,
currentStyle,
fcamelCase = function( all, letter ) { fcamelCase = function( all, letter ) {
return letter.toUpperCase(); return letter.toUpperCase();
}; };
...@@ -172,10 +169,6 @@ jQuery.each(["height", "width"], function( i, name ) { ...@@ -172,10 +169,6 @@ jQuery.each(["height", "width"], function( i, name ) {
if ( val <= 0 ) { if ( val <= 0 ) {
val = curCSS( elem, name, name ); val = curCSS( elem, name, name );
if ( val === "0px" && currentStyle ) {
val = currentStyle( elem, name, name );
}
if ( val != null ) { if ( val != null ) {
// Should return "auto" instead of 0, use 0 for // Should return "auto" instead of 0, use 0 for
// temporary backwards-compat // temporary backwards-compat
...@@ -241,7 +234,7 @@ if ( !jQuery.support.opacity ) { ...@@ -241,7 +234,7 @@ if ( !jQuery.support.opacity ) {
} }
if ( document.defaultView && document.defaultView.getComputedStyle ) { if ( document.defaultView && document.defaultView.getComputedStyle ) {
getComputedStyle = function( elem, newName, name ) { curCSS = function( elem, newName, name ) {
var ret, defaultView, computedStyle; var ret, defaultView, computedStyle;
name = name.replace( rupper, "-$1" ).toLowerCase(); name = name.replace( rupper, "-$1" ).toLowerCase();
...@@ -259,10 +252,8 @@ if ( document.defaultView && document.defaultView.getComputedStyle ) { ...@@ -259,10 +252,8 @@ if ( document.defaultView && document.defaultView.getComputedStyle ) {
return ret; return ret;
}; };
} } else if ( document.documentElement.currentStyle ) {
curCSS = function( elem, name ) {
if ( document.documentElement.currentStyle ) {
currentStyle = function( elem, name ) {
var left, rsLeft, var left, rsLeft,
ret = elem.currentStyle && elem.currentStyle[ name ], ret = elem.currentStyle && elem.currentStyle[ name ],
style = elem.style; style = elem.style;
...@@ -291,8 +282,6 @@ if ( document.documentElement.currentStyle ) { ...@@ -291,8 +282,6 @@ if ( document.documentElement.currentStyle ) {
}; };
} }
curCSS = getComputedStyle || currentStyle;
function getWH( elem, name, extra ) { function getWH( elem, name, extra ) {
var which = name === "width" ? cssWidth : cssHeight, var which = name === "width" ? cssWidth : cssHeight,
val = name === "width" ? elem.offsetWidth : elem.offsetHeight; val = name === "width" ? elem.offsetWidth : elem.offsetHeight;
......
...@@ -9,8 +9,9 @@ jQuery.extend({ ...@@ -9,8 +9,9 @@ jQuery.extend({
// Please use with caution // Please use with caution
uuid: 0, uuid: 0,
// Unique for each copy of jQuery on the page // Unique for each copy of jQuery on the page
expando: "jQuery" + jQuery.now(), // Non-digits removed to match rinlinejQuery
expando: "jQuery" + ( jQuery.fn.jquery + Math.random() ).replace( /\D/g, "" ),
// The following elements throw uncatchable exceptions if you // The following elements throw uncatchable exceptions if you
// attempt to add expando properties to them. // attempt to add expando properties to them.
...@@ -21,6 +22,14 @@ jQuery.extend({ ...@@ -21,6 +22,14 @@ jQuery.extend({
"applet": true "applet": true
}, },
hasData: function( elem ) {
if ( elem.nodeType ) {
elem = jQuery.cache[ elem[jQuery.expando] ];
}
return !!elem && !jQuery.isEmptyObject(elem);
},
data: function( elem, name, data ) { data: function( elem, name, data ) {
if ( !jQuery.acceptData( elem ) ) { if ( !jQuery.acceptData( elem ) ) {
return; return;
...@@ -144,7 +153,7 @@ jQuery.fn.extend({ ...@@ -144,7 +153,7 @@ jQuery.fn.extend({
var attr = this[0].attributes, name; var attr = this[0].attributes, name;
for ( var i = 0, l = attr.length; i < l; i++ ) { for ( var i = 0, l = attr.length; i < l; i++ ) {
name = attr[i].name; name = attr[i].name;
if ( name.indexOf( "data-" ) === 0 ) { if ( name.indexOf( "data-" ) === 0 ) {
name = name.substr( 5 ); name = name.substr( 5 );
dataAttr( this[0], name, data[ name ] ); dataAttr( this[0], name, data[ name ] );
......
...@@ -25,7 +25,7 @@ jQuery.each([ "Height", "Width" ], function( i, name ) { ...@@ -25,7 +25,7 @@ jQuery.each([ "Height", "Width" ], function( i, name ) {
if ( !elem ) { if ( !elem ) {
return size == null ? null : this; return size == null ? null : this;
} }
if ( jQuery.isFunction( size ) ) { if ( jQuery.isFunction( size ) ) {
return this.each(function( i ) { return this.each(function( i ) {
var self = jQuery( this ); var self = jQuery( this );
......
...@@ -61,7 +61,7 @@ jQuery.fn.extend({ ...@@ -61,7 +61,7 @@ jQuery.fn.extend({
} else { } else {
for ( var i = 0, j = this.length; i < j; i++ ) { for ( var i = 0, j = this.length; i < j; i++ ) {
var display = jQuery.css( this[i], "display" ); var display = jQuery.css( this[i], "display" );
if ( display !== "none" && !jQuery.data( this[i], "olddisplay" ) ) { if ( display !== "none" && !jQuery.data( this[i], "olddisplay" ) ) {
jQuery.data( this[i], "olddisplay", display ); jQuery.data( this[i], "olddisplay", display );
} }
...@@ -337,7 +337,7 @@ jQuery.fx.prototype = { ...@@ -337,7 +337,7 @@ jQuery.fx.prototype = {
} }
var r = parseFloat( jQuery.css( this.elem, this.prop ) ); var r = parseFloat( jQuery.css( this.elem, this.prop ) );
return r && r > -10000 ? r : 0; return r || 0;
}, },
// Start an animation from one number to another // Start an animation from one number to another
......
...@@ -63,7 +63,7 @@ jQuery.event = { ...@@ -63,7 +63,7 @@ jQuery.event = {
var eventKey = elem.nodeType ? "events" : "__events__", var eventKey = elem.nodeType ? "events" : "__events__",
events = elemData[ eventKey ], events = elemData[ eventKey ],
eventHandle = elemData.handle; eventHandle = elemData.handle;
if ( typeof events === "function" ) { if ( typeof events === "function" ) {
// On plain objects events is a fn that holds the the data // On plain objects events is a fn that holds the the data
// which prevents this data from being JSON serialized // which prevents this data from being JSON serialized
...@@ -143,9 +143,9 @@ jQuery.event = { ...@@ -143,9 +143,9 @@ jQuery.event = {
} }
} }
} }
if ( special.add ) { if ( special.add ) {
special.add.call( elem, handleObj ); special.add.call( elem, handleObj );
if ( !handleObj.handler.guid ) { if ( !handleObj.handler.guid ) {
handleObj.handler.guid = handler.guid; handleObj.handler.guid = handler.guid;
...@@ -184,7 +184,7 @@ jQuery.event = { ...@@ -184,7 +184,7 @@ jQuery.event = {
if ( !elemData || !events ) { if ( !elemData || !events ) {
return; return;
} }
if ( typeof events === "function" ) { if ( typeof events === "function" ) {
elemData = events; elemData = events;
events = events.events; events = events.events;
...@@ -222,7 +222,7 @@ jQuery.event = { ...@@ -222,7 +222,7 @@ jQuery.event = {
namespaces = type.split("."); namespaces = type.split(".");
type = namespaces.shift(); type = namespaces.shift();
namespace = new RegExp("(^|\\.)" + namespace = new RegExp("(^|\\.)" +
jQuery.map( namespaces.slice(0).sort(), fcleanup ).join("\\.(?:.*\\.)?") + "(\\.|$)"); jQuery.map( namespaces.slice(0).sort(), fcleanup ).join("\\.(?:.*\\.)?") + "(\\.|$)");
} }
...@@ -384,7 +384,7 @@ jQuery.event = { ...@@ -384,7 +384,7 @@ jQuery.event = {
isClick = jQuery.nodeName( target, "a" ) && targetType === "click", isClick = jQuery.nodeName( target, "a" ) && targetType === "click",
special = jQuery.event.special[ targetType ] || {}; special = jQuery.event.special[ targetType ] || {};
if ( (!special._default || special._default.call( elem, event ) === false) && if ( (!special._default || special._default.call( elem, event ) === false) &&
!isClick && !(target && target.nodeName && jQuery.noData[target.nodeName.toLowerCase()]) ) { !isClick && !(target && target.nodeName && jQuery.noData[target.nodeName.toLowerCase()]) ) {
try { try {
...@@ -454,7 +454,7 @@ jQuery.event = { ...@@ -454,7 +454,7 @@ jQuery.event = {
event.handler = handleObj.handler; event.handler = handleObj.handler;
event.data = handleObj.data; event.data = handleObj.data;
event.handleObj = handleObj; event.handleObj = handleObj;
var ret = handleObj.handler.apply( this, args ); var ret = handleObj.handler.apply( this, args );
if ( ret !== undefined ) { if ( ret !== undefined ) {
...@@ -553,7 +553,7 @@ jQuery.event = { ...@@ -553,7 +553,7 @@ jQuery.event = {
add: function( handleObj ) { add: function( handleObj ) {
jQuery.event.add( this, jQuery.event.add( this,
liveConvert( handleObj.origType, handleObj.selector ), liveConvert( handleObj.origType, handleObj.selector ),
jQuery.extend({}, handleObj, {handler: liveHandler, guid: handleObj.handler.guid}) ); jQuery.extend({}, handleObj, {handler: liveHandler, guid: handleObj.handler.guid}) );
}, },
remove: function( handleObj ) { remove: function( handleObj ) {
...@@ -583,7 +583,7 @@ jQuery.removeEvent = document.removeEventListener ? ...@@ -583,7 +583,7 @@ jQuery.removeEvent = document.removeEventListener ?
if ( elem.removeEventListener ) { if ( elem.removeEventListener ) {
elem.removeEventListener( type, handle, false ); elem.removeEventListener( type, handle, false );
} }
} : } :
function( elem, type, handle ) { function( elem, type, handle ) {
if ( elem.detachEvent ) { if ( elem.detachEvent ) {
elem.detachEvent( "on" + type, handle ); elem.detachEvent( "on" + type, handle );
...@@ -600,6 +600,12 @@ jQuery.Event = function( src ) { ...@@ -600,6 +600,12 @@ jQuery.Event = function( src ) {
if ( src && src.type ) { if ( src && src.type ) {
this.originalEvent = src; this.originalEvent = src;
this.type = src.type; this.type = src.type;
// Events bubbling up the document may have been marked as prevented
// by a handler lower down the tree; reflect the correct value.
this.isDefaultPrevented = (src.defaultPrevented || src.returnValue === false ||
src.getPreventDefault && src.getPreventDefault()) ? returnTrue : returnFalse;
// Event type // Event type
} else { } else {
this.type = src; this.type = src;
...@@ -630,7 +636,7 @@ jQuery.Event.prototype = { ...@@ -630,7 +636,7 @@ jQuery.Event.prototype = {
if ( !e ) { if ( !e ) {
return; return;
} }
// if preventDefault exists run it on the original event // if preventDefault exists run it on the original event
if ( e.preventDefault ) { if ( e.preventDefault ) {
e.preventDefault(); e.preventDefault();
...@@ -726,7 +732,7 @@ if ( !jQuery.support.submitBubbles ) { ...@@ -726,7 +732,7 @@ if ( !jQuery.support.submitBubbles ) {
return trigger( "submit", this, arguments ); return trigger( "submit", this, arguments );
} }
}); });
jQuery.event.add(this, "keypress.specialSubmit", function( e ) { jQuery.event.add(this, "keypress.specialSubmit", function( e ) {
var elem = e.target, var elem = e.target,
type = elem.type; type = elem.type;
...@@ -788,7 +794,7 @@ if ( !jQuery.support.changeBubbles ) { ...@@ -788,7 +794,7 @@ if ( !jQuery.support.changeBubbles ) {
if ( e.type !== "focusout" || elem.type !== "radio" ) { if ( e.type !== "focusout" || elem.type !== "radio" ) {
jQuery.data( elem, "_change_data", val ); jQuery.data( elem, "_change_data", val );
} }
if ( data === undefined || val === data ) { if ( data === undefined || val === data ) {
return; return;
} }
...@@ -802,7 +808,7 @@ if ( !jQuery.support.changeBubbles ) { ...@@ -802,7 +808,7 @@ if ( !jQuery.support.changeBubbles ) {
jQuery.event.special.change = { jQuery.event.special.change = {
filters: { filters: {
focusout: testChange, focusout: testChange,
beforedeactivate: testChange, beforedeactivate: testChange,
...@@ -873,15 +879,15 @@ if ( document.addEventListener ) { ...@@ -873,15 +879,15 @@ if ( document.addEventListener ) {
if ( focusCounts[fix]++ === 0 ) { if ( focusCounts[fix]++ === 0 ) {
document.addEventListener( orig, handler, true ); document.addEventListener( orig, handler, true );
} }
}, },
teardown: function() { teardown: function() {
if ( --focusCounts[fix] === 0 ) { if ( --focusCounts[fix] === 0 ) {
document.removeEventListener( orig, handler, true ); document.removeEventListener( orig, handler, true );
} }
} }
}; };
function handler( e ) { function handler( e ) {
e = jQuery.event.fix( e ); e = jQuery.event.fix( e );
e.type = fix; e.type = fix;
return jQuery.event.trigger( e, null, e.target ); return jQuery.event.trigger( e, null, e.target );
...@@ -898,7 +904,7 @@ jQuery.each(["bind", "one"], function( i, name ) { ...@@ -898,7 +904,7 @@ jQuery.each(["bind", "one"], function( i, name ) {
} }
return this; return this;
} }
if ( jQuery.isFunction( data ) || data === false ) { if ( jQuery.isFunction( data ) || data === false ) {
fn = data; fn = data;
data = undefined; data = undefined;
...@@ -938,20 +944,20 @@ jQuery.fn.extend({ ...@@ -938,20 +944,20 @@ jQuery.fn.extend({
return this; return this;
}, },
delegate: function( selector, types, data, fn ) { delegate: function( selector, types, data, fn ) {
return this.live( types, data, fn, selector ); return this.live( types, data, fn, selector );
}, },
undelegate: function( selector, types, fn ) { undelegate: function( selector, types, fn ) {
if ( arguments.length === 0 ) { if ( arguments.length === 0 ) {
return this.unbind( "live" ); return this.unbind( "live" );
} else { } else {
return this.die( types, null, fn, selector ); return this.die( types, null, fn, selector );
} }
}, },
trigger: function( type, data ) { trigger: function( type, data ) {
return this.each(function() { return this.each(function() {
jQuery.event.trigger( type, data, this ); jQuery.event.trigger( type, data, this );
...@@ -1008,12 +1014,12 @@ jQuery.each(["live", "die"], function( i, name ) { ...@@ -1008,12 +1014,12 @@ jQuery.each(["live", "die"], function( i, name ) {
var type, i = 0, match, namespaces, preType, var type, i = 0, match, namespaces, preType,
selector = origSelector || this.selector, selector = origSelector || this.selector,
context = origSelector ? this : jQuery( this.context ); context = origSelector ? this : jQuery( this.context );
if ( typeof types === "object" && !types.preventDefault ) { if ( typeof types === "object" && !types.preventDefault ) {
for ( var key in types ) { for ( var key in types ) {
context[ name ]( key, data, types[key], selector ); context[ name ]( key, data, types[key], selector );
} }
return this; return this;
} }
...@@ -1060,7 +1066,7 @@ jQuery.each(["live", "die"], function( i, name ) { ...@@ -1060,7 +1066,7 @@ jQuery.each(["live", "die"], function( i, name ) {
context.unbind( "live." + liveConvert( type, selector ), fn ); context.unbind( "live." + liveConvert( type, selector ), fn );
} }
} }
return this; return this;
}; };
}); });
...@@ -1079,7 +1085,7 @@ function liveHandler( event ) { ...@@ -1079,7 +1085,7 @@ function liveHandler( event ) {
if ( event.liveFired === this || !events || !events.live || event.target.disabled || event.button && event.type === "click" ) { if ( event.liveFired === this || !events || !events.live || event.target.disabled || event.button && event.type === "click" ) {
return; return;
} }
if ( event.namespace ) { if ( event.namespace ) {
namespace = new RegExp("(^|\\.)" + event.namespace.split(".").join("\\.(?:.*\\.)?") + "(\\.|$)"); namespace = new RegExp("(^|\\.)" + event.namespace.split(".").join("\\.(?:.*\\.)?") + "(\\.|$)");
} }
...@@ -1177,21 +1183,4 @@ jQuery.each( ("blur focus focusin focusout load resize scroll unload click dblcl ...@@ -1177,21 +1183,4 @@ jQuery.each( ("blur focus focusin focusout load resize scroll unload click dblcl
} }
}); });
// Prevent memory leaks in IE
// Window isn't included so as not to unbind existing unload events
// More info:
// - http://isaacschlueter.com/2006/10/msie-memory-leaks/
if ( window.attachEvent && !window.addEventListener ) {
jQuery(window).bind("unload", function() {
for ( var id in jQuery.cache ) {
if ( jQuery.cache[ id ].handle ) {
// Try/Catch is to handle iframes being unloaded, see #4280
try {
jQuery.event.remove( jQuery.cache[ id ].handle.elem );
} catch(e) {}
}
}
});
}
})( jQuery ); })( jQuery );
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
* Copyright 2010, The Dojo Foundation * Copyright 2010, The Dojo Foundation
* Released under the MIT, BSD, and GPL Licenses. * Released under the MIT, BSD, and GPL Licenses.
* *
* Date: * Date: @DATE
*/ */
(function( window, undefined ) { (function( window, undefined ) {
......
...@@ -370,14 +370,18 @@ function root( elem, cur ) { ...@@ -370,14 +370,18 @@ function root( elem, cur ) {
} }
function cloneCopyEvent(orig, ret) { function cloneCopyEvent(orig, ret) {
var i = 0; ret.each(function (nodeIndex) {
if ( this.nodeType !== 1 || !jQuery.hasData(orig[nodeIndex]) ) {
ret.each(function() {
if ( this.nodeType !== 1 || this.nodeName !== (orig[i] && orig[i].nodeName) ) {
return; return;
} }
var oldData = jQuery.data( orig[i++] ), // XXX remove for 1.5 RC or merge back in if there is actually a reason for this check that has been
// unexposed by unit tests
if ( this.nodeName !== (orig[nodeIndex] && orig[nodeIndex].nodeName) ) {
throw "Cloned data mismatch";
}
var oldData = jQuery.data( orig[nodeIndex] ),
curData = jQuery.data( this, oldData ), curData = jQuery.data( this, oldData ),
events = oldData && oldData.events; events = oldData && oldData.events;
...@@ -386,8 +390,8 @@ function cloneCopyEvent(orig, ret) { ...@@ -386,8 +390,8 @@ function cloneCopyEvent(orig, ret) {
curData.events = {}; curData.events = {};
for ( var type in events ) { for ( var type in events ) {
for ( var handler in events[ type ] ) { for ( var i = 0, l = events[ type ].length; i < l; i++ ) {
jQuery.event.add( this, type, events[ type ][ handler ], events[ type ][ handler ].data ); jQuery.event.add( this, type, events[ type ][ i ], events[ type ][ i ].data );
} }
} }
} }
...@@ -416,15 +420,29 @@ function cloneFixAttributes(src, dest) { ...@@ -416,15 +420,29 @@ function cloneFixAttributes(src, dest) {
if ( nodeName === "object" ) { if ( nodeName === "object" ) {
dest.outerHTML = src.outerHTML; dest.outerHTML = src.outerHTML;
// IE6-8 fails to persist the checked state of a cloned checkbox } else if ( nodeName === "input" && (src.type === "checkbox" || src.type === "radio") ) {
// or radio button // IE6-8 fails to persist the checked state of a cloned checkbox
} else if ( nodeName === "input" && src.checked ) { // or radio button. Worse, IE6-7 fail to give the cloned element
dest.defaultChecked = dest.checked = src.checked; // a checked appearance if the defaultChecked value isn't also set
if ( src.checked ) {
dest.defaultChecked = dest.checked = src.checked;
}
// IE6-7 get confused and end up setting the value of a cloned
// checkbox/radio button to an empty string instead of "on"
if ( dest.value !== src.value ) {
dest.value = src.value;
}
// IE6-8 fails to return the selected option to the default selected // IE6-8 fails to return the selected option to the default selected
// state when cloning options // state when cloning options
} else if ( nodeName === "option" ) { } else if ( nodeName === "option" ) {
dest.selected = src.defaultSelected; dest.selected = src.defaultSelected;
// IE6-8 fails to set the defaultValue to the correct value when
// cloning other types of input fields
} else if ( nodeName === "input" || nodeName === "textarea" ) {
dest.defaultValue = src.defaultValue;
} }
// Event data gets referenced instead of copied if the expando // Event data gets referenced instead of copied if the expando
...@@ -436,12 +454,12 @@ jQuery.buildFragment = function( args, nodes, scripts ) { ...@@ -436,12 +454,12 @@ jQuery.buildFragment = function( args, nodes, scripts ) {
var fragment, cacheable, cacheresults, var fragment, cacheable, cacheresults,
doc = (nodes && nodes[0] ? nodes[0].ownerDocument || nodes[0] : document); doc = (nodes && nodes[0] ? nodes[0].ownerDocument || nodes[0] : document);
// Only cache "small" (1/2 KB) strings that are associated with the main document // Only cache "small" (1/2 KB) HTML strings that are associated with the main document
// Cloning options loses the selected state, so don't cache them // Cloning options loses the selected state, so don't cache them
// IE 6 doesn't like it when you put <object> or <embed> elements in a fragment // IE 6 doesn't like it when you put <object> or <embed> elements in a fragment
// Also, WebKit does not clone 'checked' attributes on cloneNode, so don't cache // Also, WebKit does not clone 'checked' attributes on cloneNode, so don't cache
if ( args.length === 1 && typeof args[0] === "string" && args[0].length < 512 && doc === document && if ( args.length === 1 && typeof args[0] === "string" && args[0].length < 512 && doc === document &&
!rnocache.test( args[0] ) && (jQuery.support.checkClone || !rchecked.test( args[0] )) ) { args[0].charAt(0) === "<" && !rnocache.test( args[0] ) && (jQuery.support.checkClone || !rchecked.test( args[0] )) ) {
cacheable = true; cacheable = true;
cacheresults = jQuery.fragments[ args[0] ]; cacheresults = jQuery.fragments[ args[0] ];
...@@ -613,6 +631,11 @@ jQuery.extend({ ...@@ -613,6 +631,11 @@ jQuery.extend({
jQuery.removeEvent( elem, type, data.handle ); jQuery.removeEvent( elem, type, data.handle );
} }
} }
// Null the DOM reference to avoid IE6/7/8 leak (#7054)
if ( data.handle ) {
data.handle.elem = null;
}
} }
if ( deleteExpando ) { if ( deleteExpando ) {
......
...@@ -7,7 +7,7 @@ if ( "getBoundingClientRect" in document.documentElement ) { ...@@ -7,7 +7,7 @@ if ( "getBoundingClientRect" in document.documentElement ) {
jQuery.fn.offset = function( options ) { jQuery.fn.offset = function( options ) {
var elem = this[0], box; var elem = this[0], box;
if ( options ) { if ( options ) {
return this.each(function( i ) { return this.each(function( i ) {
jQuery.offset.setOffset( this, options, i ); jQuery.offset.setOffset( this, options, i );
}); });
...@@ -49,7 +49,7 @@ if ( "getBoundingClientRect" in document.documentElement ) { ...@@ -49,7 +49,7 @@ if ( "getBoundingClientRect" in document.documentElement ) {
jQuery.fn.offset = function( options ) { jQuery.fn.offset = function( options ) {
var elem = this[0]; var elem = this[0];
if ( options ) { if ( options ) {
return this.each(function( i ) { return this.each(function( i ) {
jQuery.offset.setOffset( this, options, i ); jQuery.offset.setOffset( this, options, i );
}); });
...@@ -168,7 +168,7 @@ jQuery.offset = { ...@@ -168,7 +168,7 @@ jQuery.offset = {
return { top: top, left: left }; return { top: top, left: left };
}, },
setOffset: function( elem, options, i ) { setOffset: function( elem, options, i ) {
var position = jQuery.css( elem, "position" ); var position = jQuery.css( elem, "position" );
...@@ -202,7 +202,7 @@ jQuery.offset = { ...@@ -202,7 +202,7 @@ jQuery.offset = {
if (options.left != null) { if (options.left != null) {
props.left = (options.left - curOffset.left) + curLeft; props.left = (options.left - curOffset.left) + curLeft;
} }
if ( "using" in options ) { if ( "using" in options ) {
options.using.call( elem, props ); options.using.call( elem, props );
} else { } else {
...@@ -262,7 +262,7 @@ jQuery.each( ["Left", "Top"], function( i, name ) { ...@@ -262,7 +262,7 @@ jQuery.each( ["Left", "Top"], function( i, name ) {
jQuery.fn[ method ] = function(val) { jQuery.fn[ method ] = function(val) {
var elem = this[0], win; var elem = this[0], win;
if ( !elem ) { if ( !elem ) {
return null; return null;
} }
......
...@@ -147,7 +147,7 @@ ...@@ -147,7 +147,7 @@
jQuery.support.shrinkWrapBlocks = div.offsetWidth !== 2; jQuery.support.shrinkWrapBlocks = div.offsetWidth !== 2;
} }
div.innerHTML = "<table><tr><td style='padding:0;display:none'></td><td>t</td></tr></table>"; div.innerHTML = "<table><tr><td style='padding:0;border:0;display:none'></td><td>t</td></tr></table>";
var tds = div.getElementsByTagName("td"); var tds = div.getElementsByTagName("td");
// Check if table cells still have offsetWidth/Height when they are set // Check if table cells still have offsetWidth/Height when they are set
......
(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 );
...@@ -51,7 +51,7 @@ jQuery.fn.extend({ ...@@ -51,7 +51,7 @@ jQuery.fn.extend({
filter: function( selector ) { filter: function( selector ) {
return this.pushStack( winnow(this, selector, true), "filter", selector ); return this.pushStack( winnow(this, selector, true), "filter", selector );
}, },
is: function( selector ) { is: function( selector ) {
return !!selector && jQuery.filter( selector, this ).length > 0; return !!selector && jQuery.filter( selector, this ).length > 0;
}, },
...@@ -69,7 +69,7 @@ jQuery.fn.extend({ ...@@ -69,7 +69,7 @@ jQuery.fn.extend({
selector = selectors[i]; selector = selectors[i];
if ( !matches[selector] ) { if ( !matches[selector] ) {
matches[selector] = jQuery.expr.match.POS.test( selector ) ? matches[selector] = jQuery.expr.match.POS.test( selector ) ?
jQuery( selector, context || this.context ) : jQuery( selector, context || this.context ) :
selector; selector;
} }
...@@ -92,7 +92,7 @@ jQuery.fn.extend({ ...@@ -92,7 +92,7 @@ jQuery.fn.extend({
return ret; return ret;
} }
var pos = POS.test( selectors ) ? var pos = POS.test( selectors ) ?
jQuery( selectors, context || this.context ) : null; jQuery( selectors, context || this.context ) : null;
for ( i = 0, l = this.length; i < l; i++ ) { for ( i = 0, l = this.length; i < l; i++ ) {
...@@ -113,10 +113,10 @@ jQuery.fn.extend({ ...@@ -113,10 +113,10 @@ jQuery.fn.extend({
} }
ret = ret.length > 1 ? jQuery.unique(ret) : ret; ret = ret.length > 1 ? jQuery.unique(ret) : ret;
return this.pushStack( ret, "closest", selectors ); return this.pushStack( ret, "closest", selectors );
}, },
// Determine the position of an element within // Determine the position of an element within
// the matched set of elements // the matched set of elements
index: function( elem ) { index: function( elem ) {
...@@ -197,7 +197,7 @@ jQuery.each({ ...@@ -197,7 +197,7 @@ jQuery.each({
}, function( name, fn ) { }, function( name, fn ) {
jQuery.fn[ name ] = function( until, selector ) { jQuery.fn[ name ] = function( until, selector ) {
var ret = jQuery.map( this, fn, until ); var ret = jQuery.map( this, fn, until );
if ( !runtil.test( name ) ) { if ( !runtil.test( name ) ) {
selector = until; selector = until;
} }
...@@ -226,7 +226,7 @@ jQuery.extend({ ...@@ -226,7 +226,7 @@ jQuery.extend({
jQuery.find.matchesSelector(elems[0], expr) ? [ elems[0] ] : [] : jQuery.find.matchesSelector(elems[0], expr) ? [ elems[0] ] : [] :
jQuery.find.matches(expr, elems); jQuery.find.matches(expr, elems);
}, },
dir: function( elem, dir, until ) { dir: function( elem, dir, until ) {
var matched = [], var matched = [],
cur = elem[ dir ]; cur = elem[ dir ];
......
This diff is collapsed.
<?php
header("HTTP/1.0 400 Bad Request");
echo "plain text message";
\ No newline at end of file
...@@ -4,17 +4,13 @@ header( "Sample-Header: Hello World" ); ...@@ -4,17 +4,13 @@ header( "Sample-Header: Hello World" );
$headers = array(); $headers = array();
foreach( $_SERVER as $key => $value ) { foreach( $_SERVER as $key => $value ) {
if ( substr( $key , 0 , 5 ) == "HTTP_" ) {
$key = str_replace( "_" , "-" , substr( $key , 5) );
$headers[ $key ] = $value;
} $key = str_replace( "_" , "-" , substr( $key , 0 , 5 ) == "HTTP_" ? substr( $key , 5 ) : $key );
$headers[ $key ] = $value;
}
}
foreach( explode( "_" , $_GET[ "keys" ] ) as $key ) { foreach( explode( "_" , $_GET[ "keys" ] ) as $key ) {
echo "$key: " . $headers[ strtoupper( $key ) ] . "\n"; echo "$key: " . @$headers[ strtoupper( $key ) ] . "\n";
} }
<?php <?php
error_reporting(0); error_reporting(0);
$callback = $_REQUEST['callback']; $callback = $_REQUEST['callback'];
if ( ! $callback ) {
$callback = explode("?",end(explode("/",$_SERVER['REQUEST_URI'])));
$callback = $callback[0];
}
$json = $_REQUEST['json']; $json = $_REQUEST['json'];
if($json) { if($json) {
echo $callback . '([ {"name": "John", "age": 21}, {"name": "Peter", "age": 25 } ])'; echo $callback . '([ {"name": "John", "age": 21}, {"name": "Peter", "age": 25 } ])';
......
<div id="post"> <div id="post">
<?php <?php
foreach( $_POST as $key=>$value ) foreach( $_POST as $key=>$value )
echo "<b id='$key'>$value</b>"; echo "<b id='$key'>$value</b>";
?> ?>
</div> </div>
<div id="get"> <div id="get">
<?php <?php
foreach( $_GET as $key=>$value ) foreach( $_GET as $key=>$value )
echo "<b id='$key'>$value</b>"; echo "<b id='$key'>$value</b>";
?> ?>
</div> </div>
\ No newline at end of file
...@@ -206,7 +206,7 @@ ...@@ -206,7 +206,7 @@
$(document).bind("focusin", function() { $(document).bind("focusin", function() {
jQuery("#boundFocus").blink(); jQuery("#boundFocus").blink();
}); });
$(document).bind("focusout", function() { $(document).bind("focusout", function() {
jQuery("#boundBlur").blink(); jQuery("#boundBlur").blink();
}); });
...@@ -229,14 +229,14 @@ ...@@ -229,14 +229,14 @@
$(document).bind("change", function(){ $(document).bind("change", function(){
jQuery("#boundChange").blink(); jQuery("#boundChange").blink();
}); });
$("#text_submit").addSubmitTest("#textSubmit", true); $("#text_submit").addSubmitTest("#textSubmit", true);
$("#password_submit").addSubmitTest("#passwordSubmit", true); $("#password_submit").addSubmitTest("#passwordSubmit", true);
$("#submit_submit").addSubmitTest("#submitSubmit", true); $("#submit_submit").addSubmitTest("#submitSubmit", true);
$(document).bind("submit", function(){ $(document).bind("submit", function(){
jQuery("#boundSubmit").blink(); jQuery("#boundSubmit").blink();
}); });
</script> </script>
</body> </body>
</html> </html>
...@@ -20,10 +20,9 @@ ...@@ -20,10 +20,9 @@
<script src="../src/manipulation.js"></script> <script src="../src/manipulation.js"></script>
<script src="../src/css.js"></script> <script src="../src/css.js"></script>
<script src="../src/ajax.js"></script> <script src="../src/ajax.js"></script>
<script src="../src/xhr.js"></script> <script src="../src/ajax/jsonp.js"></script>
<script src="../src/transports/jsonp.js"></script> <script src="../src/ajax/script.js"></script>
<script src="../src/transports/script.js"></script> <script src="../src/ajax/xhr.js"></script>
<script src="../src/transports/xhr.js"></script>
<script src="../src/effects.js"></script> <script src="../src/effects.js"></script>
<script src="../src/offset.js"></script> <script src="../src/offset.js"></script>
<script src="../src/dimensions.js"></script> <script src="../src/dimensions.js"></script>
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
$suite = file_get_contents('index.html'); $suite = file_get_contents('index.html');
echo str_replace( '<!-- Includes -->', $includes, $suite ); echo str_replace( '<!-- Includes -->', $includes, $suite );
exit; exit;
} }
?> ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
...@@ -43,7 +43,7 @@ ...@@ -43,7 +43,7 @@
<h1 id="header">jQuery Test Suite</h1> <h1 id="header">jQuery Test Suite</h1>
<h2 id="banner" class="fail"></h2> <h2 id="banner" class="fail"></h2>
<h2 id="userAgent">Choose other libraries to include</h2> <h2 id="userAgent">Choose other libraries to include</h2>
<form class="otherlibs" action="" method="post"> <form class="otherlibs" action="" method="post">
<?php <?php
$libs = scandir('otherlibs'); $libs = scandir('otherlibs');
......
This diff is collapsed.
...@@ -4,13 +4,13 @@ var bareObj = function(value) { return value; }; ...@@ -4,13 +4,13 @@ var bareObj = function(value) { return value; };
var functionReturningObj = function(value) { return (function() { return value; }); }; var functionReturningObj = function(value) { return (function() { return value; }); };
test("jQuery.props: itegrity test", function() { test("jQuery.props: itegrity test", function() {
expect(1); expect(1);
// This must be maintained and equal jQuery.props // This must be maintained and equal jQuery.props
// Ensure that accidental or erroneous property // Ensure that accidental or erroneous property
// overwrites don't occur // overwrites don't occur
// This is simply for better code coverage and future proofing. // This is simply for better code coverage and future proofing.
var propsShouldBe = { var propsShouldBe = {
"for": "htmlFor", "for": "htmlFor",
"class": "className", "class": "className",
...@@ -23,7 +23,7 @@ test("jQuery.props: itegrity test", function() { ...@@ -23,7 +23,7 @@ test("jQuery.props: itegrity test", function() {
usemap: "useMap", usemap: "useMap",
frameborder: "frameBorder" frameborder: "frameBorder"
}; };
same(propsShouldBe, jQuery.props, "jQuery.props passes integrity check"); same(propsShouldBe, jQuery.props, "jQuery.props passes integrity check");
}); });
...@@ -33,7 +33,7 @@ test("attr(String)", function() { ...@@ -33,7 +33,7 @@ test("attr(String)", function() {
// This one sometimes fails randomly ?! // This one sometimes fails randomly ?!
equals( jQuery('#text1').attr('value'), "Test", 'Check for value attribute' ); equals( jQuery('#text1').attr('value'), "Test", 'Check for value attribute' );
equals( jQuery('#text1').attr('value', "Test2").attr('defaultValue'), "Test", 'Check for defaultValue attribute' ); equals( jQuery('#text1').attr('value', "Test2").attr('defaultValue'), "Test", 'Check for defaultValue attribute' );
equals( jQuery('#text1').attr('type'), "text", 'Check for type attribute' ); equals( jQuery('#text1').attr('type'), "text", 'Check for type attribute' );
equals( jQuery('#radio1').attr('type'), "radio", 'Check for type attribute' ); equals( jQuery('#radio1').attr('type'), "radio", 'Check for type attribute' );
...@@ -255,30 +255,30 @@ test("attr(String, Object)", function() { ...@@ -255,30 +255,30 @@ test("attr(String, Object)", function() {
test("attr(jquery_method)", function(){ test("attr(jquery_method)", function(){
expect(7); expect(7);
var $elem = jQuery("<div />"), var $elem = jQuery("<div />"),
elem = $elem[0]; elem = $elem[0];
// one at a time // one at a time
$elem.attr({'html': 'foo'}, true); $elem.attr({'html': 'foo'}, true);
equals( elem.innerHTML, 'foo', 'attr(html)'); equals( elem.innerHTML, 'foo', 'attr(html)');
$elem.attr({'text': 'bar'}, true); $elem.attr({'text': 'bar'}, true);
equals( elem.innerHTML, 'bar', 'attr(text)'); equals( elem.innerHTML, 'bar', 'attr(text)');
$elem.attr({'css': {color:'red'}}, true); $elem.attr({'css': {color:'red'}}, true);
ok( /^(#ff0000|red)$/i.test(elem.style.color), 'attr(css)'); ok( /^(#ff0000|red)$/i.test(elem.style.color), 'attr(css)');
$elem.attr({'height': 10}, true); $elem.attr({'height': 10}, true);
equals( elem.style.height, '10px', 'attr(height)'); equals( elem.style.height, '10px', 'attr(height)');
// Multiple attributes // Multiple attributes
$elem.attr({ $elem.attr({
width:10, width:10,
css:{ paddingLeft:1, paddingRight:1 } css:{ paddingLeft:1, paddingRight:1 }
}, true); }, true);
equals( elem.style.width, '10px', 'attr({...})'); equals( elem.style.width, '10px', 'attr({...})');
equals( elem.style.paddingLeft, '1px', 'attr({...})'); equals( elem.style.paddingLeft, '1px', 'attr({...})');
equals( elem.style.paddingRight, '1px', 'attr({...})'); equals( elem.style.paddingRight, '1px', 'attr({...})');
...@@ -491,7 +491,7 @@ test( "val(Array of Numbers) (Bug #7123)", function() { ...@@ -491,7 +491,7 @@ test( "val(Array of Numbers) (Bug #7123)", function() {
ok( elements[1].checked, "Second element was checked" ); ok( elements[1].checked, "Second element was checked" );
ok( !elements[2].checked, "Third element was unchecked" ); ok( !elements[2].checked, "Third element was unchecked" );
ok( !elements[3].checked, "Fourth element remained unchecked" ); ok( !elements[3].checked, "Fourth element remained unchecked" );
elements.remove(); elements.remove();
}); });
...@@ -672,7 +672,7 @@ test("removeClass(Function) with incoming value", function() { ...@@ -672,7 +672,7 @@ test("removeClass(Function) with incoming value", function() {
ok( !$divs.is('.test'), "Remove Class" ); ok( !$divs.is('.test'), "Remove Class" );
QUnit.reset(); QUnit.reset();
}); });
var testToggleClass = function(valueObj) { var testToggleClass = function(valueObj) {
...@@ -740,21 +740,21 @@ test("toggleClass(Fucntion[, boolean]) with incoming value", function() { ...@@ -740,21 +740,21 @@ test("toggleClass(Fucntion[, boolean]) with incoming value", function() {
var e = jQuery("#firstp"), old = e.attr("class"); var e = jQuery("#firstp"), old = e.attr("class");
ok( !e.is(".test"), "Assert class not present" ); ok( !e.is(".test"), "Assert class not present" );
e.toggleClass(function(i, val) { e.toggleClass(function(i, val) {
equals( val, old, "Make sure the incoming value is correct." ); equals( val, old, "Make sure the incoming value is correct." );
return "test"; return "test";
}); });
ok( e.is(".test"), "Assert class present" ); ok( e.is(".test"), "Assert class present" );
old = e.attr("class"); old = e.attr("class");
e.toggleClass(function(i, val) { e.toggleClass(function(i, val) {
equals( val, old, "Make sure the incoming value is correct." ); equals( val, old, "Make sure the incoming value is correct." );
return "test"; return "test";
}); });
ok( !e.is(".test"), "Assert class not present" ); ok( !e.is(".test"), "Assert class not present" );
old = e.attr("class"); old = e.attr("class");
// class name with a boolean // class name with a boolean
...@@ -764,18 +764,18 @@ test("toggleClass(Fucntion[, boolean]) with incoming value", function() { ...@@ -764,18 +764,18 @@ test("toggleClass(Fucntion[, boolean]) with incoming value", function() {
return "test"; return "test";
}, false ); }, false );
ok( !e.is(".test"), "Assert class not present" ); ok( !e.is(".test"), "Assert class not present" );
old = e.attr("class"); old = e.attr("class");
e.toggleClass(function(i, val, state) { e.toggleClass(function(i, val, state) {
equals( val, old, "Make sure the incoming value is correct." ); equals( val, old, "Make sure the incoming value is correct." );
equals( state, true, "Make sure that the state is passed in." ); equals( state, true, "Make sure that the state is passed in." );
return "test"; return "test";
}, true ); }, true );
ok( e.is(".test"), "Assert class present" ); ok( e.is(".test"), "Assert class present" );
old = e.attr("class"); old = e.attr("class");
e.toggleClass(function(i, val, state) { e.toggleClass(function(i, val, state) {
equals( val, old, "Make sure the incoming value is correct." ); equals( val, old, "Make sure the incoming value is correct." );
equals( state, false, "Make sure that the state is passed in." ); equals( state, false, "Make sure that the state is passed in." );
...@@ -790,25 +790,25 @@ test("toggleClass(Fucntion[, boolean]) with incoming value", function() { ...@@ -790,25 +790,25 @@ test("toggleClass(Fucntion[, boolean]) with incoming value", function() {
test("addClass, removeClass, hasClass", function() { test("addClass, removeClass, hasClass", function() {
expect(17); expect(17);
var jq = jQuery("<p>Hi</p>"), x = jq[0]; var jq = jQuery("<p>Hi</p>"), x = jq[0];
jq.addClass("hi"); jq.addClass("hi");
equals( x.className, "hi", "Check single added class" ); equals( x.className, "hi", "Check single added class" );
jq.addClass("foo bar"); jq.addClass("foo bar");
equals( x.className, "hi foo bar", "Check more added classes" ); equals( x.className, "hi foo bar", "Check more added classes" );
jq.removeClass(); jq.removeClass();
equals( x.className, "", "Remove all classes" ); equals( x.className, "", "Remove all classes" );
jq.addClass("hi foo bar"); jq.addClass("hi foo bar");
jq.removeClass("foo"); jq.removeClass("foo");
equals( x.className, "hi bar", "Check removal of one class" ); equals( x.className, "hi bar", "Check removal of one class" );
ok( jq.hasClass("hi"), "Check has1" ); ok( jq.hasClass("hi"), "Check has1" );
ok( jq.hasClass("bar"), "Check has2" ); ok( jq.hasClass("bar"), "Check has2" );
var jq = jQuery("<p class='class1\nclass2\tcla.ss3\n\rclass4'></p>"); var jq = jQuery("<p class='class1\nclass2\tcla.ss3\n\rclass4'></p>");
ok( jq.hasClass("class1"), "Check hasClass with line feed" ); ok( jq.hasClass("class1"), "Check hasClass with line feed" );
ok( jq.is(".class1"), "Check is with line feed" ); ok( jq.is(".class1"), "Check is with line feed" );
...@@ -817,7 +817,7 @@ test("addClass, removeClass, hasClass", function() { ...@@ -817,7 +817,7 @@ test("addClass, removeClass, hasClass", function() {
ok( jq.hasClass("cla.ss3"), "Check hasClass with dot" ); ok( jq.hasClass("cla.ss3"), "Check hasClass with dot" );
ok( jq.hasClass("class4"), "Check hasClass with carriage return" ); ok( jq.hasClass("class4"), "Check hasClass with carriage return" );
ok( jq.is(".class4"), "Check is with carriage return" ); ok( jq.is(".class4"), "Check is with carriage return" );
jq.removeClass("class2"); jq.removeClass("class2");
ok( jq.hasClass("class2")==false, "Check the class has been properly removed" ); ok( jq.hasClass("class2")==false, "Check the class has been properly removed" );
jq.removeClass("cla"); jq.removeClass("cla");
......
This diff is collapsed.
...@@ -178,24 +178,24 @@ if ( !jQuery.support.opacity ) { ...@@ -178,24 +178,24 @@ if ( !jQuery.support.opacity ) {
test("css(String, Function)", function() { test("css(String, Function)", function() {
expect(3); expect(3);
var sizes = ["10px", "20px", "30px"]; var sizes = ["10px", "20px", "30px"];
jQuery("<div id='cssFunctionTest'><div class='cssFunction'></div>" + jQuery("<div id='cssFunctionTest'><div class='cssFunction'></div>" +
"<div class='cssFunction'></div>" + "<div class='cssFunction'></div>" +
"<div class='cssFunction'></div></div>") "<div class='cssFunction'></div></div>")
.appendTo("body"); .appendTo("body");
var index = 0; var index = 0;
jQuery("#cssFunctionTest div").css("font-size", function() { jQuery("#cssFunctionTest div").css("font-size", function() {
var size = sizes[index]; var size = sizes[index];
index++; index++;
return size; return size;
}); });
index = 0; index = 0;
jQuery("#cssFunctionTest div").each(function() { jQuery("#cssFunctionTest div").each(function() {
var computedSize = jQuery(this).css("font-size") var computedSize = jQuery(this).css("font-size")
var expectedSize = sizes[index] var expectedSize = sizes[index]
...@@ -208,24 +208,24 @@ test("css(String, Function)", function() { ...@@ -208,24 +208,24 @@ test("css(String, Function)", function() {
test("css(String, Function) with incoming value", function() { test("css(String, Function) with incoming value", function() {
expect(3); expect(3);
var sizes = ["10px", "20px", "30px"]; var sizes = ["10px", "20px", "30px"];
jQuery("<div id='cssFunctionTest'><div class='cssFunction'></div>" + jQuery("<div id='cssFunctionTest'><div class='cssFunction'></div>" +
"<div class='cssFunction'></div>" + "<div class='cssFunction'></div>" +
"<div class='cssFunction'></div></div>") "<div class='cssFunction'></div></div>")
.appendTo("body"); .appendTo("body");
var index = 0; var index = 0;
jQuery("#cssFunctionTest div").css("font-size", function() { jQuery("#cssFunctionTest div").css("font-size", function() {
var size = sizes[index]; var size = sizes[index];
index++; index++;
return size; return size;
}); });
index = 0; index = 0;
jQuery("#cssFunctionTest div").css("font-size", function(i, computedSize) { jQuery("#cssFunctionTest div").css("font-size", function(i, computedSize) {
var expectedSize = sizes[index] var expectedSize = sizes[index]
equals( computedSize, expectedSize, "Div #" + index + " should be " + expectedSize ); equals( computedSize, expectedSize, "Div #" + index + " should be " + expectedSize );
...@@ -238,61 +238,61 @@ test("css(String, Function) with incoming value", function() { ...@@ -238,61 +238,61 @@ test("css(String, Function) with incoming value", function() {
test("css(Object) where values are Functions", function() { test("css(Object) where values are Functions", function() {
expect(3); expect(3);
var sizes = ["10px", "20px", "30px"]; var sizes = ["10px", "20px", "30px"];
jQuery("<div id='cssFunctionTest'><div class='cssFunction'></div>" + jQuery("<div id='cssFunctionTest'><div class='cssFunction'></div>" +
"<div class='cssFunction'></div>" + "<div class='cssFunction'></div>" +
"<div class='cssFunction'></div></div>") "<div class='cssFunction'></div></div>")
.appendTo("body"); .appendTo("body");
var index = 0; var index = 0;
jQuery("#cssFunctionTest div").css({fontSize: function() { jQuery("#cssFunctionTest div").css({fontSize: function() {
var size = sizes[index]; var size = sizes[index];
index++; index++;
return size; return size;
}}); }});
index = 0; index = 0;
jQuery("#cssFunctionTest div").each(function() { jQuery("#cssFunctionTest div").each(function() {
var computedSize = jQuery(this).css("font-size") var computedSize = jQuery(this).css("font-size")
var expectedSize = sizes[index] var expectedSize = sizes[index]
equals( computedSize, expectedSize, "Div #" + index + " should be " + expectedSize ); equals( computedSize, expectedSize, "Div #" + index + " should be " + expectedSize );
index++; index++;
}); });
jQuery("#cssFunctionTest").remove(); jQuery("#cssFunctionTest").remove();
}); });
test("css(Object) where values are Functions with incoming values", function() { test("css(Object) where values are Functions with incoming values", function() {
expect(3); expect(3);
var sizes = ["10px", "20px", "30px"]; var sizes = ["10px", "20px", "30px"];
jQuery("<div id='cssFunctionTest'><div class='cssFunction'></div>" + jQuery("<div id='cssFunctionTest'><div class='cssFunction'></div>" +
"<div class='cssFunction'></div>" + "<div class='cssFunction'></div>" +
"<div class='cssFunction'></div></div>") "<div class='cssFunction'></div></div>")
.appendTo("body"); .appendTo("body");
var index = 0; var index = 0;
jQuery("#cssFunctionTest div").css({fontSize: function() { jQuery("#cssFunctionTest div").css({fontSize: function() {
var size = sizes[index]; var size = sizes[index];
index++; index++;
return size; return size;
}}); }});
index = 0; index = 0;
jQuery("#cssFunctionTest div").css({"font-size": function(i, computedSize) { jQuery("#cssFunctionTest div").css({"font-size": function(i, computedSize) {
var expectedSize = sizes[index] var expectedSize = sizes[index]
equals( computedSize, expectedSize, "Div #" + index + " should be " + expectedSize ); equals( computedSize, expectedSize, "Div #" + index + " should be " + expectedSize );
index++; index++;
return computedSize; return computedSize;
}}); }});
jQuery("#cssFunctionTest").remove(); jQuery("#cssFunctionTest").remove();
}); });
......
...@@ -78,6 +78,21 @@ test("jQuery.data", function() { ...@@ -78,6 +78,21 @@ test("jQuery.data", function() {
ok( jQuery.data( window, "BAD" ), "Make sure that the value was set." ); ok( jQuery.data( window, "BAD" ), "Make sure that the value was set." );
}); });
test("jQuery.hasData", function() {
expect(6);
function testData(obj) {
equals( jQuery.hasData(obj), false, "No data exists" );
jQuery.data( obj, "foo", "bar" );
equals( jQuery.hasData(obj), true, "Data exists" );
jQuery.removeData( obj, "foo" );
equals( jQuery.hasData(obj), false, "Data was removed" );
}
testData(document.createElement('div'));
testData({});
});
test(".data()", function() { test(".data()", function() {
expect(5); expect(5);
...@@ -180,7 +195,7 @@ test(".data(String) and .data(String, Object)", function() { ...@@ -180,7 +195,7 @@ test(".data(String) and .data(String, Object)", function() {
equals( $elem.data('emptyString','').data('emptyString'), '', "Empty strings are preserved"); equals( $elem.data('emptyString','').data('emptyString'), '', "Empty strings are preserved");
equals( $elem.data('false',false).data('false'), false, "false's are preserved"); equals( $elem.data('false',false).data('false'), false, "false's are preserved");
equals( $elem.data('exists'), true, "Existing data is returned" ); equals( $elem.data('exists'), true, "Existing data is returned" );
// Clean up // Clean up
$elem.removeData(); $elem.removeData();
ok( jQuery.isEmptyObject( $elem[0] ), "removeData clears the object" ); ok( jQuery.isEmptyObject( $elem[0] ), "removeData clears the object" );
...@@ -191,7 +206,7 @@ test("data-* attributes", function() { ...@@ -191,7 +206,7 @@ test("data-* attributes", function() {
var div = jQuery("<div>"), var div = jQuery("<div>"),
child = jQuery("<div data-myobj='old data' data-ignored=\"DOM\" data-other='test'></div>"), child = jQuery("<div data-myobj='old data' data-ignored=\"DOM\" data-other='test'></div>"),
dummy = jQuery("<div data-myobj='old data' data-ignored=\"DOM\" data-other='test'></div>"); dummy = jQuery("<div data-myobj='old data' data-ignored=\"DOM\" data-other='test'></div>");
equals( div.data("attr"), undefined, "Check for non-existing data-attr attribute" ); equals( div.data("attr"), undefined, "Check for non-existing data-attr attribute" );
div.attr("data-attr", "exists"); div.attr("data-attr", "exists");
...@@ -199,10 +214,10 @@ test("data-* attributes", function() { ...@@ -199,10 +214,10 @@ test("data-* attributes", function() {
div.attr("data-attr", "exists2"); div.attr("data-attr", "exists2");
equals( div.data("attr"), "exists", "Check that updates to data- don't update .data()" ); equals( div.data("attr"), "exists", "Check that updates to data- don't update .data()" );
div.data("attr", "internal").attr("data-attr", "external"); div.data("attr", "internal").attr("data-attr", "external");
equals( div.data("attr"), "internal", "Check for .data('attr') precedence (internal > external data-* attribute)" ); equals( div.data("attr"), "internal", "Check for .data('attr') precedence (internal > external data-* attribute)" );
child.appendTo('#main'); child.appendTo('#main');
equals( child.data("myobj"), "old data", "Value accessed from data-* attribute"); equals( child.data("myobj"), "old data", "Value accessed from data-* attribute");
...@@ -249,7 +264,7 @@ test("data-* attributes", function() { ...@@ -249,7 +264,7 @@ test("data-* attributes", function() {
.attr("data-space", " ") .attr("data-space", " ")
.attr("data-null", "null") .attr("data-null", "null")
.attr("data-string", "test"); .attr("data-string", "test");
strictEqual( child.data('true'), true, "Primitive true read from attribute"); strictEqual( child.data('true'), true, "Primitive true read from attribute");
strictEqual( child.data('false'), false, "Primitive false read from attribute"); strictEqual( child.data('false'), false, "Primitive false read from attribute");
strictEqual( child.data('five'), 5, "Primitive number read from attribute"); strictEqual( child.data('five'), 5, "Primitive number read from attribute");
...@@ -265,7 +280,7 @@ test("data-* attributes", function() { ...@@ -265,7 +280,7 @@ test("data-* attributes", function() {
strictEqual( child.data('string'), "test", "Typical string read from attribute"); strictEqual( child.data('string'), "test", "Typical string read from attribute");
child.remove(); child.remove();
// tests from metadata plugin // tests from metadata plugin
function testData(index, elem) { function testData(index, elem) {
switch (index) { switch (index) {
...@@ -289,10 +304,10 @@ test("data-* attributes", function() { ...@@ -289,10 +304,10 @@ test("data-* attributes", function() {
ok(false, ["Assertion failed on index ", index, ", with data ", data].join('')); ok(false, ["Assertion failed on index ", index, ", with data ", data].join(''));
} }
} }
var metadata = '<ol><li class="test test2" data-foo="bar" data-bar="baz" data-arr="[1,2]">Some stuff</li><li class="test test2" data-test="bar" data-bar="baz">Some stuff</li><li class="test test2" data-zoooo="bar" data-bar=\'{"test":"baz"}\'>Some stuff</li><li class="test test2" data-number=true data-stuff="[2,8]">Some stuff</li></ol>', var metadata = '<ol><li class="test test2" data-foo="bar" data-bar="baz" data-arr="[1,2]">Some stuff</li><li class="test test2" data-test="bar" data-bar="baz">Some stuff</li><li class="test test2" data-zoooo="bar" data-bar=\'{"test":"baz"}\'>Some stuff</li><li class="test test2" data-number=true data-stuff="[2,8]">Some stuff</li></ol>',
elem = jQuery(metadata).appendTo('#main'); elem = jQuery(metadata).appendTo('#main');
elem.find("li").each(testData); elem.find("li").each(testData);
elem.remove(); elem.remove();
}); });
...@@ -305,12 +320,12 @@ test(".data(Object)", function() { ...@@ -305,12 +320,12 @@ test(".data(Object)", function() {
div.data({ "test": "in", "test2": "in2" }); div.data({ "test": "in", "test2": "in2" });
equals( div.data("test"), "in", "Verify setting an object in data" ); equals( div.data("test"), "in", "Verify setting an object in data" );
equals( div.data("test2"), "in2", "Verify setting an object in data" ); equals( div.data("test2"), "in2", "Verify setting an object in data" );
var obj = {test:"unset"}, var obj = {test:"unset"},
jqobj = jQuery(obj); jqobj = jQuery(obj);
jqobj.data({ "test": "in", "test2": "in2" }); jqobj.data({ "test": "in", "test2": "in2" });
equals( obj.test, "in", "Verify setting an object on an object extends the object" ); equals( obj.test, "in", "Verify setting an object on an object extends the object" );
equals( obj.test2, "in2", "Verify setting an object on an object extends the object" ); equals( obj.test2, "in2", "Verify setting an object on an object extends the object" );
}); });
test("jQuery.removeData", function() { test("jQuery.removeData", function() {
...@@ -324,13 +339,13 @@ test("jQuery.removeData", function() { ...@@ -324,13 +339,13 @@ test("jQuery.removeData", function() {
jQuery.removeData( div ); jQuery.removeData( div );
ok( !jQuery.data(div, "test2"), "Make sure that the data property no longer exists." ); ok( !jQuery.data(div, "test2"), "Make sure that the data property no longer exists." );
ok( !div[ jQuery.expando ], "Make sure the expando no longer exists, as well." ); ok( !div[ jQuery.expando ], "Make sure the expando no longer exists, as well." );
var obj = {}; var obj = {};
jQuery.data(obj, "test", "testing"); jQuery.data(obj, "test", "testing");
equals( obj.test, "testing", "verify data on plain object"); equals( obj.test, "testing", "verify data on plain object");
jQuery.removeData(obj, "test"); jQuery.removeData(obj, "test");
equals( jQuery.data(obj, "test"), undefined, "Check removal of data on plain object" ); equals( jQuery.data(obj, "test"), undefined, "Check removal of data on plain object" );
equals( obj.test, undefined, "Check removal of data directly from plain object" ); equals( obj.test, undefined, "Check removal of data directly from plain object" );
jQuery.data( window, "BAD", true ); jQuery.data( window, "BAD", true );
jQuery.removeData( window, "BAD" ); jQuery.removeData( window, "BAD" );
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment