Merge branch 'master' of http://github.com/jquery/jquery into effectsCleanup

This commit is contained in:
louisremi 2011-04-14 11:46:29 +02:00
commit 8806435a77
27 changed files with 1556 additions and 1284 deletions

View file

@ -111,7 +111,7 @@ update_submodules:
# update the submodules to the latest at the most logical branch # update the submodules to the latest at the most logical branch
pull_submodules: pull_submodules:
@@git submodule foreach "git pull origin \$$(git branch --no-color --contains \$$(git rev-parse HEAD) | grep -v \( | head -1)" @@git submodule foreach "git pull \$$(git config remote.origin.url)"
@@git submodule summary @@git submodule summary
pull: pull_submodules pull: pull_submodules

View file

@ -63,7 +63,7 @@ As the source code is handled by the version control system Git, it's useful to
### Submodules ### ### Submodules ###
The repository uses submodules, which normally are handles directly by the Makefile, but sometimes you want to The repository uses submodules, which normally are handled directly by the Makefile, but sometimes you want to
be able to work with them manually. be able to work with them manually.
Following are the steps to manually get the submodules: Following are the steps to manually get the submodules:
@ -86,7 +86,7 @@ If you want to work inside a submodule, it is possible, but first you need to ch
1. `cd src/sizzle` 1. `cd src/sizzle`
2. `git checkout master` 2. `git checkout master`
After you've commited your changes to the submodule, you'll update the jquery project to point to the new commit, After you've committed your changes to the submodule, you'll update the jquery project to point to the new commit,
but remember to push the submodule changes before pushing the new jquery commit: but remember to push the submodule changes before pushing the new jquery commit:
1. `cd src/sizzle` 1. `cd src/sizzle`
@ -99,12 +99,12 @@ The makefile has some targets to simplify submodule handling:
#### `make update_submodules` #### #### `make update_submodules` ####
checks out the commit pointed to byu jquery, but merges your local changes, if any. This target is executed checks out the commit pointed to by jquery, but merges your local changes, if any. This target is executed
when you are doing a normal `make`. when you are doing a normal `make`.
#### `make pull_submodules` #### #### `make pull_submodules` ####
updates the content of the submoduels to what is probably the latest upstream code updates the content of the submodules to what is probably the latest upstream code.
#### `make pull` #### #### `make pull` ####

View file

@ -14,13 +14,12 @@ jQuery.ajaxSetup({
// Detect, normalize options and install callbacks for jsonp requests // Detect, normalize options and install callbacks for jsonp requests
jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) { jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) {
var dataIsString = ( typeof s.data === "string" ); var inspectData = s.contentType === "application/x-www-form-urlencoded" &&
( typeof s.data === "string" );
if ( s.dataTypes[ 0 ] === "jsonp" || if ( s.dataTypes[ 0 ] === "jsonp" ||
originalSettings.jsonpCallback ||
originalSettings.jsonp != null ||
s.jsonp !== false && ( jsre.test( s.url ) || s.jsonp !== false && ( jsre.test( s.url ) ||
dataIsString && jsre.test( s.data ) ) ) { inspectData && jsre.test( s.data ) ) ) {
var responseContainer, var responseContainer,
jsonpCallback = s.jsonpCallback = jsonpCallback = s.jsonpCallback =
@ -28,20 +27,12 @@ jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) {
previous = window[ jsonpCallback ], previous = window[ jsonpCallback ],
url = s.url, url = s.url,
data = s.data, data = s.data,
replace = "$1" + jsonpCallback + "$2", replace = "$1" + jsonpCallback + "$2";
cleanUp = function() {
// Set callback back to previous value
window[ jsonpCallback ] = previous;
// Call if it was a function and we have a response
if ( responseContainer && jQuery.isFunction( previous ) ) {
window[ jsonpCallback ]( responseContainer[ 0 ] );
}
};
if ( s.jsonp !== false ) { if ( s.jsonp !== false ) {
url = url.replace( jsre, replace ); url = url.replace( jsre, replace );
if ( s.url === url ) { if ( s.url === url ) {
if ( dataIsString ) { if ( inspectData ) {
data = data.replace( jsre, replace ); data = data.replace( jsre, replace );
} }
if ( s.data === data ) { if ( s.data === data ) {
@ -59,8 +50,15 @@ jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) {
responseContainer = [ response ]; responseContainer = [ response ];
}; };
// Install cleanUp function // Clean-up function
jqXHR.then( cleanUp, cleanUp ); jqXHR.always(function() {
// Set callback back to previous value
window[ jsonpCallback ] = previous;
// Call if it was a function and we have a response
if ( responseContainer && jQuery.isFunction( previous ) ) {
window[ jsonpCallback ]( responseContainer[ 0 ] );
}
});
// Use data converter to retrieve json after script execution // Use data converter to retrieve json after script execution
s.converters["script json"] = function() { s.converters["script json"] = function() {

View file

@ -479,7 +479,7 @@ jQuery.each([ "selected", "checked", "readOnly", "disabled" ], function( i, name
// Some attributes require a special call on IE // Some attributes require a special call on IE
if ( !jQuery.support.hrefNormalized ) { if ( !jQuery.support.hrefNormalized ) {
jQuery.each([ "href", "src", "width", "height", "list" ], function( i, name ) { jQuery.each([ "href", "src", "width", "height" ], function( i, name ) {
jQuery.attrHooks[ name ] = jQuery.extend( jQuery.attrHooks[ name ], { jQuery.attrHooks[ name ] = jQuery.extend( jQuery.attrHooks[ name ], {
get: function( elem ) { get: function( elem ) {
var ret = elem.getAttribute( name, 2 ); var ret = elem.getAttribute( name, 2 );

View file

@ -358,9 +358,11 @@ jQuery.extend = jQuery.fn.extend = function() {
jQuery.extend({ jQuery.extend({
noConflict: function( deep ) { noConflict: function( deep ) {
window.$ = _$; if ( window.$ === jQuery ) {
window.$ = _$;
}
if ( deep ) { if ( deep && window.jQuery === jQuery ) {
window.jQuery = _jQuery; window.jQuery = _jQuery;
} }
@ -436,7 +438,7 @@ jQuery.extend({
} else if ( document.attachEvent ) { } else if ( document.attachEvent ) {
// ensure firing before onload, // ensure firing before onload,
// maybe late but safe also for iframes // maybe late but safe also for iframes
document.attachEvent("onreadystatechange", DOMContentLoaded); document.attachEvent( "onreadystatechange", DOMContentLoaded );
// A fallback to window.onload, that will always work // A fallback to window.onload, that will always work
window.attachEvent( "onload", jQuery.ready ); window.attachEvent( "onload", jQuery.ready );
@ -587,7 +589,7 @@ jQuery.extend({
each: function( object, callback, args ) { each: function( object, callback, args ) {
var name, i = 0, var name, i = 0,
length = object.length, length = object.length,
isObj = length === undefined || jQuery.isFunction(object); isObj = length === undefined || jQuery.isFunction( object );
if ( args ) { if ( args ) {
if ( isObj ) { if ( isObj ) {
@ -613,8 +615,11 @@ jQuery.extend({
} }
} }
} else { } else {
for ( var value = object[0]; for ( ; i < length; ) {
i < length && callback.call( value, i, value ) !== false; value = object[++i] ) {} if ( callback.call( object[ i ], i, object[ i++ ] ) === false ) {
break;
}
}
} }
} }
@ -645,7 +650,7 @@ jQuery.extend({
// The extra typeof function check is to prevent crashes // The extra typeof function check is to prevent crashes
// in Safari 2 (See: #3039) // in Safari 2 (See: #3039)
// Tweaked logic slightly to handle Blackberry 4.7 RegExp issues #6930 // Tweaked logic slightly to handle Blackberry 4.7 RegExp issues #6930
var type = jQuery.type(array); var type = jQuery.type( array );
if ( array.length == null || type === "string" || type === "function" || type === "regexp" || jQuery.isWindow( array ) ) { if ( array.length == null || type === "string" || type === "function" || type === "regexp" || jQuery.isWindow( array ) ) {
push.call( ret, array ); push.call( ret, array );
@ -841,24 +846,24 @@ jQuery.extend({
}, },
sub: function() { sub: function() {
function jQuerySubclass( selector, context ) { function jQuerySub( selector, context ) {
return new jQuerySubclass.fn.init( selector, context ); return new jQuerySub.fn.init( selector, context );
} }
jQuery.extend( true, jQuerySubclass, this ); jQuery.extend( true, jQuerySub, this );
jQuerySubclass.superclass = this; jQuerySub.superclass = this;
jQuerySubclass.fn = jQuerySubclass.prototype = this(); jQuerySub.fn = jQuerySub.prototype = this();
jQuerySubclass.fn.constructor = jQuerySubclass; jQuerySub.fn.constructor = jQuerySub;
jQuerySubclass.subclass = this.subclass; jQuerySub.sub = this.sub;
jQuerySubclass.fn.init = function init( selector, context ) { jQuerySub.fn.init = function init( selector, context ) {
if ( context && context instanceof jQuery && !(context instanceof jQuerySubclass) ) { if ( context && context instanceof jQuery && !(context instanceof jQuerySub) ) {
context = jQuerySubclass(context); context = jQuerySub( context );
} }
return jQuery.fn.init.call( this, selector, context, rootjQuerySubclass ); return jQuery.fn.init.call( this, selector, context, rootjQuerySub );
}; };
jQuerySubclass.fn.init.prototype = jQuerySubclass.fn; jQuerySub.fn.init.prototype = jQuerySub.fn;
var rootjQuerySubclass = jQuerySubclass(document); var rootjQuerySub = jQuerySub(document);
return jQuerySubclass; return jQuerySub;
}, },
browser: {} browser: {}

View file

@ -93,7 +93,7 @@ jQuery.extend({
// convert relative number strings (+= or -=) to relative numbers. #7345 // convert relative number strings (+= or -=) to relative numbers. #7345
if ( type === "string" && rrelNum.test( value ) ) { if ( type === "string" && rrelNum.test( value ) ) {
value = +value.replace( rrelNumFilter, '' ) + parseFloat( jQuery.css( elem, name ) ); value = +value.replace( rrelNumFilter, "" ) + parseFloat( jQuery.css( elem, name ) );
} }
// If a number was passed in, add 'px' to the (except for certain CSS properties) // If a number was passed in, add 'px' to the (except for certain CSS properties)
@ -122,11 +122,17 @@ jQuery.extend({
}, },
css: function( elem, name, extra ) { css: function( elem, name, extra ) {
// Make sure that we're working with the right name var ret, hooks;
var ret, origName = jQuery.camelCase( name ),
hooks = jQuery.cssHooks[ origName ];
name = jQuery.cssProps[ origName ] || origName; // Make sure that we're working with the right name
name = jQuery.camelCase( name );
hooks = jQuery.cssHooks[ name ];
name = jQuery.cssProps[ name ] || name;
// cssFloat needs a special treatment
if ( name === "cssFloat" ) {
name = "float";
}
// If a hook was provided get the computed value from there // If a hook was provided get the computed value from there
if ( hooks && "get" in hooks && (ret = hooks.get( elem, true, extra )) !== undefined ) { if ( hooks && "get" in hooks && (ret = hooks.get( elem, true, extra )) !== undefined ) {
@ -134,7 +140,7 @@ jQuery.extend({
// Otherwise, if a way to get the computed value exists, use that // Otherwise, if a way to get the computed value exists, use that
} else if ( curCSS ) { } else if ( curCSS ) {
return curCSS( elem, name, origName ); return curCSS( elem, name );
} }
}, },
@ -225,27 +231,28 @@ if ( !jQuery.support.opacity ) {
jQuery.cssHooks.opacity = { jQuery.cssHooks.opacity = {
get: function( elem, computed ) { get: function( elem, computed ) {
// IE uses filters for opacity // IE uses filters for opacity
return ropacity.test((computed && elem.currentStyle ? elem.currentStyle.filter : elem.style.filter) || "") ? return ropacity.test( (computed && elem.currentStyle ? elem.currentStyle.filter : elem.style.filter) || "" ) ?
(parseFloat(RegExp.$1) / 100) + "" : ( parseFloat( RegExp.$1 ) / 100 ) + "" :
computed ? "1" : ""; computed ? "1" : "";
}, },
set: function( elem, value ) { set: function( elem, value ) {
var style = elem.style; var style = elem.style,
currentStyle = elem.currentStyle;
// IE has trouble with opacity if it does not have layout // IE has trouble with opacity if it does not have layout
// Force it by setting the zoom level // Force it by setting the zoom level
style.zoom = 1; style.zoom = 1;
// Set the alpha filter to set the opacity // Set the alpha filter to set the opacity
var opacity = jQuery.isNaN(value) ? var opacity = jQuery.isNaN( value ) ?
"" : "" :
"alpha(opacity=" + value * 100 + ")", "alpha(opacity=" + value * 100 + ")",
filter = style.filter || ""; filter = currentStyle && currentStyle.filter || style.filter || "";
style.filter = ralpha.test(filter) ? style.filter = ralpha.test( filter ) ?
filter.replace(ralpha, opacity) : filter.replace( ralpha, opacity ) :
style.filter + ' ' + opacity; filter + " " + opacity;
} }
}; };
} }
@ -273,7 +280,7 @@ jQuery(function() {
}); });
if ( document.defaultView && document.defaultView.getComputedStyle ) { if ( document.defaultView && document.defaultView.getComputedStyle ) {
getComputedStyle = function( elem, newName, name ) { getComputedStyle = function( elem, name ) {
var ret, defaultView, computedStyle; var ret, defaultView, computedStyle;
name = name.replace( rupper, "-$1" ).toLowerCase(); name = name.replace( rupper, "-$1" ).toLowerCase();

17
src/effects.js vendored
View file

@ -152,13 +152,17 @@ jQuery.fn.extend({
var optall = jQuery.speed(speed, easing, callback); var optall = jQuery.speed(speed, easing, callback);
if ( jQuery.isEmptyObject( prop ) ) { if ( jQuery.isEmptyObject( prop ) ) {
return this.each( optall.complete ); return this.each( optall.complete, [ false ] );
} }
return this[ optall.queue === false ? "each" : "queue" ](function() { return this[ optall.queue === false ? "each" : "queue" ](function() {
// XXX 'this' does not always have a nodeName when running the // XXX 'this' does not always have a nodeName when running the
// test suite // test suite
if ( optall.queue === false ) {
jQuery._mark( this );
}
var opt = jQuery.extend({}, optall), p, var opt = jQuery.extend({}, optall), p,
isElement = this.nodeType === 1, isElement = this.nodeType === 1,
hidden = isElement && jQuery(this).is(":hidden"), hidden = isElement && jQuery(this).is(":hidden"),
@ -268,6 +272,10 @@ jQuery.fn.extend({
} }
this.each(function() { this.each(function() {
// clear marker counters if we know they won't be
if ( !gotoEnd ) {
jQuery._unmark( true, this );
}
// go in reverse order so anything added to the queue during the loop is ignored // go in reverse order so anything added to the queue during the loop is ignored
for ( var i = timers.length - 1; i >= 0; i-- ) { for ( var i = timers.length - 1; i >= 0; i-- ) {
if ( timers[i].elem === this ) { if ( timers[i].elem === this ) {
@ -319,10 +327,13 @@ jQuery.extend({
// Queueing // Queueing
opt.old = opt.complete; opt.old = opt.complete;
opt.complete = function() { opt.complete = function( noUnmark ) {
if ( opt.queue !== false ) { if ( opt.queue !== false ) {
jQuery(this).dequeue(); jQuery.dequeue( this );
} else if ( noUnmark !== false ) {
jQuery._unmark( this );
} }
if ( jQuery.isFunction( opt.old ) ) { if ( jQuery.isFunction( opt.old ) ) {
opt.old.call( this ); opt.old.call( this );
} }

View file

@ -24,17 +24,6 @@ jQuery.event = {
return; return;
} }
// TODO :: Use a try/catch until it's safe to pull this out (likely 1.6)
// Minor release fix for bug #8018
try {
// For whatever reason, IE has trouble passing the window object
// around, causing it to be cloned in the process
if ( jQuery.isWindow( elem ) && ( elem !== window && !elem.frameElement ) ) {
elem = window;
}
}
catch ( e ) {}
if ( handler === false ) { if ( handler === false ) {
handler = returnFalse; handler = returnFalse;
} else if ( !handler ) { } else if ( !handler ) {
@ -277,34 +266,53 @@ jQuery.event = {
} }
} }
}, },
// Events that are safe to short-circuit if no handlers are attached.
// Native DOM events should not be added, they may have inline handlers.
customEvent: {
"getData": true,
"setData": true,
"changeData": true
},
trigger: function( event, data, elem ) { trigger: function( event, data, elem ) {
// Event object or event type // Event object or event type
var type = event.type || event, var type = event.type || event,
namespaces = []; namespaces = [],
exclusive;
if ( type.indexOf("!") >= 0 ) {
// Exclusive events trigger only for the exact event (no namespaces)
type = type.slice(0, -1);
exclusive = true;
}
if ( type.indexOf(".") >= 0 ) {
// Namespaced trigger; create a regexp to match event type in handle()
namespaces = type.split(".");
type = namespaces.shift();
namespaces.sort();
}
if ( jQuery.event.customEvent[ type ] && !jQuery.event.global[ type ] ) {
// No jQuery handlers for this event type, and it can't have inline handlers
return;
}
// Caller can pass in an Event, Object, or just an event type string
event = typeof event === "object" ? event = typeof event === "object" ?
// jQuery.Event object // jQuery.Event object
event[ jQuery.expando ] ? event : event[ jQuery.expando ] ? event :
// Object literal // Object literal
jQuery.extend( jQuery.Event(type), event ) : new jQuery.Event( type, event ) :
// Just the event type (string) // Just the event type (string)
jQuery.Event(type); new jQuery.Event( type );
if ( type.indexOf("!") >= 0 ) { event.type = type;
// Exclusive events trigger only for the bare event type (no namespaces)
event.type = type = type.slice(0, -1);
event.exclusive = true;
}
if ( type.indexOf(".") >= 0 ) {
// Namespaced trigger; create a regexp to match event type in handle()
namespaces = type.split(".");
event.type = type = namespaces.shift();
namespaces.sort();
}
event.namespace = namespaces.join("."); event.namespace = namespaces.join(".");
event.namespace_re = new RegExp("(^|\\.)" + namespaces.join("\\.(?:.*\\.)?") + "(\\.|$)"); event.namespace_re = new RegExp("(^|\\.)" + namespaces.join("\\.(?:.*\\.)?") + "(\\.|$)");
event.exclusive = exclusive;
// Handle a global trigger // Handle a global trigger
if ( !elem ) { if ( !elem ) {
// Don't bubble custom events when global (to avoid too much overhead) // Don't bubble custom events when global (to avoid too much overhead)
@ -338,12 +346,12 @@ jQuery.event = {
event.target = elem; event.target = elem;
// Clone any incoming data and prepend the event, creating the handler arg list // Clone any incoming data and prepend the event, creating the handler arg list
data = jQuery.makeArray( data ); data = data ? jQuery.makeArray( data ) : [];
data.unshift( event ); data.unshift( event );
var cur = elem, var cur = elem,
// IE doesn't like method names with a colon (#3533, #8272) // IE doesn't like method names with a colon (#3533, #8272)
ontype = type.indexOf(":") < 0? "on" + type : ""; ontype = type.indexOf(":") < 0 ? "on" + type : "";
// Fire event on the current element, then bubble up the DOM tree // Fire event on the current element, then bubble up the DOM tree
do { do {
@ -355,7 +363,7 @@ jQuery.event = {
} }
// Trigger an inline bound script // Trigger an inline bound script
if ( ontype &&jQuery.acceptData( cur ) && cur[ ontype ] && cur[ ontype ].apply( cur, data ) === false ) { if ( ontype && jQuery.acceptData( cur ) && cur[ ontype ] && cur[ ontype ].apply( cur, data ) === false ) {
event.result = false; event.result = false;
event.preventDefault(); event.preventDefault();
} }
@ -403,7 +411,7 @@ jQuery.event = {
// Snapshot the handlers list since a called handler may add/remove events. // Snapshot the handlers list since a called handler may add/remove events.
var handlers = ((jQuery._data( this, "events" ) || {})[ event.type ] || []).slice(0), var handlers = ((jQuery._data( this, "events" ) || {})[ event.type ] || []).slice(0),
run_all = !event.exclusive && !event.namespace, run_all = !event.exclusive && !event.namespace,
args = jQuery.makeArray( arguments ); args = Array.prototype.slice.call( arguments, 0 );
// Use the fix-ed Event rather than the (read-only) native event // Use the fix-ed Event rather than the (read-only) native event
args[0] = event; args[0] = event;
@ -555,24 +563,16 @@ jQuery.removeEvent = document.removeEventListener ?
} }
}; };
jQuery.Event = function( src ) { jQuery.Event = function( src, props ) {
// Allow instantiation without the 'new' keyword // Allow instantiation without the 'new' keyword
if ( !this.preventDefault ) { if ( !this.preventDefault ) {
return new jQuery.Event( src ); return new jQuery.Event( src, props );
} }
// Event object // Event object
if ( src && src.type ) { if ( src && src.type ) {
this.originalEvent = src; this.originalEvent = src;
this.type = src.type;
// Push explicitly provided properties onto the event object
for ( var prop in src ) {
// Ensure we don't clobber jQuery.Event prototype
// with own properties.
if ( hasOwn.call( src, prop ) ) {
this[ prop ] = src[ prop ];
}
}
// Events bubbling up the document may have been marked as prevented // Events bubbling up the document may have been marked as prevented
// by a handler lower down the tree; reflect the correct value. // by a handler lower down the tree; reflect the correct value.
@ -584,6 +584,11 @@ jQuery.Event = function( src ) {
this.type = src; this.type = src;
} }
// Put explicitly provided properties onto the event object
if ( props ) {
jQuery.extend( this, props );
}
// timeStamp is buggy for some events on Firefox(#3843) // timeStamp is buggy for some events on Firefox(#3843)
// So we won't rely on the native value // So we won't rely on the native value
this.timeStamp = jQuery.now(); this.timeStamp = jQuery.now();
@ -790,7 +795,7 @@ if ( !jQuery.support.changeBubbles ) {
beforedeactivate: testChange, beforedeactivate: testChange,
click: function( e ) { click: function( e ) {
var elem = e.target, type = elem.type; var elem = e.target, type = jQuery.nodeName( elem, "input" ) ? elem.type : "";
if ( type === "radio" || type === "checkbox" || elem.nodeName.toLowerCase() === "select" ) { if ( type === "radio" || type === "checkbox" || elem.nodeName.toLowerCase() === "select" ) {
testChange.call( this, e ); testChange.call( this, e );
@ -800,7 +805,7 @@ if ( !jQuery.support.changeBubbles ) {
// Change has to be called before submit // Change has to be called before submit
// Keydown will be called before keypress, which is used in submit-event delegation // Keydown will be called before keypress, which is used in submit-event delegation
keydown: function( e ) { keydown: function( e ) {
var elem = e.target, type = elem.type; var elem = e.target, type = jQuery.nodeName( elem, "input" ) ? elem.type : "";
if ( (e.keyCode === 13 && elem.nodeName.toLowerCase() !== "textarea") || if ( (e.keyCode === 13 && elem.nodeName.toLowerCase() !== "textarea") ||
(e.keyCode === 32 && (type === "checkbox" || type === "radio")) || (e.keyCode === 32 && (type === "checkbox" || type === "radio")) ||
@ -955,7 +960,7 @@ jQuery.fn.extend({
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 );
@ -970,7 +975,7 @@ jQuery.fn.extend({
triggerHandler: function( type, data ) { triggerHandler: function( type, data ) {
if ( this[0] ) { if ( this[0] ) {
var event = jQuery.Event( type ); var event = new jQuery.Event( type );
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
jQuery.event.trigger( event, data, this[0] ); jQuery.event.trigger( event, data, this[0] );
@ -1030,10 +1035,18 @@ jQuery.each(["live", "die"], function( i, name ) {
return this; return this;
} }
if ( name === "die" && !types &&
origSelector && origSelector.charAt(0) === "." ) {
context.unbind( origSelector );
return this;
}
if ( data === false || jQuery.isFunction( data ) ) { if ( data === false || jQuery.isFunction( data ) ) {
fn = data || returnFalse; fn = data || returnFalse;
data = undefined; data = undefined;
} }
types = (types || "").split(" "); types = (types || "").split(" ");

View file

@ -9,6 +9,7 @@ var rinlinejQuery = / jQuery\d+="(?:\d+|null)"/g,
rnocache = /<(?:script|object|embed|option|style)/i, rnocache = /<(?:script|object|embed|option|style)/i,
// checked="checked" or checked // checked="checked" or checked
rchecked = /checked\s*(?:[^=]|=\s*.checked.)/i, rchecked = /checked\s*(?:[^=]|=\s*.checked.)/i,
rscriptType = /\/(java|ecma)script/i,
wrapMap = { wrapMap = {
option: [ 1, "<select multiple='multiple'>", "</select>" ], option: [ 1, "<select multiple='multiple'>", "</select>" ],
legend: [ 1, "<fieldset>", "</fieldset>" ], legend: [ 1, "<fieldset>", "</fieldset>" ],
@ -387,11 +388,15 @@ function cloneFixAttributes( src, dest ) {
// clearAttributes removes the attributes, which we don't want, // clearAttributes removes the attributes, which we don't want,
// but also removes the attachEvent events, which we *do* want // but also removes the attachEvent events, which we *do* want
dest.clearAttributes(); if ( dest.clearAttributes ) {
dest.clearAttributes();
}
// mergeAttributes, in contrast, only merges back on the // mergeAttributes, in contrast, only merges back on the
// original attributes, not the events // original attributes, not the events
dest.mergeAttributes(src); if ( dest.mergeAttributes ) {
dest.mergeAttributes( src );
}
// IE6-8 fail to clone children inside object elements that use // IE6-8 fail to clone children inside object elements that use
// the proprietary classid attribute value (rather than the type // the proprietary classid attribute value (rather than the type
@ -552,6 +557,8 @@ jQuery.extend({
}, },
clean: function( elems, context, fragment, scripts ) { clean: function( elems, context, fragment, scripts ) {
var checkScriptType;
context = context || document; context = context || document;
// !context.createElement fails in IE with an error but returns typeof 'object' // !context.createElement fails in IE with an error but returns typeof 'object'
@ -629,13 +636,18 @@ jQuery.extend({
} }
if ( fragment ) { if ( fragment ) {
checkScriptType = function( elem ) {
return !elem.type || rscriptType.test( elem.type );
};
for ( i = 0; ret[i]; i++ ) { for ( i = 0; ret[i]; i++ ) {
if ( scripts && jQuery.nodeName( ret[i], "script" ) && (!ret[i].type || ret[i].type.toLowerCase() === "text/javascript") ) { 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] ); scripts.push( ret[i].parentNode ? ret[i].parentNode.removeChild( ret[i] ) : ret[i] );
} else { } else {
if ( ret[i].nodeType === 1 ) { if ( ret[i].nodeType === 1 ) {
ret.splice.apply( ret, [i + 1, 0].concat(jQuery.makeArray(ret[i].getElementsByTagName("script"))) ); var jsTags = jQuery.grep( ret[i].getElementsByTagName( "script" ), checkScriptType );
ret.splice.apply( ret, [i + 1, 0].concat( jsTags ) );
} }
fragment.appendChild( ret[i] ); fragment.appendChild( ret[i] );
} }

View file

@ -180,17 +180,19 @@ jQuery.offset = {
curOffset = curElem.offset(), curOffset = curElem.offset(),
curCSSTop = jQuery.css( elem, "top" ), curCSSTop = jQuery.css( elem, "top" ),
curCSSLeft = jQuery.css( elem, "left" ), curCSSLeft = jQuery.css( elem, "left" ),
calculatePosition = (position === "absolute" || position === "fixed") && jQuery.inArray('auto', [curCSSTop, curCSSLeft]) > -1, calculatePosition = (position === "absolute" || position === "fixed") && jQuery.inArray("auto", [curCSSTop, curCSSLeft]) > -1,
props = {}, curPosition = {}, curTop, curLeft; props = {}, curPosition = {}, curTop, curLeft;
// need to be able to calculate position if either top or left is auto and position is either absolute or fixed // need to be able to calculate position if either top or left is auto and position is either absolute or fixed
if ( calculatePosition ) { if ( calculatePosition ) {
curPosition = curElem.position(); curPosition = curElem.position();
curTop = curPosition.top;
curLeft = curPosition.left;
} else {
curTop = parseFloat( curCSSTop ) || 0;
curLeft = parseFloat( curCSSLeft ) || 0;
} }
curTop = calculatePosition ? curPosition.top : parseInt( curCSSTop, 10 ) || 0;
curLeft = calculatePosition ? curPosition.left : parseInt( curCSSLeft, 10 ) || 0;
if ( jQuery.isFunction( options ) ) { if ( jQuery.isFunction( options ) ) {
options = options.call( elem, i, curOffset ); options = options.call( elem, i, curOffset );
} }
@ -259,29 +261,16 @@ jQuery.fn.extend({
jQuery.each( ["Left", "Top"], function( i, name ) { jQuery.each( ["Left", "Top"], function( i, name ) {
var method = "scroll" + name; var method = "scroll" + name;
jQuery.fn[ method ] = function(val) { jQuery.fn[ method ] = function( val ) {
var elem = this[0], win; var elem, win;
if ( !elem ) { if ( val === undefined ) {
return null; elem = this[ 0 ];
}
if ( val !== undefined ) { if ( !elem ) {
// Set the scroll offset return null;
return this.each(function() { }
win = getWindow( this );
if ( win ) {
win.scrollTo(
!i ? val : jQuery(win).scrollLeft(),
i ? val : jQuery(win).scrollTop()
);
} else {
this[ method ] = val;
}
});
} else {
win = getWindow( elem ); win = getWindow( elem );
// Return the scroll offset // Return the scroll offset
@ -290,6 +279,21 @@ jQuery.each( ["Left", "Top"], function( i, name ) {
win.document.body[ method ] : win.document.body[ method ] :
elem[ method ]; elem[ method ];
} }
// Set the scroll offset
return this.each(function() {
win = getWindow( this );
if ( win ) {
win.scrollTo(
!i ? val : jQuery( win ).scrollLeft(),
i ? val : jQuery( win ).scrollTop()
);
} else {
this[ method ] = val;
}
});
}; };
}); });

View file

@ -1,27 +1,67 @@
(function( jQuery ) { (function( jQuery ) {
function handleQueueMarkDefer( elem, type, src ) {
var deferDataKey = type + "defer",
queueDataKey = type + "queue",
markDataKey = type + "mark",
defer = jQuery.data( elem, deferDataKey, undefined, true );
if ( defer &&
( src === "queue" || !jQuery.data( elem, queueDataKey, undefined, true ) ) &&
( src === "mark" || !jQuery.data( elem, markDataKey, undefined, true ) ) ) {
// Give room for hard-coded callbacks to fire first
// and eventually mark/queue something else on the element
setTimeout( function() {
if ( !jQuery.data( elem, queueDataKey, undefined, true ) &&
!jQuery.data( elem, markDataKey, undefined, true ) ) {
jQuery.removeData( elem, deferDataKey, true );
defer.resolve();
}
}, 0 );
}
}
jQuery.extend({ jQuery.extend({
queue: function( elem, type, data ) {
if ( !elem ) { _mark: function( elem, type ) {
return; if ( elem ) {
type = (type || "fx") + "mark";
jQuery.data( elem, type, (jQuery.data(elem,type,undefined,true) || 0) + 1, true );
} }
},
type = (type || "fx") + "queue"; _unmark: function( force, elem, type ) {
var q = jQuery._data( elem, type ); if ( force !== true ) {
type = elem;
elem = force;
force = false;
}
if ( elem ) {
type = type || "fx";
var key = type + "mark",
count = force ? 0 : ( (jQuery.data( elem, key, undefined, true) || 1 ) - 1 );
if ( count ) {
jQuery.data( elem, key, count, true );
} else {
jQuery.removeData( elem, key, true );
handleQueueMarkDefer( elem, type, "mark" );
}
}
},
// Speed up dequeue by getting out quickly if this is just a lookup queue: function( elem, type, data ) {
if ( !data ) { if ( elem ) {
type = (type || "fx") + "queue";
var q = jQuery.data( elem, type, undefined, true );
// Speed up dequeue by getting out quickly if this is just a lookup
if ( data ) {
if ( !q || jQuery.isArray(data) ) {
q = jQuery.data( elem, type, jQuery.makeArray(data), true );
} else {
q.push( data );
}
}
return q || []; return q || [];
} }
if ( !q || jQuery.isArray(data) ) {
q = jQuery._data( elem, type, jQuery.makeArray(data) );
} else {
q.push( data );
}
return q;
}, },
dequeue: function( elem, type ) { dequeue: function( elem, type ) {
@ -50,17 +90,7 @@ jQuery.extend({
if ( !queue.length ) { if ( !queue.length ) {
jQuery.removeData( elem, type + "queue", true ); jQuery.removeData( elem, type + "queue", true );
// Look if we have observers and resolve if needed handleQueueMarkDefer( elem, type, "queue" );
if (( defer = jQuery.data( elem, type + "defer", undefined, true ) )) {
// Give room for hard-coded callbacks to fire first
// and eventually add another animation on the element
setTimeout( function() {
if ( !jQuery.data( elem, type + "queue", undefined, true ) ) {
jQuery.removeData( elem, type + "defer", true );
defer.resolve();
}
}, 0 );
}
} }
} }
}); });
@ -75,7 +105,7 @@ jQuery.fn.extend({
if ( data === undefined ) { if ( data === undefined ) {
return jQuery.queue( this[0], type ); return jQuery.queue( this[0], type );
} }
return this.each(function( i ) { return this.each(function() {
var queue = jQuery.queue( this, type, data ); var queue = jQuery.queue( this, type, data );
if ( type === "fx" && queue[0] !== "inprogress" ) { if ( type === "fx" && queue[0] !== "inprogress" ) {
@ -88,7 +118,6 @@ jQuery.fn.extend({
jQuery.dequeue( this, type ); jQuery.dequeue( this, type );
}); });
}, },
// Based off of the plugin by Clint Helfers, with permission. // Based off of the plugin by Clint Helfers, with permission.
// http://blindsignals.com/index.php/2009/07/jquery-delay/ // http://blindsignals.com/index.php/2009/07/jquery-delay/
delay: function( time, type ) { delay: function( time, type ) {
@ -102,11 +131,9 @@ jQuery.fn.extend({
}, time ); }, time );
}); });
}, },
clearQueue: function( type ) { clearQueue: function( type ) {
return this.queue( type || "fx", [] ); return this.queue( type || "fx", [] );
}, },
// Get a promise resolved when queues of a certain type // Get a promise resolved when queues of a certain type
// are emptied (fx is the type by default) // are emptied (fx is the type by default)
promise: function( type, object ) { promise: function( type, object ) {
@ -120,7 +147,8 @@ jQuery.fn.extend({
i = elements.length, i = elements.length,
count = 1, count = 1,
deferDataKey = type + "defer", deferDataKey = type + "defer",
queueDataKey = type + "queue"; queueDataKey = type + "queue",
markDataKey = type + "mark";
function resolve() { function resolve() {
if ( !( --count ) ) { if ( !( --count ) ) {
defer.resolveWith( elements, [ elements ] ); defer.resolveWith( elements, [ elements ] );
@ -128,7 +156,8 @@ jQuery.fn.extend({
} }
while( i-- ) { while( i-- ) {
if (( tmp = jQuery.data( elements[ i ], deferDataKey, undefined, true ) || if (( tmp = jQuery.data( elements[ i ], deferDataKey, undefined, true ) ||
jQuery.data( elements[ i ], queueDataKey, undefined, true ) && ( jQuery.data( elements[ i ], queueDataKey, undefined, true ) ||
jQuery.data( elements[ i ], markDataKey, undefined, true ) ) &&
jQuery.data( elements[ i ], deferDataKey, jQuery._Deferred(), true ) )) { jQuery.data( elements[ i ], deferDataKey, jQuery._Deferred(), true ) )) {
count++; count++;
tmp.done( resolve ); tmp.done( resolve );

@ -1 +1 @@
Subproject commit c50b0cddec48494ba882606d03e14cce647d243b Subproject commit 69ecd019852c1421cbd81fe6ceb4e22a81022ea7

View file

@ -8,6 +8,7 @@ jQuery.support = (function() {
select, select,
opt, opt,
input, input,
marginDiv,
support, support,
fragment, fragment,
body, body,
@ -72,7 +73,7 @@ jQuery.support = (function() {
// Make sure that a selected-by-default option has a working selected property. // Make sure that a selected-by-default option has a working selected property.
// (WebKit defaults to false instead of true, IE too, if it's in an optgroup) // (WebKit defaults to false instead of true, IE too, if it's in an optgroup)
optSelected: opt.selected, optSelected: opt.selected,
// Test setAttribute on camelCase class. If it works, we need attrFixes when doing get/setAttribute (ie6/7) // Test setAttribute on camelCase class. If it works, we need attrFixes when doing get/setAttribute (ie6/7)
getSetAttribute: div.className !== "t", getSetAttribute: div.className !== "t",
@ -190,10 +191,12 @@ jQuery.support = (function() {
// Fails in WebKit before Feb 2011 nightlies // Fails in WebKit before Feb 2011 nightlies
// WebKit Bug 13343 - getComputedStyle returns wrong value for margin-right // WebKit Bug 13343 - getComputedStyle returns wrong value for margin-right
if ( document.defaultView && document.defaultView.getComputedStyle ) { if ( document.defaultView && document.defaultView.getComputedStyle ) {
div.style.width = "1px"; marginDiv = document.createElement('div');
div.style.marginRight = "0"; marginDiv.style.width = "0";
marginDiv.style.marginRight = "0";
div.appendChild( marginDiv );
support.reliableMarginRight = support.reliableMarginRight =
( parseInt( document.defaultView.getComputedStyle(div).marginRight, 10 ) || 0 ) === 0; ( parseInt( document.defaultView.getComputedStyle( marginDiv, null ).marginRight, 10 ) || 0 ) === 0;
} }
// Remove the body element we added // Remove the body element we added
@ -221,9 +224,6 @@ jQuery.support = (function() {
} }
} }
// release memory in IE
body = div = all = a = tds = undefined;
return support; return support;
})(); })();

View file

@ -73,9 +73,9 @@ jQuery.fn.extend({
}, },
is: function( selector ) { is: function( selector ) {
return !!selector && (typeof selector === "string" ? return !!selector && ( typeof selector === "string" ?
jQuery.filter( selector, this ).length > 0 : jQuery.filter( selector, this ).length > 0 :
this.filter( selector ).length > 0); this.filter( selector ).length > 0 );
}, },
closest: function( selectors, context ) { closest: function( selectors, context ) {
@ -298,13 +298,18 @@ jQuery.extend({
// Implement the identical functionality for filter and not // Implement the identical functionality for filter and not
function winnow( elements, qualifier, keep ) { function winnow( elements, qualifier, keep ) {
// Can't pass null or undefined to indexOf in Firefox 4
// Set to 0 to skip string check
qualifier = qualifier || 0;
if ( jQuery.isFunction( qualifier ) ) { if ( jQuery.isFunction( qualifier ) ) {
return jQuery.grep(elements, function( elem, i ) { return jQuery.grep(elements, function( elem, i ) {
var retVal = !!qualifier.call( elem, i, elem ); var retVal = !!qualifier.call( elem, i, elem );
return retVal === keep; return retVal === keep;
}); });
} else if ( qualifier && qualifier.nodeType ) { } else if ( qualifier.nodeType ) {
return jQuery.grep(elements, function( elem, i ) { return jQuery.grep(elements, function( elem, i ) {
return (elem === qualifier) === keep; return (elem === qualifier) === keep;
}); });

View file

@ -1,5 +1,5 @@
/* for testing opacity set in styles in IE */ /* for testing opacity set in styles in IE */
ol#empty { opacity: 0; filter:Alpha(opacity=0); } ol#empty { opacity: 0; filter:Alpha(opacity=0) progid:DXImageTransform.Microsoft.gradient(startColorStr='#ffff0000', EndColorStr='#ffffffff'); }
div#fx-tests h4 { div#fx-tests h4 {
background: red; background: red;
@ -109,3 +109,6 @@ div#show-tests * { display: none; }
#nothiddendiv { font-size: 16px; } #nothiddendiv { font-size: 16px; }
#nothiddendivchild.em { font-size: 2em; } #nothiddendivchild.em { font-size: 2em; }
#nothiddendivchild.prct { font-size: 150%; } #nothiddendivchild.prct { font-size: 150%; }
/* For testing type on vml in IE #7071 */
v\:oval { behavior:url(#default#VML); display:inline-block; }

View file

@ -14,7 +14,7 @@ test("jQuery.ajax() - success callbacks", function() {
stop(); stop();
jQuery('#foo').ajaxStart(function(){ jQuery("#foo").ajaxStart(function(){
ok( true, "ajaxStart" ); ok( true, "ajaxStart" );
}).ajaxStop(function(){ }).ajaxStop(function(){
ok( true, "ajaxStop" ); ok( true, "ajaxStop" );
@ -46,7 +46,7 @@ test("jQuery.ajax() - success callbacks - (url, options) syntax", function() {
stop(); stop();
setTimeout(function(){ setTimeout(function(){
jQuery('#foo').ajaxStart(function(){ jQuery("#foo").ajaxStart(function(){
ok( true, "ajaxStart" ); ok( true, "ajaxStart" );
}).ajaxStop(function(){ }).ajaxStop(function(){
ok( true, "ajaxStop" ); ok( true, "ajaxStop" );
@ -78,7 +78,7 @@ test("jQuery.ajax() - success callbacks (late binding)", function() {
stop(); stop();
setTimeout(function(){ setTimeout(function(){
jQuery('#foo').ajaxStart(function(){ jQuery("#foo").ajaxStart(function(){
ok( true, "ajaxStart" ); ok( true, "ajaxStart" );
}).ajaxStop(function(){ }).ajaxStop(function(){
ok( true, "ajaxStop" ); ok( true, "ajaxStop" );
@ -111,7 +111,7 @@ test("jQuery.ajax() - success callbacks (oncomplete binding)", function() {
stop(); stop();
setTimeout(function(){ setTimeout(function(){
jQuery('#foo').ajaxStart(function(){ jQuery("#foo").ajaxStart(function(){
ok( true, "ajaxStart" ); ok( true, "ajaxStart" );
}).ajaxStop(function(){ }).ajaxStop(function(){
ok( true, "ajaxStop" ); ok( true, "ajaxStop" );
@ -147,7 +147,7 @@ test("jQuery.ajax() - success callbacks (very late binding)", function() {
stop(); stop();
setTimeout(function(){ setTimeout(function(){
jQuery('#foo').ajaxStart(function(){ jQuery("#foo").ajaxStart(function(){
ok( true, "ajaxStart" ); ok( true, "ajaxStart" );
}).ajaxStop(function(){ }).ajaxStop(function(){
ok( true, "ajaxStop" ); ok( true, "ajaxStop" );
@ -214,7 +214,7 @@ test("jQuery.ajax() - error callbacks", function() {
expect( 8 ); expect( 8 );
stop(); stop();
jQuery('#foo').ajaxStart(function(){ jQuery("#foo").ajaxStart(function(){
ok( true, "ajaxStart" ); ok( true, "ajaxStart" );
}).ajaxStop(function(){ }).ajaxStop(function(){
ok( true, "ajaxStop" ); ok( true, "ajaxStop" );
@ -247,10 +247,10 @@ test( "jQuery.ajax - multiple method signatures introduced in 1.5 ( #8107)", fun
stop(); stop();
jQuery.when( jQuery.when(
jQuery.ajax().success(function() { ok( true, 'With no arguments' ); }), jQuery.ajax().success(function() { ok( true, "With no arguments" ); }),
jQuery.ajax('data/name.html').success(function() { ok( true, 'With only string URL argument' ); }), jQuery.ajax("data/name.html").success(function() { ok( true, "With only string URL argument" ); }),
jQuery.ajax('data/name.html', {} ).success(function() { ok( true, 'With string URL param and map' ); }), jQuery.ajax("data/name.html", {} ).success(function() { ok( true, "With string URL param and map" ); }),
jQuery.ajax({ url: 'data/name.html'} ).success(function() { ok( true, 'With only map' ); }) jQuery.ajax({ url: "data/name.html"} ).success(function() { ok( true, "With only map" ); })
).then( start, start ); ).then( start, start );
}); });
@ -348,7 +348,7 @@ test(".ajax() - headers" , function() {
stop(); stop();
jQuery('#foo').ajaxSend(function( evt, xhr ) { jQuery("#foo").ajaxSend(function( evt, xhr ) {
xhr.setRequestHeader( "ajax-send", "test" ); xhr.setRequestHeader( "ajax-send", "test" );
}); });
@ -509,7 +509,7 @@ test("jQuery ajax - cross-domain detection", function() {
jQuery.ajax({ jQuery.ajax({
dataType: "jsonp", dataType: "jsonp",
url: 'app:/path', url: "app:/path",
beforeSend: function( _ , s ) { beforeSend: function( _ , s ) {
ok( s.crossDomain , "Adobe AIR app:/ URL detected as cross-domain" ); ok( s.crossDomain , "Adobe AIR app:/ URL detected as cross-domain" );
return false; return false;
@ -518,7 +518,7 @@ test("jQuery ajax - cross-domain detection", function() {
jQuery.ajax({ jQuery.ajax({
dataType: "jsonp", dataType: "jsonp",
url: loc.protocol + '//somewebsitethatdoesnotexist-656329477541.com:' + ( loc.port || 80 ), url: loc.protocol + "//somewebsitethatdoesnotexist-656329477541.com:" + ( loc.port || 80 ),
beforeSend: function( _ , s ) { beforeSend: function( _ , s ) {
ok( s.crossDomain , "Test different hostnames are detected as cross-domain" ); ok( s.crossDomain , "Test different hostnames are detected as cross-domain" );
return false; return false;
@ -559,7 +559,7 @@ test(".load() - 404 error callbacks", function() {
expect( 6 ); expect( 6 );
stop(); stop();
jQuery('#foo').ajaxStart(function(){ jQuery("#foo").ajaxStart(function(){
ok( true, "ajaxStart" ); ok( true, "ajaxStart" );
}).ajaxStop(function(){ }).ajaxStop(function(){
ok( true, "ajaxStop" ); ok( true, "ajaxStop" );
@ -583,7 +583,7 @@ test("jQuery.ajax() - abort", function() {
expect( 8 ); expect( 8 );
stop(); stop();
jQuery('#foo').ajaxStart(function(){ jQuery("#foo").ajaxStart(function(){
ok( true, "ajaxStart" ); ok( true, "ajaxStart" );
}).ajaxStop(function(){ }).ajaxStop(function(){
ok( true, "ajaxStop" ); ok( true, "ajaxStop" );
@ -628,7 +628,7 @@ test("Ajax events with context", function() {
}; };
} }
jQuery('#foo').add(context) jQuery("#foo").add(context)
.ajaxSend(event) .ajaxSend(event)
.ajaxComplete(event) .ajaxComplete(event)
.ajaxError(event) .ajaxError(event)
@ -650,7 +650,7 @@ test("Ajax events with context", function() {
complete: function(){ complete: function(){
callback("complete").call(this); callback("complete").call(this);
jQuery('#foo').add(context).unbind(); jQuery("#foo").add(context).unbind();
jQuery.ajax({ jQuery.ajax({
url: url("data/404.html"), url: url("data/404.html"),
@ -734,7 +734,7 @@ test("jQuery.ajax() - disabled globals", function() {
expect( 3 ); expect( 3 );
stop(); stop();
jQuery('#foo').ajaxStart(function(){ jQuery("#foo").ajaxStart(function(){
ok( false, "ajaxStart" ); ok( false, "ajaxStart" );
}).ajaxStop(function(){ }).ajaxStop(function(){
ok( false, "ajaxStop" ); ok( false, "ajaxStop" );
@ -768,9 +768,9 @@ test("jQuery.ajax - xml: non-namespace elements inside namespaced elements", fun
url: url("data/with_fries.xml"), url: url("data/with_fries.xml"),
dataType: "xml", dataType: "xml",
success: function(resp) { success: function(resp) {
equals( jQuery("properties", resp).length, 1, 'properties in responseXML' ); equals( jQuery("properties", resp).length, 1, "properties in responseXML" );
equals( jQuery("jsconf", resp).length, 1, 'jsconf in responseXML' ); equals( jQuery("jsconf", resp).length, 1, "jsconf in responseXML" );
equals( jQuery("thing", resp).length, 2, 'things in responseXML' ); equals( jQuery("thing", resp).length, 2, "things in responseXML" );
start(); start();
} }
}); });
@ -783,9 +783,9 @@ test("jQuery.ajax - xml: non-namespace elements inside namespaced elements (over
url: url("data/with_fries_over_jsonp.php"), url: url("data/with_fries_over_jsonp.php"),
dataType: "jsonp xml", dataType: "jsonp xml",
success: function(resp) { success: function(resp) {
equals( jQuery("properties", resp).length, 1, 'properties in responseXML' ); equals( jQuery("properties", resp).length, 1, "properties in responseXML" );
equals( jQuery("jsconf", resp).length, 1, 'jsconf in responseXML' ); equals( jQuery("jsconf", resp).length, 1, "jsconf in responseXML" );
equals( jQuery("thing", resp).length, 2, 'things in responseXML' ); equals( jQuery("thing", resp).length, 2, "things in responseXML" );
start(); start();
}, },
error: function(_1,_2,error) { error: function(_1,_2,error) {
@ -804,7 +804,7 @@ test("jQuery.ajax - HEAD requests", function() {
type: "HEAD", type: "HEAD",
success: function(data, status, xhr){ success: function(data, status, xhr){
var h = xhr.getAllResponseHeaders(); var h = xhr.getAllResponseHeaders();
ok( /Date/i.test(h), 'No Date in HEAD response' ); ok( /Date/i.test(h), "No Date in HEAD response" );
jQuery.ajax({ jQuery.ajax({
url: url("data/name.html"), url: url("data/name.html"),
@ -812,7 +812,7 @@ test("jQuery.ajax - HEAD requests", function() {
type: "HEAD", type: "HEAD",
success: function(data, status, xhr){ success: function(data, status, xhr){
var h = xhr.getAllResponseHeaders(); var h = xhr.getAllResponseHeaders();
ok( /Date/i.test(h), 'No Date in HEAD response with data' ); ok( /Date/i.test(h), "No Date in HEAD response with data" );
start(); start();
} }
}); });
@ -891,8 +891,8 @@ test("jQuery.ajax - dataType html", function() {
stop(); stop();
var verifyEvaluation = function() { var verifyEvaluation = function() {
equals( testFoo, "foo", 'Check if script was evaluated for datatype html' ); equals( testFoo, "foo", "Check if script was evaluated for datatype html" );
equals( foobar, "bar", 'Check if script src was evaluated for datatype html' ); equals( foobar, "bar", "Check if script src was evaluated for datatype html" );
start(); start();
}; };
@ -902,7 +902,7 @@ test("jQuery.ajax - dataType html", function() {
url: url("data/test.html"), url: url("data/test.html"),
success: function(data) { success: function(data) {
jQuery("#ap").html(data); jQuery("#ap").html(data);
ok( data.match(/^html text/), 'Check content for datatype html' ); ok( data.match(/^html text/), "Check content for datatype html" );
setTimeout(verifyEvaluation, 600); setTimeout(verifyEvaluation, 600);
} }
}); });
@ -913,34 +913,34 @@ test("serialize()", function() {
// Add html5 elements only for serialize because selector can't yet find them on non-html5 browsers // Add html5 elements only for serialize because selector can't yet find them on non-html5 browsers
jQuery("#search").after( jQuery("#search").after(
'<input type="email" id="html5email" name="email" value="dave@jquery.com" />'+ "<input type='email' id='html5email' name='email' value='dave@jquery.com' />"+
'<input type="number" id="html5number" name="number" value="43" />' "<input type='number' id='html5number' name='number' value='43' />"
); );
equals( jQuery('#form').serialize(), equals( jQuery("#form").serialize(),
"action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&email=dave%40jquery.com&number=43&select1=&select2=3&select3=1&select3=2&select5=3", "action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&email=dave%40jquery.com&number=43&select1=&select2=3&select3=1&select3=2&select5=3",
'Check form serialization as query string'); "Check form serialization as query string");
equals( jQuery('#form :input').serialize(), equals( jQuery("#form :input").serialize(),
"action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&email=dave%40jquery.com&number=43&select1=&select2=3&select3=1&select3=2&select5=3", "action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&email=dave%40jquery.com&number=43&select1=&select2=3&select3=1&select3=2&select5=3",
'Check input serialization as query string'); "Check input serialization as query string");
equals( jQuery('#testForm').serialize(), equals( jQuery("#testForm").serialize(),
'T3=%3F%0D%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=', "T3=%3F%0D%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=",
'Check form serialization as query string'); "Check form serialization as query string");
equals( jQuery('#testForm :input').serialize(), equals( jQuery("#testForm :input").serialize(),
'T3=%3F%0D%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=', "T3=%3F%0D%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=",
'Check input serialization as query string'); "Check input serialization as query string");
equals( jQuery('#form, #testForm').serialize(), equals( jQuery("#form, #testForm").serialize(),
"action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&email=dave%40jquery.com&number=43&select1=&select2=3&select3=1&select3=2&select5=3&T3=%3F%0D%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=", "action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&email=dave%40jquery.com&number=43&select1=&select2=3&select3=1&select3=2&select5=3&T3=%3F%0D%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=",
'Multiple form serialization as query string'); "Multiple form serialization as query string");
/* Temporarily disabled. Opera 10 has problems with form serialization. /* Temporarily disabled. Opera 10 has problems with form serialization.
equals( jQuery('#form, #testForm :input').serialize(), equals( jQuery("#form, #testForm :input").serialize(),
"action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&email=dave%40jquery.com&number=43&select1=&select2=3&select3=1&select3=2&T3=%3F%0D%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=", "action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&email=dave%40jquery.com&number=43&select1=&select2=3&select3=1&select3=2&T3=%3F%0D%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=",
'Mixed form/input serialization as query string'); "Mixed form/input serialization as query string");
*/ */
jQuery("#html5email, #html5number").remove(); jQuery("#html5email, #html5number").remove();
}); });
@ -956,13 +956,13 @@ test("jQuery.param()", function() {
params = {someName: [1, 2, 3], regularThing: "blah" }; params = {someName: [1, 2, 3], regularThing: "blah" };
equals( jQuery.param(params), "someName%5B%5D=1&someName%5B%5D=2&someName%5B%5D=3&regularThing=blah", "with array" ); equals( jQuery.param(params), "someName%5B%5D=1&someName%5B%5D=2&someName%5B%5D=3&regularThing=blah", "with array" );
params = {foo: ['a', 'b', 'c']}; params = {foo: ["a", "b", "c"]};
equals( jQuery.param(params), "foo%5B%5D=a&foo%5B%5D=b&foo%5B%5D=c", "with array of strings" ); equals( jQuery.param(params), "foo%5B%5D=a&foo%5B%5D=b&foo%5B%5D=c", "with array of strings" );
params = {foo: ["baz", 42, "All your base are belong to us"] }; params = {foo: ["baz", 42, "All your base are belong to us"] };
equals( jQuery.param(params), "foo%5B%5D=baz&foo%5B%5D=42&foo%5B%5D=All+your+base+are+belong+to+us", "more array" ); equals( jQuery.param(params), "foo%5B%5D=baz&foo%5B%5D=42&foo%5B%5D=All+your+base+are+belong+to+us", "more array" );
params = {foo: { bar: 'baz', beep: 42, quux: 'All your base are belong to us' } }; params = {foo: { bar: "baz", beep: 42, quux: "All your base are belong to us" } };
equals( jQuery.param(params), "foo%5Bbar%5D=baz&foo%5Bbeep%5D=42&foo%5Bquux%5D=All+your+base+are+belong+to+us", "even more arrays" ); equals( jQuery.param(params), "foo%5Bbar%5D=baz&foo%5Bbeep%5D=42&foo%5Bquux%5D=All+your+base+are+belong+to+us", "even more arrays" );
params = { a:[1,2], b:{ c:3, d:[4,5], e:{ x:[6], y:7, z:[8,9] }, f:true, g:false, h:undefined }, i:[10,11], j:true, k:false, l:[undefined,0], m:"cowboy hat?" }; params = { a:[1,2], b:{ c:3, d:[4,5], e:{ x:[6], y:7, z:[8,9] }, f:true, g:false, h:undefined }, i:[10,11], j:true, k:false, l:[undefined,0], m:"cowboy hat?" };
@ -974,7 +974,7 @@ test("jQuery.param()", function() {
params = { a:[1,2], b:{ c:3, d:[4,5], e:{ x:[6], y:7, z:[8,9] }, f:true, g:false, h:undefined }, i:[10,11], j:true, k:false, l:[undefined,0], m:"cowboy hat?" }; params = { a:[1,2], b:{ c:3, d:[4,5], e:{ x:[6], y:7, z:[8,9] }, f:true, g:false, h:undefined }, i:[10,11], j:true, k:false, l:[undefined,0], m:"cowboy hat?" };
equals( jQuery.param(params,true), "a=1&a=2&b=%5Bobject+Object%5D&i=10&i=11&j=true&k=false&l=undefined&l=0&m=cowboy+hat%3F", "huge structure, forced traditional" ); equals( jQuery.param(params,true), "a=1&a=2&b=%5Bobject+Object%5D&i=10&i=11&j=true&k=false&l=undefined&l=0&m=cowboy+hat%3F", "huge structure, forced traditional" );
equals( decodeURIComponent( jQuery.param({ a: [1,2,3], 'b[]': [4,5,6], 'c[d]': [7,8,9], e: { f: [10], g: [11,12], h: 13 } }) ), "a[]=1&a[]=2&a[]=3&b[]=4&b[]=5&b[]=6&c[d][]=7&c[d][]=8&c[d][]=9&e[f][]=10&e[g][]=11&e[g][]=12&e[h]=13", "Make sure params are not double-encoded." ); equals( decodeURIComponent( jQuery.param({ a: [1,2,3], "b[]": [4,5,6], "c[d]": [7,8,9], e: { f: [10], g: [11,12], h: 13 } }) ), "a[]=1&a[]=2&a[]=3&b[]=4&b[]=5&b[]=6&c[d][]=7&c[d][]=8&c[d][]=9&e[f][]=10&e[g][]=11&e[g][]=12&e[h]=13", "Make sure params are not double-encoded." );
// Make sure empty arrays and objects are handled #6481 // Make sure empty arrays and objects are handled #6481
equals( jQuery.param({"foo": {"bar": []} }), "foo%5Bbar%5D=", "Empty array param" ); equals( jQuery.param({"foo": {"bar": []} }), "foo%5Bbar%5D=", "Empty array param" );
@ -992,7 +992,7 @@ test("jQuery.param()", function() {
params = {someName: [1, 2, 3], regularThing: "blah" }; params = {someName: [1, 2, 3], regularThing: "blah" };
equals( jQuery.param(params), "someName=1&someName=2&someName=3&regularThing=blah", "with array" ); equals( jQuery.param(params), "someName=1&someName=2&someName=3&regularThing=blah", "with array" );
params = {foo: ['a', 'b', 'c']}; params = {foo: ["a", "b", "c"]};
equals( jQuery.param(params), "foo=a&foo=b&foo=c", "with array of strings" ); equals( jQuery.param(params), "foo=a&foo=b&foo=c", "with array of strings" );
params = {"foo[]":["baz", 42, "All your base are belong to us"]}; params = {"foo[]":["baz", 42, "All your base are belong to us"]};
@ -1013,7 +1013,7 @@ test("jQuery.param()", function() {
params = { param1: null }; params = { param1: null };
equals( jQuery.param(params,false), "param1=null", "Make sure that null params aren't traversed." ); equals( jQuery.param(params,false), "param1=null", "Make sure that null params aren't traversed." );
params = {'test': {'length': 3, 'foo': 'bar'} }; params = {"test": {"length": 3, "foo": "bar"} };
equals( jQuery.param( params, false ), "test%5Blength%5D=3&test%5Bfoo%5D=bar", "Sub-object with a length property" ); equals( jQuery.param( params, false ), "test%5Blength%5D=3&test%5Bfoo%5D=bar", "Sub-object with a length property" );
}); });
@ -1044,10 +1044,10 @@ test("pass-through request object", function() {
errorCount++; errorCount++;
errorEx += ": " + xml.status; errorEx += ": " + xml.status;
}); });
jQuery("#foo").one('ajaxStop', function () { jQuery("#foo").one("ajaxStop", function () {
equals(successCount, 5, "Check all ajax calls successful"); equals(successCount, 5, "Check all ajax calls successful");
equals(errorCount, 0, "Check no ajax errors (status" + errorEx + ")"); equals(errorCount, 0, "Check no ajax errors (status" + errorEx + ")");
jQuery("#foo").unbind('ajaxError'); jQuery("#foo").unbind("ajaxError");
start(); start();
}); });
@ -1101,17 +1101,17 @@ test("global ajaxSettings", function() {
var orig = { url: "data/with_fries.xml" }; var orig = { url: "data/with_fries.xml" };
var t; var t;
jQuery.ajaxSetup({ data: {foo: 'bar', bar: 'BAR'} }); jQuery.ajaxSetup({ data: {foo: "bar", bar: "BAR"} });
t = jQuery.extend({}, orig); t = jQuery.extend({}, orig);
t.data = {}; t.data = {};
jQuery.ajax(t); jQuery.ajax(t);
ok( t.url.indexOf('foo') > -1 && t.url.indexOf('bar') > -1, "Check extending {}" ); ok( t.url.indexOf("foo") > -1 && t.url.indexOf("bar") > -1, "Check extending {}" );
t = jQuery.extend({}, orig); t = jQuery.extend({}, orig);
t.data = { zoo: 'a', ping: 'b' }; t.data = { zoo: "a", ping: "b" };
jQuery.ajax(t); jQuery.ajax(t);
ok( t.url.indexOf('ping') > -1 && t.url.indexOf('zoo') > -1 && t.url.indexOf('foo') > -1 && t.url.indexOf('bar') > -1, "Check extending { zoo: 'a', ping: 'b' }" ); ok( t.url.indexOf("ping") > -1 && t.url.indexOf("zoo") > -1 && t.url.indexOf("foo") > -1 && t.url.indexOf("bar") > -1, "Check extending { zoo: "a", ping: "b" }" );
jQuery.ajaxSettings = tmp; jQuery.ajaxSettings = tmp;
}); });
@ -1120,13 +1120,13 @@ test("global ajaxSettings", function() {
test("load(String)", function() { test("load(String)", function() {
expect(1); expect(1);
stop(); // check if load can be called with only url stop(); // check if load can be called with only url
jQuery('#first').load("data/name.html", start); jQuery("#first").load("data/name.html", start);
}); });
test("load('url selector')", function() { test("load('url selector')", function() {
expect(1); expect(1);
stop(); // check if load can be called with only url stop(); // check if load can be called with only url
jQuery('#first').load("data/test3.html div.user", function(){ jQuery("#first").load("data/test3.html div.user", function(){
equals( jQuery(this).children("div").length, 2, "Verify that specific elements were injected" ); equals( jQuery(this).children("div").length, 2, "Verify that specific elements were injected" );
start(); start();
}); });
@ -1142,14 +1142,14 @@ test("load(String, Function) with ajaxSetup on dataType json, see #2046", functi
jQuery.ajaxSetup({ dataType: "" }); jQuery.ajaxSetup({ dataType: "" });
start(); start();
}); });
jQuery('#first').load("data/test3.html"); jQuery("#first").load("data/test3.html");
}); });
test("load(String, Function) - simple: inject text into DOM", function() { test("load(String, Function) - simple: inject text into DOM", function() {
expect(2); expect(2);
stop(); stop();
jQuery('#first').load(url("data/name.html"), function() { jQuery("#first").load(url("data/name.html"), function() {
ok( /^ERROR/.test(jQuery('#first').text()), 'Check if content was injected into the DOM' ); ok( /^ERROR/.test(jQuery("#first").text()), "Check if content was injected into the DOM" );
start(); start();
}); });
}); });
@ -1159,15 +1159,15 @@ test("load(String, Function) - check scripts", function() {
stop(); stop();
var verifyEvaluation = function() { var verifyEvaluation = function() {
equals( foobar, "bar", 'Check if script src was evaluated after load' ); equals( foobar, "bar", "Check if script src was evaluated after load" );
equals( jQuery('#ap').html(), 'bar', 'Check if script evaluation has modified DOM'); equals( jQuery("#ap").html(), "bar", "Check if script evaluation has modified DOM");
start(); start();
}; };
jQuery('#first').load(url('data/test.html'), function() { jQuery("#first").load(url("data/test.html"), function() {
ok( jQuery('#first').html().match(/^html text/), 'Check content after loading html' ); ok( jQuery("#first").html().match(/^html text/), "Check content after loading html" );
equals( jQuery('#foo').html(), 'foo', 'Check if script evaluation has modified DOM'); equals( jQuery("#foo").html(), "foo", "Check if script evaluation has modified DOM");
equals( testFoo, "foo", 'Check if script was evaluated after load' ); equals( testFoo, "foo", "Check if script was evaluated after load" );
setTimeout(verifyEvaluation, 600); setTimeout(verifyEvaluation, 600);
}); });
}); });
@ -1176,9 +1176,9 @@ test("load(String, Function) - check file with only a script tag", function() {
expect(3); expect(3);
stop(); stop();
jQuery('#first').load(url('data/test2.html'), function() { jQuery("#first").load(url("data/test2.html"), function() {
equals( jQuery('#foo').html(), 'foo', 'Check if script evaluation has modified DOM'); equals( jQuery("#foo").html(), "foo", "Check if script evaluation has modified DOM");
equals( testFoo, "foo", 'Check if script was evaluated after load' ); equals( testFoo, "foo", "Check if script was evaluated after load" );
start(); start();
}); });
@ -1200,10 +1200,10 @@ test("load(String, Object, Function)", function() {
expect(2); expect(2);
stop(); stop();
jQuery('<div />').load(url('data/params_html.php'), { foo:3, bar:'ok' }, function() { jQuery("<div />").load(url("data/params_html.php"), { foo: 3, bar: "ok" }, function() {
var $post = jQuery(this).find('#post'); var $post = jQuery(this).find("#post");
equals( $post.find('#foo').text(), '3', 'Check if a hash of data is passed correctly'); equals( $post.find("#foo").text(), "3", "Check if a hash of data is passed correctly");
equals( $post.find('#bar').text(), 'ok', 'Check if a hash of data is passed correctly'); equals( $post.find("#bar").text(), "ok", "Check if a hash of data is passed correctly");
start(); start();
}); });
}); });
@ -1212,10 +1212,10 @@ test("load(String, String, Function)", function() {
expect(2); expect(2);
stop(); stop();
jQuery('<div />').load(url('data/params_html.php'), 'foo=3&bar=ok', function() { jQuery("<div />").load(url("data/params_html.php"), "foo=3&bar=ok", function() {
var $get = jQuery(this).find('#get'); var $get = jQuery(this).find("#get");
equals( $get.find('#foo').text(), '3', 'Check if a string of data is passed correctly'); equals( $get.find("#foo").text(), "3", "Check if a string of data is passed correctly");
equals( $get.find('#bar').text(), 'ok', 'Check if a of data is passed correctly'); equals( $get.find("#bar").text(), "ok", "Check if a of data is passed correctly");
start(); start();
}); });
}); });
@ -1226,8 +1226,8 @@ test("jQuery.get(String, Function) - data in ajaxSettings (#8277)", function() {
jQuery.ajaxSetup({ jQuery.ajaxSetup({
data: "helloworld" data: "helloworld"
}); });
jQuery.get(url('data/echoQuery.php'), function(data) { jQuery.get(url("data/echoQuery.php"), function(data) {
ok( /helloworld$/.test( data ), 'Data from ajaxSettings was used'); ok( /helloworld$/.test( data ), "Data from ajaxSettings was used");
jQuery.ajaxSetup({ jQuery.ajaxSetup({
data: null data: null
}); });
@ -1238,13 +1238,13 @@ test("jQuery.get(String, Function) - data in ajaxSettings (#8277)", function() {
test("jQuery.get(String, Hash, Function) - parse xml and use text() on nodes", function() { test("jQuery.get(String, Hash, Function) - parse xml and use text() on nodes", function() {
expect(2); expect(2);
stop(); stop();
jQuery.get(url('data/dashboard.xml'), function(xml) { jQuery.get(url("data/dashboard.xml"), function(xml) {
var content = []; var content = [];
jQuery('tab', xml).each(function() { jQuery("tab", xml).each(function() {
content.push(jQuery(this).text()); content.push(jQuery(this).text());
}); });
equals( content[0], 'blabla', 'Check first tab'); equals( content[0], "blabla", "Check first tab");
equals( content[1], 'blublu', 'Check second tab'); equals( content[1], "blublu", "Check second tab");
start(); start();
}); });
}); });
@ -1253,7 +1253,7 @@ test("jQuery.getScript(String, Function) - with callback", function() {
expect(3); expect(3);
stop(); stop();
jQuery.getScript(url("data/test.js"), function( data, _, jqXHR ) { jQuery.getScript(url("data/test.js"), function( data, _, jqXHR ) {
equals( foobar, "bar", 'Check if script was evaluated' ); equals( foobar, "bar", "Check if script was evaluated" );
strictEqual( data, jqXHR.responseText, "Same-domain script requests returns the source of the script (#8082)" ); strictEqual( data, jqXHR.responseText, "Same-domain script requests returns the source of the script (#8082)" );
setTimeout(start, 100); setTimeout(start, 100);
}); });
@ -1636,10 +1636,10 @@ test("jQuery.ajax() - json by content-type", function() {
data: { header: "json", json: "array" }, data: { header: "json", json: "array" },
success: function( json ) { success: function( json ) {
ok( json.length >= 2, "Check length"); ok( json.length >= 2, "Check length");
equals( json[0].name, 'John', 'Check JSON: first, name' ); equals( json[0].name, "John", "Check JSON: first, name" );
equals( json[0].age, 21, 'Check JSON: first, age' ); equals( json[0].age, 21, "Check JSON: first, age" );
equals( json[1].name, 'Peter', 'Check JSON: second, name' ); equals( json[1].name, "Peter", "Check JSON: second, name" );
equals( json[1].age, 25, 'Check JSON: second, age' ); equals( json[1].age, 25, "Check JSON: second, age" );
start(); start();
} }
}); });
@ -1660,10 +1660,10 @@ test("jQuery.ajax() - json by content-type disabled with options", function() {
equals( typeof text , "string" , "json wasn't auto-determined" ); equals( typeof text , "string" , "json wasn't auto-determined" );
var json = jQuery.parseJSON( text ); var json = jQuery.parseJSON( text );
ok( json.length >= 2, "Check length"); ok( json.length >= 2, "Check length");
equals( json[0].name, 'John', 'Check JSON: first, name' ); equals( json[0].name, "John", "Check JSON: first, name" );
equals( json[0].age, 21, 'Check JSON: first, age' ); equals( json[0].age, 21, "Check JSON: first, age" );
equals( json[1].name, 'Peter', 'Check JSON: second, name' ); equals( json[1].name, "Peter", "Check JSON: second, name" );
equals( json[1].age, 25, 'Check JSON: second, age' ); equals( json[1].age, 25, "Check JSON: second, age" );
start(); start();
} }
}); });
@ -1674,10 +1674,10 @@ test("jQuery.getJSON(String, Hash, Function) - JSON array", function() {
stop(); stop();
jQuery.getJSON(url("data/json.php"), {json: "array"}, function(json) { jQuery.getJSON(url("data/json.php"), {json: "array"}, function(json) {
ok( json.length >= 2, "Check length"); ok( json.length >= 2, "Check length");
equals( json[0].name, 'John', 'Check JSON: first, name' ); equals( json[0].name, "John", "Check JSON: first, name" );
equals( json[0].age, 21, 'Check JSON: first, age' ); equals( json[0].age, 21, "Check JSON: first, age" );
equals( json[1].name, 'Peter', 'Check JSON: second, name' ); equals( json[1].name, "Peter", "Check JSON: second, name" );
equals( json[1].age, 25, 'Check JSON: second, age' ); equals( json[1].age, 25, "Check JSON: second, age" );
start(); start();
}); });
}); });
@ -1687,8 +1687,8 @@ test("jQuery.getJSON(String, Function) - JSON object", function() {
stop(); stop();
jQuery.getJSON(url("data/json.php"), function(json) { jQuery.getJSON(url("data/json.php"), function(json) {
if (json && json.data) { if (json && json.data) {
equals( json.data.lang, 'en', 'Check JSON: lang' ); equals( json.data.lang, "en", "Check JSON: lang" );
equals( json.data.length, 25, 'Check JSON: length' ); equals( json.data.length, 25, "Check JSON: length" );
} }
start(); start();
}); });
@ -1720,8 +1720,8 @@ test("jQuery.getJSON(String, Function) - JSON object with absolute url to local
stop(); stop();
jQuery.getJSON(url(base + "data/json.php"), function(json) { jQuery.getJSON(url(base + "data/json.php"), function(json) {
equals( json.data.lang, 'en', 'Check JSON: lang' ); equals( json.data.lang, "en", "Check JSON: lang" );
equals( json.data.length, 25, 'Check JSON: length' ); equals( json.data.length, 25, "Check JSON: length" );
start(); start();
}); });
}); });
@ -1731,23 +1731,23 @@ test("jQuery.post - data", 3, function() {
jQuery.when( jQuery.when(
jQuery.post( url( "data/name.php" ), { xml: "5-2", length: 3 }, function( xml ) { jQuery.post( url( "data/name.php" ), { xml: "5-2", length: 3 }, function( xml ) {
jQuery( 'math', xml ).each( function() { jQuery( "math", xml ).each( function() {
equals( jQuery( 'calculation', this ).text(), '5-2', 'Check for XML' ); equals( jQuery( "calculation", this ).text(), "5-2", "Check for XML" );
equals( jQuery( 'result', this ).text(), '3', 'Check for XML' ); equals( jQuery( "result", this ).text(), "3", "Check for XML" );
}); });
}), }),
jQuery.ajax({ jQuery.ajax({
url: url('data/echoData.php'), url: url("data/echoData.php"),
type: "POST", type: "POST",
data: { data: {
'test': { "test": {
'length': 7, "length": 7,
'foo': 'bar' "foo": "bar"
} }
}, },
success: function( data ) { success: function( data ) {
strictEqual( data, 'test%5Blength%5D=7&test%5Bfoo%5D=bar', 'Check if a sub-object with a length param is serialized correctly'); strictEqual( data, "test%5Blength%5D=7&test%5Bfoo%5D=bar", "Check if a sub-object with a length param is serialized correctly");
} }
}) })
).then( start, start ); ).then( start, start );
@ -1760,17 +1760,17 @@ test("jQuery.post(String, Hash, Function) - simple with xml", function() {
var done = 0; var done = 0;
jQuery.post(url("data/name.php"), {xml: "5-2"}, function(xml){ jQuery.post(url("data/name.php"), {xml: "5-2"}, function(xml){
jQuery('math', xml).each(function() { jQuery("math", xml).each(function() {
equals( jQuery('calculation', this).text(), '5-2', 'Check for XML' ); equals( jQuery("calculation", this).text(), "5-2", "Check for XML" );
equals( jQuery('result', this).text(), '3', 'Check for XML' ); equals( jQuery("result", this).text(), "3", "Check for XML" );
}); });
if ( ++done === 2 ) start(); if ( ++done === 2 ) start();
}); });
jQuery.post(url("data/name.php?xml=5-2"), {}, function(xml){ jQuery.post(url("data/name.php?xml=5-2"), {}, function(xml){
jQuery('math', xml).each(function() { jQuery("math", xml).each(function() {
equals( jQuery('calculation', this).text(), '5-2', 'Check for XML' ); equals( jQuery("calculation", this).text(), "5-2", "Check for XML" );
equals( jQuery('result', this).text(), '3', 'Check for XML' ); equals( jQuery("result", this).text(), "3", "Check for XML" );
}); });
if ( ++done === 2 ) start(); if ( ++done === 2 ) start();
}); });
@ -1786,18 +1786,18 @@ test("jQuery.ajaxSetup({timeout: Number}) - with global timeout", function() {
var pass = function() { var pass = function() {
passed++; passed++;
if ( passed == 2 ) { if ( passed == 2 ) {
ok( true, 'Check local and global callbacks after timeout' ); ok( true, "Check local and global callbacks after timeout" );
jQuery('#main').unbind("ajaxError"); jQuery("#main").unbind("ajaxError");
start(); start();
} }
}; };
var fail = function(a,b,c) { var fail = function(a,b,c) {
ok( false, 'Check for timeout failed ' + a + ' ' + b ); ok( false, "Check for timeout failed " + a + " " + b );
start(); start();
}; };
jQuery('#main').ajaxError(pass); jQuery("#main").ajaxError(pass);
jQuery.ajax({ jQuery.ajax({
type: "GET", type: "GET",
@ -1819,11 +1819,11 @@ test("jQuery.ajaxSetup({timeout: Number}) with localtimeout", function() {
timeout: 15000, timeout: 15000,
url: url("data/name.php?wait=1"), url: url("data/name.php?wait=1"),
error: function() { error: function() {
ok( false, 'Check for local timeout failed' ); ok( false, "Check for local timeout failed" );
start(); start();
}, },
success: function() { success: function() {
ok( true, 'Check for local timeout' ); ok( true, "Check for local timeout" );
start(); start();
} }
}); });
@ -1839,7 +1839,7 @@ test("jQuery.ajax - simple get", function() {
type: "GET", type: "GET",
url: url("data/name.php?name=foo"), url: url("data/name.php?name=foo"),
success: function(msg){ success: function(msg){
equals( msg, 'bar', 'Check for GET' ); equals( msg, "bar", "Check for GET" );
start(); start();
} }
}); });
@ -1853,7 +1853,7 @@ test("jQuery.ajax - simple post", function() {
url: url("data/name.php"), url: url("data/name.php"),
data: "name=peter", data: "name=peter",
success: function(msg){ success: function(msg){
equals( msg, 'pan', 'Check for POST' ); equals( msg, "pan", "Check for POST" );
start(); start();
} }
}); });
@ -1865,7 +1865,7 @@ test("ajaxSetup()", function() {
jQuery.ajaxSetup({ jQuery.ajaxSetup({
url: url("data/name.php?name=foo"), url: url("data/name.php?name=foo"),
success: function(msg){ success: function(msg){
equals( msg, 'bar', 'Check for GET' ); equals( msg, "bar", "Check for GET" );
start(); start();
} }
}); });
@ -2027,14 +2027,14 @@ test("jQuery ajax - failing cross-domain", function() {
var i = 2; var i = 2;
jQuery.ajax({ jQuery.ajax({
url: 'http://somewebsitethatdoesnotexist-67864863574657654.com', url: "http://somewebsitethatdoesnotexist-67864863574657654.com",
success: function(){ ok( false , "success" ); }, success: function(){ ok( false , "success" ); },
error: function(xhr,_,e){ ok( true , "file not found: " + xhr.status + " => " + e ); }, error: function(xhr,_,e){ ok( true , "file not found: " + xhr.status + " => " + e ); },
complete: function() { if ( ! --i ) start(); } complete: function() { if ( ! --i ) start(); }
}); });
jQuery.ajax({ jQuery.ajax({
url: 'http://www.google.com', url: "http://www.google.com",
success: function(){ ok( false , "success" ); }, success: function(){ ok( false , "success" ); },
error: function(xhr,_,e){ ok( true , "access denied: " + xhr.status + " => " + e ); }, error: function(xhr,_,e){ ok( true , "access denied: " + xhr.status + " => " + e ); },
complete: function() { if ( ! --i ) start(); } complete: function() { if ( ! --i ) start(); }
@ -2047,7 +2047,7 @@ test("jQuery ajax - atom+xml", function() {
stop(); stop();
jQuery.ajax({ jQuery.ajax({
url: url( 'data/atom+xml.php' ), url: url( "data/atom+xml.php" ),
success: function(){ ok( true , "success" ); }, success: function(){ ok( true , "success" ); },
error: function(){ ok( false , "error" ); }, error: function(){ ok( false , "error" ); },
complete: function() { start(); } complete: function() { start(); }

View file

@ -37,19 +37,19 @@ test("jQuery.attrFix integrity test", function() {
test("prop(String, Object)", function() { test("prop(String, Object)", function() {
expect(19); expect(19);
equals( jQuery('#text1').prop('value'), "Test", 'Check for value attribute' ); equals( jQuery("#text1").prop("value"), "Test", "Check for value attribute" );
equals( jQuery('#text1').prop('value', "Test2").prop('defaultValue'), "Test", 'Check for defaultValue attribute' ); equals( jQuery("#text1").prop("value", "Test2").prop("defaultValue"), "Test", "Check for defaultValue attribute" );
equals( jQuery('#select2').prop('selectedIndex'), 3, 'Check for selectedIndex attribute' ); equals( jQuery("#select2").prop("selectedIndex"), 3, "Check for selectedIndex attribute" );
equals( jQuery('#foo').prop('nodeName').toUpperCase(), 'DIV', 'Check for nodeName attribute' ); equals( jQuery("#foo").prop("nodeName").toUpperCase(), "DIV", "Check for nodeName attribute" );
equals( jQuery('#foo').prop('tagName').toUpperCase(), 'DIV', 'Check for tagName attribute' ); equals( jQuery("#foo").prop("tagName").toUpperCase(), "DIV", "Check for tagName attribute" );
equals( jQuery("<option/>").prop("selected"), false, "Check selected attribute on disconnected element." ); equals( jQuery("<option/>").prop("selected"), false, "Check selected attribute on disconnected element." );
var body = document.body, $body = jQuery( body ); var body = document.body, $body = jQuery( body );
ok( $body.prop('nextSibling') === null, 'Make sure a null expando returns null' ); ok( $body.prop("nextSibling") === null, "Make sure a null expando returns null" );
body.foo = 'bar'; body.foo = "bar";
equals( $body.prop('foo'), 'bar', 'Make sure the expando is preferred over the dom attribute' ); equals( $body.prop("foo"), "bar", "Make sure the expando is preferred over the dom attribute" );
body.foo = undefined; body.foo = undefined;
ok( $body.prop('foo') === undefined, 'Make sure the expando is preferred over the dom attribute, even if undefined' ); ok( $body.prop("foo") === undefined, "Make sure the expando is preferred over the dom attribute, even if undefined" );
var select = document.createElement("select"), optgroup = document.createElement("optgroup"), option = document.createElement("option"); var select = document.createElement("select"), optgroup = document.createElement("optgroup"), option = document.createElement("option");
optgroup.appendChild( option ); optgroup.appendChild( option );
@ -78,62 +78,62 @@ test("prop(String, Object)", function() {
test("attr(String)", function() { test("attr(String)", function() {
expect(32); expect(32);
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" );
equals( jQuery('#check1').attr('type'), "checkbox", 'Check for type attribute' ); equals( jQuery("#check1").attr("type"), "checkbox", "Check for type attribute" );
equals( jQuery('#simon1').attr('rel'), "bookmark", 'Check for rel attribute' ); equals( jQuery("#simon1").attr("rel"), "bookmark", "Check for rel attribute" );
equals( jQuery('#google').attr('title'), "Google!", 'Check for title attribute' ); equals( jQuery("#google").attr("title"), "Google!", "Check for title attribute" );
equals( jQuery('#mark').attr('hreflang'), "en", 'Check for hreflang attribute' ); equals( jQuery("#mark").attr("hreflang"), "en", "Check for hreflang attribute" );
equals( jQuery('#en').attr('lang'), "en", 'Check for lang attribute' ); equals( jQuery("#en").attr("lang"), "en", "Check for lang attribute" );
equals( jQuery('#simon').attr('class'), "blog link", 'Check for class attribute' ); equals( jQuery("#simon").attr("class"), "blog link", "Check for class attribute" );
equals( jQuery('#name').attr('name'), "name", 'Check for name attribute' ); equals( jQuery("#name").attr("name"), "name", "Check for name attribute" );
equals( jQuery('#text1').attr('name'), "action", 'Check for name attribute' ); equals( jQuery("#text1").attr("name"), "action", "Check for name attribute" );
ok( jQuery('#form').attr('action').indexOf("formaction") >= 0, 'Check for action attribute' ); ok( jQuery("#form").attr("action").indexOf("formaction") >= 0, "Check for action attribute" );
equals( jQuery('#form').attr('blah', 'blah').attr('blah'), 'blah', 'Set non-existant attribute on a form' ); equals( jQuery("#form").attr("blah", "blah").attr("blah"), "blah", "Set non-existant attribute on a form" );
equals( jQuery('#foo').attr('height'), undefined, 'Non existent height attribute should return undefined' ); equals( jQuery("#foo").attr("height"), undefined, "Non existent height attribute should return undefined" );
// [7472] & [3113] (form contains an input with name="action" or name="id") // [7472] & [3113] (form contains an input with name="action" or name="id")
var extras = jQuery('<input name="id" name="name" /><input id="target" name="target" />').appendTo('#testForm'); var extras = jQuery("<input name='id' name='name' /><input id='target' name='target' />").appendTo("#testForm");
equals( jQuery('#form').attr('action','newformaction').attr('action'), 'newformaction', 'Check that action attribute was changed' ); equals( jQuery("#form").attr("action","newformaction").attr("action"), "newformaction", "Check that action attribute was changed" );
equals( jQuery('#testForm').attr('target'), undefined, 'Retrieving target does not equal the input with name=target' ); equals( jQuery("#testForm").attr("target"), undefined, "Retrieving target does not equal the input with name=target" );
equals( jQuery('#testForm').attr('target', 'newTarget').attr('target'), 'newTarget', 'Set target successfully on a form' ); equals( jQuery("#testForm").attr("target", "newTarget").attr("target"), "newTarget", "Set target successfully on a form" );
equals( jQuery('#testForm').removeAttr('id').attr('id'), undefined, 'Retrieving id does not equal the input with name=id after id is removed [#7472]' ); equals( jQuery("#testForm").removeAttr("id").attr("id"), undefined, "Retrieving id does not equal the input with name=id after id is removed [#7472]" );
// Bug #3685 (form contains input with name="name") // Bug #3685 (form contains input with name="name")
equals( jQuery('#testForm').attr('name'), undefined, 'Retrieving name does not retrieve input with name=name' ); equals( jQuery("#testForm").attr("name"), undefined, "Retrieving name does not retrieve input with name=name" );
extras.remove(); extras.remove();
equals( jQuery('#text1').attr('maxlength'), '30', 'Check for maxlength attribute' ); equals( jQuery("#text1").attr("maxlength"), "30", "Check for maxlength attribute" );
equals( jQuery('#text1').attr('maxLength'), '30', 'Check for maxLength attribute' ); equals( jQuery("#text1").attr("maxLength"), "30", "Check for maxLength attribute" );
equals( jQuery('#area1').attr('maxLength'), '30', 'Check for maxLength attribute' ); equals( jQuery("#area1").attr("maxLength"), "30", "Check for maxLength attribute" );
// using innerHTML in IE causes href attribute to be serialized to the full path // using innerHTML in IE causes href attribute to be serialized to the full path
jQuery('<a/>').attr({ 'id': 'tAnchor5', 'href': '#5' }).appendTo('#main'); jQuery("<a/>").attr({ "id": "tAnchor5", "href": "#5" }).appendTo("#main");
equals( jQuery('#tAnchor5').attr('href'), "#5", 'Check for non-absolute href (an anchor)' ); equals( jQuery("#tAnchor5").attr("href"), "#5", "Check for non-absolute href (an anchor)" );
// list attribute is readonly by default in browsers that support it // list attribute is readonly by default in browsers that support it
jQuery('#list-test').attr('list', 'datalist'); jQuery("#list-test").attr("list", "datalist");
equals( jQuery('#list-test').attr('list'), 'datalist', 'Check setting list attribute' ); equals( jQuery("#list-test").attr("list"), "datalist", "Check setting list attribute" );
// Related to [5574] and [5683] // Related to [5574] and [5683]
var body = document.body, $body = jQuery(body); var body = document.body, $body = jQuery(body);
strictEqual( $body.attr('foo'), undefined, 'Make sure that a non existent attribute returns undefined' ); strictEqual( $body.attr("foo"), undefined, "Make sure that a non existent attribute returns undefined" );
body.setAttribute('foo', 'baz'); body.setAttribute("foo", "baz");
equals( $body.attr('foo'), 'baz', 'Make sure the dom attribute is retrieved when no expando is found' ); equals( $body.attr("foo"), "baz", "Make sure the dom attribute is retrieved when no expando is found" );
$body.attr('foo','cool'); $body.attr("foo","cool");
equals( $body.attr('foo'), 'cool', 'Make sure that setting works well when both expando and dom attribute are available' ); equals( $body.attr("foo"), "cool", "Make sure that setting works well when both expando and dom attribute are available" );
body.removeAttribute('foo'); // Cleanup body.removeAttribute("foo"); // Cleanup
var $img = jQuery('<img style="display:none" width="215" height="53" src="http://static.jquery.com/files/rocker/images/logo_jquery_215x53.gif"/>').appendTo('body'); var $img = jQuery("<img style='display:none' width='215' height='53' src='http://static.jquery.com/files/rocker/images/logo_jquery_215x53.gif'/>").appendTo("body");
equals( $img.attr('width'), "215", "Retrieve width attribute an an element with display:none." ); equals( $img.attr("width"), "215", "Retrieve width attribute an an element with display:none." );
equals( $img.attr('height'), "53", "Retrieve height attribute an an element with display:none." ); equals( $img.attr("height"), "53", "Retrieve height attribute an an element with display:none." );
// Check for style support // Check for style support
ok( !!~jQuery('#dl').attr('style').indexOf('position'), 'Check style attribute getter, also normalize css props to lowercase' ); ok( !!~jQuery("#dl").attr("style").indexOf("position"), "Check style attribute getter, also normalize css props to lowercase" );
ok( !!~jQuery('#foo').attr('style', 'position:absolute;').attr('style').indexOf('position'), 'Check style setter' ); ok( !!~jQuery("#foo").attr("style", "position:absolute;").attr("style").indexOf("position"), "Check style setter" );
ok( jQuery("<div/>").attr("doesntexist") === undefined, "Make sure undefined is returned when no attribute is found." ); ok( jQuery("<div/>").attr("doesntexist") === undefined, "Make sure undefined is returned when no attribute is found." );
ok( jQuery().attr("doesntexist") === undefined, "Make sure undefined is returned when no element is there." ); ok( jQuery().attr("doesntexist") === undefined, "Make sure undefined is returned when no element is there." );
@ -153,19 +153,19 @@ if ( !isLocal ) {
test("attr(String, Function)", function() { test("attr(String, Function)", function() {
expect(2); expect(2);
equals( jQuery('#text1').attr('value', function() { return this.id; })[0].value, "text1", "Set value from id" ); equals( jQuery("#text1").attr("value", function() { return this.id; })[0].value, "text1", "Set value from id" );
equals( jQuery('#text1').attr('title', function(i) { return i; }).attr('title'), "0", "Set value with an index"); equals( jQuery("#text1").attr("title", function(i) { return i; }).attr("title"), "0", "Set value with an index");
}); });
test("attr(Hash)", function() { test("attr(Hash)", function() {
expect(3); expect(3);
var pass = true; var pass = true;
jQuery("div").attr({foo: 'baz', zoo: 'ping'}).each(function(){ jQuery("div").attr({foo: "baz", zoo: "ping"}).each(function(){
if ( this.getAttribute('foo') != "baz" && this.getAttribute('zoo') != "ping" ) pass = false; if ( this.getAttribute("foo") != "baz" && this.getAttribute("zoo") != "ping" ) pass = false;
}); });
ok( pass, "Set Multiple Attributes" ); ok( pass, "Set Multiple Attributes" );
equals( jQuery('#text1').attr({'value': function() { return this.id; }})[0].value, "text1", "Set attribute to computed value #1" ); equals( jQuery("#text1").attr({value: function() { return this.id; }})[0].value, "text1", "Set attribute to computed value #1" );
equals( jQuery('#text1').attr({'title': function(i) { return i; }}).attr('title'), "0", "Set attribute to computed value #2"); equals( jQuery("#text1").attr({title: function(i) { return i; }}).attr("title"), "0", "Set attribute to computed value #2");
}); });
@ -176,7 +176,7 @@ test("attr(String, Object)", function() {
fail = false; fail = false;
for ( var i = 0; i < div.size(); i++ ) { for ( var i = 0; i < div.size(); i++ ) {
if ( div.get(i).getAttribute('foo') != "bar" ){ if ( div.get(i).getAttribute("foo") != "bar" ){
fail = i; fail = i;
break; break;
} }
@ -187,25 +187,25 @@ test("attr(String, Object)", function() {
// Fails on IE since recent changes to .attr() // Fails on IE since recent changes to .attr()
// ok( jQuery("#foo").attr({"width": null}), "Try to set an attribute to nothing" ); // ok( jQuery("#foo").attr({"width": null}), "Try to set an attribute to nothing" );
jQuery("#name").attr('name', 'something'); jQuery("#name").attr("name", "something");
equals( jQuery("#name").attr('name'), 'something', 'Set name attribute' ); equals( jQuery("#name").attr("name"), "something", "Set name attribute" );
jQuery("#name").attr('name', null); jQuery("#name").attr("name", null);
equals( jQuery("#name").attr('name'), undefined, 'Remove name attribute' ); equals( jQuery("#name").attr("name"), undefined, "Remove name attribute" );
jQuery("#check2").attr('checked', true); jQuery("#check2").attr("checked", true);
equals( document.getElementById('check2').checked, true, 'Set checked attribute' ); equals( document.getElementById("check2").checked, true, "Set checked attribute" );
jQuery("#check2").attr('checked', false); jQuery("#check2").attr("checked", false);
equals( document.getElementById('check2').checked, false, 'Set checked attribute' ); equals( document.getElementById("check2").checked, false, "Set checked attribute" );
jQuery("#text1").attr('readonly', true); jQuery("#text1").attr("readonly", true);
equals( document.getElementById('text1').readOnly, true, 'Set readonly attribute' ); equals( document.getElementById("text1").readOnly, true, "Set readonly attribute" );
jQuery("#text1").attr('readonly', false); jQuery("#text1").attr("readonly", false);
equals( document.getElementById('text1').readOnly, false, 'Set readonly attribute' ); equals( document.getElementById("text1").readOnly, false, "Set readonly attribute" );
jQuery("#name").attr('maxlength', '5'); jQuery("#name").attr("maxlength", "5");
equals( document.getElementById('name').maxLength, 5, 'Set maxlength attribute' ); equals( document.getElementById("name").maxLength, 5, "Set maxlength attribute" );
jQuery("#name").attr('maxLength', '10'); jQuery("#name").attr("maxLength", "10");
equals( document.getElementById('name').maxLength, 10, 'Set maxlength attribute' ); equals( document.getElementById("name").maxLength, 10, "Set maxlength attribute" );
var $p = jQuery('#firstp').attr('nonexisting', 'foo'); var $p = jQuery("#firstp").attr("nonexisting", "foo");
equals( $p.attr('nonexisting'), 'foo', "attr(name, value) works correctly for non existing attributes (bug #7500)."); equals( $p.attr("nonexisting"), "foo", "attr(name, value) works correctly for non existing attributes (bug #7500).");
$p.removeAttr('nonexisting'); $p.removeAttr("nonexisting");
var attributeNode = document.createAttribute("irrelevant"), var attributeNode = document.createAttribute("irrelevant"),
commentNode = document.createComment("some comment"), commentNode = document.createComment("some comment"),
@ -217,8 +217,8 @@ test("attr(String, Object)", function() {
strictEqual( $ele.attr("nonexisting"), undefined, "attr(name, value) works correctly on comment and text nodes (bug #7500)." ); strictEqual( $ele.attr("nonexisting"), undefined, "attr(name, value) works correctly on comment and text nodes (bug #7500)." );
}); });
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>"), 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 = table.find("td:first");
td.attr("rowspan", "2"); td.attr("rowspan", "2");
equals( td[0].rowSpan, 2, "Check rowspan is correctly set" ); equals( td[0].rowSpan, 2, "Check rowspan is correctly set" );
td.attr("colspan", "2"); td.attr("colspan", "2");
@ -227,12 +227,12 @@ test("attr(String, Object)", function() {
equals( table[0].cellSpacing, "2", "Check cellspacing is correctly set" ); equals( table[0].cellSpacing, "2", "Check cellspacing is correctly set" );
// for #1070 // for #1070
jQuery("#name").attr('someAttr', '0'); jQuery("#name").attr("someAttr", "0");
equals( jQuery("#name").attr('someAttr'), '0', 'Set attribute to a string of "0"' ); equals( jQuery("#name").attr("someAttr"), "0", "Set attribute to a string of \"0\"" );
jQuery("#name").attr('someAttr', 0); jQuery("#name").attr("someAttr", 0);
equals( jQuery("#name").attr('someAttr'), '0', 'Set attribute to the number 0' ); equals( jQuery("#name").attr("someAttr"), "0", "Set attribute to the number 0" );
jQuery("#name").attr('someAttr', 1); jQuery("#name").attr("someAttr", 1);
equals( jQuery("#name").attr('someAttr'), '1', 'Set attribute to the number 1' ); equals( jQuery("#name").attr("someAttr"), "1", "Set attribute to the number 1" );
// using contents will get comments regular, text, and comment nodes // using contents will get comments regular, text, and comment nodes
var j = jQuery("#nonnodes").contents(); var j = jQuery("#nonnodes").contents();
@ -244,51 +244,51 @@ test("attr(String, Object)", function() {
QUnit.reset(); QUnit.reset();
// Type // Type
var type = jQuery("#check2").attr('type'); var type = jQuery("#check2").attr("type");
var thrown = false; var thrown = false;
try { try {
jQuery("#check2").attr('type','hidden'); jQuery("#check2").attr("type","hidden");
} catch(e) { } catch(e) {
thrown = true; thrown = true;
} }
ok( thrown, "Exception thrown when trying to change type property" ); ok( thrown, "Exception thrown when trying to change type property" );
equals( type, jQuery("#check2").attr('type'), "Verify that you can't change the type of an input element" ); equals( type, jQuery("#check2").attr("type"), "Verify that you can't change the type of an input element" );
var check = document.createElement("input"); var check = document.createElement("input");
var thrown = true; var thrown = true;
try { try {
jQuery(check).attr('type','checkbox'); jQuery(check).attr("type", "checkbox");
} catch(e) { } catch(e) {
thrown = false; thrown = false;
} }
ok( thrown, "Exception thrown when trying to change type property" ); ok( thrown, "Exception thrown when trying to change type property" );
equals( "checkbox", jQuery(check).attr('type'), "Verify that you can change the type of an input element that isn't in the DOM" ); equals( "checkbox", jQuery(check).attr("type"), "Verify that you can change the type of an input element that isn't in the DOM" );
var check = jQuery("<input />"); var check = jQuery("<input />");
var thrown = true; var thrown = true;
try { try {
check.attr('type','checkbox'); check.attr("type","checkbox");
} catch(e) { } catch(e) {
thrown = false; thrown = false;
} }
ok( thrown, "Exception thrown when trying to change type property" ); ok( thrown, "Exception thrown when trying to change type property" );
equals( "checkbox", check.attr('type'), "Verify that you can change the type of an input element that isn't in the DOM" ); equals( "checkbox", check.attr("type"), "Verify that you can change the type of an input element that isn't in the DOM" );
var button = jQuery("#button"); var button = jQuery("#button");
var thrown = false; var thrown = false;
try { try {
button.attr('type','submit'); button.attr("type","submit");
} catch(e) { } catch(e) {
thrown = true; thrown = true;
} }
ok( thrown, "Exception thrown when trying to change type property" ); ok( thrown, "Exception thrown when trying to change type property" );
equals( "button", button.attr('type'), "Verify that you can't change the type of a button element" ); equals( "button", button.attr("type"), "Verify that you can't change the type of a button element" );
// Setting attributes on svg elements (bug #3116) // Setting attributes on svg elements (bug #3116)
var $svg = jQuery('<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" baseProfile="full" width="3000" height="3000">' var $svg = jQuery("<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' version='1.1' baseProfile='full' width='200' height='200'>"
+ '<circle cx="200" cy="200" r="150" />' + "<circle cx='200' cy='200' r='150' />"
+ '</svg>').appendTo('body'); + "</svg>").appendTo("body");
equals( $svg.attr('cx', 100).attr('cx'), "100", "Set attribute on svg element" ); equals( $svg.attr("cx", 100).attr("cx"), "100", "Set attribute on svg element" );
$svg.remove(); $svg.remove();
}); });
@ -299,17 +299,17 @@ test("attr(jquery_method)", function(){
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
@ -318,22 +318,22 @@ test("attr(jquery_method)", function(){
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({...})");
}); });
if ( !isLocal ) { if ( !isLocal ) {
test("attr(String, Object) - Loaded via XML document", function() { test("attr(String, Object) - Loaded via XML document", function() {
expect(2); expect(2);
stop(); stop();
jQuery.get('data/dashboard.xml', function(xml) { jQuery.get("data/dashboard.xml", function(xml) {
var titles = []; var titles = [];
jQuery('tab', xml).each(function() { jQuery("tab", xml).each(function() {
titles.push(jQuery(this).attr('title')); titles.push(jQuery(this).attr("title"));
}); });
equals( titles[0], 'Location', 'attr() in XML context: Check first title' ); equals( titles[0], "Location", "attr() in XML context: Check first title" );
equals( titles[1], 'Users', 'attr() in XML context: Check second title' ); equals( titles[1], "Users", "attr() in XML context: Check second title" );
start(); start();
}); });
}); });
@ -343,64 +343,64 @@ test("attr('tabindex')", function() {
expect(8); expect(8);
// elements not natively tabbable // elements not natively tabbable
equals(jQuery('#listWithTabIndex').attr('tabindex'), 5, 'not natively tabbable, with tabindex set to 0'); equals(jQuery("#listWithTabIndex").attr("tabindex"), 5, "not natively tabbable, with tabindex set to 0");
equals(jQuery('#divWithNoTabIndex').attr('tabindex'), undefined, 'not natively tabbable, no tabindex set'); equals(jQuery("#divWithNoTabIndex").attr("tabindex"), undefined, "not natively tabbable, no tabindex set");
// anchor with href // anchor with href
equals(jQuery('#linkWithNoTabIndex').attr('tabindex'), 0, 'anchor with href, no tabindex set'); equals(jQuery("#linkWithNoTabIndex").attr("tabindex"), 0, "anchor with href, no tabindex set");
equals(jQuery('#linkWithTabIndex').attr('tabindex'), 2, 'anchor with href, tabindex set to 2'); equals(jQuery("#linkWithTabIndex").attr("tabindex"), 2, "anchor with href, tabindex set to 2");
equals(jQuery('#linkWithNegativeTabIndex').attr('tabindex'), -1, 'anchor with href, tabindex set to -1'); equals(jQuery("#linkWithNegativeTabIndex").attr("tabindex"), -1, "anchor with href, tabindex set to -1");
// anchor without href // anchor without href
equals(jQuery('#linkWithNoHrefWithNoTabIndex').attr('tabindex'), undefined, 'anchor without href, no tabindex set'); equals(jQuery("#linkWithNoHrefWithNoTabIndex").attr("tabindex"), undefined, "anchor without href, no tabindex set");
equals(jQuery('#linkWithNoHrefWithTabIndex').attr('tabindex'), 1, 'anchor without href, tabindex set to 2'); equals(jQuery("#linkWithNoHrefWithTabIndex").attr("tabindex"), 1, "anchor without href, tabindex set to 2");
equals(jQuery('#linkWithNoHrefWithNegativeTabIndex').attr('tabindex'), -1, 'anchor without href, no tabindex set'); equals(jQuery("#linkWithNoHrefWithNegativeTabIndex").attr("tabindex"), -1, "anchor without href, no tabindex set");
}); });
test("attr('tabindex', value)", function() { test("attr('tabindex', value)", function() {
expect(9); expect(9);
var element = jQuery('#divWithNoTabIndex'); var element = jQuery("#divWithNoTabIndex");
equals(element.attr('tabindex'), undefined, 'start with no tabindex'); equals(element.attr("tabindex"), undefined, "start with no tabindex");
// set a positive string // set a positive string
element.attr('tabindex', '1'); element.attr("tabindex", "1");
equals(element.attr('tabindex'), 1, 'set tabindex to 1 (string)'); equals(element.attr("tabindex"), 1, "set tabindex to 1 (string)");
// set a zero string // set a zero string
element.attr('tabindex', '0'); element.attr("tabindex", "0");
equals(element.attr('tabindex'), 0, 'set tabindex to 0 (string)'); equals(element.attr("tabindex"), 0, "set tabindex to 0 (string)");
// set a negative string // set a negative string
element.attr('tabindex', '-1'); element.attr("tabindex", "-1");
equals(element.attr('tabindex'), -1, 'set tabindex to -1 (string)'); equals(element.attr("tabindex"), -1, "set tabindex to -1 (string)");
// set a positive number // set a positive number
element.attr('tabindex', 1); element.attr("tabindex", 1);
equals(element.attr('tabindex'), 1, 'set tabindex to 1 (number)'); equals(element.attr("tabindex"), 1, "set tabindex to 1 (number)");
// set a zero number // set a zero number
element.attr('tabindex', 0); element.attr("tabindex", 0);
equals(element.attr('tabindex'), 0, 'set tabindex to 0 (number)'); equals(element.attr("tabindex"), 0, "set tabindex to 0 (number)");
// set a negative number // set a negative number
element.attr('tabindex', -1); element.attr("tabindex", -1);
equals(element.attr('tabindex'), -1, 'set tabindex to -1 (number)'); equals(element.attr("tabindex"), -1, "set tabindex to -1 (number)");
element = jQuery('#linkWithTabIndex'); element = jQuery("#linkWithTabIndex");
equals(element.attr('tabindex'), 2, 'start with tabindex 2'); equals(element.attr("tabindex"), 2, "start with tabindex 2");
element.attr('tabindex', -1); element.attr("tabindex", -1);
equals(element.attr('tabindex'), -1, 'set negative tabindex'); equals(element.attr("tabindex"), -1, "set negative tabindex");
}); });
test("removeAttr(String)", function() { test("removeAttr(String)", function() {
expect(5); expect(5);
equals( jQuery('#mark').removeAttr( "class" )[0].className, "", "remove class" ); equals( jQuery("#mark").removeAttr( "class" )[0].className, "", "remove class" );
equals( jQuery('#form').removeAttr('id').attr('id'), undefined, 'Remove id' ); equals( jQuery("#form").removeAttr("id").attr("id"), undefined, "Remove id" );
equals( jQuery('#foo').attr('style', 'position:absolute;').removeAttr('style').attr('style'), undefined, 'Check removing style attribute' ); equals( jQuery("#foo").attr("style", "position:absolute;").removeAttr("style").attr("style"), undefined, "Check removing style attribute" );
equals( jQuery('#form').attr('style', 'position:absolute;').removeAttr('style').attr('style'), undefined, 'Check removing style attribute on a form' ); equals( jQuery("#form").attr("style", "position:absolute;").removeAttr("style").attr("style"), undefined, "Check removing style attribute on a form" );
equals( jQuery('#fx-test-group').attr('height', '3px').removeAttr('height').css('height'), "1px", 'Removing height attribute has no effect on height set with style attribute' ); equals( jQuery("#fx-test-group").attr("height", "3px").removeAttr("height").css("height"), "1px", "Removing height attribute has no effect on height set with style attribute" );
}); });
test("removeProp(String)", function() { test("removeProp(String)", function() {
@ -427,7 +427,7 @@ test("removeProp(String)", function() {
test("val()", function() { test("val()", function() {
expect(23); expect(23);
document.getElementById('text1').value = "bla"; document.getElementById("text1").value = "bla";
equals( jQuery("#text1").val(), "bla", "Check for modified value of input element" ); equals( jQuery("#text1").val(), "bla", "Check for modified value of input element" );
QUnit.reset(); QUnit.reset();
@ -437,36 +437,36 @@ test("val()", function() {
equals( jQuery("#first").val(), "", "Check a paragraph element to see if it has a value" ); equals( jQuery("#first").val(), "", "Check a paragraph element to see if it has a value" );
ok( jQuery([]).val() === undefined, "Check an empty jQuery object will return undefined from val" ); ok( jQuery([]).val() === undefined, "Check an empty jQuery object will return undefined from val" );
equals( jQuery('#select2').val(), '3', 'Call val() on a single="single" select' ); equals( jQuery("#select2").val(), "3", "Call val() on a single=\"single\" select" );
same( jQuery('#select3').val(), ['1', '2'], 'Call val() on a multiple="multiple" select' ); same( jQuery("#select3").val(), ["1", "2"], "Call val() on a multiple=\"multiple\" select" );
equals( jQuery('#option3c').val(), '2', 'Call val() on a option element with value' ); equals( jQuery("#option3c").val(), "2", "Call val() on a option element with value" );
equals( jQuery('#option3a').val(), '', 'Call val() on a option element with empty value' ); equals( jQuery("#option3a").val(), "", "Call val() on a option element with empty value" );
equals( jQuery('#option3e').val(), 'no value', 'Call val() on a option element with no value attribute' ); equals( jQuery("#option3e").val(), "no value", "Call val() on a option element with no value attribute" );
equals( jQuery('#option3a').val(), '', 'Call val() on a option element with no value attribute' ); equals( jQuery("#option3a").val(), "", "Call val() on a option element with no value attribute" );
jQuery('#select3').val(""); jQuery("#select3").val("");
same( jQuery('#select3').val(), [''], 'Call val() on a multiple="multiple" select' ); same( jQuery("#select3").val(), [""], "Call val() on a multiple=\"multiple\" select" );
same( jQuery('#select4').val(), [], 'Call val() on multiple="multiple" select with all disabled options' ); same( jQuery("#select4").val(), [], "Call val() on multiple=\"multiple\" select with all disabled options" );
jQuery('#select4 optgroup').add('#select4 > [disabled]').attr('disabled', false); jQuery("#select4 optgroup").add("#select4 > [disabled]").attr("disabled", false);
same( jQuery('#select4').val(), ['2', '3'], 'Call val() on multiple="multiple" select with some disabled options' ); same( jQuery("#select4").val(), ["2", "3"], "Call val() on multiple=\"multiple\" select with some disabled options" );
jQuery('#select4').attr('disabled', true); jQuery("#select4").attr("disabled", true);
same( jQuery('#select4').val(), ['2', '3'], 'Call val() on disabled multiple="multiple" select' ); same( jQuery("#select4").val(), ["2", "3"], "Call val() on disabled multiple=\"multiple\" select" );
equals( jQuery('#select5').val(), "3", "Check value on ambiguous select." ); equals( jQuery("#select5").val(), "3", "Check value on ambiguous select." );
jQuery('#select5').val(1); jQuery("#select5").val(1);
equals( jQuery('#select5').val(), "1", "Check value on ambiguous select." ); equals( jQuery("#select5").val(), "1", "Check value on ambiguous select." );
jQuery('#select5').val(3); jQuery("#select5").val(3);
equals( jQuery('#select5').val(), "3", "Check value on ambiguous select." ); equals( jQuery("#select5").val(), "3", "Check value on ambiguous select." );
var checks = jQuery("<input type='checkbox' name='test' value='1'/><input type='checkbox' name='test' value='2'/><input type='checkbox' name='test' value=''/><input type='checkbox' name='test'/>").appendTo("#form"); var checks = jQuery("<input type='checkbox' name='test' value='1'/><input type='checkbox' name='test' value='2'/><input type='checkbox' name='test' value=''/><input type='checkbox' name='test'/>").appendTo("#form");
@ -492,27 +492,29 @@ test("val()", function() {
var testVal = function(valueObj) { var testVal = function(valueObj) {
expect(8); expect(8);
jQuery("#text1").val(valueObj( 'test' )); QUnit.reset();
equals( document.getElementById('text1').value, "test", "Check for modified (via val(String)) value of input element" ); jQuery("#text1").val(valueObj( "test" ));
equals( document.getElementById("text1").value, "test", "Check for modified (via val(String)) value of input element" );
jQuery("#text1").val(valueObj( undefined )); jQuery("#text1").val(valueObj( undefined ));
equals( document.getElementById('text1').value, "", "Check for modified (via val(undefined)) value of input element" ); equals( document.getElementById("text1").value, "", "Check for modified (via val(undefined)) value of input element" );
jQuery("#text1").val(valueObj( 67 )); jQuery("#text1").val(valueObj( 67 ));
equals( document.getElementById('text1').value, "67", "Check for modified (via val(Number)) value of input element" ); equals( document.getElementById("text1").value, "67", "Check for modified (via val(Number)) value of input element" );
jQuery("#text1").val(valueObj( null )); jQuery("#text1").val(valueObj( null ));
equals( document.getElementById('text1').value, "", "Check for modified (via val(null)) value of input element" ); equals( document.getElementById("text1").value, "", "Check for modified (via val(null)) value of input element" );
jQuery("#select1").val(valueObj( "3" )); var $select1 = jQuery("#select1");
equals( jQuery("#select1").val(), "3", "Check for modified (via val(String)) value of select element" ); $select1.val(valueObj( "3" ));
equals( $select1.val(), "3", "Check for modified (via val(String)) value of select element" );
jQuery("#select1").val(valueObj( 2 )); $select1.val(valueObj( 2 ));
equals( jQuery("#select1").val(), "2", "Check for modified (via val(Number)) value of select element" ); equals( $select1.val(), "2", "Check for modified (via val(Number)) value of select element" );
jQuery("#select1").append("<option value='4'>four</option>"); $select1.append("<option value='4'>four</option>");
jQuery("#select1").val(valueObj( 4 )); $select1.val(valueObj( 4 ));
equals( jQuery("#select1").val(), "4", "Should be possible to set the val() to a newly created option" ); equals( $select1.val(), "4", "Should be possible to set the val() to a newly created option" );
// using contents will get comments regular, text, and comment nodes // using contents will get comments regular, text, and comment nodes
var j = jQuery("#nonnodes").contents(); var j = jQuery("#nonnodes").contents();
@ -531,8 +533,8 @@ test("val(Function)", function() {
test( "val(Array of Numbers) (Bug #7123)", function() { test( "val(Array of Numbers) (Bug #7123)", function() {
expect(4); expect(4);
jQuery('#form').append('<input type="checkbox" name="arrayTest" value="1" /><input type="checkbox" name="arrayTest" value="2" /><input type="checkbox" name="arrayTest" value="3" checked="checked" /><input type="checkbox" name="arrayTest" value="4" />'); jQuery("#form").append("<input type='checkbox' name='arrayTest' value='1' /><input type='checkbox' name='arrayTest' value='2' /><input type='checkbox' name='arrayTest' value='3' checked='checked' /><input type='checkbox' name='arrayTest' value='4' />");
var elements = jQuery('input[name=arrayTest]').val([ 1, 2 ]); var elements = jQuery("input[name=arrayTest]").val([ 1, 2 ]);
ok( elements[0].checked, "First element was checked" ); ok( elements[0].checked, "First element was checked" );
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" );
@ -551,7 +553,7 @@ test("val(Function) with incoming value", function() {
return "test"; return "test";
}); });
equals( document.getElementById('text1').value, "test", "Check for modified (via val(String)) value of input element" ); equals( document.getElementById("text1").value, "test", "Check for modified (via val(String)) value of input element" );
oldVal = jQuery("#text1").val(); oldVal = jQuery("#text1").val();
@ -560,7 +562,7 @@ test("val(Function) with incoming value", function() {
return 67; return 67;
}); });
equals( document.getElementById('text1').value, "67", "Check for modified (via val(Number)) value of input element" ); equals( document.getElementById("text1").value, "67", "Check for modified (via val(Number)) value of input element" );
oldVal = jQuery("#select1").val(); oldVal = jQuery("#select1").val();
@ -596,7 +598,7 @@ test("val(Function) with incoming value", function() {
test("val(select) after form.reset() (Bug #2551)", function() { test("val(select) after form.reset() (Bug #2551)", function() {
expect(3); expect(3);
jQuery('<form id="kk" name="kk"><select id="kkk"><option value="cf">cf</option><option value="gf">gf</option></select></form>').appendTo("#main"); jQuery("<form id='kk' name='kk'><select id='kkk'><option value='cf'>cf</option><option value='gf'>gf</option></select></form>").appendTo("#main");
jQuery("#kkk").val( "gf" ); jQuery("#kkk").val( "gf" );
@ -606,7 +608,7 @@ test("val(select) after form.reset() (Bug #2551)", function() {
equal( jQuery("#kkk").val(), "cf", "Check value of select after form reset." ); equal( jQuery("#kkk").val(), "cf", "Check value of select after form reset." );
// re-verify the multi-select is not broken (after form.reset) by our fix for single-select // re-verify the multi-select is not broken (after form.reset) by our fix for single-select
same( jQuery('#select3').val(), ['1', '2'], 'Call val() on a multiple="multiple" select' ); same( jQuery("#select3").val(), ["1", "2"], "Call val() on a multiple=\"multiple\" select" );
jQuery("#kk").remove(); jQuery("#kk").remove();
}); });
@ -671,29 +673,29 @@ test("addClass(Function) with incoming value", function() {
var testRemoveClass = function(valueObj) { var testRemoveClass = function(valueObj) {
expect(7); expect(7);
var $divs = jQuery('div'); var $divs = jQuery("div");
$divs.addClass("test").removeClass( valueObj("test") ); $divs.addClass("test").removeClass( valueObj("test") );
ok( !$divs.is('.test'), "Remove Class" ); ok( !$divs.is(".test"), "Remove Class" );
QUnit.reset(); QUnit.reset();
$divs = jQuery('div'); $divs = jQuery("div");
$divs.addClass("test").addClass("foo").addClass("bar"); $divs.addClass("test").addClass("foo").addClass("bar");
$divs.removeClass( valueObj("test") ).removeClass( valueObj("bar") ).removeClass( valueObj("foo") ); $divs.removeClass( valueObj("test") ).removeClass( valueObj("bar") ).removeClass( valueObj("foo") );
ok( !$divs.is('.test,.bar,.foo'), "Remove multiple classes" ); ok( !$divs.is(".test,.bar,.foo"), "Remove multiple classes" );
QUnit.reset(); QUnit.reset();
$divs = jQuery('div'); $divs = jQuery("div");
// Make sure that a null value doesn't cause problems // Make sure that a null value doesn't cause problems
$divs.eq(0).addClass("test").removeClass( valueObj(null) ); $divs.eq(0).addClass("test").removeClass( valueObj(null) );
ok( $divs.eq(0).is('.test'), "Null value passed to removeClass" ); ok( $divs.eq(0).is(".test"), "Null value passed to removeClass" );
$divs.eq(0).addClass("test").removeClass( valueObj("") ); $divs.eq(0).addClass("test").removeClass( valueObj("") );
ok( $divs.eq(0).is('.test'), "Empty string passed to removeClass" ); ok( $divs.eq(0).is(".test"), "Empty string passed to removeClass" );
// using contents will get regular, text, and comment nodes // using contents will get regular, text, and comment nodes
var j = jQuery("#nonnodes").contents(); var j = jQuery("#nonnodes").contents();
@ -723,7 +725,7 @@ test("removeClass(Function) - simple", function() {
test("removeClass(Function) with incoming value", function() { test("removeClass(Function) with incoming value", function() {
expect(45); expect(45);
var $divs = jQuery('div').addClass("test"), old = $divs.map(function(){ var $divs = jQuery("div").addClass("test"), old = $divs.map(function(){
return jQuery(this).attr("class"); return jQuery(this).attr("class");
}); });
@ -734,7 +736,7 @@ test("removeClass(Function) with incoming value", function() {
} }
}); });
ok( !$divs.is('.test'), "Remove Class" ); ok( !$divs.is(".test"), "Remove Class" );
QUnit.reset(); QUnit.reset();
}); });
@ -772,7 +774,7 @@ var testToggleClass = function(valueObj) {
ok( e.is(".testD.testE"), "Assert class present" ); ok( e.is(".testD.testE"), "Assert class present" );
e.toggleClass(); e.toggleClass();
ok( !e.is(".testD.testE"), "Assert class not present" ); ok( !e.is(".testD.testE"), "Assert class not present" );
ok( jQuery._data(e[0], '__className__') === 'testD testE', "Assert data was stored" ); ok( jQuery._data(e[0], "__className__") === "testD testE", "Assert data was stored" );
e.toggleClass(); e.toggleClass();
ok( e.is(".testD.testE"), "Assert class present (restored from data)" ); ok( e.is(".testD.testE"), "Assert class present (restored from data)" );
e.toggleClass(false); e.toggleClass(false);
@ -786,7 +788,7 @@ var testToggleClass = function(valueObj) {
// Cleanup // Cleanup
e.removeClass("testD"); e.removeClass("testD");
jQuery.removeData(e[0], '__className__', true); jQuery.removeData(e[0], "__className__", true);
}; };
test("toggleClass(String|boolean|undefined[, boolean])", function() { test("toggleClass(String|boolean|undefined[, boolean])", function() {
@ -847,7 +849,7 @@ test("toggleClass(Fucntion[, boolean]) with incoming value", function() {
// Cleanup // Cleanup
e.removeClass("test"); e.removeClass("test");
jQuery.removeData(e[0], '__className__', true); jQuery.removeData(e[0], "__className__", true);
}); });
test("addClass, removeClass, hasClass", function() { test("addClass, removeClass, hasClass", function() {

View file

@ -62,7 +62,7 @@ test("jQuery()", function() {
equals( jQuery([1,2,3]).get(1), 2, "Test passing an array to the factory" ); equals( jQuery([1,2,3]).get(1), 2, "Test passing an array to the factory" );
equals( jQuery(document.body).get(0), jQuery('body').get(0), "Test passing an html node to the factory" ); equals( jQuery(document.body).get(0), jQuery("body").get(0), "Test passing an html node to the factory" );
var exec = false; var exec = false;
@ -75,13 +75,13 @@ test("jQuery()", function() {
id: "test3" id: "test3"
}); });
equals( elem[0].style.width, '10px', 'jQuery() quick setter width'); equals( elem[0].style.width, "10px", "jQuery() quick setter width");
equals( elem[0].style.paddingLeft, '1px', 'jQuery quick setter css'); equals( elem[0].style.paddingLeft, "1px", "jQuery quick setter css");
equals( elem[0].style.paddingRight, '1px', 'jQuery quick setter css'); equals( elem[0].style.paddingRight, "1px", "jQuery quick setter css");
equals( elem[0].childNodes.length, 1, 'jQuery quick setter text'); equals( elem[0].childNodes.length, 1, "jQuery quick setter text");
equals( elem[0].firstChild.nodeValue, "test", 'jQuery quick setter text'); equals( elem[0].firstChild.nodeValue, "test", "jQuery quick setter text");
equals( elem[0].className, "test2", 'jQuery() quick setter class'); equals( elem[0].className, "test2", "jQuery() quick setter class");
equals( elem[0].id, "test3", 'jQuery() quick setter id'); equals( elem[0].id, "test3", "jQuery() quick setter id");
exec = true; exec = true;
elem.click(); elem.click();
@ -460,7 +460,7 @@ if ( !isLocal ) {
test("isXMLDoc - XML", function() { test("isXMLDoc - XML", function() {
expect(3); expect(3);
stop(); stop();
jQuery.get('data/dashboard.xml', function(xml) { jQuery.get("data/dashboard.xml", function(xml) {
ok( jQuery.isXMLDoc( xml ), "XML document" ); ok( jQuery.isXMLDoc( xml ), "XML document" );
ok( jQuery.isXMLDoc( xml.documentElement ), "XML documentElement" ); ok( jQuery.isXMLDoc( xml.documentElement ), "XML documentElement" );
ok( jQuery.isXMLDoc( jQuery("tab", xml)[0] ), "XML Tab Element" ); ok( jQuery.isXMLDoc( jQuery("tab", xml)[0] ), "XML Tab Element" );
@ -524,15 +524,15 @@ test("jQuery('html')", function() {
// Test very large html string #7990 // Test very large html string #7990
var i; var i;
var li = '<li>very large html string</li>'; var li = "<li>very large html string</li>";
var html = ['<ul>']; var html = ["<ul>"];
for ( i = 0; i < 50000; i += 1 ) { for ( i = 0; i < 50000; i += 1 ) {
html.push(li); html.push(li);
} }
html.push('</ul>'); html.push("</ul>");
html = jQuery(html.join(''))[0]; html = jQuery(html.join(""))[0];
equals( html.nodeName.toUpperCase(), 'UL'); equals( html.nodeName.toUpperCase(), "UL");
equals( html.firstChild.nodeName.toUpperCase(), 'LI'); equals( html.firstChild.nodeName.toUpperCase(), "LI");
equals( html.childNodes.length, 50000 ); equals( html.childNodes.length, 50000 );
}); });
@ -548,7 +548,7 @@ if ( !isLocal ) {
test("jQuery(selector, xml).text(str) - Loaded via XML document", function() { test("jQuery(selector, xml).text(str) - Loaded via XML document", function() {
expect(2); expect(2);
stop(); stop();
jQuery.get('data/dashboard.xml', function(xml) { jQuery.get("data/dashboard.xml", function(xml) {
// tests for #1419 where IE was a problem // tests for #1419 where IE was a problem
var tab = jQuery("tab", xml).eq(0); var tab = jQuery("tab", xml).eq(0);
equals( tab.text(), "blabla", "Verify initial text correct" ); equals( tab.text(), "blabla", "Verify initial text correct" );
@ -561,12 +561,12 @@ test("jQuery(selector, xml).text(str) - Loaded via XML document", function() {
test("end()", function() { test("end()", function() {
expect(3); expect(3);
equals( 'Yahoo', jQuery('#yahoo').parent().end().text(), 'Check for end' ); equals( "Yahoo", jQuery("#yahoo").parent().end().text(), "Check for end" );
ok( jQuery('#yahoo').end(), 'Check for end with nothing to end' ); ok( jQuery("#yahoo").end(), "Check for end with nothing to end" );
var x = jQuery('#yahoo'); var x = jQuery("#yahoo");
x.parent(); x.parent();
equals( 'Yahoo', jQuery('#yahoo').text(), 'Check for non-destructive behaviour' ); equals( "Yahoo", jQuery("#yahoo").text(), "Check for non-destructive behaviour" );
}); });
test("length", function() { test("length", function() {
@ -606,7 +606,7 @@ test("get(-Number)",function() {
test("each(Function)", function() { test("each(Function)", function() {
expect(1); expect(1);
var div = jQuery("div"); var div = jQuery("div");
div.each(function(){this.foo = 'zoo';}); div.each(function(){this.foo = "zoo";});
var pass = true; var pass = true;
for ( var i = 0; i < div.size(); i++ ) { for ( var i = 0; i < div.size(); i++ ) {
if ( div.get(i).foo != "zoo" ) pass = false; if ( div.get(i).foo != "zoo" ) pass = false;
@ -625,7 +625,7 @@ test("slice()", function() {
same( $links.slice(-1).get(), q("mark"), "slice(-1)" ); same( $links.slice(-1).get(), q("mark"), "slice(-1)" );
same( $links.eq(1).get(), q("groups"), "eq(1)" ); same( $links.eq(1).get(), q("groups"), "eq(1)" );
same( $links.eq('2').get(), q("anchor1"), "eq('2')" ); same( $links.eq("2").get(), q("anchor1"), "eq('2')" );
same( $links.eq(-1).get(), q("mark"), "eq(-1)" ); same( $links.eq(-1).get(), q("mark"), "eq(-1)" );
}); });
@ -792,7 +792,7 @@ test("jQuery.extend(Object, Object)", function() {
ok( typeof ret.foo != "string", "Check to make sure values equal with coersion (but not actually equal) overwrite correctly" ); ok( typeof ret.foo != "string", "Check to make sure values equal with coersion (but not actually equal) overwrite correctly" );
var ret = jQuery.extend(true, { foo:"bar" }, { foo:null } ); var ret = jQuery.extend(true, { foo:"bar" }, { foo:null } );
ok( typeof ret.foo !== 'undefined', "Make sure a null value doesn't crash with deep extend, for #1908" ); ok( typeof ret.foo !== "undefined", "Make sure a null value doesn't crash with deep extend, for #1908" );
var obj = { foo:null }; var obj = { foo:null };
jQuery.extend(true, obj, { foo:"notnull" } ); jQuery.extend(true, obj, { foo:"notnull" } );
@ -818,7 +818,7 @@ test("jQuery.extend(Object, Object)", function() {
}); });
test("jQuery.each(Object,Function)", function() { test("jQuery.each(Object,Function)", function() {
expect(13); expect(14);
jQuery.each( [0,1,2], function(i, n){ jQuery.each( [0,1,2], function(i, n){
equals( i, n, "Check array iteration" ); equals( i, n, "Check array iteration" );
}); });
@ -845,17 +845,24 @@ test("jQuery.each(Object,Function)", function() {
equals( total, 3, "Looping over an object, with break" ); equals( total, 3, "Looping over an object, with break" );
var f = function(){}; var f = function(){};
f.foo = 'bar'; f.foo = "bar";
jQuery.each(f, function(i){ jQuery.each(f, function(i){
f[i] = 'baz'; f[i] = "baz";
}); });
equals( "baz", f.foo, "Loop over a function" ); equals( "baz", f.foo, "Loop over a function" );
var stylesheet_count = 0;
jQuery.each(document.styleSheets, function(i){
stylesheet_count++;
});
equals(stylesheet_count, 2, "should not throw an error in IE while looping over document.styleSheets and return proper amount");
}); });
test("jQuery.makeArray", function(){ test("jQuery.makeArray", function(){
expect(17); expect(17);
equals( jQuery.makeArray(jQuery('html>*'))[0].nodeName.toUpperCase(), "HEAD", "Pass makeArray a jQuery object" ); equals( jQuery.makeArray(jQuery("html>*"))[0].nodeName.toUpperCase(), "HEAD", "Pass makeArray a jQuery object" );
equals( jQuery.makeArray(document.getElementsByName("PWD")).slice(0,1)[0].name, "PWD", "Pass makeArray a nodelist" ); equals( jQuery.makeArray(document.getElementsByName("PWD")).slice(0,1)[0].name, "PWD", "Pass makeArray a nodelist" );
@ -885,11 +892,11 @@ test("jQuery.makeArray", function(){
equals( jQuery.makeArray(/a/)[0].constructor, RegExp, "Pass makeArray a regex" ); equals( jQuery.makeArray(/a/)[0].constructor, RegExp, "Pass makeArray a regex" );
ok( jQuery.makeArray(document.getElementById('form')).length >= 13, "Pass makeArray a form (treat as elements)" ); ok( jQuery.makeArray(document.getElementById("form")).length >= 13, "Pass makeArray a form (treat as elements)" );
// For #5610 // For #5610
same( jQuery.makeArray({'length': '0'}), [], "Make sure object is coerced properly."); same( jQuery.makeArray({length: "0"}), [], "Make sure object is coerced properly.");
same( jQuery.makeArray({'length': '5'}), [], "Make sure object is coerced properly."); same( jQuery.makeArray({length: "5"}), [], "Make sure object is coerced properly.");
}); });
test("jQuery.isEmptyObject", function(){ test("jQuery.isEmptyObject", function(){
@ -938,9 +945,9 @@ test("jQuery.parseJSON", function(){
equals( jQuery.parseJSON( "" ), null, "Nothing in, null out." ); equals( jQuery.parseJSON( "" ), null, "Nothing in, null out." );
same( jQuery.parseJSON("{}"), {}, "Plain object parsing." ); same( jQuery.parseJSON("{}"), {}, "Plain object parsing." );
same( jQuery.parseJSON('{"test":1}'), {"test":1}, "Plain object parsing." ); same( jQuery.parseJSON("{\"test\":1}"), {"test":1}, "Plain object parsing." );
same( jQuery.parseJSON('\n{"test":1}'), {"test":1}, "Make sure leading whitespaces are handled." ); same( jQuery.parseJSON("\n{\"test\":1}"), {"test":1}, "Make sure leading whitespaces are handled." );
try { try {
jQuery.parseJSON("{a:1}"); jQuery.parseJSON("{a:1}");
@ -964,7 +971,7 @@ test("jQuery.sub() - Static Methods", function(){
topLevelMethod: function() {return this.debug;}, topLevelMethod: function() {return this.debug;},
debug: false, debug: false,
config: { config: {
locale: 'en_US' locale: "en_US"
}, },
setup: function(config) { setup: function(config) {
this.extend(true, this.config, config); this.extend(true, this.config, config);
@ -973,37 +980,37 @@ test("jQuery.sub() - Static Methods", function(){
Subclass.fn.extend({subClassMethod: function() { return this;}}); Subclass.fn.extend({subClassMethod: function() { return this;}});
//Test Simple Subclass //Test Simple Subclass
ok(Subclass.topLevelMethod() === false, 'Subclass.topLevelMethod thought debug was true'); ok(Subclass.topLevelMethod() === false, "Subclass.topLevelMethod thought debug was true");
ok(Subclass.config.locale == 'en_US', Subclass.config.locale + ' is wrong!'); ok(Subclass.config.locale == "en_US", Subclass.config.locale + " is wrong!");
same(Subclass.config.test, undefined, 'Subclass.config.test is set incorrectly'); same(Subclass.config.test, undefined, "Subclass.config.test is set incorrectly");
equal(jQuery.ajax, Subclass.ajax, 'The subclass failed to get all top level methods'); equal(jQuery.ajax, Subclass.ajax, "The subclass failed to get all top level methods");
//Create a SubSubclass //Create a SubSubclass
var SubSubclass = Subclass.sub(); var SubSubclass = Subclass.sub();
//Make Sure the SubSubclass inherited properly //Make Sure the SubSubclass inherited properly
ok(SubSubclass.topLevelMethod() === false, 'SubSubclass.topLevelMethod thought debug was true'); ok(SubSubclass.topLevelMethod() === false, "SubSubclass.topLevelMethod thought debug was true");
ok(SubSubclass.config.locale == 'en_US', SubSubclass.config.locale + ' is wrong!'); ok(SubSubclass.config.locale == "en_US", SubSubclass.config.locale + " is wrong!");
same(SubSubclass.config.test, undefined, 'SubSubclass.config.test is set incorrectly'); same(SubSubclass.config.test, undefined, "SubSubclass.config.test is set incorrectly");
equal(jQuery.ajax, SubSubclass.ajax, 'The subsubclass failed to get all top level methods'); equal(jQuery.ajax, SubSubclass.ajax, "The subsubclass failed to get all top level methods");
//Modify The Subclass and test the Modifications //Modify The Subclass and test the Modifications
SubSubclass.fn.extend({subSubClassMethod: function() { return this;}}); SubSubclass.fn.extend({subSubClassMethod: function() { return this;}});
SubSubclass.setup({locale: 'es_MX', test: 'worked'}); SubSubclass.setup({locale: "es_MX", test: "worked"});
SubSubclass.debug = true; SubSubclass.debug = true;
SubSubclass.ajax = function() {return false;}; SubSubclass.ajax = function() {return false;};
ok(SubSubclass.topLevelMethod(), 'SubSubclass.topLevelMethod thought debug was false'); ok(SubSubclass.topLevelMethod(), "SubSubclass.topLevelMethod thought debug was false");
same(SubSubclass(document).subClassMethod, Subclass.fn.subClassMethod, 'Methods Differ!'); same(SubSubclass(document).subClassMethod, Subclass.fn.subClassMethod, "Methods Differ!");
ok(SubSubclass.config.locale == 'es_MX', SubSubclass.config.locale + ' is wrong!'); ok(SubSubclass.config.locale == "es_MX", SubSubclass.config.locale + " is wrong!");
ok(SubSubclass.config.test == 'worked', 'SubSubclass.config.test is set incorrectly'); ok(SubSubclass.config.test == "worked", "SubSubclass.config.test is set incorrectly");
notEqual(jQuery.ajax, SubSubclass.ajax, 'The subsubclass failed to get all top level methods'); notEqual(jQuery.ajax, SubSubclass.ajax, "The subsubclass failed to get all top level methods");
//This shows that the modifications to the SubSubClass did not bubble back up to it's superclass //This shows that the modifications to the SubSubClass did not bubble back up to it's superclass
ok(Subclass.topLevelMethod() === false, 'Subclass.topLevelMethod thought debug was true'); ok(Subclass.topLevelMethod() === false, "Subclass.topLevelMethod thought debug was true");
ok(Subclass.config.locale == 'en_US', Subclass.config.locale + ' is wrong!'); ok(Subclass.config.locale == "en_US", Subclass.config.locale + " is wrong!");
same(Subclass.config.test, undefined, 'Subclass.config.test is set incorrectly'); same(Subclass.config.test, undefined, "Subclass.config.test is set incorrectly");
same(Subclass(document).subSubClassMethod, undefined, 'subSubClassMethod set incorrectly'); same(Subclass(document).subSubClassMethod, undefined, "subSubClassMethod set incorrectly");
equal(jQuery.ajax, Subclass.ajax, 'The subclass failed to get all top level methods'); equal(jQuery.ajax, Subclass.ajax, "The subclass failed to get all top level methods");
}); });
test("jQuery.sub() - .fn Methods", function(){ test("jQuery.sub() - .fn Methods", function(){
@ -1014,25 +1021,25 @@ test("jQuery.sub() - .fn Methods", function(){
jQueryDocument = jQuery(document), jQueryDocument = jQuery(document),
selectors, contexts, methods, method, arg, description; selectors, contexts, methods, method, arg, description;
jQueryDocument.toString = function(){ return 'jQueryDocument'; }; jQueryDocument.toString = function(){ return "jQueryDocument"; };
Subclass.fn.subclassMethod = function(){}; Subclass.fn.subclassMethod = function(){};
SubclassSubclass.fn.subclassSubclassMethod = function(){}; SubclassSubclass.fn.subclassSubclassMethod = function(){};
selectors = [ selectors = [
'body', "body",
'html, body', "html, body",
'<div></div>' "<div></div>"
]; ];
methods = [ // all methods that return a new jQuery instance methods = [ // all methods that return a new jQuery instance
['eq', 1], ["eq", 1],
['add', document], ["add", document],
['end'], ["end"],
['has'], ["has"],
['closest', 'div'], ["closest", "div"],
['filter', document], ["filter", document],
['find', 'div'] ["find", "div"]
]; ];
contexts = [undefined, document, jQueryDocument]; contexts = [undefined, document, jQueryDocument];
@ -1045,31 +1052,31 @@ test("jQuery.sub() - .fn Methods", function(){
jQuery.each(contexts, function(i, context){ jQuery.each(contexts, function(i, context){
description = '("'+selector+'", '+context+').'+method+'('+(arg||'')+')'; description = "(\""+selector+"\", "+context+")."+method+"("+(arg||"")+")";
same( same(
jQuery(selector, context)[method](arg).subclassMethod, undefined, jQuery(selector, context)[method](arg).subclassMethod, undefined,
'jQuery'+description+' doesnt have Subclass methods' "jQuery"+description+" doesn't have Subclass methods"
); );
same( same(
jQuery(selector, context)[method](arg).subclassSubclassMethod, undefined, jQuery(selector, context)[method](arg).subclassSubclassMethod, undefined,
'jQuery'+description+' doesnt have SubclassSubclass methods' "jQuery"+description+" doesn't have SubclassSubclass methods"
); );
same( same(
Subclass(selector, context)[method](arg).subclassMethod, Subclass.fn.subclassMethod, Subclass(selector, context)[method](arg).subclassMethod, Subclass.fn.subclassMethod,
'Subclass'+description+' has Subclass methods' "Subclass"+description+" has Subclass methods"
); );
same( same(
Subclass(selector, context)[method](arg).subclassSubclassMethod, undefined, Subclass(selector, context)[method](arg).subclassSubclassMethod, undefined,
'Subclass'+description+' doesnt have SubclassSubclass methods' "Subclass"+description+" doesn't have SubclassSubclass methods"
); );
same( same(
SubclassSubclass(selector, context)[method](arg).subclassMethod, Subclass.fn.subclassMethod, SubclassSubclass(selector, context)[method](arg).subclassMethod, Subclass.fn.subclassMethod,
'SubclassSubclass'+description+' has Subclass methods' "SubclassSubclass"+description+" has Subclass methods"
); );
same( same(
SubclassSubclass(selector, context)[method](arg).subclassSubclassMethod, SubclassSubclass.fn.subclassSubclassMethod, SubclassSubclass(selector, context)[method](arg).subclassSubclassMethod, SubclassSubclass.fn.subclassSubclassMethod,
'SubclassSubclass'+description+' has SubclassSubclass methods' "SubclassSubclass"+description+" has SubclassSubclass methods"
); );
}); });

View file

@ -1,15 +1,15 @@
module("css", { teardown: moduleTeardown }); module("css", { teardown: moduleTeardown });
test("css(String|Hash)", function() { test("css(String|Hash)", function() {
expect(41); expect( 42 );
equals( jQuery('#main').css("display"), 'block', 'Check for css property "display"'); equals( jQuery("#main").css("display"), "block", "Check for css property \"display\"");
ok( jQuery('#nothiddendiv').is(':visible'), 'Modifying CSS display: Assert element is visible'); ok( jQuery("#nothiddendiv").is(":visible"), "Modifying CSS display: Assert element is visible");
jQuery('#nothiddendiv').css({display: 'none'}); jQuery("#nothiddendiv").css({display: "none"});
ok( !jQuery('#nothiddendiv').is(':visible'), 'Modified CSS display: Assert element is hidden'); ok( !jQuery("#nothiddendiv").is(":visible"), "Modified CSS display: Assert element is hidden");
jQuery('#nothiddendiv').css({display: 'block'}); jQuery("#nothiddendiv").css({display: "block"});
ok( jQuery('#nothiddendiv').is(':visible'), 'Modified CSS display: Assert element is visible'); ok( jQuery("#nothiddendiv").is(":visible"), "Modified CSS display: Assert element is visible");
var div = jQuery( "<div>" ); var div = jQuery( "<div>" );
@ -32,34 +32,37 @@ test("css(String|Hash)", function() {
div2.remove(); div2.remove();
// handle negative numbers by ignoring #1599, #4216 // handle negative numbers by ignoring #1599, #4216
jQuery('#nothiddendiv').css({ 'width': 1, 'height': 1 }); jQuery("#nothiddendiv").css( {width: 1, height: 1} );
var width = parseFloat(jQuery('#nothiddendiv').css('width')), height = parseFloat(jQuery('#nothiddendiv').css('height')); var width = parseFloat(jQuery("#nothiddendiv").css("width")), height = parseFloat(jQuery("#nothiddendiv").css("height"));
jQuery('#nothiddendiv').css({ width: -1, height: -1 }); jQuery("#nothiddendiv").css({ width: -1, height: -1 });
equals( parseFloat(jQuery('#nothiddendiv').css('width')), width, 'Test negative width ignored') equals( parseFloat(jQuery("#nothiddendiv").css("width")), width, "Test negative width ignored")
equals( parseFloat(jQuery('#nothiddendiv').css('height')), height, 'Test negative height ignored') equals( parseFloat(jQuery("#nothiddendiv").css("height")), height, "Test negative height ignored")
equals( jQuery('<div style="display: none;">').css('display'), 'none', 'Styles on disconnected nodes'); equals( jQuery("<div style='display: none;'>").css("display"), "none", "Styles on disconnected nodes");
jQuery('#floatTest').css({'float': 'right'}); jQuery("#floatTest").css({"float": "right"});
equals( jQuery('#floatTest').css('float'), 'right', 'Modified CSS float using "float": Assert float is right'); equals( jQuery("#floatTest").css("float"), "right", "Modified CSS float using \"float\": Assert float is right");
jQuery('#floatTest').css({'font-size': '30px'}); jQuery("#floatTest").css({"font-size": "30px"});
equals( jQuery('#floatTest').css('font-size'), '30px', 'Modified CSS font-size: Assert font-size is 30px'); equals( jQuery("#floatTest").css("font-size"), "30px", "Modified CSS font-size: Assert font-size is 30px");
jQuery.each("0,0.25,0.5,0.75,1".split(','), function(i, n) { jQuery.each("0,0.25,0.5,0.75,1".split(","), function(i, n) {
jQuery('#foo').css({opacity: n}); jQuery("#foo").css({opacity: n});
equals( jQuery('#foo').css('opacity'), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a String" ); equals( jQuery("#foo").css("opacity"), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a String" );
jQuery('#foo').css({opacity: parseFloat(n)}); jQuery("#foo").css({opacity: parseFloat(n)});
equals( jQuery('#foo').css('opacity'), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a Number" ); equals( jQuery("#foo").css("opacity"), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a Number" );
}); });
jQuery('#foo').css({opacity: ''}); jQuery("#foo").css({opacity: ""});
equals( jQuery('#foo').css('opacity'), '1', "Assert opacity is 1 when set to an empty String" ); equals( jQuery("#foo").css("opacity"), "1", "Assert opacity is 1 when set to an empty String" );
equals( jQuery('#empty').css('opacity'), '0', "Assert opacity is accessible via filter property set in stylesheet in IE" ); equals( jQuery("#empty").css("opacity"), "0", "Assert opacity is accessible via filter property set in stylesheet in IE" );
jQuery('#empty').css({ opacity: '1' }); jQuery("#empty").css({ opacity: "1" });
equals( jQuery('#empty').css('opacity'), '1', "Assert opacity is taken from style attribute when set vs stylesheet in IE with filters" ); equals( jQuery("#empty").css("opacity"), "1", "Assert opacity is taken from style attribute when set vs stylesheet in IE with filters" );
jQuery.support.opacity ?
ok(true, "Requires the same number of tests"):
ok( ~jQuery("#empty")[0].currentStyle.filter.indexOf("gradient"), "Assert setting opacity doesn't overwrite other filters of the stylesheet in IE" );
var div = jQuery('#nothiddendiv'), child = jQuery('#nothiddendivchild'); var div = jQuery("#nothiddendiv"), child = jQuery("#nothiddendivchild");
equals( parseInt(div.css("fontSize")), 16, "Verify fontSize px set." ); equals( parseInt(div.css("fontSize")), 16, "Verify fontSize px set." );
equals( parseInt(div.css("font-size")), 16, "Verify fontSize px set." ); equals( parseInt(div.css("font-size")), 16, "Verify fontSize px set." );
@ -107,7 +110,7 @@ test("css(String|Hash)", function() {
test("css() explicit and relative values", function() { test("css() explicit and relative values", function() {
expect(9); expect(9);
var $elem = jQuery('#nothiddendiv'); var $elem = jQuery("#nothiddendiv");
$elem.css({ width: 1, height: 1 }); $elem.css({ width: 1, height: 1 });
equals( $elem.width(), 1, "Initial css set or width/height works (hash)" ); equals( $elem.width(), 1, "Initial css set or width/height works (hash)" );
@ -140,28 +143,28 @@ test("css() explicit and relative values", function() {
test("css(String, Object)", function() { test("css(String, Object)", function() {
expect(22); expect(22);
ok( jQuery('#nothiddendiv').is(':visible'), 'Modifying CSS display: Assert element is visible'); ok( jQuery("#nothiddendiv").is(":visible"), "Modifying CSS display: Assert element is visible");
jQuery('#nothiddendiv').css("display", 'none'); jQuery("#nothiddendiv").css("display", "none");
ok( !jQuery('#nothiddendiv').is(':visible'), 'Modified CSS display: Assert element is hidden'); ok( !jQuery("#nothiddendiv").is(":visible"), "Modified CSS display: Assert element is hidden");
jQuery('#nothiddendiv').css("display", 'block'); jQuery("#nothiddendiv").css("display", "block");
ok( jQuery('#nothiddendiv').is(':visible'), 'Modified CSS display: Assert element is visible'); ok( jQuery("#nothiddendiv").is(":visible"), "Modified CSS display: Assert element is visible");
jQuery("#nothiddendiv").css("top", "-1em"); jQuery("#nothiddendiv").css("top", "-1em");
ok( jQuery("#nothiddendiv").css("top"), -16, "Check negative number in EMs." ); ok( jQuery("#nothiddendiv").css("top"), -16, "Check negative number in EMs." );
jQuery('#floatTest').css('float', 'left'); jQuery("#floatTest").css("float", "left");
equals( jQuery('#floatTest').css('float'), 'left', 'Modified CSS float using "float": Assert float is left'); equals( jQuery("#floatTest").css("float"), "left", "Modified CSS float using \"float\": Assert float is left");
jQuery('#floatTest').css('font-size', '20px'); jQuery("#floatTest").css("font-size", "20px");
equals( jQuery('#floatTest').css('font-size'), '20px', 'Modified CSS font-size: Assert font-size is 20px'); equals( jQuery("#floatTest").css("font-size"), "20px", "Modified CSS font-size: Assert font-size is 20px");
jQuery.each("0,0.25,0.5,0.75,1".split(','), function(i, n) { jQuery.each("0,0.25,0.5,0.75,1".split(","), function(i, n) {
jQuery('#foo').css('opacity', n); jQuery("#foo").css("opacity", n);
equals( jQuery('#foo').css('opacity'), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a String" ); equals( jQuery("#foo").css("opacity"), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a String" );
jQuery('#foo').css('opacity', parseFloat(n)); jQuery("#foo").css("opacity", parseFloat(n));
equals( jQuery('#foo').css('opacity'), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a Number" ); equals( jQuery("#foo").css("opacity"), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a Number" );
}); });
jQuery('#foo').css('opacity', ''); jQuery("#foo").css("opacity", "");
equals( jQuery('#foo').css('opacity'), '1', "Assert opacity is 1 when set to an empty String" ); equals( jQuery("#foo").css("opacity"), "1", "Assert opacity is 1 when set to an empty String" );
// using contents will get comments regular, text, and comment nodes // using contents will get comments regular, text, and comment nodes
var j = jQuery("#nonnodes").contents(); var j = jQuery("#nonnodes").contents();
@ -181,7 +184,7 @@ test("css(String, Object)", function() {
// Test for Bug #5509 // Test for Bug #5509
var success = true; var success = true;
try { try {
jQuery('#foo').css("backgroundColor", "rgba(0, 0, 0, 0.1)"); jQuery("#foo").css("backgroundColor", "rgba(0, 0, 0, 0.1)");
} }
catch (e) { catch (e) {
success = false; success = false;
@ -192,19 +195,19 @@ test("css(String, Object)", function() {
if ( !jQuery.support.opacity ) { if ( !jQuery.support.opacity ) {
test("css(String, Object) for MSIE", function() { test("css(String, Object) for MSIE", function() {
// for #1438, IE throws JS error when filter exists but doesn't have opacity in it // for #1438, IE throws JS error when filter exists but doesn't have opacity in it
jQuery('#foo').css("filter", "progid:DXImageTransform.Microsoft.Chroma(color='red');"); jQuery("#foo").css("filter", "progid:DXImageTransform.Microsoft.Chroma(color='red');");
equals( jQuery('#foo').css('opacity'), '1', "Assert opacity is 1 when a different filter is set in IE, #1438" ); equals( jQuery("#foo").css("opacity"), "1", "Assert opacity is 1 when a different filter is set in IE, #1438" );
var filterVal = "progid:DXImageTransform.Microsoft.Alpha(opacity=30) progid:DXImageTransform.Microsoft.Blur(pixelradius=5)"; var filterVal = "progid:DXImageTransform.Microsoft.Alpha(opacity=30) progid:DXImageTransform.Microsoft.Blur(pixelradius=5)";
var filterVal2 = "progid:DXImageTransform.Microsoft.alpha(opacity=100) progid:DXImageTransform.Microsoft.Blur(pixelradius=5)"; var filterVal2 = "progid:DXImageTransform.Microsoft.alpha(opacity=100) progid:DXImageTransform.Microsoft.Blur(pixelradius=5)";
var filterVal3 = "progid:DXImageTransform.Microsoft.Blur(pixelradius=5)"; var filterVal3 = "progid:DXImageTransform.Microsoft.Blur(pixelradius=5)";
jQuery('#foo').css("filter", filterVal); jQuery("#foo").css("filter", filterVal);
equals( jQuery('#foo').css("filter"), filterVal, "css('filter', val) works" ); equals( jQuery("#foo").css("filter"), filterVal, "css('filter', val) works" );
jQuery('#foo').css("opacity", 1); jQuery("#foo").css("opacity", 1);
equals( jQuery('#foo').css("filter"), filterVal2, "Setting opacity in IE doesn't duplicate opacity filter" ); equals( jQuery("#foo").css("filter"), filterVal2, "Setting opacity in IE doesn't duplicate opacity filter" );
equals( jQuery('#foo').css("opacity"), 1, "Setting opacity in IE with other filters works" ); equals( jQuery("#foo").css("opacity"), 1, "Setting opacity in IE with other filters works" );
jQuery('#foo').css("filter", filterVal3).css("opacity", 1); jQuery("#foo").css("filter", filterVal3).css("opacity", 1);
ok( jQuery('#foo').css("filter").indexOf(filterVal3) !== -1, "Setting opacity in IE doesn't clobber other filters" ); ok( jQuery("#foo").css("filter").indexOf(filterVal3) !== -1, "Setting opacity in IE doesn't clobber other filters" );
}); });
} }
@ -343,14 +346,14 @@ test("jQuery.css(elem, 'height') doesn't clear radio buttons (bug #1095)", funct
test(":visible selector works properly on table elements (bug #4512)", function () { test(":visible selector works properly on table elements (bug #4512)", function () {
expect(1); expect(1);
jQuery('#table').html('<tr><td style="display:none">cell</td><td>cell</td></tr>'); jQuery("#table").html("<tr><td style='display:none'>cell</td><td>cell</td></tr>");
equals(jQuery('#table td:visible').length, 1, "hidden cell is not perceived as visible"); equals(jQuery("#table td:visible").length, 1, "hidden cell is not perceived as visible");
}); });
test(":visible selector works properly on children with a hidden parent (bug #4512)", function () { test(":visible selector works properly on children with a hidden parent (bug #4512)", function () {
expect(1); expect(1);
jQuery('#table').css('display', 'none').html('<tr><td>cell</td><td>cell</td></tr>'); jQuery("#table").css("display", "none").html("<tr><td>cell</td><td>cell</td></tr>");
equals(jQuery('#table td:visible').length, 0, "hidden cell children not perceived as visible"); equals(jQuery("#table td:visible").length, 0, "hidden cell children not perceived as visible");
}); });
test("internal ref to elem.runtimeStyle (bug #7608)", function () { test("internal ref to elem.runtimeStyle (bug #7608)", function () {
@ -375,5 +378,19 @@ test("marginRight computed style (bug #3333)", function() {
marginRight: 0 marginRight: 0
}); });
equals($div.css("marginRight"), "0px"); equals($div.css("marginRight"), "0px", "marginRight correctly calculated with a width and display block");
});
test("jQuery.cssProps behavior, (bug #8402)", function() {
var div = jQuery( "<div>" ).appendTo(document.body).css({
position: "absolute",
top: 0,
left: 10
});
jQuery.cssProps.top = "left";
equal( div.css("top"), "10px", "the fixed property is used when accessing the computed style");
div.css("top", "100px");
equal( div[0].style.left, "100px", "the fixed property is used when setting the style");
// cleanup jQuery.cssProps
jQuery.cssProps.top = undefined;
}); });

View file

@ -283,11 +283,11 @@ test(".data(String) and .data(String, Object)", function() {
// #3748 // #3748
var $elem = jQuery({exists:true}); var $elem = jQuery({exists:true});
equals( $elem.data('nothing'), undefined, "Non-existent data returns undefined"); equals( $elem.data("nothing"), undefined, "Non-existent data returns undefined");
equals( $elem.data('null',null).data('null'), null, "null's are preserved"); equals( $elem.data("null", null).data("null"), null, "null's are preserved");
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'), undefined, "Existing data is not returned" ); equals( $elem.data("exists"), undefined, "Existing data is not returned" );
// Clean up // Clean up
$elem.removeData(); $elem.removeData();
@ -316,7 +316,7 @@ test("data-* attributes", function() {
div.remove(); div.remove();
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");
child.data("myobj", "replaced"); child.data("myobj", "replaced");
@ -365,19 +365,19 @@ test("data-* attributes", function() {
.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");
strictEqual( child.data('point'), 5.5, "Primitive number read from attribute"); strictEqual( child.data("point"), 5.5, "Primitive number read from attribute");
strictEqual( child.data('pointe'), 5500, "Primitive number read from attribute"); strictEqual( child.data("pointe"), 5500, "Primitive number read from attribute");
strictEqual( child.data('pointbad'), "5..5", "Bad number read from attribute"); strictEqual( child.data("pointbad"), "5..5", "Bad number read from attribute");
strictEqual( child.data('pointbad2'), "-.", "Bad number read from attribute"); strictEqual( child.data("pointbad2"), "-.", "Bad number read from attribute");
strictEqual( child.data('badjson'), "{123}", "Bad number read from attribute"); strictEqual( child.data("badjson"), "{123}", "Bad number read from attribute");
strictEqual( child.data('badjson2'), "[abc]", "Bad number read from attribute"); strictEqual( child.data("badjson2"), "[abc]", "Bad number read from attribute");
strictEqual( child.data('empty'), "", "Empty string read from attribute"); strictEqual( child.data("empty"), "", "Empty string read from attribute");
strictEqual( child.data('space'), " ", "Empty string read from attribute"); strictEqual( child.data("space"), " ", "Empty string read from attribute");
strictEqual( child.data('null'), null, "Primitive null read from attribute"); strictEqual( child.data("null"), null, "Primitive null read from attribute");
strictEqual( child.data('string'), "test", "Typical string read from attribute"); strictEqual( child.data("string"), "test", "Typical string read from attribute");
child.remove(); child.remove();
@ -401,12 +401,12 @@ test("data-* attributes", function() {
same(jQuery(elem).data("stuff"), [2,8], "Check stuff property"); same(jQuery(elem).data("stuff"), [2,8], "Check stuff property");
break; break;
default: default:
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();
@ -483,7 +483,7 @@ if (window.JSON && window.JSON.stringify) {
var obj = { foo: "bar" }; var obj = { foo: "bar" };
jQuery.data(obj, "hidden", true); jQuery.data(obj, "hidden", true);
equals( JSON.stringify(obj), '{"foo":"bar"}', "Expando is hidden from JSON.stringify" ); equals( JSON.stringify(obj), "{\"foo\":\"bar\"}", "Expando is hidden from JSON.stringify" );
}); });
} }

View file

@ -34,7 +34,7 @@ function testWidth( val ) {
equals( blah.width( val(10) ), blah, "Make sure that setting a width on an empty set returns the set." ); equals( blah.width( val(10) ), blah, "Make sure that setting a width on an empty set returns the set." );
equals( blah.width(), null, "Make sure 'null' is returned on an empty set"); equals( blah.width(), null, "Make sure 'null' is returned on an empty set");
jQuery.removeData($div[0], 'olddisplay', true); jQuery.removeData($div[0], "olddisplay", true);
} }
test("width()", function() { test("width()", function() {
@ -83,7 +83,7 @@ function testHeight( val ) {
equals( blah.height( val(10) ), blah, "Make sure that setting a height on an empty set returns the set." ); equals( blah.height( val(10) ), blah, "Make sure that setting a height on an empty set returns the set." );
equals( blah.height(), null, "Make sure 'null' is returned on an empty set"); equals( blah.height(), null, "Make sure 'null' is returned on an empty set");
jQuery.removeData($div[0], 'olddisplay', true); jQuery.removeData($div[0], "olddisplay", true);
} }
test("height()", function() { test("height()", function() {
@ -132,7 +132,7 @@ test("innerWidth()", function() {
equals( div.innerWidth(), 0, "Make sure that disconnected nodes are handled." ); equals( div.innerWidth(), 0, "Make sure that disconnected nodes are handled." );
div.remove(); div.remove();
jQuery.removeData($div[0], 'olddisplay', true); jQuery.removeData($div[0], "olddisplay", true);
}); });
test("innerHeight()", function() { test("innerHeight()", function() {
@ -161,7 +161,7 @@ test("innerHeight()", function() {
equals( div.innerHeight(), 0, "Make sure that disconnected nodes are handled." ); equals( div.innerHeight(), 0, "Make sure that disconnected nodes are handled." );
div.remove(); div.remove();
jQuery.removeData($div[0], 'olddisplay', true); jQuery.removeData($div[0], "olddisplay", true);
}); });
test("outerWidth()", function() { test("outerWidth()", function() {
@ -191,7 +191,7 @@ test("outerWidth()", function() {
equals( div.outerWidth(), 0, "Make sure that disconnected nodes are handled." ); equals( div.outerWidth(), 0, "Make sure that disconnected nodes are handled." );
div.remove(); div.remove();
jQuery.removeData($div[0], 'olddisplay', true); jQuery.removeData($div[0], "olddisplay", true);
}); });
test("outerHeight()", function() { test("outerHeight()", function() {
@ -220,5 +220,5 @@ test("outerHeight()", function() {
equals( div.outerHeight(), 0, "Make sure that disconnected nodes are handled." ); equals( div.outerHeight(), 0, "Make sure that disconnected nodes are handled." );
div.remove(); div.remove();
jQuery.removeData($div[0], 'olddisplay', true); jQuery.removeData($div[0], "olddisplay", true);
}); });

98
test/unit/effects.js vendored
View file

@ -62,7 +62,7 @@ test("show()", function() {
}); });
// #show-tests * is set display: none in CSS // #show-tests * is set display: none in CSS
jQuery("#main").append('<div id="show-tests"><div><p><a href="#"></a></p><code></code><pre></pre><span></span></div><table><thead><tr><th></th></tr></thead><tbody><tr><td></td></tr></tbody></table><ul><li></li></ul></div><table id="test-table"></table>'); jQuery("#main").append("<div id='show-tests'><div><p><a href='#'></a></p><code></code><pre></pre><span></span></div><table><thead><tr><th></th></tr></thead><tbody><tr><td></td></tr></tbody></table><ul><li></li></ul></div><table id='test-table'></table>");
var old = jQuery("#test-table").show().css("display") !== "table"; var old = jQuery("#test-table").show().css("display") !== "table";
jQuery("#test-table").remove(); jQuery("#test-table").remove();
@ -96,7 +96,7 @@ test("show(Number) - other displays", function() {
stop(); stop();
// #show-tests * is set display: none in CSS // #show-tests * is set display: none in CSS
jQuery("#main").append('<div id="show-tests"><div><p><a href="#"></a></p><code></code><pre></pre><span></span></div><table><thead><tr><th></th></tr></thead><tbody><tr><td></td></tr></tbody></table><ul><li></li></ul></div><table id="test-table"></table>'); jQuery("#main").append("<div id='show-tests'><div><p><a href='#'></a></p><code></code><pre></pre><span></span></div><table><thead><tr><th></th></tr></thead><tbody><tr><td></td></tr></tbody></table><ul><li></li></ul></div><table id='test-table'></table>");
var old = jQuery("#test-table").show().css("display") !== "table", var old = jQuery("#test-table").show().css("display") !== "table",
num = 0; num = 0;
@ -138,11 +138,11 @@ test("Persist correct display value", function() {
stop(); stop();
// #show-tests * is set display: none in CSS // #show-tests * is set display: none in CSS
jQuery("#main").append('<div id="show-tests"><span style="position:absolute;">foo</span></div>'); jQuery("#main").append("<div id='show-tests'><span style='position:absolute;'>foo</span></div>");
var $span = jQuery("#show-tests span"), var $span = jQuery("#show-tests span"),
displayNone = $span.css("display"), displayNone = $span.css("display"),
display = '', num = 0; display = "", num = 0;
$span.show(); $span.show();
@ -165,10 +165,10 @@ test("Persist correct display value", function() {
test("animate(Hash, Object, Function)", function() { test("animate(Hash, Object, Function)", function() {
expect(1); expect(1);
stop(); stop();
var hash = {opacity: 'show'}; var hash = {opacity: "show"};
var hashCopy = jQuery.extend({}, hash); var hashCopy = jQuery.extend({}, hash);
jQuery('#foo').animate(hash, 0, function() { jQuery("#foo").animate(hash, 0, function() {
equals( hash.opacity, hashCopy.opacity, 'Check if animate changed the hash parameter' ); equals( hash.opacity, hashCopy.opacity, "Check if animate changed the hash parameter" );
start(); start();
}); });
}); });
@ -193,7 +193,7 @@ test("animate block as inline width/height", function() {
if ( jQuery.support.inlineBlockNeedsLayout || expected === "inline-block" ) { if ( jQuery.support.inlineBlockNeedsLayout || expected === "inline-block" ) {
stop(); stop();
jQuery("#foo").css({ display: "inline", width: '', height: '' }).animate({ width: 42, height: 42 }, 100, function() { jQuery("#foo").css({ display: "inline", width: "", height: "" }).animate({ width: 42, height: 42 }, 100, function() {
equals( jQuery(this).css("display"), jQuery.support.inlineBlockNeedsLayout ? "inline" : "inline-block", "inline-block was set on non-floated inline element when animating width/height" ); equals( jQuery(this).css("display"), jQuery.support.inlineBlockNeedsLayout ? "inline" : "inline-block", "inline-block was set on non-floated inline element when animating width/height" );
equals( this.offsetWidth, 42, "width was animated" ); equals( this.offsetWidth, 42, "width was animated" );
equals( this.offsetHeight, 42, "height was animated" ); equals( this.offsetHeight, 42, "height was animated" );
@ -218,9 +218,9 @@ test("animate native inline width/height", function() {
if ( jQuery.support.inlineBlockNeedsLayout || expected === "inline-block" ) { if ( jQuery.support.inlineBlockNeedsLayout || expected === "inline-block" ) {
stop(); stop();
jQuery("#foo").css({ display: "", width: '', height: '' }) jQuery("#foo").css({ display: "", width: "", height: "" })
.append('<span>text</span>') .append("<span>text</span>")
.children('span') .children("span")
.animate({ width: 42, height: 42 }, 100, function() { .animate({ width: 42, height: 42 }, 100, function() {
equals( jQuery(this).css("display"), "inline-block", "inline-block was set on non-floated inline element when animating width/height" ); equals( jQuery(this).css("display"), "inline-block", "inline-block was set on non-floated inline element when animating width/height" );
equals( this.offsetWidth, 42, "width was animated" ); equals( this.offsetWidth, 42, "width was animated" );
@ -317,13 +317,13 @@ test("animate option (queue === false)", function () {
var order = []; var order = [];
var $foo = jQuery("#foo"); var $foo = jQuery("#foo");
$foo.animate({width:'100px'}, 3000, function () { $foo.animate({width:"100px"}, 3000, function () {
// should finish after unqueued animation so second // should finish after unqueued animation so second
order.push(2); order.push(2);
same( order, [ 1, 2 ], "Animations finished in the correct order" ); same( order, [ 1, 2 ], "Animations finished in the correct order" );
start(); start();
}); });
$foo.animate({fontSize:'2em'}, {queue:false, duration:10, complete:function () { $foo.animate({fontSize:"2em"}, {queue:false, duration:10, complete:function () {
// short duration and out of queue so should finish first // short duration and out of queue so should finish first
order.push(1); order.push(1);
}}); }});
@ -433,7 +433,7 @@ test("stop()", function() {
var w = 0; var w = 0;
$foo.hide().width(200).width(); $foo.hide().width(200).width();
$foo.animate({ width:'show' }, 1000); $foo.animate({ width: "show" }, 1000);
setTimeout(function(){ setTimeout(function(){
var nw = $foo.width(); var nw = $foo.width();
notEqual( nw, w, "An animation occurred " + nw + "px " + w + "px"); notEqual( nw, w, "An animation occurred " + nw + "px " + w + "px");
@ -458,9 +458,9 @@ test("stop() - several in queue", function() {
var w = 0; var w = 0;
$foo.hide().width(200).width(); $foo.hide().width(200).width();
$foo.animate({ width:'show' }, 1000); $foo.animate({ width: "show" }, 1000);
$foo.animate({ width:'hide' }, 1000); $foo.animate({ width: "hide" }, 1000);
$foo.animate({ width:'show' }, 1000); $foo.animate({ width: "show" }, 1000);
setTimeout(function(){ setTimeout(function(){
equals( $foo.queue().length, 3, "All 3 still in the queue" ); equals( $foo.queue().length, 3, "All 3 still in the queue" );
var nw = $foo.width(); var nw = $foo.width();
@ -483,9 +483,9 @@ test("stop(clearQueue)", function() {
var w = 0; var w = 0;
$foo.hide().width(200).width(); $foo.hide().width(200).width();
$foo.animate({ width:'show' }, 1000); $foo.animate({ width: "show" }, 1000);
$foo.animate({ width:'hide' }, 1000); $foo.animate({ width: "hide" }, 1000);
$foo.animate({ width:'show' }, 1000); $foo.animate({ width: "show" }, 1000);
setTimeout(function(){ setTimeout(function(){
var nw = $foo.width(); var nw = $foo.width();
ok( nw != w, "An animation occurred " + nw + "px " + w + "px"); ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
@ -510,10 +510,10 @@ test("stop(clearQueue, gotoEnd)", function() {
var w = 0; var w = 0;
$foo.hide().width(200).width(); $foo.hide().width(200).width();
$foo.animate({ width:'show' }, 1000); $foo.animate({ width: "show" }, 1000);
$foo.animate({ width:'hide' }, 1000); $foo.animate({ width: "hide" }, 1000);
$foo.animate({ width:'show' }, 1000); $foo.animate({ width: "show" }, 1000);
$foo.animate({ width:'hide' }, 1000); $foo.animate({ width: "hide" }, 1000);
setTimeout(function(){ setTimeout(function(){
var nw = $foo.width(); var nw = $foo.width();
ok( nw != w, "An animation occurred " + nw + "px " + w + "px"); ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
@ -783,7 +783,7 @@ jQuery.each( {
}); });
jQuery.fn.saveState = function(hiddenOverflow){ jQuery.fn.saveState = function(hiddenOverflow){
var check = ['opacity','height','width','display','overflow']; var check = ["opacity", "height", "width", "display", "overflow"];
expect(check.length); expect(check.length);
stop(); stop();
@ -804,64 +804,64 @@ jQuery.checkState = function(){
}); });
// manually clean data on modified element // manually clean data on modified element
jQuery.removeData(this, 'olddisplay', true); jQuery.removeData(this, "olddisplay", true);
start(); start();
} };
// Chaining Tests // Chaining Tests
test("Chain fadeOut fadeIn", function() { test("Chain fadeOut fadeIn", function() {
jQuery('#fadein div').saveState().fadeOut('fast').fadeIn('fast',jQuery.checkState); jQuery("#fadein div").saveState().fadeOut("fast").fadeIn("fast",jQuery.checkState);
}); });
test("Chain fadeIn fadeOut", function() { test("Chain fadeIn fadeOut", function() {
jQuery('#fadeout div').saveState().fadeIn('fast').fadeOut('fast',jQuery.checkState); jQuery("#fadeout div").saveState().fadeIn("fast").fadeOut("fast",jQuery.checkState);
}); });
test("Chain hide show", function() { test("Chain hide show", function() {
jQuery('#show div').saveState(jQuery.support.shrinkWrapBlocks).hide('fast').show('fast',jQuery.checkState); jQuery("#show div").saveState(jQuery.support.shrinkWrapBlocks).hide("fast").show("fast",jQuery.checkState);
}); });
test("Chain show hide", function() { test("Chain show hide", function() {
jQuery('#hide div').saveState(jQuery.support.shrinkWrapBlocks).show('fast').hide('fast',jQuery.checkState); jQuery("#hide div").saveState(jQuery.support.shrinkWrapBlocks).show("fast").hide("fast",jQuery.checkState);
}); });
test("Chain show hide with easing and callback", function() { test("Chain show hide with easing and callback", function() {
jQuery('#hide div').saveState().show('fast').hide('fast','linear',jQuery.checkState); jQuery("#hide div").saveState().show("fast").hide("fast","linear",jQuery.checkState);
}); });
test("Chain toggle in", function() { test("Chain toggle in", function() {
jQuery('#togglein div').saveState(jQuery.support.shrinkWrapBlocks).toggle('fast').toggle('fast',jQuery.checkState); jQuery("#togglein div").saveState(jQuery.support.shrinkWrapBlocks).toggle("fast").toggle("fast",jQuery.checkState);
}); });
test("Chain toggle out", function() { test("Chain toggle out", function() {
jQuery('#toggleout div').saveState(jQuery.support.shrinkWrapBlocks).toggle('fast').toggle('fast',jQuery.checkState); jQuery("#toggleout div").saveState(jQuery.support.shrinkWrapBlocks).toggle("fast").toggle("fast",jQuery.checkState);
}); });
test("Chain toggle out with easing and callback", function() { test("Chain toggle out with easing and callback", function() {
jQuery('#toggleout div').saveState(jQuery.support.shrinkWrapBlocks).toggle('fast').toggle('fast','linear',jQuery.checkState); jQuery("#toggleout div").saveState(jQuery.support.shrinkWrapBlocks).toggle("fast").toggle("fast","linear",jQuery.checkState);
}); });
test("Chain slideDown slideUp", function() { test("Chain slideDown slideUp", function() {
jQuery('#slidedown div').saveState(jQuery.support.shrinkWrapBlocks).slideDown('fast').slideUp('fast',jQuery.checkState); jQuery("#slidedown div").saveState(jQuery.support.shrinkWrapBlocks).slideDown("fast").slideUp("fast",jQuery.checkState);
}); });
test("Chain slideUp slideDown", function() { test("Chain slideUp slideDown", function() {
jQuery('#slideup div').saveState(jQuery.support.shrinkWrapBlocks).slideUp('fast').slideDown('fast',jQuery.checkState); jQuery("#slideup div").saveState(jQuery.support.shrinkWrapBlocks).slideUp("fast").slideDown("fast",jQuery.checkState);
}); });
test("Chain slideUp slideDown with easing and callback", function() { test("Chain slideUp slideDown with easing and callback", function() {
jQuery('#slideup div').saveState(jQuery.support.shrinkWrapBlocks).slideUp('fast').slideDown('fast','linear',jQuery.checkState); jQuery("#slideup div").saveState(jQuery.support.shrinkWrapBlocks).slideUp("fast").slideDown("fast","linear",jQuery.checkState);
}); });
test("Chain slideToggle in", function() { test("Chain slideToggle in", function() {
jQuery('#slidetogglein div').saveState(jQuery.support.shrinkWrapBlocks).slideToggle('fast').slideToggle('fast',jQuery.checkState); jQuery("#slidetogglein div").saveState(jQuery.support.shrinkWrapBlocks).slideToggle("fast").slideToggle("fast",jQuery.checkState);
}); });
test("Chain slideToggle out", function() { test("Chain slideToggle out", function() {
jQuery('#slidetoggleout div').saveState(jQuery.support.shrinkWrapBlocks).slideToggle('fast').slideToggle('fast',jQuery.checkState); jQuery("#slidetoggleout div").saveState(jQuery.support.shrinkWrapBlocks).slideToggle("fast").slideToggle("fast",jQuery.checkState);
}); });
test("Chain fadeToggle in", function() { test("Chain fadeToggle in", function() {
jQuery('#fadetogglein div').saveState().fadeToggle('fast').fadeToggle('fast',jQuery.checkState); jQuery("#fadetogglein div").saveState().fadeToggle("fast").fadeToggle("fast",jQuery.checkState);
}); });
test("Chain fadeToggle out", function() { test("Chain fadeToggle out", function() {
jQuery('#fadetoggleout div').saveState().fadeToggle('fast').fadeToggle('fast',jQuery.checkState); jQuery("#fadetoggleout div").saveState().fadeToggle("fast").fadeToggle("fast",jQuery.checkState);
}); });
test("Chain fadeTo 0.5 1.0 with easing and callback)", function() { test("Chain fadeTo 0.5 1.0 with easing and callback)", function() {
jQuery('#fadeto div').saveState().fadeTo('fast',0.5).fadeTo('fast',1.0,'linear',jQuery.checkState); jQuery("#fadeto div").saveState().fadeTo("fast",0.5).fadeTo("fast",1.0,"linear",jQuery.checkState);
}); });
jQuery.makeTest = function( text ){ jQuery.makeTest = function( text ){
@ -903,23 +903,23 @@ test("animate with per-property easing", function(){
var _test2_called = false; var _test2_called = false;
var _default_test_called = false; var _default_test_called = false;
jQuery.easing['_test1'] = function() { jQuery.easing["_test1"] = function() {
_test1_called = true; _test1_called = true;
}; };
jQuery.easing['_test2'] = function() { jQuery.easing["_test2"] = function() {
_test2_called = true; _test2_called = true;
}; };
jQuery.easing['_default_test'] = function() { jQuery.easing["_default_test"] = function() {
_default_test_called = true; _default_test_called = true;
}; };
jQuery({a:0,b:0,c:0}).animate({ jQuery({a:0,b:0,c:0}).animate({
a: [100, '_test1'], a: [100, "_test1"],
b: [100, '_test2'], b: [100, "_test2"],
c: 100 c: 100
}, 400, '_default_test', function(){ }, 400, "_default_test", function(){
start(); start();
ok(_test1_called, "Easing function (1) called"); ok(_test1_called, "Easing function (1) called");
ok(_test2_called, "Easing function (2) called"); ok(_test2_called, "Easing function (2) called");

View file

@ -305,7 +305,7 @@ test("bind/delegate bubbling, isDefaultPrevented", function() {
fakeClick = function($jq) { fakeClick = function($jq) {
// Use a native click so we don't get jQuery simulated bubbling // Use a native click so we don't get jQuery simulated bubbling
if ( document.createEvent ) { if ( document.createEvent ) {
var e = document.createEvent( 'MouseEvents' ); var e = document.createEvent( "MouseEvents" );
e.initEvent( "click", true, true ); e.initEvent( "click", true, true );
$jq[0].dispatchEvent(e); $jq[0].dispatchEvent(e);
} }
@ -347,7 +347,7 @@ test("bind(), iframes", function() {
jQuery("div", doc).bind("click", function() { jQuery("div", doc).bind("click", function() {
ok( true, "Binding to element inside iframe" ); ok( true, "Binding to element inside iframe" );
}).click().unbind('click'); }).click().unbind("click");
}); });
test("bind(), trigger change on select", function() { test("bind(), trigger change on select", function() {
@ -357,8 +357,8 @@ test("bind(), trigger change on select", function() {
equals( event.data, counter++, "Event.data is not a global event object" ); equals( event.data, counter++, "Event.data is not a global event object" );
}; };
jQuery("#form select").each(function(i){ jQuery("#form select").each(function(i){
jQuery(this).bind('change', i, selectOnChange); jQuery(this).bind("change", i, selectOnChange);
}).trigger('change'); }).trigger("change");
}); });
test("bind(), namespaced events, cloned events", 18, function() { test("bind(), namespaced events, cloned events", 18, function() {
@ -646,23 +646,23 @@ test("unbind(type)", function() {
} }
message = "unbind passing function"; message = "unbind passing function";
$elem.bind('error1', error).unbind('error1',error).triggerHandler('error1'); $elem.bind("error1", error).unbind("error1", error).triggerHandler("error1");
message = "unbind all from event"; message = "unbind all from event";
$elem.bind('error1', error).unbind('error1').triggerHandler('error1'); $elem.bind("error1", error).unbind("error1").triggerHandler("error1");
message = "unbind all"; message = "unbind all";
$elem.bind('error1', error).unbind().triggerHandler('error1'); $elem.bind("error1", error).unbind().triggerHandler("error1");
message = "unbind many with function"; message = "unbind many with function";
$elem.bind('error1 error2',error) $elem.bind("error1 error2",error)
.unbind('error1 error2', error ) .unbind("error1 error2", error )
.trigger('error1').triggerHandler('error2'); .trigger("error1").triggerHandler("error2");
message = "unbind many"; // #3538 message = "unbind many"; // #3538
$elem.bind('error1 error2',error) $elem.bind("error1 error2", error)
.unbind('error1 error2') .unbind("error1 error2")
.trigger('error1').triggerHandler('error2'); .trigger("error1").triggerHandler("error2");
message = "unbind without a type or handler"; message = "unbind without a type or handler";
$elem.bind("error1 error2.test",error) $elem.bind("error1 error2.test",error)
@ -678,28 +678,28 @@ test("unbind(eventObject)", function() {
function assert( expected ){ function assert( expected ){
num = 0; num = 0;
$elem.trigger('foo').triggerHandler('bar'); $elem.trigger("foo").triggerHandler("bar");
equals( num, expected, "Check the right handlers are triggered" ); equals( num, expected, "Check the right handlers are triggered" );
} }
$elem $elem
// This handler shouldn't be unbound // This handler shouldn't be unbound
.bind('foo', function(){ .bind("foo", function(){
num += 1; num += 1;
}) })
.bind('foo', function(e){ .bind("foo", function(e){
$elem.unbind( e ) $elem.unbind( e )
num += 2; num += 2;
}) })
// Neither this one // Neither this one
.bind('bar', function(){ .bind("bar", function(){
num += 4; num += 4;
}); });
assert( 7 ); assert( 7 );
assert( 5 ); assert( 5 );
$elem.unbind('bar'); $elem.unbind("bar");
assert( 1 ); assert( 1 );
$elem.unbind(); $elem.unbind();
@ -732,7 +732,7 @@ test("mouseover triggers mouseenter", function() {
elem.mouseenter(function () { elem.mouseenter(function () {
count++; count++;
}); });
elem.trigger('mouseover'); elem.trigger("mouseover");
equals(count, 1, "make sure mouseover triggers a mouseenter" ); equals(count, 1, "make sure mouseover triggers a mouseenter" );
elem.remove(); elem.remove();
@ -741,9 +741,9 @@ test("mouseover triggers mouseenter", function() {
test("trigger() shortcuts", function() { test("trigger() shortcuts", function() {
expect(6); expect(6);
var elem = jQuery('<li><a href="#">Change location</a></li>').prependTo('#firstUL'); var elem = jQuery("<li><a href='#'>Change location</a></li>").prependTo("#firstUL");
elem.find('a').bind('click', function() { elem.find("a").bind("click", function() {
var close = jQuery('spanx', this); // same with jQuery(this).find('span'); var close = jQuery("spanx", this); // same with jQuery(this).find("span");
equals( close.length, 0, "Context element does not exist, length must be zero" ); equals( close.length, 0, "Context element does not exist, length must be zero" );
ok( !close[0], "Context element does not exist, direct access to element must return undefined" ); ok( !close[0], "Context element does not exist, direct access to element must return undefined" );
return false; return false;
@ -757,25 +757,30 @@ test("trigger() shortcuts", function() {
}).click(); }).click();
var counter = 0; var counter = 0;
jQuery('#firstp')[0].onclick = function(event) { jQuery("#firstp")[0].onclick = function(event) {
counter++; counter++;
}; };
jQuery('#firstp').click(); jQuery("#firstp").click();
equals( counter, 1, "Check that click, triggers onclick event handler also" ); equals( counter, 1, "Check that click, triggers onclick event handler also" );
var clickCounter = 0; var clickCounter = 0;
jQuery('#simon1')[0].onclick = function(event) { jQuery("#simon1")[0].onclick = function(event) {
clickCounter++; clickCounter++;
}; };
jQuery('#simon1').click(); jQuery("#simon1").click();
equals( clickCounter, 1, "Check that click, triggers onclick event handler on an a tag also" ); equals( clickCounter, 1, "Check that click, triggers onclick event handler on an a tag also" );
elem = jQuery('<img />').load(function(){ elem = jQuery("<img />").load(function(){
ok( true, "Trigger the load event, using the shortcut .load() (#2819)"); ok( true, "Trigger the load event, using the shortcut .load() (#2819)");
}).load(); }).load();
// manually clean up detached elements // manually clean up detached elements
elem.remove(); elem.remove();
// test that special handlers do not blow up with VML elements (#7071)
jQuery('<xml:namespace ns="urn:schemas-microsoft-com:vml" prefix="v" />').appendTo('head');
jQuery('<v:oval id="oval" style="width:100pt;height:75pt;" fillcolor="red"> </v:oval>').appendTo('#form');
jQuery("#oval").click().keydown();
}); });
test("trigger() bubbling", function() { test("trigger() bubbling", function() {
@ -853,7 +858,7 @@ test("trigger(type, [data], [fn])", function() {
var pass = true; var pass = true;
try { try {
jQuery('#form input:first').hide().trigger('focus'); jQuery("#form input:first").hide().trigger("focus");
} catch(e) { } catch(e) {
pass = false; pass = false;
} }
@ -861,7 +866,7 @@ test("trigger(type, [data], [fn])", function() {
pass = true; pass = true;
try { try {
jQuery('#main table:first').bind('test:test', function(){}).trigger('test:test'); jQuery("#main table:first").bind("test:test", function(){}).trigger("test:test");
} catch (e) { } catch (e) {
pass = false; pass = false;
} }
@ -899,8 +904,8 @@ test("jQuery.Event.currentTarget", function(){
test("trigger(eventObject, [data], [fn])", function() { test("trigger(eventObject, [data], [fn])", function() {
expect(25); expect(25);
var $parent = jQuery('<div id="par" />').hide().appendTo('body'), var $parent = jQuery("<div id='par' />").hide().appendTo("body"),
$child = jQuery('<p id="child">foo</p>').appendTo( $parent ); $child = jQuery("<p id='child'>foo</p>").appendTo( $parent );
var event = jQuery.Event("noNew"); var event = jQuery.Event("noNew");
ok( event != window, "Instantiate jQuery.Event without the 'new' keyword" ); ok( event != window, "Instantiate jQuery.Event without the 'new' keyword" );
@ -920,21 +925,21 @@ test("trigger(eventObject, [data], [fn])", function() {
equals( event.isPropagationStopped(), true, "Verify isPropagationStopped" ); equals( event.isPropagationStopped(), true, "Verify isPropagationStopped" );
equals( event.isImmediatePropagationStopped(), true, "Verify isPropagationStopped" ); equals( event.isImmediatePropagationStopped(), true, "Verify isPropagationStopped" );
$parent.bind('foo',function(e){ $parent.bind("foo",function(e){
// Tries bubbling // Tries bubbling
equals( e.type, 'foo', 'Verify event type when passed passing an event object' ); equals( e.type, "foo", "Verify event type when passed passing an event object" );
equals( e.target.id, 'child', 'Verify event.target when passed passing an event object' ); equals( e.target.id, "child", "Verify event.target when passed passing an event object" );
equals( e.currentTarget.id, 'par', 'Verify event.target when passed passing an event object' ); equals( e.currentTarget.id, "par", "Verify event.target when passed passing an event object" );
equals( e.secret, 'boo!', 'Verify event object\'s custom attribute when passed passing an event object' ); equals( e.secret, "boo!", "Verify event object's custom attribute when passed passing an event object" );
}); });
// test with an event object // test with an event object
event = new jQuery.Event("foo"); event = new jQuery.Event("foo");
event.secret = 'boo!'; event.secret = "boo!";
$child.trigger(event); $child.trigger(event);
// test with a literal object // test with a literal object
$child.trigger({type:'foo', secret:'boo!'}); $child.trigger({type: "foo", secret: "boo!"});
$parent.unbind(); $parent.unbind();
@ -942,9 +947,9 @@ test("trigger(eventObject, [data], [fn])", function() {
ok( false, "This assertion shouldn't be reached"); ok( false, "This assertion shouldn't be reached");
} }
$parent.bind('foo', error ); $parent.bind("foo", error );
$child.bind('foo',function(e, a, b, c ){ $child.bind("foo",function(e, a, b, c ){
equals( arguments.length, 4, "Check arguments length"); equals( arguments.length, 4, "Check arguments length");
equals( a, 1, "Check first custom argument"); equals( a, 1, "Check first custom argument");
equals( b, 2, "Check second custom argument"); equals( b, 2, "Check second custom argument");
@ -962,24 +967,24 @@ test("trigger(eventObject, [data], [fn])", function() {
// We should add this back in when we want to test the order // We should add this back in when we want to test the order
// in which event handlers are iterated. // in which event handlers are iterated.
//$child.bind('foo', error ); //$child.bind("foo", error );
event = new jQuery.Event("foo"); event = new jQuery.Event("foo");
$child.trigger( event, [1,2,3] ).unbind(); $child.trigger( event, [1,2,3] ).unbind();
equals( event.result, "result", "Check event.result attribute"); equals( event.result, "result", "Check event.result attribute");
// Will error if it bubbles // Will error if it bubbles
$child.triggerHandler('foo'); $child.triggerHandler("foo");
$child.unbind(); $child.unbind();
$parent.unbind().remove(); $parent.unbind().remove();
}); });
test("jQuery.Event({ /* props */ })", function() { test("jQuery.Event( type, props )", function() {
expect(4); expect(4);
var event = jQuery.Event({ type: "keydown", keyCode: 64 }), var event = jQuery.Event( "keydown", { keyCode: 64 }),
handler = function( event ) { handler = function( event ) {
ok( "keyCode" in event, "Special property 'keyCode' exists" ); ok( "keyCode" in event, "Special property 'keyCode' exists" );
equal( event.keyCode, 64, "event.keyCode has explicit value '64'" ); equal( event.keyCode, 64, "event.keyCode has explicit value '64'" );
@ -1000,12 +1005,12 @@ test("jQuery.Event.currentTarget", function(){
expect(1); expect(1);
var counter = 0, var counter = 0,
$elem = jQuery('<button>a</button>').click(function(e){ $elem = jQuery("<button>a</button>").click(function(e){
equals( e.currentTarget, this, "Check currentTarget on "+(counter++?"native":"fake") +" event" ); equals( e.currentTarget, this, "Check currentTarget on "+(counter++?"native":"fake") +" event" );
}); });
// Fake event // Fake event
$elem.trigger('click'); $elem.trigger("click");
// Cleanup // Cleanup
$elem.unbind(); $elem.unbind();
@ -1018,7 +1023,7 @@ test("toggle(Function, Function, ...)", function() {
fn1 = function(e) { count++; }, fn1 = function(e) { count++; },
fn2 = function(e) { count--; }, fn2 = function(e) { count--; },
preventDefault = function(e) { e.preventDefault() }, preventDefault = function(e) { e.preventDefault() },
link = jQuery('#mark'); link = jQuery("#mark");
link.click(preventDefault).click().toggle(fn1, fn2).click().click().click().click().click(); link.click(preventDefault).click().toggle(fn1, fn2).click().click().click().click().click();
equals( count, 1, "Check for toggle(fn, fn)" ); equals( count, 1, "Check for toggle(fn, fn)" );
@ -1062,8 +1067,8 @@ test("toggle(Function, Function, ...)", function() {
$div.click(); $div.click();
equals( turn, 2, "Trying toggle with 3 functions, attempt 5 yields 2"); equals( turn, 2, "Trying toggle with 3 functions, attempt 5 yields 2");
$div.unbind('click',fns[0]); $div.unbind("click",fns[0]);
var data = jQuery._data( $div[0], 'events' ); var data = jQuery._data( $div[0], "events" );
ok( !data, "Unbinding one function from toggle unbinds them all"); ok( !data, "Unbinding one function from toggle unbinds them all");
// manually clean up detached elements // manually clean up detached elements
@ -1178,12 +1183,12 @@ test(".live()/.die()", function() {
jQuery("div").die("submit"); jQuery("div").die("submit");
// Test binding with a different context // Test binding with a different context
var clicked = 0, container = jQuery('#main')[0]; var clicked = 0, container = jQuery("#main")[0];
jQuery("#foo", container).live("click", function(e){ clicked++; }); jQuery("#foo", container).live("click", function(e){ clicked++; });
jQuery("div").trigger('click'); jQuery("div").trigger("click");
jQuery("#foo").trigger('click'); jQuery("#foo").trigger("click");
jQuery("#main").trigger('click'); jQuery("#main").trigger("click");
jQuery("body").trigger('click'); jQuery("body").trigger("click");
equals( clicked, 2, "live with a context" ); equals( clicked, 2, "live with a context" );
// Make sure the event is actually stored on the context // Make sure the event is actually stored on the context
@ -1191,7 +1196,7 @@ test(".live()/.die()", function() {
// Test unbinding with a different context // Test unbinding with a different context
jQuery("#foo", container).die("click"); jQuery("#foo", container).die("click");
jQuery("#foo").trigger('click'); jQuery("#foo").trigger("click");
equals( clicked, 2, "die with a context"); equals( clicked, 2, "die with a context");
// Test binding with event data // Test binding with event data
@ -1273,9 +1278,9 @@ test(".live()/.die()", function() {
// Make sure we don't loose the target by DOM modifications // Make sure we don't loose the target by DOM modifications
// after the bubble already reached the liveHandler // after the bubble already reached the liveHandler
var livec = 0, elemDiv = jQuery("#nothiddendivchild").html('<span></span>').get(0); var livec = 0, elemDiv = jQuery("#nothiddendivchild").html("<span></span>").get(0);
jQuery("#nothiddendivchild").live("click", function(e){ jQuery("#nothiddendivchild").html(''); }); jQuery("#nothiddendivchild").live("click", function(e){ jQuery("#nothiddendivchild").html(""); });
jQuery("#nothiddendivchild").live("click", function(e){ if(e.target) {livec++;} }); jQuery("#nothiddendivchild").live("click", function(e){ if(e.target) {livec++;} });
jQuery("#nothiddendiv span").click(); jQuery("#nothiddendiv span").click();
@ -1290,20 +1295,20 @@ test(".live()/.die()", function() {
var lived = 0, livee = 0; var lived = 0, livee = 0;
// bind one pair in one order // bind one pair in one order
jQuery('span#liveSpan1 a').live('click', function(){ lived++; return false; }); jQuery("span#liveSpan1 a").live("click", function(){ lived++; return false; });
jQuery('span#liveSpan1').live('click', function(){ livee++; }); jQuery("span#liveSpan1").live("click", function(){ livee++; });
jQuery('span#liveSpan1 a').click(); jQuery("span#liveSpan1 a").click();
equals( lived, 1, "Verify that only one first handler occurred." ); equals( lived, 1, "Verify that only one first handler occurred." );
equals( livee, 0, "Verify that second handler doesn't." ); equals( livee, 0, "Verify that second handler doesn't." );
// and one pair in inverse // and one pair in inverse
jQuery('span#liveSpan2').live('click', function(){ livee++; }); jQuery("span#liveSpan2").live("click", function(){ livee++; });
jQuery('span#liveSpan2 a').live('click', function(){ lived++; return false; }); jQuery("span#liveSpan2 a").live("click", function(){ lived++; return false; });
lived = 0; lived = 0;
livee = 0; livee = 0;
jQuery('span#liveSpan2 a').click(); jQuery("span#liveSpan2 a").click();
equals( lived, 1, "Verify that only one first handler occurred." ); equals( lived, 1, "Verify that only one first handler occurred." );
equals( livee, 0, "Verify that second handler doesn't." ); equals( livee, 0, "Verify that second handler doesn't." );
@ -1314,15 +1319,15 @@ test(".live()/.die()", function() {
jQuery("span#liveSpan2").die("click"); jQuery("span#liveSpan2").die("click");
// Test this, target and currentTarget are correct // Test this, target and currentTarget are correct
jQuery('span#liveSpan1').live('click', function(e){ jQuery("span#liveSpan1").live("click", function(e){
equals( this.id, 'liveSpan1', 'Check the this within a live handler' ); equals( this.id, "liveSpan1", "Check the this within a live handler" );
equals( e.currentTarget.id, 'liveSpan1', 'Check the event.currentTarget within a live handler' ); equals( e.currentTarget.id, "liveSpan1", "Check the event.currentTarget within a live handler" );
equals( e.target.nodeName.toUpperCase(), 'A', 'Check the event.target within a live handler' ); equals( e.target.nodeName.toUpperCase(), "A", "Check the event.target within a live handler" );
}); });
jQuery('span#liveSpan1 a').click(); jQuery("span#liveSpan1 a").click();
jQuery('span#liveSpan1').die('click'); jQuery("span#liveSpan1").die("click");
// Work with deep selectors // Work with deep selectors
livee = 0; livee = 0;
@ -1705,12 +1710,12 @@ test(".delegate()/.undelegate()", function() {
jQuery("#body").undelegate("div", "submit"); jQuery("#body").undelegate("div", "submit");
// Test binding with a different context // Test binding with a different context
var clicked = 0, container = jQuery('#main')[0]; var clicked = 0, container = jQuery("#main")[0];
jQuery("#main").delegate("#foo", "click", function(e){ clicked++; }); jQuery("#main").delegate("#foo", "click", function(e){ clicked++; });
jQuery("div").trigger('click'); jQuery("div").trigger("click");
jQuery("#foo").trigger('click'); jQuery("#foo").trigger("click");
jQuery("#main").trigger('click'); jQuery("#main").trigger("click");
jQuery("body").trigger('click'); jQuery("body").trigger("click");
equals( clicked, 2, "delegate with a context" ); equals( clicked, 2, "delegate with a context" );
// Make sure the event is actually stored on the context // Make sure the event is actually stored on the context
@ -1718,7 +1723,7 @@ test(".delegate()/.undelegate()", function() {
// Test unbinding with a different context // Test unbinding with a different context
jQuery("#main").undelegate("#foo", "click"); jQuery("#main").undelegate("#foo", "click");
jQuery("#foo").trigger('click'); jQuery("#foo").trigger("click");
equals( clicked, 2, "undelegate with a context"); equals( clicked, 2, "undelegate with a context");
// Test binding with event data // Test binding with event data
@ -1804,9 +1809,9 @@ test(".delegate()/.undelegate()", function() {
// Make sure we don't loose the target by DOM modifications // Make sure we don't loose the target by DOM modifications
// after the bubble already reached the liveHandler // after the bubble already reached the liveHandler
var livec = 0, elemDiv = jQuery("#nothiddendivchild").html('<span></span>').get(0); var livec = 0, elemDiv = jQuery("#nothiddendivchild").html("<span></span>").get(0);
jQuery("#body").delegate("#nothiddendivchild", "click", function(e){ jQuery("#nothiddendivchild").html(''); }); jQuery("#body").delegate("#nothiddendivchild", "click", function(e){ jQuery("#nothiddendivchild").html(""); });
jQuery("#body").delegate("#nothiddendivchild", "click", function(e){ if(e.target) {livec++;} }); jQuery("#body").delegate("#nothiddendivchild", "click", function(e){ if(e.target) {livec++;} });
jQuery("#nothiddendiv span").click(); jQuery("#nothiddendiv span").click();
@ -1821,20 +1826,20 @@ test(".delegate()/.undelegate()", function() {
var lived = 0, livee = 0; var lived = 0, livee = 0;
// bind one pair in one order // bind one pair in one order
jQuery("#body").delegate('span#liveSpan1 a', 'click', function(){ lived++; return false; }); jQuery("#body").delegate("span#liveSpan1 a", "click", function(){ lived++; return false; });
jQuery("#body").delegate('span#liveSpan1', 'click', function(){ livee++; }); jQuery("#body").delegate("span#liveSpan1", "click", function(){ livee++; });
jQuery('span#liveSpan1 a').click(); jQuery("span#liveSpan1 a").click();
equals( lived, 1, "Verify that only one first handler occurred." ); equals( lived, 1, "Verify that only one first handler occurred." );
equals( livee, 0, "Verify that second handler doesn't." ); equals( livee, 0, "Verify that second handler doesn't." );
// and one pair in inverse // and one pair in inverse
jQuery("#body").delegate('span#liveSpan2', 'click', function(){ livee++; }); jQuery("#body").delegate("span#liveSpan2", "click", function(){ livee++; });
jQuery("#body").delegate('span#liveSpan2 a', 'click', function(){ lived++; return false; }); jQuery("#body").delegate("span#liveSpan2 a", "click", function(){ lived++; return false; });
lived = 0; lived = 0;
livee = 0; livee = 0;
jQuery('span#liveSpan2 a').click(); jQuery("span#liveSpan2 a").click();
equals( lived, 1, "Verify that only one first handler occurred." ); equals( lived, 1, "Verify that only one first handler occurred." );
equals( livee, 0, "Verify that second handler doesn't." ); equals( livee, 0, "Verify that second handler doesn't." );
@ -1842,15 +1847,15 @@ test(".delegate()/.undelegate()", function() {
jQuery("#body").undelegate("click"); jQuery("#body").undelegate("click");
// Test this, target and currentTarget are correct // Test this, target and currentTarget are correct
jQuery("#body").delegate('span#liveSpan1', 'click', function(e){ jQuery("#body").delegate("span#liveSpan1", "click", function(e){
equals( this.id, 'liveSpan1', 'Check the this within a delegate handler' ); equals( this.id, "liveSpan1", "Check the this within a delegate handler" );
equals( e.currentTarget.id, 'liveSpan1', 'Check the event.currentTarget within a delegate handler' ); equals( e.currentTarget.id, "liveSpan1", "Check the event.currentTarget within a delegate handler" );
equals( e.target.nodeName.toUpperCase(), 'A', 'Check the event.target within a delegate handler' ); equals( e.target.nodeName.toUpperCase(), "A", "Check the event.target within a delegate handler" );
}); });
jQuery('span#liveSpan1 a').click(); jQuery("span#liveSpan1 a").click();
jQuery("#body").undelegate('span#liveSpan1', 'click'); jQuery("#body").undelegate("span#liveSpan1", "click");
// Work with deep selectors // Work with deep selectors
livee = 0; livee = 0;
@ -2022,16 +2027,37 @@ test("delegate with submit", function() {
jQuery(document).undelegate(); jQuery(document).undelegate();
}); });
test("undelegate() with only namespaces", function() {
expect(2);
var $delegate = jQuery("#liveHandlerOrder"),
count = 0;
$delegate.delegate("a", "click.ns", function(e) {
count++;
});
jQuery("a", $delegate).eq(0).trigger("click.ns");
equals( count, 1, "delegated click.ns");
$delegate.undelegate(".ns");
jQuery("a", $delegate).eq(1).trigger("click.ns");
equals( count, 1, "no more .ns after undelegate");
});
test("Non DOM element events", function() { test("Non DOM element events", function() {
expect(1); expect(1);
var o = {}; var o = {};
jQuery(o).bind('nonelementobj', function(e) { jQuery(o).bind("nonelementobj", function(e) {
ok( true, "Event on non-DOM object triggered" ); ok( true, "Event on non-DOM object triggered" );
}); });
jQuery(o).trigger('nonelementobj'); jQuery(o).trigger("nonelementobj");
}); });
test("window resize", function() { test("window resize", function() {
@ -2049,7 +2075,7 @@ test("window resize", function() {
test("focusin bubbles", function() { test("focusin bubbles", function() {
expect(5); expect(5);
var input = jQuery( '<input type="text" />' ).prependTo( "body" ), var input = jQuery( "<input type='text' />" ).prependTo( "body" ),
order = 0; order = 0;
jQuery( "body" ).bind( "focusin.focusinBubblesTest", function(){ jQuery( "body" ).bind( "focusin.focusinBubblesTest", function(){

View file

@ -9,7 +9,7 @@ var functionReturningObj = function(value) { return (function() { return value;
test("text()", function() { test("text()", function() {
expect(2); expect(2);
var expected = "This link has class=\"blog\": Simon Willison's Weblog"; var expected = "This link has class=\"blog\": Simon Willison's Weblog";
equals( jQuery('#sap').text(), expected, 'Check for merged text of more then one element.' ); equals( jQuery("#sap").text(), expected, "Check for merged text of more then one element." );
// Check serialization of text values // Check serialization of text values
equals( jQuery(document.createTextNode("foo")).text(), "foo", "Text node was retreived from .text()." ); equals( jQuery(document.createTextNode("foo")).text(), "foo", "Text node was retreived from .text()." );
@ -43,34 +43,34 @@ test("text(Function) with incoming value", function() {
var old = "This link has class=\"blog\": Simon Willison's Weblog"; var old = "This link has class=\"blog\": Simon Willison's Weblog";
jQuery('#sap').text(function(i, val) { jQuery("#sap").text(function(i, val) {
equals( val, old, "Make sure the incoming value is correct." ); equals( val, old, "Make sure the incoming value is correct." );
return "foobar"; return "foobar";
}); });
equals( jQuery("#sap").text(), "foobar", 'Check for merged text of more then one element.' ); equals( jQuery("#sap").text(), "foobar", "Check for merged text of more then one element." );
QUnit.reset(); QUnit.reset();
}); });
var testWrap = function(val) { var testWrap = function(val) {
expect(19); expect(19);
var defaultText = 'Try them out:' var defaultText = "Try them out:"
var result = jQuery('#first').wrap(val( '<div class="red"><span></span></div>' )).text(); var result = jQuery("#first").wrap(val( "<div class='red'><span></span></div>" )).text();
equals( defaultText, result, 'Check for wrapping of on-the-fly html' ); equals( defaultText, result, "Check for wrapping of on-the-fly html" );
ok( jQuery('#first').parent().parent().is('.red'), 'Check if wrapper has class "red"' ); ok( jQuery("#first").parent().parent().is(".red"), "Check if wrapper has class 'red'" );
QUnit.reset(); QUnit.reset();
var defaultText = 'Try them out:' var defaultText = "Try them out:"
var result = jQuery('#first').wrap(val( document.getElementById('empty') )).parent(); var result = jQuery("#first").wrap(val( document.getElementById("empty") )).parent();
ok( result.is('ol'), 'Check for element wrapping' ); ok( result.is("ol"), "Check for element wrapping" );
equals( result.text(), defaultText, 'Check for element wrapping' ); equals( result.text(), defaultText, "Check for element wrapping" );
QUnit.reset(); QUnit.reset();
jQuery('#check1').click(function() { jQuery("#check1").click(function() {
var checkbox = this; var checkbox = this;
ok( checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" ); ok( checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" );
jQuery(checkbox).wrap(val( '<div id="c1" style="display:none;"></div>' )); jQuery(checkbox).wrap(val( "<div id='c1' style='display:none;'></div>" ));
ok( checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" ); ok( checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" );
}).click(); }).click();
@ -143,17 +143,17 @@ var testWrapAll = function(val) {
var prev = jQuery("#firstp")[0].previousSibling; var prev = jQuery("#firstp")[0].previousSibling;
var p = jQuery("#firstp,#first")[0].parentNode; var p = jQuery("#firstp,#first")[0].parentNode;
var result = jQuery('#firstp,#first').wrapAll(val( '<div class="red"><div class="tmp"></div></div>' )); var result = jQuery("#firstp,#first").wrapAll(val( "<div class='red'><div class='tmp'></div></div>" ));
equals( result.parent().length, 1, 'Check for wrapping of on-the-fly html' ); equals( result.parent().length, 1, "Check for wrapping of on-the-fly html" );
ok( jQuery('#first').parent().parent().is('.red'), 'Check if wrapper has class "red"' ); ok( jQuery("#first").parent().parent().is(".red"), "Check if wrapper has class 'red'" );
ok( jQuery('#firstp').parent().parent().is('.red'), 'Check if wrapper has class "red"' ); ok( jQuery("#firstp").parent().parent().is(".red"), "Check if wrapper has class 'red'" );
equals( jQuery("#first").parent().parent()[0].previousSibling, prev, "Correct Previous Sibling" ); equals( jQuery("#first").parent().parent()[0].previousSibling, prev, "Correct Previous Sibling" );
equals( jQuery("#first").parent().parent()[0].parentNode, p, "Correct Parent" ); equals( jQuery("#first").parent().parent()[0].parentNode, p, "Correct Parent" );
QUnit.reset(); QUnit.reset();
var prev = jQuery("#firstp")[0].previousSibling; var prev = jQuery("#firstp")[0].previousSibling;
var p = jQuery("#first")[0].parentNode; var p = jQuery("#first")[0].parentNode;
var result = jQuery('#firstp,#first').wrapAll(val( document.getElementById('empty') )); var result = jQuery("#firstp,#first").wrapAll(val( document.getElementById("empty") ));
equals( jQuery("#first").parent()[0], jQuery("#firstp").parent()[0], "Same Parent" ); equals( jQuery("#first").parent()[0], jQuery("#firstp").parent()[0], "Same Parent" );
equals( jQuery("#first").parent()[0].previousSibling, prev, "Correct Previous Sibling" ); equals( jQuery("#first").parent()[0].previousSibling, prev, "Correct Previous Sibling" );
equals( jQuery("#first").parent()[0].parentNode, p, "Correct Parent" ); equals( jQuery("#first").parent()[0].parentNode, p, "Correct Parent" );
@ -166,21 +166,21 @@ test("wrapAll(String|Element)", function() {
var testWrapInner = function(val) { var testWrapInner = function(val) {
expect(11); expect(11);
var num = jQuery("#first").children().length; var num = jQuery("#first").children().length;
var result = jQuery('#first').wrapInner(val('<div class="red"><div id="tmp"></div></div>')); var result = jQuery("#first").wrapInner(val("<div class='red'><div id='tmp'></div></div>"));
equals( jQuery("#first").children().length, 1, "Only one child" ); equals( jQuery("#first").children().length, 1, "Only one child" );
ok( jQuery("#first").children().is(".red"), "Verify Right Element" ); ok( jQuery("#first").children().is(".red"), "Verify Right Element" );
equals( jQuery("#first").children().children().children().length, num, "Verify Elements Intact" ); equals( jQuery("#first").children().children().children().length, num, "Verify Elements Intact" );
QUnit.reset(); QUnit.reset();
var num = jQuery("#first").html("foo<div>test</div><div>test2</div>").children().length; var num = jQuery("#first").html("foo<div>test</div><div>test2</div>").children().length;
var result = jQuery('#first').wrapInner(val('<div class="red"><div id="tmp"></div></div>')); var result = jQuery("#first").wrapInner(val("<div class='red'><div id='tmp'></div></div>"));
equals( jQuery("#first").children().length, 1, "Only one child" ); equals( jQuery("#first").children().length, 1, "Only one child" );
ok( jQuery("#first").children().is(".red"), "Verify Right Element" ); ok( jQuery("#first").children().is(".red"), "Verify Right Element" );
equals( jQuery("#first").children().children().children().length, num, "Verify Elements Intact" ); equals( jQuery("#first").children().children().children().length, num, "Verify Elements Intact" );
QUnit.reset(); QUnit.reset();
var num = jQuery("#first").children().length; var num = jQuery("#first").children().length;
var result = jQuery('#first').wrapInner(val(document.getElementById('empty'))); var result = jQuery("#first").wrapInner(val(document.getElementById("empty")));
equals( jQuery("#first").children().length, 1, "Only one child" ); equals( jQuery("#first").children().length, 1, "Only one child" );
ok( jQuery("#first").children().is("#empty"), "Verify Right Element" ); ok( jQuery("#first").children().is("#empty"), "Verify Right Element" );
equals( jQuery("#first").children().children().length, num, "Verify Elements Intact" ); equals( jQuery("#first").children().children().length, num, "Verify Elements Intact" );
@ -202,51 +202,51 @@ test("wrapInner(Function)", function() {
test("unwrap()", function() { test("unwrap()", function() {
expect(9); expect(9);
jQuery("body").append(' <div id="unwrap" style="display: none;"> <div id="unwrap1"> <span class="unwrap">a</span> <span class="unwrap">b</span> </div> <div id="unwrap2"> <span class="unwrap">c</span> <span class="unwrap">d</span> </div> <div id="unwrap3"> <b><span class="unwrap unwrap3">e</span></b> <b><span class="unwrap unwrap3">f</span></b> </div> </div>'); jQuery("body").append(" <div id='unwrap' style='display: none;'> <div id='unwrap1'> <span class='unwrap'>a</span> <span class='unwrap'>b</span> </div> <div id='unwrap2'> <span class='unwrap'>c</span> <span class='unwrap'>d</span> </div> <div id='unwrap3'> <b><span class='unwrap unwrap3'>e</span></b> <b><span class='unwrap unwrap3'>f</span></b> </div> </div>");
var abcd = jQuery('#unwrap1 > span, #unwrap2 > span').get(), var abcd = jQuery("#unwrap1 > span, #unwrap2 > span").get(),
abcdef = jQuery('#unwrap span').get(); abcdef = jQuery("#unwrap span").get();
equals( jQuery('#unwrap1 span').add('#unwrap2 span:first').unwrap().length, 3, 'make #unwrap1 and #unwrap2 go away' ); equals( jQuery("#unwrap1 span").add("#unwrap2 span:first").unwrap().length, 3, "make #unwrap1 and #unwrap2 go away" );
same( jQuery('#unwrap > span').get(), abcd, 'all four spans should still exist' ); same( jQuery("#unwrap > span").get(), abcd, "all four spans should still exist" );
same( jQuery('#unwrap3 span').unwrap().get(), jQuery('#unwrap3 > span').get(), 'make all b in #unwrap3 go away' ); same( jQuery("#unwrap3 span").unwrap().get(), jQuery("#unwrap3 > span").get(), "make all b in #unwrap3 go away" );
same( jQuery('#unwrap3 span').unwrap().get(), jQuery('#unwrap > span.unwrap3').get(), 'make #unwrap3 go away' ); same( jQuery("#unwrap3 span").unwrap().get(), jQuery("#unwrap > span.unwrap3").get(), "make #unwrap3 go away" );
same( jQuery('#unwrap').children().get(), abcdef, '#unwrap only contains 6 child spans' ); same( jQuery("#unwrap").children().get(), abcdef, "#unwrap only contains 6 child spans" );
same( jQuery('#unwrap > span').unwrap().get(), jQuery('body > span.unwrap').get(), 'make the 6 spans become children of body' ); same( jQuery("#unwrap > span").unwrap().get(), jQuery("body > span.unwrap").get(), "make the 6 spans become children of body" );
same( jQuery('body > span.unwrap').unwrap().get(), jQuery('body > span.unwrap').get(), 'can\'t unwrap children of body' ); same( jQuery("body > span.unwrap").unwrap().get(), jQuery("body > span.unwrap").get(), "can't unwrap children of body" );
same( jQuery('body > span.unwrap').unwrap().get(), abcdef, 'can\'t unwrap children of body' ); same( jQuery("body > span.unwrap").unwrap().get(), abcdef, "can't unwrap children of body" );
same( jQuery('body > span.unwrap').get(), abcdef, 'body contains 6 .unwrap child spans' ); same( jQuery("body > span.unwrap").get(), abcdef, "body contains 6 .unwrap child spans" );
jQuery('body > span.unwrap').remove(); jQuery("body > span.unwrap").remove();
}); });
var testAppend = function(valueObj) { var testAppend = function(valueObj) {
expect(37); expect(37);
var defaultText = 'Try them out:' var defaultText = "Try them out:"
var result = jQuery('#first').append(valueObj('<b>buga</b>')); var result = jQuery("#first").append(valueObj("<b>buga</b>"));
equals( result.text(), defaultText + 'buga', 'Check if text appending works' ); equals( result.text(), defaultText + "buga", "Check if text appending works" );
equals( jQuery('#select3').append(valueObj('<option value="appendTest">Append Test</option>')).find('option:last-child').attr('value'), 'appendTest', 'Appending html options to select element'); equals( jQuery("#select3").append(valueObj("<option value='appendTest'>Append Test</option>")).find("option:last-child").attr("value"), "appendTest", "Appending html options to select element");
QUnit.reset(); QUnit.reset();
var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:"; var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
jQuery('#sap').append(valueObj(document.getElementById('first'))); jQuery("#sap").append(valueObj(document.getElementById("first")));
equals( jQuery('#sap').text(), expected, "Check for appending of element" ); equals( jQuery("#sap").text(), expected, "Check for appending of element" );
QUnit.reset(); QUnit.reset();
expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo"; expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
jQuery('#sap').append(valueObj([document.getElementById('first'), document.getElementById('yahoo')])); jQuery("#sap").append(valueObj([document.getElementById("first"), document.getElementById("yahoo")]));
equals( jQuery('#sap').text(), expected, "Check for appending of array of elements" ); equals( jQuery("#sap").text(), expected, "Check for appending of array of elements" );
QUnit.reset(); QUnit.reset();
expected = "This link has class=\"blog\": Simon Willison's WeblogYahooTry them out:"; expected = "This link has class=\"blog\": Simon Willison's WeblogYahooTry them out:";
jQuery('#sap').append(valueObj(jQuery("#yahoo, #first"))); jQuery("#sap").append(valueObj(jQuery("#yahoo, #first")));
equals( jQuery('#sap').text(), expected, "Check for appending of jQuery object" ); equals( jQuery("#sap").text(), expected, "Check for appending of jQuery object" );
QUnit.reset(); QUnit.reset();
jQuery("#sap").append(valueObj( 5 )); jQuery("#sap").append(valueObj( 5 ));
@ -262,25 +262,25 @@ var testAppend = function(valueObj) {
ok( jQuery("#sap").append(valueObj( document.getElementsByTagName("foo") )), "Check for appending an empty nodelist." ); ok( jQuery("#sap").append(valueObj( document.getElementsByTagName("foo") )), "Check for appending an empty nodelist." );
QUnit.reset(); QUnit.reset();
jQuery("form").append(valueObj('<input name="radiotest" type="radio" checked="checked" />')); jQuery("form").append(valueObj("<input name='radiotest' type='radio' checked='checked' />"));
jQuery("form input[name=radiotest]").each(function(){ jQuery("form input[name=radiotest]").each(function(){
ok( jQuery(this).is(':checked'), "Append checked radio"); ok( jQuery(this).is(":checked"), "Append checked radio");
}).remove(); }).remove();
QUnit.reset(); QUnit.reset();
jQuery("form").append(valueObj('<input name="radiotest" type="radio" checked = \'checked\' />')); jQuery("form").append(valueObj("<input name='radiotest' type='radio' checked = 'checked' />"));
jQuery("form input[name=radiotest]").each(function(){ jQuery("form input[name=radiotest]").each(function(){
ok( jQuery(this).is(':checked'), "Append alternately formated checked radio"); ok( jQuery(this).is(":checked"), "Append alternately formated checked radio");
}).remove(); }).remove();
QUnit.reset(); QUnit.reset();
jQuery("form").append(valueObj('<input name="radiotest" type="radio" checked />')); jQuery("form").append(valueObj("<input name='radiotest' type='radio' checked />"));
jQuery("form input[name=radiotest]").each(function(){ jQuery("form input[name=radiotest]").each(function(){
ok( jQuery(this).is(':checked'), "Append HTML5-formated checked radio"); ok( jQuery(this).is(":checked"), "Append HTML5-formated checked radio");
}).remove(); }).remove();
QUnit.reset(); QUnit.reset();
jQuery("#sap").append(valueObj( document.getElementById('form') )); jQuery("#sap").append(valueObj( document.getElementById("form") ));
equals( jQuery("#sap>form").size(), 1, "Check for appending a form" ); // Bug #910 equals( jQuery("#sap>form").size(), 1, "Check for appending a form" ); // Bug #910
QUnit.reset(); QUnit.reset();
@ -296,31 +296,31 @@ var testAppend = function(valueObj) {
ok( pass, "Test for appending a DOM node to the contents of an IFrame" ); ok( pass, "Test for appending a DOM node to the contents of an IFrame" );
QUnit.reset(); QUnit.reset();
jQuery('<fieldset/>').appendTo('#form').append(valueObj( '<legend id="legend">test</legend>' )); jQuery("<fieldset/>").appendTo("#form").append(valueObj( "<legend id='legend'>test</legend>" ));
t( 'Append legend', '#legend', ['legend'] ); t( "Append legend", "#legend", ["legend"] );
QUnit.reset(); QUnit.reset();
jQuery('#select1').append(valueObj( '<OPTION>Test</OPTION>' )); jQuery("#select1").append(valueObj( "<OPTION>Test</OPTION>" ));
equals( jQuery('#select1 option:last').text(), "Test", "Appending &lt;OPTION&gt; (all caps)" ); equals( jQuery("#select1 option:last").text(), "Test", "Appending &lt;OPTION&gt; (all caps)" );
jQuery('#table').append(valueObj( '<colgroup></colgroup>' )); jQuery("#table").append(valueObj( "<colgroup></colgroup>" ));
ok( jQuery('#table colgroup').length, "Append colgroup" ); ok( jQuery("#table colgroup").length, "Append colgroup" );
jQuery('#table colgroup').append(valueObj( '<col/>' )); jQuery("#table colgroup").append(valueObj( "<col/>" ));
ok( jQuery('#table colgroup col').length, "Append col" ); ok( jQuery("#table colgroup col").length, "Append col" );
QUnit.reset(); QUnit.reset();
jQuery('#table').append(valueObj( '<caption></caption>' )); jQuery("#table").append(valueObj( "<caption></caption>" ));
ok( jQuery('#table caption').length, "Append caption" ); ok( jQuery("#table caption").length, "Append caption" );
QUnit.reset(); QUnit.reset();
jQuery('form:last') jQuery("form:last")
.append(valueObj( '<select id="appendSelect1"></select>' )) .append(valueObj( "<select id='appendSelect1'></select>" ))
.append(valueObj( '<select id="appendSelect2"><option>Test</option></select>' )); .append(valueObj( "<select id='appendSelect2'><option>Test</option></select>" ));
t( "Append Select", "#appendSelect1, #appendSelect2", ["appendSelect1", "appendSelect2"] ); t( "Append Select", "#appendSelect1, #appendSelect2", ["appendSelect1", "appendSelect2"] );
equals( "Two nodes", jQuery('<div />').append("Two", " nodes").text(), "Appending two text nodes (#4011)" ); equals( "Two nodes", jQuery("<div />").append("Two", " nodes").text(), "Appending two text nodes (#4011)" );
// using contents will get comments regular, text, and comment nodes // using contents will get comments regular, text, and comment nodes
var j = jQuery("#nonnodes").contents(); var j = jQuery("#nonnodes").contents();
@ -343,51 +343,51 @@ test("append(Function)", function() {
test("append(Function) with incoming value", function() { test("append(Function) with incoming value", function() {
expect(12); expect(12);
var defaultText = 'Try them out:', old = jQuery("#first").html(); var defaultText = "Try them out:", old = jQuery("#first").html();
var result = jQuery('#first').append(function(i, val){ var result = jQuery("#first").append(function(i, val){
equals( val, old, "Make sure the incoming value is correct." ); equals( val, old, "Make sure the incoming value is correct." );
return '<b>buga</b>'; return "<b>buga</b>";
}); });
equals( result.text(), defaultText + 'buga', 'Check if text appending works' ); equals( result.text(), defaultText + "buga", "Check if text appending works" );
var select = jQuery('#select3'); var select = jQuery("#select3");
old = select.html(); old = select.html();
equals( select.append(function(i, val){ equals( select.append(function(i, val){
equals( val, old, "Make sure the incoming value is correct." ); equals( val, old, "Make sure the incoming value is correct." );
return '<option value="appendTest">Append Test</option>'; return "<option value='appendTest'>Append Test</option>";
}).find('option:last-child').attr('value'), 'appendTest', 'Appending html options to select element'); }).find("option:last-child").attr("value"), "appendTest", "Appending html options to select element");
QUnit.reset(); QUnit.reset();
var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:"; var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
old = jQuery("#sap").html(); old = jQuery("#sap").html();
jQuery('#sap').append(function(i, val){ jQuery("#sap").append(function(i, val){
equals( val, old, "Make sure the incoming value is correct." ); equals( val, old, "Make sure the incoming value is correct." );
return document.getElementById('first'); return document.getElementById("first");
}); });
equals( jQuery('#sap').text(), expected, "Check for appending of element" ); equals( jQuery("#sap").text(), expected, "Check for appending of element" );
QUnit.reset(); QUnit.reset();
expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo"; expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
old = jQuery("#sap").html(); old = jQuery("#sap").html();
jQuery('#sap').append(function(i, val){ jQuery("#sap").append(function(i, val){
equals( val, old, "Make sure the incoming value is correct." ); equals( val, old, "Make sure the incoming value is correct." );
return [document.getElementById('first'), document.getElementById('yahoo')]; return [document.getElementById("first"), document.getElementById("yahoo")];
}); });
equals( jQuery('#sap').text(), expected, "Check for appending of array of elements" ); equals( jQuery("#sap").text(), expected, "Check for appending of array of elements" );
QUnit.reset(); QUnit.reset();
expected = "This link has class=\"blog\": Simon Willison's WeblogYahooTry them out:"; expected = "This link has class=\"blog\": Simon Willison's WeblogYahooTry them out:";
old = jQuery("#sap").html(); old = jQuery("#sap").html();
jQuery('#sap').append(function(i, val){ jQuery("#sap").append(function(i, val){
equals( val, old, "Make sure the incoming value is correct." ); equals( val, old, "Make sure the incoming value is correct." );
return jQuery("#yahoo, #first"); return jQuery("#yahoo, #first");
}); });
equals( jQuery('#sap').text(), expected, "Check for appending of jQuery object" ); equals( jQuery("#sap").text(), expected, "Check for appending of jQuery object" );
QUnit.reset(); QUnit.reset();
old = jQuery("#sap").html(); old = jQuery("#sap").html();
@ -414,11 +414,11 @@ test("append the same fragment with events (Bug #6997, 5566)", function () {
if ( doExtra ) { if ( doExtra ) {
element = jQuery("div:first").click(function () { element = jQuery("div:first").click(function () {
ok(true, "Event exists on original after being unbound on clone"); ok(true, "Event exists on original after being unbound on clone");
jQuery(this).unbind('click'); jQuery(this).unbind("click");
}); });
var clone = element.clone(true).unbind('click'); var clone = element.clone(true).unbind("click");
clone[0].fireEvent('onclick'); clone[0].fireEvent("onclick");
element[0].fireEvent('onclick'); element[0].fireEvent("onclick");
// manually clean up detached elements // manually clean up detached elements
clone.remove(); clone.remove();
@ -429,7 +429,7 @@ test("append the same fragment with events (Bug #6997, 5566)", function () {
}); });
jQuery("#listWithTabIndex li").append(element) jQuery("#listWithTabIndex li").append(element)
.find('a.test6997').eq(1).click(); .find("a.test6997").eq(1).click();
element = jQuery("<li class='test6997'></li>").click(function () { element = jQuery("<li class='test6997'></li>").click(function () {
ok(true, "Before second element events work"); ok(true, "Before second element events work");
@ -443,10 +443,10 @@ test("append the same fragment with events (Bug #6997, 5566)", function () {
test("appendTo(String|Element|Array&lt;Element&gt;|jQuery)", function() { test("appendTo(String|Element|Array&lt;Element&gt;|jQuery)", function() {
expect(16); expect(16);
var defaultText = 'Try them out:' var defaultText = "Try them out:"
jQuery('<b>buga</b>').appendTo('#first'); jQuery("<b>buga</b>").appendTo("#first");
equals( jQuery("#first").text(), defaultText + 'buga', 'Check if text appending works' ); equals( jQuery("#first").text(), defaultText + "buga", "Check if text appending works" );
equals( jQuery('<option value="appendTest">Append Test</option>').appendTo('#select3').parent().find('option:last-child').attr('value'), 'appendTest', 'Appending html options to select element'); equals( jQuery("<option value='appendTest'>Append Test</option>").appendTo("#select3").parent().find("option:last-child").attr("value"), "appendTest", "Appending html options to select element");
QUnit.reset(); QUnit.reset();
var l = jQuery("#first").children().length + 2; var l = jQuery("#first").children().length + 2;
@ -459,25 +459,25 @@ test("appendTo(String|Element|Array&lt;Element&gt;|jQuery)", function() {
QUnit.reset(); QUnit.reset();
var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:"; var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
jQuery(document.getElementById('first')).appendTo('#sap'); jQuery(document.getElementById("first")).appendTo("#sap");
equals( jQuery('#sap').text(), expected, "Check for appending of element" ); equals( jQuery("#sap").text(), expected, "Check for appending of element" );
QUnit.reset(); QUnit.reset();
expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo"; expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
jQuery([document.getElementById('first'), document.getElementById('yahoo')]).appendTo('#sap'); jQuery([document.getElementById("first"), document.getElementById("yahoo")]).appendTo("#sap");
equals( jQuery('#sap').text(), expected, "Check for appending of array of elements" ); equals( jQuery("#sap").text(), expected, "Check for appending of array of elements" );
QUnit.reset(); QUnit.reset();
ok( jQuery(document.createElement("script")).appendTo("body").length, "Make sure a disconnected script can be appended." ); ok( jQuery(document.createElement("script")).appendTo("body").length, "Make sure a disconnected script can be appended." );
QUnit.reset(); QUnit.reset();
expected = "This link has class=\"blog\": Simon Willison's WeblogYahooTry them out:"; expected = "This link has class=\"blog\": Simon Willison's WeblogYahooTry them out:";
jQuery("#yahoo, #first").appendTo('#sap'); jQuery("#yahoo, #first").appendTo("#sap");
equals( jQuery('#sap').text(), expected, "Check for appending of jQuery object" ); equals( jQuery("#sap").text(), expected, "Check for appending of jQuery object" );
QUnit.reset(); QUnit.reset();
jQuery('#select1').appendTo('#foo'); jQuery("#select1").appendTo("#foo");
t( 'Append select', '#foo select', ['select1'] ); t( "Append select", "#foo select", ["select1"] );
QUnit.reset(); QUnit.reset();
var div = jQuery("<div/>").click(function(){ var div = jQuery("<div/>").click(function(){
@ -517,25 +517,25 @@ test("appendTo(String|Element|Array&lt;Element&gt;|jQuery)", function() {
var testPrepend = function(val) { var testPrepend = function(val) {
expect(5); expect(5);
var defaultText = 'Try them out:' var defaultText = "Try them out:"
var result = jQuery('#first').prepend(val( '<b>buga</b>' )); var result = jQuery("#first").prepend(val( "<b>buga</b>" ));
equals( result.text(), 'buga' + defaultText, 'Check if text prepending works' ); equals( result.text(), "buga" + defaultText, "Check if text prepending works" );
equals( jQuery('#select3').prepend(val( '<option value="prependTest">Prepend Test</option>' )).find('option:first-child').attr('value'), 'prependTest', 'Prepending html options to select element'); equals( jQuery("#select3").prepend(val( "<option value='prependTest'>Prepend Test</option>" )).find("option:first-child").attr("value"), "prependTest", "Prepending html options to select element");
QUnit.reset(); QUnit.reset();
var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog"; var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
jQuery('#sap').prepend(val( document.getElementById('first') )); jQuery("#sap").prepend(val( document.getElementById("first") ));
equals( jQuery('#sap').text(), expected, "Check for prepending of element" ); equals( jQuery("#sap").text(), expected, "Check for prepending of element" );
QUnit.reset(); QUnit.reset();
expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog"; expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
jQuery('#sap').prepend(val( [document.getElementById('first'), document.getElementById('yahoo')] )); jQuery("#sap").prepend(val( [document.getElementById("first"), document.getElementById("yahoo")] ));
equals( jQuery('#sap').text(), expected, "Check for prepending of array of elements" ); equals( jQuery("#sap").text(), expected, "Check for prepending of array of elements" );
QUnit.reset(); QUnit.reset();
expected = "YahooTry them out:This link has class=\"blog\": Simon Willison's Weblog"; expected = "YahooTry them out:This link has class=\"blog\": Simon Willison's Weblog";
jQuery('#sap').prepend(val( jQuery("#yahoo, #first") )); jQuery("#sap").prepend(val( 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("prepend(String|Element|Array&lt;Element&gt;|jQuery)", function() { test("prepend(String|Element|Array&lt;Element&gt;|jQuery)", function() {
@ -549,103 +549,103 @@ test("prepend(Function)", function() {
test("prepend(Function) with incoming value", function() { test("prepend(Function) with incoming value", function() {
expect(10); expect(10);
var defaultText = 'Try them out:', old = jQuery('#first').html(); var defaultText = "Try them out:", old = jQuery("#first").html();
var result = jQuery('#first').prepend(function(i, val) { var result = jQuery("#first").prepend(function(i, val) {
equals( val, old, "Make sure the incoming value is correct." ); equals( val, old, "Make sure the incoming value is correct." );
return '<b>buga</b>'; return "<b>buga</b>";
}); });
equals( result.text(), 'buga' + defaultText, 'Check if text prepending works' ); equals( result.text(), "buga" + defaultText, "Check if text prepending works" );
old = jQuery("#select3").html(); old = jQuery("#select3").html();
equals( jQuery('#select3').prepend(function(i, val) { equals( jQuery("#select3").prepend(function(i, val) {
equals( val, old, "Make sure the incoming value is correct." ); equals( val, old, "Make sure the incoming value is correct." );
return '<option value="prependTest">Prepend Test</option>'; return "<option value='prependTest'>Prepend Test</option>";
}).find('option:first-child').attr('value'), 'prependTest', 'Prepending html options to select element'); }).find("option:first-child").attr("value"), "prependTest", "Prepending html options to select element");
QUnit.reset(); QUnit.reset();
var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog"; var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
old = jQuery('#sap').html(); old = jQuery("#sap").html();
jQuery('#sap').prepend(function(i, val) { jQuery("#sap").prepend(function(i, val) {
equals( val, old, "Make sure the incoming value is correct." ); equals( val, old, "Make sure the incoming value is correct." );
return document.getElementById('first'); return document.getElementById("first");
}); });
equals( jQuery('#sap').text(), expected, "Check for prepending of element" ); equals( jQuery("#sap").text(), expected, "Check for prepending of element" );
QUnit.reset(); QUnit.reset();
expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog"; expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
old = jQuery('#sap').html(); old = jQuery("#sap").html();
jQuery('#sap').prepend(function(i, val) { jQuery("#sap").prepend(function(i, val) {
equals( val, old, "Make sure the incoming value is correct." ); equals( val, old, "Make sure the incoming value is correct." );
return [document.getElementById('first'), document.getElementById('yahoo')]; return [document.getElementById("first"), document.getElementById("yahoo")];
}); });
equals( jQuery('#sap').text(), expected, "Check for prepending of array of elements" ); equals( jQuery("#sap").text(), expected, "Check for prepending of array of elements" );
QUnit.reset(); QUnit.reset();
expected = "YahooTry them out:This link has class=\"blog\": Simon Willison's Weblog"; expected = "YahooTry them out:This link has class=\"blog\": Simon Willison's Weblog";
old = jQuery('#sap').html(); old = jQuery("#sap").html();
jQuery('#sap').prepend(function(i, val) { jQuery("#sap").prepend(function(i, val) {
equals( val, old, "Make sure the incoming value is correct." ); equals( val, old, "Make sure the incoming value is correct." );
return jQuery("#yahoo, #first"); 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&lt;Element&gt;|jQuery)", function() { test("prependTo(String|Element|Array&lt;Element&gt;|jQuery)", function() {
expect(6); expect(6);
var defaultText = 'Try them out:' var defaultText = "Try them out:"
jQuery('<b>buga</b>').prependTo('#first'); jQuery("<b>buga</b>").prependTo("#first");
equals( jQuery('#first').text(), 'buga' + defaultText, 'Check if text prepending works' ); equals( jQuery("#first").text(), "buga" + defaultText, "Check if text prepending works" );
equals( jQuery('<option value="prependTest">Prepend Test</option>').prependTo('#select3').parent().find('option:first-child').attr('value'), 'prependTest', 'Prepending html options to select element'); equals( jQuery("<option value='prependTest'>Prepend Test</option>").prependTo("#select3").parent().find("option:first-child").attr("value"), "prependTest", "Prepending html options to select element");
QUnit.reset(); QUnit.reset();
var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog"; var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
jQuery(document.getElementById('first')).prependTo('#sap'); jQuery(document.getElementById("first")).prependTo("#sap");
equals( jQuery('#sap').text(), expected, "Check for prepending of element" ); equals( jQuery("#sap").text(), expected, "Check for prepending of element" );
QUnit.reset(); QUnit.reset();
expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog"; expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
jQuery([document.getElementById('first'), document.getElementById('yahoo')]).prependTo('#sap'); jQuery([document.getElementById("first"), document.getElementById("yahoo")]).prependTo("#sap");
equals( jQuery('#sap').text(), expected, "Check for prepending of array of elements" ); equals( jQuery("#sap").text(), expected, "Check for prepending of array of elements" );
QUnit.reset(); QUnit.reset();
expected = "YahooTry them out:This link has class=\"blog\": Simon Willison's Weblog"; expected = "YahooTry them out:This link has class=\"blog\": Simon Willison's Weblog";
jQuery("#yahoo, #first").prependTo('#sap'); jQuery("#yahoo, #first").prependTo("#sap");
equals( jQuery('#sap').text(), expected, "Check for prepending of jQuery object" ); equals( jQuery("#sap").text(), expected, "Check for prepending of jQuery object" );
QUnit.reset(); QUnit.reset();
jQuery('<select id="prependSelect1"></select>').prependTo('form:last'); jQuery("<select id='prependSelect1'></select>").prependTo("form:last");
jQuery('<select id="prependSelect2"><option>Test</option></select>').prependTo('form:last'); jQuery("<select id='prependSelect2'><option>Test</option></select>").prependTo("form:last");
t( "Prepend Select", "#prependSelect2, #prependSelect1", ["prependSelect2", "prependSelect1"] ); t( "Prepend Select", "#prependSelect2, #prependSelect1", ["prependSelect2", "prependSelect1"] );
}); });
var testBefore = function(val) { var testBefore = function(val) {
expect(6); expect(6);
var expected = 'This is a normal link: bugaYahoo'; var expected = "This is a normal link: bugaYahoo";
jQuery('#yahoo').before(val( '<b>buga</b>' )); jQuery("#yahoo").before(val( "<b>buga</b>" ));
equals( jQuery('#en').text(), expected, 'Insert String before' ); equals( jQuery("#en").text(), expected, "Insert String before" );
QUnit.reset(); QUnit.reset();
expected = "This is a normal link: Try them out:Yahoo"; expected = "This is a normal link: Try them out:Yahoo";
jQuery('#yahoo').before(val( document.getElementById('first') )); jQuery("#yahoo").before(val( document.getElementById("first") ));
equals( jQuery('#en').text(), expected, "Insert element before" ); equals( jQuery("#en").text(), expected, "Insert element before" );
QUnit.reset(); QUnit.reset();
expected = "This is a normal link: Try them out:diveintomarkYahoo"; expected = "This is a normal link: Try them out:diveintomarkYahoo";
jQuery('#yahoo').before(val( [document.getElementById('first'), document.getElementById('mark')] )); jQuery("#yahoo").before(val( [document.getElementById("first"), document.getElementById("mark")] ));
equals( jQuery('#en').text(), expected, "Insert array of elements before" ); equals( jQuery("#en").text(), expected, "Insert array of elements before" );
QUnit.reset(); QUnit.reset();
expected = "This is a normal link: diveintomarkTry them out:Yahoo"; expected = "This is a normal link: diveintomarkTry them out:Yahoo";
jQuery('#yahoo').before(val( jQuery("#mark, #first") )); jQuery("#yahoo").before(val( jQuery("#mark, #first") ));
equals( jQuery('#en').text(), expected, "Insert jQuery before" ); equals( jQuery("#en").text(), expected, "Insert jQuery before" );
var set = jQuery("<div/>").before("<span>test</span>"); var set = jQuery("<div/>").before("<span>test</span>");
equals( set[0].nodeName.toLowerCase(), "span", "Insert the element before the disconnected node." ); equals( set[0].nodeName.toLowerCase(), "span", "Insert the element before the disconnected node." );
@ -662,46 +662,46 @@ test("before(Function)", function() {
test("insertBefore(String|Element|Array&lt;Element&gt;|jQuery)", function() { test("insertBefore(String|Element|Array&lt;Element&gt;|jQuery)", function() {
expect(4); expect(4);
var expected = 'This is a normal link: bugaYahoo'; var expected = "This is a normal link: bugaYahoo";
jQuery('<b>buga</b>').insertBefore('#yahoo'); jQuery("<b>buga</b>").insertBefore("#yahoo");
equals( jQuery('#en').text(), expected, 'Insert String before' ); equals( jQuery("#en").text(), expected, "Insert String before" );
QUnit.reset(); QUnit.reset();
expected = "This is a normal link: Try them out:Yahoo"; expected = "This is a normal link: Try them out:Yahoo";
jQuery(document.getElementById('first')).insertBefore('#yahoo'); jQuery(document.getElementById("first")).insertBefore("#yahoo");
equals( jQuery('#en').text(), expected, "Insert element before" ); equals( jQuery("#en").text(), expected, "Insert element before" );
QUnit.reset(); QUnit.reset();
expected = "This is a normal link: Try them out:diveintomarkYahoo"; expected = "This is a normal link: Try them out:diveintomarkYahoo";
jQuery([document.getElementById('first'), document.getElementById('mark')]).insertBefore('#yahoo'); jQuery([document.getElementById("first"), document.getElementById("mark")]).insertBefore("#yahoo");
equals( jQuery('#en').text(), expected, "Insert array of elements before" ); equals( jQuery("#en").text(), expected, "Insert array of elements before" );
QUnit.reset(); QUnit.reset();
expected = "This is a normal link: diveintomarkTry them out:Yahoo"; expected = "This is a normal link: diveintomarkTry them out:Yahoo";
jQuery("#mark, #first").insertBefore('#yahoo'); jQuery("#mark, #first").insertBefore("#yahoo");
equals( jQuery('#en').text(), expected, "Insert jQuery before" ); equals( jQuery("#en").text(), expected, "Insert jQuery before" );
}); });
var testAfter = function(val) { var testAfter = function(val) {
expect(6); expect(6);
var expected = 'This is a normal link: Yahoobuga'; var expected = "This is a normal link: Yahoobuga";
jQuery('#yahoo').after(val( '<b>buga</b>' )); jQuery("#yahoo").after(val( "<b>buga</b>" ));
equals( jQuery('#en').text(), expected, 'Insert String after' ); equals( jQuery("#en").text(), expected, "Insert String after" );
QUnit.reset(); QUnit.reset();
expected = "This is a normal link: YahooTry them out:"; expected = "This is a normal link: YahooTry them out:";
jQuery('#yahoo').after(val( document.getElementById('first') )); jQuery("#yahoo").after(val( document.getElementById("first") ));
equals( jQuery('#en').text(), expected, "Insert element after" ); equals( jQuery("#en").text(), expected, "Insert element after" );
QUnit.reset(); QUnit.reset();
expected = "This is a normal link: YahooTry them out:diveintomark"; expected = "This is a normal link: YahooTry them out:diveintomark";
jQuery('#yahoo').after(val( [document.getElementById('first'), document.getElementById('mark')] )); jQuery("#yahoo").after(val( [document.getElementById("first"), document.getElementById("mark")] ));
equals( jQuery('#en').text(), expected, "Insert array of elements after" ); equals( jQuery("#en").text(), expected, "Insert array of elements after" );
QUnit.reset(); QUnit.reset();
expected = "This is a normal link: YahoodiveintomarkTry them out:"; expected = "This is a normal link: YahoodiveintomarkTry them out:";
jQuery('#yahoo').after(val( jQuery("#mark, #first") )); jQuery("#yahoo").after(val( jQuery("#mark, #first") ));
equals( jQuery('#en').text(), expected, "Insert jQuery after" ); equals( jQuery("#en").text(), expected, "Insert jQuery after" );
var set = jQuery("<div/>").after("<span>test</span>"); var set = jQuery("<div/>").after("<span>test</span>");
equals( set[1].nodeName.toLowerCase(), "span", "Insert the element after the disconnected node." ); equals( set[1].nodeName.toLowerCase(), "span", "Insert the element after the disconnected node." );
@ -718,58 +718,58 @@ test("after(Function)", function() {
test("insertAfter(String|Element|Array&lt;Element&gt;|jQuery)", function() { test("insertAfter(String|Element|Array&lt;Element&gt;|jQuery)", function() {
expect(4); expect(4);
var expected = 'This is a normal link: Yahoobuga'; var expected = "This is a normal link: Yahoobuga";
jQuery('<b>buga</b>').insertAfter('#yahoo'); jQuery("<b>buga</b>").insertAfter("#yahoo");
equals( jQuery('#en').text(), expected, 'Insert String after' ); equals( jQuery("#en").text(), expected, "Insert String after" );
QUnit.reset(); QUnit.reset();
expected = "This is a normal link: YahooTry them out:"; expected = "This is a normal link: YahooTry them out:";
jQuery(document.getElementById('first')).insertAfter('#yahoo'); jQuery(document.getElementById("first")).insertAfter("#yahoo");
equals( jQuery('#en').text(), expected, "Insert element after" ); equals( jQuery("#en").text(), expected, "Insert element after" );
QUnit.reset(); QUnit.reset();
expected = "This is a normal link: YahooTry them out:diveintomark"; expected = "This is a normal link: YahooTry them out:diveintomark";
jQuery([document.getElementById('first'), document.getElementById('mark')]).insertAfter('#yahoo'); jQuery([document.getElementById("first"), document.getElementById("mark")]).insertAfter("#yahoo");
equals( jQuery('#en').text(), expected, "Insert array of elements after" ); equals( jQuery("#en").text(), expected, "Insert array of elements after" );
QUnit.reset(); QUnit.reset();
expected = "This is a normal link: YahoodiveintomarkTry them out:"; expected = "This is a normal link: YahoodiveintomarkTry them out:";
jQuery("#mark, #first").insertAfter('#yahoo'); jQuery("#mark, #first").insertAfter("#yahoo");
equals( jQuery('#en').text(), expected, "Insert jQuery after" ); equals( jQuery("#en").text(), expected, "Insert jQuery after" );
}); });
var testReplaceWith = function(val) { var testReplaceWith = function(val) {
expect(21); expect(21);
jQuery('#yahoo').replaceWith(val( '<b id="replace">buga</b>' )); jQuery("#yahoo").replaceWith(val( "<b id='replace'>buga</b>" ));
ok( jQuery("#replace")[0], 'Replace element with string' ); ok( jQuery("#replace")[0], "Replace element with string" );
ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after string' ); ok( !jQuery("#yahoo")[0], "Verify that original element is gone, after string" );
QUnit.reset(); QUnit.reset();
jQuery('#yahoo').replaceWith(val( document.getElementById('first') )); jQuery("#yahoo").replaceWith(val( document.getElementById("first") ));
ok( jQuery("#first")[0], 'Replace element with element' ); ok( jQuery("#first")[0], "Replace element with element" );
ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after element' ); ok( !jQuery("#yahoo")[0], "Verify that original element is gone, after element" );
QUnit.reset(); QUnit.reset();
jQuery("#main").append('<div id="bar"><div id="baz">Foo</div></div>'); jQuery("#main").append("<div id='bar'><div id='baz'</div></div>");
jQuery('#baz').replaceWith("Baz"); jQuery("#baz").replaceWith("Baz");
equals( jQuery("#bar").text(),"Baz", 'Replace element with text' ); equals( jQuery("#bar").text(),"Baz", "Replace element with text" );
ok( !jQuery("#baz")[0], 'Verify that original element is gone, after element' ); ok( !jQuery("#baz")[0], "Verify that original element is gone, after element" );
QUnit.reset(); QUnit.reset();
jQuery('#yahoo').replaceWith(val( [document.getElementById('first'), document.getElementById('mark')] )); jQuery("#yahoo").replaceWith(val( [document.getElementById("first"), document.getElementById("mark")] ));
ok( jQuery("#first")[0], 'Replace element with array of elements' ); ok( jQuery("#first")[0], "Replace element with array of elements" );
ok( jQuery("#mark")[0], 'Replace element with array of elements' ); ok( jQuery("#mark")[0], "Replace element with array of elements" );
ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after array of elements' ); ok( !jQuery("#yahoo")[0], "Verify that original element is gone, after array of elements" );
QUnit.reset(); QUnit.reset();
jQuery('#yahoo').replaceWith(val( jQuery("#mark, #first") )); jQuery("#yahoo").replaceWith(val( jQuery("#mark, #first") ));
ok( jQuery("#first")[0], 'Replace element with set of elements' ); ok( jQuery("#first")[0], "Replace element with set of elements" );
ok( jQuery("#mark")[0], 'Replace element with set of elements' ); ok( jQuery("#mark")[0], "Replace element with set of elements" );
ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after set of elements' ); ok( !jQuery("#yahoo")[0], "Verify that original element is gone, after set of elements" );
QUnit.reset(); QUnit.reset();
var tmp = jQuery("<div/>").appendTo("body").click(function(){ ok(true, "Newly bound click run." ); }); var tmp = jQuery("<div/>").appendTo("body").click(function(){ ok(true, "Newly bound click run." ); });
var y = jQuery('<div/>').appendTo("body").click(function(){ ok(true, "Previously bound click run." ); }); var y = jQuery("<div/>").appendTo("body").click(function(){ ok(true, "Previously bound click run." ); });
var child = y.append("<b>test</b>").find("b").click(function(){ ok(true, "Child bound click run." ); return false; }); var child = y.append("<b>test</b>").find("b").click(function(){ ok(true, "Child bound click run." ); return false; });
y.replaceWith( tmp ); y.replaceWith( tmp );
@ -784,7 +784,7 @@ var testReplaceWith = function(val) {
QUnit.reset(); QUnit.reset();
y = jQuery('<div/>').appendTo("body").click(function(){ ok(true, "Previously bound click run." ); }); y = jQuery("<div/>").appendTo("body").click(function(){ ok(true, "Previously bound click run." ); });
var child2 = y.append("<u>test</u>").find("u").click(function(){ ok(true, "Child 2 bound click run." ); return false; }); var child2 = y.append("<u>test</u>").find("u").click(function(){ ok(true, "Child 2 bound click run." ); return false; });
y.replaceWith( child2 ); y.replaceWith( child2 );
@ -800,7 +800,7 @@ var testReplaceWith = function(val) {
equals( set[0].nodeName.toLowerCase(), "span", "Replace the disconnected node." ); equals( set[0].nodeName.toLowerCase(), "span", "Replace the disconnected node." );
equals( set.length, 1, "Replace the disconnected node." ); equals( set.length, 1, "Replace the disconnected node." );
var non_existant = jQuery('#does-not-exist').replaceWith( val("<b>should not throw an error</b>") ); var non_existant = jQuery("#does-not-exist").replaceWith( val("<b>should not throw an error</b>") );
equals( non_existant.length, 0, "Length of non existant element." ); equals( non_existant.length, 0, "Length of non existant element." );
var $div = jQuery("<div class='replacewith'></div>").appendTo("body"); var $div = jQuery("<div class='replacewith'></div>").appendTo("body");
@ -808,8 +808,8 @@ var testReplaceWith = function(val) {
//$div.replaceWith("<div class='replacewith'></div><script>" + //$div.replaceWith("<div class='replacewith'></div><script>" +
//"equals(jQuery('.replacewith').length, 1, 'Check number of elements in page.');" + //"equals(jQuery('.replacewith').length, 1, 'Check number of elements in page.');" +
//"</script>"); //"</script>");
equals(jQuery('.replacewith').length, 1, 'Check number of elements in page.'); equals(jQuery(".replacewith").length, 1, "Check number of elements in page.");
jQuery('.replacewith').remove(); jQuery(".replacewith").remove();
QUnit.reset(); QUnit.reset();
@ -844,35 +844,35 @@ test("replaceWith(Function)", function() {
test("replaceWith(string) for more than one element", function(){ test("replaceWith(string) for more than one element", function(){
expect(3); expect(3);
equals(jQuery('#foo p').length, 3, 'ensuring that test data has not changed'); equals(jQuery("#foo p").length, 3, "ensuring that test data has not changed");
jQuery('#foo p').replaceWith('<span>bar</span>'); jQuery("#foo p").replaceWith("<span>bar</span>");
equals(jQuery('#foo span').length, 3, 'verify that all the three original element have been replaced'); equals(jQuery("#foo span").length, 3, "verify that all the three original element have been replaced");
equals(jQuery('#foo p').length, 0, 'verify that all the three original element have been replaced'); equals(jQuery("#foo p").length, 0, "verify that all the three original element have been replaced");
}); });
test("replaceAll(String|Element|Array&lt;Element&gt;|jQuery)", function() { test("replaceAll(String|Element|Array&lt;Element&gt;|jQuery)", function() {
expect(10); expect(10);
jQuery('<b id="replace">buga</b>').replaceAll("#yahoo"); jQuery("<b id='replace'>buga</b>").replaceAll("#yahoo");
ok( jQuery("#replace")[0], 'Replace element with string' ); ok( jQuery("#replace")[0], "Replace element with string" );
ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after string' ); ok( !jQuery("#yahoo")[0], "Verify that original element is gone, after string" );
QUnit.reset(); QUnit.reset();
jQuery(document.getElementById('first')).replaceAll("#yahoo"); jQuery(document.getElementById("first")).replaceAll("#yahoo");
ok( jQuery("#first")[0], 'Replace element with element' ); ok( jQuery("#first")[0], "Replace element with element" );
ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after element' ); ok( !jQuery("#yahoo")[0], "Verify that original element is gone, after element" );
QUnit.reset(); QUnit.reset();
jQuery([document.getElementById('first'), document.getElementById('mark')]).replaceAll("#yahoo"); jQuery([document.getElementById("first"), document.getElementById("mark")]).replaceAll("#yahoo");
ok( jQuery("#first")[0], 'Replace element with array of elements' ); ok( jQuery("#first")[0], "Replace element with array of elements" );
ok( jQuery("#mark")[0], 'Replace element with array of elements' ); ok( jQuery("#mark")[0], "Replace element with array of elements" );
ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after array of elements' ); ok( !jQuery("#yahoo")[0], "Verify that original element is gone, after array of elements" );
QUnit.reset(); QUnit.reset();
jQuery("#mark, #first").replaceAll("#yahoo"); jQuery("#mark, #first").replaceAll("#yahoo");
ok( jQuery("#first")[0], 'Replace element with set of elements' ); ok( jQuery("#first")[0], "Replace element with set of elements" );
ok( jQuery("#mark")[0], 'Replace element with set of elements' ); ok( jQuery("#mark")[0], "Replace element with set of elements" );
ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after set of elements' ); ok( !jQuery("#yahoo")[0], "Verify that original element is gone, after set of elements" );
}); });
test("jQuery.clone() (#8017)", function() { test("jQuery.clone() (#8017)", function() {
@ -890,9 +890,9 @@ test("jQuery.clone() (#8017)", function() {
test("clone() (#8070)", function () { test("clone() (#8070)", function () {
expect(2); expect(2);
jQuery('<select class="test8070"></select><select class="test8070"></select>').appendTo('#main'); jQuery("<select class='test8070'></select><select class='test8070'></select>").appendTo("#main");
var selects = jQuery('.test8070'); var selects = jQuery(".test8070");
selects.append('<OPTION>1</OPTION><OPTION>2</OPTION>'); selects.append("<OPTION>1</OPTION><OPTION>2</OPTION>");
equals( selects[0].childNodes.length, 2, "First select got two nodes" ); equals( selects[0].childNodes.length, 2, "First select got two nodes" );
equals( selects[1].childNodes.length, 2, "Second select got two nodes" ); equals( selects[1].childNodes.length, 2, "Second select got two nodes" );
@ -902,10 +902,10 @@ test("clone() (#8070)", function () {
test("clone()", function() { test("clone()", function() {
expect(37); expect(37);
equals( 'This is a normal link: Yahoo', jQuery('#en').text(), 'Assert text for #en' ); equals( "This is a normal link: Yahoo", jQuery("#en").text(), "Assert text for #en" );
var clone = jQuery('#yahoo').clone(); var clone = jQuery("#yahoo").clone();
equals( 'Try them out:Yahoo', jQuery('#first').append(clone).text(), 'Check for clone' ); equals( "Try them out:Yahoo", jQuery("#first").append(clone).text(), "Check for clone" );
equals( 'This is a normal link: Yahoo', jQuery('#en').text(), 'Reassert text for #en' ); equals( "This is a normal link: Yahoo", jQuery("#en").text(), "Reassert text for #en" );
var cloneTags = [ var cloneTags = [
"<table/>", "<tr/>", "<td/>", "<div/>", "<table/>", "<tr/>", "<td/>", "<div/>",
@ -915,7 +915,7 @@ test("clone()", function() {
]; ];
for (var i = 0; i < cloneTags.length; i++) { for (var i = 0; i < cloneTags.length; i++) {
var j = jQuery(cloneTags[i]); var j = jQuery(cloneTags[i]);
equals( j[0].tagName, j.clone()[0].tagName, 'Clone a ' + cloneTags[i]); equals( j[0].tagName, j.clone()[0].tagName, "Clone a " + cloneTags[i]);
} }
// using contents will get comments regular, text, and comment nodes // using contents will get comments regular, text, and comment nodes
@ -971,7 +971,7 @@ test("clone()", function() {
// this is technically an invalid object, but because of the special // this is technically an invalid object, but because of the special
// classid instantiation it is the only kind that IE has trouble with, // classid instantiation it is the only kind that IE has trouble with,
// so let's test with it too. // 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&amp;hl=en"> <param name="wmode" value="transparent"> </object>'); 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&amp;hl=en'> <param name='wmode' value='transparent'> </object>");
clone = div.clone(true); clone = div.clone(true);
equals( clone.length, 1, "One element cloned" ); equals( clone.length, 1, "One element cloned" );
@ -979,7 +979,7 @@ test("clone()", function() {
equals( clone[0].nodeName.toUpperCase(), "DIV", "DIV element cloned" ); equals( clone[0].nodeName.toUpperCase(), "DIV", "DIV element cloned" );
// and here's a valid one. // 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&amp;hl=en"> <param name="movie" value="http://www.youtube.com/v/3KANI2dpXLw&amp;hl=en"> <param name="wmode" value="transparent"> </object>'); div = jQuery("<div/>").html("<object height='355' width='425' type='application/x-shockwave-flash' data='http://www.youtube.com/v/3KANI2dpXLw&amp;hl=en'> <param name='movie' value='http://www.youtube.com/v/3KANI2dpXLw&amp;hl=en'> <param name='wmode' value='transparent'> </object>");
clone = div.clone(true); clone = div.clone(true);
equals( clone.length, 1, "One element cloned" ); equals( clone.length, 1, "One element cloned" );
@ -1014,7 +1014,7 @@ test("clone(form element) (Bug #3879, #6655)", function() {
equals( element.clone().find("option:selected").val(), element.find("option:selected").val(), "Selected option cloned correctly" ); equals( element.clone().find("option:selected").val(), element.find("option:selected").val(), "Selected option cloned correctly" );
element = jQuery("<input type='checkbox' value='foo'>").attr('checked', 'checked'); element = jQuery("<input type='checkbox' value='foo'>").attr("checked", "checked");
clone = element.clone(); clone = element.clone();
equals( clone.is(":checked"), element.is(":checked"), "Checked input cloned correctly" ); equals( clone.is(":checked"), element.is(":checked"), "Checked input cloned correctly" );
@ -1058,7 +1058,7 @@ test("clone() on XML nodes", function() {
} }
var testHtml = function(valueObj) { var testHtml = function(valueObj) {
expect(31); expect(34);
jQuery.scriptorder = 0; jQuery.scriptorder = 0;
@ -1070,7 +1070,7 @@ var testHtml = function(valueObj) {
} }
ok( pass, "Set HTML" ); ok( pass, "Set HTML" );
div = jQuery("<div/>").html( valueObj('<div id="parent_1"><div id="child_1"/></div><div id="parent_2"/>') ); div = jQuery("<div/>").html( valueObj("<div id='parent_1'><div id='child_1'/></div><div id='parent_2'/>") );
equals( div.children().length, 2, "Make sure two child nodes exist." ); equals( div.children().length, 2, "Make sure two child nodes exist." );
equals( div.children().children().length, 1, "Make sure that a grandchild exists." ); equals( div.children().children().length, 1, "Make sure that a grandchild exists." );
@ -1090,18 +1090,18 @@ var testHtml = function(valueObj) {
j.html(valueObj("<b>bold</b>")); j.html(valueObj("<b>bold</b>"));
// this is needed, or the expando added by jQuery unique will yield a different html // this is needed, or the expando added by jQuery unique will yield a different html
j.find('b').removeData(); j.find("b").removeData();
equals( j.html().replace(/ xmlns="[^"]+"/g, "").toLowerCase(), "<b>bold</b>", "Check node,textnode,comment with html()" ); equals( j.html().replace(/ xmlns="[^"]+"/g, "").toLowerCase(), "<b>bold</b>", "Check node,textnode,comment with html()" );
jQuery("#main").html(valueObj("<select/>")); jQuery("#main").html(valueObj("<select/>"));
jQuery("#main select").html(valueObj("<option>O1</option><option selected='selected'>O2</option><option>O3</option>")); jQuery("#main select").html(valueObj("<option>O1</option><option selected='selected'>O2</option><option>O3</option>"));
equals( jQuery("#main select").val(), "O2", "Selected option correct" ); equals( jQuery("#main select").val(), "O2", "Selected option correct" );
var $div = jQuery('<div />'); var $div = jQuery("<div />");
equals( $div.html(valueObj( 5 )).html(), '5', 'Setting a number as html' ); equals( $div.html(valueObj( 5 )).html(), "5", "Setting a number as html" );
equals( $div.html(valueObj( 0 )).html(), '0', 'Setting a zero as html' ); equals( $div.html(valueObj( 0 )).html(), "0", "Setting a zero as html" );
var $div2 = jQuery('<div/>'), insert = "&lt;div&gt;hello1&lt;/div&gt;"; var $div2 = jQuery("<div/>"), insert = "&lt;div&gt;hello1&lt;/div&gt;";
equals( $div2.html(insert).html().replace(/>/g, "&gt;"), insert, "Verify escaped insertion." ); equals( $div2.html(insert).html().replace(/>/g, "&gt;"), insert, "Verify escaped insertion." );
equals( $div2.html("x" + insert).html().replace(/>/g, "&gt;"), "x" + insert, "Verify escaped insertion." ); equals( $div2.html("x" + insert).html().replace(/>/g, "&gt;"), "x" + insert, "Verify escaped insertion." );
equals( $div2.html(" " + insert).html().replace(/>/g, "&gt;"), " " + insert, "Verify escaped insertion." ); equals( $div2.html(" " + insert).html().replace(/>/g, "&gt;"), " " + insert, "Verify escaped insertion." );
@ -1113,15 +1113,21 @@ var testHtml = function(valueObj) {
QUnit.reset(); QUnit.reset();
jQuery("#main").html(valueObj('<script type="something/else">ok( false, "Non-script evaluated." );</script><script type="text/javascript">ok( true, "text/javascript is evaluated." );</script><script>ok( true, "No type is evaluated." );</script><div><script type="text/javascript">ok( true, "Inner text/javascript is evaluated." );</script><script>ok( true, "Inner No type is evaluated." );</script><script type="something/else">ok( false, "Non-script evaluated." );</script></div>')); jQuery("#main").html(valueObj("<script type='something/else'>ok( false, 'Non-script evaluated.' );</script><script type='text/javascript'>ok( true, 'text/javascript is evaluated.' );</script><script>ok( true, 'No type is evaluated.' );</script><div><script type='text/javascript'>ok( true, 'Inner text/javascript is evaluated.' );</script><script>ok( true, 'Inner No type is evaluated.' );</script><script type='something/else'>ok( false, 'Non-script evaluated.' );</script></div>"));
var child = jQuery("#main").find("script");
equals( child.length, 2, "Make sure that two non-JavaScript script tags are left." );
equals( child[0].type, "something/else", "Verify type of script tag." );
equals( child[1].type, "something/else", "Verify type of script tag." );
jQuery("#main").html(valueObj("<script>ok( true, 'Test repeated injection of script.' );</script>")); jQuery("#main").html(valueObj("<script>ok( true, 'Test repeated injection of script.' );</script>"));
jQuery("#main").html(valueObj("<script>ok( true, 'Test repeated injection of script.' );</script>")); jQuery("#main").html(valueObj("<script>ok( true, 'Test repeated injection of script.' );</script>"));
jQuery("#main").html(valueObj("<script>ok( true, 'Test repeated injection of script.' );</script>")); jQuery("#main").html(valueObj("<script>ok( true, 'Test repeated injection of script.' );</script>"));
jQuery("#main").html(valueObj('<script type="text/javascript">ok( true, "jQuery().html().evalScripts() Evals Scripts Twice in Firefox, see #975 (1)" );</script>')); jQuery("#main").html(valueObj("<script type='text/javascript'>ok( true, 'jQuery().html().evalScripts() Evals Scripts Twice in Firefox, see #975 (1)' );</script>"));
jQuery("#main").html(valueObj('foo <form><script type="text/javascript">ok( true, "jQuery().html().evalScripts() Evals Scripts Twice in Firefox, see #975 (2)" );</script></form>')); jQuery("#main").html(valueObj("foo <form><script type='text/javascript'>ok( true, 'jQuery().html().evalScripts() Evals Scripts Twice in Firefox, see #975 (2)' );</script></form>"));
jQuery("#main").html(valueObj("<script>equals(jQuery.scriptorder++, 0, 'Script is executed in order');equals(jQuery('#scriptorder').length, 1,'Execute after html (even though appears before)')<\/script><span id='scriptorder'><script>equals(jQuery.scriptorder++, 1, 'Script (nested) is executed in order');equals(jQuery('#scriptorder').length, 1,'Execute after html')<\/script></span><script>equals(jQuery.scriptorder++, 2, 'Script (unnested) is executed in order');equals(jQuery('#scriptorder').length, 1,'Execute after html')<\/script>")); jQuery("#main").html(valueObj("<script>equals(jQuery.scriptorder++, 0, 'Script is executed in order');equals(jQuery('#scriptorder').length, 1,'Execute after html (even though appears before)')<\/script><span id='scriptorder'><script>equals(jQuery.scriptorder++, 1, 'Script (nested) is executed in order');equals(jQuery('#scriptorder').length, 1,'Execute after html')<\/script></span><script>equals(jQuery.scriptorder++, 2, 'Script (unnested) is executed in order');equals(jQuery('#scriptorder').length, 1,'Execute after html')<\/script>"));
} }
@ -1133,7 +1139,7 @@ test("html(String)", function() {
test("html(Function)", function() { test("html(Function)", function() {
testHtml(functionReturningObj); testHtml(functionReturningObj);
expect(33); expect(36);
QUnit.reset(); QUnit.reset();
@ -1178,22 +1184,22 @@ test("html(Function) with incoming value", function() {
equals( null, null, "Make sure the incoming value is correct." ); equals( null, null, "Make sure the incoming value is correct." );
} }
j.find('b').removeData(); j.find("b").removeData();
equals( j.html().replace(/ xmlns="[^"]+"/g, "").toLowerCase(), "<b>bold</b>", "Check node,textnode,comment with html()" ); equals( j.html().replace(/ xmlns="[^"]+"/g, "").toLowerCase(), "<b>bold</b>", "Check node,textnode,comment with html()" );
var $div = jQuery('<div />'); var $div = jQuery("<div />");
equals( $div.html(function(i, val) { equals( $div.html(function(i, val) {
equals( val, "", "Make sure the incoming value is correct." ); equals( val, "", "Make sure the incoming value is correct." );
return 5; return 5;
}).html(), '5', 'Setting a number as html' ); }).html(), "5", "Setting a number as html" );
equals( $div.html(function(i, val) { equals( $div.html(function(i, val) {
equals( val, "5", "Make sure the incoming value is correct." ); equals( val, "5", "Make sure the incoming value is correct." );
return 0; return 0;
}).html(), '0', 'Setting a zero as html' ); }).html(), "0", "Setting a zero as html" );
var $div2 = jQuery('<div/>'), insert = "&lt;div&gt;hello1&lt;/div&gt;"; var $div2 = jQuery("<div/>"), insert = "&lt;div&gt;hello1&lt;/div&gt;";
equals( $div2.html(function(i, val) { equals( $div2.html(function(i, val) {
equals( val, "", "Make sure the incoming value is correct." ); equals( val, "", "Make sure the incoming value is correct." );
return insert; return insert;
@ -1362,6 +1368,6 @@ test("jQuery.buildFragment - no plain-text caching (Bug #6779)", function() {
} }
catch(e) {} catch(e) {}
} }
equals($f.text(), bad.join(''), "Cached strings that match Object properties"); equals($f.text(), bad.join(""), "Cached strings that match Object properties");
$f.remove(); $f.remove();
}); });

View file

@ -20,7 +20,7 @@ testoffset("absolute"/* in iframe */, function($, iframe) {
// this insures that the results will be wrong // this insures that the results will be wrong
// if the offset method is using the scroll offset // if the offset method is using the scroll offset
// of the parent window // of the parent window
var forceScroll = jQuery('<div>', { width: 2000, height: 2000 }).appendTo('body'); var forceScroll = jQuery("<div>", { width: 2000, height: 2000 }).appendTo("body");
window.scrollTo(200, 200); window.scrollTo(200, 200);
if ( document.documentElement.scrollTop || document.body.scrollTop ) { if ( document.documentElement.scrollTop || document.body.scrollTop ) {
@ -31,7 +31,7 @@ testoffset("absolute"/* in iframe */, function($, iframe) {
// get offset // get offset
tests = [ tests = [
{ id: '#absolute-1', top: 1, left: 1 } { id: "#absolute-1", top: 1, left: 1 }
]; ];
jQuery.each( tests, function() { jQuery.each( tests, function() {
equals( jQuery( this.id, doc ).offset().top, this.top, "jQuery('" + this.id + "').offset().top" ); equals( jQuery( this.id, doc ).offset().top, this.top, "jQuery('" + this.id + "').offset().top" );
@ -41,7 +41,7 @@ testoffset("absolute"/* in iframe */, function($, iframe) {
// get position // get position
tests = [ tests = [
{ id: '#absolute-1', top: 0, left: 0 } { id: "#absolute-1", top: 0, left: 0 }
]; ];
jQuery.each( tests, function() { jQuery.each( tests, function() {
equals( jQuery( this.id, doc ).position().top, this.top, "jQuery('" + this.id + "').position().top" ); equals( jQuery( this.id, doc ).position().top, this.top, "jQuery('" + this.id + "').position().top" );
@ -56,10 +56,10 @@ testoffset("absolute", function( jQuery ) {
// get offset tests // get offset tests
var tests = [ var tests = [
{ id: '#absolute-1', top: 1, left: 1 }, { id: "#absolute-1", top: 1, left: 1 },
{ id: '#absolute-1-1', top: 5, left: 5 }, { id: "#absolute-1-1", top: 5, left: 5 },
{ id: '#absolute-1-1-1', top: 9, left: 9 }, { id: "#absolute-1-1-1", top: 9, left: 9 },
{ id: '#absolute-2', top: 20, left: 20 } { id: "#absolute-2", top: 20, left: 20 }
]; ];
jQuery.each( tests, function() { jQuery.each( tests, function() {
equals( jQuery( this.id ).offset().top, this.top, "jQuery('" + this.id + "').offset().top" ); equals( jQuery( this.id ).offset().top, this.top, "jQuery('" + this.id + "').offset().top" );
@ -69,10 +69,10 @@ testoffset("absolute", function( jQuery ) {
// get position // get position
tests = [ tests = [
{ id: '#absolute-1', top: 0, left: 0 }, { id: "#absolute-1", top: 0, left: 0 },
{ id: '#absolute-1-1', top: 1, left: 1 }, { id: "#absolute-1-1", top: 1, left: 1 },
{ id: '#absolute-1-1-1', top: 1, left: 1 }, { id: "#absolute-1-1-1", top: 1, left: 1 },
{ id: '#absolute-2', top: 19, left: 19 } { id: "#absolute-2", top: 19, left: 19 }
]; ];
jQuery.each( tests, function() { jQuery.each( tests, function() {
equals( jQuery( this.id ).position().top, this.top, "jQuery('" + this.id + "').position().top" ); equals( jQuery( this.id ).position().top, this.top, "jQuery('" + this.id + "').position().top" );
@ -80,29 +80,29 @@ testoffset("absolute", function( jQuery ) {
}); });
// test #5781 // test #5781
var offset = jQuery( '#positionTest' ).offset({ top: 10, left: 10 }).offset(); var offset = jQuery( "#positionTest" ).offset({ top: 10, left: 10 }).offset();
equals( offset.top, 10, "Setting offset on element with position absolute but 'auto' values." ) equals( offset.top, 10, "Setting offset on element with position absolute but 'auto' values." )
equals( offset.left, 10, "Setting offset on element with position absolute but 'auto' values." ) equals( offset.left, 10, "Setting offset on element with position absolute but 'auto' values." )
// set offset // set offset
tests = [ tests = [
{ id: '#absolute-2', top: 30, left: 30 }, { id: "#absolute-2", top: 30, left: 30 },
{ id: '#absolute-2', top: 10, left: 10 }, { id: "#absolute-2", top: 10, left: 10 },
{ id: '#absolute-2', top: -1, left: -1 }, { id: "#absolute-2", top: -1, left: -1 },
{ id: '#absolute-2', top: 19, left: 19 }, { id: "#absolute-2", top: 19, left: 19 },
{ id: '#absolute-1-1-1', top: 15, left: 15 }, { id: "#absolute-1-1-1", top: 15, left: 15 },
{ id: '#absolute-1-1-1', top: 5, left: 5 }, { id: "#absolute-1-1-1", top: 5, left: 5 },
{ id: '#absolute-1-1-1', top: -1, left: -1 }, { id: "#absolute-1-1-1", top: -1, left: -1 },
{ id: '#absolute-1-1-1', top: 9, left: 9 }, { id: "#absolute-1-1-1", top: 9, left: 9 },
{ id: '#absolute-1-1', top: 10, left: 10 }, { id: "#absolute-1-1", top: 10, left: 10 },
{ id: '#absolute-1-1', top: 0, left: 0 }, { id: "#absolute-1-1", top: 0, left: 0 },
{ id: '#absolute-1-1', top: -1, left: -1 }, { id: "#absolute-1-1", top: -1, left: -1 },
{ id: '#absolute-1-1', top: 5, left: 5 }, { id: "#absolute-1-1", top: 5, left: 5 },
{ id: '#absolute-1', top: 2, left: 2 }, { id: "#absolute-1", top: 2, left: 2 },
{ id: '#absolute-1', top: 0, left: 0 }, { id: "#absolute-1", top: 0, left: 0 },
{ id: '#absolute-1', top: -1, left: -1 }, { id: "#absolute-1", top: -1, left: -1 },
{ id: '#absolute-1', top: 1, left: 1 } { id: "#absolute-1", top: 1, left: 1 }
]; ];
jQuery.each( tests, function() { jQuery.each( tests, function() {
jQuery( this.id ).offset({ top: this.top, left: this.left }); jQuery( this.id ).offset({ top: this.top, left: this.left });
@ -144,9 +144,9 @@ testoffset("relative", function( jQuery ) {
// get offset // get offset
var tests = [ var tests = [
{ id: '#relative-1', top: ie ? 6 : 7, left: 7 }, { id: "#relative-1", top: ie ? 6 : 7, left: 7 },
{ id: '#relative-1-1', top: ie ? 13 : 15, left: 15 }, { id: "#relative-1-1", top: ie ? 13 : 15, left: 15 },
{ id: '#relative-2', top: ie ? 141 : 142, left: 27 } { id: "#relative-2", top: ie ? 141 : 142, left: 27 }
]; ];
jQuery.each( tests, function() { jQuery.each( tests, function() {
equals( jQuery( this.id ).offset().top, this.top, "jQuery('" + this.id + "').offset().top" ); equals( jQuery( this.id ).offset().top, this.top, "jQuery('" + this.id + "').offset().top" );
@ -156,9 +156,9 @@ testoffset("relative", function( jQuery ) {
// get position // get position
tests = [ tests = [
{ id: '#relative-1', top: ie ? 5 : 6, left: 6 }, { id: "#relative-1", top: ie ? 5 : 6, left: 6 },
{ id: '#relative-1-1', top: ie ? 4 : 5, left: 5 }, { id: "#relative-1-1", top: ie ? 4 : 5, left: 5 },
{ id: '#relative-2', top: ie ? 140 : 141, left: 26 } { id: "#relative-2", top: ie ? 140 : 141, left: 26 }
]; ];
jQuery.each( tests, function() { jQuery.each( tests, function() {
equals( jQuery( this.id ).position().top, this.top, "jQuery('" + this.id + "').position().top" ); equals( jQuery( this.id ).position().top, this.top, "jQuery('" + this.id + "').position().top" );
@ -168,18 +168,18 @@ testoffset("relative", function( jQuery ) {
// set offset // set offset
tests = [ tests = [
{ id: '#relative-2', top: 200, left: 50 }, { id: "#relative-2", top: 200, left: 50 },
{ id: '#relative-2', top: 100, left: 10 }, { id: "#relative-2", top: 100, left: 10 },
{ id: '#relative-2', top: -5, left: -5 }, { id: "#relative-2", top: -5, left: -5 },
{ id: '#relative-2', top: 142, left: 27 }, { id: "#relative-2", top: 142, left: 27 },
{ id: '#relative-1-1', top: 100, left: 100 }, { id: "#relative-1-1", top: 100, left: 100 },
{ id: '#relative-1-1', top: 5, left: 5 }, { id: "#relative-1-1", top: 5, left: 5 },
{ id: '#relative-1-1', top: -1, left: -1 }, { id: "#relative-1-1", top: -1, left: -1 },
{ id: '#relative-1-1', top: 15, left: 15 }, { id: "#relative-1-1", top: 15, left: 15 },
{ id: '#relative-1', top: 100, left: 100 }, { id: "#relative-1", top: 100, left: 100 },
{ id: '#relative-1', top: 0, left: 0 }, { id: "#relative-1", top: 0, left: 0 },
{ id: '#relative-1', top: -1, left: -1 }, { id: "#relative-1", top: -1, left: -1 },
{ id: '#relative-1', top: 7, left: 7 } { id: "#relative-1", top: 7, left: 7 }
]; ];
jQuery.each( tests, function() { jQuery.each( tests, function() {
jQuery( this.id ).offset({ top: this.top, left: this.left }); jQuery( this.id ).offset({ top: this.top, left: this.left });
@ -205,10 +205,10 @@ testoffset("static", function( jQuery ) {
// get offset // get offset
var tests = [ var tests = [
{ id: '#static-1', top: ie ? 6 : 7, left: 7 }, { id: "#static-1", top: ie ? 6 : 7, left: 7 },
{ id: '#static-1-1', top: ie ? 13 : 15, left: 15 }, { id: "#static-1-1", top: ie ? 13 : 15, left: 15 },
{ id: '#static-1-1-1', top: ie ? 20 : 23, left: 23 }, { id: "#static-1-1-1", top: ie ? 20 : 23, left: 23 },
{ id: '#static-2', top: ie ? 121 : 122, left: 7 } { id: "#static-2", top: ie ? 121 : 122, left: 7 }
]; ];
jQuery.each( tests, function() { jQuery.each( tests, function() {
equals( jQuery( this.id ).offset().top, this.top, "jQuery('" + this.id + "').offset().top" ); equals( jQuery( this.id ).offset().top, this.top, "jQuery('" + this.id + "').offset().top" );
@ -218,10 +218,10 @@ testoffset("static", function( jQuery ) {
// get position // get position
tests = [ tests = [
{ id: '#static-1', top: ie ? 5 : 6, left: 6 }, { id: "#static-1", top: ie ? 5 : 6, left: 6 },
{ id: '#static-1-1', top: ie ? 12 : 14, left: 14 }, { id: "#static-1-1", top: ie ? 12 : 14, left: 14 },
{ id: '#static-1-1-1', top: ie ? 19 : 22, left: 22 }, { id: "#static-1-1-1", top: ie ? 19 : 22, left: 22 },
{ id: '#static-2', top: ie ? 120 : 121, left: 6 } { id: "#static-2", top: ie ? 120 : 121, left: 6 }
]; ];
jQuery.each( tests, function() { jQuery.each( tests, function() {
equals( jQuery( this.id ).position().top, this.top, "jQuery('" + this.top + "').position().top" ); equals( jQuery( this.id ).position().top, this.top, "jQuery('" + this.top + "').position().top" );
@ -231,22 +231,22 @@ testoffset("static", function( jQuery ) {
// set offset // set offset
tests = [ tests = [
{ id: '#static-2', top: 200, left: 200 }, { id: "#static-2", top: 200, left: 200 },
{ id: '#static-2', top: 100, left: 100 }, { id: "#static-2", top: 100, left: 100 },
{ id: '#static-2', top: -2, left: -2 }, { id: "#static-2", top: -2, left: -2 },
{ id: '#static-2', top: 121, left: 6 }, { id: "#static-2", top: 121, left: 6 },
{ id: '#static-1-1-1', top: 50, left: 50 }, { id: "#static-1-1-1", top: 50, left: 50 },
{ id: '#static-1-1-1', top: 10, left: 10 }, { id: "#static-1-1-1", top: 10, left: 10 },
{ id: '#static-1-1-1', top: -1, left: -1 }, { id: "#static-1-1-1", top: -1, left: -1 },
{ id: '#static-1-1-1', top: 22, left: 22 }, { id: "#static-1-1-1", top: 22, left: 22 },
{ id: '#static-1-1', top: 25, left: 25 }, { id: "#static-1-1", top: 25, left: 25 },
{ id: '#static-1-1', top: 10, left: 10 }, { id: "#static-1-1", top: 10, left: 10 },
{ id: '#static-1-1', top: -3, left: -3 }, { id: "#static-1-1", top: -3, left: -3 },
{ id: '#static-1-1', top: 14, left: 14 }, { id: "#static-1-1", top: 14, left: 14 },
{ id: '#static-1', top: 30, left: 30 }, { id: "#static-1", top: 30, left: 30 },
{ id: '#static-1', top: 2, left: 2 }, { id: "#static-1", top: 2, left: 2 },
{ id: '#static-1', top: -2, left: -2 }, { id: "#static-1", top: -2, left: -2 },
{ id: '#static-1', top: 7, left: 7 } { id: "#static-1", top: 7, left: 7 }
]; ];
jQuery.each( tests, function() { jQuery.each( tests, function() {
jQuery( this.id ).offset({ top: this.top, left: this.left }); jQuery( this.id ).offset({ top: this.top, left: this.left });
@ -270,8 +270,8 @@ testoffset("fixed", function( jQuery ) {
jQuery.offset.initialize(); jQuery.offset.initialize();
var tests = [ var tests = [
{ id: '#fixed-1', top: 1001, left: 1001 }, { id: "#fixed-1", top: 1001, left: 1001 },
{ id: '#fixed-2', top: 1021, left: 1021 } { id: "#fixed-2", top: 1021, left: 1021 }
]; ];
jQuery.each( tests, function() { jQuery.each( tests, function() {
@ -284,18 +284,18 @@ testoffset("fixed", function( jQuery ) {
equals( jQuery( this.id ).offset().left, this.left, "jQuery('" + this.id + "').offset().left" ); equals( jQuery( this.id ).offset().left, this.left, "jQuery('" + this.id + "').offset().left" );
} else { } else {
// need to have same number of assertions // need to have same number of assertions
ok( true, 'Fixed position is not supported' ); ok( true, "Fixed position is not supported" );
ok( true, 'Fixed position is not supported' ); ok( true, "Fixed position is not supported" );
} }
}); });
tests = [ tests = [
{ id: '#fixed-1', top: 100, left: 100 }, { id: "#fixed-1", top: 100, left: 100 },
{ id: '#fixed-1', top: 0, left: 0 }, { id: "#fixed-1", top: 0, left: 0 },
{ id: '#fixed-1', top: -4, left: -4 }, { id: "#fixed-1", top: -4, left: -4 },
{ id: '#fixed-2', top: 200, left: 200 }, { id: "#fixed-2", top: 200, left: 200 },
{ id: '#fixed-2', top: 0, left: 0 }, { id: "#fixed-2", top: 0, left: 0 },
{ id: '#fixed-2', top: -5, left: -5 } { id: "#fixed-2", top: -5, left: -5 }
]; ];
jQuery.each( tests, function() { jQuery.each( tests, function() {
@ -314,58 +314,58 @@ testoffset("fixed", function( jQuery ) {
equals( jQuery( this.id ).offset().left, this.left + 1, "jQuery('" + this.id + "').offset({ left: " + (this.left + 1) + ", using: fn })" ); equals( jQuery( this.id ).offset().left, this.left + 1, "jQuery('" + this.id + "').offset({ left: " + (this.left + 1) + ", using: fn })" );
} else { } else {
// need to have same number of assertions // need to have same number of assertions
ok( true, 'Fixed position is not supported' ); ok( true, "Fixed position is not supported" );
ok( true, 'Fixed position is not supported' ); ok( true, "Fixed position is not supported" );
ok( true, 'Fixed position is not supported' ); ok( true, "Fixed position is not supported" );
ok( true, 'Fixed position is not supported' ); ok( true, "Fixed position is not supported" );
} }
}); });
// Bug 8316 // Bug 8316
var $noTopLeft = jQuery('#fixed-no-top-left'); var $noTopLeft = jQuery("#fixed-no-top-left");
if ( jQuery.offset.supportsFixedPosition ) { if ( jQuery.offset.supportsFixedPosition ) {
equals( $noTopLeft.offset().top, 1007, "Check offset top for fixed element with no top set" ); equals( $noTopLeft.offset().top, 1007, "Check offset top for fixed element with no top set" );
equals( $noTopLeft.offset().left, 1007, "Check offset left for fixed element with no left set" ); equals( $noTopLeft.offset().left, 1007, "Check offset left for fixed element with no left set" );
} else { } else {
// need to have same number of assertions // need to have same number of assertions
ok( true, 'Fixed position is not supported' ); ok( true, "Fixed position is not supported" );
ok( true, 'Fixed position is not supported' ); ok( true, "Fixed position is not supported" );
} }
}); });
testoffset("table", function( jQuery ) { testoffset("table", function( jQuery ) {
expect(4); expect(4);
equals( jQuery('#table-1').offset().top, 6, "jQuery('#table-1').offset().top" ); equals( jQuery("#table-1").offset().top, 6, "jQuery('#table-1').offset().top" );
equals( jQuery('#table-1').offset().left, 6, "jQuery('#table-1').offset().left" ); equals( jQuery("#table-1").offset().left, 6, "jQuery('#table-1').offset().left" );
equals( jQuery('#th-1').offset().top, 10, "jQuery('#th-1').offset().top" ); equals( jQuery("#th-1").offset().top, 10, "jQuery('#th-1').offset().top" );
equals( jQuery('#th-1').offset().left, 10, "jQuery('#th-1').offset().left" ); equals( jQuery("#th-1").offset().left, 10, "jQuery('#th-1').offset().left" );
}); });
testoffset("scroll", function( jQuery, win ) { testoffset("scroll", function( jQuery, win ) {
expect(16); expect(22);
var ie = jQuery.browser.msie && parseInt( jQuery.browser.version, 10 ) < 8; var ie = jQuery.browser.msie && parseInt( jQuery.browser.version, 10 ) < 8;
// IE is collapsing the top margin of 1px // IE is collapsing the top margin of 1px
equals( jQuery('#scroll-1').offset().top, ie ? 6 : 7, "jQuery('#scroll-1').offset().top" ); equals( jQuery("#scroll-1").offset().top, ie ? 6 : 7, "jQuery('#scroll-1').offset().top" );
equals( jQuery('#scroll-1').offset().left, 7, "jQuery('#scroll-1').offset().left" ); equals( jQuery("#scroll-1").offset().left, 7, "jQuery('#scroll-1').offset().left" );
// IE is collapsing the top margin of 1px // IE is collapsing the top margin of 1px
equals( jQuery('#scroll-1-1').offset().top, ie ? 9 : 11, "jQuery('#scroll-1-1').offset().top" ); equals( jQuery("#scroll-1-1").offset().top, ie ? 9 : 11, "jQuery('#scroll-1-1').offset().top" );
equals( jQuery('#scroll-1-1').offset().left, 11, "jQuery('#scroll-1-1').offset().left" ); equals( jQuery("#scroll-1-1").offset().left, 11, "jQuery('#scroll-1-1').offset().left" );
// scroll offset tests .scrollTop/Left // scroll offset tests .scrollTop/Left
equals( jQuery('#scroll-1').scrollTop(), 5, "jQuery('#scroll-1').scrollTop()" ); equals( jQuery("#scroll-1").scrollTop(), 5, "jQuery('#scroll-1').scrollTop()" );
equals( jQuery('#scroll-1').scrollLeft(), 5, "jQuery('#scroll-1').scrollLeft()" ); equals( jQuery("#scroll-1").scrollLeft(), 5, "jQuery('#scroll-1').scrollLeft()" );
equals( jQuery('#scroll-1-1').scrollTop(), 0, "jQuery('#scroll-1-1').scrollTop()" ); equals( jQuery("#scroll-1-1").scrollTop(), 0, "jQuery('#scroll-1-1').scrollTop()" );
equals( jQuery('#scroll-1-1').scrollLeft(), 0, "jQuery('#scroll-1-1').scrollLeft()" ); equals( jQuery("#scroll-1-1").scrollLeft(), 0, "jQuery('#scroll-1-1').scrollLeft()" );
// equals( jQuery('body').scrollTop(), 0, "jQuery('body').scrollTop()" ); // equals( jQuery("body").scrollTop(), 0, "jQuery("body").scrollTop()" );
// equals( jQuery('body').scrollLeft(), 0, "jQuery('body').scrollTop()" ); // equals( jQuery("body").scrollLeft(), 0, "jQuery("body").scrollTop()" );
win.name = "test"; win.name = "test";
@ -390,13 +390,21 @@ testoffset("scroll", function( jQuery, win ) {
equals( jQuery(window).scrollLeft(), 0, "jQuery(window).scrollLeft() other window" ); equals( jQuery(window).scrollLeft(), 0, "jQuery(window).scrollLeft() other window" );
equals( jQuery(document).scrollTop(), 0, "jQuery(window).scrollTop() other document" ); equals( jQuery(document).scrollTop(), 0, "jQuery(window).scrollTop() other document" );
equals( jQuery(document).scrollLeft(), 0, "jQuery(window).scrollLeft() other document" ); equals( jQuery(document).scrollLeft(), 0, "jQuery(window).scrollLeft() other document" );
// Tests scrollTop/Left with empty jquery objects
notEqual( jQuery().scrollTop(100), null, "jQuery().scrollTop(100) testing setter on empty jquery object" );
notEqual( jQuery().scrollLeft(100), null, "jQuery().scrollLeft(100) testing setter on empty jquery object" );
notEqual( jQuery().scrollTop(null), null, "jQuery().scrollTop(null) testing setter on empty jquery object" );
notEqual( jQuery().scrollLeft(null), null, "jQuery().scrollLeft(null) testing setter on empty jquery object" );
strictEqual( jQuery().scrollTop(), null, "jQuery().scrollTop(100) testing setter on empty jquery object" );
strictEqual( jQuery().scrollLeft(), null, "jQuery().scrollLeft(100) testing setter on empty jquery object" );
}); });
testoffset("body", function( jQuery ) { testoffset("body", function( jQuery ) {
expect(2); expect(2);
equals( jQuery('body').offset().top, 1, "jQuery('#body').offset().top" ); equals( jQuery("body").offset().top, 1, "jQuery('#body').offset().top" );
equals( jQuery('body').offset().left, 1, "jQuery('#body').offset().left" ); equals( jQuery("body").offset().left, 1, "jQuery('#body').offset().left" );
}); });
test("Chaining offset(coords) returns jQuery object", function() { test("Chaining offset(coords) returns jQuery object", function() {
@ -433,7 +441,33 @@ test("offsetParent", function(){
equals( div[1], jQuery("#nothiddendiv")[0], "The div is the offsetParent." ); equals( div[1], jQuery("#nothiddendiv")[0], "The div is the offsetParent." );
}); });
function testoffset( name, fn ) { test("fractions (see #7730 and #7885)", function() {
expect(2);
jQuery('body').append('<div id="fractions"/>');
var expected = { top: 1000, left: 1000 };
var div = jQuery('#fractions');
div.css({
position: 'absolute',
left: '1000.7432222px',
top: '1000.532325px',
width: 100,
height: 100
});
div.offset(expected);
var result = div.offset();
equals( result.top, expected.top, "Check top" );
equals( result.left, expected.left, "Check left" );
div.remove();
});
function testoffset(name, fn) {
test(name, function() { test(name, function() {
// pause execution for now // pause execution for now
@ -456,10 +490,10 @@ function testoffset( name, fn ) {
}); });
function loadFixture() { function loadFixture() {
var src = './data/offset/' + name + '.html?' + parseInt( Math.random()*1000, 10 ), var src = "./data/offset/" + name + ".html?" + parseInt( Math.random()*1000, 10 ),
iframe = jQuery('<iframe />').css({ iframe = jQuery("<iframe />").css({
width: 500, height: 500, position: 'absolute', top: -600, left: -600, visibility: 'hidden' width: 500, height: 500, position: "absolute", top: -600, left: -600, visibility: "hidden"
}).appendTo('body')[0]; }).appendTo("body")[0];
iframe.contentWindow.location = src; iframe.contentWindow.location = src;
return iframe; return iframe;
} }

View file

@ -1,38 +1,50 @@
module("queue", { teardown: moduleTeardown }); module("queue", { teardown: moduleTeardown });
test("queue() with other types",function() { test("queue() with other types",function() {
expect(9); expect(11);
var counter = 0; var counter = 0;
var $div = jQuery({}); stop();
var $div = jQuery({}),
defer;
$div.promise("foo").done(function() {
equals( counter, 0, "Deferred for collection with no queue is automatically resolved" );
});
$div $div
.queue('foo',function(){ .queue("foo",function(){
equals( ++counter, 1, "Dequeuing" ); equals( ++counter, 1, "Dequeuing" );
jQuery.dequeue(this,'foo'); jQuery.dequeue(this,"foo");
}) })
.queue('foo',function(){ .queue("foo",function(){
equals( ++counter, 2, "Dequeuing" ); equals( ++counter, 2, "Dequeuing" );
jQuery(this).dequeue('foo'); jQuery(this).dequeue("foo");
}) })
.queue('foo',function(){ .queue("foo",function(){
equals( ++counter, 3, "Dequeuing" ); equals( ++counter, 3, "Dequeuing" );
}) })
.queue('foo',function(){ .queue("foo",function(){
equals( ++counter, 4, "Dequeuing" ); equals( ++counter, 4, "Dequeuing" );
}); });
equals( $div.queue('foo').length, 4, "Testing queue length" ); defer = $div.promise("foo").done(function() {
equals( counter, 4, "Testing previous call to dequeue in deferred" );
start();
});
$div.dequeue('foo'); equals( $div.queue("foo").length, 4, "Testing queue length" );
$div.dequeue("foo");
equals( counter, 3, "Testing previous call to dequeue" ); equals( counter, 3, "Testing previous call to dequeue" );
equals( $div.queue('foo').length, 1, "Testing queue length" ); equals( $div.queue("foo").length, 1, "Testing queue length" );
$div.dequeue('foo'); $div.dequeue("foo");
equals( counter, 4, "Testing previous call to dequeue" ); equals( counter, 4, "Testing previous call to dequeue" );
equals( $div.queue('foo').length, 0, "Testing queue length" ); equals( $div.queue("foo").length, 0, "Testing queue length" );
}); });
test("queue(name) passes in the next item in the queue as a parameter", function() { test("queue(name) passes in the next item in the queue as a parameter", function() {
@ -74,7 +86,7 @@ test("queue(name) passes in the next item in the queue as a parameter", function
}); });
test("queue() passes in the next item in the queue as a parameter to fx queues", function() { test("queue() passes in the next item in the queue as a parameter to fx queues", function() {
expect(2); expect(3);
stop(); stop();
var div = jQuery({}); var div = jQuery({});
@ -87,11 +99,15 @@ test("queue() passes in the next item in the queue as a parameter to fx queues",
}).queue(function(next) { }).queue(function(next) {
equals(++counter, 2, "Next was called"); equals(++counter, 2, "Next was called");
next(); next();
start();
}).queue("bar", function() { }).queue("bar", function() {
equals(++counter, 3, "Other queues are not triggered by next()") equals(++counter, 3, "Other queues are not triggered by next()")
}); });
jQuery.when( div.promise("fx"), div ).done(function() {
equals(counter, 2, "Deferreds resolved");
start();
});
}); });
test("delay()", function() { test("delay()", function() {
@ -110,7 +126,9 @@ test("delay()", function() {
}); });
test("clearQueue(name) clears the queue", function() { test("clearQueue(name) clears the queue", function() {
expect(1); expect(2);
stop()
var div = jQuery({}); var div = jQuery({});
var counter = 0; var counter = 0;
@ -123,6 +141,11 @@ test("clearQueue(name) clears the queue", function() {
counter++; counter++;
}); });
div.promise("foo").done(function() {
ok( true, "dequeue resolves the deferred" );
start();
});
div.dequeue("foo"); div.dequeue("foo");
equals(counter, 1, "the queue was cleared"); equals(counter, 1, "the queue was cleared");
@ -146,3 +169,81 @@ test("clearQueue() clears the fx queue", function() {
div.removeData(); div.removeData();
}); });
test("_mark() and _unmark()", function() {
expect(1);
var div = {},
$div = jQuery( div );
stop();
jQuery._mark( div, "foo" );
jQuery._mark( div, "foo" );
jQuery._unmark( div, "foo" );
jQuery._unmark( div, "foo" );
$div.promise( "foo" ).done(function() {
ok( true, "No more marks" );
start();
});
});
test("_mark() and _unmark() default to 'fx'", function() {
expect(1);
var div = {},
$div = jQuery( div );
stop();
jQuery._mark( div );
jQuery._mark( div );
jQuery._unmark( div, "fx" );
jQuery._unmark( div );
$div.promise().done(function() {
ok( true, "No more marks" );
start();
});
});
test("promise()", function() {
expect(1);
stop();
var objects = [];
jQuery.each( [{}, {}], function( i, div ) {
var $div = jQuery( div );
$div.queue(function( next ) {
setTimeout( function() {
if ( i ) {
next();
setTimeout( function() {
jQuery._unmark( div );
}, 20 );
} else {
jQuery._unmark( div );
setTimeout( function() {
next();
}, 20 );
}
}, 50 );
}).queue(function( next ) {
next();
});
jQuery._mark( div );
objects.push( $div );
});
jQuery.when.apply( jQuery, objects ).done(function() {
ok( true, "Deferred resolved" );
start();
});
jQuery.each( objects, function() {
this.dequeue();
});
});

View file

@ -2,7 +2,7 @@ module("traversing", { teardown: moduleTeardown });
test("find(String)", function() { test("find(String)", function() {
expect(5); expect(5);
equals( 'Yahoo', jQuery('#foo').find('.blogTest').text(), 'Check for find' ); equals( "Yahoo", jQuery("#foo").find(".blogTest").text(), "Check for find" );
// using contents will get comments regular, text, and comment nodes // using contents will get comments regular, text, and comment nodes
var j = jQuery("#nonnodes").contents(); var j = jQuery("#nonnodes").contents();
@ -16,89 +16,86 @@ test("find(String)", function() {
test("find(node|jQuery object)", function() { test("find(node|jQuery object)", function() {
expect( 11 ); expect( 11 );
var $foo = jQuery('#foo'), var $foo = jQuery("#foo"),
$blog = jQuery('.blogTest'), $blog = jQuery(".blogTest"),
$first = jQuery('#first'), $first = jQuery("#first"),
$two = $blog.add( $first ), $two = $blog.add( $first ),
$fooTwo = $foo.add( $blog ); $fooTwo = $foo.add( $blog );
equals( $foo.find( $blog ).text(), 'Yahoo', 'Find with blog jQuery object' ); equals( $foo.find( $blog ).text(), "Yahoo", "Find with blog jQuery object" );
equals( $foo.find( $blog[0] ).text(), 'Yahoo', 'Find with blog node' ); equals( $foo.find( $blog[0] ).text(), "Yahoo", "Find with blog node" );
equals( $foo.find( $first ).length, 0, '#first is not in #foo' ); equals( $foo.find( $first ).length, 0, "#first is not in #foo" );
equals( $foo.find( $first[0]).length, 0, '#first not in #foo (node)' ); equals( $foo.find( $first[0]).length, 0, "#first not in #foo (node)" );
ok( $foo.find( $two ).is('.blogTest'), 'Find returns only nodes within #foo' ); ok( $foo.find( $two ).is(".blogTest"), "Find returns only nodes within #foo" );
ok( $fooTwo.find( $blog ).is('.blogTest'), 'Blog is part of the collection, but also within foo' ); ok( $fooTwo.find( $blog ).is(".blogTest"), "Blog is part of the collection, but also within foo" );
ok( $fooTwo.find( $blog[0] ).is('.blogTest'), 'Blog is part of the collection, but also within foo(node)' ); ok( $fooTwo.find( $blog[0] ).is(".blogTest"), "Blog is part of the collection, but also within foo(node)" );
equals( $two.find( $foo ).length, 0, 'Foo is not in two elements' ); equals( $two.find( $foo ).length, 0, "Foo is not in two elements" );
equals( $two.find( $foo[0] ).length, 0, 'Foo is not in two elements(node)' ); equals( $two.find( $foo[0] ).length, 0, "Foo is not in two elements(node)" );
equals( $two.find( $first ).length, 0, 'first is in the collection and not within two' ); equals( $two.find( $first ).length, 0, "first is in the collection and not within two" );
equals( $two.find( $first ).length, 0, 'first is in the collection and not within two(node)' ); equals( $two.find( $first ).length, 0, "first is in the collection and not within two(node)" );
}); });
test("is(String|undefined)", function() { test("is(String|undefined)", function() {
expect(27); expect(27);
ok( jQuery('#form').is('form'), 'Check for element: A form must be a form' ); ok( jQuery("#form").is("form"), "Check for element: A form must be a form" );
ok( !jQuery('#form').is('div'), 'Check for element: A form is not a div' ); ok( !jQuery("#form").is("div"), "Check for element: A form is not a div" );
ok( jQuery('#mark').is('.blog'), 'Check for class: Expected class "blog"' ); ok( jQuery("#mark").is(".blog"), "Check for class: Expected class 'blog'" );
ok( !jQuery('#mark').is('.link'), 'Check for class: Did not expect class "link"' ); ok( !jQuery("#mark").is(".link"), "Check for class: Did not expect class 'link'" );
ok( jQuery('#simon').is('.blog.link'), 'Check for multiple classes: Expected classes "blog" and "link"' ); ok( jQuery("#simon").is(".blog.link"), "Check for multiple classes: Expected classes 'blog' and 'link'" );
ok( !jQuery('#simon').is('.blogTest'), 'Check for multiple classes: Expected classes "blog" and "link", but not "blogTest"' ); ok( !jQuery("#simon").is(".blogTest"), "Check for multiple classes: Expected classes 'blog' and 'link', but not 'blogTest'" );
ok( jQuery('#en').is('[lang="en"]'), 'Check for attribute: Expected attribute lang to be "en"' ); ok( jQuery("#en").is("[lang=\"en\"]"), "Check for attribute: Expected attribute lang to be 'en'" );
ok( !jQuery('#en').is('[lang="de"]'), 'Check for attribute: Expected attribute lang to be "en", not "de"' ); ok( !jQuery("#en").is("[lang=\"de\"]"), "Check for attribute: Expected attribute lang to be 'en', not 'de'" );
ok( jQuery('#text1').is('[type="text"]'), 'Check for attribute: Expected attribute type to be "text"' ); ok( jQuery("#text1").is("[type=\"text\"]"), "Check for attribute: Expected attribute type to be 'text'" );
ok( !jQuery('#text1').is('[type="radio"]'), 'Check for attribute: Expected attribute type to be "text", not "radio"' ); ok( !jQuery("#text1").is("[type=\"radio\"]"), "Check for attribute: Expected attribute type to be 'text', not 'radio'" );
ok( jQuery('#text2').is(':disabled'), 'Check for pseudoclass: Expected to be disabled' ); ok( jQuery("#text2").is(":disabled"), "Check for pseudoclass: Expected to be disabled" );
ok( !jQuery('#text1').is(':disabled'), 'Check for pseudoclass: Expected not disabled' ); ok( !jQuery("#text1").is(":disabled"), "Check for pseudoclass: Expected not disabled" );
ok( jQuery('#radio2').is(':checked'), 'Check for pseudoclass: Expected to be checked' ); ok( jQuery("#radio2").is(":checked"), "Check for pseudoclass: Expected to be checked" );
ok( !jQuery('#radio1').is(':checked'), 'Check for pseudoclass: Expected not checked' ); ok( !jQuery("#radio1").is(":checked"), "Check for pseudoclass: Expected not checked" );
ok( jQuery('#foo').is(':has(p)'), 'Check for child: Expected a child "p" element' ); ok( jQuery("#foo").is(":has(p)"), "Check for child: Expected a child 'p' element" );
ok( !jQuery('#foo').is(':has(ul)'), 'Check for child: Did not expect "ul" element' ); ok( !jQuery("#foo").is(":has(ul)"), "Check for child: Did not expect 'ul' element" );
ok( jQuery('#foo').is(':has(p):has(a):has(code)'), 'Check for childs: Expected "p", "a" and "code" child elements' ); ok( jQuery("#foo").is(":has(p):has(a):has(code)"), "Check for childs: Expected 'p', 'a' and 'code' child elements" );
ok( !jQuery('#foo').is(':has(p):has(a):has(code):has(ol)'), 'Check for childs: Expected "p", "a" and "code" child elements, but no "ol"' ); ok( !jQuery("#foo").is(":has(p):has(a):has(code):has(ol)"), "Check for childs: Expected 'p', 'a' and 'code' child elements, but no 'ol'" );
ok( !jQuery('#foo').is(0), 'Expected false for an invalid expression - 0' ); ok( !jQuery("#foo").is(0), "Expected false for an invalid expression - 0" );
ok( !jQuery('#foo').is(null), 'Expected false for an invalid expression - null' ); ok( !jQuery("#foo").is(null), "Expected false for an invalid expression - null" );
ok( !jQuery('#foo').is(''), 'Expected false for an invalid expression - ""' ); ok( !jQuery("#foo").is(""), "Expected false for an invalid expression - \"\"" );
ok( !jQuery('#foo').is(undefined), 'Expected false for an invalid expression - undefined' ); ok( !jQuery("#foo").is(undefined), "Expected false for an invalid expression - undefined" );
ok( !jQuery('#foo').is({ plain: "object" }), 'Check passing invalid object' ); ok( !jQuery("#foo").is({ plain: "object" }), "Check passing invalid object" );
// test is() with comma-seperated expressions // test is() with comma-seperated expressions
ok( jQuery('#en').is('[lang="en"],[lang="de"]'), 'Comma-seperated; Check for lang attribute: Expect en or de' ); ok( jQuery("#en").is("[lang=\"en\"],[lang=\"de\"]"), "Comma-seperated; Check for lang attribute: Expect en or de" );
ok( jQuery('#en').is('[lang="de"],[lang="en"]'), 'Comma-seperated; Check for lang attribute: Expect en or de' ); ok( jQuery("#en").is("[lang=\"de\"],[lang=\"en\"]"), "Comma-seperated; Check for lang attribute: Expect en or de" );
ok( jQuery('#en').is('[lang="en"] , [lang="de"]'), 'Comma-seperated; Check for lang attribute: Expect en or de' ); ok( jQuery("#en").is("[lang=\"en\"] , [lang=\"de\"]"), "Comma-seperated; Check for lang attribute: Expect en or de" );
ok( jQuery('#en').is('[lang="de"] , [lang="en"]'), 'Comma-seperated; Check for lang attribute: Expect en or de' ); ok( jQuery("#en").is("[lang=\"de\"] , [lang=\"en\"]"), "Comma-seperated; Check for lang attribute: Expect en or de" );
}); });
test("is(jQuery)", function() { test("is(jQuery)", function() {
expect(24); expect(21);
ok( jQuery('#form').is( jQuery('form') ), 'Check for element: A form is a form' ); ok( jQuery("#form").is( jQuery("form") ), "Check for element: A form is a form" );
ok( !jQuery('#form').is( jQuery('div') ), 'Check for element: A form is not a div' ); ok( !jQuery("#form").is( jQuery("div") ), "Check for element: A form is not a div" );
ok( jQuery('#mark').is( jQuery('.blog') ), 'Check for class: Expected class "blog"' ); ok( jQuery("#mark").is( jQuery(".blog") ), "Check for class: Expected class 'blog'" );
ok( !jQuery('#mark').is( jQuery('.link') ), 'Check for class: Did not expect class "link"' ); ok( !jQuery("#mark").is( jQuery(".link") ), "Check for class: Did not expect class 'link'" );
ok( jQuery('#simon').is( jQuery('.blog.link') ), 'Check for multiple classes: Expected classes "blog" and "link"' ); ok( jQuery("#simon").is( jQuery(".blog.link") ), "Check for multiple classes: Expected classes 'blog' and 'link'" );
ok( !jQuery('#simon').is( jQuery('.blogTest') ), 'Check for multiple classes: Expected classes "blog" and "link", but not "blogTest"' ); ok( !jQuery("#simon").is( jQuery(".blogTest") ), "Check for multiple classes: Expected classes 'blog' and 'link', but not 'blogTest'" );
ok( jQuery('#en').is( jQuery('[lang="en"]') ), 'Check for attribute: Expected attribute lang to be "en"' ); ok( jQuery("#en").is( jQuery("[lang=\"en\"]") ), "Check for attribute: Expected attribute lang to be 'en'" );
ok( !jQuery('#en').is( jQuery('[lang="de"]') ), 'Check for attribute: Expected attribute lang to be "en", not "de"' ); ok( !jQuery("#en").is( jQuery("[lang=\"de\"]") ), "Check for attribute: Expected attribute lang to be 'en', not 'de'" );
ok( jQuery('#text1').is( jQuery('[type="text"]') ), 'Check for attribute: Expected attribute type to be "text"' ); ok( jQuery("#text1").is( jQuery("[type=\"text\"]") ), "Check for attribute: Expected attribute type to be 'text'" );
ok( !jQuery('#text1').is( jQuery('[type="radio"]') ), 'Check for attribute: Expected attribute type to be "text", not "radio"' ); ok( !jQuery("#text1").is( jQuery("[type=\"radio\"]") ), "Check for attribute: Expected attribute type to be 'text', not 'radio'" );
ok( jQuery('#text2').is( jQuery(':disabled') ), 'Check for pseudoclass: Expected to be disabled' ); ok( !jQuery("#text1").is( jQuery("input:disabled") ), "Check for pseudoclass: Expected not disabled" );
ok( !jQuery('#text1').is( jQuery(':disabled') ), 'Check for pseudoclass: Expected not disabled' ); ok( jQuery("#radio2").is( jQuery("input:checked") ), "Check for pseudoclass: Expected to be checked" );
ok( jQuery('#radio2').is( jQuery(':checked') ), 'Check for pseudoclass: Expected to be checked' ); ok( !jQuery("#radio1").is( jQuery("input:checked") ), "Check for pseudoclass: Expected not checked" );
ok( !jQuery('#radio1').is( jQuery(':checked') ), 'Check for pseudoclass: Expected not checked' ); ok( jQuery("#foo").is( jQuery("div:has(p)") ), "Check for child: Expected a child 'p' element" );
ok( jQuery('#foo').is( jQuery(':has(p)') ), 'Check for child: Expected a child "p" element' ); ok( !jQuery("#foo").is( jQuery("div:has(ul)") ), "Check for child: Did not expect 'ul' element" );
ok( !jQuery('#foo').is( jQuery(':has(ul)') ), 'Check for child: Did not expect "ul" element' );
ok( jQuery('#foo').is( jQuery(':has(p):has(a):has(code)') ), 'Check for childs: Expected "p", "a" and "code" child elements' );
ok( !jQuery('#foo').is( jQuery(':has(p):has(a):has(code):has(ol)') ), 'Check for childs: Expected "p", "a" and "code" child elements, but no "ol"' );
// Some raw elements // Some raw elements
ok( jQuery('#form').is( jQuery('form')[0] ), 'Check for element: A form is a form' ); ok( jQuery("#form").is( jQuery("form")[0] ), "Check for element: A form is a form" );
ok( !jQuery('#form').is( jQuery('div')[0] ), 'Check for element: A form is not a div' ); ok( !jQuery("#form").is( jQuery("div")[0] ), "Check for element: A form is not a div" );
ok( jQuery('#mark').is( jQuery('.blog')[0] ), 'Check for class: Expected class "blog"' ); ok( jQuery("#mark").is( jQuery(".blog")[0] ), "Check for class: Expected class 'blog'" );
ok( !jQuery('#mark').is( jQuery('.link')[0] ), 'Check for class: Did not expect class "link"' ); ok( !jQuery("#mark").is( jQuery(".link")[0] ), "Check for class: Did not expect class 'link'" );
ok( jQuery('#simon').is( jQuery('.blog.link')[0] ), 'Check for multiple classes: Expected classes "blog" and "link"' ); ok( jQuery("#simon").is( jQuery(".blog.link")[0] ), "Check for multiple classes: Expected classes 'blog' and 'link'" );
ok( !jQuery('#simon').is( jQuery('.blogTest')[0] ), 'Check for multiple classes: Expected classes "blog" and "link", but not "blogTest"' ); ok( !jQuery("#simon").is( jQuery(".blogTest")[0] ), "Check for multiple classes: Expected classes 'blog' and 'link', but not 'blogTest'" );
}); });
test("index()", function() { test("index()", function() {
@ -111,15 +108,15 @@ test("index(Object|String|undefined)", function() {
expect(16); expect(16);
var elements = jQuery([window, document]), var elements = jQuery([window, document]),
inputElements = jQuery('#radio1,#radio2,#check1,#check2'); inputElements = jQuery("#radio1,#radio2,#check1,#check2");
// Passing a node // Passing a node
equals( elements.index(window), 0, "Check for index of elements" ); equals( elements.index(window), 0, "Check for index of elements" );
equals( elements.index(document), 1, "Check for index of elements" ); equals( elements.index(document), 1, "Check for index of elements" );
equals( inputElements.index(document.getElementById('radio1')), 0, "Check for index of elements" ); equals( inputElements.index(document.getElementById("radio1")), 0, "Check for index of elements" );
equals( inputElements.index(document.getElementById('radio2')), 1, "Check for index of elements" ); equals( inputElements.index(document.getElementById("radio2")), 1, "Check for index of elements" );
equals( inputElements.index(document.getElementById('check1')), 2, "Check for index of elements" ); equals( inputElements.index(document.getElementById("check1")), 2, "Check for index of elements" );
equals( inputElements.index(document.getElementById('check2')), 3, "Check for index of elements" ); equals( inputElements.index(document.getElementById("check2")), 3, "Check for index of elements" );
equals( inputElements.index(window), -1, "Check for not found index" ); equals( inputElements.index(window), -1, "Check for not found index" );
equals( inputElements.index(document), -1, "Check for not found index" ); equals( inputElements.index(document), -1, "Check for not found index" );
@ -131,11 +128,11 @@ test("index(Object|String|undefined)", function() {
// Passing a selector or nothing // Passing a selector or nothing
// enabled since [6330] // enabled since [6330]
equals( jQuery('#text2').index(), 2, "Check for index amongst siblings" ); equals( jQuery("#text2").index(), 2, "Check for index amongst siblings" );
equals( jQuery('#form').children().eq(4).index(), 4, "Check for index amongst siblings" ); equals( jQuery("#form").children().eq(4).index(), 4, "Check for index amongst siblings" );
equals( jQuery('#radio2').index('#form :radio') , 1, "Check for index within a selector" ); equals( jQuery("#radio2").index("#form :radio") , 1, "Check for index within a selector" );
equals( jQuery('#form :radio').index( jQuery('#radio2') ), 1, "Check for index within a selector" ); equals( jQuery("#form :radio").index( jQuery("#radio2") ), 1, "Check for index within a selector" );
equals( jQuery('#radio2').index('#form :text') , -1, "Check for index not found within a selector" ); equals( jQuery("#radio2").index("#form :text") , -1, "Check for index not found within a selector" );
}); });
test("filter(Selector|undefined)", function() { test("filter(Selector|undefined)", function() {
@ -144,10 +141,10 @@ test("filter(Selector|undefined)", function() {
same( jQuery("p").filter("#ap, #sndp").get(), q("ap", "sndp"), "filter('String, String')" ); same( jQuery("p").filter("#ap, #sndp").get(), q("ap", "sndp"), "filter('String, String')" );
same( jQuery("p").filter("#ap,#sndp").get(), q("ap", "sndp"), "filter('String,String')" ); same( jQuery("p").filter("#ap,#sndp").get(), q("ap", "sndp"), "filter('String,String')" );
same( jQuery('p').filter(null).get(), [], "filter(null) should return an empty jQuery object"); same( jQuery("p").filter(null).get(), [], "filter(null) should return an empty jQuery object");
same( jQuery('p').filter(undefined).get(), [], "filter(undefined) should return an empty jQuery object"); same( jQuery("p").filter(undefined).get(), [], "filter(undefined) should return an empty jQuery object");
same( jQuery('p').filter(0).get(), [], "filter(0) should return an empty jQuery object"); same( jQuery("p").filter(0).get(), [], "filter(0) should return an empty jQuery object");
same( jQuery('p').filter('').get(), [], "filter('') should return an empty jQuery object"); same( jQuery("p").filter("").get(), [], "filter('') should return an empty jQuery object");
// using contents will get comments regular, text, and comment nodes // using contents will get comments regular, text, and comment nodes
var j = jQuery("#nonnodes").contents(); var j = jQuery("#nonnodes").contents();
@ -201,14 +198,14 @@ test("closest()", function() {
same( jq.closest("#nothiddendiv", document.body).get(), q("nothiddendiv"), "Context not reached." ); same( jq.closest("#nothiddendiv", document.body).get(), q("nothiddendiv"), "Context not reached." );
//Test that .closest() returns unique'd set //Test that .closest() returns unique'd set
equals( jQuery('#main p').closest('#main').length, 1, "Closest should return a unique set" ); equals( jQuery("#main p").closest("#main").length, 1, "Closest should return a unique set" );
// Test on disconnected node // Test on disconnected node
equals( jQuery("<div><p></p></div>").find("p").closest("table").length, 0, "Make sure disconnected closest work." ); equals( jQuery("<div><p></p></div>").find("p").closest("table").length, 0, "Make sure disconnected closest work." );
// Bug #7369 // Bug #7369
equals( jQuery('<div foo="bar"></div>').closest('[foo]').length, 1, "Disconnected nodes with attribute selector" ); equals( jQuery("<div foo='bar'></div>").closest("[foo]").length, 1, "Disconnected nodes with attribute selector" );
equals( jQuery('<div>text</div>').closest('[lang]').length, 0, "Disconnected nodes with text and non-existent attribute selector" ); equals( jQuery("<div>text</div>").closest("[lang]").length, 0, "Disconnected nodes with text and non-existent attribute selector" );
}); });
test("closest(Array)", function() { test("closest(Array)", function() {
@ -223,43 +220,38 @@ test("closest(Array)", function() {
same( jQuery("body").closest(["span","html"]), [{selector:"html", elem:document.documentElement, level:2}], "closest([body, html])" ); same( jQuery("body").closest(["span","html"]), [{selector:"html", elem:document.documentElement, level:2}], "closest([body, html])" );
}); });
<<<<<<< HEAD
test("not(Selector|undefined)", function() {
expect(11);
=======
test("closest(jQuery)", function() { test("closest(jQuery)", function() {
expect(8); expect(8);
var $child = jQuery("#nothiddendivchild"), var $child = jQuery("#nothiddendivchild"),
$parent = jQuery("#nothiddendiv"), $parent = jQuery("#nothiddendiv"),
$main = jQuery("#main"), $main = jQuery("#main"),
$body = jQuery("body"); $body = jQuery("body");
ok( $child.closest( $parent ).is('#nothiddendiv'), "closest( jQuery('#nothiddendiv') )" ); ok( $child.closest( $parent ).is("#nothiddendiv"), "closest( jQuery('#nothiddendiv') )" );
ok( $child.closest( $parent[0] ).is('#nothiddendiv'), "closest( jQuery('#nothiddendiv') ) :: node" ); ok( $child.closest( $parent[0] ).is("#nothiddendiv"), "closest( jQuery('#nothiddendiv') ) :: node" );
ok( $child.closest( $child ).is('#nothiddendivchild'), "child is included" ); ok( $child.closest( $child ).is("#nothiddendivchild"), "child is included" );
ok( $child.closest( $child[0] ).is('#nothiddendivchild'), "child is included :: node" ); ok( $child.closest( $child[0] ).is("#nothiddendivchild"), "child is included :: node" );
equals( $child.closest( document.createElement('div') ).length, 0, "created element is not related" ); equals( $child.closest( document.createElement("div") ).length, 0, "created element is not related" );
equals( $child.closest( $main ).length, 0, "Main not a parent of child" ); equals( $child.closest( $main ).length, 0, "Main not a parent of child" );
equals( $child.closest( $main[0] ).length, 0, "Main not a parent of child :: node" ); equals( $child.closest( $main[0] ).length, 0, "Main not a parent of child :: node" );
ok( $child.closest( $body.add($parent) ).is('#nothiddendiv'), "Closest ancestor retrieved." ); ok( $child.closest( $body.add($parent) ).is("#nothiddendiv"), "Closest ancestor retrieved." );
}); });
test("not(Selector)", function() { test("not(Selector|undefined)", function() {
expect(7); expect(11);
>>>>>>> 1a167767305202797cf4c839eb64bd7adfb00182
equals( jQuery("#main > p#ap > a").not("#google").length, 2, "not('selector')" ); equals( jQuery("#main > p#ap > a").not("#google").length, 2, "not('selector')" );
same( jQuery("p").not(".result").get(), q("firstp", "ap", "sndp", "en", "sap", "first"), "not('.class')" ); same( jQuery("p").not(".result").get(), q("firstp", "ap", "sndp", "en", "sap", "first"), "not('.class')" );
same( jQuery("p").not("#ap, #sndp, .result").get(), q("firstp", "en", "sap", "first"), "not('selector, selector')" ); same( jQuery("p").not("#ap, #sndp, .result").get(), q("firstp", "en", "sap", "first"), "not('selector, selector')" );
same( jQuery("#form option").not("option.emptyopt:contains('Nothing'),[selected],[value='1']").get(), q("option1c", "option1d", "option2c", "option3d", "option3e", "option4e","option5b"), "not('complex selector')"); same( jQuery("#form option").not("option.emptyopt:contains('Nothing'),[selected],[value='1']").get(), q("option1c", "option1d", "option2c", "option3d", "option3e", "option4e","option5b"), "not('complex selector')");
same( jQuery('#ap *').not('code').get(), q("google", "groups", "anchor1", "mark"), "not('tag selector')" ); same( jQuery("#ap *").not("code").get(), q("google", "groups", "anchor1", "mark"), "not('tag selector')" );
same( jQuery('#ap *').not('code, #mark').get(), q("google", "groups", "anchor1"), "not('tag, ID selector')" ); same( jQuery("#ap *").not("code, #mark").get(), q("google", "groups", "anchor1"), "not('tag, ID selector')" );
same( jQuery('#ap *').not('#mark, code').get(), q("google", "groups", "anchor1"), "not('ID, tag selector')"); same( jQuery("#ap *").not("#mark, code").get(), q("google", "groups", "anchor1"), "not('ID, tag selector')");
var all = jQuery('p').get(); var all = jQuery("p").get();
same( jQuery('p').not(null).get(), all, "not(null) should have no effect"); same( jQuery("p").not(null).get(), all, "not(null) should have no effect");
same( jQuery('p').not(undefined).get(), all, "not(undefined) should have no effect"); same( jQuery("p").not(undefined).get(), all, "not(undefined) should have no effect");
same( jQuery('p').not(0).get(), all, "not(0) should have no effect"); same( jQuery("p").not(0).get(), all, "not(0) should have no effect");
same( jQuery('p').not('').get(), all, "not('') should have no effect"); same( jQuery("p").not("").get(), all, "not('') should have no effect");
}); });
test("not(Element)", function() { test("not(Element)", function() {
@ -372,7 +364,7 @@ test("parentsUntil([String])", function() {
same( jQuery("#groups").parentsUntil().get(), parents.get(), "parentsUntil with no selector (nextAll)" ); same( jQuery("#groups").parentsUntil().get(), parents.get(), "parentsUntil with no selector (nextAll)" );
same( jQuery("#groups").parentsUntil(".foo").get(), parents.get(), "parentsUntil with invalid selector (nextAll)" ); same( jQuery("#groups").parentsUntil(".foo").get(), parents.get(), "parentsUntil with invalid selector (nextAll)" );
same( jQuery("#groups").parentsUntil("#html").get(), parents.not(':last').get(), "Simple parentsUntil check" ); same( jQuery("#groups").parentsUntil("#html").get(), parents.not(":last").get(), "Simple parentsUntil check" );
equals( jQuery("#groups").parentsUntil("#ap").length, 0, "Simple parentsUntil check" ); equals( jQuery("#groups").parentsUntil("#ap").length, 0, "Simple parentsUntil check" );
same( jQuery("#groups").parentsUntil("#html, #body").get(), parents.slice( 0, 3 ).get(), "Less simple parentsUntil check" ); same( jQuery("#groups").parentsUntil("#html, #body").get(), parents.slice( 0, 3 ).get(), "Less simple parentsUntil check" );
same( jQuery("#groups").parentsUntil("#html", "div").get(), jQuery("#main").get(), "Filtered parentsUntil check" ); same( jQuery("#groups").parentsUntil("#html", "div").get(), jQuery("#main").get(), "Filtered parentsUntil check" );
@ -400,29 +392,29 @@ test("prev([String])", function() {
test("nextAll([String])", function() { test("nextAll([String])", function() {
expect(4); expect(4);
var elems = jQuery('#form').children(); var elems = jQuery("#form").children();
same( jQuery("#label-for").nextAll().get(), elems.not(':first').get(), "Simple nextAll check" ); same( jQuery("#label-for").nextAll().get(), elems.not(":first").get(), "Simple nextAll check" );
same( jQuery("#label-for").nextAll('input').get(), elems.not(':first').filter('input').get(), "Filtered nextAll check" ); same( jQuery("#label-for").nextAll("input").get(), elems.not(":first").filter("input").get(), "Filtered nextAll check" );
same( jQuery("#label-for").nextAll('input,select').get(), elems.not(':first').filter('input,select').get(), "Multiple-filtered nextAll check" ); same( jQuery("#label-for").nextAll("input,select").get(), elems.not(":first").filter("input,select").get(), "Multiple-filtered nextAll check" );
same( jQuery("#label-for, #hidden1").nextAll('input,select').get(), elems.not(':first').filter('input,select').get(), "Multi-source, multiple-filtered nextAll check" ); same( jQuery("#label-for, #hidden1").nextAll("input,select").get(), elems.not(":first").filter("input,select").get(), "Multi-source, multiple-filtered nextAll check" );
}); });
test("prevAll([String])", function() { test("prevAll([String])", function() {
expect(4); expect(4);
var elems = jQuery( jQuery('#form').children().slice(0, 12).get().reverse() ); var elems = jQuery( jQuery("#form").children().slice(0, 12).get().reverse() );
same( jQuery("#area1").prevAll().get(), elems.get(), "Simple prevAll check" ); same( jQuery("#area1").prevAll().get(), elems.get(), "Simple prevAll check" );
same( jQuery("#area1").prevAll('input').get(), elems.filter('input').get(), "Filtered prevAll check" ); same( jQuery("#area1").prevAll("input").get(), elems.filter("input").get(), "Filtered prevAll check" );
same( jQuery("#area1").prevAll('input,select').get(), elems.filter('input,select').get(), "Multiple-filtered prevAll check" ); same( jQuery("#area1").prevAll("input,select").get(), elems.filter("input,select").get(), "Multiple-filtered prevAll check" );
same( jQuery("#area1, #hidden1").prevAll('input,select').get(), elems.filter('input,select').get(), "Multi-source, multiple-filtered prevAll check" ); same( jQuery("#area1, #hidden1").prevAll("input,select").get(), elems.filter("input,select").get(), "Multi-source, multiple-filtered prevAll check" );
}); });
test("nextUntil([String])", function() { test("nextUntil([String])", function() {
expect(11); expect(11);
var elems = jQuery('#form').children().slice( 2, 12 ); var elems = jQuery("#form").children().slice( 2, 12 );
same( jQuery("#text1").nextUntil().get(), jQuery("#text1").nextAll().get(), "nextUntil with no selector (nextAll)" ); same( jQuery("#text1").nextUntil().get(), jQuery("#text1").nextAll().get(), "nextUntil with no selector (nextAll)" );
same( jQuery("#text1").nextUntil(".foo").get(), jQuery("#text1").nextAll().get(), "nextUntil with invalid selector (nextAll)" ); same( jQuery("#text1").nextUntil(".foo").get(), jQuery("#text1").nextAll().get(), "nextUntil with invalid selector (nextAll)" );
@ -445,14 +437,14 @@ test("prevUntil([String])", function() {
same( jQuery("#area1").prevUntil().get(), elems.get(), "prevUntil with no selector (prevAll)" ); same( jQuery("#area1").prevUntil().get(), elems.get(), "prevUntil with no selector (prevAll)" );
same( jQuery("#area1").prevUntil(".foo").get(), elems.get(), "prevUntil with invalid selector (prevAll)" ); same( jQuery("#area1").prevUntil(".foo").get(), elems.get(), "prevUntil with invalid selector (prevAll)" );
same( jQuery("#area1").prevUntil("label").get(), elems.not(':last').get(), "Simple prevUntil check" ); same( jQuery("#area1").prevUntil("label").get(), elems.not(":last").get(), "Simple prevUntil check" );
equals( jQuery("#area1").prevUntil("#button").length, 0, "Simple prevUntil check" ); equals( jQuery("#area1").prevUntil("#button").length, 0, "Simple prevUntil check" );
same( jQuery("#area1").prevUntil("label, #search").get(), jQuery("#area1").prev().get(), "Less simple prevUntil check" ); same( jQuery("#area1").prevUntil("label, #search").get(), jQuery("#area1").prev().get(), "Less simple prevUntil check" );
same( jQuery("#area1").prevUntil("label", "input").get(), elems.not(':last').not("button").get(), "Filtered prevUntil check" ); same( jQuery("#area1").prevUntil("label", "input").get(), elems.not(":last").not("button").get(), "Filtered prevUntil check" );
same( jQuery("#area1").prevUntil("label", "button").get(), elems.not(':last').not("input").get(), "Filtered prevUntil check" ); same( jQuery("#area1").prevUntil("label", "button").get(), elems.not(":last").not("input").get(), "Filtered prevUntil check" );
same( jQuery("#area1").prevUntil("label", "button,input").get(), elems.not(':last').get(), "Multiple-filtered prevUntil check" ); same( jQuery("#area1").prevUntil("label", "button,input").get(), elems.not(":last").get(), "Multiple-filtered prevUntil check" );
equals( jQuery("#area1").prevUntil("label", "div").length, 0, "Filtered prevUntil check, no match" ); equals( jQuery("#area1").prevUntil("label", "div").length, 0, "Filtered prevUntil check, no match" );
same( jQuery("#area1, #hidden1").prevUntil("label", "button,input").get(), elems.not(':last').get(), "Multi-source, multiple-filtered prevUntil check" ); same( jQuery("#area1, #hidden1").prevUntil("label", "button,input").get(), elems.not(":last").get(), "Multi-source, multiple-filtered prevUntil check" );
}); });
test("contents()", function() { test("contents()", function() {
@ -527,7 +519,7 @@ test("add(String|Element|Array|undefined)", function() {
var notDefined; var notDefined;
equals( jQuery([]).add(notDefined).length, 0, "Check that undefined adds nothing" ); equals( jQuery([]).add(notDefined).length, 0, "Check that undefined adds nothing" );
ok( jQuery([]).add( document.getElementById('form') ).length >= 13, "Add a form (adds the elements)" ); ok( jQuery([]).add( document.getElementById("form") ).length >= 13, "Add a form (adds the elements)" );
}); });
test("add(String, Context)", function() { test("add(String, Context)", function() {