" ).append( jQuery.parseHTML( responseText ) ).find( selector ) :
// Otherwise use the full result
responseText );
- }).complete( callback && function( jqXHR, status ) {
+ } ).complete( callback && function( jqXHR, status ) {
self.each( callback, response || [ jqXHR.responseText, status, jqXHR ] );
- });
+ } );
}
return this;
};
// Attach a bunch of functions for handling common AJAX events
-jQuery.each( [ "ajaxStart", "ajaxStop", "ajaxComplete", "ajaxError", "ajaxSuccess", "ajaxSend" ], function( i, type ){
- jQuery.fn[ type ] = function( fn ){
+jQuery.each( [ "ajaxStart", "ajaxStop", "ajaxComplete", "ajaxError", "ajaxSuccess", "ajaxSend" ], function( i, type ) {
+ jQuery.fn[ type ] = function( fn ) {
return this.on( type, fn );
};
-});
+} );
jQuery.each( [ "get", "post" ], function( i, method ) {
jQuery[ method ] = function( url, data, callback, type ) {
+
// shift arguments if data argument was omitted
if ( jQuery.isFunction( data ) ) {
type = type || callback;
@@ -7611,17 +7840,17 @@ jQuery.each( [ "get", "post" ], function( i, method ) {
data = undefined;
}
- return jQuery.ajax({
+ return jQuery.ajax( {
url: url,
type: method,
dataType: type,
data: data,
success: callback
- });
+ } );
};
-});
+} );
-jQuery.extend({
+jQuery.extend( {
// Counter for holding the number of active queries
active: 0,
@@ -7726,12 +7955,16 @@ jQuery.extend({
var // Cross-domain detection vars
parts,
+
// Loop variable
i,
+
// URL without anti-cache param
cacheURL,
+
// Response headers as string
responseHeadersString,
+
// timeout handle
timeoutTimer,
@@ -7739,28 +7972,38 @@ jQuery.extend({
fireGlobals,
transport,
+
// Response headers
responseHeaders,
+
// Create the final options object
s = jQuery.ajaxSetup( {}, options ),
+
// Callbacks context
callbackContext = s.context || s,
+
// Context for global events is callbackContext if it is a DOM node or jQuery collection
globalEventContext = s.context && ( callbackContext.nodeType || callbackContext.jquery ) ?
jQuery( callbackContext ) :
jQuery.event,
+
// Deferreds
deferred = jQuery.Deferred(),
- completeDeferred = jQuery.Callbacks("once memory"),
+ completeDeferred = jQuery.Callbacks( "once memory" ),
+
// Status-dependent callbacks
statusCode = s.statusCode || {},
+
// Headers (they are sent all at once)
requestHeaders = {},
requestHeadersNames = {},
+
// The jqXHR state
state = 0,
+
// Default abort message
strAbort = "canceled",
+
// Fake xhr
jqXHR = {
readyState: 0,
@@ -7771,8 +8014,8 @@ jQuery.extend({
if ( state === 2 ) {
if ( !responseHeaders ) {
responseHeaders = {};
- while ( (match = rheaders.exec( responseHeadersString )) ) {
- responseHeaders[ match[1].toLowerCase() ] = match[ 2 ];
+ while ( ( match = rheaders.exec( responseHeadersString ) ) ) {
+ responseHeaders[ match[ 1 ].toLowerCase() ] = match[ 2 ];
}
}
match = responseHeaders[ key.toLowerCase() ];
@@ -7809,10 +8052,12 @@ jQuery.extend({
if ( map ) {
if ( state < 2 ) {
for ( code in map ) {
+
// Lazy-add the new callback in a way that preserves old ones
statusCode[ code ] = [ statusCode[ code ], map[ code ] ];
}
} else {
+
// Execute the appropriate callbacks
jqXHR.always( map[ jqXHR.status ] );
}
@@ -7846,7 +8091,7 @@ jQuery.extend({
s.type = options.method || options.type || s.method || s.type;
// Extract dataTypes list
- s.dataTypes = jQuery.trim( s.dataType || "*" ).toLowerCase().match( core_rnotwhite ) || [""];
+ s.dataTypes = jQuery.trim( s.dataType || "*" ).toLowerCase().match( core_rnotwhite ) || [ "" ];
// A cross-domain request is in order when we have a protocol:host:port mismatch
if ( s.crossDomain == null ) {
@@ -7876,7 +8121,7 @@ jQuery.extend({
// Watch for a new set of requests
if ( fireGlobals && jQuery.active++ === 0 ) {
- jQuery.event.trigger("ajaxStart");
+ jQuery.event.trigger( "ajaxStart" );
}
// Uppercase the type
@@ -7895,6 +8140,7 @@ jQuery.extend({
// If data is available, append data to url
if ( s.data ) {
cacheURL = ( s.url += ( ajax_rquery.test( cacheURL ) ? "&" : "?" ) + s.data );
+
// #9682: remove data so that it's not used in an eventual retry
delete s.data;
}
@@ -7929,8 +8175,8 @@ jQuery.extend({
// Set the Accepts header for the server, depending on the dataType
jqXHR.setRequestHeader(
"Accept",
- s.dataTypes[ 0 ] && s.accepts[ s.dataTypes[0] ] ?
- s.accepts[ s.dataTypes[0] ] + ( s.dataTypes[ 0 ] !== "*" ? ", " + allTypes + "; q=0.01" : "" ) :
+ s.dataTypes[ 0 ] && s.accepts[ s.dataTypes[ 0 ] ] ?
+ s.accepts[ s.dataTypes[ 0 ] ] + ( s.dataTypes[ 0 ] !== "*" ? ", " + allTypes + "; q=0.01" : "" ) :
s.accepts[ "*" ]
);
@@ -7941,6 +8187,7 @@ jQuery.extend({
// Allow custom headers/mimetypes and early abort
if ( s.beforeSend && ( s.beforeSend.call( callbackContext, jqXHR, s ) === false || state === 2 ) ) {
+
// Abort if not done already and return
return jqXHR.abort();
}
@@ -7966,10 +8213,11 @@ jQuery.extend({
if ( fireGlobals ) {
globalEventContext.trigger( "ajaxSend", [ jqXHR, s ] );
}
+
// Timeout
if ( s.async && s.timeout > 0 ) {
- timeoutTimer = setTimeout(function() {
- jqXHR.abort("timeout");
+ timeoutTimer = setTimeout( function() {
+ jqXHR.abort( "timeout" );
}, s.timeout );
}
@@ -7977,9 +8225,11 @@ jQuery.extend({
state = 1;
transport.send( requestHeaders, done );
} catch ( e ) {
+
// Propagate exception as error if not done
if ( state < 2 ) {
done( -1, e );
+
// Simply rethrow otherwise
} else {
throw e;
@@ -8025,11 +8275,11 @@ jQuery.extend({
// Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
if ( s.ifModified ) {
- modified = jqXHR.getResponseHeader("Last-Modified");
+ modified = jqXHR.getResponseHeader( "Last-Modified" );
if ( modified ) {
jQuery.lastModified[ cacheURL ] = modified;
}
- modified = jqXHR.getResponseHeader("etag");
+ modified = jqXHR.getResponseHeader( "etag" );
if ( modified ) {
jQuery.etag[ cacheURL ] = modified;
}
@@ -8054,6 +8304,7 @@ jQuery.extend({
isSuccess = !error;
}
} else {
+
// We extract error from statusText
// then normalize statusText and status for non-aborts
error = statusText;
@@ -8090,9 +8341,10 @@ jQuery.extend({
if ( fireGlobals ) {
globalEventContext.trigger( "ajaxComplete", [ jqXHR, s ] );
+
// Handle the global AJAX counter
if ( !( --jQuery.active ) ) {
- jQuery.event.trigger("ajaxStop");
+ jQuery.event.trigger( "ajaxStop" );
}
}
}
@@ -8107,7 +8359,7 @@ jQuery.extend({
getJSON: function( url, data, callback ) {
return jQuery.get( url, data, callback, "json" );
}
-});
+} );
/* Handles responses to an ajax request:
* - sets all responseXXX fields accordingly
@@ -8123,15 +8375,15 @@ function ajaxHandleResponses( s, jqXHR, responses ) {
// Fill responseXXX fields
for ( type in responseFields ) {
if ( type in responses ) {
- jqXHR[ responseFields[type] ] = responses[ type ];
+ jqXHR[ responseFields[ type ] ] = responses[ type ];
}
}
// Remove auto dataType and get content-type in the process
- while( dataTypes[ 0 ] === "*" ) {
+ while ( dataTypes[ 0 ] === "*" ) {
dataTypes.shift();
if ( ct === undefined ) {
- ct = s.mimeType || jqXHR.getResponseHeader("Content-Type");
+ ct = s.mimeType || jqXHR.getResponseHeader( "Content-Type" );
}
}
@@ -8149,9 +8401,10 @@ function ajaxHandleResponses( s, jqXHR, responses ) {
if ( dataTypes[ 0 ] in responses ) {
finalDataType = dataTypes[ 0 ];
} else {
+
// Try convertible dataTypes
for ( type in responses ) {
- if ( !dataTypes[ 0 ] || s.converters[ type + " " + dataTypes[0] ] ) {
+ if ( !dataTypes[ 0 ] || s.converters[ type + " " + dataTypes[ 0 ] ] ) {
finalDataType = type;
break;
}
@@ -8159,6 +8412,7 @@ function ajaxHandleResponses( s, jqXHR, responses ) {
firstDataType = type;
}
}
+
// Or just use first one
finalDataType = finalDataType || firstDataType;
}
@@ -8179,6 +8433,7 @@ function ajaxConvert( s, response ) {
var conv2, current, conv, tmp,
converters = {},
i = 0,
+
// Work with a copy of dataTypes in case we need to modify it for conversion
dataTypes = s.dataTypes.slice(),
prev = dataTypes[ 0 ];
@@ -8196,7 +8451,7 @@ function ajaxConvert( s, response ) {
}
// Convert to each sequential dataType, tolerating list modification
- for ( ; (current = dataTypes[++i]); ) {
+ for ( ; ( current = dataTypes[ ++i ] ); ) {
// There's only work to do if current dataType is non-auto
if ( current !== "*" ) {
@@ -8212,13 +8467,14 @@ function ajaxConvert( s, response ) {
for ( conv2 in converters ) {
// If conv2 outputs current
- tmp = conv2.split(" ");
+ tmp = conv2.split( " " );
if ( tmp[ 1 ] === current ) {
// If prev can be converted to accepted input
conv = converters[ prev + " " + tmp[ 0 ] ] ||
converters[ "* " + tmp[ 0 ] ];
if ( conv ) {
+
// Condense equivalence converters
if ( conv === true ) {
conv = converters[ conv2 ];
@@ -8239,7 +8495,7 @@ function ajaxConvert( s, response ) {
if ( conv !== true ) {
// Unless errors are allowed to bubble, catch and return them
- if ( conv && s["throws"] ) {
+ if ( conv && s[ "throws" ] ) {
response = conv( response );
} else {
try {
@@ -8258,8 +8514,9 @@ function ajaxConvert( s, response ) {
return { state: "success", data: response };
}
+
// Install script dataType
-jQuery.ajaxSetup({
+jQuery.ajaxSetup( {
accepts: {
script: "text/javascript, application/javascript, application/ecmascript, application/x-ecmascript"
},
@@ -8272,7 +8529,7 @@ jQuery.ajaxSetup({
return text;
}
}
-});
+} );
// Handle cache's special case and global
jQuery.ajaxPrefilter( "script", function( s ) {
@@ -8283,22 +8540,22 @@ jQuery.ajaxPrefilter( "script", function( s ) {
s.type = "GET";
s.global = false;
}
-});
+} );
// Bind script tag hack transport
-jQuery.ajaxTransport( "script", function(s) {
+jQuery.ajaxTransport( "script", function( s ) {
// This transport only deals with cross domain requests
if ( s.crossDomain ) {
var script,
- head = document.head || jQuery("head")[0] || document.documentElement;
+ head = document.head || jQuery( "head" )[ 0 ] || document.documentElement;
return {
send: function( _, callback ) {
- script = document.createElement("script");
+ script = document.createElement( "script" );
script.async = true;
@@ -8343,19 +8600,19 @@ jQuery.ajaxTransport( "script", function(s) {
}
};
}
-});
+} );
var oldCallbacks = [],
rjsonp = /(=)\?(?=&|$)|\?\?/;
// Default jsonp settings
-jQuery.ajaxSetup({
+jQuery.ajaxSetup( {
jsonp: "callback",
jsonpCallback: function() {
var callback = oldCallbacks.pop() || ( jQuery.expando + "_" + ( ajax_nonce++ ) );
this[ callback ] = true;
return callback;
}
-});
+} );
// Detect, normalize options and install callbacks for jsonp requests
jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) {
@@ -8363,7 +8620,7 @@ jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) {
var callbackName, overwritten, responseContainer,
jsonProp = s.jsonp !== false && ( rjsonp.test( s.url ) ?
"url" :
- typeof s.data === "string" && !( s.contentType || "" ).indexOf("application/x-www-form-urlencoded") && rjsonp.test( s.data ) && "data"
+ typeof s.data === "string" && !( s.contentType || "" ).indexOf( "application/x-www-form-urlencoded" ) && rjsonp.test( s.data ) && "data"
);
// Handle iff the expected data type is "jsonp" or we have a parameter to set
@@ -8382,7 +8639,7 @@ jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) {
}
// Use data converter to retrieve json after script execution
- s.converters["script json"] = function() {
+ s.converters[ "script json" ] = function() {
if ( !responseContainer ) {
jQuery.error( callbackName + " was not called" );
}
@@ -8399,12 +8656,14 @@ jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) {
};
// Clean-up function (fires after converters)
- jqXHR.always(function() {
+ jqXHR.always( function() {
+
// Restore preexisting value
window[ callbackName ] = overwritten;
// Save back as free
if ( s[ callbackName ] ) {
+
// make sure that re-using the options doesn't screw things around
s.jsonpCallback = originalSettings.jsonpCallback;
@@ -8418,16 +8677,18 @@ jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) {
}
responseContainer = overwritten = undefined;
- });
+ } );
// Delegate to script
return "script";
}
-});
+} );
var xhrCallbacks, xhrSupported,
xhrId = 0,
+
// #5280: Internet Explorer will keep connections alive if we don't abort on unload
xhrOnUnloadAbort = window.ActiveXObject && function() {
+
// Abort all pending requests
var key;
for ( key in xhrCallbacks ) {
@@ -8439,13 +8700,13 @@ var xhrCallbacks, xhrSupported,
function createStandardXHR() {
try {
return new window.XMLHttpRequest();
- } catch( e ) {}
+ } catch ( e ) {}
}
function createActiveXHR() {
try {
- return new window.ActiveXObject("Microsoft.XMLHTTP");
- } catch( e ) {}
+ return new window.ActiveXObject( "Microsoft.XMLHTTP" );
+ } catch ( e ) {}
}
// Create the request object
@@ -8460,6 +8721,7 @@ jQuery.ajaxSettings.xhr = window.ActiveXObject ?
function() {
return !this.isLocal && createStandardXHR() || createActiveXHR();
} :
+
// For all other browsers, use the standard XMLHttpRequest object
createStandardXHR;
@@ -8471,7 +8733,8 @@ xhrSupported = jQuery.support.ajax = !!xhrSupported;
// Create transport if the browser can provide an xhr
if ( xhrSupported ) {
- jQuery.ajaxTransport(function( s ) {
+ jQuery.ajaxTransport( function( s ) {
+
// Cross domain only allowed if supported through XMLHttpRequest
if ( !s.crossDomain || jQuery.support.cors ) {
@@ -8509,8 +8772,8 @@ if ( xhrSupported ) {
// akin to a jigsaw puzzle, we simply never set it to be sure.
// (it can always be set on a per-request basis or even using ajaxSetup)
// For same-domain requests, won't change header if already provided.
- if ( !s.crossDomain && !headers["X-Requested-With"] ) {
- headers["X-Requested-With"] = "XMLHttpRequest";
+ if ( !s.crossDomain && !headers[ "X-Requested-With" ] ) {
+ headers[ "X-Requested-With" ] = "XMLHttpRequest";
}
// Need an extra try/catch for cross domain requests in Firefox 3
@@ -8518,7 +8781,7 @@ if ( xhrSupported ) {
for ( i in headers ) {
xhr.setRequestHeader( i, headers[ i ] );
}
- } catch( err ) {}
+ } catch ( err ) {}
// Do send the request
// This may raise an exception which is actually
@@ -8550,6 +8813,7 @@ if ( xhrSupported ) {
// If it's an abort
if ( isAbort ) {
+
// Abort it manually if needed
if ( xhr.readyState !== 4 ) {
xhr.abort();
@@ -8569,7 +8833,8 @@ if ( xhrSupported ) {
// statusText for faulty cross-domain requests
try {
statusText = xhr.statusText;
- } catch( e ) {
+ } catch ( e ) {
+
// We normalize with Webkit giving an empty statusText
statusText = "";
}
@@ -8581,13 +8846,14 @@ if ( xhrSupported ) {
// can do given current implementations)
if ( !status && s.isLocal && !s.crossDomain ) {
status = responses.text ? 200 : 404;
+
// IE - #1450: sometimes returns 1223 when it should be 204
} else if ( status === 1223 ) {
status = 204;
}
}
}
- } catch( firefoxAccessException ) {
+ } catch ( firefoxAccessException ) {
if ( !isAbort ) {
complete( -1, firefoxAccessException );
}
@@ -8600,21 +8866,25 @@ if ( xhrSupported ) {
};
if ( !s.async ) {
+
// if we're in sync mode we fire the callback
callback();
} else if ( xhr.readyState === 4 ) {
+
// (IE6 & IE7) if it's in cache and has been
// retrieved directly we need to fire the callback
setTimeout( callback );
} else {
handle = ++xhrId;
if ( xhrOnUnloadAbort ) {
+
// Create the active xhrs callbacks list if needed
// and attach the unload handler
if ( !xhrCallbacks ) {
xhrCallbacks = {};
jQuery( window ).unload( xhrOnUnloadAbort );
}
+
// Add to list of active xhrs callbacks
xhrCallbacks[ handle ] = callback;
}
@@ -8629,7 +8899,7 @@ if ( xhrSupported ) {
}
};
}
- });
+ } );
}
var fxNow, timerId,
rfxtypes = /^(?:toggle|show|hide)$/,
@@ -8637,7 +8907,7 @@ var fxNow, timerId,
rrun = /queueHooks$/,
animationPrefilters = [ defaultPrefilter ],
tweeners = {
- "*": [function( prop, value ) {
+ "*": [ function( prop, value ) {
var end, unit,
tween = this.createTween( prop, value ),
parts = rfxnum.exec( value ),
@@ -8647,17 +8917,19 @@ var fxNow, timerId,
maxIterations = 20;
if ( parts ) {
- end = +parts[2];
- unit = parts[3] || ( jQuery.cssNumber[ prop ] ? "" : "px" );
+ end = +parts[ 2 ];
+ unit = parts[ 3 ] || ( jQuery.cssNumber[ prop ] ? "" : "px" );
// We need to compute starting value
if ( unit !== "px" && start ) {
+
// Iteratively approximate from a nonzero starting point
// Prefer the current property, because this process will be trivial if it uses the same units
// Fallback to end or a simple constant
start = jQuery.css( tween.elem, prop, true ) || end || 1;
do {
+
// If previous iteration zeroed out, double until we get *something*
// Use a string for doubling factor so we don't accidentally see scale as unchanged below
scale = scale || ".5";
@@ -8668,23 +8940,24 @@ var fxNow, timerId,
// Update scale, tolerating zero or NaN from tween.cur()
// And breaking the loop if scale is unchanged or perfect, or if we've just had enough
- } while ( scale !== (scale = tween.cur() / target) && scale !== 1 && --maxIterations );
+ } while ( scale !== ( scale = tween.cur() / target ) && scale !== 1 && --maxIterations );
}
tween.unit = unit;
tween.start = start;
+
// If a +=/-= token was provided, we're doing a relative animation
- tween.end = parts[1] ? start + ( parts[1] + 1 ) * end : end;
+ tween.end = parts[ 1 ] ? start + ( parts[ 1 ] + 1 ) * end : end;
}
return tween;
- }]
+ } ]
};
// Animations created synchronously will run synchronously
function createFxNow() {
- setTimeout(function() {
+ setTimeout( function() {
fxNow = undefined;
- });
+ } );
return ( fxNow = jQuery.now() );
}
@@ -8700,7 +8973,7 @@ function createTweens( animation, props ) {
return;
}
}
- });
+ } );
}
function Animation( elem, properties, options ) {
@@ -8709,15 +8982,17 @@ function Animation( elem, properties, options ) {
index = 0,
length = animationPrefilters.length,
deferred = jQuery.Deferred().always( function() {
+
// don't match elem in the :animated selector
delete tick.elem;
- }),
+ } ),
tick = function() {
if ( stopped ) {
return false;
}
var currentTime = fxNow || createFxNow(),
remaining = Math.max( 0, animation.startTime + animation.duration - currentTime ),
+
// archaic crash bug won't allow us to use 1 - ( 0.5 || 0 ) (#12497)
temp = remaining / animation.duration || 0,
percent = 1 - temp,
@@ -8728,7 +9003,7 @@ function Animation( elem, properties, options ) {
animation.tweens[ index ].run( percent );
}
- deferred.notifyWith( elem, [ animation, percent, remaining ]);
+ deferred.notifyWith( elem, [ animation, percent, remaining ] );
if ( percent < 1 && length ) {
return remaining;
@@ -8737,7 +9012,7 @@ function Animation( elem, properties, options ) {
return false;
}
},
- animation = deferred.promise({
+ animation = deferred.promise( {
elem: elem,
props: jQuery.extend( {}, properties ),
opts: jQuery.extend( true, { specialEasing: {} }, options ),
@@ -8754,6 +9029,7 @@ function Animation( elem, properties, options ) {
},
stop: function( gotoEnd ) {
var index = 0,
+
// if we are going to the end, we want to run all the tweens
// otherwise we skip this part
length = gotoEnd ? animation.tweens.length : 0;
@@ -8774,7 +9050,7 @@ function Animation( elem, properties, options ) {
}
return this;
}
- }),
+ } ),
props = animation.props;
propFilter( props, animation.opts.specialEasing );
@@ -8797,7 +9073,7 @@ function Animation( elem, properties, options ) {
elem: elem,
anim: animation,
queue: animation.opts.queue
- })
+ } )
);
// attach callbacks from options
@@ -8851,7 +9127,7 @@ jQuery.Animation = jQuery.extend( Animation, {
callback = props;
props = [ "*" ];
} else {
- props = props.split(" ");
+ props = props.split( " " );
}
var prop,
@@ -8872,7 +9148,7 @@ jQuery.Animation = jQuery.extend( Animation, {
animationPrefilters.push( callback );
}
}
-});
+} );
function defaultPrefilter( elem, props, opts ) {
/*jshint validthis:true */
@@ -8899,20 +9175,22 @@ function defaultPrefilter( elem, props, opts ) {
}
hooks.unqueued++;
- anim.always(function() {
+ anim.always( function() {
+
// doing this makes sure that the complete handler will be called
// before this completes
- anim.always(function() {
+ anim.always( function() {
hooks.unqueued--;
if ( !jQuery.queue( elem, "fx" ).length ) {
hooks.empty.fire();
}
- });
- });
+ } );
+ } );
}
// height/width overflow pass
if ( elem.nodeType === 1 && ( "height" in props || "width" in props ) ) {
+
// Make sure that nothing sneaks out
// Record all 3 overflow attributes because IE does not
// change the overflow attribute when overflowX and
@@ -8938,15 +9216,14 @@ function defaultPrefilter( elem, props, opts ) {
if ( opts.overflow ) {
style.overflow = "hidden";
if ( !jQuery.support.shrinkWrapBlocks ) {
- anim.always(function() {
+ anim.always( function() {
style.overflow = opts.overflow[ 0 ];
style.overflowX = opts.overflow[ 1 ];
style.overflowY = opts.overflow[ 2 ];
- });
+ } );
}
}
-
// show/hide pass
for ( index in props ) {
value = props[ index ];
@@ -8974,17 +9251,17 @@ function defaultPrefilter( elem, props, opts ) {
if ( hidden ) {
jQuery( elem ).show();
} else {
- anim.done(function() {
+ anim.done( function() {
jQuery( elem ).hide();
- });
+ } );
}
- anim.done(function() {
+ anim.done( function() {
var prop;
jQuery._removeData( elem, "fxshow" );
for ( prop in orig ) {
jQuery.style( elem, prop, orig[ prop ] );
}
- });
+ } );
for ( index = 0 ; index < length ; index++ ) {
prop = handled[ index ];
tween = anim.createTween( prop, hidden ? dataShow[ prop ] : 0 );
@@ -9058,7 +9335,7 @@ Tween.propHooks = {
var result;
if ( tween.elem[ tween.prop ] != null &&
- (!tween.elem.style || tween.elem.style[ tween.prop ] == null) ) {
+ ( !tween.elem.style || tween.elem.style[ tween.prop ] == null ) ) {
return tween.elem[ tween.prop ];
}
@@ -9067,10 +9344,12 @@ Tween.propHooks = {
// so, simple values such as "10px" are parsed to Float.
// complex values such as "rotate(1rad)" are returned as is.
result = jQuery.css( tween.elem, tween.prop, "" );
+
// Empty strings, null, undefined and "auto" are converted to 0.
return !result || result === "auto" ? 0 : result;
},
set: function( tween ) {
+
// use step hook for back compat - use cssHook if its there - use .style if its
// available and use plain properties where available
if ( jQuery.fx.step[ tween.prop ] ) {
@@ -9095,33 +9374,35 @@ Tween.propHooks.scrollTop = Tween.propHooks.scrollLeft = {
}
};
-jQuery.each([ "toggle", "show", "hide" ], function( i, name ) {
+jQuery.each( [ "toggle", "show", "hide" ], function( i, name ) {
var cssFn = jQuery.fn[ name ];
jQuery.fn[ name ] = function( speed, easing, callback ) {
return speed == null || typeof speed === "boolean" ?
cssFn.apply( this, arguments ) :
this.animate( genFx( name, true ), speed, easing, callback );
};
-});
+} );
-jQuery.fn.extend({
+jQuery.fn.extend( {
fadeTo: function( speed, to, easing, callback ) {
// show any hidden elements after setting opacity to 0
return this.filter( isHidden ).css( "opacity", 0 ).show()
// animate to the value specified
- .end().animate({ opacity: to }, speed, easing, callback );
+ .end().animate( { opacity: to }, speed, easing, callback );
},
animate: function( prop, speed, easing, callback ) {
var empty = jQuery.isEmptyObject( prop ),
optall = jQuery.speed( speed, easing, callback ),
doAnimation = function() {
+
// Operate on a copy of prop so per-property easing won't be lost
var anim = Animation( this, jQuery.extend( {}, prop ), optall );
doAnimation.finish = function() {
anim.stop( true );
};
+
// Empty animations, or finishing resolves immediately
if ( empty || jQuery._data( this, "finish" ) ) {
anim.stop( true );
@@ -9149,7 +9430,7 @@ jQuery.fn.extend({
this.queue( type || "fx", [] );
}
- return this.each(function() {
+ return this.each( function() {
var dequeue = true,
index = type != null && type + "queueHooks",
timers = jQuery.timers,
@@ -9168,7 +9449,7 @@ jQuery.fn.extend({
}
for ( index = timers.length; index--; ) {
- if ( timers[ index ].elem === this && (type == null || timers[ index ].queue === type) ) {
+ if ( timers[ index ].elem === this && ( type == null || timers[ index ].queue === type ) ) {
timers[ index ].anim.stop( gotoEnd );
dequeue = false;
timers.splice( index, 1 );
@@ -9181,13 +9462,13 @@ jQuery.fn.extend({
if ( dequeue || !gotoEnd ) {
jQuery.dequeue( this, type );
}
- });
+ } );
},
finish: function( type ) {
if ( type !== false ) {
type = type || "fx";
}
- return this.each(function() {
+ return this.each( function() {
var index,
data = jQuery._data( this ),
queue = data[ type + "queue" ],
@@ -9222,9 +9503,9 @@ jQuery.fn.extend({
// turn off finishing flag
delete data.finish;
- });
+ } );
}
-});
+} );
// Generate parameters to create a standard animation
function genFx( type, includeWidth ) {
@@ -9234,8 +9515,8 @@ function genFx( type, includeWidth ) {
// if we include width, step value is 1 to do all cssExpand values,
// if we don't include width, step value is 2 to skip over Left and Right
- includeWidth = includeWidth? 1 : 0;
- for( ; i < 4 ; i += 2 - includeWidth ) {
+ includeWidth = includeWidth ? 1 : 0;
+ for ( ; i < 4 ; i += 2 - includeWidth ) {
which = cssExpand[ i ];
attrs[ "margin" + which ] = attrs[ "padding" + which ] = type;
}
@@ -9248,10 +9529,10 @@ function genFx( type, includeWidth ) {
}
// Generate shortcuts for custom animations
-jQuery.each({
- slideDown: genFx("show"),
- slideUp: genFx("hide"),
- slideToggle: genFx("toggle"),
+jQuery.each( {
+ slideDown: genFx( "show" ),
+ slideUp: genFx( "hide" ),
+ slideToggle: genFx( "toggle" ),
fadeIn: { opacity: "show" },
fadeOut: { opacity: "hide" },
fadeToggle: { opacity: "toggle" }
@@ -9259,7 +9540,7 @@ jQuery.each({
jQuery.fn[ name ] = function( speed, easing, callback ) {
return this.animate( props, speed, easing, callback );
};
-});
+} );
jQuery.speed = function( speed, easing, fn ) {
var opt = speed && typeof speed === "object" ? jQuery.extend( {}, speed ) : {
@@ -9298,7 +9579,7 @@ jQuery.easing = {
return p;
},
swing: function( p ) {
- return 0.5 - Math.cos( p*Math.PI ) / 2;
+ return 0.5 - Math.cos( p * Math.PI ) / 2;
}
};
@@ -9313,6 +9594,7 @@ jQuery.fx.tick = function() {
for ( ; i < timers.length; i++ ) {
timer = timers[ i ];
+
// Checks the timer has not already been removed
if ( !timer() && timers[ i ] === timer ) {
timers.splice( i--, 1 );
@@ -9347,6 +9629,7 @@ jQuery.fx.stop = function() {
jQuery.fx.speeds = {
slow: 600,
fast: 200,
+
// Default speed
_default: 400
};
@@ -9356,18 +9639,18 @@ jQuery.fx.step = {};
if ( jQuery.expr && jQuery.expr.filters ) {
jQuery.expr.filters.animated = function( elem ) {
- return jQuery.grep(jQuery.timers, function( fn ) {
+ return jQuery.grep( jQuery.timers, function( fn ) {
return elem === fn.elem;
- }).length;
+ } ).length;
};
}
jQuery.fn.offset = function( options ) {
if ( arguments.length ) {
return options === undefined ?
this :
- this.each(function( i ) {
+ this.each( function( i ) {
jQuery.offset.setOffset( this, options, i );
- });
+ } );
}
var docElem, win,
@@ -9412,7 +9695,7 @@ jQuery.offset = {
curOffset = curElem.offset(),
curCSSTop = jQuery.css( elem, "top" ),
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;
// need to be able to calculate position if either top or left is auto and position is either absolute or fixed
@@ -9444,8 +9727,7 @@ jQuery.offset = {
}
};
-
-jQuery.fn.extend({
+jQuery.fn.extend( {
position: function() {
if ( !this[ 0 ] ) {
@@ -9458,9 +9740,11 @@ jQuery.fn.extend({
// fixed elements are offset from window (parentOffset = {top:0, left: 0}, because it is it's only offset parent
if ( jQuery.css( elem, "position" ) === "fixed" ) {
+
// we assume that getBoundingClientRect is available when computed position is fixed
offset = elem.getBoundingClientRect();
} else {
+
// Get *real* offsetParent
offsetParent = this.offsetParent();
@@ -9480,24 +9764,23 @@ jQuery.fn.extend({
// are the same in Safari causing offset.left to incorrectly be 0
return {
top: offset.top - parentOffset.top - jQuery.css( elem, "marginTop", true ),
- left: offset.left - parentOffset.left - jQuery.css( elem, "marginLeft", true)
+ left: offset.left - parentOffset.left - jQuery.css( elem, "marginLeft", true )
};
},
offsetParent: function() {
- return this.map(function() {
+ return this.map( function() {
var offsetParent = this.offsetParent || document.documentElement;
- while ( offsetParent && ( !jQuery.nodeName( offsetParent, "html" ) && jQuery.css( offsetParent, "position") === "static" ) ) {
+ while ( offsetParent && ( !jQuery.nodeName( offsetParent, "html" ) && jQuery.css( offsetParent, "position" ) === "static" ) ) {
offsetParent = offsetParent.offsetParent;
}
return offsetParent || document.documentElement;
- });
+ } );
}
-});
-
+} );
// Create scrollLeft and scrollTop methods
-jQuery.each( {scrollLeft: "pageXOffset", scrollTop: "pageYOffset"}, function( method, prop ) {
+jQuery.each( { scrollLeft: "pageXOffset", scrollTop: "pageYOffset" }, function( method, prop ) {
var top = /Y/.test( prop );
jQuery.fn[ method ] = function( val ) {
@@ -9505,7 +9788,7 @@ jQuery.each( {scrollLeft: "pageXOffset", scrollTop: "pageYOffset"}, function( me
var win = getWindow( elem );
if ( val === undefined ) {
- return win ? (prop in win) ? win[ prop ] :
+ return win ? ( prop in win ) ? win[ prop ] :
win.document.documentElement[ method ] :
elem[ method ];
}
@@ -9521,7 +9804,7 @@ jQuery.each( {scrollLeft: "pageXOffset", scrollTop: "pageYOffset"}, function( me
}
}, method, val, arguments.length, null );
};
-});
+} );
function getWindow( elem ) {
return jQuery.isWindow( elem ) ?
@@ -9530,9 +9813,11 @@ function getWindow( elem ) {
elem.defaultView || elem.parentWindow :
false;
}
+
// Create innerHeight, innerWidth, height, width, outerHeight and outerWidth methods
jQuery.each( { Height: "height", Width: "width" }, function( name, type ) {
jQuery.each( { padding: "inner" + name, content: type, "": "outer" + name }, function( defaultExtra, funcName ) {
+
// margin is only for outerHeight, outerWidth
jQuery.fn[ funcName ] = function( margin, value ) {
var chainable = arguments.length && ( defaultExtra || typeof margin !== "boolean" ),
@@ -9542,6 +9827,7 @@ jQuery.each( { Height: "height", Width: "width" }, function( name, type ) {
var doc;
if ( jQuery.isWindow( elem ) ) {
+
// As of 5/8/2012 this will yield incorrect results for Mobile Safari, but there
// isn't a whole lot we can do. See pull request at this URL for discussion:
// https://github.com/jquery/jquery/pull/764
@@ -9562,6 +9848,7 @@ jQuery.each( { Height: "height", Width: "width" }, function( name, type ) {
}
return value === undefined ?
+
// Get width or height on the element, requesting but not forcing parseFloat
jQuery.css( elem, type, extra ) :
@@ -9569,8 +9856,9 @@ jQuery.each( { Height: "height", Width: "width" }, function( name, type ) {
jQuery.style( elem, type, value, extra );
}, type, chainable ? margin : undefined, chainable, null );
};
- });
-});
+ } );
+} );
+
// Limit scope pollution from any deprecated API
// (function() {
@@ -9591,7 +9879,7 @@ window.jQuery = window.$ = jQuery;
// Do this after creating the global so that if an AMD module wants to call
// noConflict to hide this version of jQuery, it will work.
if ( typeof define === "function" && define.amd && define.amd.jQuery ) {
- define( "jquery", [], function () { return jQuery; } );
+ define( "jquery", [], function() { return jQuery; } );
}
-})( window );
+} )( window );
diff --git a/test/data/readywaitloader.js b/test/data/readywaitloader.js
index e07dac7a9..8f4a3452e 100644
--- a/test/data/readywaitloader.js
+++ b/test/data/readywaitloader.js
@@ -1,19 +1,19 @@
// Simple script loader that uses jQuery.readyWait via jQuery.holdReady()
//Hold on jQuery!
-jQuery.holdReady(true);
+jQuery.holdReady( true );
var readyRegExp = /^(complete|loaded)$/;
-function assetLoaded( evt ){
+function assetLoaded( evt ) {
var node = evt.currentTarget || evt.srcElement;
- if ( evt.type === "load" || readyRegExp.test(node.readyState) ) {
- jQuery.holdReady(false);
+ if ( evt.type === "load" || readyRegExp.test( node.readyState ) ) {
+ jQuery.holdReady( false );
}
}
setTimeout( function() {
- var script = document.createElement("script");
+ var script = document.createElement( "script" );
script.type = "text/javascript";
if ( script.addEventListener ) {
script.addEventListener( "load", assetLoaded, false );
@@ -21,5 +21,5 @@ setTimeout( function() {
script.attachEvent( "onreadystatechange", assetLoaded );
}
script.src = "data/readywaitasset.js";
- document.getElementsByTagName("head")[0].appendChild(script);
+ document.getElementsByTagName( "head" )[ 0 ].appendChild( script );
}, 2000 );
diff --git a/test/data/support/csp.js b/test/data/support/csp.js
index a25bd8ae5..5ebdcea08 100644
--- a/test/data/support/csp.js
+++ b/test/data/support/csp.js
@@ -1,3 +1,3 @@
-jQuery(function() {
+jQuery( function() {
parent.iframeCallback( getComputedSupport( jQuery.support ) );
-});
+} );
diff --git a/test/data/testinit.js b/test/data/testinit.js
index f56dba736..273436cf9 100644
--- a/test/data/testinit.js
+++ b/test/data/testinit.js
@@ -3,6 +3,7 @@
var fireNative, originaljQuery, original$,
baseURL = "",
supportjQuery = this.jQuery,
+
// see RFC 2606
externalHost = "example.com";
@@ -24,7 +25,7 @@ this.q = function() {
i = 0;
for ( ; i < arguments.length; i++ ) {
- r.push( document.getElementById( arguments[i] ) );
+ r.push( document.getElementById( arguments[ i ] ) );
}
return r;
};
@@ -38,7 +39,7 @@ this.q = function() {
* @result returns true if "//[a]" return two elements with the IDs 'foo' and 'baar'
*/
this.t = function( a, b, c ) {
- var f = jQuery(b).get(),
+ var f = jQuery( b ).get(),
s = "",
i = 0;
@@ -46,7 +47,7 @@ this.t = function( a, b, c ) {
s += ( s && "," ) + '"' + f[ i ].id + '"';
}
- deepEqual(f, q.apply( q, c ), a + " (" + b + ")");
+ deepEqual( f, q.apply( q, c ), a + " (" + b + ")" );
};
this.createDashboardXML = function() {
@@ -62,7 +63,7 @@ this.createDashboardXML = function() {
\
';
- return jQuery.parseXML(string);
+ return jQuery.parseXML( string );
};
this.createWithFriesXML = function() {
@@ -98,13 +99,13 @@ this.createWithFriesXML = function() {
this.createXMLFragment = function() {
var xml, frag;
if ( window.ActiveXObject ) {
- xml = new ActiveXObject("msxml2.domdocument");
+ xml = new ActiveXObject( "msxml2.domdocument" );
} else {
xml = document.implementation.createDocument( "", "", null );
}
if ( xml ) {
- frag = xml.createElement("data");
+ frag = xml.createElement( "data" );
}
return frag;
@@ -112,13 +113,13 @@ this.createXMLFragment = function() {
fireNative = document.createEvent ?
function( node, type ) {
- var event = document.createEvent('HTMLEvents');
+ var event = document.createEvent( "HTMLEvents" );
event.initEvent( type, true, true );
node.dispatchEvent( event );
} :
function( node, type ) {
var event = document.createEventObject();
- node.fireEvent( 'on' + type, event );
+ node.fireEvent( "on" + type, event );
};
/**
@@ -131,7 +132,7 @@ fireNative = document.createEvent ?
* @result "data/test.php?foo=bar&10538358345554"
*/
function url( value ) {
- return baseURL + value + (/\?/.test( value ) ? "&" : "?") +
+ return baseURL + value + ( /\?/.test( value ) ? "&" : "?" ) +
new Date().getTime() + "" + parseInt( Math.random() * 100000, 10 );
}
@@ -186,7 +187,7 @@ this.ajaxTest = function( title, expect, options ) {
.done( callIfDefined( "done", "success" ) )
.fail( callIfDefined( "fail", "error" ) )
.always( complete );
- });
+ } );
ajaxTest.abort = function( reason ) {
if ( !completed ) {
@@ -195,19 +196,19 @@ this.ajaxTest = function( title, expect, options ) {
ok( false, "aborted " + reason );
jQuery.each( requests, function( i, request ) {
request.abort();
- });
+ } );
}
};
- });
+ } );
};
this.testIframe = function( fileName, name, fn ) {
- asyncTest(name, function() {
+ asyncTest( name, function() {
// load fixture in iframe
var iframe = loadFixture(),
win = iframe.contentWindow,
- interval = setInterval(function() {
+ interval = setInterval( function() {
if ( win && win.jQuery && win.jQuery.isReady ) {
clearInterval( interval );
@@ -219,7 +220,7 @@ this.testIframe = function( fileName, name, fn ) {
iframe = null;
}
}, 15 );
- });
+ } );
function loadFixture() {
var src = url( "./data/" + fileName + ".html" ),
@@ -244,7 +245,7 @@ this.testIframeWithCallback = function( title, fileName, func ) {
window.iframeCallback = function() {
var self = this,
args = arguments;
- setTimeout(function() {
+ setTimeout( function() {
window.iframeCallback = undefined;
iframe.remove();
func.apply( self, args );
@@ -252,10 +253,10 @@ this.testIframeWithCallback = function( title, fileName, func ) {
start();
}, 0 );
};
- iframe = jQuery( "
" ).css({ position: "absolute", width: "500px", left: "-600px" })
+ iframe = jQuery( "
" ).css( { position: "absolute", width: "500px", left: "-600px" } )
.append( jQuery( "
" ).attr( "src", url( "./data/" + fileName ) ) )
.appendTo( "#qunit-fixture" );
- });
+ } );
};
window.iframeCallback = undefined;
@@ -269,7 +270,7 @@ this.loadTests = function() {
loadSwarm = url && url.indexOf( "http" ) === 0;
// Get testSubproject from testrunner first
- require([ "data/testrunner.js" ], function() {
+ require( [ "data/testrunner.js" ], function() {
var tests = [
"unit/core.js",
"unit/callbacks.js",
@@ -294,7 +295,7 @@ this.loadTests = function() {
];
// Ensure load order (to preserve test numbers)
- (function loadDep() {
+ ( function loadDep() {
var dep = tests.shift();
if ( dep ) {
@@ -312,14 +313,14 @@ this.loadTests = function() {
// Load the TestSwarm listener if swarmURL is in the address.
if ( loadSwarm ) {
- require( [ "http://swarm.jquery.org/js/inject.js?" + (new Date()).getTime() ],
+ require( [ "http://swarm.jquery.org/js/inject.js?" + ( new Date() ).getTime() ],
function() {
QUnit.start();
- });
+ } );
} else {
QUnit.start();
}
}
- })();
- });
+ } )();
+ } );
};
diff --git a/test/data/testrunner.js b/test/data/testrunner.js
index d1e8b8fa8..c60b152b1 100644
--- a/test/data/testrunner.js
+++ b/test/data/testrunner.js
@@ -1,4 +1,4 @@
-define(function() {
+define( function() {
// Store the old counts so that we only assert on tests that have actually leaked,
// instead of asserting every time a test has leaked sometime in the past
@@ -68,6 +68,7 @@ QUnit.expectJqData = function( env, elems, key ) {
// be available as long as the object is not garbage collected by
// the js engine, and when it is, the data will be removed with it.
if ( !elem.nodeType ) {
+
// Fixes false positives for dataTests(window), dataTests({}).
continue;
}
@@ -75,6 +76,7 @@ QUnit.expectJqData = function( env, elems, key ) {
expando = elem[ jQuery.expando ];
if ( expando === undefined ) {
+
// In this case the element exists fine, but
// jQuery.data (or internal data) was never (in)directly
// called.
@@ -98,12 +100,12 @@ QUnit.expectJqData = function( env, elems, key ) {
}
};
-QUnit.config.urlConfig.push({
+QUnit.config.urlConfig.push( {
id: "jqdata",
label: "Always check jQuery.data",
tooltip: "Trigger QUnit.expectJqData detection for all tests " +
"instead of just the ones that call it"
-});
+} );
/**
* Ensures that tests have cleaned up properly after themselves. Should be passed as the
@@ -126,6 +128,7 @@ window.moduleTeardown = function() {
delete jQuery.cache[ i ];
delete expectedDataKeys[ i ];
}
+
// In case it was removed from cache before (or never there in the first place)
for ( i in expectedDataKeys ) {
deepEqual(
@@ -170,16 +173,18 @@ window.moduleTeardown = function() {
}
};
-QUnit.done(function() {
+QUnit.done( function() {
+
// Remove our own fixtures outside #qunit-fixture
supportjQuery( "#qunit ~ *" ).remove();
-});
+} );
// jQuery-specific post-test cleanup
reset = function() {
// Ensure jQuery events and data on the fixture are properly removed
jQuery( "#qunit-fixture" ).empty();
+
// ...even if the jQuery under test has a broken .empty()
supportjQuery( "#qunit-fixture" ).empty();
@@ -199,7 +204,7 @@ QUnit.testDone( reset );
// Register globals for cleanup and the cleanup code itself
// Explanation at http://perfectionkills.com/understanding-delete/#ie_bugs
-window.Globals = (function() {
+window.Globals = ( function() {
var globals = {};
return {
register: function( name ) {
@@ -218,6 +223,6 @@ window.Globals = (function() {
}
}
};
-})();
+} )();
-});
+} );
diff --git a/test/integration/data/gh-1764-fullscreen.js b/test/integration/data/gh-1764-fullscreen.js
index c13c609f3..b2bb4cdb5 100644
--- a/test/integration/data/gh-1764-fullscreen.js
+++ b/test/integration/data/gh-1764-fullscreen.js
@@ -17,10 +17,10 @@ function bootstrapFrom( mainSelector, mode ) {
document.webkitExitFullscreen;
function isFullscreen() {
- return !!(document.fullscreenElement ||
+ return !!( document.fullscreenElement ||
document.mozFullScreenElement ||
document.webkitFullscreenElement ||
- document.msFullscreenElement);
+ document.msFullscreenElement );
}
function requestFullscreen( element ) {
@@ -82,7 +82,7 @@ function bootstrapFrom( mainSelector, mode ) {
if ( isFullscreen() ) {
exitFullscreen();
} else {
- requestFullscreen( jQuery( mainSelector + " .container" )[0] );
+ requestFullscreen( jQuery( mainSelector + " .container" )[ 0 ] );
}
}
diff --git a/test/jquery.js b/test/jquery.js
index 2c1f15d6a..a595e3b47 100644
--- a/test/jquery.js
+++ b/test/jquery.js
@@ -1,5 +1,5 @@
// Use the right jQuery source on the test page (and iframes)
-(function() {
+( function() {
/* global loadTests: false */
var src,
@@ -8,11 +8,11 @@
require = window.require || parent.require;
// Config parameter to force basic code paths
- QUnit.config.urlConfig.push({
+ QUnit.config.urlConfig.push( {
id: "basic",
label: "Bypass optimizations",
tooltip: "Force use of the most basic code by disabling native querySelectorAll; contains; compareDocumentPosition; JSON.parse"
- });
+ } );
if ( QUnit.urlParams.basic ) {
document.querySelectorAll = null;
document.documentElement.contains = null;
@@ -21,21 +21,23 @@
}
// iFrames won't load AMD (the iframe tests synchronously expect jQuery to be there)
- QUnit.config.urlConfig.push({
+ QUnit.config.urlConfig.push( {
id: "amd",
label: "Load with AMD",
tooltip: "Load the AMD jQuery file (and its dependencies)"
- });
+ } );
+
// If QUnit is on window, this is the main window
// This detection allows AMD tests to be run in an iframe
if ( QUnit.urlParams.amd && window.QUnit ) {
- require.config({
+ require.config( {
baseUrl: path,
paths: {
sizzle: "external/sizzle/dist/sizzle"
}
- });
+ } );
src = "src/jquery";
+
// Include tests if specified
if ( typeof loadTests !== "undefined" ) {
require( [ src ], loadTests );
@@ -46,11 +48,11 @@
}
// Config parameter to use minified jQuery
- QUnit.config.urlConfig.push({
+ QUnit.config.urlConfig.push( {
id: "dev",
label: "Load unminified",
tooltip: "Load the development (unminified) jQuery file"
- });
+ } );
if ( QUnit.urlParams.dev ) {
src = "dist/jquery.js";
} else {
@@ -63,7 +65,7 @@
// Synchronous-only tests
// Other tests are loaded from the test page
if ( typeof loadTests !== "undefined" ) {
- document.write( "");
+ jQuery( "#qunit-fixture" ).append( "" );
- jQuery( document ).off("ajaxStart ajaxStop");
- });
+ jQuery( document ).off( "ajaxStart ajaxStop" );
+ } );
asyncTest( "jQuery#load() - always use GET method even if it overrided through ajaxSetup (#11264)", 1, function() {
- jQuery.ajaxSetup({
+ jQuery.ajaxSetup( {
type: "POST"
- });
+ } );
jQuery( "#qunit-fixture" ).load( "data/ajax/method.php", function( method ) {
equal( method, "GET" );
start();
- });
- });
+ } );
+ } );
asyncTest( "#11402 - jQuery.domManip() - script in comments are properly evaluated", 2, function() {
- jQuery("#qunit-fixture").load( "data/cleanScript.html", start );
- });
+ jQuery( "#qunit-fixture" ).load( "data/cleanScript.html", start );
+ } );
//----------- jQuery.get()
asyncTest( "jQuery.get( String, Hash, Function ) - parse xml and use text() on nodes", 2, function() {
- jQuery.get( url("data/dashboard.xml"), function( xml ) {
+ jQuery.get( url( "data/dashboard.xml" ), function( xml ) {
var content = [];
- jQuery( "tab", xml ).each(function() {
+ jQuery( "tab", xml ).each( function() {
content.push( jQuery( this ).text() );
- });
+ } );
strictEqual( content[ 0 ], "blabla", "Check first tab" );
strictEqual( content[ 1 ], "blublu", "Check second tab" );
start();
- });
- });
+ } );
+ } );
asyncTest( "#8277 - jQuery.get( String, Function ) - data in ajaxSettings", 1, function() {
- jQuery.ajaxSetup({
+ jQuery.ajaxSetup( {
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" );
start();
- });
- });
+ } );
+ } );
//----------- jQuery.getJSON()
asyncTest( "jQuery.getJSON( String, Hash, Function ) - JSON array", 5, function() {
jQuery.getJSON(
- url("data/json.php"),
+ url( "data/json.php" ),
{
"json": "array"
},
function( json ) {
ok( json.length >= 2, "Check length" );
- strictEqual( json[ 0 ]["name"], "John", "Check JSON: first, name" );
- strictEqual( json[ 0 ]["age"], 21, "Check JSON: first, age" );
- strictEqual( json[ 1 ]["name"], "Peter", "Check JSON: second, name" );
- strictEqual( json[ 1 ]["age"], 25, "Check JSON: second, age" );
+ strictEqual( json[ 0 ][ "name" ], "John", "Check JSON: first, name" );
+ strictEqual( json[ 0 ][ "age" ], 21, "Check JSON: first, age" );
+ strictEqual( json[ 1 ][ "name" ], "Peter", "Check JSON: second, name" );
+ strictEqual( json[ 1 ][ "age" ], 25, "Check JSON: second, age" );
start();
}
);
- });
+ } );
asyncTest( "jQuery.getJSON( String, Function ) - JSON object", 2, function() {
- jQuery.getJSON( url("data/json.php"), function( json ) {
- if ( json && json["data"] ) {
- strictEqual( json["data"]["lang"], "en", "Check JSON: lang" );
- strictEqual( json["data"].length, 25, "Check JSON: length" );
+ jQuery.getJSON( url( "data/json.php" ), function( json ) {
+ if ( json && json[ "data" ] ) {
+ strictEqual( json[ "data" ][ "lang" ], "en", "Check JSON: lang" );
+ strictEqual( json[ "data" ].length, 25, "Check JSON: length" );
start();
}
- });
- });
+ } );
+ } );
asyncTest( "jQuery.getJSON() - Using Native JSON", 2, function() {
var restore = "JSON" in window,
old = window.JSON;
if ( !restore ) {
- Globals.register("JSON");
+ Globals.register( "JSON" );
}
window.JSON = {
parse: function() {
@@ -1823,183 +1828,183 @@ module( "ajax", {
return true;
}
};
- jQuery.getJSON( url("data/json.php"), function( json ) {
+ jQuery.getJSON( url( "data/json.php" ), function( json ) {
strictEqual( json, true, "Verifying return value" );
start();
- });
- });
+ } );
+ } );
asyncTest( "jQuery.getJSON( String, Function ) - JSON object with absolute url to local content", 2, function() {
jQuery.getJSON( url( window.location.href.replace( /[^\/]*$/, "" ) + "data/json.php" ), function( json ) {
strictEqual( json.data.lang, "en", "Check JSON: lang" );
strictEqual( json.data.length, 25, "Check JSON: length" );
start();
- });
- });
+ } );
+ } );
//----------- jQuery.getScript()
asyncTest( "jQuery.getScript( String, Function ) - with callback", 2, function() {
- Globals.register("testBar");
- jQuery.getScript( url("data/testbar.php"), function() {
- strictEqual( window["testBar"], "bar", "Check if script was evaluated" );
+ Globals.register( "testBar" );
+ jQuery.getScript( url( "data/testbar.php" ), function() {
+ strictEqual( window[ "testBar" ], "bar", "Check if script was evaluated" );
start();
- });
- });
+ } );
+ } );
asyncTest( "jQuery.getScript( String, Function ) - no callback", 1, function() {
- Globals.register("testBar");
- jQuery.getScript( url("data/testbar.php") ).done( start );
- });
+ Globals.register( "testBar" );
+ jQuery.getScript( url( "data/testbar.php" ) ).done( start );
+ } );
asyncTest( "#8082 - jQuery.getScript( String, Function ) - source as responseText", 2, function() {
- Globals.register("testBar");
- jQuery.getScript( url("data/testbar.php"), function( data, _, jqXHR ) {
+ Globals.register( "testBar" );
+ jQuery.getScript( url( "data/testbar.php" ), function( data, _, jqXHR ) {
strictEqual( data, jqXHR.responseText, "Same-domain script requests returns the source of the script" );
start();
- });
- });
+ } );
+ } );
//----------- jQuery.fn.load()
// check if load can be called with only url
asyncTest( "jQuery.fn.load( String )", 2, function() {
- jQuery.ajaxSetup({
+ jQuery.ajaxSetup( {
beforeSend: function() {
strictEqual( this.type, "GET", "no data means GET request" );
}
- });
- jQuery("#first").load( "data/name.html", start );
- });
+ } );
+ jQuery( "#first" ).load( "data/name.html", start );
+ } );
asyncTest( "jQuery.fn.load() - 404 error callbacks", 6, function() {
- addGlobalEvents("ajaxStart ajaxStop ajaxSend ajaxComplete ajaxError")();
+ addGlobalEvents( "ajaxStart ajaxStop ajaxSend ajaxComplete ajaxError" )();
jQuery( document ).ajaxStop( start );
- jQuery("
" ).load( "data/404.html", function() {
ok( true, "complete" );
- });
- });
+ } );
+ } );
// check if load can be called with url and null data
asyncTest( "jQuery.fn.load( String, null )", 2, function() {
- jQuery.ajaxSetup({
+ jQuery.ajaxSetup( {
beforeSend: function() {
strictEqual( this.type, "GET", "no data means GET request" );
}
- });
- jQuery("#first").load( "data/name.html", null, start );
- });
+ } );
+ jQuery( "#first" ).load( "data/name.html", null, start );
+ } );
// check if load can be called with url and undefined data
asyncTest( "jQuery.fn.load( String, undefined )", 2, function() {
- jQuery.ajaxSetup({
+ jQuery.ajaxSetup( {
beforeSend: function() {
strictEqual( this.type, "GET", "no data means GET request" );
}
- });
- jQuery("#first").load( "data/name.html", undefined, start );
- });
+ } );
+ jQuery( "#first" ).load( "data/name.html", undefined, start );
+ } );
// check if load can be called with only url
asyncTest( "jQuery.fn.load( URL_SELECTOR )", 1, function() {
- jQuery("#first").load( "data/test3.html div.user", function() {
- strictEqual( jQuery( this ).children("div").length, 2, "Verify that specific elements were injected" );
+ jQuery( "#first" ).load( "data/test3.html div.user", function() {
+ strictEqual( jQuery( this ).children( "div" ).length, 2, "Verify that specific elements were injected" );
start();
- });
- });
+ } );
+ } );
// Selector should be trimmed to avoid leading spaces (#14773)
asyncTest( "jQuery.fn.load( URL_SELECTOR with spaces )", 1, function() {
- jQuery("#first").load( "data/test3.html #superuser ", function() {
- strictEqual( jQuery( this ).children("div").length, 1, "Verify that specific elements were injected" );
+ jQuery( "#first" ).load( "data/test3.html #superuser ", function() {
+ strictEqual( jQuery( this ).children( "div" ).length, 1, "Verify that specific elements were injected" );
start();
- });
- });
+ } );
+ } );
asyncTest( "jQuery.fn.load( String, Function ) - simple: inject text into DOM", 2, function() {
- jQuery("#first").load( url("data/name.html"), function() {
- ok( /^ERROR/.test(jQuery("#first").text()), "Check if content was injected into the DOM" );
+ jQuery( "#first" ).load( url( "data/name.html" ), function() {
+ ok( /^ERROR/.test( jQuery( "#first" ).text() ), "Check if content was injected into the DOM" );
start();
- });
- });
+ } );
+ } );
asyncTest( "jQuery.fn.load( String, Function ) - check scripts", 7, function() {
var verifyEvaluation = function() {
- strictEqual( window["testBar"], "bar", "Check if script src was evaluated after load" );
- strictEqual( jQuery("#ap").html(), "bar", "Check if script evaluation has modified DOM");
+ strictEqual( window[ "testBar" ], "bar", "Check if script src was evaluated after load" );
+ strictEqual( jQuery( "#ap" ).html(), "bar", "Check if script evaluation has modified DOM" );
start();
};
- Globals.register("testFoo");
- Globals.register("testBar");
+ Globals.register( "testFoo" );
+ Globals.register( "testBar" );
- jQuery("#first").load( url("data/test.html"), function() {
- ok( jQuery("#first").html().match( /^html text/ ), "Check content after loading html" );
- strictEqual( jQuery("#foo").html(), "foo", "Check if script evaluation has modified DOM" );
- strictEqual( window["testFoo"], "foo", "Check if script was evaluated after load" );
+ jQuery( "#first" ).load( url( "data/test.html" ), function() {
+ ok( jQuery( "#first" ).html().match( /^html text/ ), "Check content after loading html" );
+ strictEqual( jQuery( "#foo" ).html(), "foo", "Check if script evaluation has modified DOM" );
+ strictEqual( window[ "testFoo" ], "foo", "Check if script was evaluated after load" );
setTimeout( verifyEvaluation, 600 );
- });
- });
+ } );
+ } );
asyncTest( "jQuery.fn.load( String, Function ) - check file with only a script tag", 3, function() {
- Globals.register("testFoo");
+ Globals.register( "testFoo" );
- jQuery("#first").load( url("data/test2.html"), function() {
- strictEqual( jQuery("#foo").html(), "foo", "Check if script evaluation has modified DOM");
- strictEqual( window["testFoo"], "foo", "Check if script was evaluated after load" );
+ jQuery( "#first" ).load( url( "data/test2.html" ), function() {
+ strictEqual( jQuery( "#foo" ).html(), "foo", "Check if script evaluation has modified DOM" );
+ strictEqual( window[ "testFoo" ], "foo", "Check if script was evaluated after load" );
start();
- });
- });
+ } );
+ } );
asyncTest( "jQuery.fn.load( String, Function ) - dataFilter in ajaxSettings", 2, function() {
- jQuery.ajaxSetup({
+ jQuery.ajaxSetup( {
dataFilter: function() {
return "Hello World";
}
- });
- jQuery("
" ).load( url( "data/name.html" ), function( responseText ) {
strictEqual( jQuery( this ).html(), "Hello World", "Test div was filled with filtered data" );
strictEqual( responseText, "Hello World", "Test callback receives filtered data" );
start();
- });
- });
+ } );
+ } );
asyncTest( "jQuery.fn.load( String, Object, Function )", 2, function() {
- jQuery("
" ).load( url( "data/params_html.php" ), {
"foo": 3,
"bar": "ok"
}, function() {
- var $post = jQuery( this ).find("#post");
- strictEqual( $post.find("#foo").text(), "3", "Check if a hash of data is passed correctly" );
- strictEqual( $post.find("#bar").text(), "ok", "Check if a hash of data is passed correctly" );
+ var $post = jQuery( this ).find( "#post" );
+ strictEqual( $post.find( "#foo" ).text(), "3", "Check if a hash of data is passed correctly" );
+ strictEqual( $post.find( "#bar" ).text(), "ok", "Check if a hash of data is passed correctly" );
start();
- });
- });
+ } );
+ } );
asyncTest( "jQuery.fn.load( String, String, Function )", 2, function() {
- jQuery("
").load( url("data/params_html.php"), "foo=3&bar=ok", function() {
- var $get = jQuery( this ).find("#get");
- strictEqual( $get.find("#foo").text(), "3", "Check if a string of data is passed correctly" );
- strictEqual( $get.find("#bar").text(), "ok", "Check if a of data is passed correctly" );
+ jQuery( "
" ).load( url( "data/params_html.php" ), "foo=3&bar=ok", function() {
+ var $get = jQuery( this ).find( "#get" );
+ strictEqual( $get.find( "#foo" ).text(), "3", "Check if a string of data is passed correctly" );
+ strictEqual( $get.find( "#bar" ).text(), "ok", "Check if a of data is passed correctly" );
start();
- });
- });
+ } );
+ } );
asyncTest( "jQuery.fn.load() - callbacks get the correct parameters", 8, function() {
var completeArgs = {};
- jQuery.ajaxSetup({
+ jQuery.ajaxSetup( {
success: function( _, status, jqXHR ) {
completeArgs[ this.url ] = [ jqXHR.responseText, status, jqXHR ];
},
error: function( jqXHR, status ) {
completeArgs[ this.url ] = [ jqXHR.responseText, status, jqXHR ];
}
- });
+ } );
jQuery.when.apply(
jQuery,
- jQuery.map([
+ jQuery.map( [
{
type: "success",
url: "data/echoQuery.php?arg=pop"
@@ -2010,67 +2015,67 @@ module( "ajax", {
}
],
function( options ) {
- return jQuery.Deferred(function( defer ) {
- jQuery("#foo").load( options.url, function() {
+ return jQuery.Deferred( function( defer ) {
+ jQuery( "#foo" ).load( options.url, function() {
var args = arguments;
strictEqual( completeArgs[ options.url ].length, args.length, "same number of arguments (" + options.type + ")" );
jQuery.each( completeArgs[ options.url ], function( i, value ) {
strictEqual( args[ i ], value, "argument #" + i + " is the same (" + options.type + ")" );
- });
+ } );
defer.resolve();
- });
- });
- })
+ } );
+ } );
+ } )
).always( start );
- });
+ } );
asyncTest( "#2046 - jQuery.fn.load( String, Function ) with ajaxSetup on dataType json", 1, function() {
- jQuery.ajaxSetup({
+ jQuery.ajaxSetup( {
dataType: "json"
- });
- jQuery( document ).ajaxComplete(function( e, xml, s ) {
+ } );
+ jQuery( document ).ajaxComplete( function( e, xml, s ) {
strictEqual( s.dataType, "html", "Verify the load() dataType was html" );
- jQuery( document ).off("ajaxComplete");
+ jQuery( document ).off( "ajaxComplete" );
start();
- });
- jQuery("#first").load("data/test3.html");
- });
+ } );
+ jQuery( "#first" ).load( "data/test3.html" );
+ } );
asyncTest( "#10524 - jQuery.fn.load() - data specified in ajaxSettings is merged in", 1, function() {
var data = {
"baz": 1
};
- jQuery.ajaxSetup({
+ jQuery.ajaxSetup( {
data: {
"foo": "bar"
}
- });
- jQuery("#foo").load( "data/echoQuery.php", data );
- jQuery( document ).ajaxComplete(function( event, jqXHR, options ) {
- ok( ~options.data.indexOf("foo=bar"), "Data from ajaxSettings was used" );
+ } );
+ jQuery( "#foo" ).load( "data/echoQuery.php", data );
+ jQuery( document ).ajaxComplete( function( event, jqXHR, options ) {
+ ok( ~options.data.indexOf( "foo=bar" ), "Data from ajaxSettings was used" );
start();
- });
- });
+ } );
+ } );
//----------- jQuery.post()
asyncTest( "jQuery.post() - data", 3, function() {
jQuery.when(
jQuery.post(
- url("data/name.php"),
+ url( "data/name.php" ),
{
xml: "5-2",
length: 3
},
function( xml ) {
- jQuery( "math", xml ).each(function() {
+ jQuery( "math", xml ).each( function() {
strictEqual( jQuery( "calculation", this ).text(), "5-2", "Check for XML" );
strictEqual( jQuery( "result", this ).text(), "3", "Check for XML" );
- });
+ } );
}
),
- jQuery.ajax({
- url: url("data/echoData.php"),
+ jQuery.ajax( {
+ url: url( "data/echoData.php" ),
type: "POST",
data: {
"test": {
@@ -2081,56 +2086,56 @@ module( "ajax", {
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" );
}
- })
- ).always(function() {
+ } )
+ ).always( function() {
start();
- });
- });
+ } );
+ } );
asyncTest( "jQuery.post( String, Hash, Function ) - simple with xml", 4, function() {
jQuery.when(
jQuery.post(
- url("data/name.php"),
+ url( "data/name.php" ),
{
"xml": "5-2"
},
function( xml ) {
- jQuery( "math", xml ).each(function() {
+ jQuery( "math", xml ).each( function() {
strictEqual( jQuery( "calculation", this ).text(), "5-2", "Check for XML" );
strictEqual( jQuery( "result", this ).text(), "3", "Check for XML" );
- });
+ } );
}
),
- jQuery.post( url("data/name.php?xml=5-2"), {}, function( xml ) {
- jQuery( "math", xml ).each(function() {
+ jQuery.post( url( "data/name.php?xml=5-2" ), {}, function( xml ) {
+ jQuery( "math", xml ).each( function() {
strictEqual( jQuery( "calculation", this ).text(), "5-2", "Check for XML" );
strictEqual( jQuery( "result", this ).text(), "3", "Check for XML" );
- });
- })
- ).always(function() {
+ } );
+ } )
+ ).always( function() {
start();
- });
- });
+ } );
+ } );
asyncTest( "jQuery[get|post]( options ) - simple with xml", 2, function() {
jQuery.when.apply( jQuery,
- jQuery.map( [ "get", "post" ] , function( method ) {
- return jQuery[ method ]({
+ jQuery.map( [ "get", "post" ], function( method ) {
+ return jQuery[ method ]( {
url: url( "data/name.php" ),
data: {
"xml": "5-2"
},
success: function( xml ) {
- jQuery( "math", xml ).each(function() {
+ jQuery( "math", xml ).each( function() {
strictEqual( jQuery( "result", this ).text(), "3", "Check for XML" );
- });
+ } );
}
- });
- })
- ).always(function() {
+ } );
+ } )
+ ).always( function() {
start();
- });
- });
+ } );
+ } );
//----------- jQuery.active
@@ -2138,6 +2143,6 @@ module( "ajax", {
expect( 1 );
ok( jQuery.active === 0, "ajax active counter should be zero: " + jQuery.active );
- });
+ } );
-})();
+} )();
diff --git a/test/unit/attributes.js b/test/unit/attributes.js
index cb0322834..ec55556d1 100644
--- a/test/unit/attributes.js
+++ b/test/unit/attributes.js
@@ -1,6 +1,6 @@
module( "attributes", {
teardown: moduleTeardown
-});
+} );
function bareObj( value ) {
return value;
@@ -47,7 +47,7 @@ test( "jQuery.propFix integrity test", function() {
};
deepEqual( props, jQuery.propFix, "jQuery.propFix passes integrity check" );
-});
+} );
test( "attr(String)", function() {
expect( 50 );
@@ -56,199 +56,200 @@ test( "attr(String)", function() {
select, optgroup, option, $img, styleElem,
$button, $form, $a;
- equal( jQuery("#text1").attr("type"), "text", "Check for type attribute" );
- equal( jQuery("#radio1").attr("type"), "radio", "Check for type attribute" );
- equal( jQuery("#check1").attr("type"), "checkbox", "Check for type attribute" );
- equal( jQuery("#simon1").attr("rel"), "bookmark", "Check for rel attribute" );
- equal( jQuery("#google").attr("title"), "Google!", "Check for title attribute" );
- equal( jQuery("#mark").attr("hreflang"), "en", "Check for hreflang attribute" );
- equal( jQuery("#en").attr("lang"), "en", "Check for lang attribute" );
- equal( jQuery("#simon").attr("class"), "blog link", "Check for class attribute" );
- equal( jQuery("#name").attr("name"), "name", "Check for name attribute" );
- equal( jQuery("#text1").attr("name"), "action", "Check for name attribute" );
- ok( jQuery("#form").attr("action").indexOf("formaction") >= 0, "Check for action attribute" );
- equal( jQuery("#text1").attr("value", "t").attr("value"), "t", "Check setting the value attribute" );
- equal( jQuery("#text1").attr("value", "").attr("value"), "", "Check setting the value attribute to empty string" );
- equal( jQuery("
").attr("value"), "t", "Check setting custom attr named 'value' on a div" );
- equal( jQuery("#form").attr("blah", "blah").attr("blah"), "blah", "Set non-existent attribute on a form" );
- equal( jQuery("#foo").attr("height"), undefined, "Non existent height attribute should return undefined" );
+ equal( jQuery( "#text1" ).attr( "type" ), "text", "Check for type attribute" );
+ equal( jQuery( "#radio1" ).attr( "type" ), "radio", "Check for type attribute" );
+ equal( jQuery( "#check1" ).attr( "type" ), "checkbox", "Check for type attribute" );
+ equal( jQuery( "#simon1" ).attr( "rel" ), "bookmark", "Check for rel attribute" );
+ equal( jQuery( "#google" ).attr( "title" ), "Google!", "Check for title attribute" );
+ equal( jQuery( "#mark" ).attr( "hreflang" ), "en", "Check for hreflang attribute" );
+ equal( jQuery( "#en" ).attr( "lang" ), "en", "Check for lang attribute" );
+ equal( jQuery( "#simon" ).attr( "class" ), "blog link", "Check for class attribute" );
+ equal( jQuery( "#name" ).attr( "name" ), "name", "Check for name attribute" );
+ equal( jQuery( "#text1" ).attr( "name" ), "action", "Check for name attribute" );
+ ok( jQuery( "#form" ).attr( "action" ).indexOf( "formaction" ) >= 0, "Check for action attribute" );
+ equal( jQuery( "#text1" ).attr( "value", "t" ).attr( "value" ), "t", "Check setting the value attribute" );
+ equal( jQuery( "#text1" ).attr( "value", "" ).attr( "value" ), "", "Check setting the value attribute to empty string" );
+ equal( jQuery( "
" ).attr( "value" ), "t", "Check setting custom attr named 'value' on a div" );
+ equal( jQuery( "#form" ).attr( "blah", "blah" ).attr( "blah" ), "blah", "Set non-existent attribute on a form" );
+ equal( jQuery( "#foo" ).attr( "height" ), undefined, "Non existent height attribute should return undefined" );
// [7472] & [3113] (form contains an input with name="action" or name="id")
- extras = jQuery("
").appendTo("#testForm");
- equal( jQuery("#form").attr("action","newformaction").attr("action"), "newformaction", "Check that action attribute was changed" );
- equal( jQuery("#testForm").attr("target"), undefined, "Retrieving target does not equal the input with name=target" );
- equal( jQuery("#testForm").attr("target", "newTarget").attr("target"), "newTarget", "Set target successfully on a form" );
- equal( jQuery("#testForm").removeAttr("id").attr("id"), undefined, "Retrieving id does not equal the input with name=id after id is removed [#7472]" );
+ extras = jQuery( "
" ).appendTo( "#testForm" );
+ equal( jQuery( "#form" ).attr( "action", "newformaction" ).attr( "action" ), "newformaction", "Check that action attribute was changed" );
+ equal( jQuery( "#testForm" ).attr( "target" ), undefined, "Retrieving target does not equal the input with name=target" );
+ equal( jQuery( "#testForm" ).attr( "target", "newTarget" ).attr( "target" ), "newTarget", "Set target successfully on a form" );
+ equal( 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")
- equal( jQuery("#testForm").attr("name"), undefined, "Retrieving name does not retrieve input with name=name" );
+ equal( jQuery( "#testForm" ).attr( "name" ), undefined, "Retrieving name does not retrieve input with name=name" );
extras.remove();
- equal( jQuery("#text1").attr("maxlength"), "30", "Check for maxlength attribute" );
- equal( jQuery("#text1").attr("maxLength"), "30", "Check for maxLength attribute" );
- equal( jQuery("#area1").attr("maxLength"), "30", "Check for maxLength attribute" );
+ equal( jQuery( "#text1" ).attr( "maxlength" ), "30", "Check for maxlength attribute" );
+ equal( jQuery( "#text1" ).attr( "maxLength" ), "30", "Check for maxLength attribute" );
+ equal( jQuery( "#area1" ).attr( "maxLength" ), "30", "Check for maxLength attribute" );
// using innerHTML in IE causes href attribute to be serialized to the full path
- jQuery("
" ).attr( {
"id": "tAnchor5",
"href": "#5"
- }).appendTo("#qunit-fixture");
- equal( jQuery("#tAnchor5").attr("href"), "#5", "Check for non-absolute href (an anchor)" );
- jQuery("
").appendTo("#qunit-fixture");
- equal( jQuery("#tAnchor5").prop("href"), jQuery("#tAnchor6").prop("href"), "Check for absolute href prop on an anchor" );
+ } ).appendTo( "#qunit-fixture" );
+ equal( jQuery( "#tAnchor5" ).attr( "href" ), "#5", "Check for non-absolute href (an anchor)" );
+ jQuery( "
" ).appendTo( "#qunit-fixture" );
+ equal( jQuery( "#tAnchor5" ).prop( "href" ), jQuery( "#tAnchor6" ).prop( "href" ), "Check for absolute href prop on an anchor" );
- jQuery("").appendTo("#qunit-fixture");
- equal( jQuery("#tAnchor5").prop("href"), jQuery("#scriptSrc").prop("src"), "Check for absolute src prop on a script" );
+ jQuery( "" ).appendTo( "#qunit-fixture" );
+ equal( jQuery( "#tAnchor5" ).prop( "href" ), jQuery( "#scriptSrc" ).prop( "src" ), "Check for absolute src prop on a script" );
// list attribute is readonly by default in browsers that support it
- jQuery("#list-test").attr( "list", "datalist" );
- equal( jQuery("#list-test").attr("list"), "datalist", "Check setting list attribute" );
+ jQuery( "#list-test" ).attr( "list", "datalist" );
+ equal( jQuery( "#list-test" ).attr( "list" ), "datalist", "Check setting list attribute" );
// Related to [5574] and [5683]
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" );
- equal( $body.attr("foo"), "baz", "Make sure the dom attribute is retrieved when no expando is found" );
+ equal( $body.attr( "foo" ), "baz", "Make sure the dom attribute is retrieved when no expando is found" );
- $body.attr( "foo","cool" );
- equal( $body.attr("foo"), "cool", "Make sure that setting works well when both expando and dom attribute are available" );
+ $body.attr( "foo", "cool" );
+ equal( $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
- select = document.createElement("select");
- optgroup = document.createElement("optgroup");
- option = document.createElement("option");
+ select = document.createElement( "select" );
+ optgroup = document.createElement( "optgroup" );
+ option = document.createElement( "option" );
optgroup.appendChild( option );
select.appendChild( optgroup );
- equal( jQuery( option ).prop("selected"), true, "Make sure that a single option is selected, even when in an optgroup." );
+ equal( jQuery( option ).prop( "selected" ), true, "Make sure that a single option is selected, even when in an optgroup." );
- $img = jQuery("
").appendTo("body");
- equal( $img.attr("width"), "215", "Retrieve width attribute an an element with display:none." );
- equal( $img.attr("height"), "53", "Retrieve height attribute an an element with display:none." );
+ $img = jQuery( "
" ).appendTo( "body" );
+ equal( $img.attr( "width" ), "215", "Retrieve width attribute an an element with display:none." );
+ equal( $img.attr( "height" ), "53", "Retrieve height attribute an an element with display:none." );
// Check for style support
- styleElem = jQuery("
" ).appendTo( "#qunit-fixture" ).css( {
background: "url(UPPERlower.gif)"
- });
- ok( !!~styleElem.attr("style").indexOf("UPPERlower.gif"), "Check style attribute getter" );
- ok( !!~styleElem.attr("style", "position:absolute;").attr("style").indexOf("absolute"), "Check style setter" );
+ } );
+ ok( !!~styleElem.attr( "style" ).indexOf( "UPPERlower.gif" ), "Check style attribute getter" );
+ ok( !!~styleElem.attr( "style", "position:absolute;" ).attr( "style" ).indexOf( "absolute" ), "Check style setter" );
// Check value on button element (#1954)
- $button = jQuery("
").insertAfter("#button");
- strictEqual( $button.attr("value"), undefined, "Absence of value attribute on a button" );
- equal( $button.attr( "value", "foobar" ).attr("value"), "foobar", "Value attribute on a button does not return innerHTML" );
- equal( $button.attr("value", "baz").html(), "text", "Setting the value attribute does not change innerHTML" );
+ $button = jQuery( "
" ).insertAfter( "#button" );
+ strictEqual( $button.attr( "value" ), undefined, "Absence of value attribute on a button" );
+ equal( $button.attr( "value", "foobar" ).attr( "value" ), "foobar", "Value attribute on a button does not return innerHTML" );
+ equal( $button.attr( "value", "baz" ).html(), "text", "Setting the value attribute does not change innerHTML" );
// Attributes with a colon on a table element (#1591)
- equal( jQuery("#table").attr("test:attrib"), undefined, "Retrieving a non-existent attribute on a table with a colon does not throw an error." );
- equal( jQuery("#table").attr( "test:attrib", "foobar" ).attr("test:attrib"), "foobar", "Setting an attribute on a table with a colon does not throw an error." );
+ equal( jQuery( "#table" ).attr( "test:attrib" ), undefined, "Retrieving a non-existent attribute on a table with a colon does not throw an error." );
+ equal( jQuery( "#table" ).attr( "test:attrib", "foobar" ).attr( "test:attrib" ), "foobar", "Setting an attribute on a table with a colon does not throw an error." );
- $form = jQuery("
").appendTo("#qunit-fixture");
- equal( $form.attr("class"), "something", "Retrieve the class attribute on a form." );
+ $form = jQuery( "
" ).appendTo( "#qunit-fixture" );
+ equal( $form.attr( "class" ), "something", "Retrieve the class attribute on a form." );
- $a = jQuery("
").appendTo("#qunit-fixture");
- equal( $a.attr("onclick"), "something()", "Retrieve ^on attribute without anonymous function wrapper." );
+ $a = jQuery( "
" ).appendTo( "#qunit-fixture" );
+ equal( $a.attr( "onclick" ), "something()", "Retrieve ^on attribute without anonymous function wrapper." );
- ok( jQuery("
").attr("doesntexist") === undefined, "Make sure undefined is returned when no attribute is found." );
- ok( jQuery("
").attr("title") === undefined, "Make sure undefined is returned when no attribute is found." );
- equal( jQuery("
").attr( "title", "something" ).attr("title"), "something", "Set the title attribute." );
- ok( jQuery().attr("doesntexist") === undefined, "Make sure undefined is returned when no element is there." );
- equal( jQuery("
").attr("value"), undefined, "An unset value on a div returns undefined." );
- strictEqual( jQuery("
").attr("value"), undefined, "An unset value on a select returns undefined." );
+ ok( jQuery( "
" ).attr( "doesntexist" ) === undefined, "Make sure undefined is returned when no attribute is found." );
+ ok( jQuery( "
" ).attr( "title" ) === undefined, "Make sure undefined is returned when no attribute is found." );
+ equal( jQuery( "
" ).attr( "title", "something" ).attr( "title" ), "something", "Set the title attribute." );
+ ok( jQuery().attr( "doesntexist" ) === undefined, "Make sure undefined is returned when no element is there." );
+ equal( jQuery( "
" ).attr( "value" ), undefined, "An unset value on a div returns undefined." );
+ strictEqual( jQuery( "
" ).attr( "value" ), undefined, "An unset value on a select returns undefined." );
- $form = jQuery("#form").attr( "enctype", "multipart/form-data" );
- equal( $form.prop("enctype"), "multipart/form-data", "Set the enctype of a form (encoding in IE6/7 #6743)" );
+ $form = jQuery( "#form" ).attr( "enctype", "multipart/form-data" );
+ equal( $form.prop( "enctype" ), "multipart/form-data", "Set the enctype of a form (encoding in IE6/7 #6743)" );
-});
+} );
test( "attr(String) on cloned elements, #9646", function() {
expect( 4 );
var div,
- input = jQuery("
" );
- input.attr("name");
+ input.attr( "name" );
strictEqual( input.clone( true ).attr( "name", "test" )[ 0 ].name, "test", "Name attribute should be changed on cloned element" );
- div = jQuery("
" );
+ div.attr( "id" );
strictEqual( div.clone( true ).attr( "id", "test" )[ 0 ].id, "test", "Id attribute should be changed on cloned element" );
- input = jQuery("
" );
+ input.attr( "value" );
strictEqual( input.clone( true ).attr( "value", "test" )[ 0 ].value, "test", "Value attribute should be changed on cloned element" );
strictEqual( input.clone( true ).attr( "value", 42 )[ 0 ].value, "42", "Value attribute should be changed on cloned element" );
-});
+} );
test( "attr(String) in XML Files", function() {
expect( 3 );
var xml = createDashboardXML();
- equal( jQuery( "locations", xml ).attr("class"), "foo", "Check class attribute in XML document" );
- equal( jQuery( "location", xml ).attr("for"), "bar", "Check for attribute in XML document" );
- equal( jQuery( "location", xml ).attr("checked"), "different", "Check that hooks are not attached in XML document" );
-});
+ equal( jQuery( "locations", xml ).attr( "class" ), "foo", "Check class attribute in XML document" );
+ equal( jQuery( "location", xml ).attr( "for" ), "bar", "Check for attribute in XML document" );
+ equal( jQuery( "location", xml ).attr( "checked" ), "different", "Check that hooks are not attached in XML document" );
+} );
test( "attr(String, Function)", function() {
expect( 2 );
equal(
- jQuery("#text1").attr( "value", function() {
+ jQuery( "#text1" ).attr( "value", function() {
return this.id;
- }).attr("value"),
+ } ).attr( "value" ),
"text1",
"Set value from id"
);
equal(
- jQuery("#text1").attr( "title", function(i) {
+ jQuery( "#text1" ).attr( "title", function( i ) {
return i;
- }).attr("title"),
+ } ).attr( "title" ),
"0",
"Set value with an index"
);
-});
+} );
test( "attr(Hash)", function() {
expect( 3 );
var pass = true;
- jQuery("div").attr({
+ jQuery( "div" ).attr( {
"foo": "baz",
"zoo": "ping"
- }).each(function() {
- if ( this.getAttribute("foo") !== "baz" && this.getAttribute("zoo") !== "ping" ) {
+ } ).each( function() {
+ if ( this.getAttribute( "foo" ) !== "baz" && this.getAttribute( "zoo" ) !== "ping" ) {
pass = false;
}
- });
+ } );
ok( pass, "Set Multiple Attributes" );
equal(
- jQuery("#text1").attr({
+ jQuery( "#text1" ).attr( {
"value": function() {
- return this["id"];
- }}).attr("value"),
+ return this[ "id" ];
+ } } ).attr( "value" ),
"text1",
"Set attribute to computed value #1"
);
equal(
- jQuery("#text1").attr({
- "title": function(i) {
+ jQuery( "#text1" ).attr( {
+ "title": function( i ) {
return i;
}
- }).attr("title"),
+ } ).attr( "title" ),
"0",
"Set attribute to computed value #2"
);
-});
+} );
test( "attr(String, Object)", function() {
expect( 71 );
@@ -257,12 +258,12 @@ test( "attr(String, Object)", function() {
attributeNode, commentNode, textNode, obj,
table, td, j, type,
check, thrown, button, $radio, $radios, $svg,
- div = jQuery("div").attr("foo", "bar"),
+ div = jQuery( "div" ).attr( "foo", "bar" ),
i = 0,
fail = false;
for ( ; i < div.length; i++ ) {
- if ( div[ i ].getAttribute("foo") !== "bar" ) {
+ if ( div[ i ].getAttribute( "foo" ) !== "bar" ) {
fail = i;
break;
}
@@ -271,187 +272,187 @@ test( "attr(String, Object)", function() {
equal( fail, false, "Set Attribute, the #" + fail + " element didn't get the attribute 'foo'" );
ok(
- jQuery("#foo").attr({
+ jQuery( "#foo" ).attr( {
"width": null
- }),
+ } ),
"Try to set an attribute to nothing"
);
- jQuery("#name").attr( "name", "something" );
- equal( jQuery("#name").attr("name"), "something", "Set name attribute" );
- jQuery("#name").attr( "name", null );
- equal( jQuery("#name").attr("name"), undefined, "Remove name attribute" );
+ jQuery( "#name" ).attr( "name", "something" );
+ equal( jQuery( "#name" ).attr( "name" ), "something", "Set name attribute" );
+ jQuery( "#name" ).attr( "name", null );
+ equal( jQuery( "#name" ).attr( "name" ), undefined, "Remove name attribute" );
$input = jQuery( "
", {
name: "something",
id: "specified"
- });
- equal( $input.attr("name"), "something", "Check element creation gets/sets the name attribute." );
- equal( $input.attr("id"), "specified", "Check element creation gets/sets the id attribute." );
+ } );
+ equal( $input.attr( "name" ), "something", "Check element creation gets/sets the name attribute." );
+ equal( $input.attr( "id" ), "specified", "Check element creation gets/sets the id attribute." );
// As of fixing #11115, we only guarantee boolean property update for checked and selected
- $input = jQuery("
").attr( "checked", true );
- equal( $input.prop("checked"), true, "Setting checked updates property (verified by .prop)" );
- equal( $input[0].checked, true, "Setting checked updates property (verified by native property)" );
- $input = jQuery("
").attr( "selected", true );
- equal( $input.prop("selected"), true, "Setting selected updates property (verified by .prop)" );
- equal( $input[0].selected, true, "Setting selected updates property (verified by native property)" );
+ $input = jQuery( "
" ).attr( "checked", true );
+ equal( $input.prop( "checked" ), true, "Setting checked updates property (verified by .prop)" );
+ equal( $input[ 0 ].checked, true, "Setting checked updates property (verified by native property)" );
+ $input = jQuery( "
" ).attr( "selected", true );
+ equal( $input.prop( "selected" ), true, "Setting selected updates property (verified by .prop)" );
+ equal( $input[ 0 ].selected, true, "Setting selected updates property (verified by native property)" );
- $input = jQuery("#check2");
+ $input = jQuery( "#check2" );
$input.prop( "checked", true ).prop( "checked", false ).attr( "checked", true );
- equal( $input.attr("checked"), "checked", "Set checked (verified by .attr)" );
+ equal( $input.attr( "checked" ), "checked", "Set checked (verified by .attr)" );
$input.prop( "checked", false ).prop( "checked", true ).attr( "checked", false );
- equal( $input.attr("checked"), undefined, "Remove checked (verified by .attr)" );
+ equal( $input.attr( "checked" ), undefined, "Remove checked (verified by .attr)" );
- $input = jQuery("#text1").prop( "readOnly", true ).prop( "readOnly", false ).attr( "readonly", true );
- equal( $input.attr("readonly"), "readonly", "Set readonly (verified by .attr)" );
+ $input = jQuery( "#text1" ).prop( "readOnly", true ).prop( "readOnly", false ).attr( "readonly", true );
+ equal( $input.attr( "readonly" ), "readonly", "Set readonly (verified by .attr)" );
$input.prop( "readOnly", false ).prop( "readOnly", true ).attr( "readonly", false );
- equal( $input.attr("readonly"), undefined, "Remove readonly (verified by .attr)" );
+ equal( $input.attr( "readonly" ), undefined, "Remove readonly (verified by .attr)" );
- $input = jQuery("#check2").attr( "checked", true ).attr( "checked", false ).prop( "checked", true );
- equal( $input[0].checked, true, "Set checked property (verified by native property)" );
- equal( $input.prop("checked"), true, "Set checked property (verified by .prop)" );
- equal( $input.attr("checked"), undefined, "Setting checked property doesn't affect checked attribute" );
+ $input = jQuery( "#check2" ).attr( "checked", true ).attr( "checked", false ).prop( "checked", true );
+ equal( $input[ 0 ].checked, true, "Set checked property (verified by native property)" );
+ equal( $input.prop( "checked" ), true, "Set checked property (verified by .prop)" );
+ equal( $input.attr( "checked" ), undefined, "Setting checked property doesn't affect checked attribute" );
$input.attr( "checked", false ).attr( "checked", true ).prop( "checked", false );
- equal( $input[0].checked, false, "Clear checked property (verified by native property)" );
- equal( $input.prop("checked"), false, "Clear checked property (verified by .prop)" );
- equal( $input.attr("checked"), "checked", "Clearing checked property doesn't affect checked attribute" );
+ equal( $input[ 0 ].checked, false, "Clear checked property (verified by native property)" );
+ equal( $input.prop( "checked" ), false, "Clear checked property (verified by .prop)" );
+ equal( $input.attr( "checked" ), "checked", "Clearing checked property doesn't affect checked attribute" );
- $input = jQuery("#check2").attr( "checked", false ).attr( "checked", "checked" );
- equal( $input.attr("checked"), "checked", "Set checked to 'checked' (verified by .attr)" );
+ $input = jQuery( "#check2" ).attr( "checked", false ).attr( "checked", "checked" );
+ equal( $input.attr( "checked" ), "checked", "Set checked to 'checked' (verified by .attr)" );
- $radios = jQuery("#checkedtest").find("input[type='radio']");
- $radios.eq( 1 ).trigger("click");
- equal( $radios.eq( 1 ).prop("checked"), true, "Second radio was checked when clicked" );
- equal( $radios.eq( 0 ).attr("checked"), "checked", "First radio is still [checked]" );
+ $radios = jQuery( "#checkedtest" ).find( "input[type='radio']" );
+ $radios.eq( 1 ).trigger( "click" );
+ equal( $radios.eq( 1 ).prop( "checked" ), true, "Second radio was checked when clicked" );
+ equal( $radios.eq( 0 ).attr( "checked" ), "checked", "First radio is still [checked]" );
- $input = jQuery("#text1").attr( "readonly", false ).prop( "readOnly", true );
- equal( $input[0].readOnly, true, "Set readonly property (verified by native property)" );
- equal( $input.prop("readOnly"), true, "Set readonly property (verified by .prop)" );
+ $input = jQuery( "#text1" ).attr( "readonly", false ).prop( "readOnly", true );
+ equal( $input[ 0 ].readOnly, true, "Set readonly property (verified by native property)" );
+ equal( $input.prop( "readOnly" ), true, "Set readonly property (verified by .prop)" );
$input.attr( "readonly", true ).prop( "readOnly", false );
- equal( $input[0].readOnly, false, "Clear readonly property (verified by native property)" );
- equal( $input.prop("readOnly"), false, "Clear readonly property (verified by .prop)" );
+ equal( $input[ 0 ].readOnly, false, "Clear readonly property (verified by native property)" );
+ equal( $input.prop( "readOnly" ), false, "Clear readonly property (verified by .prop)" );
- $input = jQuery("#name").attr( "maxlength", "5" );
- equal( $input[0].maxLength, 5, "Set maxlength (verified by native property)" );
+ $input = jQuery( "#name" ).attr( "maxlength", "5" );
+ equal( $input[ 0 ].maxLength, 5, "Set maxlength (verified by native property)" );
$input.attr( "maxLength", "10" );
- equal( $input[0].maxLength, 10, "Set maxlength (verified by native property)" );
+ equal( $input[ 0 ].maxLength, 10, "Set maxlength (verified by native property)" );
// HTML5 boolean attributes
- $text = jQuery("#text1").attr({
+ $text = jQuery( "#text1" ).attr( {
"autofocus": true,
"required": true
- });
- equal( $text.attr("autofocus"), "autofocus", "Reading autofocus attribute yields 'autofocus'" );
- equal( $text.attr( "autofocus", false ).attr("autofocus"), undefined, "Setting autofocus to false removes it" );
- equal( $text.attr("required"), "required", "Reading required attribute yields 'required'" );
- equal( $text.attr( "required", false ).attr("required"), undefined, "Setting required attribute to false removes it" );
+ } );
+ equal( $text.attr( "autofocus" ), "autofocus", "Reading autofocus attribute yields 'autofocus'" );
+ equal( $text.attr( "autofocus", false ).attr( "autofocus" ), undefined, "Setting autofocus to false removes it" );
+ equal( $text.attr( "required" ), "required", "Reading required attribute yields 'required'" );
+ equal( $text.attr( "required", false ).attr( "required" ), undefined, "Setting required attribute to false removes it" );
- $details = jQuery("
").appendTo("#qunit-fixture");
- equal( $details.attr("open"), "open", "open attribute presence indicates true" );
- equal( $details.attr( "open", false ).attr("open"), undefined, "Setting open attribute to false removes it" );
+ $details = jQuery( "
" ).appendTo( "#qunit-fixture" );
+ equal( $details.attr( "open" ), "open", "open attribute presence indicates true" );
+ equal( $details.attr( "open", false ).attr( "open" ), undefined, "Setting open attribute to false removes it" );
$text.attr( "data-something", true );
- equal( $text.attr("data-something"), "true", "Set data attributes");
- equal( $text.data("something"), true, "Setting data attributes are not affected by boolean settings");
+ equal( $text.attr( "data-something" ), "true", "Set data attributes" );
+ equal( $text.data( "something" ), true, "Setting data attributes are not affected by boolean settings" );
$text.attr( "data-another", false );
- equal( $text.attr("data-another"), "false", "Set data attributes");
- equal( $text.data("another"), false, "Setting data attributes are not affected by boolean settings" );
- equal( $text.attr( "aria-disabled", false ).attr("aria-disabled"), "false", "Setting aria attributes are not affected by boolean settings" );
- $text.removeData("something").removeData("another").removeAttr("aria-disabled");
+ equal( $text.attr( "data-another" ), "false", "Set data attributes" );
+ equal( $text.data( "another" ), false, "Setting data attributes are not affected by boolean settings" );
+ equal( $text.attr( "aria-disabled", false ).attr( "aria-disabled" ), "false", "Setting aria attributes are not affected by boolean settings" );
+ $text.removeData( "something" ).removeData( "another" ).removeAttr( "aria-disabled" );
- jQuery("#foo").attr("contenteditable", true);
- equal( jQuery("#foo").attr("contenteditable"), "true", "Enumerated attributes are set properly" );
+ jQuery( "#foo" ).attr( "contenteditable", true );
+ equal( jQuery( "#foo" ).attr( "contenteditable" ), "true", "Enumerated attributes are set properly" );
- attributeNode = document.createAttribute("irrelevant");
- commentNode = document.createComment("some comment");
- textNode = document.createTextNode("some text");
+ attributeNode = document.createAttribute( "irrelevant" );
+ commentNode = document.createComment( "some comment" );
+ textNode = document.createTextNode( "some text" );
obj = {};
jQuery.each( [ commentNode, textNode, attributeNode ], function( i, elem ) {
var $elem = jQuery( elem );
$elem.attr( "nonexisting", "foo" );
- strictEqual( $elem.attr("nonexisting"), undefined, "attr(name, value) works correctly on comment and text nodes (bug #7500)." );
- });
+ strictEqual( $elem.attr( "nonexisting" ), undefined, "attr(name, value) works correctly on comment and text nodes (bug #7500)." );
+ } );
jQuery.each( [ window, document, obj, "#firstp" ], function( i, elem ) {
var oldVal = elem.nonexisting,
$elem = jQuery( elem );
- strictEqual( $elem.attr("nonexisting"), undefined, "attr works correctly for non existing attributes (bug #7500)." );
- equal( $elem.attr( "nonexisting", "foo" ).attr("nonexisting"), "foo", "attr falls back to prop on unsupported arguments" );
+ strictEqual( $elem.attr( "nonexisting" ), undefined, "attr works correctly for non existing attributes (bug #7500)." );
+ equal( $elem.attr( "nonexisting", "foo" ).attr( "nonexisting" ), "foo", "attr falls back to prop on unsupported arguments" );
elem.nonexisting = oldVal;
- });
+ } );
// Register the property on the window for the previous assertion so it will be clean up
Globals.register( "nonexisting" );
- table = jQuery("#table").append("
" );
+ td = table.find( "td" ).eq( 0 );
td.attr( "rowspan", "2" );
- equal( td[ 0 ]["rowSpan"], 2, "Check rowspan is correctly set" );
+ equal( td[ 0 ][ "rowSpan" ], 2, "Check rowspan is correctly set" );
td.attr( "colspan", "2" );
- equal( td[ 0 ]["colSpan"], 2, "Check colspan is correctly set" );
- table.attr("cellspacing", "2");
- equal( table[ 0 ]["cellSpacing"], "2", "Check cellspacing is correctly set" );
+ equal( td[ 0 ][ "colSpan" ], 2, "Check colspan is correctly set" );
+ table.attr( "cellspacing", "2" );
+ equal( table[ 0 ][ "cellSpacing" ], "2", "Check cellspacing is correctly set" );
- equal( jQuery("#area1").attr("value"), undefined, "Value attribute is distinct from value property." );
+ equal( jQuery( "#area1" ).attr( "value" ), undefined, "Value attribute is distinct from value property." );
// for #1070
- jQuery("#name").attr( "someAttr", "0" );
- equal( jQuery("#name").attr("someAttr"), "0", "Set attribute to a string of '0'" );
- jQuery("#name").attr( "someAttr", 0 );
- equal( jQuery("#name").attr("someAttr"), "0", "Set attribute to the number 0" );
- jQuery("#name").attr( "someAttr", 1 );
- equal( jQuery("#name").attr("someAttr"), "1", "Set attribute to the number 1" );
+ jQuery( "#name" ).attr( "someAttr", "0" );
+ equal( jQuery( "#name" ).attr( "someAttr" ), "0", "Set attribute to a string of '0'" );
+ jQuery( "#name" ).attr( "someAttr", 0 );
+ equal( jQuery( "#name" ).attr( "someAttr" ), "0", "Set attribute to the number 0" );
+ jQuery( "#name" ).attr( "someAttr", 1 );
+ equal( jQuery( "#name" ).attr( "someAttr" ), "1", "Set attribute to the number 1" );
// using contents will get comments regular, text, and comment nodes
- j = jQuery("#nonnodes").contents();
+ j = jQuery( "#nonnodes" ).contents();
j.attr( "name", "attrvalue" );
- equal( j.attr("name"), "attrvalue", "Check node,textnode,comment for attr" );
- j.removeAttr("name");
+ equal( j.attr( "name" ), "attrvalue", "Check node,textnode,comment for attr" );
+ j.removeAttr( "name" );
// Type
- type = jQuery("#check2").attr("type");
+ type = jQuery( "#check2" ).attr( "type" );
try {
- jQuery("#check2").attr( "type", "hidden" );
+ jQuery( "#check2" ).attr( "type", "hidden" );
ok( true, "No exception thrown on input type change" );
- } catch( e ) {
+ } catch ( e ) {
ok( true, "Exception thrown on input type change: " + e );
}
- check = document.createElement("input");
+ check = document.createElement( "input" );
thrown = true;
try {
jQuery( check ).attr( "type", "checkbox" );
- } catch( e ) {
+ } catch ( e ) {
thrown = false;
}
ok( thrown, "Exception thrown when trying to change type property" );
- equal( "checkbox", jQuery( check ).attr("type"), "Verify that you can change the type of an input element that isn't in the DOM" );
+ equal( "checkbox", jQuery( check ).attr( "type" ), "Verify that you can change the type of an input element that isn't in the DOM" );
- check = jQuery("
" );
thrown = true;
try {
check.attr( "type", "checkbox" );
- } catch( e ) {
+ } catch ( e ) {
thrown = false;
}
ok( thrown, "Exception thrown when trying to change type property" );
- equal( "checkbox", check.attr("type"), "Verify that you can change the type of an input element that isn't in the DOM" );
+ equal( "checkbox", check.attr( "type" ), "Verify that you can change the type of an input element that isn't in the DOM" );
- button = jQuery("#button");
+ button = jQuery( "#button" );
try {
button.attr( "type", "submit" );
ok( true, "No exception thrown on button type change" );
- } catch( e ) {
+ } catch ( e ) {
ok( true, "Exception thrown on button type change: " + e );
}
$radio = jQuery( "
", {
"value": "sup",
"type": "radio"
- }).appendTo("#testForm");
+ } ).appendTo( "#testForm" );
equal( $radio.val(), "sup", "Value is not reset when type is set after value on a radio" );
// Setting attributes on svg elements (bug #3116)
@@ -459,16 +460,16 @@ test( "attr(String, Object)", function() {
"
"
- ).appendTo("body");
- equal( $svg.attr( "cx", 100 ).attr("cx"), "100", "Set attribute on svg element" );
+ ).appendTo( "body" );
+ equal( $svg.attr( "cx", 100 ).attr( "cx" ), "100", "Set attribute on svg element" );
$svg.remove();
// undefined values are chainable
- jQuery("#name").attr( "maxlength", "5" ).removeAttr("nonexisting");
- equal( typeof jQuery("#name").attr( "maxlength", undefined ), "object", ".attr('attribute', undefined) is chainable (#5571)" );
- equal( jQuery("#name").attr( "maxlength", undefined ).attr("maxlength"), "5", ".attr('attribute', undefined) does not change value (#5571)" );
- equal( jQuery("#name").attr( "nonexisting", undefined ).attr("nonexisting"), undefined, ".attr('attribute', undefined) does not create attribute (#5571)" );
-});
+ jQuery( "#name" ).attr( "maxlength", "5" ).removeAttr( "nonexisting" );
+ equal( typeof jQuery( "#name" ).attr( "maxlength", undefined ), "object", ".attr('attribute', undefined) is chainable (#5571)" );
+ equal( jQuery( "#name" ).attr( "maxlength", undefined ).attr( "maxlength" ), "5", ".attr('attribute', undefined) does not change value (#5571)" );
+ equal( jQuery( "#name" ).attr( "nonexisting", undefined ).attr( "nonexisting" ), undefined, ".attr('attribute', undefined) does not create attribute (#5571)" );
+} );
test( "attr - extending the boolean attrHandle", function() {
expect( 1 );
@@ -482,18 +483,18 @@ test( "attr - extending the boolean attrHandle", function() {
called = false;
jQuery( "input" ).attr( "checked" );
ok( called, "The boolean attrHandle does not drop custom attrHandles" );
-});
+} );
test( "attr(String, Object) - Loaded via XML document", function() {
expect( 2 );
var xml = createDashboardXML(),
titles = [];
- jQuery( "tab", xml ).each(function() {
- titles.push( jQuery( this ).attr("title") );
- });
+ jQuery( "tab", xml ).each( function() {
+ titles.push( jQuery( this ).attr( "title" ) );
+ } );
equal( titles[ 0 ], "Location", "attr() in XML context: Check first title" );
equal( titles[ 1 ], "Users", "attr() in XML context: Check second title" );
-});
+} );
test( "attr(String, Object) - Loaded via XML fragment", function() {
expect( 2 );
@@ -501,121 +502,121 @@ test( "attr(String, Object) - Loaded via XML fragment", function() {
$frag = jQuery( frag );
$frag.attr( "test", "some value" );
- equal( $frag.attr("test"), "some value", "set attribute" );
+ equal( $frag.attr( "test" ), "some value", "set attribute" );
$frag.attr( "test", null );
- equal( $frag.attr("test"), undefined, "remove attribute" );
-});
+ equal( $frag.attr( "test" ), undefined, "remove attribute" );
+} );
test( "attr('tabindex')", function() {
expect( 8 );
// elements not natively tabbable
- equal( jQuery("#listWithTabIndex").attr("tabindex"), "5", "not natively tabbable, with tabindex set to 0" );
- equal( jQuery("#divWithNoTabIndex").attr("tabindex"), undefined, "not natively tabbable, no tabindex set" );
+ equal( jQuery( "#listWithTabIndex" ).attr( "tabindex" ), "5", "not natively tabbable, with tabindex set to 0" );
+ equal( jQuery( "#divWithNoTabIndex" ).attr( "tabindex" ), undefined, "not natively tabbable, no tabindex set" );
// anchor with href
- equal( jQuery("#linkWithNoTabIndex").attr("tabindex"), undefined, "anchor with href, no tabindex set" );
- equal( jQuery("#linkWithTabIndex").attr("tabindex"), "2", "anchor with href, tabindex set to 2" );
- equal( jQuery("#linkWithNegativeTabIndex").attr("tabindex"), "-1", "anchor with href, tabindex set to -1" );
+ equal( jQuery( "#linkWithNoTabIndex" ).attr( "tabindex" ), undefined, "anchor with href, no tabindex set" );
+ equal( jQuery( "#linkWithTabIndex" ).attr( "tabindex" ), "2", "anchor with href, tabindex set to 2" );
+ equal( jQuery( "#linkWithNegativeTabIndex" ).attr( "tabindex" ), "-1", "anchor with href, tabindex set to -1" );
// anchor without href
- equal( jQuery("#linkWithNoHrefWithNoTabIndex").attr("tabindex"), undefined, "anchor without href, no tabindex set" );
- equal( jQuery("#linkWithNoHrefWithTabIndex").attr("tabindex"), "1", "anchor without href, tabindex set to 2" );
- equal( jQuery("#linkWithNoHrefWithNegativeTabIndex").attr("tabindex"), "-1", "anchor without href, no tabindex set" );
-});
+ equal( jQuery( "#linkWithNoHrefWithNoTabIndex" ).attr( "tabindex" ), undefined, "anchor without href, no tabindex set" );
+ equal( jQuery( "#linkWithNoHrefWithTabIndex" ).attr( "tabindex" ), "1", "anchor without href, tabindex set to 2" );
+ equal( jQuery( "#linkWithNoHrefWithNegativeTabIndex" ).attr( "tabindex" ), "-1", "anchor without href, no tabindex set" );
+} );
test( "attr('tabindex', value)", function() {
expect( 9 );
- var element = jQuery("#divWithNoTabIndex");
- equal( element.attr("tabindex"), undefined, "start with no tabindex" );
+ var element = jQuery( "#divWithNoTabIndex" );
+ equal( element.attr( "tabindex" ), undefined, "start with no tabindex" );
// set a positive string
element.attr( "tabindex", "1" );
- equal( element.attr("tabindex"), "1", "set tabindex to 1 (string)" );
+ equal( element.attr( "tabindex" ), "1", "set tabindex to 1 (string)" );
// set a zero string
element.attr( "tabindex", "0" );
- equal( element.attr("tabindex"), "0", "set tabindex to 0 (string)" );
+ equal( element.attr( "tabindex" ), "0", "set tabindex to 0 (string)" );
// set a negative string
element.attr( "tabindex", "-1" );
- equal( element.attr("tabindex"), "-1", "set tabindex to -1 (string)" );
+ equal( element.attr( "tabindex" ), "-1", "set tabindex to -1 (string)" );
// set a positive number
element.attr( "tabindex", 1 );
- equal( element.attr("tabindex"), "1", "set tabindex to 1 (number)" );
+ equal( element.attr( "tabindex" ), "1", "set tabindex to 1 (number)" );
// set a zero number
element.attr( "tabindex", 0 );
- equal(element.attr("tabindex"), "0", "set tabindex to 0 (number)");
+ equal( element.attr( "tabindex" ), "0", "set tabindex to 0 (number)" );
// set a negative number
element.attr( "tabindex", -1 );
- equal( element.attr("tabindex"), "-1", "set tabindex to -1 (number)" );
+ equal( element.attr( "tabindex" ), "-1", "set tabindex to -1 (number)" );
- element = jQuery("#linkWithTabIndex");
- equal( element.attr("tabindex"), "2", "start with tabindex 2" );
+ element = jQuery( "#linkWithTabIndex" );
+ equal( element.attr( "tabindex" ), "2", "start with tabindex 2" );
element.attr( "tabindex", -1 );
- equal( element.attr("tabindex"), "-1", "set negative tabindex" );
-});
+ equal( element.attr( "tabindex" ), "-1", "set negative tabindex" );
+} );
test( "removeAttr(String)", function() {
expect( 12 );
var $first;
- equal( jQuery("#mark").removeAttr("class").attr("class"), undefined, "remove class" );
- equal( jQuery("#form").removeAttr("id").attr("id"), undefined, "Remove id" );
- equal( jQuery("#foo").attr( "style", "position:absolute;" ).removeAttr("style").attr("style"), undefined, "Check removing style attribute" );
- equal( jQuery("#form").attr( "style", "position:absolute;" ).removeAttr("style").attr("style"), undefined, "Check removing style attribute on a form" );
- equal( jQuery("
").appendTo("#foo").removeAttr("style").prop("style").cssText, "", "Check removing style attribute (#9699 Webkit)" );
- equal( jQuery("#fx-test-group").attr( "height", "3px" ).removeAttr("height").get( 0 ).style.height, "1px", "Removing height attribute has no effect on height set with style attribute" );
+ equal( jQuery( "#mark" ).removeAttr( "class" ).attr( "class" ), undefined, "remove class" );
+ equal( jQuery( "#form" ).removeAttr( "id" ).attr( "id" ), undefined, "Remove id" );
+ equal( jQuery( "#foo" ).attr( "style", "position:absolute;" ).removeAttr( "style" ).attr( "style" ), undefined, "Check removing style attribute" );
+ equal( jQuery( "#form" ).attr( "style", "position:absolute;" ).removeAttr( "style" ).attr( "style" ), undefined, "Check removing style attribute on a form" );
+ equal( jQuery( "
" ).appendTo( "#foo" ).removeAttr( "style" ).prop( "style" ).cssText, "", "Check removing style attribute (#9699 Webkit)" );
+ equal( jQuery( "#fx-test-group" ).attr( "height", "3px" ).removeAttr( "height" ).get( 0 ).style.height, "1px", "Removing height attribute has no effect on height set with style attribute" );
- jQuery("#check1").removeAttr("checked").prop( "checked", true ).removeAttr("checked");
- equal( document.getElementById("check1").checked, false, "removeAttr sets boolean properties to false" );
- jQuery("#text1").prop( "readOnly", true ).removeAttr("readonly");
- equal( document.getElementById("text1").readOnly, false, "removeAttr sets boolean properties to false" );
+ jQuery( "#check1" ).removeAttr( "checked" ).prop( "checked", true ).removeAttr( "checked" );
+ equal( document.getElementById( "check1" ).checked, false, "removeAttr sets boolean properties to false" );
+ jQuery( "#text1" ).prop( "readOnly", true ).removeAttr( "readonly" );
+ equal( document.getElementById( "text1" ).readOnly, false, "removeAttr sets boolean properties to false" );
- jQuery("#option2c").removeAttr("selected");
- equal( jQuery("#option2d").attr("selected"), "selected", "Removing `selected` from an option that is not selected does not remove selected from the currently selected option (#10870)" );
+ jQuery( "#option2c" ).removeAttr( "selected" );
+ equal( jQuery( "#option2d" ).attr( "selected" ), "selected", "Removing `selected` from an option that is not selected does not remove selected from the currently selected option (#10870)" );
try {
- $first = jQuery("#first").attr( "contenteditable", "true" ).removeAttr("contenteditable");
- equal( $first.attr("contenteditable"), undefined, "Remove the contenteditable attribute" );
- } catch( e ) {
+ $first = jQuery( "#first" ).attr( "contenteditable", "true" ).removeAttr( "contenteditable" );
+ equal( $first.attr( "contenteditable" ), undefined, "Remove the contenteditable attribute" );
+ } catch ( e ) {
ok( false, "Removing contenteditable threw an error (#10429)" );
}
- $first = jQuery("
");
- equal( $first.attr("Case"), "mixed", "case of attribute doesn't matter" );
- $first.removeAttr("Case");
- equal( $first.attr("Case"), undefined, "mixed-case attribute was removed" );
-});
+ $first = jQuery( "
" );
+ equal( $first.attr( "Case" ), "mixed", "case of attribute doesn't matter" );
+ $first.removeAttr( "Case" );
+ equal( $first.attr( "Case" ), undefined, "mixed-case attribute was removed" );
+} );
test( "removeAttr(String) in XML", function() {
expect( 7 );
var xml = createDashboardXML(),
iwt = jQuery( "infowindowtab", xml );
- equal( iwt.attr("normal"), "ab", "Check initial value" );
- iwt.removeAttr("Normal");
- equal( iwt.attr("normal"), "ab", "Should still be there" );
- iwt.removeAttr("normal");
- equal( iwt.attr("normal"), undefined, "Removed" );
+ equal( iwt.attr( "normal" ), "ab", "Check initial value" );
+ iwt.removeAttr( "Normal" );
+ equal( iwt.attr( "normal" ), "ab", "Should still be there" );
+ iwt.removeAttr( "normal" );
+ equal( iwt.attr( "normal" ), undefined, "Removed" );
- equal( iwt.attr("mixedCase"), "yes", "Check initial value" );
- equal( iwt.attr("mixedcase"), undefined, "toLowerCase not work good" );
- iwt.removeAttr("mixedcase");
- equal( iwt.attr("mixedCase"), "yes", "Should still be there" );
- iwt.removeAttr("mixedCase");
- equal( iwt.attr("mixedCase"), undefined, "Removed" );
-});
+ equal( iwt.attr( "mixedCase" ), "yes", "Check initial value" );
+ equal( iwt.attr( "mixedcase" ), undefined, "toLowerCase not work good" );
+ iwt.removeAttr( "mixedcase" );
+ equal( iwt.attr( "mixedCase" ), "yes", "Should still be there" );
+ iwt.removeAttr( "mixedCase" );
+ equal( iwt.attr( "mixedCase" ), undefined, "Removed" );
+} );
test( "removeAttr(Multi String, variable space width)", function() {
expect( 8 );
- var div = jQuery("
" ),
tests = {
id: "a",
alt: "b",
@@ -625,45 +626,45 @@ test( "removeAttr(Multi String, variable space width)", function() {
jQuery.each( tests, function( key, val ) {
equal( div.attr( key ), val, "Attribute `" + key + "` exists, and has a value of `" + val + "`" );
- });
+ } );
div.removeAttr( "id alt title rel " );
jQuery.each( tests, function( key ) {
equal( div.attr( key ), undefined, "Attribute `" + key + "` was removed" );
- });
-});
+ } );
+} );
test( "prop(String, Object)", function() {
expect( 17 );
- equal( jQuery("#text1").prop("value"), "Test", "Check for value attribute" );
- equal( jQuery("#text1").prop( "value", "Test2" ).prop("defaultValue"), "Test", "Check for defaultValue attribute" );
- equal( jQuery("#select2").prop("selectedIndex"), 3, "Check for selectedIndex attribute" );
- equal( jQuery("#foo").prop("nodeName").toUpperCase(), "DIV", "Check for nodeName attribute" );
- equal( jQuery("#foo").prop("tagName").toUpperCase(), "DIV", "Check for tagName attribute" );
- equal( jQuery("
").prop("selected"), false, "Check selected attribute on disconnected element." );
+ equal( jQuery( "#text1" ).prop( "value" ), "Test", "Check for value attribute" );
+ equal( jQuery( "#text1" ).prop( "value", "Test2" ).prop( "defaultValue" ), "Test", "Check for defaultValue attribute" );
+ equal( jQuery( "#select2" ).prop( "selectedIndex" ), 3, "Check for selectedIndex attribute" );
+ equal( jQuery( "#foo" ).prop( "nodeName" ).toUpperCase(), "DIV", "Check for nodeName attribute" );
+ equal( jQuery( "#foo" ).prop( "tagName" ).toUpperCase(), "DIV", "Check for tagName attribute" );
+ equal( jQuery( "
" ).prop( "selected" ), false, "Check selected attribute on disconnected element." );
- equal( jQuery("#listWithTabIndex").prop("tabindex"), 5, "Check retrieving tabindex" );
- jQuery("#text1").prop( "readonly", true );
- equal( document.getElementById("text1").readOnly, true, "Check setting readOnly property with 'readonly'" );
- equal( jQuery("#label-for").prop("for"), "action", "Check retrieving htmlFor" );
- jQuery("#text1").prop("class", "test");
- equal( document.getElementById("text1").className, "test", "Check setting className with 'class'" );
- equal( jQuery("#text1").prop("maxlength"), 30, "Check retrieving maxLength" );
- jQuery("#table").prop( "cellspacing", 1 );
- equal( jQuery("#table").prop("cellSpacing"), "1", "Check setting and retrieving cellSpacing" );
- jQuery("#table").prop( "cellpadding", 1 );
- equal( jQuery("#table").prop("cellPadding"), "1", "Check setting and retrieving cellPadding" );
- jQuery("#table").prop( "rowspan", 1 );
- equal( jQuery("#table").prop("rowSpan"), 1, "Check setting and retrieving rowSpan" );
- jQuery("#table").prop( "colspan", 1 );
- equal( jQuery("#table").prop("colSpan"), 1, "Check setting and retrieving colSpan" );
- jQuery("#table").prop( "usemap", 1 );
- equal( jQuery("#table").prop("useMap"), 1, "Check setting and retrieving useMap" );
- jQuery("#table").prop( "frameborder", 1 );
- equal( jQuery("#table").prop("frameBorder"), 1, "Check setting and retrieving frameBorder" );
-});
+ equal( jQuery( "#listWithTabIndex" ).prop( "tabindex" ), 5, "Check retrieving tabindex" );
+ jQuery( "#text1" ).prop( "readonly", true );
+ equal( document.getElementById( "text1" ).readOnly, true, "Check setting readOnly property with 'readonly'" );
+ equal( jQuery( "#label-for" ).prop( "for" ), "action", "Check retrieving htmlFor" );
+ jQuery( "#text1" ).prop( "class", "test" );
+ equal( document.getElementById( "text1" ).className, "test", "Check setting className with 'class'" );
+ equal( jQuery( "#text1" ).prop( "maxlength" ), 30, "Check retrieving maxLength" );
+ jQuery( "#table" ).prop( "cellspacing", 1 );
+ equal( jQuery( "#table" ).prop( "cellSpacing" ), "1", "Check setting and retrieving cellSpacing" );
+ jQuery( "#table" ).prop( "cellpadding", 1 );
+ equal( jQuery( "#table" ).prop( "cellPadding" ), "1", "Check setting and retrieving cellPadding" );
+ jQuery( "#table" ).prop( "rowspan", 1 );
+ equal( jQuery( "#table" ).prop( "rowSpan" ), 1, "Check setting and retrieving rowSpan" );
+ jQuery( "#table" ).prop( "colspan", 1 );
+ equal( jQuery( "#table" ).prop( "colSpan" ), 1, "Check setting and retrieving colSpan" );
+ jQuery( "#table" ).prop( "usemap", 1 );
+ equal( jQuery( "#table" ).prop( "useMap" ), 1, "Check setting and retrieving useMap" );
+ jQuery( "#table" ).prop( "frameborder", 1 );
+ equal( jQuery( "#table" ).prop( "frameBorder" ), 1, "Check setting and retrieving frameBorder" );
+} );
test( "prop(String, Object) on null/undefined", function() {
@@ -673,242 +674,243 @@ test( "prop(String, Object) on null/undefined", function() {
body = document.body,
$body = jQuery( body );
- ok( $body.prop("nextSibling") === null, "Make sure a null expando returns null" );
- body["foo"] = "bar";
- equal( $body.prop("foo"), "bar", "Make sure the expando is preferred over the dom attribute" );
- body["foo"] = undefined;
- ok( $body.prop("foo") === undefined, "Make sure the expando is preferred over the dom attribute, even if undefined" );
+ ok( $body.prop( "nextSibling" ) === null, "Make sure a null expando returns null" );
+ body[ "foo" ] = "bar";
+ equal( $body.prop( "foo" ), "bar", "Make sure the expando is preferred over the dom attribute" );
+ body[ "foo" ] = undefined;
+ ok( $body.prop( "foo" ) === undefined, "Make sure the expando is preferred over the dom attribute, even if undefined" );
- select = document.createElement("select");
- optgroup = document.createElement("optgroup");
- option = document.createElement("option");
+ select = document.createElement( "select" );
+ optgroup = document.createElement( "optgroup" );
+ option = document.createElement( "option" );
optgroup.appendChild( option );
select.appendChild( optgroup );
- equal( jQuery( option ).prop("selected"), true, "Make sure that a single option is selected, even when in an optgroup." );
- equal( jQuery( document ).prop("nodeName"), "#document", "prop works correctly on document nodes (bug #7451)." );
+ equal( jQuery( option ).prop( "selected" ), true, "Make sure that a single option is selected, even when in an optgroup." );
+ equal( jQuery( document ).prop( "nodeName" ), "#document", "prop works correctly on document nodes (bug #7451)." );
- attributeNode = document.createAttribute("irrelevant");
- commentNode = document.createComment("some comment");
- textNode = document.createTextNode("some text");
+ attributeNode = document.createAttribute( "irrelevant" );
+ commentNode = document.createComment( "some comment" );
+ textNode = document.createTextNode( "some text" );
obj = {};
jQuery.each( [ document, attributeNode, commentNode, textNode, obj, "#firstp" ], function( i, ele ) {
- strictEqual( jQuery( ele ).prop("nonexisting"), undefined, "prop works correctly for non existing attributes (bug #7500)." );
- });
+ strictEqual( jQuery( ele ).prop( "nonexisting" ), undefined, "prop works correctly for non existing attributes (bug #7500)." );
+ } );
obj = {};
jQuery.each( [ document, obj ], function( i, ele ) {
var $ele = jQuery( ele );
$ele.prop( "nonexisting", "foo" );
- equal( $ele.prop("nonexisting"), "foo", "prop(name, value) works correctly for non existing attributes (bug #7500)." );
- });
- jQuery( document ).removeProp("nonexisting");
+ equal( $ele.prop( "nonexisting" ), "foo", "prop(name, value) works correctly for non existing attributes (bug #7500)." );
+ } );
+ jQuery( document ).removeProp( "nonexisting" );
- $form = jQuery("#form").prop( "enctype", "multipart/form-data" );
- equal( $form.prop("enctype"), "multipart/form-data", "Set the enctype of a form (encoding in IE6/7 #6743)" );
-});
+ $form = jQuery( "#form" ).prop( "enctype", "multipart/form-data" );
+ equal( $form.prop( "enctype" ), "multipart/form-data", "Set the enctype of a form (encoding in IE6/7 #6743)" );
+} );
test( "prop('tabindex')", function() {
expect( 11 );
// inputs without tabIndex attribute
- equal( jQuery("#inputWithoutTabIndex").prop("tabindex"), 0, "input without tabindex" );
- equal( jQuery("#buttonWithoutTabIndex").prop("tabindex"), 0, "button without tabindex" );
- equal( jQuery("#textareaWithoutTabIndex").prop("tabindex"), 0, "textarea without tabindex" );
+ equal( jQuery( "#inputWithoutTabIndex" ).prop( "tabindex" ), 0, "input without tabindex" );
+ equal( jQuery( "#buttonWithoutTabIndex" ).prop( "tabindex" ), 0, "button without tabindex" );
+ equal( jQuery( "#textareaWithoutTabIndex" ).prop( "tabindex" ), 0, "textarea without tabindex" );
// elements not natively tabbable
- equal( jQuery("#listWithTabIndex").prop("tabindex"), 5, "not natively tabbable, with tabindex set to 0" );
- equal( jQuery("#divWithNoTabIndex").prop("tabindex"), -1, "not natively tabbable, no tabindex set" );
+ equal( jQuery( "#listWithTabIndex" ).prop( "tabindex" ), 5, "not natively tabbable, with tabindex set to 0" );
+ equal( jQuery( "#divWithNoTabIndex" ).prop( "tabindex" ), -1, "not natively tabbable, no tabindex set" );
// anchor with href
- equal( jQuery("#linkWithNoTabIndex").prop("tabindex"), 0, "anchor with href, no tabindex set" );
- equal( jQuery("#linkWithTabIndex").prop("tabindex"), 2, "anchor with href, tabindex set to 2" );
- equal( jQuery("#linkWithNegativeTabIndex").prop("tabindex"), -1, "anchor with href, tabindex set to -1" );
+ equal( jQuery( "#linkWithNoTabIndex" ).prop( "tabindex" ), 0, "anchor with href, no tabindex set" );
+ equal( jQuery( "#linkWithTabIndex" ).prop( "tabindex" ), 2, "anchor with href, tabindex set to 2" );
+ equal( jQuery( "#linkWithNegativeTabIndex" ).prop( "tabindex" ), -1, "anchor with href, tabindex set to -1" );
// anchor without href
- equal( jQuery("#linkWithNoHrefWithNoTabIndex").prop("tabindex"), -1, "anchor without href, no tabindex set" );
- equal( jQuery("#linkWithNoHrefWithTabIndex").prop("tabindex"), 1, "anchor without href, tabindex set to 2" );
- equal( jQuery("#linkWithNoHrefWithNegativeTabIndex").prop("tabindex"), -1, "anchor without href, no tabindex set" );
-});
+ equal( jQuery( "#linkWithNoHrefWithNoTabIndex" ).prop( "tabindex" ), -1, "anchor without href, no tabindex set" );
+ equal( jQuery( "#linkWithNoHrefWithTabIndex" ).prop( "tabindex" ), 1, "anchor without href, tabindex set to 2" );
+ equal( jQuery( "#linkWithNoHrefWithNegativeTabIndex" ).prop( "tabindex" ), -1, "anchor without href, no tabindex set" );
+} );
test( "prop('tabindex', value)", function() {
expect( 10 );
var clone,
- element = jQuery("#divWithNoTabIndex");
+ element = jQuery( "#divWithNoTabIndex" );
- equal( element.prop("tabindex"), -1, "start with no tabindex" );
+ equal( element.prop( "tabindex" ), -1, "start with no tabindex" );
// set a positive string
element.prop( "tabindex", "1" );
- equal( element.prop("tabindex"), 1, "set tabindex to 1 (string)" );
+ equal( element.prop( "tabindex" ), 1, "set tabindex to 1 (string)" );
// set a zero string
element.prop( "tabindex", "0" );
- equal( element.prop("tabindex"), 0, "set tabindex to 0 (string)" );
+ equal( element.prop( "tabindex" ), 0, "set tabindex to 0 (string)" );
// set a negative string
element.prop( "tabindex", "-1" );
- equal( element.prop("tabindex"), -1, "set tabindex to -1 (string)" );
+ equal( element.prop( "tabindex" ), -1, "set tabindex to -1 (string)" );
// set a positive number
element.prop( "tabindex", 1 );
- equal( element.prop("tabindex"), 1, "set tabindex to 1 (number)" );
+ equal( element.prop( "tabindex" ), 1, "set tabindex to 1 (number)" );
// set a zero number
element.prop( "tabindex", 0 );
- equal( element.prop("tabindex"), 0, "set tabindex to 0 (number)" );
+ equal( element.prop( "tabindex" ), 0, "set tabindex to 0 (number)" );
// set a negative number
element.prop( "tabindex", -1 );
- equal( element.prop("tabindex"), -1, "set tabindex to -1 (number)" );
+ equal( element.prop( "tabindex" ), -1, "set tabindex to -1 (number)" );
- element = jQuery("#linkWithTabIndex");
- equal( element.prop("tabindex"), 2, "start with tabindex 2" );
+ element = jQuery( "#linkWithTabIndex" );
+ equal( element.prop( "tabindex" ), 2, "start with tabindex 2" );
element.prop( "tabindex", -1 );
- equal( element.prop("tabindex"), -1, "set negative tabindex" );
+ equal( element.prop( "tabindex" ), -1, "set negative tabindex" );
clone = element.clone();
clone.prop( "tabindex", 1 );
- equal( clone[ 0 ].getAttribute("tabindex"), "1", "set tabindex on cloned element" );
-});
+ equal( clone[ 0 ].getAttribute( "tabindex" ), "1", "set tabindex on cloned element" );
+} );
test( "removeProp(String)", function() {
expect( 6 );
- var attributeNode = document.createAttribute("irrelevant"),
- commentNode = document.createComment("some comment"),
- textNode = document.createTextNode("some text"),
+ var attributeNode = document.createAttribute( "irrelevant" ),
+ commentNode = document.createComment( "some comment" ),
+ textNode = document.createTextNode( "some text" ),
obj = {};
strictEqual(
- jQuery( "#firstp" ).prop( "nonexisting", "foo" ).removeProp( "nonexisting" )[ 0 ]["nonexisting"],
+ jQuery( "#firstp" ).prop( "nonexisting", "foo" ).removeProp( "nonexisting" )[ 0 ][ "nonexisting" ],
undefined,
"removeprop works correctly on DOM element nodes"
);
jQuery.each( [ document, obj ], function( i, ele ) {
var $ele = jQuery( ele );
- $ele.prop( "nonexisting", "foo" ).removeProp("nonexisting");
- strictEqual( ele["nonexisting"], undefined, "removeProp works correctly on non DOM element nodes (bug #7500)." );
- });
+ $ele.prop( "nonexisting", "foo" ).removeProp( "nonexisting" );
+ strictEqual( ele[ "nonexisting" ], undefined, "removeProp works correctly on non DOM element nodes (bug #7500)." );
+ } );
jQuery.each( [ commentNode, textNode, attributeNode ], function( i, ele ) {
var $ele = jQuery( ele );
- $ele.prop( "nonexisting", "foo" ).removeProp("nonexisting");
- strictEqual( ele["nonexisting"], undefined, "removeProp works correctly on non DOM element nodes (bug #7500)." );
- });
-});
+ $ele.prop( "nonexisting", "foo" ).removeProp( "nonexisting" );
+ strictEqual( ele[ "nonexisting" ], undefined, "removeProp works correctly on non DOM element nodes (bug #7500)." );
+ } );
+} );
test( "val() after modification", function() {
expect( 1 );
- document.getElementById("text1").value = "bla";
- equal( jQuery("#text1").val(), "bla", "Check for modified value of input element" );
+ document.getElementById( "text1" ).value = "bla";
+ equal( jQuery( "#text1" ).val(), "bla", "Check for modified value of input element" );
-});
+} );
test( "val()", function() {
expect( 20 + ( jQuery.fn.serialize ? 6 : 0 ) );
var checks, $button;
- equal( jQuery("#text1").val(), "Test", "Check for value of input element" );
+ equal( jQuery( "#text1" ).val(), "Test", "Check for value of input element" );
+
// ticket #1714 this caused a JS error in IE
- equal( 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" );
+ equal( 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" );
- equal( jQuery("#select2").val(), "3", "Call val() on a single='single' select" );
+ equal( jQuery( "#select2" ).val(), "3", "Call val() on a single='single' select" );
- deepEqual( jQuery("#select3").val(), [ "1", "2" ], "Call val() on a multiple='multiple' select" );
+ deepEqual( jQuery( "#select3" ).val(), [ "1", "2" ], "Call val() on a multiple='multiple' select" );
- equal( jQuery("#option3c").val(), "2", "Call val() on a option element with value" );
+ equal( jQuery( "#option3c" ).val(), "2", "Call val() on a option element with value" );
- equal( jQuery("#option3a").val(), "", "Call val() on a option element with empty value" );
+ equal( jQuery( "#option3a" ).val(), "", "Call val() on a option element with empty value" );
- equal( jQuery("#option3e").val(), "no value", "Call val() on a option element with no value attribute" );
+ equal( jQuery( "#option3e" ).val(), "no value", "Call val() on a option element with no value attribute" );
- equal( jQuery("#option3a").val(), "", "Call val() on a option element with no value attribute" );
+ equal( jQuery( "#option3a" ).val(), "", "Call val() on a option element with no value attribute" );
- jQuery("#select3").val("");
- deepEqual( jQuery("#select3").val(), [""], "Call val() on a multiple='multiple' select" );
+ jQuery( "#select3" ).val( "" );
+ deepEqual( jQuery( "#select3" ).val(), [ "" ], "Call val() on a multiple='multiple' select" );
- deepEqual( jQuery("#select4").val(), [], "Call val() on multiple='multiple' select with all disabled options" );
+ deepEqual( jQuery( "#select4" ).val(), [], "Call val() on multiple='multiple' select with all disabled options" );
- jQuery("#select4 optgroup").add("#select4 > [disabled]").attr( "disabled", false );
- deepEqual( jQuery("#select4").val(), [ "2", "3" ], "Call val() on multiple='multiple' select with some disabled options" );
+ jQuery( "#select4 optgroup" ).add( "#select4 > [disabled]" ).attr( "disabled", false );
+ deepEqual( jQuery( "#select4" ).val(), [ "2", "3" ], "Call val() on multiple='multiple' select with some disabled options" );
- jQuery("#select4").attr( "disabled", true );
- deepEqual( jQuery("#select4").val(), [ "2", "3" ], "Call val() on disabled multiple='multiple' select" );
+ jQuery( "#select4" ).attr( "disabled", true );
+ deepEqual( jQuery( "#select4" ).val(), [ "2", "3" ], "Call val() on disabled multiple='multiple' select" );
- equal( jQuery("#select5").val(), "3", "Check value on ambiguous select." );
+ equal( jQuery( "#select5" ).val(), "3", "Check value on ambiguous select." );
- jQuery("#select5").val( 1 );
- equal( jQuery("#select5").val(), "1", "Check value on ambiguous select." );
+ jQuery( "#select5" ).val( 1 );
+ equal( jQuery( "#select5" ).val(), "1", "Check value on ambiguous select." );
- jQuery("#select5").val( 3 );
- equal( jQuery("#select5").val(), "3", "Check value on ambiguous select." );
+ jQuery( "#select5" ).val( 3 );
+ equal( jQuery( "#select5" ).val(), "3", "Check value on ambiguous select." );
strictEqual(
- jQuery("
" ).val(),
null,
"Select-one with only option disabled (#12584)"
);
if ( jQuery.fn.serialize ) {
- checks = jQuery("
" ).appendTo( "#form" );
deepEqual( checks.serialize(), "", "Get unchecked values." );
equal( checks.eq( 3 ).val(), "on", "Make sure a value of 'on' is provided if none is specified." );
- checks.val([ "2" ]);
+ checks.val( [ "2" ] );
deepEqual( checks.serialize(), "test=2", "Get a single checked value." );
- checks.val([ "1", "" ]);
+ checks.val( [ "1", "" ] );
deepEqual( checks.serialize(), "test=1&test=", "Get multiple checked values." );
- checks.val([ "", "2" ]);
+ checks.val( [ "", "2" ] );
deepEqual( checks.serialize(), "test=2&test=", "Get multiple checked values." );
- checks.val([ "1", "on" ]);
+ checks.val( [ "1", "on" ] );
deepEqual( checks.serialize(), "test=1&test=on", "Get multiple checked values." );
checks.remove();
}
- $button = jQuery("
" ).insertAfter( "#button" );
equal( $button.val(), "foobar", "Value retrieval on a button does not return innerHTML" );
- equal( $button.val("baz").html(), "text", "Setting the value does not change innerHTML" );
+ equal( $button.val( "baz" ).html(), "text", "Setting the value does not change innerHTML" );
- equal( jQuery("
").val("test").attr("value"), "test", "Setting value sets the value attribute" );
-});
+ equal( jQuery( "
" ).val( "test" ).attr( "value" ), "test", "Setting value sets the value attribute" );
+} );
-test("val() with non-matching values on dropdown list", function() {
+test( "val() with non-matching values on dropdown list", function() {
expect( 3 );
- jQuery("#select5").val( "" );
- equal( jQuery("#select5").val(), null, "Non-matching set on select-one" );
+ jQuery( "#select5" ).val( "" );
+ equal( jQuery( "#select5" ).val(), null, "Non-matching set on select-one" );
- var select6 = jQuery("
").appendTo("#form");
- jQuery(select6).val( "nothing" );
- equal( jQuery(select6).val(), null, "Non-matching set (single value) on select-multiple" );
+ var select6 = jQuery( "
" ).appendTo( "#form" );
+ jQuery( select6 ).val( "nothing" );
+ equal( jQuery( select6 ).val(), null, "Non-matching set (single value) on select-multiple" );
- jQuery(select6).val( ["nothing1", "nothing2"] );
- equal( jQuery(select6).val(), null, "Non-matching set (array of values) on select-multiple" );
+ jQuery( select6 ).val( [ "nothing1", "nothing2" ] );
+ equal( jQuery( select6 ).val(), null, "Non-matching set (array of values) on select-multiple" );
select6.remove();
-});
+} );
-if ( "value" in document.createElement("meter") &&
- "value" in document.createElement("progress") ) {
+if ( "value" in document.createElement( "meter" ) &&
+ "value" in document.createElement( "progress" ) ) {
test( "val() respects numbers without exception (Bug #9319)", function() {
expect( 4 );
- var $meter = jQuery("
" );
try {
equal( typeof $meter.val(), "number", "meter, returns a number and does not throw exception" );
@@ -917,47 +919,47 @@ if ( "value" in document.createElement("meter") &&
equal( typeof $progress.val(), "number", "progress, returns a number and does not throw exception" );
equal( $progress.val(), $progress[ 0 ].value, "progress, api matches host and does not throw exception" );
- } catch( e ) {}
+ } catch ( e ) {}
$meter.remove();
$progress.remove();
- });
+ } );
}
var testVal = function( valueObj ) {
expect( 9 );
- jQuery("#text1").val( valueObj("test") );
- equal( document.getElementById("text1").value, "test", "Check for modified (via val(String)) value of input element" );
+ jQuery( "#text1" ).val( valueObj( "test" ) );
+ equal( document.getElementById( "text1" ).value, "test", "Check for modified (via val(String)) value of input element" );
- jQuery("#text1").val( valueObj( undefined ) );
- equal( document.getElementById("text1").value, "", "Check for modified (via val(undefined)) value of input element" );
+ jQuery( "#text1" ).val( valueObj( undefined ) );
+ equal( document.getElementById( "text1" ).value, "", "Check for modified (via val(undefined)) value of input element" );
- jQuery("#text1").val( valueObj( 67 ) );
- equal( document.getElementById("text1").value, "67", "Check for modified (via val(Number)) value of input element" );
+ jQuery( "#text1" ).val( valueObj( 67 ) );
+ equal( document.getElementById( "text1" ).value, "67", "Check for modified (via val(Number)) value of input element" );
- jQuery("#text1").val( valueObj( null ) );
- equal( document.getElementById("text1").value, "", "Check for modified (via val(null)) value of input element" );
+ jQuery( "#text1" ).val( valueObj( null ) );
+ equal( document.getElementById( "text1" ).value, "", "Check for modified (via val(null)) value of input element" );
var j,
$select = jQuery( "
" ),
- $select1 = jQuery("#select1");
+ $select1 = jQuery( "#select1" );
- $select1.val( valueObj("3") );
+ $select1.val( valueObj( "3" ) );
equal( $select1.val(), "3", "Check for modified (via val(String)) value of select element" );
$select1.val( valueObj( 2 ) );
equal( $select1.val(), "2", "Check for modified (via val(Number)) value of select element" );
- $select1.append("
" );
$select1.val( valueObj( 4 ) );
equal( $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
- j = jQuery("#nonnodes").contents();
+ j = jQuery( "#nonnodes" ).contents();
j.val( valueObj( "asdf" ) );
equal( j.val(), "asdf", "Check node,textnode,comment with val()" );
- j.removeAttr("value");
+ j.removeAttr( "value" );
$select.val( valueObj( [ "1", "2" ] ) );
deepEqual( $select.val(), [ "1", "2" ], "Should set array of values" );
@@ -965,408 +967,407 @@ var testVal = function( valueObj ) {
test( "val(String/Number)", function() {
testVal( bareObj );
-});
+} );
test( "val(Function)", function() {
testVal( functionReturningObj );
-});
+} );
test( "val(Array of Numbers) (Bug #7123)", function() {
expect( 4 );
- jQuery("#form").append("
");
- var elements = jQuery("input[name=arrayTest]").val([ 1, 2 ]);
+ jQuery( "#form" ).append( "
" );
+ var elements = jQuery( "input[name=arrayTest]" ).val( [ 1, 2 ] );
ok( elements[ 0 ].checked, "First element was checked" );
ok( elements[ 1 ].checked, "Second element was checked" );
ok( !elements[ 2 ].checked, "Third element was unchecked" );
ok( !elements[ 3 ].checked, "Fourth element remained unchecked" );
elements.remove();
-});
+} );
test( "val(Function) with incoming value", function() {
expect( 10 );
- var oldVal = jQuery("#text1").val();
+ var oldVal = jQuery( "#text1" ).val();
- jQuery("#text1").val(function( i, val ) {
+ jQuery( "#text1" ).val( function( i, val ) {
equal( val, oldVal, "Make sure the incoming value is correct." );
return "test";
- });
+ } );
- equal( document.getElementById("text1").value, "test", "Check for modified (via val(String)) value of input element" );
+ equal( document.getElementById( "text1" ).value, "test", "Check for modified (via val(String)) value of input element" );
- oldVal = jQuery("#text1").val();
+ oldVal = jQuery( "#text1" ).val();
- jQuery("#text1").val(function( i, val ) {
+ jQuery( "#text1" ).val( function( i, val ) {
equal( val, oldVal, "Make sure the incoming value is correct." );
return 67;
- });
+ } );
- equal( document.getElementById("text1").value, "67", "Check for modified (via val(Number)) value of input element" );
+ equal( document.getElementById( "text1" ).value, "67", "Check for modified (via val(Number)) value of input element" );
- oldVal = jQuery("#select1").val();
+ oldVal = jQuery( "#select1" ).val();
- jQuery("#select1").val(function( i, val ) {
+ jQuery( "#select1" ).val( function( i, val ) {
equal( val, oldVal, "Make sure the incoming value is correct." );
return "3";
- });
+ } );
- equal( jQuery("#select1").val(), "3", "Check for modified (via val(String)) value of select element" );
+ equal( jQuery( "#select1" ).val(), "3", "Check for modified (via val(String)) value of select element" );
- oldVal = jQuery("#select1").val();
+ oldVal = jQuery( "#select1" ).val();
- jQuery("#select1").val(function( i, val ) {
+ jQuery( "#select1" ).val( function( i, val ) {
equal( val, oldVal, "Make sure the incoming value is correct." );
return 2;
- });
+ } );
- equal( jQuery("#select1").val(), "2", "Check for modified (via val(Number)) value of select element" );
+ equal( jQuery( "#select1" ).val(), "2", "Check for modified (via val(Number)) value of select element" );
- jQuery("#select1").append("
" );
- oldVal = jQuery("#select1").val();
+ oldVal = jQuery( "#select1" ).val();
- jQuery("#select1").val(function( i, val ) {
+ jQuery( "#select1" ).val( function( i, val ) {
equal( val, oldVal, "Make sure the incoming value is correct." );
return 4;
- });
+ } );
- equal( jQuery("#select1").val(), "4", "Should be possible to set the val() to a newly created option" );
-});
+ equal( jQuery( "#select1" ).val(), "4", "Should be possible to set the val() to a newly created option" );
+} );
// testing if a form.reset() breaks a subsequent call to a select element's .val() (in IE only)
test( "val(select) after form.reset() (Bug #2551)", function() {
expect( 3 );
- jQuery("
" ).appendTo( "#qunit-fixture" );
- jQuery("#kkk").val("gf");
+ jQuery( "#kkk" ).val( "gf" );
- document["kk"].reset();
+ document[ "kk" ].reset();
- equal( jQuery("#kkk")[ 0 ].value, "cf", "Check value of select after form reset." );
- equal( jQuery("#kkk").val(), "cf", "Check value of select after form reset." );
+ equal( jQuery( "#kkk" )[ 0 ].value, "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
- deepEqual( jQuery("#select3").val(), ["1", "2"], "Call val() on a multiple='multiple' select" );
+ deepEqual( jQuery( "#select3" ).val(), [ "1", "2" ], "Call val() on a multiple='multiple' select" );
- jQuery("#kk").remove();
-});
+ jQuery( "#kk" ).remove();
+} );
var testAddClass = function( valueObj ) {
expect( 9 );
var pass, j, i,
- div = jQuery("#qunit-fixture div");
+ div = jQuery( "#qunit-fixture div" );
- div.addClass( valueObj("test") );
+ div.addClass( valueObj( "test" ) );
pass = true;
for ( i = 0; i < div.length; i++ ) {
- if ( !~div.get( i ).className.indexOf("test") ) {
+ if ( !~div.get( i ).className.indexOf( "test" ) ) {
pass = false;
}
}
ok( pass, "Add Class" );
// using contents will get regular, text, and comment nodes
- j = jQuery("#nonnodes").contents();
- j.addClass( valueObj("asdf") );
- ok( j.hasClass("asdf"), "Check node,textnode,comment for addClass" );
+ j = jQuery( "#nonnodes" ).contents();
+ j.addClass( valueObj( "asdf" ) );
+ ok( j.hasClass( "asdf" ), "Check node,textnode,comment for addClass" );
- div = jQuery("
" );
- div.addClass( valueObj("test") );
- equal( div.attr("class"), "test", "Make sure there's no extra whitespace." );
+ div.addClass( valueObj( "test" ) );
+ equal( div.attr( "class" ), "test", "Make sure there's no extra whitespace." );
div.attr( "class", " foo" );
- div.addClass( valueObj("test") );
- equal( div.attr("class"), "foo test", "Make sure there's no extra whitespace." );
+ div.addClass( valueObj( "test" ) );
+ equal( div.attr( "class" ), "foo test", "Make sure there's no extra whitespace." );
div.attr( "class", "foo" );
- div.addClass( valueObj("bar baz") );
- equal( div.attr("class"), "foo bar baz", "Make sure there isn't too much trimming." );
+ div.addClass( valueObj( "bar baz" ) );
+ equal( div.attr( "class" ), "foo bar baz", "Make sure there isn't too much trimming." );
div.removeClass();
- div.addClass( valueObj("foo") ).addClass( valueObj("foo") );
- equal( div.attr("class"), "foo", "Do not add the same class twice in separate calls." );
+ div.addClass( valueObj( "foo" ) ).addClass( valueObj( "foo" ) );
+ equal( div.attr( "class" ), "foo", "Do not add the same class twice in separate calls." );
- div.addClass( valueObj("fo") );
- equal( div.attr("class"), "foo fo", "Adding a similar class does not get interrupted." );
- div.removeClass().addClass("wrap2");
- ok( div.addClass("wrap").hasClass("wrap"), "Can add similarly named classes");
+ div.addClass( valueObj( "fo" ) );
+ equal( div.attr( "class" ), "foo fo", "Adding a similar class does not get interrupted." );
+ div.removeClass().addClass( "wrap2" );
+ ok( div.addClass( "wrap" ).hasClass( "wrap" ), "Can add similarly named classes" );
div.removeClass();
- div.addClass( valueObj("bar bar") );
- equal( div.attr("class"), "bar", "Do not add the same class twice in the same call." );
+ div.addClass( valueObj( "bar bar" ) );
+ equal( div.attr( "class" ), "bar", "Do not add the same class twice in the same call." );
};
test( "addClass(String)", function() {
testAddClass( bareObj );
-});
+} );
test( "addClass(Function)", function() {
testAddClass( functionReturningObj );
-});
+} );
test( "addClass(Function) with incoming value", function() {
expect( 52 );
var pass, i,
- div = jQuery("#qunit-fixture div"),
- old = div.map(function() {
- return jQuery(this).attr("class") || "";
- });
+ div = jQuery( "#qunit-fixture div" ),
+ old = div.map( function() {
+ return jQuery( this ).attr( "class" ) || "";
+ } );
- div.addClass(function( i, val ) {
+ div.addClass( function( i, val ) {
if ( this.id !== "_firebugConsole" ) {
equal( val, old[ i ], "Make sure the incoming value is correct." );
return "test";
}
- });
+ } );
pass = true;
for ( i = 0; i < div.length; i++ ) {
- if ( div.get(i).className.indexOf("test") === -1 ) {
+ if ( div.get( i ).className.indexOf( "test" ) === -1 ) {
pass = false;
}
}
ok( pass, "Add Class" );
-});
+} );
-var testRemoveClass = function(valueObj) {
+var testRemoveClass = function( valueObj ) {
expect( 8 );
- var $set = jQuery("#qunit-fixture div"),
- div = document.createElement("div");
+ var $set = jQuery( "#qunit-fixture div" ),
+ div = document.createElement( "div" );
- $set.addClass("test").removeClass( valueObj("test") );
+ $set.addClass( "test" ).removeClass( valueObj( "test" ) );
- ok( !$set.is(".test"), "Remove Class" );
+ ok( !$set.is( ".test" ), "Remove Class" );
- $set.addClass("test").addClass("foo").addClass("bar");
- $set.removeClass( valueObj("test") ).removeClass( valueObj("bar") ).removeClass( valueObj("foo") );
+ $set.addClass( "test" ).addClass( "foo" ).addClass( "bar" );
+ $set.removeClass( valueObj( "test" ) ).removeClass( valueObj( "bar" ) ).removeClass( valueObj( "foo" ) );
- ok( !$set.is(".test,.bar,.foo"), "Remove multiple classes" );
+ ok( !$set.is( ".test,.bar,.foo" ), "Remove multiple classes" );
// Make sure that a null value doesn't cause problems
- $set.eq( 0 ).addClass("expected").removeClass( valueObj( null ) );
- ok( $set.eq( 0 ).is(".expected"), "Null value passed to removeClass" );
+ $set.eq( 0 ).addClass( "expected" ).removeClass( valueObj( null ) );
+ ok( $set.eq( 0 ).is( ".expected" ), "Null value passed to removeClass" );
- $set.eq( 0 ).addClass("expected").removeClass( valueObj("") );
- ok( $set.eq( 0 ).is(".expected"), "Empty string passed to removeClass" );
+ $set.eq( 0 ).addClass( "expected" ).removeClass( valueObj( "" ) );
+ ok( $set.eq( 0 ).is( ".expected" ), "Empty string passed to removeClass" );
// using contents will get regular, text, and comment nodes
- $set = jQuery("#nonnodes").contents();
- $set.removeClass( valueObj("asdf") );
- ok( !$set.hasClass("asdf"), "Check node,textnode,comment for removeClass" );
+ $set = jQuery( "#nonnodes" ).contents();
+ $set.removeClass( valueObj( "asdf" ) );
+ ok( !$set.hasClass( "asdf" ), "Check node,textnode,comment for removeClass" );
-
- jQuery( div ).removeClass( valueObj("foo") );
- strictEqual( jQuery( div ).attr("class"), undefined, "removeClass doesn't create a class attribute" );
+ jQuery( div ).removeClass( valueObj( "foo" ) );
+ strictEqual( jQuery( div ).attr( "class" ), undefined, "removeClass doesn't create a class attribute" );
div.className = " test foo ";
- jQuery( div ).removeClass( valueObj("foo") );
+ jQuery( div ).removeClass( valueObj( "foo" ) );
equal( div.className, "test", "Make sure remaining className is trimmed." );
div.className = " test ";
- jQuery( div ).removeClass( valueObj("test") );
+ jQuery( div ).removeClass( valueObj( "test" ) );
equal( div.className, "", "Make sure there is nothing left after everything is removed." );
};
test( "removeClass(String) - simple", function() {
testRemoveClass( bareObj );
-});
+} );
test( "removeClass(Function) - simple", function() {
testRemoveClass( functionReturningObj );
-});
+} );
test( "removeClass(Function) with incoming value", function() {
expect( 52 );
- var $divs = jQuery("#qunit-fixture div").addClass("test"), old = $divs.map(function() {
- return jQuery( this ).attr("class");
- });
+ var $divs = jQuery( "#qunit-fixture div" ).addClass( "test" ), old = $divs.map( function() {
+ return jQuery( this ).attr( "class" );
+ } );
- $divs.removeClass(function( i, val ) {
+ $divs.removeClass( function( i, val ) {
if ( this.id !== "_firebugConsole" ) {
equal( val, old[ i ], "Make sure the incoming value is correct." );
return "test";
}
- });
+ } );
- ok( !$divs.is(".test"), "Remove Class" );
-});
+ ok( !$divs.is( ".test" ), "Remove Class" );
+} );
test( "removeClass() removes duplicates", function() {
expect( 1 );
- var $div = jQuery( jQuery.parseHTML("
" ) );
- $div.removeClass("x");
+ $div.removeClass( "x" );
- ok( !$div.hasClass("x"), "Element with multiple same classes does not escape the wrath of removeClass()" );
-});
+ ok( !$div.hasClass( "x" ), "Element with multiple same classes does not escape the wrath of removeClass()" );
+} );
-test("removeClass(undefined) is a no-op", function() {
+test( "removeClass(undefined) is a no-op", function() {
expect( 1 );
- var $div = jQuery("
" );
$div.removeClass( undefined );
- ok( $div.hasClass("base") && $div.hasClass("second"), "Element still has classes after removeClass(undefined)" );
-});
+ ok( $div.hasClass( "base" ) && $div.hasClass( "second" ), "Element still has classes after removeClass(undefined)" );
+} );
-var testToggleClass = function(valueObj) {
+var testToggleClass = function( valueObj ) {
expect( 17 );
- var e = jQuery("#firstp");
- ok( !e.is(".test"), "Assert class not present" );
- e.toggleClass( valueObj("test") );
- ok( e.is(".test"), "Assert class present" );
- e.toggleClass( valueObj("test") );
- ok( !e.is(".test"), "Assert class not present" );
+ var e = jQuery( "#firstp" );
+ ok( !e.is( ".test" ), "Assert class not present" );
+ e.toggleClass( valueObj( "test" ) );
+ ok( e.is( ".test" ), "Assert class present" );
+ e.toggleClass( valueObj( "test" ) );
+ ok( !e.is( ".test" ), "Assert class not present" );
// class name with a boolean
- e.toggleClass( valueObj("test"), false );
- ok( !e.is(".test"), "Assert class not present" );
- e.toggleClass( valueObj("test"), true );
- ok( e.is(".test"), "Assert class present" );
- e.toggleClass( valueObj("test"), false );
- ok( !e.is(".test"), "Assert class not present" );
+ e.toggleClass( valueObj( "test" ), false );
+ ok( !e.is( ".test" ), "Assert class not present" );
+ e.toggleClass( valueObj( "test" ), true );
+ ok( e.is( ".test" ), "Assert class present" );
+ e.toggleClass( valueObj( "test" ), false );
+ ok( !e.is( ".test" ), "Assert class not present" );
// multiple class names
- e.addClass("testA testB");
- ok( e.is(".testA.testB"), "Assert 2 different classes present" );
- e.toggleClass( valueObj("testB testC") );
- ok( (e.is(".testA.testC") && !e.is(".testB")), "Assert 1 class added, 1 class removed, and 1 class kept" );
- e.toggleClass( valueObj("testA testC") );
- ok( (!e.is(".testA") && !e.is(".testB") && !e.is(".testC")), "Assert no class present" );
+ e.addClass( "testA testB" );
+ ok( e.is( ".testA.testB" ), "Assert 2 different classes present" );
+ e.toggleClass( valueObj( "testB testC" ) );
+ ok( ( e.is( ".testA.testC" ) && !e.is( ".testB" ) ), "Assert 1 class added, 1 class removed, and 1 class kept" );
+ e.toggleClass( valueObj( "testA testC" ) );
+ ok( ( !e.is( ".testA" ) && !e.is( ".testB" ) && !e.is( ".testC" ) ), "Assert no class present" );
// toggleClass storage
e.toggleClass( true );
ok( e[ 0 ].className === "", "Assert class is empty (data was empty)" );
- e.addClass("testD testE");
- ok( e.is(".testD.testE"), "Assert class present" );
+ e.addClass( "testD testE" );
+ ok( e.is( ".testD.testE" ), "Assert class present" );
e.toggleClass();
- ok( !e.is(".testD.testE"), "Assert class not present" );
- ok( jQuery._data(e[ 0 ], "__className__") === "testD testE", "Assert data was stored" );
+ ok( !e.is( ".testD.testE" ), "Assert class not present" );
+ ok( jQuery._data( e[ 0 ], "__className__" ) === "testD testE", "Assert data was stored" );
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 );
- ok( !e.is(".testD.testE"), "Assert class not present" );
+ ok( !e.is( ".testD.testE" ), "Assert class not present" );
e.toggleClass( true );
- ok( e.is(".testD.testE"), "Assert class present (restored from data)" );
+ ok( e.is( ".testD.testE" ), "Assert class present (restored from data)" );
e.toggleClass();
e.toggleClass( false );
e.toggleClass();
- ok( e.is(".testD.testE"), "Assert class present (restored from data)" );
+ ok( e.is( ".testD.testE" ), "Assert class present (restored from data)" );
// Cleanup
- e.removeClass("testD");
+ e.removeClass( "testD" );
QUnit.expectJqData( this, e[ 0 ], "__className__" );
};
test( "toggleClass(String|boolean|undefined[, boolean])", function() {
testToggleClass( bareObj );
-});
+} );
test( "toggleClass(Function[, boolean])", function() {
testToggleClass( functionReturningObj );
-});
+} );
test( "toggleClass(Function[, boolean]) with incoming value", function() {
expect( 14 );
- var e = jQuery("#firstp"),
- old = e.attr("class") || "";
+ var e = jQuery( "#firstp" ),
+ old = e.attr( "class" ) || "";
- ok( !e.is(".test"), "Assert class not present" );
+ ok( !e.is( ".test" ), "Assert class not present" );
- e.toggleClass(function( i, val ) {
+ e.toggleClass( function( i, val ) {
equal( old, val, "Make sure the incoming value is correct." );
return "test";
- });
- ok( e.is(".test"), "Assert class present" );
+ } );
+ ok( e.is( ".test" ), "Assert class present" );
- old = e.attr("class");
+ old = e.attr( "class" );
- e.toggleClass(function( i, val ) {
+ e.toggleClass( function( i, val ) {
equal( old, val, "Make sure the incoming value is correct." );
return "test";
- });
- ok( !e.is(".test"), "Assert class not present" );
+ } );
+ ok( !e.is( ".test" ), "Assert class not present" );
- old = e.attr("class") || "";
+ old = e.attr( "class" ) || "";
// class name with a boolean
- e.toggleClass(function( i, val, state ) {
+ e.toggleClass( function( i, val, state ) {
equal( old, val, "Make sure the incoming value is correct." );
equal( state, false, "Make sure that the state is passed in." );
return "test";
}, false );
- ok( !e.is(".test"), "Assert class not present" );
+ ok( !e.is( ".test" ), "Assert class not present" );
- old = e.attr("class") || "";
+ old = e.attr( "class" ) || "";
- e.toggleClass(function( i, val, state ) {
+ e.toggleClass( function( i, val, state ) {
equal( old, val, "Make sure the incoming value is correct." );
equal( state, true, "Make sure that the state is passed in." );
return "test";
}, true );
- ok( e.is(".test"), "Assert class present" );
+ ok( e.is( ".test" ), "Assert class present" );
- old = e.attr("class");
+ old = e.attr( "class" );
- e.toggleClass(function( i, val, state ) {
+ e.toggleClass( function( i, val, state ) {
equal( old, val, "Make sure the incoming value is correct." );
equal( state, false, "Make sure that the state is passed in." );
return "test";
}, false );
- ok( !e.is(".test"), "Assert class not present" );
-});
+ ok( !e.is( ".test" ), "Assert class not present" );
+} );
test( "addClass, removeClass, hasClass", function() {
expect( 17 );
- var jq = jQuery("
" ), x = jq[ 0 ];
- jq.addClass("hi");
+ jq.addClass( "hi" );
equal( x.className, "hi", "Check single added class" );
- jq.addClass("foo bar");
+ jq.addClass( "foo bar" );
equal( x.className, "hi foo bar", "Check more added classes" );
jq.removeClass();
equal( x.className, "", "Remove all classes" );
- jq.addClass("hi foo bar");
- jq.removeClass("foo");
+ jq.addClass( "hi foo bar" );
+ jq.removeClass( "foo" );
equal( x.className, "hi bar", "Check removal of one class" );
- ok( jq.hasClass("hi"), "Check has1" );
- ok( jq.hasClass("bar"), "Check has2" );
+ ok( jq.hasClass( "hi" ), "Check has1" );
+ ok( jq.hasClass( "bar" ), "Check has2" );
- jq = jQuery("
" );
- ok( jq.hasClass("class1"), "Check hasClass with line feed" );
- ok( jq.is(".class1"), "Check is with line feed" );
- ok( jq.hasClass("class2"), "Check hasClass with tab" );
- ok( jq.is(".class2"), "Check is with tab" );
- ok( jq.hasClass("cla.ss3"), "Check hasClass with dot" );
- ok( jq.hasClass("class4"), "Check hasClass with carriage return" );
- ok( jq.is(".class4"), "Check is with carriage return" );
+ ok( jq.hasClass( "class1" ), "Check hasClass with line feed" );
+ ok( jq.is( ".class1" ), "Check is with line feed" );
+ ok( jq.hasClass( "class2" ), "Check hasClass with tab" );
+ ok( jq.is( ".class2" ), "Check is with tab" );
+ ok( jq.hasClass( "cla.ss3" ), "Check hasClass with dot" );
+ ok( jq.hasClass( "class4" ), "Check hasClass with carriage return" );
+ ok( jq.is( ".class4" ), "Check is with carriage return" );
- jq.removeClass("class2");
- ok( jq.hasClass("class2") === false, "Check the class has been properly removed" );
- jq.removeClass("cla");
- ok( jq.hasClass("cla.ss3"), "Check the dotted class has not been removed" );
- jq.removeClass("cla.ss3");
- ok( jq.hasClass("cla.ss3") === false, "Check the dotted class has been removed" );
- jq.removeClass("class4");
- ok( jq.hasClass("class4") === false, "Check the class has been properly removed" );
-});
+ jq.removeClass( "class2" );
+ ok( jq.hasClass( "class2" ) === false, "Check the class has been properly removed" );
+ jq.removeClass( "cla" );
+ ok( jq.hasClass( "cla.ss3" ), "Check the dotted class has not been removed" );
+ jq.removeClass( "cla.ss3" );
+ ok( jq.hasClass( "cla.ss3" ) === false, "Check the dotted class has been removed" );
+ jq.removeClass( "class4" );
+ ok( jq.hasClass( "class4" ) === false, "Check the class has been properly removed" );
+} );
test( "addClass, removeClass, hasClass on many elements", function() {
expect( 19 );
@@ -1409,17 +1410,17 @@ test( "addClass, removeClass, hasClass on many elements", function() {
ok( !jQuery( "
" ).hasClass( "hi" ),
"Did not find a class when not present" );
-});
+} );
test( "contents().hasClass() returns correct values", function() {
expect( 2 );
- var $div = jQuery("
" ),
$contents = $div.contents();
- ok( $contents.hasClass("foo"), "Found 'foo' in $contents" );
- ok( !$contents.hasClass("undefined"), "Did not find 'undefined' in $contents (correctly)" );
-});
+ ok( $contents.hasClass( "foo" ), "Found 'foo' in $contents" );
+ ok( !$contents.hasClass( "undefined" ), "Did not find 'undefined' in $contents (correctly)" );
+} );
test( "hasClass correctly interprets non-space separators (#13835)", function() {
expect( 4 );
@@ -1433,23 +1434,23 @@ test( "hasClass correctly interprets non-space separators (#13835)", function()
},
classes = jQuery.map( map, function( separator, label ) {
return " " + separator + label + separator + " ";
- }),
+ } ),
$div = jQuery( "
" );
jQuery.each( map, function( label ) {
ok( $div.hasClass( label ), label.replace( "-", " " ) );
- });
-});
+ } );
+} );
test( "coords returns correct values in IE6/IE7, see #10828", function() {
expect( 1 );
var area,
- map = jQuery("
").find("area");
- equal( area.attr("coords"), "0,0,0,0", "did not retrieve coords correctly" );
-});
+ area = map.html( "
" ).find( "area" );
+ equal( area.attr( "coords" ), "0,0,0,0", "did not retrieve coords correctly" );
+} );
test( "should not throw at $(option).val() (#14686)", function() {
expect( 1 );
@@ -1460,12 +1461,12 @@ test( "should not throw at $(option).val() (#14686)", function() {
} catch ( _ ) {
ok( false );
}
-});
+} );
test( "option value not trimmed when setting via parent select", function() {
expect( 1 );
equal( jQuery( "
" ).val( "2" ).val(), "2" );
-});
+} );
test( "Insignificant white space returned for $(option).val() (#14858)", function() {
expect ( 3 );
@@ -1478,7 +1479,7 @@ test( "Insignificant white space returned for $(option).val() (#14858)", functio
val = jQuery( "
" ).val();
equal( val.length, 4, "insignificant white-space returned for value" );
-});
+} );
test( "SVG class manipulation (gh-2199)", function() {
@@ -1499,7 +1500,7 @@ test( "SVG class manipulation (gh-2199)", function() {
return document.createElementNS( "http://www.w3.org/2000/svg", nodeName );
}
- jQuery.each([
+ jQuery.each( [
"svg",
"rect",
"g"
@@ -1517,5 +1518,5 @@ test( "SVG class manipulation (gh-2199)", function() {
elem.toggleClass( "awesome" );
ok( !elem.hasClass( "awesome" ), "SVG element (" + this + ") toggles the class off" );
- });
-});
+ } );
+} );
diff --git a/test/unit/callbacks.js b/test/unit/callbacks.js
index b8dc8ab53..089047f03 100644
--- a/test/unit/callbacks.js
+++ b/test/unit/callbacks.js
@@ -1,8 +1,8 @@
module( "callbacks", {
teardown: moduleTeardown
-});
+} );
-(function() {
+( function() {
var output,
addToOutput = function( string ) {
@@ -10,9 +10,9 @@ var output,
output += string;
};
},
- outputA = addToOutput("A"),
- outputB = addToOutput("B"),
- outputC = addToOutput("C"),
+ outputA = addToOutput( "A" ),
+ outputB = addToOutput( "B" ),
+ outputC = addToOutput( "C" ),
tests = {
"": "XABC X XABCABCC X XBB X XABA X XX",
"once": "XABC X X X X X XABA X XX",
@@ -54,11 +54,11 @@ jQuery.each( tests, function( strFlags, resultString ) {
if ( this.length ) {
objectFlags[ this ] = true;
}
- });
+ } );
jQuery.each( filters, function( filterLabel ) {
- jQuery.each({
+ jQuery.each( {
"string": strFlags,
"object": objectFlags
}, function( flagsTypes, flags ) {
@@ -76,20 +76,20 @@ jQuery.each( tests, function( strFlags, resultString ) {
strictEqual( cblist.locked(), false, ".locked() initially false" );
strictEqual( cblist.disabled(), false, ".disabled() initially false" );
strictEqual( cblist.fired(), false, ".fired() initially false" );
- cblist.add(function( str ) {
+ cblist.add( function( str ) {
output += str;
- });
+ } );
strictEqual( cblist.fired(), false, ".fired() still false after .add" );
cblist.fire( "A" );
strictEqual( output, "XA", "Basic binding and firing" );
strictEqual( cblist.fired(), true, ".fired() detects firing" );
output = "X";
cblist.disable();
- cblist.add(function( str ) {
+ cblist.add( function( str ) {
output += str;
- });
+ } );
strictEqual( output, "X", "Adding a callback after disabling" );
- cblist.fire("A");
+ cblist.fire( "A" );
strictEqual( output, "X", "Firing after disabling" );
strictEqual( cblist.disabled(), true, ".disabled() becomes true" );
strictEqual( cblist.locked(), true, "disabling locks" );
@@ -113,20 +113,20 @@ jQuery.each( tests, function( strFlags, resultString ) {
// Basic binding and firing (context, arguments)
output = "X";
cblist = jQuery.Callbacks( flags );
- cblist.add(function() {
+ cblist.add( function() {
equal( this, window, "Basic binding and firing (context)" );
output += Array.prototype.join.call( arguments, "" );
- });
+ } );
cblist.fireWith( window, [ "A", "B" ] );
strictEqual( output, "XAB", "Basic binding and firing (arguments)" );
// fireWith with no arguments
output = "";
cblist = jQuery.Callbacks( flags );
- cblist.add(function() {
+ cblist.add( function() {
equal( this, window, "fireWith with no arguments (context is window)" );
strictEqual( arguments.length, 0, "fireWith with no arguments (no arguments)" );
- });
+ } );
cblist.fireWith();
// Basic binding, removing and firing
@@ -150,17 +150,17 @@ jQuery.each( tests, function( strFlags, resultString ) {
// Locking
output = "X";
cblist = jQuery.Callbacks( flags );
- cblist.add(function( str ) {
+ cblist.add( function( str ) {
output += str;
- });
+ } );
cblist.lock();
- cblist.add(function( str ) {
+ cblist.add( function( str ) {
output += str;
- });
- cblist.fire("A");
- cblist.add(function( str ) {
+ } );
+ cblist.fire( "A" );
+ cblist.add( function( str ) {
output += str;
- });
+ } );
strictEqual( output, "X", "Lock early" );
strictEqual( cblist.locked(), true, "Locking reflected in accessor" );
@@ -168,16 +168,16 @@ jQuery.each( tests, function( strFlags, resultString ) {
output = "X";
cblist = jQuery.Callbacks( flags );
cblist.add( cblist.lock );
- cblist.add(function( str ) {
+ cblist.add( function( str ) {
output += str;
- });
+ } );
cblist.fire( "A" );
strictEqual( output, "XA", "Locking doesn't abort execution (gh-1990)" );
// Ordering
output = "X";
cblist = jQuery.Callbacks( flags );
- cblist.add(function() {
+ cblist.add( function() {
cblist.add( outputC );
outputA();
}, outputB );
@@ -186,7 +186,7 @@ jQuery.each( tests, function( strFlags, resultString ) {
// Add and fire again
output = "X";
- cblist.add(function() {
+ cblist.add( function() {
cblist.add( outputC );
outputA();
}, outputB );
@@ -199,23 +199,23 @@ jQuery.each( tests, function( strFlags, resultString ) {
// Multiple fire
output = "X";
cblist = jQuery.Callbacks( flags );
- cblist.add(function( str ) {
+ cblist.add( function( str ) {
output += str;
- });
- cblist.fire("A");
+ } );
+ cblist.fire( "A" );
strictEqual( output, "XA", "Multiple fire (first fire)" );
output = "X";
- cblist.add(function( str ) {
+ cblist.add( function( str ) {
output += str;
- });
+ } );
strictEqual( output, results.shift(), "Multiple fire (first new callback)" );
output = "X";
- cblist.fire("B");
+ cblist.fire( "B" );
strictEqual( output, results.shift(), "Multiple fire (second fire)" );
output = "X";
- cblist.add(function( str ) {
+ cblist.add( function( str ) {
output += str;
- });
+ } );
strictEqual( output, results.shift(), "Multiple fire (second new callback)" );
// Return false
@@ -244,12 +244,12 @@ jQuery.each( tests, function( strFlags, resultString ) {
cblist.add( handler );
cblist.fire();
strictEqual( output, results.shift(), "No callback iteration" );
- });
- });
- });
-});
+ } );
+ } );
+ } );
+} );
-})();
+} )();
test( "jQuery.Callbacks( options ) - options are copied", function() {
@@ -263,25 +263,25 @@ test( "jQuery.Callbacks( options ) - options are copied", function() {
fn = function() {
ok( !( count++ ), "called once" );
};
- options["unique"] = false;
+ options[ "unique" ] = false;
cb.add( fn, fn );
cb.fire();
-});
+} );
test( "jQuery.Callbacks.fireWith - arguments are copied", function() {
expect( 1 );
- var cb = jQuery.Callbacks("memory"),
- args = ["hello"];
+ var cb = jQuery.Callbacks( "memory" ),
+ args = [ "hello" ];
cb.fireWith( null, args );
args[ 0 ] = "world";
- cb.add(function( hello ) {
+ cb.add( function( hello ) {
strictEqual( hello, "hello", "arguments are copied internally" );
- });
-});
+ } );
+} );
test( "jQuery.Callbacks.remove - should remove all instances", function() {
@@ -295,8 +295,8 @@ test( "jQuery.Callbacks.remove - should remove all instances", function() {
cb.add( fn, fn, function() {
ok( true, "end of test" );
- }).remove( fn ).fire();
-});
+ } ).remove( fn ).fire();
+} );
test( "jQuery.Callbacks.has", function() {
@@ -312,36 +312,36 @@ test( "jQuery.Callbacks.has", function() {
function getC() {
return "C";
}
- cb.add(getA, getB, getC);
+ cb.add( getA, getB, getC );
strictEqual( cb.has(), true, "No arguments to .has() returns whether callback function(s) are attached or not" );
- strictEqual( cb.has(getA), true, "Check if a specific callback function is in the Callbacks list" );
+ strictEqual( cb.has( getA ), true, "Check if a specific callback function is in the Callbacks list" );
- cb.remove(getB);
- strictEqual( cb.has(getB), false, "Remove a specific callback function and make sure its no longer there" );
- strictEqual( cb.has(getA), true, "Remove a specific callback function and make sure other callback function is still there" );
+ cb.remove( getB );
+ strictEqual( cb.has( getB ), false, "Remove a specific callback function and make sure its no longer there" );
+ strictEqual( cb.has( getA ), true, "Remove a specific callback function and make sure other callback function is still there" );
cb.empty();
strictEqual( cb.has(), false, "Empty list and make sure there are no callback function(s)" );
- strictEqual( cb.has(getA), false, "Check for a specific function in an empty() list" );
+ strictEqual( cb.has( getA ), false, "Check for a specific function in an empty() list" );
- cb.add(getA, getB, function(){
+ cb.add( getA, getB, function() {
strictEqual( cb.has(), true, "Check if list has callback function(s) from within a callback function" );
- strictEqual( cb.has(getA), true, "Check if list has a specific callback from within a callback function" );
- }).fire();
+ strictEqual( cb.has( getA ), true, "Check if list has a specific callback from within a callback function" );
+ } ).fire();
strictEqual( cb.has(), true, "Callbacks list has callback function(s) after firing" );
cb.disable();
strictEqual( cb.has(), false, "disabled() list has no callback functions (returns false)" );
- strictEqual( cb.has(getA), false, "Check for a specific function in a disabled() list" );
+ strictEqual( cb.has( getA ), false, "Check for a specific function in a disabled() list" );
- cb = jQuery.Callbacks("unique");
- cb.add(getA);
- cb.add(getA);
+ cb = jQuery.Callbacks( "unique" );
+ cb.add( getA );
+ cb.add( getA );
strictEqual( cb.has(), true, "Check if unique list has callback function(s) attached" );
cb.lock();
strictEqual( cb.has(), false, "locked() list is empty and returns false" );
-});
+} );
test( "jQuery.Callbacks() - adding a string doesn't cause a stack overflow", function() {
@@ -350,7 +350,7 @@ test( "jQuery.Callbacks() - adding a string doesn't cause a stack overflow", fun
jQuery.Callbacks().add( "hello world" );
ok( true, "no stack overflow" );
-});
+} );
test( "jQuery.Callbacks() - disabled callback doesn't fire (gh-1790)", function() {
@@ -365,4 +365,4 @@ test( "jQuery.Callbacks() - disabled callback doesn't fire (gh-1790)", function(
cb.add( shot );
cb.fire();
ok( !fired, "Disabled callback function didn't fire" );
-});
+} );
diff --git a/test/unit/core.js b/test/unit/core.js
index 688fe97a6..bf95ff04b 100644
--- a/test/unit/core.js
+++ b/test/unit/core.js
@@ -1,7 +1,7 @@
-module("core", { teardown: moduleTeardown });
+module( "core", { teardown: moduleTeardown } );
-test("Basic requirements", function() {
- expect(7);
+test( "Basic requirements", function() {
+ expect( 7 );
ok( Array.prototype.push, "Array.push()" );
ok( Function.prototype.apply, "Function.apply()" );
ok( document.getElementById, "getElementById" );
@@ -9,15 +9,15 @@ test("Basic requirements", function() {
ok( RegExp, "RegExp" );
ok( jQuery, "jQuery" );
ok( $, "$" );
-});
+} );
-test("jQuery()", function() {
+test( "jQuery()", function() {
var elem, i,
- obj = jQuery("div"),
- code = jQuery("
" ),
exec = false,
expected = 23,
attrObj = {
@@ -30,19 +30,19 @@ test("jQuery()", function() {
// few here but beware of modular builds where these methods may be excluded.
if ( jQuery.fn.click ) {
expected++;
- attrObj["click"] = function() { ok( exec, "Click executed." ); };
+ attrObj[ "click" ] = function() { ok( exec, "Click executed." ); };
}
if ( jQuery.fn.width ) {
expected++;
- attrObj["width"] = 10;
+ attrObj[ "width" ] = 10;
}
if ( jQuery.fn.offset ) {
expected++;
- attrObj["offset"] = { "top": 1, "left": 1 };
+ attrObj[ "offset" ] = { "top": 1, "left": 1 };
}
if ( jQuery.fn.css ) {
expected += 2;
- attrObj["css"] = { "paddingLeft": 1, "paddingRight": 1 };
+ attrObj[ "css" ] = { "paddingLeft": 1, "paddingRight": 1 };
}
if ( jQuery.fn.attr ) {
expected++;
@@ -53,10 +53,10 @@ test("jQuery()", function() {
// Basic constructor's behavior
equal( jQuery().length, 0, "jQuery() === jQuery([])" );
- equal( jQuery(undefined).length, 0, "jQuery(undefined) === jQuery([])" );
- equal( jQuery(null).length, 0, "jQuery(null) === jQuery([])" );
- equal( jQuery("").length, 0, "jQuery('') === jQuery([])" );
- deepEqual( jQuery(obj).get(), obj.get(), "jQuery(jQueryObj) == jQueryObj" );
+ equal( jQuery( undefined ).length, 0, "jQuery(undefined) === jQuery([])" );
+ equal( jQuery( null ).length, 0, "jQuery(null) === jQuery([])" );
+ equal( jQuery( "" ).length, 0, "jQuery('') === jQuery([])" );
+ deepEqual( jQuery( obj ).get(), obj.get(), "jQuery(jQueryObj) == jQueryObj" );
// Invalid #id goes to Sizzle which will throw an error (gh-1682)
try {
@@ -66,7 +66,7 @@ test("jQuery()", function() {
}
// can actually yield more than one, when iframes are included, the window is an array as well
- equal( jQuery(window).length, 1, "Correct number of elements generated for jQuery(window)" );
+ equal( jQuery( window ).length, 1, "Correct number of elements generated for jQuery(window)" );
/*
// disabled since this test was doing nothing. i tried to fix it but i'm not sure
@@ -95,76 +95,76 @@ test("jQuery()", function() {
equal( div.length, 4, "Correct number of elements generated for div hr code b" );
equal( div.parent().length, 0, "Make sure that the generated HTML has no parent." );
- equal( jQuery([1,2,3]).get(1), 2, "Test passing an array to the factory" );
+ equal( jQuery( [ 1,2,3 ] ).get( 1 ), 2, "Test passing an array to the factory" );
- equal( jQuery(document.body).get(0), jQuery("body").get(0), "Test passing an html node to the factory" );
+ equal( jQuery( document.body ).get( 0 ), jQuery( "body" ).get( 0 ), "Test passing an html node to the factory" );
- elem = jQuery("
" )[ 0 ];
equal( elem.nodeName.toLowerCase(), "em", "leading space" );
- elem = jQuery("\n\n
" )[ 0 ];
equal( elem.nodeName.toLowerCase(), "em", "leading newlines" );
- elem = jQuery("
", attrObj );
if ( jQuery.fn.width ) {
- equal( elem[0].style.width, "10px", "jQuery() quick setter width");
+ equal( elem[ 0 ].style.width, "10px", "jQuery() quick setter width" );
}
if ( jQuery.fn.offset ) {
- equal( elem[0].style.top, "1px", "jQuery() quick setter offset");
+ equal( elem[ 0 ].style.top, "1px", "jQuery() quick setter offset" );
}
if ( jQuery.fn.css ) {
- equal( elem[0].style.paddingLeft, "1px", "jQuery quick setter css");
- equal( elem[0].style.paddingRight, "1px", "jQuery quick setter css");
+ equal( elem[ 0 ].style.paddingLeft, "1px", "jQuery quick setter css" );
+ equal( elem[ 0 ].style.paddingRight, "1px", "jQuery quick setter css" );
}
if ( jQuery.fn.attr ) {
- equal( elem[0].getAttribute("desired"), "very", "jQuery quick setter attr");
+ equal( elem[ 0 ].getAttribute( "desired" ), "very", "jQuery quick setter attr" );
}
- equal( elem[0].childNodes.length, 1, "jQuery quick setter text");
- equal( elem[0].firstChild.nodeValue, "test", "jQuery quick setter text");
- equal( elem[0].className, "test2", "jQuery() quick setter class");
- equal( elem[0].id, "test3", "jQuery() quick setter id");
+ equal( elem[ 0 ].childNodes.length, 1, "jQuery quick setter text" );
+ equal( elem[ 0 ].firstChild.nodeValue, "test", "jQuery quick setter text" );
+ equal( elem[ 0 ].className, "test2", "jQuery() quick setter class" );
+ equal( elem[ 0 ].id, "test3", "jQuery() quick setter id" );
exec = true;
- elem.trigger("click");
+ elem.trigger( "click" );
// manually clean up detached elements
elem.remove();
for ( i = 0; i < 3; ++i ) {
- elem = jQuery("
" );
}
- equal( elem[0].defaultValue, "TEST", "Ensure cached nodes are cloned properly (Bug #6655)" );
+ equal( elem[ 0 ].defaultValue, "TEST", "Ensure cached nodes are cloned properly (Bug #6655)" );
elem = jQuery( "
", {} );
strictEqual( elem[ 0 ].ownerDocument, document,
"Empty attributes object is not interpreted as a document (trac-8950)" );
-});
+} );
-test("jQuery(selector, context)", function() {
- expect(3);
- deepEqual( jQuery("div p", "#qunit-fixture").get(), q("sndp", "en", "sap"), "Basic selector with string as context" );
- deepEqual( jQuery("div p", q("qunit-fixture")[0]).get(), q("sndp", "en", "sap"), "Basic selector with element as context" );
- deepEqual( jQuery("div p", jQuery("#qunit-fixture")).get(), q("sndp", "en", "sap"), "Basic selector with jQuery object as context" );
-});
+test( "jQuery(selector, context)", function() {
+ expect( 3 );
+ deepEqual( jQuery( "div p", "#qunit-fixture" ).get(), q( "sndp", "en", "sap" ), "Basic selector with string as context" );
+ deepEqual( jQuery( "div p", q( "qunit-fixture" )[ 0 ] ).get(), q( "sndp", "en", "sap" ), "Basic selector with element as context" );
+ deepEqual( jQuery( "div p", jQuery( "#qunit-fixture" ) ).get(), q( "sndp", "en", "sap" ), "Basic selector with jQuery object as context" );
+} );
test( "globalEval", function() {
expect( 3 );
- Globals.register("globalEvalTest");
+ Globals.register( "globalEvalTest" );
- jQuery.globalEval("globalEvalTest = 1;");
+ jQuery.globalEval( "globalEvalTest = 1;" );
equal( window.globalEvalTest, 1, "Test variable assignments are global" );
- jQuery.globalEval("var globalEvalTest = 2;");
+ jQuery.globalEval( "var globalEvalTest = 2;" );
equal( window.globalEvalTest, 2, "Test variable declarations are global" );
- jQuery.globalEval("this.globalEvalTest = 3;");
+ jQuery.globalEval( "this.globalEvalTest = 3;" );
equal( window.globalEvalTest, 3, "Test context (this) is the window object" );
-});
+} );
test( "globalEval execution after script injection (#7862)", function() {
expect( 1 );
@@ -177,41 +177,41 @@ test( "globalEval execution after script injection (#7862)", function() {
now = jQuery.now();
document.body.appendChild( script );
- jQuery.globalEval( "var strictEvalTest = " + jQuery.now() + ";");
+ jQuery.globalEval( "var strictEvalTest = " + jQuery.now() + ";" );
ok( window.strictEvalTest - now < 500, "Code executed synchronously" );
-});
+} );
// This is not run in AMD mode
if ( jQuery.noConflict ) {
- test("noConflict", function() {
- expect(7);
+ test( "noConflict", function() {
+ expect( 7 );
var $$ = jQuery;
strictEqual( jQuery, jQuery.noConflict(), "noConflict returned the jQuery object" );
- strictEqual( window["jQuery"], $$, "Make sure jQuery wasn't touched." );
- strictEqual( window["$"], original$, "Make sure $ was reverted." );
+ strictEqual( window[ "jQuery" ], $$, "Make sure jQuery wasn't touched." );
+ strictEqual( window[ "$" ], original$, "Make sure $ was reverted." );
jQuery = $ = $$;
- strictEqual( jQuery.noConflict(true), $$, "noConflict returned the jQuery object" );
- strictEqual( window["jQuery"], originaljQuery, "Make sure jQuery was reverted." );
- strictEqual( window["$"], original$, "Make sure $ was reverted." );
- ok( $$().pushStack([]), "Make sure that jQuery still works." );
+ strictEqual( jQuery.noConflict( true ), $$, "noConflict returned the jQuery object" );
+ strictEqual( window[ "jQuery" ], originaljQuery, "Make sure jQuery was reverted." );
+ strictEqual( window[ "$" ], original$, "Make sure $ was reverted." );
+ ok( $$().pushStack( [] ), "Make sure that jQuery still works." );
- window["jQuery"] = jQuery = $$;
- });
+ window[ "jQuery" ] = jQuery = $$;
+ } );
}
-test("trim", function() {
- expect(13);
+test( "trim", function() {
+ expect( 13 );
- var nbsp = String.fromCharCode(160);
+ var nbsp = String.fromCharCode( 160 );
- equal( jQuery.trim("hello "), "hello", "trailing space" );
- equal( jQuery.trim(" hello"), "hello", "leading space" );
- equal( jQuery.trim(" hello "), "hello", "space on both sides" );
- equal( jQuery.trim(" " + nbsp + "hello " + nbsp + " "), "hello", " " );
+ equal( jQuery.trim( "hello " ), "hello", "trailing space" );
+ equal( jQuery.trim( " hello" ), "hello", "leading space" );
+ equal( jQuery.trim( " hello " ), "hello", "space on both sides" );
+ equal( jQuery.trim( " " + nbsp + "hello " + nbsp + " " ), "hello", " " );
equal( jQuery.trim(), "", "Nothing in." );
equal( jQuery.trim( undefined ), "", "Undefined" );
@@ -219,85 +219,85 @@ test("trim", function() {
equal( jQuery.trim( 5 ), "5", "Number" );
equal( jQuery.trim( false ), "false", "Boolean" );
- equal( jQuery.trim(" "), "", "space should be trimmed" );
- equal( jQuery.trim("ipad\xA0"), "ipad", "nbsp should be trimmed" );
- equal( jQuery.trim("\uFEFF"), "", "zwsp should be trimmed" );
- equal( jQuery.trim("\uFEFF \xA0! | \uFEFF"), "! |", "leading/trailing should be trimmed" );
-});
+ equal( jQuery.trim( " " ), "", "space should be trimmed" );
+ equal( jQuery.trim( "ipad\xA0" ), "ipad", "nbsp should be trimmed" );
+ equal( jQuery.trim( "\uFEFF" ), "", "zwsp should be trimmed" );
+ equal( jQuery.trim( "\uFEFF \xA0! | \uFEFF" ), "! |", "leading/trailing should be trimmed" );
+} );
-test("type", function() {
+test( "type", function() {
expect( 28 );
- equal( jQuery.type(null), "null", "null" );
- equal( jQuery.type(undefined), "undefined", "undefined" );
- equal( jQuery.type(true), "boolean", "Boolean" );
- equal( jQuery.type(false), "boolean", "Boolean" );
- equal( jQuery.type(Boolean(true)), "boolean", "Boolean" );
- equal( jQuery.type(0), "number", "Number" );
- equal( jQuery.type(1), "number", "Number" );
- equal( jQuery.type(Number(1)), "number", "Number" );
- equal( jQuery.type(""), "string", "String" );
- equal( jQuery.type("a"), "string", "String" );
- equal( jQuery.type(String("a")), "string", "String" );
- equal( jQuery.type({}), "object", "Object" );
- equal( jQuery.type(/foo/), "regexp", "RegExp" );
- equal( jQuery.type(new RegExp("asdf")), "regexp", "RegExp" );
- equal( jQuery.type([1]), "array", "Array" );
- equal( jQuery.type(new Date()), "date", "Date" );
- equal( jQuery.type(new Function("return;")), "function", "Function" );
- equal( jQuery.type(function(){}), "function", "Function" );
- equal( jQuery.type(new Error()), "error", "Error" );
- equal( jQuery.type(window), "object", "Window" );
- equal( jQuery.type(document), "object", "Document" );
- equal( jQuery.type(document.body), "object", "Element" );
- equal( jQuery.type(document.createTextNode("foo")), "object", "TextNode" );
- equal( jQuery.type(document.getElementsByTagName("*")), "object", "NodeList" );
+ equal( jQuery.type( null ), "null", "null" );
+ equal( jQuery.type( undefined ), "undefined", "undefined" );
+ equal( jQuery.type( true ), "boolean", "Boolean" );
+ equal( jQuery.type( false ), "boolean", "Boolean" );
+ equal( jQuery.type( Boolean( true ) ), "boolean", "Boolean" );
+ equal( jQuery.type( 0 ), "number", "Number" );
+ equal( jQuery.type( 1 ), "number", "Number" );
+ equal( jQuery.type( Number( 1 ) ), "number", "Number" );
+ equal( jQuery.type( "" ), "string", "String" );
+ equal( jQuery.type( "a" ), "string", "String" );
+ equal( jQuery.type( String( "a" ) ), "string", "String" );
+ equal( jQuery.type( {} ), "object", "Object" );
+ equal( jQuery.type( /foo/ ), "regexp", "RegExp" );
+ equal( jQuery.type( new RegExp( "asdf" ) ), "regexp", "RegExp" );
+ equal( jQuery.type( [ 1 ] ), "array", "Array" );
+ equal( jQuery.type( new Date() ), "date", "Date" );
+ equal( jQuery.type( new Function( "return;" ) ), "function", "Function" );
+ equal( jQuery.type( function() {} ), "function", "Function" );
+ equal( jQuery.type( new Error() ), "error", "Error" );
+ equal( jQuery.type( window ), "object", "Window" );
+ equal( jQuery.type( document ), "object", "Document" );
+ equal( jQuery.type( document.body ), "object", "Element" );
+ equal( jQuery.type( document.createTextNode( "foo" ) ), "object", "TextNode" );
+ equal( jQuery.type( document.getElementsByTagName( "*" ) ), "object", "NodeList" );
// Avoid Lint complaints
var MyString = String,
MyNumber = Number,
MyBoolean = Boolean,
MyObject = Object;
- equal( jQuery.type(new MyBoolean(true)), "boolean", "Boolean" );
- equal( jQuery.type(new MyNumber(1)), "number", "Number" );
- equal( jQuery.type(new MyString("a")), "string", "String" );
- equal( jQuery.type(new MyObject()), "object", "Object" );
-});
+ equal( jQuery.type( new MyBoolean( true ) ), "boolean", "Boolean" );
+ equal( jQuery.type( new MyNumber( 1 ) ), "number", "Number" );
+ equal( jQuery.type( new MyString( "a" ) ), "string", "String" );
+ equal( jQuery.type( new MyObject() ), "object", "Object" );
+} );
-asyncTest("isPlainObject", function() {
- expect(16);
+asyncTest( "isPlainObject", function() {
+ expect( 16 );
var pass, iframe, doc,
fn = function() {};
// The use case that we want to match
- ok( jQuery.isPlainObject({}), "{}" );
+ ok( jQuery.isPlainObject( {} ), "{}" );
// Not objects shouldn't be matched
- ok( !jQuery.isPlainObject(""), "string" );
- ok( !jQuery.isPlainObject(0) && !jQuery.isPlainObject(1), "number" );
- ok( !jQuery.isPlainObject(true) && !jQuery.isPlainObject(false), "boolean" );
- ok( !jQuery.isPlainObject(null), "null" );
- ok( !jQuery.isPlainObject(undefined), "undefined" );
+ ok( !jQuery.isPlainObject( "" ), "string" );
+ ok( !jQuery.isPlainObject( 0 ) && !jQuery.isPlainObject( 1 ), "number" );
+ ok( !jQuery.isPlainObject( true ) && !jQuery.isPlainObject( false ), "boolean" );
+ ok( !jQuery.isPlainObject( null ), "null" );
+ ok( !jQuery.isPlainObject( undefined ), "undefined" );
// Arrays shouldn't be matched
- ok( !jQuery.isPlainObject([]), "array" );
+ ok( !jQuery.isPlainObject( [] ), "array" );
// Instantiated objects shouldn't be matched
- ok( !jQuery.isPlainObject(new Date()), "new Date" );
+ ok( !jQuery.isPlainObject( new Date() ), "new Date" );
// Functions shouldn't be matched
- ok( !jQuery.isPlainObject(fn), "fn" );
+ ok( !jQuery.isPlainObject( fn ), "fn" );
// Again, instantiated objects shouldn't be matched
- ok( !jQuery.isPlainObject(new fn()), "new fn (no methods)" );
+ ok( !jQuery.isPlainObject( new fn() ), "new fn (no methods)" );
// Makes the function a little more realistic
// (and harder to detect, incidentally)
- fn.prototype["someMethod"] = function(){};
+ fn.prototype[ "someMethod" ] = function() {};
// Again, instantiated objects shouldn't be matched
- ok( !jQuery.isPlainObject(new fn()), "new fn" );
+ ok( !jQuery.isPlainObject( new fn() ), "new fn" );
// Make it even harder to detect in IE < 9
fn = function() {
@@ -307,10 +307,10 @@ asyncTest("isPlainObject", function() {
b: "b"
};
- ok( !jQuery.isPlainObject(new fn()), "fn (inherited and own properties)");
+ ok( !jQuery.isPlainObject( new fn() ), "fn (inherited and own properties)" );
// DOM Element
- ok( !jQuery.isPlainObject( document.createElement("div") ), "DOM Element" );
+ ok( !jQuery.isPlainObject( document.createElement( "div" ) ), "DOM Element" );
// Window
ok( !jQuery.isPlainObject( window ), "window" );
@@ -323,27 +323,27 @@ asyncTest("isPlainObject", function() {
ok( pass, "Does not throw exceptions on host objects" );
// Objects from other windows should be matched
- Globals.register("iframeDone");
+ Globals.register( "iframeDone" );
window.iframeDone = function( otherObject, detail ) {
window.iframeDone = undefined;
iframe.parentNode.removeChild( iframe );
- ok( jQuery.isPlainObject(new otherObject()), "new otherObject" + ( detail ? " - " + detail : "" ) );
+ ok( jQuery.isPlainObject( new otherObject() ), "new otherObject" + ( detail ? " - " + detail : "" ) );
start();
};
try {
- iframe = jQuery("#qunit-fixture")[0].appendChild( document.createElement("iframe") );
+ iframe = jQuery( "#qunit-fixture" )[ 0 ].appendChild( document.createElement( "iframe" ) );
doc = iframe.contentDocument || iframe.contentWindow.document;
doc.open();
- doc.write("");
+ doc.write( "" );
doc.close();
- } catch(e) {
+ } catch ( e ) {
window.iframeDone( Object, "iframes not supported" );
}
-});
+} );
-test("isFunction", function() {
- expect(19);
+test( "isFunction", function() {
+ expect( 19 );
var mystr, myarr, myfunction, fn, obj, nodes, first, input, a;
@@ -356,31 +356,31 @@ test("isFunction", function() {
// Check built-ins
// Safari uses "(Internal Function)"
- ok( jQuery.isFunction(String), "String Function("+String+")" );
- ok( jQuery.isFunction(Array), "Array Function("+Array+")" );
- ok( jQuery.isFunction(Object), "Object Function("+Object+")" );
- ok( jQuery.isFunction(Function), "Function Function("+Function+")" );
+ ok( jQuery.isFunction( String ), "String Function(" + String + ")" );
+ ok( jQuery.isFunction( Array ), "Array Function(" + Array + ")" );
+ ok( jQuery.isFunction( Object ), "Object Function(" + Object + ")" );
+ ok( jQuery.isFunction( Function ), "Function Function(" + Function + ")" );
// When stringified, this could be misinterpreted
mystr = "function";
- ok( !jQuery.isFunction(mystr), "Function String" );
+ ok( !jQuery.isFunction( mystr ), "Function String" );
// When stringified, this could be misinterpreted
myarr = [ "function" ];
- ok( !jQuery.isFunction(myarr), "Function Array" );
+ ok( !jQuery.isFunction( myarr ), "Function Array" );
// When stringified, this could be misinterpreted
myfunction = { "function": "test" };
- ok( !jQuery.isFunction(myfunction), "Function Object" );
+ ok( !jQuery.isFunction( myfunction ), "Function Object" );
// Make sure normal functions still work
- fn = function(){};
- ok( jQuery.isFunction(fn), "Normal Function" );
+ fn = function() {};
+ ok( jQuery.isFunction( fn ), "Normal Function" );
- obj = document.createElement("object");
+ obj = document.createElement( "object" );
// Firefox says this is a function
- ok( !jQuery.isFunction(obj), "Object Element" );
+ ok( !jQuery.isFunction( obj ), "Object Element" );
// IE says this is an object
// Since 1.3, this isn't supported (#2968)
@@ -389,14 +389,14 @@ test("isFunction", function() {
nodes = document.body.childNodes;
// Safari says this is a function
- ok( !jQuery.isFunction(nodes), "childNodes Property" );
+ ok( !jQuery.isFunction( nodes ), "childNodes Property" );
first = document.body.firstChild;
// Normal elements are reported ok everywhere
- ok( !jQuery.isFunction(first), "A normal DOM Element" );
+ ok( !jQuery.isFunction( first ), "A normal DOM Element" );
- input = document.createElement("input");
+ input = document.createElement( "input" );
input.type = "text";
document.body.appendChild( input );
@@ -406,30 +406,30 @@ test("isFunction", function() {
document.body.removeChild( input );
- a = document.createElement("a");
+ a = document.createElement( "a" );
a.href = "some-function";
document.body.appendChild( a );
// This serializes with the word 'function' in it
- ok( !jQuery.isFunction(a), "Anchor Element" );
+ ok( !jQuery.isFunction( a ), "Anchor Element" );
document.body.removeChild( a );
// Recursive function calls have lengths and array-like properties
- function callme(callback){
- function fn(response){
- callback(response);
+ function callme( callback ) {
+ function fn( response ) {
+ callback( response );
}
- ok( jQuery.isFunction(fn), "Recursive Function Call" );
+ ok( jQuery.isFunction( fn ), "Recursive Function Call" );
- fn({ some: "data" });
+ fn( { some: "data" } );
}
- callme(function(){
- callme(function(){});
- });
-});
+ callme( function() {
+ callme( function() {} );
+ } );
+} );
test( "isNumeric", function() {
expect( 38 );
@@ -478,345 +478,349 @@ test( "isNumeric", function() {
equal( t( {} ), false, "Empty object" );
equal( t( [] ), false, "Empty array" );
equal( t( [ 42 ] ), false, "Array with one number" );
- equal( t( function(){} ), false, "Instance of a function" );
+ equal( t( function() {} ), false, "Instance of a function" );
equal( t( new Date() ), false, "Instance of a Date" );
-});
+} );
-test("isXMLDoc - HTML", function() {
- expect(4);
+test( "isXMLDoc - HTML", function() {
+ expect( 4 );
ok( !jQuery.isXMLDoc( document ), "HTML document" );
ok( !jQuery.isXMLDoc( document.documentElement ), "HTML documentElement" );
ok( !jQuery.isXMLDoc( document.body ), "HTML Body Element" );
var body,
- iframe = document.createElement("iframe");
+ iframe = document.createElement( "iframe" );
document.body.appendChild( iframe );
try {
- body = jQuery(iframe).contents()[0];
+ body = jQuery( iframe ).contents()[ 0 ];
try {
ok( !jQuery.isXMLDoc( body ), "Iframe body element" );
- } catch(e) {
+ } catch ( e ) {
ok( false, "Iframe body element exception" );
}
- } catch(e) {
+ } catch ( e ) {
ok( true, "Iframe body element - iframe not working correctly" );
}
document.body.removeChild( iframe );
-});
+} );
-test("XSS via location.hash", function() {
- expect(1);
+test( "XSS via location.hash", function() {
+ expect( 1 );
stop();
- jQuery["_check9521"] = function(x){
+ jQuery[ "_check9521" ] = function( x ) {
ok( x, "script called from #id-like selector with inline handler" );
- jQuery("#check9521").remove();
- delete jQuery["_check9521"];
+ jQuery( "#check9521" ).remove();
+ delete jQuery[ "_check9521" ];
start();
};
try {
- // This throws an error because it's processed like an id
- jQuery( "#
" ).appendTo("#qunit-fixture");
- } catch (err) {
- jQuery["_check9521"](true);
- }
-});
-test("isXMLDoc - XML", function() {
- expect(3);
+ // This throws an error because it's processed like an id
+ jQuery( "#
" ).appendTo( "#qunit-fixture" );
+ } catch ( err ) {
+ jQuery[ "_check9521" ]( true );
+ }
+} );
+
+test( "isXMLDoc - XML", function() {
+ expect( 3 );
var xml = createDashboardXML();
ok( jQuery.isXMLDoc( xml ), "XML document" );
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" );
+} );
-test("isWindow", function() {
+test( "isWindow", function() {
expect( 14 );
- ok( jQuery.isWindow(window), "window" );
- ok( jQuery.isWindow(document.getElementsByTagName("iframe")[0].contentWindow), "iframe.contentWindow" );
+ ok( jQuery.isWindow( window ), "window" );
+ ok( jQuery.isWindow( document.getElementsByTagName( "iframe" )[ 0 ].contentWindow ), "iframe.contentWindow" );
ok( !jQuery.isWindow(), "empty" );
- ok( !jQuery.isWindow(null), "null" );
- ok( !jQuery.isWindow(undefined), "undefined" );
- ok( !jQuery.isWindow(document), "document" );
- ok( !jQuery.isWindow(document.documentElement), "documentElement" );
- ok( !jQuery.isWindow(""), "string" );
- ok( !jQuery.isWindow(1), "number" );
- ok( !jQuery.isWindow(true), "boolean" );
- ok( !jQuery.isWindow({}), "object" );
- ok( !jQuery.isWindow({ setInterval: function(){} }), "fake window" );
- ok( !jQuery.isWindow(/window/), "regexp" );
- ok( !jQuery.isWindow(function(){}), "function" );
-});
+ ok( !jQuery.isWindow( null ), "null" );
+ ok( !jQuery.isWindow( undefined ), "undefined" );
+ ok( !jQuery.isWindow( document ), "document" );
+ ok( !jQuery.isWindow( document.documentElement ), "documentElement" );
+ ok( !jQuery.isWindow( "" ), "string" );
+ ok( !jQuery.isWindow( 1 ), "number" );
+ ok( !jQuery.isWindow( true ), "boolean" );
+ ok( !jQuery.isWindow( {} ), "object" );
+ ok( !jQuery.isWindow( { setInterval: function() {} } ), "fake window" );
+ ok( !jQuery.isWindow( /window/ ), "regexp" );
+ ok( !jQuery.isWindow( function() {} ), "function" );
+} );
-test("jQuery('html')", function() {
+test( "jQuery('html')", function() {
expect( 18 );
var s, div, j;
- jQuery["foo"] = false;
- s = jQuery("")[0];
+ jQuery[ "foo" ] = false;
+ s = jQuery( "" )[ 0 ];
ok( s, "Creating a script" );
- ok( !jQuery["foo"], "Make sure the script wasn't executed prematurely" );
- jQuery("body").append("");
- ok( jQuery["foo"], "Executing a scripts contents in the right context" );
+ ok( !jQuery[ "foo" ], "Make sure the script wasn't executed prematurely" );
+ jQuery( "body" ).append( "" );
+ ok( jQuery[ "foo" ], "Executing a scripts contents in the right context" );
// Test multi-line HTML
- div = jQuery("
" )[ 0 ];
equal( div.nodeName.toUpperCase(), "DIV", "Make sure we're getting a div." );
equal( div.firstChild.nodeType, 3, "Text node." );
equal( div.lastChild.nodeType, 3, "Text node." );
- equal( div.childNodes[1].nodeType, 1, "Paragraph." );
- equal( div.childNodes[1].firstChild.nodeType, 3, "Paragraph text." );
+ equal( div.childNodes[ 1 ].nodeType, 1, "Paragraph." );
+ equal( div.childNodes[ 1 ].firstChild.nodeType, 3, "Paragraph text." );
- ok( jQuery("
" )[ 0 ], "Creating a link" );
- ok( !jQuery("")[0].parentNode, "Create a script" );
+ ok( !jQuery( "" )[ 0 ].parentNode, "Create a script" );
- ok( jQuery("
").attr("type", "hidden"), "Create an input and set the type." );
+ ok( jQuery( "
" ).attr( "type", "hidden" ), "Create an input and set the type." );
- j = jQuery("
there " );
ok( j.length >= 2, "Check node,textnode,comment creation (some browsers delete comments)" );
- ok( !jQuery("
")[0].selected, "Make sure that options are auto-selected #2050" );
+ ok( !jQuery( "
" )[ 0 ].selected, "Make sure that options are auto-selected #2050" );
- ok( jQuery("
" )[ 0 ], "Create a table with closing tag." );
equal( jQuery( "element[attribute='
']" ).length, 0,
"When html is within brackets, do not recognize as html." );
+
//equal( jQuery( "element[attribute=
]" ).length, 0,
// "When html is within brackets, do not recognize as html." );
equal( jQuery( "element:not(
)" ).length, 0,
"When html is within parens, do not recognize as html." );
equal( jQuery( "\\
" ).length, 0, "Ignore escaped html characters" );
-});
+} );
-test("jQuery(tag-hyphenated elements) gh-1987", function() {
+test( "jQuery(tag-hyphenated elements) gh-1987", function() {
expect( 17 );
- jQuery.each( "thead tbody tfoot colgroup caption tr th td".split(" "), function( i, name ) {
- var j = jQuery("<" + name + "-d>" + name + "-d>");
- ok( j[0], "Create a tag-hyphenated elements" );
- ok( jQuery.nodeName(j[0], name.toUpperCase() + "-D"), "Tag-hyphenated element has expected node name" );
- });
+ jQuery.each( "thead tbody tfoot colgroup caption tr th td".split( " " ), function( i, name ) {
+ var j = jQuery( "<" + name + "-d>" + name + "-d>" );
+ ok( j[ 0 ], "Create a tag-hyphenated elements" );
+ ok( jQuery.nodeName( j[ 0 ], name.toUpperCase() + "-D" ), "Tag-hyphenated element has expected node name" );
+ } );
- var j = jQuery("
");
- ok( jQuery.nodeName(j[0], "TR-MULTIPLE-HYPHENS"), "Element with multiple hyphens in its tag has expected node name" );
-});
+ var j = jQuery( "
" );
+ ok( jQuery.nodeName( j[ 0 ], "TR-MULTIPLE-HYPHENS" ), "Element with multiple hyphens in its tag has expected node name" );
+} );
-test("jQuery('massive html #7990')", function() {
+test( "jQuery('massive html #7990')", function() {
expect( 3 );
var i,
li = "
very very very very large html string",
- html = ["
"];
+ html = [ "" ];
for ( i = 0; i < 30000; i += 1 ) {
- html[html.length] = li;
+ html[ html.length ] = li;
}
- html[html.length] = "
";
- html = jQuery(html.join(""))[0];
- equal( html.nodeName.toLowerCase(), "ul");
- equal( html.firstChild.nodeName.toLowerCase(), "li");
+ html[ html.length ] = "
";
+ html = jQuery( html.join( "" ) )[ 0 ];
+ equal( html.nodeName.toLowerCase(), "ul" );
+ equal( html.firstChild.nodeName.toLowerCase(), "li" );
equal( html.childNodes.length, 30000 );
-});
+} );
-test("jQuery('html', context)", function() {
- expect(1);
+test( "jQuery('html', context)", function() {
+ expect( 1 );
- var $div = jQuery("
")[0],
- $span = jQuery("
", $div);
- equal($span.length, 1, "verify a span created with a div context works, #1763");
-});
+ var $div = jQuery( "
" )[ 0 ],
+ $span = jQuery( "
", $div );
+ equal( $span.length, 1, "verify a span created with a div context works, #1763" );
+} );
-test("jQuery(selector, xml).text(str) - loaded via xml document", function() {
- expect(2);
+test( "jQuery(selector, xml).text(str) - loaded via xml document", function() {
+ expect( 2 );
var xml = createDashboardXML(),
+
// tests for #1419 where ie was a problem
- tab = jQuery("tab", xml).eq(0);
+ tab = jQuery( "tab", xml ).eq( 0 );
equal( tab.text(), "blabla", "verify initial text correct" );
- tab.text("newtext");
+ tab.text( "newtext" );
equal( tab.text(), "newtext", "verify new text correct" );
-});
+} );
-test("end()", function() {
- expect(3);
- equal( "Yahoo", jQuery("#yahoo").parent().end().text(), "check for end" );
- ok( jQuery("#yahoo").end(), "check for end with nothing to end" );
+test( "end()", function() {
+ expect( 3 );
+ equal( "Yahoo", jQuery( "#yahoo" ).parent().end().text(), "check for end" );
+ ok( jQuery( "#yahoo" ).end(), "check for end with nothing to end" );
- var x = jQuery("#yahoo");
+ var x = jQuery( "#yahoo" );
x.parent();
- equal( "Yahoo", jQuery("#yahoo").text(), "check for non-destructive behaviour" );
-});
+ equal( "Yahoo", jQuery( "#yahoo" ).text(), "check for non-destructive behaviour" );
+} );
-test("length", function() {
- expect(1);
- equal( jQuery("#qunit-fixture p").length, 6, "Get Number of Elements Found" );
-});
+test( "length", function() {
+ expect( 1 );
+ equal( jQuery( "#qunit-fixture p" ).length, 6, "Get Number of Elements Found" );
+} );
-test("get()", function() {
- expect(1);
- deepEqual( jQuery("#qunit-fixture p").get(), q("firstp","ap","sndp","en","sap","first"), "Get All Elements" );
-});
+test( "get()", function() {
+ expect( 1 );
+ deepEqual( jQuery( "#qunit-fixture p" ).get(), q( "firstp", "ap", "sndp", "en", "sap", "first" ), "Get All Elements" );
+} );
-test("toArray()", function() {
- expect(1);
- deepEqual( jQuery("#qunit-fixture p").toArray(),
- q("firstp","ap","sndp","en","sap","first"),
+test( "toArray()", function() {
+ expect( 1 );
+ deepEqual( jQuery( "#qunit-fixture p" ).toArray(),
+ q( "firstp", "ap", "sndp", "en", "sap", "first" ),
"Convert jQuery object to an Array" );
-});
+} );
-test("inArray()", function() {
- expect(19);
+test( "inArray()", function() {
+ expect( 19 );
var selections = {
- p: q("firstp", "sap", "ap", "first"),
- em: q("siblingnext", "siblingfirst"),
- div: q("qunit-testrunner-toolbar", "nothiddendiv", "nothiddendivchild", "foo"),
- a: q("mark", "groups", "google", "simon1"),
+ p: q( "firstp", "sap", "ap", "first" ),
+ em: q( "siblingnext", "siblingfirst" ),
+ div: q( "qunit-testrunner-toolbar", "nothiddendiv", "nothiddendivchild", "foo" ),
+ a: q( "mark", "groups", "google", "simon1" ),
empty: []
},
tests = {
- p: { elem: jQuery("#ap")[0], index: 2 },
- em: { elem: jQuery("#siblingfirst")[0], index: 1 },
- div: { elem: jQuery("#nothiddendiv")[0], index: 1 },
- a: { elem: jQuery("#simon1")[0], index: 3 }
+ p: { elem: jQuery( "#ap" )[ 0 ], index: 2 },
+ em: { elem: jQuery( "#siblingfirst" )[ 0 ], index: 1 },
+ div: { elem: jQuery( "#nothiddendiv" )[ 0 ], index: 1 },
+ a: { elem: jQuery( "#simon1" )[ 0 ], index: 3 }
},
falseTests = {
- p: jQuery("#liveSpan1")[0],
- em: jQuery("#nothiddendiv")[0],
+ p: jQuery( "#liveSpan1" )[ 0 ],
+ em: jQuery( "#nothiddendiv" )[ 0 ],
empty: ""
};
jQuery.each( tests, function( key, obj ) {
equal( jQuery.inArray( obj.elem, selections[ key ] ), obj.index, "elem is in the array of selections of its tag" );
+
// Third argument (fromIndex)
equal( !!~jQuery.inArray( obj.elem, selections[ key ], 5 ), false, "elem is NOT in the array of selections given a starting index greater than its position" );
equal( !!~jQuery.inArray( obj.elem, selections[ key ], 1 ), true, "elem is in the array of selections given a starting index less than or equal to its position" );
equal( !!~jQuery.inArray( obj.elem, selections[ key ], -3 ), true, "elem is in the array of selections given a negative index" );
- });
+ } );
jQuery.each( falseTests, function( key, elem ) {
equal( !!~jQuery.inArray( elem, selections[ key ] ), false, "elem is NOT in the array of selections" );
- });
+ } );
-});
+} );
-test("get(Number)", function() {
- expect(2);
- equal( jQuery("#qunit-fixture p").get(0), document.getElementById("firstp"), "Get A Single Element" );
- strictEqual( jQuery("#firstp").get(1), undefined, "Try get with index larger elements count" );
-});
+test( "get(Number)", function() {
+ expect( 2 );
+ equal( jQuery( "#qunit-fixture p" ).get( 0 ), document.getElementById( "firstp" ), "Get A Single Element" );
+ strictEqual( jQuery( "#firstp" ).get( 1 ), undefined, "Try get with index larger elements count" );
+} );
-test("get(-Number)",function() {
- expect(2);
- equal( jQuery("p").get(-1), document.getElementById("first"), "Get a single element with negative index" );
- strictEqual( jQuery("#firstp").get(-2), undefined, "Try get with index negative index larger then elements count" );
-});
+test( "get(-Number)", function() {
+ expect( 2 );
+ equal( jQuery( "p" ).get( -1 ), document.getElementById( "first" ), "Get a single element with negative index" );
+ strictEqual( jQuery( "#firstp" ).get( -2 ), undefined, "Try get with index negative index larger then elements count" );
+} );
-test("each(Function)", function() {
- expect(1);
+test( "each(Function)", function() {
+ expect( 1 );
var div, pass, i;
- div = jQuery("div");
- div.each(function(){this.foo = "zoo";});
+ div = jQuery( "div" );
+ div.each( function() {this.foo = "zoo";} );
pass = true;
for ( i = 0; i < div.length; i++ ) {
- if ( div.get(i).foo !== "zoo" ) {
+ if ( div.get( i ).foo !== "zoo" ) {
pass = false;
}
}
ok( pass, "Execute a function, Relative" );
-});
+} );
-test("slice()", function() {
- expect(7);
+test( "slice()", function() {
+ expect( 7 );
- var $links = jQuery("#ap a");
+ var $links = jQuery( "#ap a" );
- deepEqual( $links.slice(1,2).get(), q("groups"), "slice(1,2)" );
- deepEqual( $links.slice(1).get(), q("groups", "anchor1", "mark"), "slice(1)" );
- deepEqual( $links.slice(0,3).get(), q("google", "groups", "anchor1"), "slice(0,3)" );
- deepEqual( $links.slice(-1).get(), q("mark"), "slice(-1)" );
+ deepEqual( $links.slice( 1, 2 ).get(), q( "groups" ), "slice(1,2)" );
+ deepEqual( $links.slice( 1 ).get(), q( "groups", "anchor1", "mark" ), "slice(1)" );
+ deepEqual( $links.slice( 0, 3 ).get(), q( "google", "groups", "anchor1" ), "slice(0,3)" );
+ deepEqual( $links.slice( -1 ).get(), q( "mark" ), "slice(-1)" );
- deepEqual( $links.eq(1).get(), q("groups"), "eq(1)" );
- deepEqual( $links.eq("2").get(), q("anchor1"), "eq('2')" );
- deepEqual( $links.eq(-1).get(), q("mark"), "eq(-1)" );
-});
+ deepEqual( $links.eq( 1 ).get(), q( "groups" ), "eq(1)" );
+ deepEqual( $links.eq( "2" ).get(), q( "anchor1" ), "eq('2')" );
+ deepEqual( $links.eq( -1 ).get(), q( "mark" ), "eq(-1)" );
+} );
-test("first()/last()", function() {
- expect(4);
+test( "first()/last()", function() {
+ expect( 4 );
- var $links = jQuery("#ap a"), $none = jQuery("asdf");
+ var $links = jQuery( "#ap a" ), $none = jQuery( "asdf" );
- deepEqual( $links.first().get(), q("google"), "first()" );
- deepEqual( $links.last().get(), q("mark"), "last()" );
+ deepEqual( $links.first().get(), q( "google" ), "first()" );
+ deepEqual( $links.last().get(), q( "mark" ), "last()" );
deepEqual( $none.first().get(), [], "first() none" );
deepEqual( $none.last().get(), [], "last() none" );
-});
+} );
-test("map()", function() {
+test( "map()", function() {
expect( 2 );
deepEqual(
- jQuery("#ap").map(function() {
- return jQuery( this ).find("a").get();
- }).get(),
+ jQuery( "#ap" ).map( function() {
+ return jQuery( this ).find( "a" ).get();
+ } ).get(),
q( "google", "groups", "anchor1", "mark" ),
"Array Map"
);
deepEqual(
- jQuery("#ap > a").map(function() {
+ jQuery( "#ap > a" ).map( function() {
return this.parentNode;
- }).get(),
- q( "ap","ap","ap" ),
+ } ).get(),
+ q( "ap", "ap", "ap" ),
"Single Map"
);
-});
+} );
-test("jQuery.map", function() {
+test( "jQuery.map", function() {
expect( 25 );
var i, label, result, callback;
result = jQuery.map( [ 3, 4, 5 ], function( v, k ) {
return k;
- });
- equal( result.join(""), "012", "Map the keys from an array" );
+ } );
+ equal( result.join( "" ), "012", "Map the keys from an array" );
result = jQuery.map( [ 3, 4, 5 ], function( v ) {
return v;
- });
- equal( result.join(""), "345", "Map the values from an array" );
+ } );
+ equal( result.join( "" ), "345", "Map the values from an array" );
result = jQuery.map( { a: 1, b: 2 }, function( v, k ) {
return k;
- });
- equal( result.join(""), "ab", "Map the keys from an object" );
+ } );
+ equal( result.join( "" ), "ab", "Map the keys from an object" );
result = jQuery.map( { a: 1, b: 2 }, function( v ) {
return v;
- });
- equal( result.join(""), "12", "Map the values from an object" );
+ } );
+ equal( result.join( "" ), "12", "Map the values from an object" );
result = jQuery.map( [ "a", undefined, null, "b" ], function( v ) {
return v;
- });
- equal( result.join(""), "ab", "Array iteration does not include undefined/null results" );
+ } );
+ equal( result.join( "" ), "ab", "Array iteration does not include undefined/null results" );
result = jQuery.map( { a: "a", b: undefined, c: null, d: "b" }, function( v ) {
return v;
- });
- equal( result.join(""), "ab", "Object iteration does not include undefined/null results" );
+ } );
+ equal( result.join( "" ), "ab", "Object iteration does not include undefined/null results" );
result = {
Zero: function() {},
@@ -855,7 +859,7 @@ test("jQuery.map", function() {
"sparse Array": Array( 4 ),
"length: 1 plain object": { length: 1, "0": true },
"length: 2 plain object": { length: 2, "0": true, "1": true },
- NodeList: document.getElementsByTagName("html")
+ NodeList: document.getElementsByTagName( "html" )
};
callback = function( v, k ) {
if ( result[ label ] ) {
@@ -871,22 +875,22 @@ test("jQuery.map", function() {
result = false;
jQuery.map( { length: 0 }, function() {
result = true;
- });
+ } );
ok( !result, "length: 0 plain object treated like array" );
result = false;
- jQuery.map( document.getElementsByTagName("asdf"), function() {
+ jQuery.map( document.getElementsByTagName( "asdf" ), function() {
result = true;
- });
+ } );
ok( !result, "empty NodeList treated like array" );
- result = jQuery.map( Array(4), function( v, k ){
- return k % 2 ? k : [k,k,k];
- });
- equal( result.join(""), "00012223", "Array results flattened (#2616)" );
-});
+ result = jQuery.map( Array( 4 ), function( v, k ) {
+ return k % 2 ? k : [ k,k,k ];
+ } );
+ equal( result.join( "" ), "00012223", "Array results flattened (#2616)" );
+} );
-test("jQuery.merge()", function() {
+test( "jQuery.merge()", function() {
expect( 10 );
deepEqual(
@@ -920,7 +924,7 @@ test("jQuery.merge()", function() {
// Fixed at [5998], #3641
deepEqual(
jQuery.merge( [ -2, -1 ], [ 0, 1, 2 ] ),
- [ -2, -1 , 0, 1, 2 ],
+ [ -2, -1, 0, 1, 2 ],
"Second array including a zero (falsy)"
);
@@ -942,34 +946,34 @@ test("jQuery.merge()", function() {
);
deepEqual(
- jQuery.merge( [], document.getElementById("lengthtest").getElementsByTagName("input") ),
- [ document.getElementById("length"), document.getElementById("idTest") ],
+ jQuery.merge( [], document.getElementById( "lengthtest" ).getElementsByTagName( "input" ) ),
+ [ document.getElementById( "length" ), document.getElementById( "idTest" ) ],
"Second NodeList"
);
-});
+} );
-test("jQuery.grep()", function() {
- expect(8);
+test( "jQuery.grep()", function() {
+ expect( 8 );
var searchCriterion = function( value ) {
return value % 2 === 0;
};
deepEqual( jQuery.grep( [], searchCriterion ), [], "Empty array" );
- deepEqual( jQuery.grep( new Array(4), searchCriterion ), [], "Sparse array" );
+ deepEqual( jQuery.grep( new Array( 4 ), searchCriterion ), [], "Sparse array" );
deepEqual( jQuery.grep( [ 1, 2, 3, 4, 5, 6 ], searchCriterion ), [ 2, 4, 6 ], "Satisfying elements present" );
- deepEqual( jQuery.grep( [ 1, 3, 5, 7], searchCriterion ), [], "Satisfying elements absent" );
+ deepEqual( jQuery.grep( [ 1, 3, 5, 7 ], searchCriterion ), [], "Satisfying elements absent" );
deepEqual( jQuery.grep( [ 1, 2, 3, 4, 5, 6 ], searchCriterion, true ), [ 1, 3, 5 ], "Satisfying elements present and grep inverted" );
- deepEqual( jQuery.grep( [ 1, 3, 5, 7], searchCriterion, true ), [1, 3, 5, 7], "Satisfying elements absent and grep inverted" );
+ deepEqual( jQuery.grep( [ 1, 3, 5, 7 ], searchCriterion, true ), [ 1, 3, 5, 7 ], "Satisfying elements absent and grep inverted" );
deepEqual( jQuery.grep( [ 1, 2, 3, 4, 5, 6 ], searchCriterion, false ), [ 2, 4, 6 ], "Satisfying elements present but grep explicitly uninverted" );
deepEqual( jQuery.grep( [ 1, 3, 5, 7 ], searchCriterion, false ), [], "Satisfying elements absent and grep explicitly uninverted" );
-});
+} );
-test("jQuery.extend(Object, Object)", function() {
- expect(28);
+test( "jQuery.extend(Object, Object)", function() {
+ expect( 28 );
var empty, optionsWithLength, optionsWithDate, myKlass,
customObject, optionsWithCustomObject, MyNumber, ret,
@@ -983,87 +987,87 @@ test("jQuery.extend(Object, Object)", function() {
deep2 = { "foo": { "baz": true }, "foo2": document },
deep2copy = { "foo": { "baz": true }, "foo2": document },
deepmerged = { "foo": { "bar": true, "baz": true }, "foo2": document },
- arr = [1, 2, 3],
+ arr = [ 1, 2, 3 ],
nestedarray = { "arr": arr };
- jQuery.extend(settings, options);
+ jQuery.extend( settings, options );
deepEqual( settings, merged, "Check if extended: settings must be extended" );
deepEqual( options, optionsCopy, "Check if not modified: options must not be modified" );
- jQuery.extend(settings, null, options);
+ jQuery.extend( settings, null, options );
deepEqual( settings, merged, "Check if extended: settings must be extended" );
deepEqual( options, optionsCopy, "Check if not modified: options must not be modified" );
- jQuery.extend(true, deep1, deep2);
- deepEqual( deep1["foo"], deepmerged["foo"], "Check if foo: settings must be extended" );
- deepEqual( deep2["foo"], deep2copy["foo"], "Check if not deep2: options must not be modified" );
- equal( deep1["foo2"], document, "Make sure that a deep clone was not attempted on the document" );
+ jQuery.extend( true, deep1, deep2 );
+ deepEqual( deep1[ "foo" ], deepmerged[ "foo" ], "Check if foo: settings must be extended" );
+ deepEqual( deep2[ "foo" ], deep2copy[ "foo" ], "Check if not deep2: options must not be modified" );
+ equal( deep1[ "foo2" ], document, "Make sure that a deep clone was not attempted on the document" );
- ok( jQuery.extend(true, {}, nestedarray)["arr"] !== arr, "Deep extend of object must clone child array" );
+ ok( jQuery.extend( true, {}, nestedarray )[ "arr" ] !== arr, "Deep extend of object must clone child array" );
// #5991
- ok( jQuery.isArray( jQuery.extend(true, { "arr": {} }, nestedarray)["arr"] ), "Cloned array have to be an Array" );
- ok( jQuery.isPlainObject( jQuery.extend(true, { "arr": arr }, { "arr": {} })["arr"] ), "Cloned object have to be an plain object" );
+ ok( jQuery.isArray( jQuery.extend( true, { "arr": {} }, nestedarray )[ "arr" ] ), "Cloned array have to be an Array" );
+ ok( jQuery.isPlainObject( jQuery.extend( true, { "arr": arr }, { "arr": {} } )[ "arr" ] ), "Cloned object have to be an plain object" );
empty = {};
optionsWithLength = { "foo": { "length": -1 } };
- jQuery.extend(true, empty, optionsWithLength);
- deepEqual( empty["foo"], optionsWithLength["foo"], "The length property must copy correctly" );
+ jQuery.extend( true, empty, optionsWithLength );
+ deepEqual( empty[ "foo" ], optionsWithLength[ "foo" ], "The length property must copy correctly" );
empty = {};
optionsWithDate = { "foo": { "date": new Date() } };
- jQuery.extend(true, empty, optionsWithDate);
- deepEqual( empty["foo"], optionsWithDate["foo"], "Dates copy correctly" );
+ jQuery.extend( true, empty, optionsWithDate );
+ deepEqual( empty[ "foo" ], optionsWithDate[ "foo" ], "Dates copy correctly" );
/** @constructor */
myKlass = function() {};
customObject = new myKlass();
optionsWithCustomObject = { "foo": { "date": customObject } };
empty = {};
- jQuery.extend(true, empty, optionsWithCustomObject);
- ok( empty["foo"] && empty["foo"]["date"] === customObject, "Custom objects copy correctly (no methods)" );
+ jQuery.extend( true, empty, optionsWithCustomObject );
+ ok( empty[ "foo" ] && empty[ "foo" ][ "date" ] === customObject, "Custom objects copy correctly (no methods)" );
// Makes the class a little more realistic
- myKlass.prototype = { "someMethod": function(){} };
+ myKlass.prototype = { "someMethod": function() {} };
empty = {};
- jQuery.extend(true, empty, optionsWithCustomObject);
- ok( empty["foo"] && empty["foo"]["date"] === customObject, "Custom objects copy correctly" );
+ jQuery.extend( true, empty, optionsWithCustomObject );
+ ok( empty[ "foo" ] && empty[ "foo" ][ "date" ] === customObject, "Custom objects copy correctly" );
MyNumber = Number;
- ret = jQuery.extend(true, { "foo": 4 }, { "foo": new MyNumber(5) } );
- ok( parseInt(ret.foo, 10) === 5, "Wrapped numbers copy correctly" );
+ ret = jQuery.extend( true, { "foo": 4 }, { "foo": new MyNumber( 5 ) } );
+ ok( parseInt( ret.foo, 10 ) === 5, "Wrapped numbers copy correctly" );
nullUndef;
- nullUndef = jQuery.extend({}, options, { "xnumber2": null });
- ok( nullUndef["xnumber2"] === null, "Check to make sure null values are copied");
+ nullUndef = jQuery.extend( {}, options, { "xnumber2": null } );
+ ok( nullUndef[ "xnumber2" ] === null, "Check to make sure null values are copied" );
- nullUndef = jQuery.extend({}, options, { "xnumber2": undefined });
- ok( nullUndef["xnumber2"] === options["xnumber2"], "Check to make sure undefined values are not copied");
+ nullUndef = jQuery.extend( {}, options, { "xnumber2": undefined } );
+ ok( nullUndef[ "xnumber2" ] === options[ "xnumber2" ], "Check to make sure undefined values are not copied" );
- nullUndef = jQuery.extend({}, options, { "xnumber0": null });
- ok( nullUndef["xnumber0"] === null, "Check to make sure null values are inserted");
+ nullUndef = jQuery.extend( {}, options, { "xnumber0": null } );
+ ok( nullUndef[ "xnumber0" ] === null, "Check to make sure null values are inserted" );
target = {};
recursive = { foo:target, bar:5 };
- jQuery.extend(true, target, recursive);
+ jQuery.extend( true, target, recursive );
deepEqual( target, { bar:5 }, "Check to make sure a recursive obj doesn't go never-ending loop by not copying it over" );
- ret = jQuery.extend(true, { foo: [] }, { foo: [0] } ); // 1907
+ ret = jQuery.extend( true, { foo: [] }, { foo: [ 0 ] } ); // 1907
equal( ret.foo.length, 1, "Check to make sure a value with coercion 'false' copies over when necessary to fix #1907" );
- ret = jQuery.extend(true, { foo: "1,2,3" }, { foo: [1, 2, 3] } );
+ ret = jQuery.extend( true, { foo: "1,2,3" }, { foo: [ 1, 2, 3 ] } );
ok( typeof ret.foo !== "string", "Check to make sure values equal with coercion (but not actually equal) overwrite correctly" );
- ret = jQuery.extend(true, { foo:"bar" }, { foo:null } );
+ 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" );
obj = { foo:null };
- jQuery.extend(true, obj, { foo:"notnull" } );
+ jQuery.extend( true, obj, { foo:"notnull" } );
equal( obj.foo, "notnull", "Make sure a null value can be overwritten" );
function func() {}
- jQuery.extend(func, { key: "value" } );
+ jQuery.extend( func, { key: "value" } );
equal( func.key, "value", "Verify a function can be extended" );
defaults = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" };
@@ -1074,14 +1078,14 @@ test("jQuery.extend(Object, Object)", function() {
options2Copy = { xstring2: "xx", xxx: "newstringx" };
merged2 = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "xx", xxx: "newstringx" };
- settings = jQuery.extend({}, defaults, options1, options2);
+ settings = jQuery.extend( {}, defaults, options1, options2 );
deepEqual( settings, merged2, "Check if extended: settings must be extended" );
deepEqual( defaults, defaultsCopy, "Check if not modified: options1 must not be modified" );
deepEqual( options1, options1Copy, "Check if not modified: options1 must not be modified" );
deepEqual( options2, options2Copy, "Check if not modified: options2 must not be modified" );
-});
+} );
-test("jQuery.each(Object,Function)", function() {
+test( "jQuery.each(Object,Function)", function() {
expect( 23 );
var i, label, seen, callback;
@@ -1089,13 +1093,13 @@ test("jQuery.each(Object,Function)", function() {
seen = {};
jQuery.each( [ 3, 4, 5 ], function( k, v ) {
seen[ k ] = v;
- });
+ } );
deepEqual( seen, { "0": 3, "1": 4, "2": 5 }, "Array iteration" );
seen = {};
jQuery.each( { name: "name", lang: "lang" }, function( k, v ) {
seen[ k ] = v;
- });
+ } );
deepEqual( seen, { name: "name", lang: "lang" }, "Object iteration" );
seen = [];
@@ -1104,14 +1108,14 @@ test("jQuery.each(Object,Function)", function() {
if ( k === 1 ) {
return false;
}
- });
- deepEqual( seen, [ 1, 2 ] , "Broken array iteration" );
+ } );
+ deepEqual( seen, [ 1, 2 ], "Broken array iteration" );
seen = [];
- jQuery.each( {"a": 1, "b": 2,"c": 3 }, function( k, v ) {
+ jQuery.each( { "a": 1, "b": 2,"c": 3 }, function( k, v ) {
seen.push( v );
return false;
- });
+ } );
deepEqual( seen, [ 1 ], "Broken object iteration" );
seen = {
@@ -1151,7 +1155,7 @@ test("jQuery.each(Object,Function)", function() {
"sparse Array": Array( 4 ),
"length: 1 plain object": { length: 1, "0": true },
"length: 2 plain object": { length: 2, "0": true, "1": true },
- NodeList: document.getElementsByTagName("html")
+ NodeList: document.getElementsByTagName( "html" )
};
callback = function( k ) {
if ( seen[ label ] ) {
@@ -1168,23 +1172,23 @@ test("jQuery.each(Object,Function)", function() {
seen = false;
jQuery.each( { length: 0 }, function() {
seen = true;
- });
+ } );
ok( !seen, "length: 0 plain object treated like array" );
seen = false;
- jQuery.each( document.getElementsByTagName("asdf"), function() {
+ jQuery.each( document.getElementsByTagName( "asdf" ), function() {
seen = true;
- });
+ } );
ok( !seen, "empty NodeList treated like array" );
i = 0;
jQuery.each( document.styleSheets, function() {
i++;
- });
+ } );
equal( i, document.styleSheets.length, "Iteration over document.styleSheets" );
-});
+} );
-test("jQuery.each/map(undefined/null,Function)", function() {
+test( "jQuery.each/map(undefined/null,Function)", function() {
expect( 1 );
try {
@@ -1196,7 +1200,7 @@ test("jQuery.each/map(undefined/null,Function)", function() {
} catch ( e ) {
ok( false, "each/map must accept null and undefined values" );
}
-});
+} );
test( "JIT compilation does not interfere with length retrieval (gh-2145)", function() {
expect( 4 );
@@ -1214,74 +1218,74 @@ test( "JIT compilation does not interfere with length retrieval (gh-2145)", func
jQuery.each( { 1: "1", 2: "2", 3: "3" }, function( index ) {
equal( ++i, index, "Iteration over object with solely " +
"numeric indices (gh-2145 JIT iOS 8 bug)" );
- });
+ } );
equal( i, 3, "Iteration over object with solely " +
"numeric indices (gh-2145 JIT iOS 8 bug)" );
-});
+} );
-test("jQuery.makeArray", function(){
- expect(15);
+test( "jQuery.makeArray", function() {
+ expect( 15 );
- equal( jQuery.makeArray(jQuery("html>*"))[0].nodeName.toUpperCase(), "HEAD", "Pass makeArray a jQuery object" );
+ equal( jQuery.makeArray( jQuery( "html>*" ) )[ 0 ].nodeName.toUpperCase(), "HEAD", "Pass makeArray a jQuery object" );
- equal( jQuery.makeArray(document.getElementsByName("PWD")).slice(0,1)[0].name, "PWD", "Pass makeArray a nodelist" );
+ equal( jQuery.makeArray( document.getElementsByName( "PWD" ) ).slice( 0, 1 )[ 0 ].name, "PWD", "Pass makeArray a nodelist" );
- equal( (function() { return jQuery.makeArray(arguments); })(1,2).join(""), "12", "Pass makeArray an arguments array" );
+ equal( ( function() { return jQuery.makeArray( arguments ); } )( 1, 2 ).join( "" ), "12", "Pass makeArray an arguments array" );
- equal( jQuery.makeArray([1,2,3]).join(""), "123", "Pass makeArray a real array" );
+ equal( jQuery.makeArray( [ 1,2,3 ] ).join( "" ), "123", "Pass makeArray a real array" );
equal( jQuery.makeArray().length, 0, "Pass nothing to makeArray and expect an empty array" );
- equal( jQuery.makeArray( 0 )[0], 0 , "Pass makeArray a number" );
+ equal( jQuery.makeArray( 0 )[ 0 ], 0, "Pass makeArray a number" );
- equal( jQuery.makeArray( "foo" )[0], "foo", "Pass makeArray a string" );
+ equal( jQuery.makeArray( "foo" )[ 0 ], "foo", "Pass makeArray a string" );
- equal( jQuery.makeArray( true )[0].constructor, Boolean, "Pass makeArray a boolean" );
+ equal( jQuery.makeArray( true )[ 0 ].constructor, Boolean, "Pass makeArray a boolean" );
- equal( jQuery.makeArray( document.createElement("div") )[0].nodeName.toUpperCase(), "DIV", "Pass makeArray a single node" );
+ equal( jQuery.makeArray( document.createElement( "div" ) )[ 0 ].nodeName.toUpperCase(), "DIV", "Pass makeArray a single node" );
- equal( jQuery.makeArray( {length:2, 0:"a", 1:"b"} ).join(""), "ab", "Pass makeArray an array like map (with length)" );
+ equal( jQuery.makeArray( { length:2, 0:"a", 1:"b" } ).join( "" ), "ab", "Pass makeArray an array like map (with length)" );
- ok( !!jQuery.makeArray( document.documentElement.childNodes ).slice(0,1)[0].nodeName, "Pass makeArray a childNodes array" );
+ ok( !!jQuery.makeArray( document.documentElement.childNodes ).slice( 0, 1 )[ 0 ].nodeName, "Pass makeArray a childNodes array" );
// function, is tricky as it has length
- equal( jQuery.makeArray( function(){ return 1;} )[0](), 1, "Pass makeArray a function" );
+ equal( jQuery.makeArray( function() { return 1;} )[ 0 ](), 1, "Pass makeArray a function" );
//window, also has length
- equal( jQuery.makeArray(window)[0], window, "Pass makeArray the window" );
+ equal( jQuery.makeArray( window )[ 0 ], window, "Pass makeArray the window" );
- equal( jQuery.makeArray(/a/)[0].constructor, RegExp, "Pass makeArray a regex" );
+ equal( jQuery.makeArray( /a/ )[ 0 ].constructor, RegExp, "Pass makeArray a regex" );
// Some nodes inherit traits of nodelists
- ok( jQuery.makeArray(document.getElementById("form")).length >= 13,
+ ok( jQuery.makeArray( document.getElementById( "form" ) ).length >= 13,
"Pass makeArray a form (treat as elements)" );
-});
+} );
-test("jQuery.inArray", function(){
- expect(3);
+test( "jQuery.inArray", function() {
+ expect( 3 );
- equal( jQuery.inArray( 0, false ), -1 , "Search in 'false' as array returns -1 and doesn't throw exception" );
+ equal( jQuery.inArray( 0, false ), -1, "Search in 'false' as array returns -1 and doesn't throw exception" );
- equal( jQuery.inArray( 0, null ), -1 , "Search in 'null' as array returns -1 and doesn't throw exception" );
+ equal( jQuery.inArray( 0, null ), -1, "Search in 'null' as array returns -1 and doesn't throw exception" );
- equal( jQuery.inArray( 0, undefined ), -1 , "Search in 'undefined' as array returns -1 and doesn't throw exception" );
-});
+ equal( jQuery.inArray( 0, undefined ), -1, "Search in 'undefined' as array returns -1 and doesn't throw exception" );
+} );
-test("jQuery.isEmptyObject", function(){
- expect(2);
+test( "jQuery.isEmptyObject", function() {
+ expect( 2 );
- equal(true, jQuery.isEmptyObject({}), "isEmptyObject on empty object literal" );
- equal(false, jQuery.isEmptyObject({a:1}), "isEmptyObject on non-empty object literal" );
+ equal( true, jQuery.isEmptyObject( {} ), "isEmptyObject on empty object literal" );
+ equal( false, jQuery.isEmptyObject( { a:1 } ), "isEmptyObject on non-empty object literal" );
// What about this ?
// equal(true, jQuery.isEmptyObject(null), "isEmptyObject on null" );
-});
+} );
-test("jQuery.proxy", function(){
+test( "jQuery.proxy", function() {
expect( 9 );
var test2, test3, test4, fn, cb,
- test = function(){ equal( this, thisObject, "Make sure that scope is set properly." ); },
+ test = function() { equal( this, thisObject, "Make sure that scope is set properly." ); },
thisObject = { foo: "bar", method: test };
// Make sure normal works
@@ -1297,15 +1301,15 @@ test("jQuery.proxy", function(){
equal( jQuery.proxy( null, thisObject ), undefined, "Make sure no function was returned." );
// Partial application
- test2 = function( a ){ equal( a, "pre-applied", "Ensure arguments can be pre-applied." ); };
+ test2 = function( a ) { equal( a, "pre-applied", "Ensure arguments can be pre-applied." ); };
jQuery.proxy( test2, null, "pre-applied" )();
// Partial application w/ normal arguments
- test3 = function( a, b ){ equal( b, "normal", "Ensure arguments can be pre-applied and passed as usual." ); };
+ test3 = function( a, b ) { equal( b, "normal", "Ensure arguments can be pre-applied and passed as usual." ); };
jQuery.proxy( test3, null, "pre-applied" )( "normal" );
// Test old syntax
- test4 = { "meth": function( a ){ equal( a, "boom", "Ensure old syntax works." ); } };
+ test4 = { "meth": function( a ) { equal( a, "boom", "Ensure old syntax works." ); } };
jQuery.proxy( test4, "meth" )( "boom" );
// jQuery 1.9 improved currying with `this` object
@@ -1315,9 +1319,9 @@ test("jQuery.proxy", function(){
};
cb = jQuery.proxy( fn, null, "arg1", "arg2" );
cb.call( thisObject, "arg3" );
-});
+} );
-test("jQuery.parseHTML", function() {
+test( "jQuery.parseHTML", function() {
expect( 22 );
var html, nodes;
@@ -1330,88 +1334,88 @@ test("jQuery.parseHTML", function() {
deepEqual( jQuery.parseHTML( true ), [], "Boolean true" );
deepEqual( jQuery.parseHTML( 42 ), [], "Positive number" );
deepEqual( jQuery.parseHTML( "" ), [], "Empty string" );
- throws(function() {
- jQuery.parseHTML( "
", document.getElementById("form") );
- }, "Passing an element as the context raises an exception (context should be a document)");
+ throws( function() {
+ jQuery.parseHTML( "
", document.getElementById( "form" ) );
+ }, "Passing an element as the context raises an exception (context should be a document)" );
- nodes = jQuery.parseHTML( jQuery("body")[0].innerHTML );
+ nodes = jQuery.parseHTML( jQuery( "body" )[ 0 ].innerHTML );
ok( nodes.length > 4, "Parse a large html string" );
equal( jQuery.type( nodes ), "array", "parseHTML returns an array rather than a nodelist" );
html = "";
equal( jQuery.parseHTML( html ).length, 0, "Ignore scripts by default" );
- equal( jQuery.parseHTML( html, true )[0].nodeName.toLowerCase(), "script", "Preserve scripts when requested" );
+ equal( jQuery.parseHTML( html, true )[ 0 ].nodeName.toLowerCase(), "script", "Preserve scripts when requested" );
html += "
";
- equal( jQuery.parseHTML( html )[0].nodeName.toLowerCase(), "div", "Preserve non-script nodes" );
- equal( jQuery.parseHTML( html, true )[0].nodeName.toLowerCase(), "script", "Preserve script position");
+ equal( jQuery.parseHTML( html )[ 0 ].nodeName.toLowerCase(), "div", "Preserve non-script nodes" );
+ equal( jQuery.parseHTML( html, true )[ 0 ].nodeName.toLowerCase(), "script", "Preserve script position" );
- equal( jQuery.parseHTML("text")[0].nodeType, 3, "Parsing text returns a text node" );
- equal( jQuery.parseHTML( "\t
" )[0].nodeValue, "\t", "Preserve leading whitespace" );
+ equal( jQuery.parseHTML( "text" )[ 0 ].nodeType, 3, "Parsing text returns a text node" );
+ equal( jQuery.parseHTML( "\t
" )[ 0 ].nodeValue, "\t", "Preserve leading whitespace" );
- equal( jQuery.parseHTML("
")[0].nodeType, 3, "Leading spaces are treated as text nodes (#11290)" );
+ equal( jQuery.parseHTML( "
" )[ 0 ].nodeType, 3, "Leading spaces are treated as text nodes (#11290)" );
html = jQuery.parseHTML( "
test div
" );
equal( html[ 0 ].parentNode.nodeType, 11, "parentNode should be documentFragment" );
equal( html[ 0 ].innerHTML, "test div", "Content should be preserved" );
- equal( jQuery.parseHTML("
").length, 1, "Incorrect html-strings should not break anything" );
- equal( jQuery.parseHTML(" | ")[ 1 ].parentNode.nodeType, 11, "parentNode should be documentFragment" );
-});
+ equal( jQuery.parseHTML( "" ).length, 1, "Incorrect html-strings should not break anything" );
+ equal( jQuery.parseHTML( " | | " )[ 1 ].parentNode.nodeType, 11, "parentNode should be documentFragment" );
+} );
if ( jQuery.support.createHTMLDocument ) {
- asyncTest("jQuery.parseHTML", function() {
+ asyncTest( "jQuery.parseHTML", function() {
expect ( 1 );
- Globals.register("parseHTMLError");
+ Globals.register( "parseHTMLError" );
- jQuery.globalEval("parseHTMLError = false;");
+ jQuery.globalEval( "parseHTMLError = false;" );
jQuery.parseHTML( "" );
- window.setTimeout(function() {
+ window.setTimeout( function() {
start();
equal( window.parseHTMLError, false, "onerror eventhandler has not been called." );
- }, 2000);
- });
+ }, 2000 );
+ } );
}
-test("jQuery.parseJSON", function() {
+test( "jQuery.parseJSON", function() {
expect( 20 );
strictEqual( jQuery.parseJSON( null ), null, "primitive null" );
- strictEqual( jQuery.parseJSON("0.88"), 0.88, "Number" );
+ strictEqual( jQuery.parseJSON( "0.88" ), 0.88, "Number" );
strictEqual(
- jQuery.parseJSON("\" \\\" \\\\ \\/ \\b \\f \\n \\r \\t \\u007E \\u263a \""),
+ jQuery.parseJSON( "\" \\\" \\\\ \\/ \\b \\f \\n \\r \\t \\u007E \\u263a \"" ),
" \" \\ / \b \f \n \r \t ~ \u263A ",
"String escapes"
);
- deepEqual( jQuery.parseJSON("{}"), {}, "Empty object" );
- deepEqual( jQuery.parseJSON("{\"test\":1}"), { "test": 1 }, "Plain object" );
- deepEqual( jQuery.parseJSON("[0]"), [ 0 ], "Simple array" );
+ deepEqual( jQuery.parseJSON( "{}" ), {}, "Empty object" );
+ deepEqual( jQuery.parseJSON( "{\"test\":1}" ), { "test": 1 }, "Plain object" );
+ deepEqual( jQuery.parseJSON( "[0]" ), [ 0 ], "Simple array" );
deepEqual(
- jQuery.parseJSON("[ \"string\", -4.2, 2.7180e0, 3.14E-1, {}, [], true, false, null ]"),
+ jQuery.parseJSON( "[ \"string\", -4.2, 2.7180e0, 3.14E-1, {}, [], true, false, null ]" ),
[ "string", -4.2, 2.718, 0.314, {}, [], true, false, null ],
"Array of all data types"
);
deepEqual(
jQuery.parseJSON( "{ \"string\": \"\", \"number\": 4.2e+1, \"object\": {}," +
- "\"array\": [[]], \"boolean\": [ true, false ], \"null\": null }"),
- { string: "", number: 42, object: {}, array: [[]], "boolean": [ true, false ], "null": null },
+ "\"array\": [[]], \"boolean\": [ true, false ], \"null\": null }" ),
+ { string: "", number: 42, object: {}, array: [ [] ], "boolean": [ true, false ], "null": null },
"Dictionary of all data types"
);
- deepEqual( jQuery.parseJSON("\n{\"test\":1}\t"), { "test": 1 },
+ deepEqual( jQuery.parseJSON( "\n{\"test\":1}\t" ), { "test": 1 },
"Leading and trailing whitespace are ignored" );
- throws(function() {
+ throws( function() {
jQuery.parseJSON();
}, null, "Undefined raises an error" );
- throws(function() {
+ throws( function() {
jQuery.parseJSON( "" );
}, null, "Empty string raises an error" );
- throws(function() {
- jQuery.parseJSON("''");
+ throws( function() {
+ jQuery.parseJSON( "''" );
}, null, "Single-quoted string raises an error" );
/*
@@ -1431,38 +1435,38 @@ test("jQuery.parseJSON", function() {
}, null, "Number with no integer component raises an error" );
*/
- throws(function() {
- var result = jQuery.parseJSON("0101");
+ throws( function() {
+ var result = jQuery.parseJSON( "0101" );
// Support: IE9+
// Ensure base-10 interpretation on browsers that erroneously accept leading-zero numbers
if ( result === 101 ) {
- throw new Error("close enough");
+ throw new Error( "close enough" );
}
}, null, "Leading-zero number raises an error or is parsed as decimal" );
- throws(function() {
- jQuery.parseJSON("{a:1}");
+ throws( function() {
+ jQuery.parseJSON( "{a:1}" );
}, null, "Unquoted property raises an error" );
- throws(function() {
- jQuery.parseJSON("{'a':1}");
+ throws( function() {
+ jQuery.parseJSON( "{'a':1}" );
}, null, "Single-quoted property raises an error" );
- throws(function() {
- jQuery.parseJSON("[,]");
+ throws( function() {
+ jQuery.parseJSON( "[,]" );
}, null, "Array element elision raises an error" );
- throws(function() {
- jQuery.parseJSON("{},[]");
+ throws( function() {
+ jQuery.parseJSON( "{},[]" );
}, null, "Comma expression raises an error" );
- throws(function() {
- jQuery.parseJSON("[]\n,{}");
+ throws( function() {
+ jQuery.parseJSON( "[]\n,{}" );
}, null, "Newline-containing comma expression raises an error" );
- throws(function() {
- jQuery.parseJSON("\"\"\n\"\"");
+ throws( function() {
+ jQuery.parseJSON( "\"\"\n\"\"" );
}, null, "Automatic semicolon insertion raises an error" );
- strictEqual( jQuery.parseJSON([ 0 ]), 0, "Input cast to string" );
-});
+ strictEqual( jQuery.parseJSON( [ 0 ] ), 0, "Input cast to string" );
+} );
-test("jQuery.parseXML", function(){
+test( "jQuery.parseXML", function() {
expect( 8 );
var xml, tmp;
@@ -1473,13 +1477,13 @@ test("jQuery.parseXML", function(){
tmp = tmp.getElementsByTagName( "b" )[ 0 ];
ok( !!tmp, " present in document" );
strictEqual( tmp.childNodes[ 0 ].nodeValue, "well-formed", " text is as expected" );
- } catch (e) {
+ } catch ( e ) {
strictEqual( e, undefined, "unexpected error" );
}
try {
xml = jQuery.parseXML( " Not a <well-formed xml string " );
ok( false, "invalid xml not detected" );
- } catch( e ) {
+ } catch ( e ) {
strictEqual( e.message, "Invalid XML: Not a <well-formed xml string ", "invalid xml detected" );
}
try {
@@ -1491,12 +1495,12 @@ test("jQuery.parseXML", function(){
strictEqual( xml, null, "null string => null document" );
xml = jQuery.parseXML( true );
strictEqual( xml, null, "non-string => null document" );
- } catch( e ) {
+ } catch ( e ) {
ok( false, "empty input throws exception" );
}
-});
+} );
-test("jQuery.camelCase()", function() {
+test( "jQuery.camelCase()", function() {
var tests = {
"foo-bar": "fooBar",
@@ -1508,19 +1512,19 @@ test("jQuery.camelCase()", function() {
"-ms-take": "msTake"
};
- expect(7);
+ expect( 7 );
jQuery.each( tests, function( key, val ) {
equal( jQuery.camelCase( key ), val, "Converts: " + key + " => " + val );
- });
-});
+ } );
+} );
testIframeWithCallback( "Conditional compilation compatibility (#13274)", "core/cc_on.html", function( cc_on, errors, $ ) {
expect( 3 );
ok( true, "JScript conditional compilation " + ( cc_on ? "supported" : "not supported" ) );
deepEqual( errors, [], "No errors" );
ok( $(), "jQuery executes" );
-});
+} );
// iOS7 doesn't fire the load event if the long-loading iframe gets its source reset to about:blank.
// This makes this test fail but it doesn't seem to cause any real-life problems so blacklisting
@@ -1529,7 +1533,7 @@ if ( !/iphone os 7_/i.test( navigator.userAgent ) ) {
testIframeWithCallback( "document ready when jQuery loaded asynchronously (#13655)", "core/dynamic_ready.html", function( ready ) {
expect( 1 );
equal( true, ready, "document ready correctly fired when jQuery is loaded after DOMContentLoaded" );
- });
+ } );
}
testIframeWithCallback( "Tolerating alias-masked DOM properties (#14074)", "core/aliased.html",
diff --git a/test/unit/css.js b/test/unit/css.js
index b4ee1e403..ac569fdff 100644
--- a/test/unit/css.js
+++ b/test/unit/css.js
@@ -1,88 +1,88 @@
if ( jQuery.css ) {
-module("css", { teardown: moduleTeardown });
+module( "css", { teardown: moduleTeardown } );
-test("css(String|Hash)", function() {
+test( "css(String|Hash)", function() {
expect( 43 );
- equal( jQuery("#qunit-fixture").css("display"), "block", "Check for css property \"display\"" );
+ equal( jQuery( "#qunit-fixture" ).css( "display" ), "block", "Check for css property \"display\"" );
var $child, div, div2, width, height, child, prctval, checkval, old;
- $child = jQuery("#nothiddendivchild").css({ "width": "20%", "height": "20%" });
- notEqual( $child.css("width"), "20px", "Retrieving a width percentage on the child of a hidden div returns percentage" );
- notEqual( $child.css("height"), "20px", "Retrieving a height percentage on the child of a hidden div returns percentage" );
+ $child = jQuery( "#nothiddendivchild" ).css( { "width": "20%", "height": "20%" } );
+ notEqual( $child.css( "width" ), "20px", "Retrieving a width percentage on the child of a hidden div returns percentage" );
+ notEqual( $child.css( "height" ), "20px", "Retrieving a height percentage on the child of a hidden div returns percentage" );
div = jQuery( "" );
// These should be "auto" (or some better value)
// temporarily provide "0px" for backwards compat
- equal( div.css("width"), "0px", "Width on disconnected node." );
- equal( div.css("height"), "0px", "Height on disconnected node." );
+ equal( div.css( "width" ), "0px", "Width on disconnected node." );
+ equal( div.css( "height" ), "0px", "Height on disconnected node." );
- div.css({ "width": 4, "height": 4 });
+ div.css( { "width": 4, "height": 4 } );
- equal( div.css("width"), "4px", "Width on disconnected node." );
- equal( div.css("height"), "4px", "Height on disconnected node." );
+ equal( div.css( "width" ), "4px", "Width on disconnected node." );
+ equal( div.css( "height" ), "4px", "Height on disconnected node." );
- div2 = jQuery( "").appendTo("body");
+ div2 = jQuery( "" ).appendTo( "body" );
- equal( div2.find("input").css("height"), "20px", "Height on hidden input." );
- equal( div2.find("textarea").css("height"), "20px", "Height on hidden textarea." );
- equal( div2.find("div").css("height"), "20px", "Height on hidden div." );
+ equal( div2.find( "input" ).css( "height" ), "20px", "Height on hidden input." );
+ equal( div2.find( "textarea" ).css( "height" ), "20px", "Height on hidden textarea." );
+ equal( div2.find( "div" ).css( "height" ), "20px", "Height on hidden div." );
div2.remove();
// handle negative numbers by setting to zero #11604
- jQuery("#nothiddendiv").css( {"width": 1, "height": 1} );
+ jQuery( "#nothiddendiv" ).css( { "width": 1, "height": 1 } );
- width = parseFloat(jQuery("#nothiddendiv").css("width"));
- height = parseFloat(jQuery("#nothiddendiv").css("height"));
- jQuery("#nothiddendiv").css({ "overflow":"hidden", "width": -1, "height": -1 });
- equal( parseFloat(jQuery("#nothiddendiv").css("width")), 0, "Test negative width set to 0");
- equal( parseFloat(jQuery("#nothiddendiv").css("height")), 0, "Test negative height set to 0");
+ width = parseFloat( jQuery( "#nothiddendiv" ).css( "width" ) );
+ height = parseFloat( jQuery( "#nothiddendiv" ).css( "height" ) );
+ jQuery( "#nothiddendiv" ).css( { "overflow":"hidden", "width": -1, "height": -1 } );
+ equal( parseFloat( jQuery( "#nothiddendiv" ).css( "width" ) ), 0, "Test negative width set to 0" );
+ equal( parseFloat( jQuery( "#nothiddendiv" ).css( "height" ) ), 0, "Test negative height set to 0" );
- equal( jQuery("").css("display"), "none", "Styles on disconnected nodes");
+ equal( jQuery( "" ).css( "display" ), "none", "Styles on disconnected nodes" );
- jQuery("#floatTest").css({"float": "right"});
- equal( jQuery("#floatTest").css("float"), "right", "Modified CSS float using \"float\": Assert float is right");
- jQuery("#floatTest").css({"font-size": "30px"});
- equal( 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("#foo").css({"opacity": n});
+ jQuery( "#floatTest" ).css( { "float": "right" } );
+ equal( jQuery( "#floatTest" ).css( "float" ), "right", "Modified CSS float using \"float\": Assert float is right" );
+ jQuery( "#floatTest" ).css( { "font-size": "30px" } );
+ equal( 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( "#foo" ).css( { "opacity": n } );
- equal( jQuery("#foo").css("opacity"), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a String" );
- jQuery("#foo").css({"opacity": parseFloat(n)});
- equal( jQuery("#foo").css("opacity"), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a Number" );
- });
- jQuery("#foo").css({"opacity": ""});
- equal( jQuery("#foo").css("opacity"), "1", "Assert opacity is 1 when set to an empty String" );
+ equal( jQuery( "#foo" ).css( "opacity" ), parseFloat( n ), "Assert opacity is " + parseFloat( n ) + " as a String" );
+ jQuery( "#foo" ).css( { "opacity": parseFloat( n ) } );
+ equal( jQuery( "#foo" ).css( "opacity" ), parseFloat( n ), "Assert opacity is " + parseFloat( n ) + " as a Number" );
+ } );
+ jQuery( "#foo" ).css( { "opacity": "" } );
+ equal( jQuery( "#foo" ).css( "opacity" ), "1", "Assert opacity is 1 when set to an empty String" );
- equal( jQuery("#empty").css("opacity"), "0", "Assert opacity is accessible via filter property set in stylesheet in IE" );
- jQuery("#empty").css({ "opacity": "1" });
- equal( jQuery("#empty").css("opacity"), "1", "Assert opacity is taken from style attribute when set vs stylesheet in IE with filters" );
+ equal( jQuery( "#empty" ).css( "opacity" ), "0", "Assert opacity is accessible via filter property set in stylesheet in IE" );
+ jQuery( "#empty" ).css( { "opacity": "1" } );
+ equal( 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" );
+ 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" );
- div = jQuery("#nothiddendiv");
- child = jQuery("#nothiddendivchild");
+ div = jQuery( "#nothiddendiv" );
+ child = jQuery( "#nothiddendivchild" );
- equal( parseInt(div.css("fontSize"), 10), 16, "Verify fontSize px set." );
- equal( parseInt(div.css("font-size"), 10), 16, "Verify fontSize px set." );
- equal( parseInt(child.css("fontSize"), 10), 16, "Verify fontSize px set." );
- equal( parseInt(child.css("font-size"), 10), 16, "Verify fontSize px set." );
+ equal( parseInt( div.css( "fontSize" ), 10 ), 16, "Verify fontSize px set." );
+ equal( parseInt( div.css( "font-size" ), 10 ), 16, "Verify fontSize px set." );
+ equal( parseInt( child.css( "fontSize" ), 10 ), 16, "Verify fontSize px set." );
+ equal( parseInt( child.css( "font-size" ), 10 ), 16, "Verify fontSize px set." );
- child.css("height", "100%");
- equal( child[0].style.height, "100%", "Make sure the height is being set correctly." );
+ child.css( "height", "100%" );
+ equal( child[ 0 ].style.height, "100%", "Make sure the height is being set correctly." );
- child.attr("class", "em");
- equal( parseInt(child.css("fontSize"), 10), 32, "Verify fontSize em set." );
+ child.attr( "class", "em" );
+ equal( parseInt( child.css( "fontSize" ), 10 ), 32, "Verify fontSize em set." );
// Have to verify this as the result depends upon the browser's CSS
// support for font-size percentages
- child.attr("class", "prct");
- prctval = parseInt(child.css("fontSize"), 10);
+ child.attr( "class", "prct" );
+ prctval = parseInt( child.css( "fontSize" ), 10 );
checkval = 0;
if ( prctval === 16 || prctval === 24 ) {
checkval = prctval;
@@ -90,34 +90,34 @@ test("css(String|Hash)", function() {
equal( prctval, checkval, "Verify fontSize % set." );
- equal( typeof child.css("width"), "string", "Make sure that a string width is returned from css('width')." );
+ equal( typeof child.css( "width" ), "string", "Make sure that a string width is returned from css('width')." );
- old = child[0].style.height;
+ old = child[ 0 ].style.height;
// Test NaN
- child.css("height", parseFloat("zoo"));
- equal( child[0].style.height, old, "Make sure height isn't changed on NaN." );
+ child.css( "height", parseFloat( "zoo" ) );
+ equal( child[ 0 ].style.height, old, "Make sure height isn't changed on NaN." );
// Test null
- child.css("height", null);
- equal( child[0].style.height, old, "Make sure height isn't changed on null." );
+ child.css( "height", null );
+ equal( child[ 0 ].style.height, old, "Make sure height isn't changed on null." );
- old = child[0].style.fontSize;
+ old = child[ 0 ].style.fontSize;
// Test NaN
- child.css("font-size", parseFloat("zoo"));
- equal( child[0].style.fontSize, old, "Make sure font-size isn't changed on NaN." );
+ child.css( "font-size", parseFloat( "zoo" ) );
+ equal( child[ 0 ].style.fontSize, old, "Make sure font-size isn't changed on NaN." );
// Test null
- child.css("font-size", null);
- equal( child[0].style.fontSize, old, "Make sure font-size isn't changed on null." );
+ child.css( "font-size", null );
+ equal( child[ 0 ].style.fontSize, old, "Make sure font-size isn't changed on null." );
strictEqual( child.css( "x-fake" ), undefined, "Make sure undefined is returned from css(nonexistent)." );
- div = jQuery( "" ).css({ position: "absolute", "z-index": 1000 }).appendTo( "#qunit-fixture" );
+ div = jQuery( "" ).css( { position: "absolute", "z-index": 1000 } ).appendTo( "#qunit-fixture" );
strictEqual( div.css( "z-index" ), "1000",
"Make sure that a string z-index is returned from css('z-index') (#14432)." );
-});
+} );
test( "css(String) computed values", function() {
expect( 3 );
@@ -129,97 +129,96 @@ test( "css(String) computed values", function() {
strictEqual( div.css( "padding-left" ), "500px", "should get computed value for padding-left property" );
strictEqual( div.css( "width" ), "200px", "should get computed value for width property" );
strictEqual( div.css( "font-size" ), "32px", "should get computed value for font-size property" );
-});
-
+} );
test( "css() explicit and relative values", function() {
expect( 29 );
- var $elem = jQuery("#nothiddendiv");
+ var $elem = jQuery( "#nothiddendiv" );
- $elem.css({ "width": 1, "height": 1, "paddingLeft": "1px", "opacity": 1 });
- equal( $elem.css("width"), "1px", "Initial css set or width/height works (hash)" );
- equal( $elem.css("paddingLeft"), "1px", "Initial css set of paddingLeft works (hash)" );
- equal( $elem.css("opacity"), "1", "Initial css set of opacity works (hash)" );
+ $elem.css( { "width": 1, "height": 1, "paddingLeft": "1px", "opacity": 1 } );
+ equal( $elem.css( "width" ), "1px", "Initial css set or width/height works (hash)" );
+ equal( $elem.css( "paddingLeft" ), "1px", "Initial css set of paddingLeft works (hash)" );
+ equal( $elem.css( "opacity" ), "1", "Initial css set of opacity works (hash)" );
- $elem.css({ width: "+=9" });
- equal( $elem.css("width"), "10px", "'+=9' on width (hash)" );
+ $elem.css( { width: "+=9" } );
+ equal( $elem.css( "width" ), "10px", "'+=9' on width (hash)" );
- $elem.css({ "width": "-=9" });
- equal( $elem.css("width"), "1px", "'-=9' on width (hash)" );
+ $elem.css( { "width": "-=9" } );
+ equal( $elem.css( "width" ), "1px", "'-=9' on width (hash)" );
- $elem.css({ "width": "+=9px" });
- equal( $elem.css("width"), "10px", "'+=9px' on width (hash)" );
+ $elem.css( { "width": "+=9px" } );
+ equal( $elem.css( "width" ), "10px", "'+=9px' on width (hash)" );
- $elem.css({ "width": "-=9px" });
- equal( $elem.css("width"), "1px", "'-=9px' on width (hash)" );
+ $elem.css( { "width": "-=9px" } );
+ equal( $elem.css( "width" ), "1px", "'-=9px' on width (hash)" );
$elem.css( "width", "+=9" );
- equal( $elem.css("width"), "10px", "'+=9' on width (params)" );
+ equal( $elem.css( "width" ), "10px", "'+=9' on width (params)" );
$elem.css( "width", "-=9" ) ;
- equal( $elem.css("width"), "1px", "'-=9' on width (params)" );
+ equal( $elem.css( "width" ), "1px", "'-=9' on width (params)" );
$elem.css( "width", "+=9px" );
- equal( $elem.css("width"), "10px", "'+=9px' on width (params)" );
+ equal( $elem.css( "width" ), "10px", "'+=9px' on width (params)" );
$elem.css( "width", "-=9px" );
- equal( $elem.css("width"), "1px", "'-=9px' on width (params)" );
+ equal( $elem.css( "width" ), "1px", "'-=9px' on width (params)" );
$elem.css( "width", "-=-9px" );
- equal( $elem.css("width"), "10px", "'-=-9px' on width (params)" );
+ equal( $elem.css( "width" ), "10px", "'-=-9px' on width (params)" );
$elem.css( "width", "+=-9px" );
- equal( $elem.css("width"), "1px", "'+=-9px' on width (params)" );
+ equal( $elem.css( "width" ), "1px", "'+=-9px' on width (params)" );
- $elem.css({ "paddingLeft": "+=4" });
- equal( $elem.css("paddingLeft"), "5px", "'+=4' on paddingLeft (hash)" );
+ $elem.css( { "paddingLeft": "+=4" } );
+ equal( $elem.css( "paddingLeft" ), "5px", "'+=4' on paddingLeft (hash)" );
- $elem.css({ "paddingLeft": "-=4" });
- equal( $elem.css("paddingLeft"), "1px", "'-=4' on paddingLeft (hash)" );
+ $elem.css( { "paddingLeft": "-=4" } );
+ equal( $elem.css( "paddingLeft" ), "1px", "'-=4' on paddingLeft (hash)" );
- $elem.css({ "paddingLeft": "+=4px" });
- equal( $elem.css("paddingLeft"), "5px", "'+=4px' on paddingLeft (hash)" );
+ $elem.css( { "paddingLeft": "+=4px" } );
+ equal( $elem.css( "paddingLeft" ), "5px", "'+=4px' on paddingLeft (hash)" );
- $elem.css({ "paddingLeft": "-=4px" });
- equal( $elem.css("paddingLeft"), "1px", "'-=4px' on paddingLeft (hash)" );
+ $elem.css( { "paddingLeft": "-=4px" } );
+ equal( $elem.css( "paddingLeft" ), "1px", "'-=4px' on paddingLeft (hash)" );
- $elem.css({ "padding-left": "+=4" });
- equal( $elem.css("paddingLeft"), "5px", "'+=4' on padding-left (hash)" );
+ $elem.css( { "padding-left": "+=4" } );
+ equal( $elem.css( "paddingLeft" ), "5px", "'+=4' on padding-left (hash)" );
- $elem.css({ "padding-left": "-=4" });
- equal( $elem.css("paddingLeft"), "1px", "'-=4' on padding-left (hash)" );
+ $elem.css( { "padding-left": "-=4" } );
+ equal( $elem.css( "paddingLeft" ), "1px", "'-=4' on padding-left (hash)" );
- $elem.css({ "padding-left": "+=4px" });
- equal( $elem.css("paddingLeft"), "5px", "'+=4px' on padding-left (hash)" );
+ $elem.css( { "padding-left": "+=4px" } );
+ equal( $elem.css( "paddingLeft" ), "5px", "'+=4px' on padding-left (hash)" );
- $elem.css({ "padding-left": "-=4px" });
- equal( $elem.css("paddingLeft"), "1px", "'-=4px' on padding-left (hash)" );
+ $elem.css( { "padding-left": "-=4px" } );
+ equal( $elem.css( "paddingLeft" ), "1px", "'-=4px' on padding-left (hash)" );
$elem.css( "paddingLeft", "+=4" );
- equal( $elem.css("paddingLeft"), "5px", "'+=4' on paddingLeft (params)" );
+ equal( $elem.css( "paddingLeft" ), "5px", "'+=4' on paddingLeft (params)" );
$elem.css( "paddingLeft", "-=4" );
- equal( $elem.css("paddingLeft"), "1px", "'-=4' on paddingLeft (params)" );
+ equal( $elem.css( "paddingLeft" ), "1px", "'-=4' on paddingLeft (params)" );
$elem.css( "padding-left", "+=4px" );
- equal( $elem.css("paddingLeft"), "5px", "'+=4px' on padding-left (params)" );
+ equal( $elem.css( "paddingLeft" ), "5px", "'+=4px' on padding-left (params)" );
$elem.css( "padding-left", "-=4px" );
- equal( $elem.css("paddingLeft"), "1px", "'-=4px' on padding-left (params)" );
+ equal( $elem.css( "paddingLeft" ), "1px", "'-=4px' on padding-left (params)" );
- $elem.css({ "opacity": "-=0.5" });
- equal( $elem.css("opacity"), "0.5", "'-=0.5' on opacity (hash)" );
+ $elem.css( { "opacity": "-=0.5" } );
+ equal( $elem.css( "opacity" ), "0.5", "'-=0.5' on opacity (hash)" );
- $elem.css({ "opacity": "+=0.5" });
- equal( $elem.css("opacity"), "1", "'+=0.5' on opacity (hash)" );
+ $elem.css( { "opacity": "+=0.5" } );
+ equal( $elem.css( "opacity" ), "1", "'+=0.5' on opacity (hash)" );
$elem.css( "opacity", "-=0.5" );
- equal( $elem.css("opacity"), "0.5", "'-=0.5' on opacity (params)" );
+ equal( $elem.css( "opacity" ), "0.5", "'-=0.5' on opacity (params)" );
$elem.css( "opacity", "+=0.5" );
- equal( $elem.css("opacity"), "1", "'+=0.5' on opacity (params)" );
-});
+ equal( $elem.css( "opacity" ), "1", "'+=0.5' on opacity (params)" );
+} );
test( "css() non-px relative values (gh-1711)", function() {
expect( 17 );
@@ -256,12 +255,12 @@ test( "css() non-px relative values (gh-1711)", function() {
"pc": parseFloat( $child.css( prop, "100pc" ).css( prop ) ) / 100,
"cm": parseFloat( $child.css( prop, "100cm" ).css( prop ) ) / 100,
"mm": parseFloat( $child.css( prop, "100mm" ).css( prop ) ) / 100,
- "%" : parseFloat( $child.css( prop, "100%" ).css( prop ) ) / 100
+ "%": parseFloat( $child.css( prop, "100%" ).css( prop ) ) / 100
};
};
- jQuery( "#nothiddendiv" ).css({ height: 1, padding: 0, width: 400 });
- $child.css({ height: 1, padding: 0 });
+ jQuery( "#nothiddendiv" ).css( { height: 1, padding: 0, width: 400 } );
+ $child.css( { height: 1, padding: 0 } );
getUnits( "width" );
cssCurrent = parseFloat( $child.css( "width", "50%" ).css( "width" ) );
@@ -285,44 +284,44 @@ test( "css() non-px relative values (gh-1711)", function() {
add( "lineHeight", 1, "cm" );
add( "lineHeight", -20, "mm" );
add( "lineHeight", 50, "%" );
-});
+} );
-test("css(String, Object)", function() {
+test( "css(String, Object)", function() {
expect( 19 );
var j, div, display, ret, success;
- jQuery("#floatTest").css("float", "left");
- equal( jQuery("#floatTest").css("float"), "left", "Modified CSS float using \"float\": Assert float is left");
- jQuery("#floatTest").css("font-size", "20px");
- equal( jQuery("#floatTest").css("font-size"), "20px", "Modified CSS font-size: Assert font-size is 20px");
+ jQuery( "#floatTest" ).css( "float", "left" );
+ equal( jQuery( "#floatTest" ).css( "float" ), "left", "Modified CSS float using \"float\": Assert float is left" );
+ jQuery( "#floatTest" ).css( "font-size", "20px" );
+ equal( 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("#foo").css("opacity", n);
- equal( jQuery("#foo").css("opacity"), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a String" );
- jQuery("#foo").css("opacity", parseFloat(n));
- equal( jQuery("#foo").css("opacity"), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a Number" );
- });
- jQuery("#foo").css("opacity", "");
- equal( jQuery("#foo").css("opacity"), "1", "Assert opacity is 1 when set to an empty String" );
+ jQuery.each( "0,0.25,0.5,0.75,1".split( "," ), function( i, n ) {
+ jQuery( "#foo" ).css( "opacity", n );
+ equal( jQuery( "#foo" ).css( "opacity" ), parseFloat( n ), "Assert opacity is " + parseFloat( n ) + " as a String" );
+ jQuery( "#foo" ).css( "opacity", parseFloat( n ) );
+ equal( jQuery( "#foo" ).css( "opacity" ), parseFloat( n ), "Assert opacity is " + parseFloat( n ) + " as a Number" );
+ } );
+ jQuery( "#foo" ).css( "opacity", "" );
+ equal( 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
- j = jQuery("#nonnodes").contents();
- j.css("overflow", "visible");
- equal( j.css("overflow"), "visible", "Check node,textnode,comment css works" );
- equal( jQuery("#t2037 .hidden").css("display"), "none", "Make sure browser thinks it is hidden" );
+ j = jQuery( "#nonnodes" ).contents();
+ j.css( "overflow", "visible" );
+ equal( j.css( "overflow" ), "visible", "Check node,textnode,comment css works" );
+ equal( jQuery( "#t2037 .hidden" ).css( "display" ), "none", "Make sure browser thinks it is hidden" );
- div = jQuery("#nothiddendiv");
- display = div.css("display");
- ret = div.css("display", undefined);
+ div = jQuery( "#nothiddendiv" );
+ display = div.css( "display" );
+ ret = div.css( "display", undefined );
equal( ret, div, "Make sure setting undefined returns the original set." );
- equal( div.css("display"), display, "Make sure that the display wasn't changed." );
+ equal( div.css( "display" ), display, "Make sure that the display wasn't changed." );
success = true;
try {
jQuery( "#foo" ).css( "backgroundColor", "rgba(0, 0, 0, 0.1)" );
}
- catch (e) {
+ catch ( e ) {
success = false;
}
ok( success, "Setting RGBA values does not throw Error (#5509)" );
@@ -330,7 +329,7 @@ test("css(String, Object)", function() {
jQuery( "#foo" ).css( "font", "7px/21px sans-serif" );
strictEqual( jQuery( "#foo" ).css( "line-height" ), "21px",
"Set font shorthand property (#14759)" );
-});
+} );
test( "css(String, Object) with negative values", function() {
expect( 4 );
@@ -345,7 +344,7 @@ test( "css(String, Object) with negative values", function() {
jQuery( "#nothiddendiv" ).css( "left", "-20px" );
equal( jQuery( "#nothiddendiv" ).css( "top" ), "-20px", "Ensure negative top values work." );
equal( jQuery( "#nothiddendiv" ).css( "left" ), "-20px", "Ensure negative left values work." );
-});
+} );
test( "css(Array)", function() {
expect( 2 );
@@ -357,30 +356,31 @@ test( "css(Array)", function() {
expectedSingle = {
"width": "16px"
},
- elem = jQuery("").appendTo("#qunit-fixture");
+ elem = jQuery( "" ).appendTo( "#qunit-fixture" );
- deepEqual( elem.css( expectedMany ).css([ "overflow", "width" ]), expectedMany, "Getting multiple element array" );
- deepEqual( elem.css( expectedSingle ).css([ "width" ]), expectedSingle, "Getting single element array" );
-});
+ deepEqual( elem.css( expectedMany ).css( [ "overflow", "width" ] ), expectedMany, "Getting multiple element array" );
+ deepEqual( elem.css( expectedSingle ).css( [ "width" ] ), expectedSingle, "Getting single element array" );
+} );
if ( !jQuery.support.opacity ) {
- test("css(String, Object) for MSIE", function() {
+ test( "css(String, Object) for MSIE", function() {
expect( 5 );
+
// 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');");
- equal( jQuery("#foo").css("opacity"), "1", "Assert opacity is 1 when a different filter is set in IE, #1438" );
+ jQuery( "#foo" ).css( "filter", "progid:DXImageTransform.Microsoft.Chroma(color='red');" );
+ equal( 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)",
filterVal2 = "progid:DXImageTransform.Microsoft.alpha(opacity=100) progid:DXImageTransform.Microsoft.Blur(pixelradius=5)",
filterVal3 = "progid:DXImageTransform.Microsoft.Blur(pixelradius=5)";
- jQuery("#foo").css("filter", filterVal);
- equal( jQuery("#foo").css("filter"), filterVal, "css('filter', val) works" );
- jQuery("#foo").css("opacity", 1);
- equal( jQuery("#foo").css("filter"), filterVal2, "Setting opacity in IE doesn't duplicate opacity filter" );
- equal( jQuery("#foo").css("opacity"), 1, "Setting opacity in IE with other filters works" );
- 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" );
- });
+ jQuery( "#foo" ).css( "filter", filterVal );
+ equal( jQuery( "#foo" ).css( "filter" ), filterVal, "css('filter', val) works" );
+ jQuery( "#foo" ).css( "opacity", 1 );
+ equal( jQuery( "#foo" ).css( "filter" ), filterVal2, "Setting opacity in IE doesn't duplicate opacity filter" );
+ equal( jQuery( "#foo" ).css( "opacity" ), 1, "Setting opacity in IE with other filters works" );
+ 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" );
+ } );
test( "Setting opacity to 1 properly removes filter: style (#6652)", function() {
var rfilter = /filter:[^;]*/i,
@@ -388,180 +388,180 @@ if ( !jQuery.support.opacity ) {
test2 = test.find( "div" ).css( "opacity", 1 );
function hasFilter( elem ) {
- return !!rfilter.exec( elem[0].style.cssText );
+ return !!rfilter.exec( elem[ 0 ].style.cssText );
}
expect( 2 );
ok( !hasFilter( test ), "Removed filter attribute on element without filter in stylesheet" );
ok( hasFilter( test2 ), "Filter attribute remains on element that had filter in stylesheet" );
- });
+ } );
}
-test("css(String, Function)", function() {
- expect(3);
+test( "css(String, Function)", function() {
+ expect( 3 );
var index,
- sizes = ["10px", "20px", "30px"];
+ sizes = [ "10px", "20px", "30px" ];
- jQuery("" +
+ jQuery( " ")
- .appendTo("body");
+ " " )
+ .appendTo( "body" );
index = 0;
- jQuery("#cssFunctionTest div").css("font-size", function() {
- var size = sizes[index];
+ jQuery( "#cssFunctionTest div" ).css( "font-size", function() {
+ var size = sizes[ index ];
index++;
return size;
- });
+ } );
index = 0;
- jQuery("#cssFunctionTest div").each(function() {
- var computedSize = jQuery(this).css("font-size"),
- expectedSize = sizes[index];
+ jQuery( "#cssFunctionTest div" ).each( function() {
+ var computedSize = jQuery( this ).css( "font-size" ),
+ expectedSize = sizes[ index ];
equal( computedSize, expectedSize, "Div #" + index + " should be " + expectedSize );
index++;
- });
+ } );
- jQuery("#cssFunctionTest").remove();
-});
+ jQuery( "#cssFunctionTest" ).remove();
+} );
-test("css(String, Function) with incoming value", function() {
- expect(3);
+test( "css(String, Function) with incoming value", function() {
+ expect( 3 );
var index,
- sizes = ["10px", "20px", "30px"];
+ sizes = [ "10px", "20px", "30px" ];
- jQuery("" +
+ jQuery( " ")
- .appendTo("body");
+ " " )
+ .appendTo( "body" );
index = 0;
- jQuery("#cssFunctionTest div").css("font-size", function() {
- var size = sizes[index];
+ jQuery( "#cssFunctionTest div" ).css( "font-size", function() {
+ var size = sizes[ index ];
index++;
return size;
- });
+ } );
index = 0;
- jQuery("#cssFunctionTest div").css("font-size", function(i, computedSize) {
- var expectedSize = sizes[index];
+ jQuery( "#cssFunctionTest div" ).css( "font-size", function( i, computedSize ) {
+ var expectedSize = sizes[ index ];
equal( computedSize, expectedSize, "Div #" + index + " should be " + expectedSize );
index++;
return computedSize;
- });
+ } );
- jQuery("#cssFunctionTest").remove();
-});
+ jQuery( "#cssFunctionTest" ).remove();
+} );
-test("css(Object) where values are Functions", function() {
- expect(3);
+test( "css(Object) where values are Functions", function() {
+ expect( 3 );
var index,
- sizes = ["10px", "20px", "30px"];
+ sizes = [ "10px", "20px", "30px" ];
- jQuery("" +
+ jQuery( " ")
- .appendTo("body");
+ " " )
+ .appendTo( "body" );
index = 0;
- jQuery("#cssFunctionTest div").css({"fontSize": function() {
- var size = sizes[index];
+ jQuery( "#cssFunctionTest div" ).css( { "fontSize": function() {
+ var size = sizes[ index ];
index++;
return size;
- }});
+ } } );
index = 0;
- jQuery("#cssFunctionTest div").each(function() {
- var computedSize = jQuery(this).css("font-size"),
- expectedSize = sizes[index];
+ jQuery( "#cssFunctionTest div" ).each( function() {
+ var computedSize = jQuery( this ).css( "font-size" ),
+ expectedSize = sizes[ index ];
equal( computedSize, expectedSize, "Div #" + index + " should be " + expectedSize );
index++;
- });
+ } );
- jQuery("#cssFunctionTest").remove();
-});
+ jQuery( "#cssFunctionTest" ).remove();
+} );
-test("css(Object) where values are Functions with incoming values", function() {
- expect(3);
+test( "css(Object) where values are Functions with incoming values", function() {
+ expect( 3 );
var index,
- sizes = ["10px", "20px", "30px"];
+ sizes = [ "10px", "20px", "30px" ];
- jQuery("" +
+ jQuery( " ")
- .appendTo("body");
+ " " )
+ .appendTo( "body" );
index = 0;
- jQuery("#cssFunctionTest div").css({"fontSize": function() {
- var size = sizes[index];
+ jQuery( "#cssFunctionTest div" ).css( { "fontSize": function() {
+ var size = sizes[ index ];
index++;
return size;
- }});
+ } } );
index = 0;
- jQuery("#cssFunctionTest div").css({"font-size": function(i, computedSize) {
- var expectedSize = sizes[index];
+ jQuery( "#cssFunctionTest div" ).css( { "font-size": function( i, computedSize ) {
+ var expectedSize = sizes[ index ];
equal( computedSize, expectedSize, "Div #" + index + " should be " + expectedSize );
index++;
return computedSize;
- }});
+ } } );
- jQuery("#cssFunctionTest").remove();
-});
+ jQuery( "#cssFunctionTest" ).remove();
+} );
-test("show(); hide()", function() {
+test( "show(); hide()", function() {
expect( 4 );
var hiddendiv, div;
- hiddendiv = jQuery("div.hidden");
+ hiddendiv = jQuery( "div.hidden" );
hiddendiv.hide();
- equal( hiddendiv.css("display"), "none", "Cascade-hidden div after hide()" );
+ equal( hiddendiv.css( "display" ), "none", "Cascade-hidden div after hide()" );
hiddendiv.show();
- equal( hiddendiv.css("display"), "none", "Show does not trump CSS cascade" );
+ equal( hiddendiv.css( "display" ), "none", "Show does not trump CSS cascade" );
- div = jQuery("").hide();
- equal( div.css("display"), "none", "Detached div hidden" );
- div.appendTo("#qunit-fixture").show();
- equal( div.css("display"), "block", "Initially-detached div after show()" );
+ div = jQuery( " " ).hide();
+ equal( div.css( "display" ), "none", "Detached div hidden" );
+ div.appendTo( "#qunit-fixture" ).show();
+ equal( div.css( "display" ), "block", "Initially-detached div after show()" );
-});
+} );
-test("show();", function() {
+test( "show();", function() {
expect( 18 );
var hiddendiv, div, pass, test;
- hiddendiv = jQuery("div.hidden");
+ hiddendiv = jQuery( "div.hidden" );
- equal(jQuery.css( hiddendiv[0], "display"), "none", "hiddendiv is display: none");
+ equal( jQuery.css( hiddendiv[ 0 ], "display" ), "none", "hiddendiv is display: none" );
- hiddendiv.css("display", "block");
- equal(jQuery.css( hiddendiv[0], "display"), "block", "hiddendiv is display: block");
+ hiddendiv.css( "display", "block" );
+ equal( jQuery.css( hiddendiv[ 0 ], "display" ), "block", "hiddendiv is display: block" );
hiddendiv.show();
- equal(jQuery.css( hiddendiv[0], "display"), "block", "hiddendiv is display: block");
+ equal( jQuery.css( hiddendiv[ 0 ], "display" ), "block", "hiddendiv is display: block" );
- hiddendiv.css("display","");
+ hiddendiv.css( "display", "" );
pass = true;
- div = jQuery("#qunit-fixture div");
- div.show().each(function(){
+ div = jQuery( "#qunit-fixture div" );
+ div.show().each( function() {
if ( this.style.display === "none" ) {
pass = false;
}
- });
+ } );
ok( pass, "Show" );
jQuery(
@@ -572,137 +572,137 @@ test("show();", function() {
" "
).appendTo( "#qunit-fixture" ).find( "*" ).css( "display", "none" );
- jQuery("#test-table").remove();
+ jQuery( "#test-table" ).remove();
test = {
- "div" : "block",
- "p" : "block",
- "a" : "inline",
- "code" : "inline",
- "pre" : "block",
- "span" : "inline",
- "table" : "table",
- "thead" : "table-header-group",
- "tbody" : "table-row-group",
- "tr" : "table-row",
- "th" : "table-cell",
- "td" : "table-cell",
- "ul" : "block",
- "li" : "list-item"
+ "div": "block",
+ "p": "block",
+ "a": "inline",
+ "code": "inline",
+ "pre": "block",
+ "span": "inline",
+ "table": "table",
+ "thead": "table-header-group",
+ "tbody": "table-row-group",
+ "tr": "table-row",
+ "th": "table-cell",
+ "td": "table-cell",
+ "ul": "block",
+ "li": "list-item"
};
- jQuery.each(test, function(selector, expected) {
- var elem = jQuery(selector, "#show-tests").show();
- equal( elem.css("display"), expected, "Show using correct display type for " + selector );
- });
+ jQuery.each( test, function( selector, expected ) {
+ var elem = jQuery( selector, "#show-tests" ).show();
+ equal( elem.css( "display" ), expected, "Show using correct display type for " + selector );
+ } );
// Make sure that showing or hiding a text node doesn't cause an error
- jQuery(" test text test").show().remove();
- jQuery(" test text test").hide().remove();
-});
+ jQuery( " test text test" ).show().remove();
+ jQuery( " test text test" ).hide().remove();
+} );
-test( "show() resolves correct default display for detached nodes", function(){
+test( "show() resolves correct default display for detached nodes", function() {
expect( 16 );
var div, span, tr;
- div = jQuery(" ");
- div.show().appendTo("#qunit-fixture");
- equal( div.css("display"), "none",
+ div = jQuery( " " );
+ div.show().appendTo( "#qunit-fixture" );
+ equal( div.css( "display" ), "none",
"A shown-while-detached div can be hidden by the CSS cascade" );
- div = jQuery(" ").children("div");
- div.show().appendTo("#qunit-fixture");
- equal( div.css("display"), "none",
+ div = jQuery( " " ).children( "div" );
+ div.show().appendTo( "#qunit-fixture" );
+ equal( div.css( "display" ), "none",
"A shown-while-detached div inside a visible div can be hidden by the CSS cascade" );
- span = jQuery(" ");
- span.show().appendTo("#qunit-fixture");
- equal( span.css("display"), "none",
+ span = jQuery( " " );
+ span.show().appendTo( "#qunit-fixture" );
+ equal( span.css( "display" ), "none",
"A shown-while-detached span can be hidden by the CSS cascade" );
- div = jQuery("div.hidden");
+ div = jQuery( "div.hidden" );
div.detach().show();
ok( !div[ 0 ].style.display,
"show() does not update inline style of a cascade-hidden-before-detach div" );
- div.appendTo("#qunit-fixture");
- equal( div.css("display"), "none",
+ div.appendTo( "#qunit-fixture" );
+ equal( div.css( "display" ), "none",
"A shown-while-detached cascade-hidden div is hidden after attachment" );
div.remove();
- span = jQuery(" ");
- span.appendTo("#qunit-fixture").detach().show().appendTo("#qunit-fixture");
- equal( span.css("display"), "none",
+ span = jQuery( " " );
+ span.appendTo( "#qunit-fixture" ).detach().show().appendTo( "#qunit-fixture" );
+ equal( span.css( "display" ), "none",
"A shown-while-detached cascade-hidden span is hidden after attachment" );
span.remove();
- div = jQuery( document.createElement("div") );
- div.show().appendTo("#qunit-fixture");
+ div = jQuery( document.createElement( "div" ) );
+ div.show().appendTo( "#qunit-fixture" );
ok( !div[ 0 ].style.display, "A shown-while-detached div has no inline style" );
- equal( div.css("display"), "block",
+ equal( div.css( "display" ), "block",
"A shown-while-detached div has default display after attachment" );
div.remove();
- div = jQuery(" ");
+ div = jQuery( " " );
div.show();
equal( div[ 0 ].style.display, "",
"show() updates inline style of a detached inline-hidden div" );
- div.appendTo("#qunit-fixture");
- equal( div.css("display"), "block",
+ div.appendTo( "#qunit-fixture" );
+ equal( div.css( "display" ), "block",
"A shown-while-detached inline-hidden div has default display after attachment" );
- div = jQuery(" ").children("div");
- div.show().appendTo("#qunit-fixture");
- equal( div.css("display"), "block",
+ div = jQuery( " " ).children( "div" );
+ div.show().appendTo( "#qunit-fixture" );
+ equal( div.css( "display" ), "block",
"A shown-while-detached inline-hidden div inside a visible div has default display " +
"after attachment" );
- span = jQuery(" ");
+ span = jQuery( " " );
span.show();
equal( span[ 0 ].style.display, "",
"show() updates inline style of a detached inline-hidden span" );
- span.appendTo("#qunit-fixture");
- equal( span.css("display"), "inline",
+ span.appendTo( "#qunit-fixture" );
+ equal( span.css( "display" ), "inline",
"A shown-while-detached inline-hidden span has default display after attachment" );
- div = jQuery(" ");
- div.show().appendTo("#qunit-fixture");
- equal( div.css("display"), "inline",
+ div = jQuery( " " );
+ div.show().appendTo( "#qunit-fixture" );
+ equal( div.css( "display" ), "inline",
"show() does not update inline style of a detached inline-visible div" );
div.remove();
- tr = jQuery(" |
");
- jQuery("#table").append( tr );
+ tr = jQuery( " |
" );
+ jQuery( "#table" ).append( tr );
tr.detach().hide().show();
ok( !tr[ 0 ].style.display, "Not-hidden detached tr elements have no inline style" );
tr.remove();
- span = jQuery(" ").hide().show();
+ span = jQuery( " " ).hide().show();
ok( !span[ 0 ].style.display, "Not-hidden detached span elements have no inline style" );
span.remove();
-});
+} );
-test("toggle()", function() {
- expect(9);
+test( "toggle()", function() {
+ expect( 9 );
var div, oldHide,
- x = jQuery("#foo");
+ x = jQuery( "#foo" );
- ok( x.is(":visible"), "is visible" );
+ ok( x.is( ":visible" ), "is visible" );
x.toggle();
- ok( x.is(":hidden"), "is hidden" );
+ ok( x.is( ":hidden" ), "is hidden" );
x.toggle();
- ok( x.is(":visible"), "is visible again" );
+ ok( x.is( ":visible" ), "is visible again" );
- x.toggle(true);
- ok( x.is(":visible"), "is visible" );
- x.toggle(false);
- ok( x.is(":hidden"), "is hidden" );
- x.toggle(true);
- ok( x.is(":visible"), "is visible again" );
+ x.toggle( true );
+ ok( x.is( ":visible" ), "is visible" );
+ x.toggle( false );
+ ok( x.is( ":hidden" ), "is hidden" );
+ x.toggle( true );
+ ok( x.is( ":visible" ), "is visible again" );
- div = jQuery(" ").appendTo("#qunit-fixture");
- x = div.find("div");
+ div = jQuery( " " ).appendTo( "#qunit-fixture" );
+ x = div.find( "div" );
strictEqual( x.toggle().css( "display" ), "none", "is hidden" );
strictEqual( x.toggle().css( "display" ), "block", "is visible" );
@@ -714,110 +714,110 @@ test("toggle()", function() {
};
x.toggle( name === "show" );
jQuery.fn.hide = oldHide;
-});
+} );
-test("hide hidden elements (bug #7141)", function() {
- expect(3);
+test( "hide hidden elements (bug #7141)", function() {
+ expect( 3 );
- var div = jQuery(" ").appendTo("#qunit-fixture");
- equal( div.css("display"), "none", "Element is hidden by default" );
+ var div = jQuery( " " ).appendTo( "#qunit-fixture" );
+ equal( div.css( "display" ), "none", "Element is hidden by default" );
div.hide();
- ok( !jQuery._data(div, "display"), "display data is undefined after hiding an already-hidden element" );
+ ok( !jQuery._data( div, "display" ), "display data is undefined after hiding an already-hidden element" );
div.show();
- equal( div.css("display"), "block", "Show a double-hidden element" );
+ equal( div.css( "display" ), "block", "Show a double-hidden element" );
div.remove();
-});
+} );
-test("jQuery.css(elem, 'height') doesn't clear radio buttons (bug #1095)", function () {
- expect(4);
+test( "jQuery.css(elem, 'height') doesn't clear radio buttons (bug #1095)", function() {
+ expect( 4 );
- var $checkedtest = jQuery("#checkedtest");
- jQuery.css($checkedtest[0], "height");
+ var $checkedtest = jQuery( "#checkedtest" );
+ jQuery.css( $checkedtest[ 0 ], "height" );
- ok( jQuery("input[type='radio']", $checkedtest).first().attr("checked"), "Check first radio still checked." );
- ok( !jQuery("input[type='radio']", $checkedtest).last().attr("checked"), "Check last radio still NOT checked." );
- ok( jQuery("input[type='checkbox']", $checkedtest).first().attr("checked"), "Check first checkbox still checked." );
- ok( !jQuery("input[type='checkbox']", $checkedtest).last().attr("checked"), "Check last checkbox still NOT checked." );
-});
+ ok( jQuery( "input[type='radio']", $checkedtest ).first().attr( "checked" ), "Check first radio still checked." );
+ ok( !jQuery( "input[type='radio']", $checkedtest ).last().attr( "checked" ), "Check last radio still NOT checked." );
+ ok( jQuery( "input[type='checkbox']", $checkedtest ).first().attr( "checked" ), "Check first checkbox still checked." );
+ ok( !jQuery( "input[type='checkbox']", $checkedtest ).last().attr( "checked" ), "Check last checkbox still NOT checked." );
+} );
-test("internal ref to elem.runtimeStyle (bug #7608)", function () {
- expect(1);
+test( "internal ref to elem.runtimeStyle (bug #7608)", function() {
+ expect( 1 );
var result = true;
try {
- jQuery("#foo").css( { "width": "0%" } ).css("width");
- } catch (e) {
+ jQuery( "#foo" ).css( { "width": "0%" } ).css( "width" );
+ } catch ( e ) {
result = false;
}
ok( result, "elem.runtimeStyle does not throw exception" );
-});
+} );
-test("marginRight computed style (bug #3333)", function() {
- expect(1);
+test( "marginRight computed style (bug #3333)", function() {
+ expect( 1 );
- var $div = jQuery("#foo");
- $div.css({
+ var $div = jQuery( "#foo" );
+ $div.css( {
"width": "1px",
"marginRight": 0
- });
+ } );
- equal($div.css("marginRight"), "0px", "marginRight correctly calculated with a width and display block");
-});
+ equal( $div.css( "marginRight" ), "0px", "marginRight correctly calculated with a width and display block" );
+} );
-test("box model properties incorrectly returning % instead of px, see #10639 and #12088", function() {
+test( "box model properties incorrectly returning % instead of px, see #10639 and #12088", function() {
expect( 2 );
- var container = jQuery(" ").width( 400 ).appendTo("#qunit-fixture"),
- el = jQuery(" ").css({ "width": "50%", "marginRight": "50%" }).appendTo( container ),
- el2 = jQuery(" ").css({ "width": "50%", "minWidth": "300px", "marginLeft": "25%" }).appendTo( container );
+ var container = jQuery( " " ).width( 400 ).appendTo( "#qunit-fixture" ),
+ el = jQuery( " " ).css( { "width": "50%", "marginRight": "50%" } ).appendTo( container ),
+ el2 = jQuery( " " ).css( { "width": "50%", "minWidth": "300px", "marginLeft": "25%" } ).appendTo( container );
- equal( el.css("marginRight"), "200px", "css('marginRight') returning % instead of px, see #10639" );
- equal( el2.css("marginLeft"), "100px", "css('marginLeft') returning incorrect pixel value, see #12088" );
-});
+ equal( el.css( "marginRight" ), "200px", "css('marginRight') returning % instead of px, see #10639" );
+ equal( el2.css( "marginLeft" ), "100px", "css('marginLeft') returning incorrect pixel value, see #12088" );
+} );
-test("jQuery.cssProps behavior, (bug #8402)", function() {
+test( "jQuery.cssProps behavior, (bug #8402)", function() {
expect( 2 );
- var div = jQuery( " " ).appendTo(document.body).css({
+ var div = jQuery( " " ).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");
+ 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;
-});
+} );
-test("widows & orphans #8936", function () {
+test( "widows & orphans #8936", function() {
- var $p = jQuery(" ").appendTo("#qunit-fixture");
+ var $p = jQuery( " " ).appendTo( "#qunit-fixture" );
- if ( "widows" in $p[0].style ) {
- expect(2);
+ if ( "widows" in $p[ 0 ].style ) {
+ expect( 2 );
- $p.css({
+ $p.css( {
"widows": 3,
"orphans": 3
- });
+ } );
- equal( $p.css("widows") || jQuery.style( $p[0], "widows" ), 3, "widows correctly set to 3");
- equal( $p.css("orphans") || jQuery.style( $p[0], "orphans" ), 3, "orphans correctly set to 3");
+ equal( $p.css( "widows" ) || jQuery.style( $p[ 0 ], "widows" ), 3, "widows correctly set to 3" );
+ equal( $p.css( "orphans" ) || jQuery.style( $p[ 0 ], "orphans" ), 3, "orphans correctly set to 3" );
} else {
- expect(1);
- ok( true, "jQuery does not attempt to test for style props that definitely don't exist in older versions of IE");
+ expect( 1 );
+ ok( true, "jQuery does not attempt to test for style props that definitely don't exist in older versions of IE" );
}
-
$p.remove();
-});
+} );
-test("can't get css for disconnected in IE<9, see #10254 and #8388", function() {
+test( "can't get css for disconnected in IE<9, see #10254 and #8388", function() {
expect( 2 );
var span, div;
@@ -826,9 +826,9 @@ test("can't get css for disconnected in IE<9, see #10254 and #8388", function()
div = jQuery( " " ).css( "top", 10 );
equal( div.css( "top" ), "10px", "can't get top in IE<9, see #8388" );
-});
+} );
-test("can't get background-position in IE<9, see #10796", function() {
+test( "can't get background-position in IE<9, see #10796", function() {
var div = jQuery( " " ).appendTo( "#qunit-fixture" ),
units = [
"0 0",
@@ -845,62 +845,63 @@ test("can't get background-position in IE<9, see #10796", function() {
expect( l );
- for( ; i < l; i++ ) {
+ for ( ; i < l; i++ ) {
div.css( "background-position", units [ i ] );
ok( div.css( "background-position" ), "can't get background-position in IE<9, see #10796" );
}
-});
+} );
-test("percentage properties for bottom and right in IE<9 should not be incorrectly transformed to pixels, see #11311", function() {
+test( "percentage properties for bottom and right in IE<9 should not be incorrectly transformed to pixels, see #11311", function() {
expect( 1 );
- var div = jQuery(" ").appendTo( "#qunit-fixture" );
+ var div = jQuery( " " ).appendTo( "#qunit-fixture" );
ok( window.getComputedStyle || div.css( "bottom" ) === "50%", "position properties get incorrectly transformed in IE<8, see #11311" );
-});
+} );
if ( jQuery.fn.offset ) {
- test("percentage properties for left and top should be transformed to pixels, see #9505", function() {
+ test( "percentage properties for left and top should be transformed to pixels, see #9505", function() {
expect( 2 );
- var parent = jQuery(" ").appendTo( "#qunit-fixture" ),
- div = jQuery(" ").appendTo( parent );
+ var parent = jQuery( " " ).appendTo( "#qunit-fixture" ),
+ div = jQuery( " " ).appendTo( parent );
- equal( div.css("top"), "100px", "position properties not transformed to pixels, see #9505" );
- equal( div.css("left"), "100px", "position properties not transformed to pixels, see #9505" );
- });
+ equal( div.css( "top" ), "100px", "position properties not transformed to pixels, see #9505" );
+ equal( div.css( "left" ), "100px", "position properties not transformed to pixels, see #9505" );
+ } );
}
-test("Do not append px (#9548, #12990)", function() {
+test( "Do not append px (#9548, #12990)", function() {
expect( 2 );
- var $div = jQuery(" ").appendTo("#qunit-fixture");
+ var $div = jQuery( " " ).appendTo( "#qunit-fixture" );
$div.css( "fill-opacity", 1 );
+
// Support: Android 2.3 (no support for fill-opacity)
if ( $div.css( "fill-opacity" ) ) {
- equal( $div.css("fill-opacity"), 1, "Do not append px to 'fill-opacity'" );
+ equal( $div.css( "fill-opacity" ), 1, "Do not append px to 'fill-opacity'" );
} else {
ok( true, "No support for fill-opacity CSS property" );
}
$div.css( "column-count", 1 );
- if ( $div.css("column-count") ) {
- equal( $div.css("column-count"), 1, "Do not append px to 'column-count'" );
+ if ( $div.css( "column-count" ) ) {
+ equal( $div.css( "column-count" ), 1, "Do not append px to 'column-count'" );
} else {
ok( true, "No support for column-count CSS property" );
}
-});
+} );
-test("css('width') and css('height') should respect box-sizing, see #11004", function() {
+test( "css('width') and css('height') should respect box-sizing, see #11004", function() {
expect( 4 );
// Support: Android 2.3 (-webkit-box-sizing).
- var el_dis = jQuery(" test "),
- el = el_dis.clone().appendTo("#qunit-fixture");
+ var el_dis = jQuery( " test " ),
+ el = el_dis.clone().appendTo( "#qunit-fixture" );
- equal( el.css("width"), el.css("width", el.css("width")).css("width"), "css('width') is not respecting box-sizing, see #11004");
- equal( el_dis.css("width"), el_dis.css("width", el_dis.css("width")).css("width"), "css('width') is not respecting box-sizing for disconnected element, see #11004");
- equal( el.css("height"), el.css("height", el.css("height")).css("height"), "css('height') is not respecting box-sizing, see #11004");
- equal( el_dis.css("height"), el_dis.css("height", el_dis.css("height")).css("height"), "css('height') is not respecting box-sizing for disconnected element, see #11004");
-});
+ equal( el.css( "width" ), el.css( "width", el.css( "width" ) ).css( "width" ), "css('width') is not respecting box-sizing, see #11004" );
+ equal( el_dis.css( "width" ), el_dis.css( "width", el_dis.css( "width" ) ).css( "width" ), "css('width') is not respecting box-sizing for disconnected element, see #11004" );
+ equal( el.css( "height" ), el.css( "height", el.css( "height" ) ).css( "height" ), "css('height') is not respecting box-sizing, see #11004" );
+ equal( el_dis.css( "height" ), el_dis.css( "height", el_dis.css( "height" ) ).css( "height" ), "css('height') is not respecting box-sizing for disconnected element, see #11004" );
+} );
testIframeWithCallback( "css('width') should work correctly before document ready (#14084)",
"css/cssWidthBeforeDocReady.html",
@@ -917,7 +918,7 @@ testIframeWithCallback( "css('width') should work correctly before document read
div.style.width = "3.3px";
qunitFixture.appendChild( div );
supportsFractionalGBCR = jQuery.support.gBCRDimensions() &&
- div.getBoundingClientRect().width.toFixed(1) === "3.3";
+ div.getBoundingClientRect().width.toFixed( 1 ) === "3.3";
qunitFixture.removeChild( div );
test( "css('width') and css('height') should return fractional values for nodes in the document", function() {
@@ -956,23 +957,23 @@ testIframeWithCallback( "css('width') should work correctly before document read
} );
} )();
-test("certain css values of 'normal' should be convertable to a number, see #8627", function() {
+test( "certain css values of 'normal' should be convertable to a number, see #8627", function() {
expect ( 3 );
- var el = jQuery(" test ").appendTo("#qunit-fixture");
+ var el = jQuery( " test " ).appendTo( "#qunit-fixture" );
- ok( jQuery.isNumeric( parseFloat( el.css("letterSpacing") ) ), "css('letterSpacing') not convertable to number, see #8627" );
- ok( jQuery.isNumeric( parseFloat( el.css("fontWeight") ) ), "css('fontWeight') not convertable to number, see #8627" );
+ ok( jQuery.isNumeric( parseFloat( el.css( "letterSpacing" ) ) ), "css('letterSpacing') not convertable to number, see #8627" );
+ ok( jQuery.isNumeric( parseFloat( el.css( "fontWeight" ) ) ), "css('fontWeight') not convertable to number, see #8627" );
equal( typeof el.css( "fontWeight" ), "string", ".css() returns a string" );
-});
+} );
// only run this test in IE9
if ( document.documentMode === 9 ) {
test( ".css('filter') returns a string in IE9, see #12537", function() {
expect( 1 );
- equal( jQuery(" ").css("filter"), "progid:DXImageTransform.Microsoft.gradient(startColorstr=#FFFFFF, endColorstr=#ECECEC)", "IE9 returns the correct value from css('filter')." );
- });
+ equal( jQuery( " " ).css( "filter" ), "progid:DXImageTransform.Microsoft.gradient(startColorstr=#FFFFFF, endColorstr=#ECECEC)", "IE9 returns the correct value from css('filter')." );
+ } );
}
test( "cssHooks - expand", function() {
@@ -980,7 +981,7 @@ test( "cssHooks - expand", function() {
var result,
properties = {
margin: [ "marginTop", "marginRight", "marginBottom", "marginLeft" ],
- borderWidth: [ "borderTopWidth", "borderRightWidth", "borderBottomWidth", "borderLeftWidth"],
+ borderWidth: [ "borderTopWidth", "borderRightWidth", "borderBottomWidth", "borderLeftWidth" ],
padding: [ "paddingTop", "paddingRight", "paddingBottom", "paddingLeft" ]
};
@@ -989,70 +990,70 @@ test( "cssHooks - expand", function() {
expected = {};
jQuery.each( keys, function( _, key ) {
expected[ key ] = 10;
- });
+ } );
result = hook.expand( 10 );
deepEqual( result, expected, property + " expands properly with a number" );
jQuery.each( keys, function( _, key ) {
expected[ key ] = "10px";
- });
+ } );
result = hook.expand( "10px" );
deepEqual( result, expected, property + " expands properly with '10px'" );
- expected[ keys[1] ] = expected[ keys[3] ] = "20px";
+ expected[ keys[ 1 ] ] = expected[ keys[ 3 ] ] = "20px";
result = hook.expand( "10px 20px" );
deepEqual( result, expected, property + " expands properly with '10px 20px'" );
- expected[ keys[2] ] = "30px";
+ expected[ keys[ 2 ] ] = "30px";
result = hook.expand( "10px 20px 30px" );
deepEqual( result, expected, property + " expands properly with '10px 20px 30px'" );
- expected[ keys[3] ] = "40px";
+ expected[ keys[ 3 ] ] = "40px";
result = hook.expand( "10px 20px 30px 40px" );
deepEqual( result, expected, property + " expands properly with '10px 20px 30px 40px'" );
- });
+ } );
-});
+} );
test( "css opacity consistency across browsers (#12685)", function() {
expect( 4 );
var el,
- fixture = jQuery("#qunit-fixture");
+ fixture = jQuery( "#qunit-fixture" );
// Append style element
- jQuery("").appendTo( fixture );
+ jQuery( "" ).appendTo( fixture );
- el = jQuery(" ").appendTo(fixture);
+ el = jQuery( " " ).appendTo( fixture );
- equal( Math.round( el.css("opacity") * 100 ), 10, "opacity from style sheet (-ms-filter:alpha with spaces)" );
- el.removeClass("opacityWithSpaces_t12685").addClass("opacityNoSpaces_t12685");
- equal( Math.round( el.css("opacity") * 100 ), 20, "opacity from style sheet (-ms-filter:alpha without spaces)" );
+ equal( Math.round( el.css( "opacity" ) * 100 ), 10, "opacity from style sheet (-ms-filter:alpha with spaces)" );
+ el.removeClass( "opacityWithSpaces_t12685" ).addClass( "opacityNoSpaces_t12685" );
+ equal( Math.round( el.css( "opacity" ) * 100 ), 20, "opacity from style sheet (-ms-filter:alpha without spaces)" );
el.css( "opacity", 0.3 );
- equal( Math.round( el.css("opacity") * 100 ), 30, "override opacity" );
+ equal( Math.round( el.css( "opacity" ) * 100 ), 30, "override opacity" );
el.css( "opacity", "" );
- equal( Math.round( el.css("opacity") * 100 ), 20, "remove opacity override" );
-});
+ equal( Math.round( el.css( "opacity" ) * 100 ), 20, "remove opacity override" );
+} );
test( ":visible/:hidden selectors", function() {
expect( 17 );
var $div, $table, $a;
- ok( jQuery("#nothiddendiv").is(":visible"), "Modifying CSS display: Assert element is visible" );
- jQuery("#nothiddendiv").css({ display: "none" });
- ok( !jQuery("#nothiddendiv").is(":visible"), "Modified CSS display: Assert element is hidden" );
- jQuery("#nothiddendiv").css({ "display": "block" });
- ok( jQuery("#nothiddendiv").is(":visible"), "Modified CSS display: Assert element is visible");
- ok( !jQuery(window).is(":visible"), "Calling is(':visible') on window does not throw an exception (#10267).");
- ok( !jQuery(document).is(":visible"), "Calling is(':visible') on document does not throw an exception (#10267).");
+ ok( jQuery( "#nothiddendiv" ).is( ":visible" ), "Modifying CSS display: Assert element is visible" );
+ jQuery( "#nothiddendiv" ).css( { display: "none" } );
+ ok( !jQuery( "#nothiddendiv" ).is( ":visible" ), "Modified CSS display: Assert element is hidden" );
+ jQuery( "#nothiddendiv" ).css( { "display": "block" } );
+ ok( jQuery( "#nothiddendiv" ).is( ":visible" ), "Modified CSS display: Assert element is visible" );
+ ok( !jQuery( window ).is( ":visible" ), "Calling is(':visible') on window does not throw an exception (#10267)." );
+ ok( !jQuery( document ).is( ":visible" ), "Calling is(':visible') on document does not throw an exception (#10267)." );
- ok( jQuery("#nothiddendiv").is(":visible"), "Modifying CSS display: Assert element is visible");
- jQuery("#nothiddendiv").css("display", "none");
- ok( !jQuery("#nothiddendiv").is(":visible"), "Modified CSS display: Assert element is hidden");
- jQuery("#nothiddendiv").css("display", "block");
- ok( jQuery("#nothiddendiv").is(":visible"), "Modified CSS display: Assert element is visible");
+ ok( jQuery( "#nothiddendiv" ).is( ":visible" ), "Modifying CSS display: Assert element is visible" );
+ jQuery( "#nothiddendiv" ).css( "display", "none" );
+ ok( !jQuery( "#nothiddendiv" ).is( ":visible" ), "Modified CSS display: Assert element is hidden" );
+ jQuery( "#nothiddendiv" ).css( "display", "block" );
+ ok( jQuery( "#nothiddendiv" ).is( ":visible" ), "Modified CSS display: Assert element is visible" );
ok( jQuery( "#siblingspan" ).is( ":visible" ), "Span with no content is visible" );
$div = jQuery( "
" ).appendTo( "#qunit-fixture" );
@@ -1065,19 +1066,19 @@ test( ":visible/:hidden selectors", function() {
// $br = jQuery( " " ).appendTo( "#qunit-fixture" );
// ok( $br.is( ":visible" ), "br element is visible" );
- $table = jQuery("#table");
- $table.html(" cell | cell | ");
- equal(jQuery("#table td:visible").length, 1, "hidden cell is not perceived as visible (#4512). Works on table elements");
- $table.css("display", "none").html(" cell | cell | ");
- equal(jQuery("#table td:visible").length, 0, "hidden cell children not perceived as visible (#4512)");
+ $table = jQuery( "#table" );
+ $table.html( " cell | cell | " );
+ equal( jQuery( "#table td:visible" ).length, 1, "hidden cell is not perceived as visible (#4512). Works on table elements" );
+ $table.css( "display", "none" ).html( " cell | cell | " );
+ equal( jQuery( "#table td:visible" ).length, 0, "hidden cell children not perceived as visible (#4512)" );
- t( "Is Visible", "#qunit-fixture div:visible:lt(2)", ["foo", "nothiddendiv"] );
+ t( "Is Visible", "#qunit-fixture div:visible:lt(2)", [ "foo", "nothiddendiv" ] );
t( "Is Not Hidden", "#qunit-fixture:hidden", [] );
- t( "Is Hidden", "#form input:hidden", ["hidden1","hidden2"] );
+ t( "Is Hidden", "#form input:hidden", [ "hidden1","hidden2" ] );
$a = jQuery( " Header" ).appendTo( "#qunit-fixture" );
ok( $a.is( ":visible" ), "Anchor tag with flow content is visible (gh-2227)" );
-});
+} );
test( "Keep the last style if the new one isn't recognized by the browser (#14836)", function() {
expect( 2 );
@@ -1087,56 +1088,59 @@ test( "Keep the last style if the new one isn't recognized by the browser (#1483
equal( el.css( "position" ), "absolute", "The old style is kept when setting an unrecognized value" );
el = jQuery( " " ).css( "position", "absolute" ).css( "position", " " );
equal( el.css( "position" ), "absolute", "The old style is kept when setting to a space" );
-});
+} );
test( "Reset the style if set to an empty string", function() {
expect( 1 );
var el = jQuery( " " ).css( "position", "absolute" ).css( "position", "" );
+
// Some browsers return an empty string; others "static". Both those cases mean the style
// was reset successfully so accept them both.
equal( el.css( "position" ) || "static", "static",
"The style can be reset by setting to an empty string" );
-});
+} );
asyncTest( "Clearing a Cloned Element's Style Shouldn't Clear the Original Element's Style (#8908)", 24, function() {
var baseUrl = document.location.href.replace( /([^\/]*)$/, "" ),
- styles = [{
+ styles = [ {
name: "backgroundAttachment",
- value: ["fixed"],
+ value: [ "fixed" ],
expected: [ "scroll" ]
},{
name: "backgroundColor",
value: [ "rgb(255, 0, 0)", "rgb(255,0,0)", "#ff0000" ],
- expected: ["transparent"]
+ expected: [ "transparent" ]
}, {
+
// Firefox returns auto's value
name: "backgroundImage",
value: [ "url('test.png')", "url(" + baseUrl + "test.png)", "url(\"" + baseUrl + "test.png\")" ],
expected: [ "none", "url(\"http://static.jquery.com/files/rocker/images/logo_jquery_215x53.gif\")" ]
}, {
name: "backgroundPosition",
- value: ["5% 5%"],
+ value: [ "5% 5%" ],
expected: [ "0% 0%", "-1000px 0px", "-1000px 0%" ]
}, {
+
// Firefox returns no-repeat
name: "backgroundRepeat",
- value: ["repeat-y"],
+ value: [ "repeat-y" ],
expected: [ "repeat", "no-repeat" ]
}, {
name: "backgroundClip",
- value: ["padding-box"],
- expected: ["border-box"]
+ value: [ "padding-box" ],
+ expected: [ "border-box" ]
}, {
name: "backgroundOrigin",
- value: ["content-box"],
- expected: ["padding-box"]
+ value: [ "content-box" ],
+ expected: [ "padding-box" ]
}, {
name: "backgroundSize",
- value: ["80px 60px"],
+ value: [ "80px 60px" ],
expected: [ "auto auto" ]
- }];
+ } ];
- jQuery.each(styles, function( index, style ) {
+ jQuery.each( styles, function( index, style ) {
var $clone, $clonedChildren,
$source = jQuery( "#firstp" ),
source = $source[ 0 ],
@@ -1160,7 +1164,7 @@ asyncTest( "Clearing a Cloned Element's Style Shouldn't Clear the Original Eleme
$clone.css( style.name, "" );
$clonedChildren.css( style.name, "" );
- window.setTimeout(function() {
+ window.setTimeout( function() {
notEqual( $clone.css( style.name ), style.value[ 0 ], "Cloned css was changed" );
ok( jQuery.inArray( $source.css( style.name ) !== -1, style.value ),
@@ -1173,10 +1177,10 @@ asyncTest( "Clearing a Cloned Element's Style Shouldn't Clear the Original Eleme
"; result: " + $children.css( style.name ) +
"; expected: " + style.value.join( "," ) );
}, 100 );
- });
+ } );
window.setTimeout( start, 1000 );
-});
+} );
test( "show() after hide() should always set display to initial value (#14750)", function() {
expect( 1 );
@@ -1188,13 +1192,13 @@ test( "show() after hide() should always set display to initial value (#14750)",
div.css( "display", "inline" ).hide().show().css( "display", "list-item" ).hide().show();
equal( div.css( "display" ), "list-item", "should get last set display value" );
-});
+} );
// Support: IE < 11
// We have to jump through the hoops here in order to test work with "order" CSS property,
// that some browsers do not support. This test is not, strictly speaking, correct,
// but it's the best that we can do.
-(function() {
+( function() {
var style = document.createElement( "div" ).style,
exist = "order" in style || "WebkitOrder" in style;
@@ -1206,9 +1210,9 @@ test( "show() after hide() should always set display to initial value (#14750)",
$elem.css( "order", 2 );
equal( $elem.css( "order" ), "2", "2 on order" );
- });
+ } );
}
-})();
+} )();
test( "Do not throw on frame elements from css method (#15098)", function() {
expect( 1 );
@@ -1233,7 +1237,7 @@ test( "Do not throw on frame elements from css method (#15098)", function() {
} catch ( _ ) {
ok( false, "It did throw" );
}
-});
+} );
test( "get upper case alpha opacity in IE8", function() {
expect( 1 );
@@ -1247,8 +1251,7 @@ test( "get upper case alpha opacity in IE8", function() {
equal( jQuery( div ).css( "opacity" ), "0.5", "get upper case alpha opacity in IE8 ok" );
fixture.removeChild( div );
-});
-
+} );
( function() {
var vendorPrefixes = [ "Webkit", "Moz", "ms" ];
@@ -1261,6 +1264,7 @@ test( "get upper case alpha opacity in IE8", function() {
}
test( "Don't default to a cached previously used wrong prefixed name (gh-2015)", function() {
+
// Note: this test needs a property we know is only supported in a prefixed version
// by at least one of our main supported browsers. This may get out of date so let's
// use -(webkit|moz)-appearance as well as those two are not on a standards track.
diff --git a/test/unit/data.js b/test/unit/data.js
index 1b4affb32..cf98a816c 100644
--- a/test/unit/data.js
+++ b/test/unit/data.js
@@ -1,47 +1,47 @@
-module("data", { teardown: moduleTeardown });
+module( "data", { teardown: moduleTeardown } );
-test("expando", function(){
- expect(1);
+test( "expando", function() {
+ expect( 1 );
- equal(jQuery.expando !== undefined, true, "jQuery is exposing the expando");
-});
+ equal( jQuery.expando !== undefined, true, "jQuery is exposing the expando" );
+} );
function dataTests( elem ) {
var dataObj, internalDataObj;
- equal( jQuery.data(elem, "foo"), undefined, "No data exists initially" );
- strictEqual( jQuery.hasData(elem), false, "jQuery.hasData agrees no data exists initially" );
+ equal( jQuery.data( elem, "foo" ), undefined, "No data exists initially" );
+ strictEqual( jQuery.hasData( elem ), false, "jQuery.hasData agrees no data exists initially" );
- dataObj = jQuery.data(elem);
+ dataObj = jQuery.data( elem );
equal( typeof dataObj, "object", "Calling data with no args gives us a data object reference" );
- strictEqual( jQuery.data(elem), dataObj, "Calling jQuery.data returns the same data object when called multiple times" );
+ strictEqual( jQuery.data( elem ), dataObj, "Calling jQuery.data returns the same data object when called multiple times" );
- strictEqual( jQuery.hasData(elem), false, "jQuery.hasData agrees no data exists even when an empty data obj exists" );
+ strictEqual( jQuery.hasData( elem ), false, "jQuery.hasData agrees no data exists even when an empty data obj exists" );
- dataObj["foo"] = "bar";
- equal( jQuery.data(elem, "foo"), "bar", "Data is readable by jQuery.data when set directly on a returned data object" );
+ dataObj[ "foo" ] = "bar";
+ equal( jQuery.data( elem, "foo" ), "bar", "Data is readable by jQuery.data when set directly on a returned data object" );
- strictEqual( jQuery.hasData(elem), true, "jQuery.hasData agrees data exists when data exists" );
+ strictEqual( jQuery.hasData( elem ), true, "jQuery.hasData agrees data exists when data exists" );
- jQuery.data(elem, "foo", "baz");
- equal( jQuery.data(elem, "foo"), "baz", "Data can be changed by jQuery.data" );
- equal( dataObj["foo"], "baz", "Changes made through jQuery.data propagate to referenced data object" );
+ jQuery.data( elem, "foo", "baz" );
+ equal( jQuery.data( elem, "foo" ), "baz", "Data can be changed by jQuery.data" );
+ equal( dataObj[ "foo" ], "baz", "Changes made through jQuery.data propagate to referenced data object" );
- jQuery.data(elem, "foo", undefined);
- equal( jQuery.data(elem, "foo"), "baz", "Data is not unset by passing undefined to jQuery.data" );
+ jQuery.data( elem, "foo", undefined );
+ equal( jQuery.data( elem, "foo" ), "baz", "Data is not unset by passing undefined to jQuery.data" );
- jQuery.data(elem, "foo", null);
- strictEqual( jQuery.data(elem, "foo"), null, "Setting null using jQuery.data works OK" );
+ jQuery.data( elem, "foo", null );
+ strictEqual( jQuery.data( elem, "foo" ), null, "Setting null using jQuery.data works OK" );
- jQuery.data(elem, "foo", "foo1");
+ jQuery.data( elem, "foo", "foo1" );
- jQuery.data(elem, { "bar" : "baz", "boom" : "bloz" });
- strictEqual( jQuery.data(elem, "foo"), "foo1", "Passing an object extends the data object instead of replacing it" );
- equal( jQuery.data(elem, "boom"), "bloz", "Extending the data object works" );
+ jQuery.data( elem, { "bar": "baz", "boom": "bloz" } );
+ strictEqual( jQuery.data( elem, "foo" ), "foo1", "Passing an object extends the data object instead of replacing it" );
+ equal( jQuery.data( elem, "boom" ), "bloz", "Extending the data object works" );
- jQuery._data(elem, "foo", "foo2", true);
- equal( jQuery._data(elem, "foo"), "foo2", "Setting internal data works" );
- equal( jQuery.data(elem, "foo"), "foo1", "Setting internal data does not override user data" );
+ jQuery._data( elem, "foo", "foo2", true );
+ equal( jQuery._data( elem, "foo" ), "foo2", "Setting internal data works" );
+ equal( jQuery.data( elem, "foo" ), "foo1", "Setting internal data does not override user data" );
internalDataObj = jQuery._data( elem );
ok( internalDataObj, "Internal data object exists" );
@@ -49,31 +49,31 @@ function dataTests( elem ) {
strictEqual( elem.boom, undefined, "Data is never stored directly on the object" );
- jQuery.removeData(elem, "foo");
- strictEqual( jQuery.data(elem, "foo"), undefined, "jQuery.removeData removes single properties" );
+ jQuery.removeData( elem, "foo" );
+ strictEqual( jQuery.data( elem, "foo" ), undefined, "jQuery.removeData removes single properties" );
- jQuery.removeData(elem);
- strictEqual( jQuery._data(elem), internalDataObj, "jQuery.removeData does not remove internal data if it exists" );
+ jQuery.removeData( elem );
+ strictEqual( jQuery._data( elem ), internalDataObj, "jQuery.removeData does not remove internal data if it exists" );
- jQuery.data(elem, "foo", "foo1");
- jQuery._data(elem, "foo", "foo2");
+ jQuery.data( elem, "foo", "foo1" );
+ jQuery._data( elem, "foo", "foo2" );
- equal( jQuery.data(elem, "foo"), "foo1", "(sanity check) Ensure data is set in user data object" );
- equal( jQuery._data(elem, "foo"), "foo2", "(sanity check) Ensure data is set in internal data object" );
+ equal( jQuery.data( elem, "foo" ), "foo1", "(sanity check) Ensure data is set in user data object" );
+ equal( jQuery._data( elem, "foo" ), "foo2", "(sanity check) Ensure data is set in internal data object" );
- strictEqual( jQuery._data(elem, jQuery.expando), undefined, "Removing the last item in internal data destroys the internal data object" );
+ strictEqual( jQuery._data( elem, jQuery.expando ), undefined, "Removing the last item in internal data destroys the internal data object" );
- jQuery._data(elem, "foo", "foo2");
- equal( jQuery._data(elem, "foo"), "foo2", "(sanity check) Ensure data is set in internal data object" );
+ jQuery._data( elem, "foo", "foo2" );
+ equal( jQuery._data( elem, "foo" ), "foo2", "(sanity check) Ensure data is set in internal data object" );
- jQuery.removeData(elem, "foo");
- equal( jQuery._data(elem, "foo"), "foo2", "(sanity check) jQuery.removeData for user data does not remove internal data" );
+ jQuery.removeData( elem, "foo" );
+ equal( jQuery._data( elem, "foo" ), "foo2", "(sanity check) jQuery.removeData for user data does not remove internal data" );
}
-test("jQuery.data(div)", function() {
+test( "jQuery.data(div)", function() {
expect( 25 );
- var div = document.createElement("div");
+ var div = document.createElement( "div" );
dataTests( div );
@@ -81,15 +81,15 @@ test("jQuery.data(div)", function() {
// assert that nothing else was put in there, and that that
// one stayed there.
QUnit.expectJqData( this, div, "foo" );
-});
+} );
-test("jQuery.data({})", function() {
+test( "jQuery.data({})", function() {
expect( 25 );
dataTests( {} );
-});
+} );
-test("jQuery.data(window)", function() {
+test( "jQuery.data(window)", function() {
expect( 25 );
// remove bound handlers from window object to stop potential false positives caused by fix for #5280 in
@@ -97,53 +97,53 @@ test("jQuery.data(window)", function() {
jQuery( window ).off( "unload" );
dataTests( window );
-});
+} );
-test("jQuery.data(document)", function() {
+test( "jQuery.data(document)", function() {
expect( 25 );
dataTests( document );
QUnit.expectJqData( this, document, "foo" );
-});
+} );
-test("Expando cleanup", function() {
+test( "Expando cleanup", function() {
expect( 4 );
- var div = document.createElement("div");
+ var div = document.createElement( "div" );
- function assertExpandoAbsent(message) {
+ function assertExpandoAbsent( message ) {
strictEqual( div[ jQuery.expando ], undefined, message );
}
- assertExpandoAbsent("There is no expando on new elements");
+ assertExpandoAbsent( "There is no expando on new elements" );
- jQuery.data(div, "foo", 100);
- jQuery.data(div, "bar", 200);
+ jQuery.data( div, "foo", 100 );
+ jQuery.data( div, "bar", 200 );
- ok(jQuery.expando in div, "There is an expando on the element after using $.data()");
+ ok( jQuery.expando in div, "There is an expando on the element after using $.data()" );
- jQuery.removeData(div, "foo");
+ jQuery.removeData( div, "foo" );
- ok(jQuery.expando in div, "There is still an expando on the element after removing (some) of the data");
+ ok( jQuery.expando in div, "There is still an expando on the element after removing (some) of the data" );
- jQuery.removeData(div, "bar");
+ jQuery.removeData( div, "bar" );
- assertExpandoAbsent("Removing the last item in the data store deletes the expando");
+ assertExpandoAbsent( "Removing the last item in the data store deletes the expando" );
// Clean up unattached element
- jQuery(div).remove();
-});
+ jQuery( div ).remove();
+} );
-test("Data is not being set on comment and text nodes", function() {
- expect(2);
+test( "Data is not being set on comment and text nodes", function() {
+ expect( 2 );
- ok( !jQuery.hasData( jQuery("").data("foo", 0) ) );
- ok( !jQuery.hasData( jQuery(" text").contents().data("foo", 0) ) );
+ ok( !jQuery.hasData( jQuery( "" ).data( "foo", 0 ) ) );
+ ok( !jQuery.hasData( jQuery( " text" ).contents().data( "foo", 0 ) ) );
-});
+} );
-test("jQuery.acceptData", function() {
+test( "jQuery.acceptData", function() {
expect( 10 );
var flash, pdf;
@@ -168,43 +168,43 @@ test("jQuery.acceptData", function() {
ok( jQuery.acceptData(
jQuery( "#form" ).append( " " )[ 0 ] ),
"form with aliased DOM properties" );
-});
+} );
// attempting to access the data of an undefined jQuery element should be undefined
-test("jQuery().data() === undefined (#14101)", function() {
+test( "jQuery().data() === undefined (#14101)", function() {
expect( 2 );
- strictEqual(jQuery().data(), undefined);
- strictEqual(jQuery().data("key"), undefined);
-});
+ strictEqual( jQuery().data(), undefined );
+ strictEqual( jQuery().data( "key" ), undefined );
+} );
-test(".data()", function() {
- expect(5);
+test( ".data()", function() {
+ expect( 5 );
var div, dataObj, nodiv, obj;
- div = jQuery("#foo");
- strictEqual( div.data("foo"), undefined, "Make sure that missing result is undefined" );
- div.data("test", "success");
+ div = jQuery( "#foo" );
+ strictEqual( div.data( "foo" ), undefined, "Make sure that missing result is undefined" );
+ div.data( "test", "success" );
dataObj = div.data();
- deepEqual( dataObj, {test: "success"}, "data() returns entire data object with expected properties" );
- strictEqual( div.data("foo"), undefined, "Make sure that missing result is still undefined" );
+ deepEqual( dataObj, { test: "success" }, "data() returns entire data object with expected properties" );
+ strictEqual( div.data( "foo" ), undefined, "Make sure that missing result is still undefined" );
- nodiv = jQuery("#unfound");
+ nodiv = jQuery( "#unfound" );
equal( nodiv.data(), null, "data() on empty set returns null" );
obj = { foo: "bar" };
- jQuery(obj).data("foo", "baz");
+ jQuery( obj ).data( "foo", "baz" );
- dataObj = jQuery.extend(true, {}, jQuery(obj).data());
+ dataObj = jQuery.extend( true, {}, jQuery( obj ).data() );
deepEqual( dataObj, { "foo": "baz" }, "Retrieve data object from a wrapped JS object (#7524)" );
-});
+} );
function testDataTypes( $obj ) {
- jQuery.each({
+ jQuery.each( {
"null": null,
"true": true,
"false": false,
@@ -212,78 +212,78 @@ function testDataTypes( $obj ) {
"one": 1,
"empty string": "",
"empty array": [],
- "array": [1],
+ "array": [ 1 ],
"empty object": {},
"object": { foo: "bar" },
"date": new Date(),
"regex": /test/,
"function": function() {}
}, function( type, value ) {
- strictEqual( $obj.data( "test", value ).data("test"), value, "Data set to " + type );
- });
+ strictEqual( $obj.data( "test", value ).data( "test" ), value, "Data set to " + type );
+ } );
}
-test("jQuery(Element).data(String, Object).data(String)", function() {
+test( "jQuery(Element).data(String, Object).data(String)", function() {
expect( 18 );
- var parent = jQuery(" "),
+ var parent = jQuery( " " ),
div = parent.children();
- strictEqual( div.data("test"), undefined, "No data exists initially" );
- strictEqual( div.data("test", "success").data("test"), "success", "Data added" );
- strictEqual( div.data("test", "overwritten").data("test"), "overwritten", "Data overwritten" );
- strictEqual( div.data("test", undefined).data("test"), "overwritten", ".data(key,undefined) does nothing but is chainable (#5571)");
- strictEqual( div.data("notexist"), undefined, "No data exists for unset key" );
+ strictEqual( div.data( "test" ), undefined, "No data exists initially" );
+ strictEqual( div.data( "test", "success" ).data( "test" ), "success", "Data added" );
+ strictEqual( div.data( "test", "overwritten" ).data( "test" ), "overwritten", "Data overwritten" );
+ strictEqual( div.data( "test", undefined ).data( "test" ), "overwritten", ".data(key,undefined) does nothing but is chainable (#5571)" );
+ strictEqual( div.data( "notexist" ), undefined, "No data exists for unset key" );
testDataTypes( div );
parent.remove();
-});
+} );
-test("jQuery(plain Object).data(String, Object).data(String)", function() {
+test( "jQuery(plain Object).data(String, Object).data(String)", function() {
expect( 16 );
// #3748
- var $obj = jQuery({ exists: true });
- strictEqual( $obj.data("nothing"), undefined, "Non-existent data returns undefined");
- strictEqual( $obj.data("exists"), undefined, "Object properties are not returned as data" );
+ var $obj = jQuery( { exists: true } );
+ strictEqual( $obj.data( "nothing" ), undefined, "Non-existent data returns undefined" );
+ strictEqual( $obj.data( "exists" ), undefined, "Object properties are not returned as data" );
testDataTypes( $obj );
// Clean up
$obj.removeData();
- deepEqual( $obj[0], { exists: true }, "removeData does not clear the object" );
-});
+ deepEqual( $obj[ 0 ], { exists: true }, "removeData does not clear the object" );
+} );
-test("data-* attributes", function() {
+test( "data-* attributes", function() {
expect( 46 );
var prop, i, l, metadata, elem,
obj, obj2, check, num, num2,
parseJSON = jQuery.parseJSON,
- div = jQuery(" "),
- child = jQuery(" "),
- dummy = jQuery(" ");
+ div = jQuery( " " ),
+ child = jQuery( " " ),
+ dummy = jQuery( " " );
- equal( div.data("attr"), undefined, "Check for non-existing data-attr attribute" );
+ equal( div.data( "attr" ), undefined, "Check for non-existing data-attr attribute" );
- div.attr("data-attr", "exists");
- equal( div.data("attr"), "exists", "Check for existing data-attr attribute" );
+ div.attr( "data-attr", "exists" );
+ equal( div.data( "attr" ), "exists", "Check for existing data-attr attribute" );
- div.attr("data-attr", "exists2");
- equal( div.data("attr"), "exists", "Check that updates to data- don't update .data()" );
+ div.attr( "data-attr", "exists2" );
+ equal( div.data( "attr" ), "exists", "Check that updates to data- don't update .data()" );
- div.data("attr", "internal").attr("data-attr", "external");
- equal( div.data("attr"), "internal", "Check for .data('attr') precedence (internal > external data-* attribute)" );
+ div.data( "attr", "internal" ).attr( "data-attr", "external" );
+ equal( div.data( "attr" ), "internal", "Check for .data('attr') precedence (internal > external data-* attribute)" );
div.remove();
- child.appendTo("#qunit-fixture");
- equal( child.data("myobj"), "old data", "Value accessed from data-* attribute");
- equal( child.data("foo-42"), "boosh", "camelCasing does not affect numbers (#1751)" );
+ child.appendTo( "#qunit-fixture" );
+ equal( child.data( "myobj" ), "old data", "Value accessed from data-* attribute" );
+ equal( child.data( "foo-42" ), "boosh", "camelCasing does not affect numbers (#1751)" );
- child.data("myobj", "replaced");
- equal( child.data("myobj"), "replaced", "Original data overwritten");
+ child.data( "myobj", "replaced" );
+ equal( child.data( "myobj" ), "replaced", "Original data overwritten" );
- child.data("ignored", "cache");
- equal( child.data("ignored"), "cache", "Cached data used before DOM data-* fallback");
+ child.data( "ignored", "cache" );
+ equal( child.data( "ignored" ), "cache", "Cached data used before DOM data-* fallback" );
obj = child.data();
obj2 = dummy.data();
@@ -294,8 +294,8 @@ test("data-* attributes", function() {
dummy.remove();
for ( i = 0, l = check.length; i < l; i++ ) {
- ok( obj[ check[i] ], "Make sure data- property exists when calling data-." );
- ok( obj2[ check[i] ], "Make sure data- property exists when calling data-." );
+ ok( obj[ check[ i ] ], "Make sure data- property exists when calling data-." );
+ ok( obj2[ check[ i ] ], "Make sure data- property exists when calling data-." );
}
for ( prop in obj ) {
@@ -310,9 +310,9 @@ test("data-* attributes", function() {
equal( num2, check.length, "Make sure that the right number of properties came through." );
- child.attr("data-other", "newvalue");
+ child.attr( "data-other", "newvalue" );
- equal( child.data("other"), "test", "Make sure value was pulled in properly from a .data()." );
+ equal( child.data( "other" ), "test", "Make sure value was pulled in properly from a .data()." );
// attribute parsing
i = 0;
@@ -322,218 +322,218 @@ test("data-* attributes", function() {
};
child
- .attr("data-true", "true")
- .attr("data-false", "false")
- .attr("data-five", "5")
- .attr("data-point", "5.5")
- .attr("data-pointe", "5.5E3")
- .attr("data-grande", "5.574E9")
- .attr("data-hexadecimal", "0x42")
- .attr("data-pointbad", "5..5")
- .attr("data-pointbad2", "-.")
- .attr("data-bigassnum", "123456789123456789123456789")
- .attr("data-badjson", "{123}")
- .attr("data-badjson2", "[abc]")
- .attr("data-notjson", " {}")
- .attr("data-notjson2", "[] ")
- .attr("data-empty", "")
- .attr("data-space", " ")
- .attr("data-null", "null")
- .attr("data-string", "test");
+ .attr( "data-true", "true" )
+ .attr( "data-false", "false" )
+ .attr( "data-five", "5" )
+ .attr( "data-point", "5.5" )
+ .attr( "data-pointe", "5.5E3" )
+ .attr( "data-grande", "5.574E9" )
+ .attr( "data-hexadecimal", "0x42" )
+ .attr( "data-pointbad", "5..5" )
+ .attr( "data-pointbad2", "-." )
+ .attr( "data-bigassnum", "123456789123456789123456789" )
+ .attr( "data-badjson", "{123}" )
+ .attr( "data-badjson2", "[abc]" )
+ .attr( "data-notjson", " {}" )
+ .attr( "data-notjson2", "[] " )
+ .attr( "data-empty", "" )
+ .attr( "data-space", " " )
+ .attr( "data-null", "null" )
+ .attr( "data-string", "test" );
- strictEqual( child.data("true"), true, "Primitive true read from attribute");
- strictEqual( child.data("false"), false, "Primitive false read from attribute");
- strictEqual( child.data("five"), 5, "Integer read from attribute");
- strictEqual( child.data("point"), 5.5, "Floating-point number read from attribute");
- strictEqual( child.data("pointe"), "5.5E3",
- "Exponential-notation number read from attribute as string");
- strictEqual( child.data("grande"), "5.574E9",
- "Big exponential-notation number read from attribute as string");
- strictEqual( child.data("hexadecimal"), "0x42",
- "Hexadecimal number read from attribute as string");
- strictEqual( child.data("pointbad"), "5..5",
- "Extra-point non-number read from attribute as string");
- strictEqual( child.data("pointbad2"), "-.",
- "No-digit non-number read from attribute as string");
- strictEqual( child.data("bigassnum"), "123456789123456789123456789",
- "Bad bigass number read from attribute as string");
- strictEqual( child.data("badjson"), "{123}", "Bad JSON object read from attribute as string");
- strictEqual( child.data("badjson2"), "[abc]", "Bad JSON array read from attribute as string");
- strictEqual( child.data("notjson"), " {}",
- "JSON object with leading non-JSON read from attribute as string");
- strictEqual( child.data("notjson2"), "[] ",
- "JSON array with trailing non-JSON read from attribute as string");
- strictEqual( child.data("empty"), "", "Empty string read from attribute");
- strictEqual( child.data("space"), " ", "Whitespace string 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( "true" ), true, "Primitive true read from attribute" );
+ strictEqual( child.data( "false" ), false, "Primitive false read from attribute" );
+ strictEqual( child.data( "five" ), 5, "Integer read from attribute" );
+ strictEqual( child.data( "point" ), 5.5, "Floating-point number read from attribute" );
+ strictEqual( child.data( "pointe" ), "5.5E3",
+ "Exponential-notation number read from attribute as string" );
+ strictEqual( child.data( "grande" ), "5.574E9",
+ "Big exponential-notation number read from attribute as string" );
+ strictEqual( child.data( "hexadecimal" ), "0x42",
+ "Hexadecimal number read from attribute as string" );
+ strictEqual( child.data( "pointbad" ), "5..5",
+ "Extra-point non-number read from attribute as string" );
+ strictEqual( child.data( "pointbad2" ), "-.",
+ "No-digit non-number read from attribute as string" );
+ strictEqual( child.data( "bigassnum" ), "123456789123456789123456789",
+ "Bad bigass number read from attribute as string" );
+ strictEqual( child.data( "badjson" ), "{123}", "Bad JSON object read from attribute as string" );
+ strictEqual( child.data( "badjson2" ), "[abc]", "Bad JSON array read from attribute as string" );
+ strictEqual( child.data( "notjson" ), " {}",
+ "JSON object with leading non-JSON read from attribute as string" );
+ strictEqual( child.data( "notjson2" ), "[] ",
+ "JSON array with trailing non-JSON read from attribute as string" );
+ strictEqual( child.data( "empty" ), "", "Empty string read from attribute" );
+ strictEqual( child.data( "space" ), " ", "Whitespace string read from attribute" );
+ strictEqual( child.data( "null" ), null, "Primitive null read from attribute" );
+ strictEqual( child.data( "string" ), "test", "Typical string read from attribute" );
equal( i, 2, "Correct number of JSON parse attempts when reading from attributes" );
jQuery.parseJSON = parseJSON;
child.remove();
// tests from metadata plugin
- function testData(index, elem) {
- switch (index) {
+ function testData( index, elem ) {
+ switch ( index ) {
case 0:
- equal(jQuery(elem).data("foo"), "bar", "Check foo property");
- equal(jQuery(elem).data("bar"), "baz", "Check baz property");
+ equal( jQuery( elem ).data( "foo" ), "bar", "Check foo property" );
+ equal( jQuery( elem ).data( "bar" ), "baz", "Check baz property" );
break;
case 1:
- equal(jQuery(elem).data("test"), "bar", "Check test property");
- equal(jQuery(elem).data("bar"), "baz", "Check bar property");
+ equal( jQuery( elem ).data( "test" ), "bar", "Check test property" );
+ equal( jQuery( elem ).data( "bar" ), "baz", "Check bar property" );
break;
case 2:
- equal(jQuery(elem).data("zoooo"), "bar", "Check zoooo property");
- deepEqual(jQuery(elem).data("bar"), {"test":"baz"}, "Check bar property");
+ equal( jQuery( elem ).data( "zoooo" ), "bar", "Check zoooo property" );
+ deepEqual( jQuery( elem ).data( "bar" ), { "test":"baz" }, "Check bar property" );
break;
case 3:
- equal(jQuery(elem).data("number"), true, "Check number property");
- deepEqual(jQuery(elem).data("stuff"), [2,8], "Check stuff property");
+ equal( jQuery( elem ).data( "number" ), true, "Check number property" );
+ deepEqual( jQuery( elem ).data( "stuff" ), [ 2,8 ], "Check stuff property" );
break;
default:
- ok(false, ["Assertion failed on index ", index, ", with data"].join(""));
+ ok( false, [ "Assertion failed on index ", index, ", with data" ].join( "" ) );
}
}
metadata = " - Some stuff
- Some stuff
- Some stuff
- Some stuff
";
- elem = jQuery(metadata).appendTo("#qunit-fixture");
+ elem = jQuery( metadata ).appendTo( "#qunit-fixture" );
- elem.find("li").each(testData);
+ elem.find( "li" ).each( testData );
elem.remove();
-});
+} );
-test(".data(Object)", function() {
- expect(4);
+test( ".data(Object)", function() {
+ expect( 4 );
var obj, jqobj,
- div = jQuery(" ");
+ div = jQuery( " " );
- div.data({ "test": "in", "test2": "in2" });
- equal( div.data("test"), "in", "Verify setting an object in data" );
- equal( div.data("test2"), "in2", "Verify setting an object in data" );
+ div.data( { "test": "in", "test2": "in2" } );
+ equal( div.data( "test" ), "in", "Verify setting an object in data" );
+ equal( div.data( "test2" ), "in2", "Verify setting an object in data" );
- obj = {test:"unset"};
- jqobj = jQuery(obj);
+ obj = { test:"unset" };
+ jqobj = jQuery( obj );
- jqobj.data("test", "unset");
- jqobj.data({ "test": "in", "test2": "in2" });
- equal( jQuery.data(obj)["test"], "in", "Verify setting an object on an object extends the data object" );
- equal( obj["test2"], undefined, "Verify setting an object on an object does not extend the object" );
+ jqobj.data( "test", "unset" );
+ jqobj.data( { "test": "in", "test2": "in2" } );
+ equal( jQuery.data( obj )[ "test" ], "in", "Verify setting an object on an object extends the data object" );
+ equal( obj[ "test2" ], undefined, "Verify setting an object on an object does not extend the object" );
// manually clean up detached elements
div.remove();
-});
+} );
-test("jQuery.removeData", function() {
- expect(10);
+test( "jQuery.removeData", function() {
+ expect( 10 );
var obj,
- div = jQuery("#foo")[0];
- jQuery.data(div, "test", "testing");
- jQuery.removeData(div, "test");
- equal( jQuery.data(div, "test"), undefined, "Check removal of data" );
+ div = jQuery( "#foo" )[ 0 ];
+ jQuery.data( div, "test", "testing" );
+ jQuery.removeData( div, "test" );
+ equal( jQuery.data( div, "test" ), undefined, "Check removal of data" );
- jQuery.data(div, "test2", "testing");
+ jQuery.data( div, "test2", "testing" );
jQuery.removeData( div );
- ok( !jQuery.data(div, "test2"), "Make sure that the data property no longer exists." );
+ ok( !jQuery.data( div, "test2" ), "Make sure that the data property no longer exists." );
ok( !div[ jQuery.expando ], "Make sure the expando no longer exists, as well." );
- jQuery.data(div, {
+ jQuery.data( div, {
test3: "testing",
test4: "testing"
- });
+ } );
jQuery.removeData( div, "test3 test4" );
- ok( !jQuery.data(div, "test3") || jQuery.data(div, "test4"), "Multiple delete with spaces." );
+ ok( !jQuery.data( div, "test3" ) || jQuery.data( div, "test4" ), "Multiple delete with spaces." );
- jQuery.data(div, {
+ jQuery.data( div, {
test3: "testing",
test4: "testing"
- });
+ } );
jQuery.removeData( div, [ "test3", "test4" ] );
- ok( !jQuery.data(div, "test3") || jQuery.data(div, "test4"), "Multiple delete by array." );
+ ok( !jQuery.data( div, "test3" ) || jQuery.data( div, "test4" ), "Multiple delete by array." );
- jQuery.data(div, {
+ jQuery.data( div, {
"test3 test4": "testing",
"test3": "testing"
- });
+ } );
jQuery.removeData( div, "test3 test4" );
- ok( !jQuery.data(div, "test3 test4"), "Multiple delete with spaces deleted key with exact name" );
- ok( jQuery.data(div, "test3"), "Left the partial matched key alone" );
+ ok( !jQuery.data( div, "test3 test4" ), "Multiple delete with spaces deleted key with exact name" );
+ ok( jQuery.data( div, "test3" ), "Left the partial matched key alone" );
obj = {};
- jQuery.data(obj, "test", "testing");
- equal( jQuery(obj).data("test"), "testing", "verify data on plain object");
- jQuery.removeData(obj, "test");
- equal( jQuery.data(obj, "test"), undefined, "Check removal of data on plain object" );
+ jQuery.data( obj, "test", "testing" );
+ equal( jQuery( obj ).data( "test" ), "testing", "verify data on plain object" );
+ jQuery.removeData( obj, "test" );
+ equal( jQuery.data( obj, "test" ), undefined, "Check removal of data on plain object" );
jQuery.data( window, "BAD", true );
jQuery.removeData( window, "BAD" );
ok( !jQuery.data( window, "BAD" ), "Make sure that the value was not still set." );
-});
+} );
-test(".removeData()", function() {
- expect(6);
- var div = jQuery("#foo");
- div.data("test", "testing");
- div.removeData("test");
- equal( div.data("test"), undefined, "Check removal of data" );
+test( ".removeData()", function() {
+ expect( 6 );
+ var div = jQuery( "#foo" );
+ div.data( "test", "testing" );
+ div.removeData( "test" );
+ equal( div.data( "test" ), undefined, "Check removal of data" );
- div.data("test", "testing");
- div.data("test.foo", "testing2");
- div.removeData("test.bar");
- equal( div.data("test.foo"), "testing2", "Make sure data is intact" );
- equal( div.data("test"), "testing", "Make sure data is intact" );
+ div.data( "test", "testing" );
+ div.data( "test.foo", "testing2" );
+ div.removeData( "test.bar" );
+ equal( div.data( "test.foo" ), "testing2", "Make sure data is intact" );
+ equal( div.data( "test" ), "testing", "Make sure data is intact" );
- div.removeData("test");
- equal( div.data("test.foo"), "testing2", "Make sure data is intact" );
- equal( div.data("test"), undefined, "Make sure data is intact" );
+ div.removeData( "test" );
+ equal( div.data( "test.foo" ), "testing2", "Make sure data is intact" );
+ equal( div.data( "test" ), undefined, "Make sure data is intact" );
- div.removeData("test.foo");
- equal( div.data("test.foo"), undefined, "Make sure data is intact" );
-});
+ div.removeData( "test.foo" );
+ equal( div.data( "test.foo" ), undefined, "Make sure data is intact" );
+} );
-if (window.JSON && window.JSON.stringify) {
- test("JSON serialization (#8108)", function () {
- expect(1);
+if ( window.JSON && window.JSON.stringify ) {
+ test( "JSON serialization (#8108)", function() {
+ expect( 1 );
var obj = { "foo": "bar" };
- jQuery.data(obj, "hidden", true);
+ jQuery.data( obj, "hidden", true );
- equal( JSON.stringify(obj), "{\"foo\":\"bar\"}", "Expando is hidden from JSON.stringify" );
- });
+ equal( JSON.stringify( obj ), "{\"foo\":\"bar\"}", "Expando is hidden from JSON.stringify" );
+ } );
}
-test("jQuery.data should follow html5 specification regarding camel casing", function() {
- expect(10);
+test( "jQuery.data should follow html5 specification regarding camel casing", function() {
+ expect( 10 );
- var div = jQuery(" ")
- .prependTo("body");
+ var div = jQuery( " " )
+ .prependTo( "body" );
- equal( div.data()["wTF"], "ftw", "Verify single letter data-* key" );
- equal( div.data()["bigALittleA"], "bouncing-b", "Verify single letter mixed data-* key" );
+ equal( div.data()[ "wTF" ], "ftw", "Verify single letter data-* key" );
+ equal( div.data()[ "bigALittleA" ], "bouncing-b", "Verify single letter mixed data-* key" );
- equal( div.data()["foo"], "a", "Verify single word data-* key" );
- equal( div.data()["fooBar"], "b", "Verify multiple word data-* key" );
- equal( div.data()["fooBarBaz"], "c", "Verify multiple word data-* key" );
+ equal( div.data()[ "foo" ], "a", "Verify single word data-* key" );
+ equal( div.data()[ "fooBar" ], "b", "Verify multiple word data-* key" );
+ equal( div.data()[ "fooBarBaz" ], "c", "Verify multiple word data-* key" );
- equal( div.data("foo"), "a", "Verify single word data-* key" );
- equal( div.data("fooBar"), "b", "Verify multiple word data-* key" );
- equal( div.data("fooBarBaz"), "c", "Verify multiple word data-* key" );
+ equal( div.data( "foo" ), "a", "Verify single word data-* key" );
+ equal( div.data( "fooBar" ), "b", "Verify multiple word data-* key" );
+ equal( div.data( "fooBarBaz" ), "c", "Verify multiple word data-* key" );
- div.data("foo-bar", "d");
+ div.data( "foo-bar", "d" );
- equal( div.data("fooBar"), "d", "Verify updated data-* key" );
- equal( div.data("foo-bar"), "d", "Verify updated data-* key" );
+ equal( div.data( "fooBar" ), "d", "Verify updated data-* key" );
+ equal( div.data( "foo-bar" ), "d", "Verify updated data-* key" );
div.remove();
-});
+} );
-test("jQuery.data should not miss data with preset hyphenated property names", function() {
+test( "jQuery.data should not miss data with preset hyphenated property names", function() {
- expect(2);
+ expect( 2 );
- var div = jQuery(" ", { id: "hyphened" }).appendTo("#qunit-fixture"),
+ var div = jQuery( " ", { id: "hyphened" } ).appendTo( "#qunit-fixture" ),
test = {
"camelBar": "camelBar",
"hyphen-foo": "hyphen-foo"
@@ -541,36 +541,36 @@ test("jQuery.data should not miss data with preset hyphenated property names", f
div.data( test );
- jQuery.each( test , function(i, k) {
- equal( div.data(k), k, "data with property '"+k+"' was correctly found");
- });
-});
+ jQuery.each( test, function( i, k ) {
+ equal( div.data( k ), k, "data with property '" + k + "' was correctly found" );
+ } );
+} );
-test(".data should not miss attr() set data-* with hyphenated property names", function() {
- expect(2);
+test( ".data should not miss attr() set data-* with hyphenated property names", function() {
+ expect( 2 );
var a, b;
- a = jQuery(" ").appendTo("#qunit-fixture");
+ a = jQuery( " " ).appendTo( "#qunit-fixture" );
a.attr( "data-long-param", "test" );
- a.data( "long-param", { a: 2 });
+ a.data( "long-param", { a: 2 } );
- deepEqual( a.data("long-param"), { a: 2 }, "data with property long-param was found, 1" );
+ deepEqual( a.data( "long-param" ), { a: 2 }, "data with property long-param was found, 1" );
- b = jQuery(" ").appendTo("#qunit-fixture");
+ b = jQuery( " " ).appendTo( "#qunit-fixture" );
b.attr( "data-long-param", "test" );
b.data( "long-param" );
- b.data( "long-param", { a: 2 });
+ b.data( "long-param", { a: 2 } );
- deepEqual( b.data("long-param"), { a: 2 }, "data with property long-param was found, 2" );
-});
+ deepEqual( b.data( "long-param" ), { a: 2 }, "data with property long-param was found, 2" );
+} );
-test(".data always sets data with the camelCased key (gh-2257)", function() {
+test( ".data always sets data with the camelCased key (gh-2257)", function() {
expect( 36 );
- var div = jQuery(" ").appendTo("#qunit-fixture"),
+ var div = jQuery( " " ).appendTo( "#qunit-fixture" ),
datas = {
"non-empty": "a string",
"empty-string": "",
@@ -592,7 +592,7 @@ test(".data always sets data with the camelCased key (gh-2257)", function() {
var allData = div.data();
equal( allData[ key ], undefined, ".data(key, val) does not store with hyphenated keys" );
equal( allData[ jQuery.camelCase( key ) ], val, ".data(key, val) stores the camelCased key" );
- });
+ } );
div.removeData();
@@ -601,8 +601,8 @@ test(".data always sets data with the camelCased key (gh-2257)", function() {
var allData = div.data();
equal( allData[ key ], undefined, ".data(object) does not store with hyphenated keys" );
equal( allData[ jQuery.camelCase( key ) ], val, ".data(object) stores the camelCased key" );
- });
-});
+ } );
+} );
test( ".data should not strip more than one hyphen when camelCasing (gh-2070)", function() {
expect( 3 );
@@ -612,10 +612,10 @@ test( ".data should not strip more than one hyphen when camelCasing (gh-2070)",
equal( allData.nestedSingle, "single", "Key is correctly camelCased" );
equal( allData[ "nested-Double" ], "double", "Key with double hyphens is correctly camelCased" );
equal( allData[ "nested--Triple" ], "triple", "Key with triple hyphens is correctly camelCased" );
-});
+} );
-test(".data supports interoperable hyphenated/camelCase get/set of properties with arbitrary non-null|NaN|undefined values", function() {
- var div = jQuery(" ", { id: "hyphened" }).appendTo("#qunit-fixture"),
+test( ".data supports interoperable hyphenated/camelCase get/set of properties with arbitrary non-null|NaN|undefined values", function() {
+ var div = jQuery( " ", { id: "hyphened" } ).appendTo( "#qunit-fixture" ),
datas = {
"non-empty": "a string",
"empty-string": "",
@@ -625,6 +625,7 @@ test(".data supports interoperable hyphenated/camelCase get/set of properties wi
"an-object": {},
"bool-true": true,
"bool-false": false,
+
// JSHint enforces double quotes,
// but JSON strings need double quotes to parse
// so we need escaped double quotes here
@@ -641,11 +642,11 @@ test(".data supports interoperable hyphenated/camelCase get/set of properties wi
deepEqual( div.data( key ), val, "get: " + key );
deepEqual( div.data( jQuery.camelCase( key ) ), val, "get: " + jQuery.camelCase( key ) );
- });
-});
+ } );
+} );
-test("jQuery.data supports interoperable removal of hyphenated/camelCase properties", function() {
- var div = jQuery(" ", { id: "hyphened" }).appendTo("#qunit-fixture"),
+test( "jQuery.data supports interoperable removal of hyphenated/camelCase properties", function() {
+ var div = jQuery( " ", { id: "hyphened" } ).appendTo( "#qunit-fixture" ),
datas = {
"non-empty": "a string",
"empty-string": "",
@@ -655,6 +656,7 @@ test("jQuery.data supports interoperable removal of hyphenated/camelCase propert
"an-object": {},
"bool-true": true,
"bool-false": false,
+
// JSHint enforces double quotes,
// but JSON strings need double quotes to parse
// so we need escaped double quotes here
@@ -673,11 +675,11 @@ test("jQuery.data supports interoperable removal of hyphenated/camelCase propert
equal( div.data( key ), undefined, "get: " + key );
- });
-});
+ } );
+} );
-test(".data supports interoperable removal of properties SET TWICE #13850", function() {
- var div = jQuery(" ").appendTo("#qunit-fixture"),
+test( ".data supports interoperable removal of properties SET TWICE #13850", function() {
+ var div = jQuery( " " ).appendTo( "#qunit-fixture" ),
datas = {
"non-empty": "a string",
"empty-string": "",
@@ -687,6 +689,7 @@ test(".data supports interoperable removal of properties SET TWICE #13850", func
"an-object": {},
"bool-true": true,
"bool-false": false,
+
// JSHint enforces double quotes,
// but JSON strings need double quotes to parse
// so we need escaped double quotes here
@@ -702,51 +705,54 @@ test(".data supports interoperable removal of properties SET TWICE #13850", func
div.removeData( key );
equal( div.data( key ), undefined, "removal: " + key );
- });
-});
+ } );
+} );
test( ".removeData supports removal of hyphenated properties via array (#12786, gh-2257)", function() {
expect( 4 );
var div, plain, compare;
- div = jQuery(" ").appendTo("#qunit-fixture");
- plain = jQuery({});
+ div = jQuery( " " ).appendTo( "#qunit-fixture" );
+ plain = jQuery( {} );
// Properties should always be camelCased
compare = {
+
// From batch assignment .data({ "a-a": 1 })
"aA": 1,
+
// From property, value assignment .data( "b-b", 1 )
"bB": 1
};
// Mixed assignment
- div.data({ "a-a": 1 }).data( "b-b", 1 );
- plain.data({ "a-a": 1 }).data( "b-b", 1 );
+ div.data( { "a-a": 1 } ).data( "b-b", 1 );
+ plain.data( { "a-a": 1 } ).data( "b-b", 1 );
deepEqual( div.data(), compare, "Data appears as expected. (div)" );
deepEqual( plain.data(), compare, "Data appears as expected. (plain)" );
- div.removeData([ "a-a", "b-b" ]);
- plain.removeData([ "a-a", "b-b" ]);
+ div.removeData( [ "a-a", "b-b" ] );
+ plain.removeData( [ "a-a", "b-b" ] );
deepEqual( div.data(), {}, "Data is empty. (div)" );
deepEqual( plain.data(), {}, "Data is empty. (plain)" );
-});
+} );
// Test originally by Moschel
-test("Triggering the removeData should not throw exceptions. (#10080)", function() {
- expect(1);
+test( "Triggering the removeData should not throw exceptions. (#10080)", function() {
+ expect( 1 );
stop();
- var frame = jQuery("#loadediframe");
- jQuery(frame[0].contentWindow).on("unload", function() {
- ok(true, "called unload");
+ var frame = jQuery( "#loadediframe" );
+ jQuery( frame[ 0 ].contentWindow ).on( "unload", function() {
+ ok( true, "called unload" );
start();
- });
+ } );
+
// change the url to trigger unload
- frame.attr("src", "data/iframe.html?param=true");
-});
+ frame.attr( "src", "data/iframe.html?param=true" );
+} );
test( "Only check element attributes once when calling .data() - #8909", function() {
expect( 2 );
@@ -766,18 +772,18 @@ test( "Only check element attributes once when calling .data() - #8909", functio
// clean up data cache
element.remove();
-});
+} );
test( "JSON data- attributes can have newlines", function() {
- expect(1);
+ expect( 1 );
- var x = jQuery(" ");
- equal( x.data("some").foo, "bar", "got a JSON data- attribute with spaces" );
+ var x = jQuery( " " );
+ equal( x.data( "some" ).foo, "bar", "got a JSON data- attribute with spaces" );
x.remove();
-});
+} );
testIframeWithCallback( "enumerate data attrs on body (#14894)", "data/dataAttrs.html", function( result ) {
- expect(1);
+ expect( 1 );
- equal(result, "ok", "enumeration of data- attrs on body" );
-});
+ equal( result, "ok", "enumeration of data- attrs on body" );
+} );
diff --git a/test/unit/deferred.js b/test/unit/deferred.js
index 1aa15435f..3bf6ca49e 100644
--- a/test/unit/deferred.js
+++ b/test/unit/deferred.js
@@ -1,6 +1,6 @@
module( "deferred", {
teardown: moduleTeardown
-});
+} );
jQuery.each( [ "", " - new operator" ], function( _, withNew ) {
@@ -16,32 +16,32 @@ jQuery.each( [ "", " - new operator" ], function( _, withNew ) {
ok( jQuery.isFunction( defer.pipe ), "defer.pipe is a function" );
- createDeferred().resolve().done(function() {
+ createDeferred().resolve().done( function() {
ok( true, "Success on resolve" );
strictEqual( this.state(), "resolved", "Deferred is resolved (state)" );
- }).fail(function() {
+ } ).fail( function() {
ok( false, "Error on resolve" );
- }).always(function() {
+ } ).always( function() {
ok( true, "Always callback on resolve" );
- });
+ } );
- createDeferred().reject().done(function() {
+ createDeferred().reject().done( function() {
ok( false, "Success on reject" );
- }).fail(function() {
+ } ).fail( function() {
ok( true, "Error on reject" );
strictEqual( this.state(), "rejected", "Deferred is rejected (state)" );
- }).always(function() {
+ } ).always( function() {
ok( true, "Always callback on reject" );
- });
+ } );
- createDeferred(function( defer ) {
+ createDeferred( function( defer ) {
ok( this === defer, "Defer passed as this & first argument" );
- this.resolve("done");
- }).done(function( value ) {
+ this.resolve( "done" );
+ } ).done( function( value ) {
strictEqual( value, "done", "Passed function executed" );
- });
+ } );
- createDeferred(function( defer ) {
+ createDeferred( function( defer ) {
var promise = defer.promise(),
func = function() {},
funcPromise = defer.promise( func );
@@ -54,17 +54,17 @@ jQuery.each( [ "", " - new operator" ], function( _, withNew ) {
if ( promise[ key ] !== func[ key ] ) {
strictEqual( func[ key ], promise[ key ], key + " is the same" );
}
- });
- });
+ } );
+ } );
jQuery.expandedEach = jQuery.each;
- jQuery.expandedEach( "resolve reject".split(" "), function( _, change ) {
- createDeferred(function( defer ) {
+ jQuery.expandedEach( "resolve reject".split( " " ), function( _, change ) {
+ createDeferred( function( defer ) {
strictEqual( defer.state(), "pending", "pending after creation" );
var checked = 0;
- defer.progress(function( value ) {
+ defer.progress( function( value ) {
strictEqual( value, checked, "Progress: right value (" + value + ") received" );
- });
+ } );
for ( checked = 0; checked < 3; checked++ ) {
defer.notify( checked );
}
@@ -72,11 +72,10 @@ jQuery.each( [ "", " - new operator" ], function( _, withNew ) {
defer[ change ]();
notStrictEqual( defer.state(), "pending", "not pending after " + change );
defer.notify();
- });
- });
- });
-});
-
+ } );
+ } );
+ } );
+} );
test( "jQuery.Deferred - chainability", function() {
@@ -85,13 +84,13 @@ test( "jQuery.Deferred - chainability", function() {
expect( 10 );
jQuery.expandedEach = jQuery.each;
- jQuery.expandedEach( "resolve reject notify resolveWith rejectWith notifyWith done fail progress always".split(" "), function( _, method ) {
+ jQuery.expandedEach( "resolve reject notify resolveWith rejectWith notifyWith done fail progress always".split( " " ), function( _, method ) {
var object = {
m: defer[ method ]
};
strictEqual( object.m(), object, method + " is chainable" );
- });
-});
+ } );
+} );
test( "jQuery.Deferred.then - filtering (done)", function( assert ) {
@@ -99,36 +98,36 @@ test( "jQuery.Deferred.then - filtering (done)", function( assert ) {
var value1, value2, value3,
defer = jQuery.Deferred(),
- piped = defer.then(function( a, b ) {
+ piped = defer.then( function( a, b ) {
return a * b;
- }),
+ } ),
done = jQuery.map( new Array( 3 ), function() { return assert.async(); } );
- piped.done(function( result ) {
+ piped.done( function( result ) {
value3 = result;
- });
+ } );
- defer.done(function( a, b ) {
+ defer.done( function( a, b ) {
value1 = a;
value2 = b;
- });
+ } );
- defer.resolve( 2, 3 ).then(function() {
+ defer.resolve( 2, 3 ).then( function() {
assert.strictEqual( value1, 2, "first resolve value ok" );
assert.strictEqual( value2, 3, "second resolve value ok" );
assert.strictEqual( value3, 6, "result of filter ok" );
done.pop().call();
- });
+ } );
- jQuery.Deferred().reject().then(function() {
+ jQuery.Deferred().reject().then( function() {
assert.ok( false, "then should not be called on reject" );
- }).then( null, done.pop() );
+ } ).then( null, done.pop() );
- jQuery.Deferred().resolve().then( jQuery.noop ).done(function( value ) {
+ jQuery.Deferred().resolve().then( jQuery.noop ).done( function( value ) {
assert.strictEqual( value, undefined, "then done callback can return undefined/null" );
done.pop().call();
- });
-});
+ } );
+} );
test( "jQuery.Deferred.then - filtering (fail)", function( assert ) {
@@ -138,70 +137,70 @@ test( "jQuery.Deferred.then - filtering (fail)", function( assert ) {
defer = jQuery.Deferred(),
piped = defer.then( null, function( a, b ) {
return a * b;
- }),
+ } ),
done = jQuery.map( new Array( 3 ), function() { return assert.async(); } );
- piped.done(function( result ) {
+ piped.done( function( result ) {
value3 = result;
- });
+ } );
- defer.fail(function( a, b ) {
+ defer.fail( function( a, b ) {
value1 = a;
value2 = b;
- });
+ } );
defer.reject( 2, 3 ).then( null, function() {
assert.strictEqual( value1, 2, "first reject value ok" );
assert.strictEqual( value2, 3, "second reject value ok" );
assert.strictEqual( value3, 6, "result of filter ok" );
done.pop().call();
- });
+ } );
jQuery.Deferred().resolve().then( null, function() {
assert.ok( false, "then should not be called on resolve" );
- }).then( done.pop() );
+ } ).then( done.pop() );
- jQuery.Deferred().reject().then( null, jQuery.noop ).done(function( value ) {
+ jQuery.Deferred().reject().then( null, jQuery.noop ).done( function( value ) {
assert.strictEqual( value, undefined, "then fail callback can return undefined/null" );
done.pop().call();
- });
-});
+ } );
+} );
test( "jQuery.Deferred.catch", function( assert ) {
assert.expect( 4 );
var value1, value2, value3,
defer = jQuery.Deferred(),
- piped = defer[ "catch" ](function( a, b ) {
+ piped = defer[ "catch" ]( function( a, b ) {
return a * b;
- }),
+ } ),
done = jQuery.map( new Array( 3 ), function() { return assert.async(); } );
- piped.done(function( result ) {
+ piped.done( function( result ) {
value3 = result;
- });
+ } );
- defer.fail(function( a, b ) {
+ defer.fail( function( a, b ) {
value1 = a;
value2 = b;
- });
+ } );
- defer.reject( 2, 3 )[ "catch" ](function() {
+ defer.reject( 2, 3 )[ "catch" ]( function() {
assert.strictEqual( value1, 2, "first reject value ok" );
assert.strictEqual( value2, 3, "second reject value ok" );
assert.strictEqual( value3, 6, "result of filter ok" );
done.pop().call();
- });
+ } );
- jQuery.Deferred().resolve()[ "catch" ](function() {
+ jQuery.Deferred().resolve()[ "catch" ]( function() {
assert.ok( false, "then should not be called on resolve" );
- }).then( done.pop() );
+ } ).then( done.pop() );
- jQuery.Deferred().reject()[ "catch" ]( jQuery.noop ).done(function( value ) {
+ jQuery.Deferred().reject()[ "catch" ]( jQuery.noop ).done( function( value ) {
assert.strictEqual( value, undefined, "then fail callback can return undefined/null" );
done.pop().call();
- });
-});
+ } );
+} );
test( "[PIPE ONLY] jQuery.Deferred.pipe - filtering (fail)", function( assert ) {
@@ -211,34 +210,34 @@ test( "[PIPE ONLY] jQuery.Deferred.pipe - filtering (fail)", function( assert )
defer = jQuery.Deferred(),
piped = defer.pipe( null, function( a, b ) {
return a * b;
- }),
+ } ),
done = jQuery.map( new Array( 3 ), function() { return assert.async(); } );
- piped.fail(function( result ) {
+ piped.fail( function( result ) {
value3 = result;
- });
+ } );
- defer.fail(function( a, b ) {
+ defer.fail( function( a, b ) {
value1 = a;
value2 = b;
- });
+ } );
defer.reject( 2, 3 ).pipe( null, function() {
assert.strictEqual( value1, 2, "first reject value ok" );
assert.strictEqual( value2, 3, "second reject value ok" );
assert.strictEqual( value3, 6, "result of filter ok" );
done.pop().call();
- });
+ } );
jQuery.Deferred().resolve().pipe( null, function() {
assert.ok( false, "then should not be called on resolve" );
- }).then( done.pop() );
+ } ).then( done.pop() );
- jQuery.Deferred().reject().pipe( null, jQuery.noop ).fail(function( value ) {
+ jQuery.Deferred().reject().pipe( null, jQuery.noop ).fail( function( value ) {
assert.strictEqual( value, undefined, "then fail callback can return undefined/null" );
done.pop().call();
- });
-});
+ } );
+} );
test( "jQuery.Deferred.then - filtering (progress)", function( assert ) {
@@ -248,25 +247,25 @@ test( "jQuery.Deferred.then - filtering (progress)", function( assert ) {
defer = jQuery.Deferred(),
piped = defer.then( null, null, function( a, b ) {
return a * b;
- }),
+ } ),
done = assert.async();
- piped.progress(function( result ) {
+ piped.progress( function( result ) {
value3 = result;
- });
+ } );
- defer.progress(function( a, b ) {
+ defer.progress( function( a, b ) {
value1 = a;
value2 = b;
- });
+ } );
defer.notify( 2, 3 ).then( null, null, function() {
assert.strictEqual( value1, 2, "first progress value ok" );
assert.strictEqual( value2, 3, "second progress value ok" );
assert.strictEqual( value3, 6, "result of filter ok" );
done();
- });
-});
+ } );
+} );
test( "jQuery.Deferred.then - deferred (done)", function( assert ) {
@@ -274,31 +273,31 @@ test( "jQuery.Deferred.then - deferred (done)", function( assert ) {
var value1, value2, value3,
defer = jQuery.Deferred(),
- piped = defer.then(function( a, b ) {
- return jQuery.Deferred(function( defer ) {
+ piped = defer.then( function( a, b ) {
+ return jQuery.Deferred( function( defer ) {
defer.reject( a * b );
- });
- }),
+ } );
+ } ),
done = assert.async();
- piped.fail(function( result ) {
+ piped.fail( function( result ) {
value3 = result;
- });
+ } );
- defer.done(function( a, b ) {
+ defer.done( function( a, b ) {
value1 = a;
value2 = b;
- });
+ } );
defer.resolve( 2, 3 );
- piped.fail(function() {
+ piped.fail( function() {
assert.strictEqual( value1, 2, "first resolve value ok" );
assert.strictEqual( value2, 3, "second resolve value ok" );
assert.strictEqual( value3, 6, "result of filter ok" );
done();
- });
-});
+ } );
+} );
test( "jQuery.Deferred.then - deferred (fail)", function( assert ) {
@@ -307,30 +306,30 @@ test( "jQuery.Deferred.then - deferred (fail)", function( assert ) {
var value1, value2, value3,
defer = jQuery.Deferred(),
piped = defer.then( null, function( a, b ) {
- return jQuery.Deferred(function( defer ) {
+ return jQuery.Deferred( function( defer ) {
defer.resolve( a * b );
- });
- }),
+ } );
+ } ),
done = assert.async();
- piped.done(function( result ) {
+ piped.done( function( result ) {
value3 = result;
- });
+ } );
- defer.fail(function( a, b ) {
+ defer.fail( function( a, b ) {
value1 = a;
value2 = b;
- });
+ } );
defer.reject( 2, 3 );
- piped.done(function() {
+ piped.done( function() {
assert.strictEqual( value1, 2, "first reject value ok" );
assert.strictEqual( value2, 3, "second reject value ok" );
assert.strictEqual( value3, 6, "result of filter ok" );
done();
- });
-});
+ } );
+} );
test( "jQuery.Deferred.then - deferred (progress)", function( assert ) {
@@ -339,38 +338,38 @@ test( "jQuery.Deferred.then - deferred (progress)", function( assert ) {
var value1, value2, value3,
defer = jQuery.Deferred(),
piped = defer.then( null, null, function( a, b ) {
- return jQuery.Deferred(function( defer ) {
+ return jQuery.Deferred( function( defer ) {
defer.resolve( a * b );
- });
- }),
+ } );
+ } ),
done = assert.async();
- piped.progress(function( result ) {
- return jQuery.Deferred().resolve().then(function() {
+ piped.progress( function( result ) {
+ return jQuery.Deferred().resolve().then( function() {
return result;
- }).then(function( result ) {
+ } ).then( function( result ) {
value3 = result;
- });
- });
+ } );
+ } );
- defer.progress(function( a, b ) {
+ defer.progress( function( a, b ) {
value1 = a;
value2 = b;
- });
+ } );
defer.notify( 2, 3 );
piped.then( null, null, function( result ) {
- return jQuery.Deferred().resolve().then(function() {
+ return jQuery.Deferred().resolve().then( function() {
return result;
- }).then(function() {
+ } ).then( function() {
assert.strictEqual( value1, 2, "first progress value ok" );
assert.strictEqual( value2, 3, "second progress value ok" );
assert.strictEqual( value3, 6, "result of filter ok" );
done();
- });
- });
-});
+ } );
+ } );
+} );
test( "[PIPE ONLY] jQuery.Deferred.pipe - deferred (progress)", function( assert ) {
@@ -379,30 +378,30 @@ test( "[PIPE ONLY] jQuery.Deferred.pipe - deferred (progress)", function( assert
var value1, value2, value3,
defer = jQuery.Deferred(),
piped = defer.pipe( null, null, function( a, b ) {
- return jQuery.Deferred(function( defer ) {
+ return jQuery.Deferred( function( defer ) {
defer.resolve( a * b );
- });
- }),
+ } );
+ } ),
done = assert.async();
- piped.done(function( result ) {
+ piped.done( function( result ) {
value3 = result;
- });
+ } );
- defer.progress(function( a, b ) {
+ defer.progress( function( a, b ) {
value1 = a;
value2 = b;
- });
+ } );
defer.notify( 2, 3 );
- piped.done(function() {
+ piped.done( function() {
assert.strictEqual( value1, 2, "first progress value ok" );
assert.strictEqual( value2, 3, "second progress value ok" );
assert.strictEqual( value3, 6, "result of filter ok" );
done();
- });
-});
+ } );
+} );
test( "jQuery.Deferred.then - context", function( assert ) {
@@ -412,48 +411,48 @@ test( "jQuery.Deferred.then - context", function( assert ) {
context = {},
done = jQuery.map( new Array( 4 ), function() { return assert.async(); } );
- jQuery.Deferred().resolveWith( context, [ 2 ] ).then(function( value ) {
+ jQuery.Deferred().resolveWith( context, [ 2 ] ).then( function( value ) {
return value * 3;
- }).done(function( value ) {
+ } ).done( function( value ) {
assert.notStrictEqual( this, context, "custom context not propagated through .then" );
assert.strictEqual( value, 6, "proper value received" );
done.pop().call();
- });
+ } );
- jQuery.Deferred().resolve().then(function() {
+ jQuery.Deferred().resolve().then( function() {
return jQuery.Deferred().resolveWith( context );
- }).done(function() {
+ } ).done( function() {
assert.strictEqual( this, context,
"custom context of returned deferred correctly propagated" );
done.pop().call();
- });
+ } );
defer = jQuery.Deferred();
- piped = defer.then(function( value ) {
+ piped = defer.then( function( value ) {
return value * 3;
- });
+ } );
defer.resolve( 2 );
- piped.done(function( value ) {
+ piped.done( function( value ) {
assert.strictEqual( this, piped,
"default context gets updated to latest promise in the chain" );
assert.strictEqual( value, 6, "proper value received" );
done.pop().call();
- });
+ } );
defer2 = jQuery.Deferred();
piped2 = defer2.then();
defer2.resolve( 2 );
- piped2.done(function( value ) {
+ piped2.done( function( value ) {
assert.strictEqual( this, piped2,
"default context updated to latest promise in the chain (without passing function)" );
assert.strictEqual( value, 2, "proper value received (without passing function)" );
done.pop().call();
- });
-});
+ } );
+} );
test( "[PIPE ONLY] jQuery.Deferred.pipe - context", function( assert ) {
@@ -463,66 +462,66 @@ test( "[PIPE ONLY] jQuery.Deferred.pipe - context", function( assert ) {
context = {},
done = jQuery.map( new Array( 4 ), function() { return assert.async(); } );
- jQuery.Deferred().resolveWith( context, [ 2 ] ).pipe(function( value ) {
+ jQuery.Deferred().resolveWith( context, [ 2 ] ).pipe( function( value ) {
return value * 3;
- }).done(function( value ) {
+ } ).done( function( value ) {
assert.strictEqual( this, context, "[PIPE ONLY] custom context correctly propagated" );
assert.strictEqual( value, 6, "proper value received" );
done.pop().call();
- });
+ } );
- jQuery.Deferred().resolve().pipe(function() {
- return jQuery.Deferred().resolveWith(context);
- }).done(function() {
+ jQuery.Deferred().resolve().pipe( function() {
+ return jQuery.Deferred().resolveWith( context );
+ } ).done( function() {
assert.strictEqual( this, context,
"custom context of returned deferred correctly propagated" );
done.pop().call();
- });
+ } );
defer = jQuery.Deferred();
- piped = defer.pipe(function( value ) {
+ piped = defer.pipe( function( value ) {
return value * 3;
- });
+ } );
defer.resolve( 2 );
- piped.done(function( value ) {
+ piped.done( function( value ) {
assert.strictEqual( this, piped,
"default context gets updated to latest promise in the chain" );
assert.strictEqual( value, 6, "proper value received" );
done.pop().call();
- });
+ } );
defer2 = jQuery.Deferred();
piped2 = defer2.pipe();
defer2.resolve( 2 );
- piped2.done(function( value ) {
+ piped2.done( function( value ) {
assert.strictEqual( this, piped2,
"default context updated to latest promise in the chain (without passing function)" );
assert.strictEqual( value, 2, "proper value received (without passing function)" );
done.pop().call();
- });
-});
+ } );
+} );
asyncTest( "jQuery.Deferred.then - spec compatibility", function() {
expect( 1 );
- var defer = jQuery.Deferred().done(function() {
+ var defer = jQuery.Deferred().done( function() {
setTimeout( start );
throw new Error();
- });
+ } );
- defer.then(function() {
+ defer.then( function() {
ok( true, "errors in .done callbacks don't stop .then handlers" );
- });
+ } );
try {
defer.resolve();
} catch ( _ ) {}
-});
+} );
test( "jQuery.Deferred - 1.x/2.x compatibility", function( assert ) {
@@ -534,46 +533,46 @@ test( "jQuery.Deferred - 1.x/2.x compatibility", function( assert ) {
thenable.unwrapped = false;
- jQuery.Deferred().resolve( 1, 2 ).then(function() {
+ jQuery.Deferred().resolve( 1, 2 ).then( function() {
assert.deepEqual( [].slice.call( arguments ), [ 1, 2 ],
".then fulfillment callbacks receive all resolution values" );
done.pop().call();
- });
+ } );
jQuery.Deferred().reject( 1, 2 ).then( null, function() {
assert.deepEqual( [].slice.call( arguments ), [ 1, 2 ],
".then rejection callbacks receive all rejection values" );
done.pop().call();
- });
+ } );
jQuery.Deferred().notify( 1, 2 ).then( null, null, function() {
assert.deepEqual( [].slice.call( arguments ), [ 1, 2 ],
".then progress callbacks receive all progress values" );
done.pop().call();
- });
+ } );
- jQuery.Deferred().resolveWith( context ).then(function() {
+ jQuery.Deferred().resolveWith( context ).then( function() {
assert.deepEqual( this, context, ".then fulfillment callbacks receive context" );
done.pop().call();
- });
+ } );
jQuery.Deferred().rejectWith( context ).then( null, function() {
assert.deepEqual( this, context, ".then rejection callbacks receive context" );
done.pop().call();
- });
+ } );
jQuery.Deferred().notifyWith( context ).then( null, null, function() {
assert.deepEqual( this, context, ".then progress callbacks receive context" );
done.pop().call();
- });
+ } );
- jQuery.Deferred().resolve( thenable ).done(function( value ) {
+ jQuery.Deferred().resolve( thenable ).done( function( value ) {
assert.strictEqual( value, thenable, ".done doesn't unwrap thenables" );
done.pop().call();
- });
+ } );
jQuery.Deferred().notify( thenable ).then().then( null, null, function( value ) {
assert.strictEqual( value, "thenable fulfillment",
".then implicit progress callbacks unwrap thenables" );
done.pop().call();
- });
-});
+ } );
+} );
test( "jQuery.Deferred.then - progress and thenables", function( assert ) {
@@ -590,16 +589,16 @@ test( "jQuery.Deferred.then - progress and thenables", function( assert ) {
trigger.then( null, null, function() {
var notifier = jQuery.Deferred().notify( "foo" );
- setTimeout(function() {
+ setTimeout( function() {
notifier.notify( "bar" ).resolve( "baz" );
- });
+ } );
return notifier;
- }).then( failer( "fulfill" ), failer( "reject" ), function( v ) {
+ } ).then( failer( "fulfill" ), failer( "reject" ), function( v ) {
assert.strictEqual( v, expectedProgress.shift(), "expected progress value" );
done.pop().call();
- });
+ } );
trigger.notify();
-});
+} );
test( "jQuery.Deferred - notify and resolve", function( assert ) {
@@ -643,18 +642,19 @@ test( "jQuery.Deferred - notify and resolve", function( assert ) {
notifiedResolved.then( null, null, function() {
return jQuery.Deferred().notify( "baz" ).resolve( "quux" );
} ).progress( function( v ) {
+
// Progress from the surrogate deferred is ignored
assert.strictEqual( v, "quux", "deferred replaced then'd progress value" );
done.pop().call();
} );
-});
+} );
test( "jQuery.when", function() {
expect( 37 );
// Some other objects
- jQuery.each({
+ jQuery.each( {
"an empty string": "",
"a non-empty string": "some string",
"zero": 0,
@@ -669,21 +669,21 @@ test( "jQuery.when", function() {
}, function( message, value ) {
ok(
jQuery.isFunction(
- jQuery.when( value ).done(function( resolveValue ) {
+ jQuery.when( value ).done( function( resolveValue ) {
strictEqual( this, window, "Context is the global object with " + message );
strictEqual( resolveValue, value, "Test the promise was resolved with " + message );
- }).promise
+ } ).promise
),
"Test " + message + " triggers the creation of a new Promise"
);
- });
+ } );
ok(
jQuery.isFunction(
- jQuery.when().done(function( resolveValue ) {
+ jQuery.when().done( function( resolveValue ) {
strictEqual( this, window, "Test the promise was resolved with window as its context" );
strictEqual( resolveValue, undefined, "Test the promise was resolved with no parameter" );
- }).promise
+ } ).promise
),
"Test calling when with no parameter triggers the creation of a new Promise"
);
@@ -691,23 +691,23 @@ test( "jQuery.when", function() {
var cache,
context = {};
- jQuery.when( jQuery.Deferred().resolveWith( context ) ).done(function() {
+ jQuery.when( jQuery.Deferred().resolveWith( context ) ).done( function() {
strictEqual( this, context, "when( promise ) propagates context" );
- });
+ } );
- jQuery.each([ 1, 2, 3 ], function( k, i ) {
+ jQuery.each( [ 1, 2, 3 ], function( k, i ) {
- jQuery.when( cache || jQuery.Deferred(function() {
+ jQuery.when( cache || jQuery.Deferred( function() {
this.resolve( i );
- })
- ).done(function( value ) {
+ } )
+ ).done( function( value ) {
strictEqual( value, 1, "Function executed" + ( i > 1 ? " only once" : "" ) );
cache = value;
- });
+ } );
- });
-});
+ } );
+} );
test( "jQuery.when - joined", function() {
@@ -762,7 +762,7 @@ test( "jQuery.when - joined", function() {
context2 = defer2 && jQuery.isFunction( defer2.promise ) ? defer2.promise() :
( defer2.then ? window : undefined );
- jQuery.when( defer1, defer2 ).done(function( a, b ) {
+ jQuery.when( defer1, defer2 ).done( function( a, b ) {
if ( shouldResolve ) {
deepEqual( [ a, b ], expected, code + " => resolve" );
strictEqual( this[ 0 ], context1, code + " => first context OK" );
@@ -770,22 +770,22 @@ test( "jQuery.when - joined", function() {
} else {
ok( false, code + " => resolve" );
}
- }).fail(function( a, b ) {
+ } ).fail( function( a, b ) {
if ( shouldError ) {
deepEqual( [ a, b ], expected, code + " => reject" );
} else {
ok( false, code + " => reject" );
}
- }).progress(function( a, b ) {
+ } ).progress( function( a, b ) {
deepEqual( [ a, b ], expectedNotify, code + " => progress" );
strictEqual( this[ 0 ], expectedNotify[ 0 ] ? context1 : undefined, code + " => first context OK" );
strictEqual( this[ 1 ], expectedNotify[ 1 ] ? context2 : undefined, code + " => second context OK" );
- }).always( restart );
- });
- });
+ } ).always( restart );
+ } );
+ } );
deferreds.eventuallyFulfilled.resolve( 1 );
deferreds.eventuallyRejected.reject( 0 );
-});
+} );
test( "jQuery.when - resolved", function() {
@@ -795,18 +795,18 @@ test( "jQuery.when - resolved", function() {
b = jQuery.Deferred().notify( 2 ).resolve( 5 ),
c = jQuery.Deferred().notify( 3 ).resolve( 6 );
- jQuery.when( a, b, c ).progress(function( a, b, c ) {
+ jQuery.when( a, b, c ).progress( function( a, b, c ) {
strictEqual( a, 1, "first notify value ok" );
strictEqual( b, 2, "second notify value ok" );
strictEqual( c, 3, "third notify value ok" );
- }).done(function( a, b, c ) {
+ } ).done( function( a, b, c ) {
strictEqual( a, 4, "first resolve value ok" );
strictEqual( b, 5, "second resolve value ok" );
strictEqual( c, 6, "third resolve value ok" );
- }).fail(function() {
+ } ).fail( function() {
ok( false, "Error on resolve" );
- });
-});
+ } );
+} );
test( "jQuery.when - filtering", function() {
@@ -821,12 +821,12 @@ test( "jQuery.when - filtering", function() {
jQuery.when(
jQuery.Deferred().resolve( 3 ).then( increment ),
jQuery.Deferred().reject( 5 ).then( null, increment )
- ).done(function( four, six ) {
+ ).done( function( four, six ) {
strictEqual( four, 4, "resolved value incremented" );
strictEqual( six, 6, "rejected value incremented" );
start();
- });
-});
+ } );
+} );
test( "jQuery.when - exceptions", function() {
@@ -838,14 +838,14 @@ test( "jQuery.when - exceptions", function() {
stop();
- jQuery.Deferred().resolve().then( woops ).fail(function( doneException ) {
+ jQuery.Deferred().resolve().then( woops ).fail( function( doneException ) {
strictEqual( doneException, "exception thrown", "throwing in done handler" );
- jQuery.Deferred().reject().then( null, woops ).fail(function( failException ) {
+ jQuery.Deferred().reject().then( null, woops ).fail( function( failException ) {
strictEqual( failException, "exception thrown", "throwing in fail handler" );
start();
- });
- });
-});
+ } );
+ } );
+} );
test( "jQuery.when - chaining", function() {
@@ -868,13 +868,13 @@ test( "jQuery.when - chaining", function() {
jQuery.Deferred().reject( 5 ).then( null, chain ),
jQuery.Deferred().resolve( 3 ).then( chainStandard ),
jQuery.Deferred().reject( 5 ).then( null, chainStandard )
- ).done(function( v1, v2, s1, s2 ) {
+ ).done( function( v1, v2, s1, s2 ) {
strictEqual( v1, "other deferred", "chaining in done handler" );
strictEqual( v2, "other deferred", "chaining in fail handler" );
strictEqual( s1, "std deferred", "chaining thenable in done handler" );
strictEqual( s2, "std deferred", "chaining thenable in fail handler" );
start();
- });
+ } );
defer.resolve( "other deferred" );
-});
+} );
diff --git a/test/unit/deprecated.js b/test/unit/deprecated.js
index 9dcad77e4..9052c6acf 100644
--- a/test/unit/deprecated.js
+++ b/test/unit/deprecated.js
@@ -1,2 +1,2 @@
-module("deprecated", { teardown: moduleTeardown });
+module( "deprecated", { teardown: moduleTeardown } );
diff --git a/test/unit/dimensions.js b/test/unit/dimensions.js
index 2eb6e73df..eadb06050 100644
--- a/test/unit/dimensions.js
+++ b/test/unit/dimensions.js
@@ -1,10 +1,10 @@
-(function() {
+( function() {
if ( !jQuery.fn.width ) {
return;
}
-module("dimensions", { teardown: moduleTeardown });
+module( "dimensions", { teardown: moduleTeardown } );
function pass( val ) {
return val;
@@ -29,111 +29,111 @@ function fn( val ) {
*/
function testWidth( val ) {
- expect(9);
+ expect( 9 );
var $div, blah;
- $div = jQuery("#nothiddendiv");
- $div.width( val(30) );
- equal($div.width(), 30, "Test set to 30 correctly");
+ $div = jQuery( "#nothiddendiv" );
+ $div.width( val( 30 ) );
+ equal( $div.width(), 30, "Test set to 30 correctly" );
$div.hide();
- equal($div.width(), 30, "Test hidden div");
+ equal( $div.width(), 30, "Test hidden div" );
$div.show();
- $div.width( val(-1) ); // handle negative numbers by setting to 0 #11604
- equal($div.width(), 0, "Test negative width normalized to 0");
- $div.css("padding", "20px");
- equal($div.width(), 0, "Test padding specified with pixels");
- $div.css("border", "2px solid #fff");
- equal($div.width(), 0, "Test border specified with pixels");
+ $div.width( val( -1 ) ); // handle negative numbers by setting to 0 #11604
+ equal( $div.width(), 0, "Test negative width normalized to 0" );
+ $div.css( "padding", "20px" );
+ equal( $div.width(), 0, "Test padding specified with pixels" );
+ $div.css( "border", "2px solid #fff" );
+ equal( $div.width(), 0, "Test border specified with pixels" );
- $div.css({ "display": "", "border": "", "padding": "" });
+ $div.css( { "display": "", "border": "", "padding": "" } );
- jQuery("#nothiddendivchild").css({ "width": 20, "padding": "3px", "border": "2px solid #fff" });
- equal(jQuery("#nothiddendivchild").width(), 20, "Test child width with border and padding");
- jQuery("#nothiddendiv, #nothiddendivchild").css({ "border": "", "padding": "", "width": "" });
+ jQuery( "#nothiddendivchild" ).css( { "width": 20, "padding": "3px", "border": "2px solid #fff" } );
+ equal( jQuery( "#nothiddendivchild" ).width(), 20, "Test child width with border and padding" );
+ jQuery( "#nothiddendiv, #nothiddendivchild" ).css( { "border": "", "padding": "", "width": "" } );
- blah = jQuery("blah");
- equal( blah.width( val(10) ), blah, "Make sure that setting a width on an empty set returns the set." );
- equal( blah.width(), null, "Make sure 'null' is returned on an empty set");
+ blah = jQuery( "blah" );
+ equal( blah.width( val( 10 ) ), blah, "Make sure that setting a width on an empty set returns the set." );
+ equal( blah.width(), null, "Make sure 'null' is returned on an empty set" );
- equal( jQuery(window).width(), document.documentElement.clientWidth, "Window width is equal to width reported by window/document." );
+ equal( jQuery( window ).width(), document.documentElement.clientWidth, "Window width is equal to width reported by window/document." );
- QUnit.expectJqData( this, $div[0], "display" );
+ QUnit.expectJqData( this, $div[ 0 ], "display" );
}
-test("width()", function() {
+test( "width()", function() {
testWidth( pass );
-});
+} );
-test("width(Function)", function() {
+test( "width(Function)", function() {
testWidth( fn );
-});
+} );
-test("width(Function(args))", function() {
+test( "width(Function(args))", function() {
expect( 2 );
- var $div = jQuery("#nothiddendiv");
- $div.width( 30 ).width(function(i, width) {
+ var $div = jQuery( "#nothiddendiv" );
+ $div.width( 30 ).width( function( i, width ) {
equal( width, 30, "Make sure previous value is correct." );
return width + 1;
- });
+ } );
equal( $div.width(), 31, "Make sure value was modified correctly." );
-});
+} );
function testHeight( val ) {
- expect(9);
+ expect( 9 );
var $div, blah;
- $div = jQuery("#nothiddendiv");
- $div.height( val(30) );
- equal($div.height(), 30, "Test set to 30 correctly");
+ $div = jQuery( "#nothiddendiv" );
+ $div.height( val( 30 ) );
+ equal( $div.height(), 30, "Test set to 30 correctly" );
$div.hide();
- equal($div.height(), 30, "Test hidden div");
+ equal( $div.height(), 30, "Test hidden div" );
$div.show();
- $div.height( val(-1) ); // handle negative numbers by setting to 0 #11604
- equal($div.height(), 0, "Test negative height normalized to 0");
- $div.css("padding", "20px");
- equal($div.height(), 0, "Test padding specified with pixels");
- $div.css("border", "2px solid #fff");
- equal($div.height(), 0, "Test border specified with pixels");
+ $div.height( val( -1 ) ); // handle negative numbers by setting to 0 #11604
+ equal( $div.height(), 0, "Test negative height normalized to 0" );
+ $div.css( "padding", "20px" );
+ equal( $div.height(), 0, "Test padding specified with pixels" );
+ $div.css( "border", "2px solid #fff" );
+ equal( $div.height(), 0, "Test border specified with pixels" );
- $div.css({ "display": "", "border": "", "padding": "", "height": "1px" });
+ $div.css( { "display": "", "border": "", "padding": "", "height": "1px" } );
- jQuery("#nothiddendivchild").css({ "height": 20, "padding": "3px", "border": "2px solid #fff" });
- equal(jQuery("#nothiddendivchild").height(), 20, "Test child height with border and padding");
- jQuery("#nothiddendiv, #nothiddendivchild").css({ "border": "", "padding": "", "height": "" });
+ jQuery( "#nothiddendivchild" ).css( { "height": 20, "padding": "3px", "border": "2px solid #fff" } );
+ equal( jQuery( "#nothiddendivchild" ).height(), 20, "Test child height with border and padding" );
+ jQuery( "#nothiddendiv, #nothiddendivchild" ).css( { "border": "", "padding": "", "height": "" } );
- blah = jQuery("blah");
- equal( blah.height( val(10) ), blah, "Make sure that setting a height on an empty set returns the set." );
- equal( blah.height(), null, "Make sure 'null' is returned on an empty set");
+ blah = jQuery( "blah" );
+ equal( blah.height( val( 10 ) ), blah, "Make sure that setting a height on an empty set returns the set." );
+ equal( blah.height(), null, "Make sure 'null' is returned on an empty set" );
- equal( jQuery(window).height(), document.documentElement.clientHeight, "Window width is equal to width reported by window/document." );
+ equal( jQuery( window ).height(), document.documentElement.clientHeight, "Window width is equal to width reported by window/document." );
- QUnit.expectJqData( this, $div[0], "display" );
+ QUnit.expectJqData( this, $div[ 0 ], "display" );
}
-test("height()", function() {
+test( "height()", function() {
testHeight( pass );
-});
+} );
-test("height(Function)", function() {
+test( "height(Function)", function() {
testHeight( fn );
-});
+} );
-test("height(Function(args))", function() {
+test( "height(Function(args))", function() {
expect( 2 );
- var $div = jQuery("#nothiddendiv");
- $div.height( 30 ).height(function(i, height) {
+ var $div = jQuery( "#nothiddendiv" );
+ $div.height( 30 ).height( function( i, height ) {
equal( height, 30, "Make sure previous value is correct." );
return height + 1;
- });
+ } );
equal( $div.height(), 31, "Make sure value was modified correctly." );
-});
+} );
-test("innerWidth()", function() {
+test( "innerWidth()", function() {
expect( 6 );
var $div, div,
@@ -144,11 +144,11 @@ test("innerWidth()", function() {
equal( jQuery( document ).innerWidth(), $doc.width(), "Test on document" );
$div = jQuery( "#nothiddendiv" );
- $div.css({
+ $div.css( {
"margin": 10,
"border": "2px solid #fff",
"width": 30
- });
+ } );
equal( $div.innerWidth(), 30, "Test with margin and border" );
$div.css( "padding", "20px" );
@@ -157,7 +157,7 @@ test("innerWidth()", function() {
equal( $div.innerWidth(), 70, "Test hidden div" );
// reset styles
- $div.css({ "display": "", "border": "", "padding": "", "width": "", "height": "" });
+ $div.css( { "display": "", "border": "", "padding": "", "width": "", "height": "" } );
div = jQuery( " " );
@@ -166,9 +166,9 @@ test("innerWidth()", function() {
div.remove();
QUnit.expectJqData( this, $div[ 0 ], "display" );
-});
+} );
-test("innerHeight()", function() {
+test( "innerHeight()", function() {
expect( 6 );
var $div, div,
@@ -179,11 +179,11 @@ test("innerHeight()", function() {
equal( jQuery( document ).innerHeight(), $doc.height(), "Test on document" );
$div = jQuery( "#nothiddendiv" );
- $div.css({
+ $div.css( {
"margin": 10,
"border": "2px solid #fff",
"height": 30
- });
+ } );
equal( $div.innerHeight(), 30, "Test with margin and border" );
$div.css( "padding", "20px" );
@@ -192,7 +192,7 @@ test("innerHeight()", function() {
equal( $div.innerHeight(), 70, "Test hidden div" );
// reset styles
- $div.css({ "display": "", "border": "", "padding": "", "width": "", "height": "" });
+ $div.css( { "display": "", "border": "", "padding": "", "width": "", "height": "" } );
div = jQuery( " " );
@@ -201,9 +201,9 @@ test("innerHeight()", function() {
div.remove();
QUnit.expectJqData( this, $div[ 0 ], "display" );
-});
+} );
-test("outerWidth()", function() {
+test( "outerWidth()", function() {
expect( 11 );
var $div, div,
@@ -231,7 +231,7 @@ test("outerWidth()", function() {
equal( $div.outerWidth( true ), 94, "Test hidden div with padding, border and margin with margin option" );
// reset styles
- $div.css({ "position": "", "display": "", "border": "", "padding": "", "width": "", "height": "" });
+ $div.css( { "position": "", "display": "", "border": "", "padding": "", "width": "", "height": "" } );
div = jQuery( " " );
@@ -240,23 +240,23 @@ test("outerWidth()", function() {
div.remove();
QUnit.expectJqData( this, $div[ 0 ], "display" );
-});
+} );
-test("child of a hidden elem (or unconnected node) has accurate inner/outer/Width()/Height() see #9441 #9300", function() {
- expect(16);
+test( "child of a hidden elem (or unconnected node) has accurate inner/outer/Width()/Height() see #9441 #9300", function() {
+ expect( 16 );
// setup html
- var $divNormal = jQuery(" ").css({ "width": "100px", "height": "100px", "border": "10px solid white", "padding": "2px", "margin": "3px" }),
+ var $divNormal = jQuery( " " ).css( { "width": "100px", "height": "100px", "border": "10px solid white", "padding": "2px", "margin": "3px" } ),
$divChild = $divNormal.clone(),
$divUnconnected = $divNormal.clone(),
- $divHiddenParent = jQuery(" ").css( "display", "none" ).append( $divChild ).appendTo("body");
- $divNormal.appendTo("body");
+ $divHiddenParent = jQuery( " " ).css( "display", "none" ).append( $divChild ).appendTo( "body" );
+ $divNormal.appendTo( "body" );
// tests that child div of a hidden div works the same as a normal div
equal( $divChild.width(), $divNormal.width(), "child of a hidden element width() is wrong see #9441" );
equal( $divChild.innerWidth(), $divNormal.innerWidth(), "child of a hidden element innerWidth() is wrong see #9441" );
equal( $divChild.outerWidth(), $divNormal.outerWidth(), "child of a hidden element outerWidth() is wrong see #9441" );
- equal( $divChild.outerWidth(true), $divNormal.outerWidth( true ), "child of a hidden element outerWidth( true ) is wrong see #9300" );
+ equal( $divChild.outerWidth( true ), $divNormal.outerWidth( true ), "child of a hidden element outerWidth( true ) is wrong see #9300" );
// Support: IE 10-11, Edge
// Child height is not always decimal
@@ -269,7 +269,7 @@ test("child of a hidden elem (or unconnected node) has accurate inner/outer/Widt
equal( $divUnconnected.width(), $divNormal.width(), "unconnected element width() is wrong see #9441" );
equal( $divUnconnected.innerWidth(), $divNormal.innerWidth(), "unconnected element innerWidth() is wrong see #9441" );
equal( $divUnconnected.outerWidth(), $divNormal.outerWidth(), "unconnected element outerWidth() is wrong see #9441" );
- equal( $divUnconnected.outerWidth(true), $divNormal.outerWidth( true ), "unconnected element outerWidth( true ) is wrong see #9300" );
+ equal( $divUnconnected.outerWidth( true ), $divNormal.outerWidth( true ), "unconnected element outerWidth( true ) is wrong see #9300" );
// Support: IE 10-11, Edge
// Child height is not always decimal
@@ -281,9 +281,9 @@ test("child of a hidden elem (or unconnected node) has accurate inner/outer/Widt
// teardown html
$divHiddenParent.remove();
$divNormal.remove();
-});
+} );
-test("getting dimensions shouldn't modify runtimeStyle see #9233", function() {
+test( "getting dimensions shouldn't modify runtimeStyle see #9233", function() {
expect( 1 );
var $div = jQuery( " " ).appendTo( "#qunit-fixture" ),
@@ -304,36 +304,36 @@ test("getting dimensions shouldn't modify runtimeStyle see #9233", function() {
}
$div.remove();
-});
+} );
test( "table dimensions", function() {
expect( 2 );
- var table = jQuery(" ").appendTo("#qunit-fixture"),
- tdElem = table.find("td").first(),
- colElem = table.find("col").first().width( 300 );
+ var table = jQuery( " " ).appendTo( "#qunit-fixture" ),
+ tdElem = table.find( "td" ).first(),
+ colElem = table.find( "col" ).first().width( 300 );
- table.find("td").css({ "margin": 0, "padding": 0 });
+ table.find( "td" ).css( { "margin": 0, "padding": 0 } );
equal( tdElem.width(), tdElem.width(), "width() doesn't alter dimension values of empty cells, see #11293" );
equal( colElem.width(), 300, "col elements have width(), see #12243" );
-});
+} );
-test("box-sizing:border-box child of a hidden elem (or unconnected node) has accurate inner/outer/Width()/Height() see #10413", function() {
- expect(16);
+test( "box-sizing:border-box child of a hidden elem (or unconnected node) has accurate inner/outer/Width()/Height() see #10413", function() {
+ expect( 16 );
// setup html
- var $divNormal = jQuery(" ").css({ "boxSizing": "border-box", "width": "100px", "height": "100px", "border": "10px solid white", "padding": "2px", "margin": "3px" }),
+ var $divNormal = jQuery( " " ).css( { "boxSizing": "border-box", "width": "100px", "height": "100px", "border": "10px solid white", "padding": "2px", "margin": "3px" } ),
$divChild = $divNormal.clone(),
$divUnconnected = $divNormal.clone(),
- $divHiddenParent = jQuery(" ").css( "display", "none" ).append( $divChild ).appendTo("body");
- $divNormal.appendTo("body");
+ $divHiddenParent = jQuery( " " ).css( "display", "none" ).append( $divChild ).appendTo( "body" );
+ $divNormal.appendTo( "body" );
// tests that child div of a hidden div works the same as a normal div
equal( $divChild.width(), $divNormal.width(), "child of a hidden element width() is wrong see #10413" );
equal( $divChild.innerWidth(), $divNormal.innerWidth(), "child of a hidden element innerWidth() is wrong see #10413" );
equal( $divChild.outerWidth(), $divNormal.outerWidth(), "child of a hidden element outerWidth() is wrong see #10413" );
- equal( $divChild.outerWidth(true), $divNormal.outerWidth( true ), "child of a hidden element outerWidth( true ) is wrong see #10413" );
+ equal( $divChild.outerWidth( true ), $divNormal.outerWidth( true ), "child of a hidden element outerWidth( true ) is wrong see #10413" );
// Support: IE 10-11, Edge
// Child height is not always decimal
@@ -346,7 +346,7 @@ test("box-sizing:border-box child of a hidden elem (or unconnected node) has acc
equal( $divUnconnected.width(), $divNormal.width(), "unconnected element width() is wrong see #10413" );
equal( $divUnconnected.innerWidth(), $divNormal.innerWidth(), "unconnected element innerWidth() is wrong see #10413" );
equal( $divUnconnected.outerWidth(), $divNormal.outerWidth(), "unconnected element outerWidth() is wrong see #10413" );
- equal( $divUnconnected.outerWidth(true), $divNormal.outerWidth( true ), "unconnected element outerWidth( true ) is wrong see #10413" );
+ equal( $divUnconnected.outerWidth( true ), $divNormal.outerWidth( true ), "unconnected element outerWidth( true ) is wrong see #10413" );
// Support: IE 10-11, Edge
// Child height is not always decimal
@@ -358,9 +358,9 @@ test("box-sizing:border-box child of a hidden elem (or unconnected node) has acc
// teardown html
$divHiddenParent.remove();
$divNormal.remove();
-});
+} );
-test("outerHeight()", function() {
+test( "outerHeight()", function() {
expect( 11 );
var $div, div,
@@ -387,7 +387,7 @@ test("outerHeight()", function() {
equal( $div.outerHeight( true ), 94, "Test hidden div with padding, border and margin with margin option" );
// reset styles
- $div.css({ "display": "", "border": "", "padding": "", "width": "", "height": "" });
+ $div.css( { "display": "", "border": "", "padding": "", "width": "", "height": "" } );
div = jQuery( " " );
@@ -396,20 +396,20 @@ test("outerHeight()", function() {
div.remove();
QUnit.expectJqData( this, $div[ 0 ], "display" );
-});
+} );
-test("passing undefined is a setter #5571", function() {
- expect(4);
- equal(jQuery("#nothiddendiv").height(30).height(undefined).height(), 30, ".height(undefined) is chainable (#5571)");
- equal(jQuery("#nothiddendiv").height(30).innerHeight(undefined).height(), 30, ".innerHeight(undefined) is chainable (#5571)");
- equal(jQuery("#nothiddendiv").height(30).outerHeight(undefined).height(), 30, ".outerHeight(undefined) is chainable (#5571)");
- equal(jQuery("#nothiddendiv").width(30).width(undefined).width(), 30, ".width(undefined) is chainable (#5571)");
-});
+test( "passing undefined is a setter #5571", function() {
+ expect( 4 );
+ equal( jQuery( "#nothiddendiv" ).height( 30 ).height( undefined ).height(), 30, ".height(undefined) is chainable (#5571)" );
+ equal( jQuery( "#nothiddendiv" ).height( 30 ).innerHeight( undefined ).height(), 30, ".innerHeight(undefined) is chainable (#5571)" );
+ equal( jQuery( "#nothiddendiv" ).height( 30 ).outerHeight( undefined ).height(), 30, ".outerHeight(undefined) is chainable (#5571)" );
+ equal( jQuery( "#nothiddendiv" ).width( 30 ).width( undefined ).width(), 30, ".width(undefined) is chainable (#5571)" );
+} );
test( "getters on non elements should return null", function() {
expect( 8 );
- var nonElem = jQuery("notAnElement");
+ var nonElem = jQuery( "notAnElement" );
strictEqual( nonElem.width(), null, ".width() is not null (#12283)" );
strictEqual( nonElem.innerWidth(), null, ".innerWidth() is not null (#12283)" );
@@ -420,14 +420,14 @@ test( "getters on non elements should return null", function() {
strictEqual( nonElem.innerHeight(), null, ".innerHeight() is not null (#12283)" );
strictEqual( nonElem.outerHeight(), null, ".outerHeight() is not null (#12283)" );
strictEqual( nonElem.outerHeight( true ), null, ".outerHeight(true) is not null (#12283)" );
-});
+} );
-test("setters with and without box-sizing:border-box", function(){
- expect(20);
+test( "setters with and without box-sizing:border-box", function() {
+ expect( 20 );
// Support: Android 2.3 (-webkit-box-sizing).
- var el_bb = jQuery(" test ").appendTo("#qunit-fixture"),
- el = jQuery(" test ").appendTo("#qunit-fixture"),
+ var el_bb = jQuery( " test " ).appendTo( "#qunit-fixture" ),
+ el = jQuery( " test " ).appendTo( "#qunit-fixture" ),
expected = 100;
equal( el_bb.width( 101 ).width(), expected + 1, "test border-box width(int) by roundtripping" );
@@ -453,9 +453,10 @@ test("setters with and without box-sizing:border-box", function(){
equal( el.outerHeight( 117 ).height(), expected + 3, "test border-box outerHeight(int) by roundtripping" );
equal( el.outerHeight( 118, false ).height(), expected + 4, "test border-box outerHeight(int, false) by roundtripping" );
equal( el.outerHeight( 129, true ).height(), expected + 5, "test border-box innerHeight(int, true) by roundtripping" );
-});
+} );
testIframe( "dimensions/documentSmall", "window vs. small document", function( jQuery, window, document ) {
+
// this test is practically tautological, but there is a bug in IE8
// with no simple workaround, so this test exposes the bug and works around it
if ( document.body.offsetWidth >= document.documentElement.offsetWidth ) {
@@ -464,18 +465,19 @@ testIframe( "dimensions/documentSmall", "window vs. small document", function( j
equal( jQuery( document ).height(), jQuery( window ).height(), "document height matches window height" );
equal( jQuery( document ).width(), jQuery( window ).width(), "document width matches window width" );
} else {
+
// all tests should have at least one assertion
expect( 1 );
ok( true, "skipping test (conditions not satisfied)" );
}
-});
+} );
testIframe( "dimensions/documentLarge", "window vs. large document", function( jQuery, window, document ) {
- expect(2);
+ expect( 2 );
ok( jQuery( document ).height() > jQuery( window ).height(), "document height is larger than window height" );
ok( jQuery( document ).width() > jQuery( window ).width(), "document width is larger than window width" );
-});
+} );
test( "allow modification of coordinates argument (gh-1848)", function() {
expect( 1 );
@@ -483,15 +485,15 @@ test( "allow modification of coordinates argument (gh-1848)", function() {
var offsetTop,
element = jQuery( " " ).appendTo( "#qunit-fixture" );
- element.offset(function( index, coords ) {
+ element.offset( function( index, coords ) {
coords.top = 100;
return coords;
- });
+ } );
offsetTop = element.offset().top;
- ok( Math.abs(offsetTop - 100) < 0.02,
- "coordinates are modified (got offset.top: " + offsetTop + ")");
-});
+ ok( Math.abs( offsetTop - 100 ) < 0.02,
+ "coordinates are modified (got offset.top: " + offsetTop + ")" );
+} );
-})();
+} )();
diff --git a/test/unit/effects.js b/test/unit/effects.js
index cd367c11a..f4bd9c145 100644
--- a/test/unit/effects.js
+++ b/test/unit/effects.js
@@ -1,4 +1,4 @@
-(function() {
+( function() {
// Can't test what ain't there
if ( !jQuery.fx ) {
@@ -7,7 +7,7 @@ if ( !jQuery.fx ) {
var oldRaf = window.requestAnimationFrame;
-module("effects", {
+module( "effects", {
setup: function() {
window.requestAnimationFrame = null;
this.sandbox = sinon.sandbox.create();
@@ -23,48 +23,48 @@ module("effects", {
window.requestAnimationFrame = oldRaf;
return moduleTeardown.apply( this, arguments );
}
-});
+} );
-test("sanity check", function() {
- expect(1);
- equal( jQuery("#dl:visible, #qunit-fixture:visible, #foo:visible").length, 3, "QUnit state is correct for testing effects" );
-});
+test( "sanity check", function() {
+ expect( 1 );
+ equal( jQuery( "#dl:visible, #qunit-fixture:visible, #foo:visible" ).length, 3, "QUnit state is correct for testing effects" );
+} );
-test("show() basic", function() {
+test( "show() basic", function() {
expect( 1 );
- var div = jQuery(" ").hide().appendTo("#qunit-fixture").show();
+ var div = jQuery( " " ).hide().appendTo( "#qunit-fixture" ).show();
- equal( div.css("display"), "block", "Make sure pre-hidden divs show" );
+ equal( div.css( "display" ), "block", "Make sure pre-hidden divs show" );
// Clean up the detached node
div.remove();
-});
+} );
-test("show()", function () {
+test( "show()", function() {
expect( 27 );
var div, speeds, test,
displaysActual, displaysExpected,
- hiddendiv = jQuery("div.hidden");
+ hiddendiv = jQuery( "div.hidden" );
- equal(jQuery.css( hiddendiv[0], "display"), "none", "hiddendiv is display: none");
+ equal( jQuery.css( hiddendiv[ 0 ], "display" ), "none", "hiddendiv is display: none" );
- hiddendiv.css("display", "block");
- equal(jQuery.css( hiddendiv[0], "display"), "block", "hiddendiv is display: block");
+ hiddendiv.css( "display", "block" );
+ equal( jQuery.css( hiddendiv[ 0 ], "display" ), "block", "hiddendiv is display: block" );
hiddendiv.show();
- equal(jQuery.css( hiddendiv[0], "display"), "block", "hiddendiv is display: block");
+ equal( jQuery.css( hiddendiv[ 0 ], "display" ), "block", "hiddendiv is display: block" );
- hiddendiv.css("display","");
+ hiddendiv.css( "display", "" );
displaysActual = [];
displaysExpected = [];
- div = jQuery("#fx-queue div").slice(0, 4);
- div.show().each(function() {
- notEqual(this.style.display, "none", "don't change any with display block");
- });
+ div = jQuery( "#fx-queue div" ).slice( 0, 4 );
+ div.show().each( function() {
+ notEqual( this.style.display, "none", "don't change any with display block" );
+ } );
speeds = {
"null speed": null,
@@ -72,23 +72,23 @@ test("show()", function () {
"false speed": false
};
- jQuery.each(speeds, function(name, speed) {
+ jQuery.each( speeds, function( name, speed ) {
var pass = true;
- div.hide().show(speed).each(function() {
+ div.hide().show( speed ).each( function() {
if ( this.style.display === "none" ) {
pass = false;
}
- });
- ok( pass, "Show with " + name);
- });
+ } );
+ ok( pass, "Show with " + name );
+ } );
- jQuery.each(speeds, function(name, speed) {
+ jQuery.each( speeds, function( name, speed ) {
var pass = true;
- div.hide().show(speed, function() {
+ div.hide().show( speed, function() {
pass = false;
- });
+ } );
ok( pass, "Show with " + name + " does not call animate callback" );
- });
+ } );
// Tolerate data from show()/hide()
QUnit.expectJqData( this, div, "display" );
@@ -101,39 +101,39 @@ test("show()", function () {
" "
).appendTo( "#qunit-fixture" ).find( "*" ).css( "display", "none" );
- jQuery("#test-table").remove();
+ jQuery( "#test-table" ).remove();
test = {
- "div" : "block",
- "p" : "block",
- "a" : "inline",
- "code" : "inline",
- "pre" : "block",
- "span" : "inline",
- "table" : "table",
- "thead" : "table-header-group",
- "tbody" : "table-row-group",
- "tr" : "table-row",
- "th" : "table-cell",
- "td" : "table-cell",
- "ul" : "block",
- "li" : "list-item"
+ "div": "block",
+ "p": "block",
+ "a": "inline",
+ "code": "inline",
+ "pre": "block",
+ "span": "inline",
+ "table": "table",
+ "thead": "table-header-group",
+ "tbody": "table-row-group",
+ "tr": "table-row",
+ "th": "table-cell",
+ "td": "table-cell",
+ "ul": "block",
+ "li": "list-item"
};
- jQuery.each(test, function(selector, expected) {
- var elem = jQuery(selector, "#show-tests").show();
- equal( elem.css("display"), expected, "Show using correct display type for " + selector );
- });
+ jQuery.each( test, function( selector, expected ) {
+ var elem = jQuery( selector, "#show-tests" ).show();
+ equal( elem.css( "display" ), expected, "Show using correct display type for " + selector );
+ } );
- jQuery("#show-tests").remove();
+ jQuery( "#show-tests" ).remove();
// Make sure that showing or hiding a text node doesn't cause an error
- jQuery(" test text test").show().remove();
- jQuery(" test text test").hide().remove();
-});
+ jQuery( " test text test" ).show().remove();
+ jQuery( " test text test" ).hide().remove();
+} );
-test("show(Number) - other displays", function() {
- expect(30);
+test( "show(Number) - other displays", function() {
+ expect( 30 );
jQuery(
" " +
@@ -145,103 +145,103 @@ test("show(Number) - other displays", function() {
var test;
- jQuery("#test-table").remove();
+ jQuery( "#test-table" ).remove();
// Note: inline elements are expected to be inline-block
// because we're showing width/height
// Can't animate width/height inline
// See #14344
test = {
- "div" : "block",
- "p" : "block",
- "a" : "inline",
- "code" : "inline",
- "pre" : "block",
- "span" : "inline",
- "table" : "table",
- "thead" : "table-header-group",
- "tbody" : "table-row-group",
- "tr" : "table-row",
- "th" : "table-cell",
- "td" : "table-cell",
- "ul" : "block",
- "li" : "list-item"
+ "div": "block",
+ "p": "block",
+ "a": "inline",
+ "code": "inline",
+ "pre": "block",
+ "span": "inline",
+ "table": "table",
+ "thead": "table-header-group",
+ "tbody": "table-row-group",
+ "tr": "table-row",
+ "th": "table-cell",
+ "td": "table-cell",
+ "ul": "block",
+ "li": "list-item"
};
jQuery.each( test, function( selector ) {
jQuery( selector, "#show-tests" ).show( 100 );
- });
+ } );
this.clock.tick( 50 );
jQuery.each( test, function( selector, expected ) {
- jQuery( selector, "#show-tests" ).each(function() {
+ jQuery( selector, "#show-tests" ).each( function() {
equal(
jQuery( this ).css( "display" ),
expected === "inline" ? "inline-block" : expected,
"Correct display type during animation for " + selector
);
- });
- });
+ } );
+ } );
this.clock.tick( 50 );
jQuery.each( test, function( selector, expected ) {
- jQuery( selector, "#show-tests" ).each(function() {
+ jQuery( selector, "#show-tests" ).each( function() {
equal( jQuery( this ).css( "display" ), expected,
"Correct display type after animation for " + selector );
- });
- });
+ } );
+ } );
- jQuery("#show-tests").remove();
-});
+ jQuery( "#show-tests" ).remove();
+} );
// Supports #7397
-test("Persist correct display value", function() {
- expect(3);
+test( "Persist correct display value", function() {
+ expect( 3 );
jQuery( " foo " )
.appendTo( "#qunit-fixture" ).find( "*" ).css( "display", "none" );
- var $span = jQuery("#show-tests span"),
- displayNone = $span.css("display"),
+ var $span = jQuery( "#show-tests span" ),
+ displayNone = $span.css( "display" ),
display = "",
clock = this.clock;
$span.show();
- display = $span.css("display");
+ display = $span.css( "display" );
$span.hide();
- $span.fadeIn(100, function() {
- equal($span.css("display"), display, "Expecting display: " + display);
- $span.fadeOut(100, function () {
- equal($span.css("display"), displayNone, "Expecting display: " + displayNone);
- $span.fadeIn(100, function() {
- equal($span.css("display"), display, "Expecting display: " + display);
- });
- });
- });
+ $span.fadeIn( 100, function() {
+ equal( $span.css( "display" ), display, "Expecting display: " + display );
+ $span.fadeOut( 100, function() {
+ equal( $span.css( "display" ), displayNone, "Expecting display: " + displayNone );
+ $span.fadeIn( 100, function() {
+ equal( $span.css( "display" ), display, "Expecting display: " + display );
+ } );
+ } );
+ } );
clock.tick( 300 );
QUnit.expectJqData( this, $span, "display" );
-});
+} );
-test("animate(Hash, Object, Function)", function() {
- expect(1);
- var hash = {opacity: "show"},
- hashCopy = jQuery.extend({}, hash);
- jQuery("#foo").animate(hash, 0, function() {
+test( "animate(Hash, Object, Function)", function() {
+ expect( 1 );
+ var hash = { opacity: "show" },
+ hashCopy = jQuery.extend( {}, hash );
+ jQuery( "#foo" ).animate( hash, 0, function() {
equal( hash.opacity, hashCopy.opacity, "Check if animate changed the hash parameter" );
- });
-});
+ } );
+} );
-test("animate relative values", function() {
+test( "animate relative values", function() {
var value = 40,
clock = this.clock,
bases = [ "%", "px", "em" ],
adjustments = [ "px", "em" ],
- container = jQuery(" ")
- .css({ position: "absolute", height: "50em", width: "50em" }),
+ container = jQuery( " " )
+ .css( { position: "absolute", height: "50em", width: "50em" } ),
animations = bases.length * adjustments.length;
expect( 2 * animations );
@@ -250,13 +250,13 @@ test("animate relative values", function() {
jQuery.each( adjustments, function( _, adjustUnit ) {
var base = value + baseUnit,
adjust = { height: "+=2" + adjustUnit, width: "-=2" + adjustUnit },
- elem = jQuery(" ")
- .appendTo( container.clone().appendTo("#qunit-fixture") )
- .css({
+ elem = jQuery( " " )
+ .appendTo( container.clone().appendTo( "#qunit-fixture" ) )
+ .css( {
position: "absolute",
height: base,
width: value + adjustUnit
- }),
+ } ),
baseScale = elem[ 0 ].offsetHeight / value,
adjustScale = elem[ 0 ].offsetWidth / value;
@@ -266,89 +266,89 @@ test("animate relative values", function() {
equal( this.offsetWidth, value * baseScale - 2 * adjustScale,
baseUnit + "-=" + adjustUnit );
- });
+ } );
clock.tick( 100 );
- });
- });
-});
+ } );
+ } );
+} );
-test("animate negative height", function() {
- expect(1);
- jQuery("#foo").animate({ height: -100 }, 100, function() {
+test( "animate negative height", function() {
+ expect( 1 );
+ jQuery( "#foo" ).animate( { height: -100 }, 100, function() {
equal( this.offsetHeight, 0, "Verify height." );
- });
+ } );
this.clock.tick( 100 );
-});
+} );
-test("animate negative margin", function() {
- expect(1);
- jQuery("#foo").animate({ "marginTop": -100 }, 100, function() {
- equal( jQuery(this).css("marginTop"), "-100px", "Verify margin." );
- });
+test( "animate negative margin", function() {
+ expect( 1 );
+ jQuery( "#foo" ).animate( { "marginTop": -100 }, 100, function() {
+ equal( jQuery( this ).css( "marginTop" ), "-100px", "Verify margin." );
+ } );
this.clock.tick( 100 );
-});
+} );
-test("animate negative margin with px", function() {
- expect(1);
- jQuery("#foo").animate({ marginTop: "-100px" }, 100, function() {
- equal( jQuery(this).css("marginTop"), "-100px", "Verify margin." );
- });
+test( "animate negative margin with px", function() {
+ expect( 1 );
+ jQuery( "#foo" ).animate( { marginTop: "-100px" }, 100, function() {
+ equal( jQuery( this ).css( "marginTop" ), "-100px", "Verify margin." );
+ } );
this.clock.tick( 100 );
-});
+} );
-test("animate negative padding", function() {
- expect(1);
- jQuery("#foo").animate({ "paddingBottom": -100 }, 100, function() {
- equal( jQuery(this).css("paddingBottom"), "0px", "Verify paddingBottom." );
- });
+test( "animate negative padding", function() {
+ expect( 1 );
+ jQuery( "#foo" ).animate( { "paddingBottom": -100 }, 100, function() {
+ equal( jQuery( this ).css( "paddingBottom" ), "0px", "Verify paddingBottom." );
+ } );
this.clock.tick( 100 );
-});
+} );
-test("animate block as inline width/height", function() {
- expect(3);
+test( "animate block as inline width/height", function() {
+ expect( 3 );
- var span = jQuery(" ").css("display", "inline-block").appendTo("body");
+ var span = jQuery( "" ).css( "display", "inline-block" ).appendTo( "body" );
span.remove();
- jQuery("#foo").css({ display: "inline", width: "", height: "" }).animate({ width: 42, height: 42 }, 100, function() {
- equal( jQuery(this).css("display"), "inline-block", "inline-block was set on non-floated inline element when animating width/height" );
+ jQuery( "#foo" ).css( { display: "inline", width: "", height: "" } ).animate( { width: 42, height: 42 }, 100, function() {
+ equal( jQuery( this ).css( "display" ), "inline-block", "inline-block was set on non-floated inline element when animating width/height" );
equal( this.offsetWidth, 42, "width was animated" );
equal( this.offsetHeight, 42, "height was animated" );
- });
+ } );
this.clock.tick( 100 );
-});
+} );
-test("animate native inline width/height", function() {
- expect(3);
+test( "animate native inline width/height", function() {
+ expect( 3 );
- var span = jQuery("").css("display", "inline-block").appendTo("body");
+ var span = jQuery( "" ).css( "display", "inline-block" ).appendTo( "body" );
span.remove();
- jQuery("#foo").css({ display: "", width: "", height: "" })
- .append("text")
- .children("span")
- .animate({ width: 42, height: 42 }, 100, function() {
- equal( jQuery(this).css("display"), "inline-block", "inline-block was set on non-floated inline element when animating width/height" );
+ jQuery( "#foo" ).css( { display: "", width: "", height: "" } )
+ .append( "text" )
+ .children( "span" )
+ .animate( { width: 42, height: 42 }, 100, function() {
+ equal( jQuery( this ).css( "display" ), "inline-block", "inline-block was set on non-floated inline element when animating width/height" );
equal( this.offsetWidth, 42, "width was animated" );
equal( this.offsetHeight, 42, "height was animated" );
- });
+ } );
this.clock.tick( 100 );
-});
+} );
test( "animate block width/height", function() {
expect( 3 );
- jQuery("").appendTo("#qunit-fixture").css({
+ jQuery( " " ).appendTo( "#qunit-fixture" ).css( {
display: "block",
width: 20,
height: 20,
paddingLeft: 60
- }).animate({
+ } ).animate( {
width: 42,
height: 42
}, {
@@ -359,78 +359,78 @@ test( "animate block width/height", function() {
}
},
complete: function() {
- equal( jQuery( this ).css("display"), "block", "inline-block was not set on block element when animating width/height" );
+ equal( jQuery( this ).css( "display" ), "block", "inline-block was not set on block element when animating width/height" );
equal( jQuery( this ).width(), 42, "width was animated" );
equal( jQuery( this ).height(), 42, "height was animated" );
}
- });
+ } );
this.clock.tick( 100 );
-});
+} );
test( "animate table width/height", function() {
- expect(1);
+ expect( 1 );
- jQuery( "#table" ).animate({ width: 42, height: 42 }, 100, function() {
+ jQuery( "#table" ).animate( { width: 42, height: 42 }, 100, function() {
equal( jQuery( this ).css( "display" ), "table", "display mode is correct" );
- });
+ } );
this.clock.tick( 100 );
-});
+} );
-test("animate table-row width/height", function() {
- expect(3);
- var tr = jQuery("#table")
- .attr({ "cellspacing": 0, "cellpadding": 0, "border": 0 })
- .html(" | ")
- .find("tr");
+test( "animate table-row width/height", function() {
+ expect( 3 );
+ var tr = jQuery( "#table" )
+ .attr( { "cellspacing": 0, "cellpadding": 0, "border": 0 } )
+ .html( " | " )
+ .find( "tr" );
- tr.animate({ width: 10, height: 10 }, 100, function() {
+ tr.animate( { width: 10, height: 10 }, 100, function() {
equal( jQuery( this ).css( "display" ), "table-row", "display mode is correct" );
equal( this.offsetWidth, 20, "width animated to shrink wrap point" );
equal( this.offsetHeight, 20, "height animated to shrink wrap point" );
- });
+ } );
this.clock.tick( 100 );
-});
+} );
-test("animate table-cell width/height", function() {
- expect(3);
+test( "animate table-cell width/height", function() {
+ expect( 3 );
var td = jQuery( "#table" )
- .attr({ "cellspacing": 0, "cellpadding": 0, "border": 0 })
+ .attr( { "cellspacing": 0, "cellpadding": 0, "border": 0 } )
.html( " | " )
.find( "td" );
- td.animate({ width: 10, height: 10 }, 100, function() {
+ td.animate( { width: 10, height: 10 }, 100, function() {
equal( jQuery( this ).css( "display" ), "table-cell", "display mode is correct" );
equal( this.offsetWidth, 20, "width animated to shrink wrap point" );
equal( this.offsetHeight, 20, "height animated to shrink wrap point" );
- });
+ } );
this.clock.tick( 100 );
-});
+} );
-test("animate percentage(%) on width/height", function() {
+test( "animate percentage(%) on width/height", function() {
expect( 2 );
- var $div = jQuery(" ")
- .appendTo("#qunit-fixture").children("div");
+ var $div = jQuery( " " )
+ .appendTo( "#qunit-fixture" ).children( "div" );
- $div.animate({ width: "25%", height: "25%" }, 13, function() {
- var $this = jQuery(this);
- equal( $this.css("width"), "15px", "Width was animated to 15px rather than 25px");
- equal( $this.css("height"), "15px", "Height was animated to 15px rather than 25px");
- });
+ $div.animate( { width: "25%", height: "25%" }, 13, function() {
+ var $this = jQuery( this );
+ equal( $this.css( "width" ), "15px", "Width was animated to 15px rather than 25px" );
+ equal( $this.css( "height" ), "15px", "Height was animated to 15px rather than 25px" );
+ } );
this.clock.tick( 20 );
-});
+} );
-test("animate resets overflow-x and overflow-y when finished", function() {
- expect(2);
- jQuery("#foo")
- .css({ display: "block", width: 20, height: 20, overflowX: "visible", overflowY: "auto" })
- .animate({ width: 42, height: 42 }, 100, function() {
+test( "animate resets overflow-x and overflow-y when finished", function() {
+ expect( 2 );
+ jQuery( "#foo" )
+ .css( { display: "block", width: 20, height: 20, overflowX: "visible", overflowY: "auto" } )
+ .animate( { width: 42, height: 42 }, 100, function() {
equal( this.style.overflowX, "visible", "overflow-x is visible" );
equal( this.style.overflowY, "auto", "overflow-y is auto" );
- });
+ } );
this.clock.tick( 100 );
-});
+} );
/* // This test ends up being flaky depending upon the CPU load
test("animate option (queue === false)", function () {
@@ -457,7 +457,7 @@ test( "animate option { queue: false }", function() {
expect( 2 );
var foo = jQuery( "#foo" );
- foo.animate({
+ foo.animate( {
fontSize: "2em"
}, {
queue: false,
@@ -465,17 +465,17 @@ test( "animate option { queue: false }", function() {
complete: function() {
ok( true, "Animation Completed" );
}
- });
+ } );
this.clock.tick( 10 );
equal( foo.queue().length, 0, "Queue is empty" );
-});
+} );
test( "animate option { queue: true }", function() {
expect( 2 );
var foo = jQuery( "#foo" );
- foo.animate({
+ foo.animate( {
fontSize: "2em"
}, {
queue: true,
@@ -483,18 +483,18 @@ test( "animate option { queue: true }", function() {
complete: function() {
ok( true, "Animation Completed" );
}
- });
+ } );
notEqual( foo.queue().length, 0, "Default queue is not empty" );
//clear out existing timers before next test
this.clock.tick( 10 );
-});
+} );
test( "animate option { queue: 'name' }", function() {
expect( 5 );
var foo = jQuery( "#foo" ),
- origWidth = parseFloat( foo.css("width") ),
+ origWidth = parseFloat( foo.css( "width" ) ),
order = [];
foo.animate( { width: origWidth + 100 }, {
@@ -504,128 +504,127 @@ test( "animate option { queue: 'name' }", function() {
// second callback function
order.push( 2 );
- equal( parseFloat( foo.css("width") ), origWidth + 100, "Animation ended" );
- equal( foo.queue("name").length, 1, "Queue length of 'name' queue" );
+ equal( parseFloat( foo.css( "width" ) ), origWidth + 100, "Animation ended" );
+ equal( foo.queue( "name" ).length, 1, "Queue length of 'name' queue" );
}
- }).queue( "name", function() {
+ } ).queue( "name", function() {
// last callback function
deepEqual( order, [ 1, 2 ], "Callbacks in expected order" );
- });
-
+ } );
// this is the first callback function that should be called
order.push( 1 );
- equal( parseFloat( foo.css("width") ), origWidth, "Animation does not start on its own." );
- equal( foo.queue("name").length, 2, "Queue length of 'name' queue" );
+ equal( parseFloat( foo.css( "width" ) ), origWidth, "Animation does not start on its own." );
+ equal( foo.queue( "name" ).length, 2, "Queue length of 'name' queue" );
foo.dequeue( "name" );
this.clock.tick( 10 );
-});
+} );
-test("animate with no properties", function() {
- expect(2);
+test( "animate with no properties", function() {
+ expect( 2 );
var foo,
- divs = jQuery("div"),
+ divs = jQuery( "div" ),
count = 0;
- divs.animate({}, function(){
+ divs.animate( {}, function() {
count++;
- });
+ } );
equal( divs.length, count, "Make sure that callback is called for each element in the set." );
+ foo = jQuery( "#foo" );
- foo = jQuery("#foo");
-
- foo.animate({});
- foo.animate({top: 10}, 100, function(){
+ foo.animate( {} );
+ foo.animate( { top: 10 }, 100, function() {
ok( true, "Animation was properly dequeued." );
- });
+ } );
this.clock.tick( 100 );
-});
-
-test("animate duration 0", function() {
- expect(11);
+} );
+test( "animate duration 0", function() {
+ expect( 11 );
var $elem,
- $elems = jQuery([{ a:0 },{ a:0 }]),
+ $elems = jQuery( [ { a:0 },{ a:0 } ] ),
counter = 0;
equal( jQuery.timers.length, 0, "Make sure no animation was running from another test" );
- $elems.eq(0).animate( {a:1}, 0, function(){
+ $elems.eq( 0 ).animate( { a:1 }, 0, function() {
ok( true, "Animate a simple property." );
counter++;
- });
+ } );
// Failed until [6115]
equal( jQuery.timers.length, 0, "Make sure synchronic animations are not left on jQuery.timers" );
equal( counter, 1, "One synchronic animations" );
- $elems.animate( { a:2 }, 0, function(){
+ $elems.animate( { a:2 }, 0, function() {
ok( true, "Animate a second simple property." );
counter++;
- });
+ } );
equal( counter, 3, "Multiple synchronic animations" );
- $elems.eq(0).animate( {a:3}, 0, function(){
+ $elems.eq( 0 ).animate( { a:3 }, 0, function() {
ok( true, "Animate a third simple property." );
counter++;
- });
- $elems.eq(1).animate( {a:3}, 200, function(){
+ } );
+ $elems.eq( 1 ).animate( { a:3 }, 200, function() {
counter++;
+
// Failed until [6115]
equal( counter, 5, "One synchronic and one asynchronic" );
- });
+ } );
this.clock.tick( 200 );
- $elem = jQuery(" ");
- $elem.show(0, function(){
- ok(true, "Show callback with no duration");
- });
- $elem.hide(0, function(){
- ok(true, "Hide callback with no duration");
- });
+ $elem = jQuery( " " );
+ $elem.show( 0, function() {
+ ok( true, "Show callback with no duration" );
+ } );
+ $elem.hide( 0, function() {
+ ok( true, "Hide callback with no duration" );
+ } );
// manually clean up detached elements
$elem.remove();
-});
+} );
-test("animate hyphenated properties", function() {
- expect(1);
+test( "animate hyphenated properties", function() {
+ expect( 1 );
- jQuery("#foo")
- .css("font-size", 10)
- .animate({"font-size": 20}, 200, function() {
+ jQuery( "#foo" )
+ .css( "font-size", 10 )
+ .animate( { "font-size": 20 }, 200, function() {
equal( this.style.fontSize, "20px", "The font-size property was animated." );
- });
+ } );
+
// FIXME why is this double only when run with other tests
this.clock.tick( 400 );
-});
+} );
-test("animate non-element", function() {
- expect(1);
+test( "animate non-element", function() {
+ expect( 1 );
var obj = { test: 0 };
- jQuery(obj).animate({test: 200}, 200, function(){
+ jQuery( obj ).animate( { test: 200 }, 200, function() {
equal( obj.test, 200, "The custom property should be modified." );
- });
+ } );
this.clock.tick( 200 );
-});
+} );
-test("stop()", function() {
+test( "stop()", function() {
expect( 4 );
var $one, $two,
- $foo = jQuery("#foo"),
+ $foo = jQuery( "#foo" ),
w = 0,
nw;
@@ -633,34 +632,35 @@ test("stop()", function() {
.animate( { "width": "show" }, 1500 );
this.clock.tick( 100 );
- nw = $foo.css("width");
+ nw = $foo.css( "width" );
notEqual( parseFloat( nw ), w, "An animation occurred " + nw + " " + w + "px" );
$foo.stop();
- nw = $foo.css("width");
+ nw = $foo.css( "width" );
notEqual( parseFloat( nw ), w, "Stop didn't reset the animation " + nw + " " + w + "px" );
this.clock.tick( 100 );
$foo.removeData();
- $foo.removeData(undefined, true);
- equal( nw, $foo.css("width"), "The animation didn't continue" );
+ $foo.removeData( undefined, true );
+ equal( nw, $foo.css( "width" ), "The animation didn't continue" );
- $one = jQuery("#fadein");
- $two = jQuery("#show");
- $one.fadeTo(100, 0, function() {
+ $one = jQuery( "#fadein" );
+ $two = jQuery( "#show" );
+ $one.fadeTo( 100, 0, function() {
$one.stop();
- });
+ } );
this.clock.tick( 100 );
- $two.fadeTo(100, 0, function() {
- equal( $two.css("opacity"), "0", "Stop does not interfere with animations on other elements (#6641)" );
- // Reset styles
- $one.add( $two ).css("opacity", "");
- });
- this.clock.tick( 100 );
-});
+ $two.fadeTo( 100, 0, function() {
+ equal( $two.css( "opacity" ), "0", "Stop does not interfere with animations on other elements (#6641)" );
-test("stop() - several in queue", function() {
+ // Reset styles
+ $one.add( $two ).css( "opacity", "" );
+ } );
+ this.clock.tick( 100 );
+} );
+
+test( "stop() - several in queue", function() {
expect( 5 );
var nw, $foo = jQuery( "#foo" );
@@ -668,9 +668,9 @@ test("stop() - several in queue", function() {
// default duration is 400ms, so 800px ensures we aren't 0 or 1 after 1ms
$foo.hide().css( "width", 800 );
- $foo.animate({ "width": "show" }, 400, "linear");
- $foo.animate({ "width": "hide" });
- $foo.animate({ "width": "show" });
+ $foo.animate( { "width": "show" }, 400, "linear" );
+ $foo.animate( { "width": "hide" } );
+ $foo.animate( { "width": "show" } );
this.clock.tick( 1 );
@@ -688,119 +688,121 @@ test("stop() - several in queue", function() {
$foo.stop( true );
equal( $foo.queue().length, 0, "0 in the queue" );
-});
+} );
-test("stop(clearQueue)", function() {
- expect(4);
+test( "stop(clearQueue)", function() {
+ expect( 4 );
- var $foo = jQuery("#foo"),
+ var $foo = jQuery( "#foo" ),
w = 0,
nw;
- $foo.hide().css( "width", 200 ).css("width");
+ $foo.hide().css( "width", 200 ).css( "width" );
- $foo.animate({ "width": "show" }, 1000);
- $foo.animate({ "width": "hide" }, 1000);
- $foo.animate({ "width": "show" }, 1000);
+ $foo.animate( { "width": "show" }, 1000 );
+ $foo.animate( { "width": "hide" }, 1000 );
+ $foo.animate( { "width": "show" }, 1000 );
this.clock.tick( 100 );
- nw = $foo.css("width");
- ok( parseFloat( nw ) !== w, "An animation occurred " + nw + " " + w + "px");
- $foo.stop(true);
+ nw = $foo.css( "width" );
+ ok( parseFloat( nw ) !== w, "An animation occurred " + nw + " " + w + "px" );
+ $foo.stop( true );
- nw = $foo.css("width");
- ok( parseFloat( nw ) !== w, "Stop didn't reset the animation " + nw + " " + w + "px");
+ nw = $foo.css( "width" );
+ ok( parseFloat( nw ) !== w, "Stop didn't reset the animation " + nw + " " + w + "px" );
equal( $foo.queue().length, 0, "The animation queue was cleared" );
this.clock.tick( 100 );
- equal( nw, $foo.css("width"), "The animation didn't continue" );
-});
+ equal( nw, $foo.css( "width" ), "The animation didn't continue" );
+} );
-test("stop(clearQueue, gotoEnd)", function() {
- expect(1);
+test( "stop(clearQueue, gotoEnd)", function() {
+ expect( 1 );
- var $foo = jQuery("#foo"),
+ var $foo = jQuery( "#foo" ),
w = 0,
nw;
- $foo.hide().css( "width", 200 ).css("width");
+ $foo.hide().css( "width", 200 ).css( "width" );
- $foo.animate({ width: "show" }, 1000);
- $foo.animate({ width: "hide" }, 1000);
- $foo.animate({ width: "show" }, 1000);
- $foo.animate({ width: "hide" }, 1000);
+ $foo.animate( { width: "show" }, 1000 );
+ $foo.animate( { width: "hide" }, 1000 );
+ $foo.animate( { width: "show" }, 1000 );
+ $foo.animate( { width: "hide" }, 1000 );
this.clock.tick( 100 );
- nw = $foo.css("width");
- ok( parseFloat( nw ) !== w, "An animation occurred " + nw + " " + w + "px");
- $foo.stop(false, true);
+ nw = $foo.css( "width" );
+ ok( parseFloat( nw ) !== w, "An animation occurred " + nw + " " + w + "px" );
+ $foo.stop( false, true );
+
+ nw = $foo.css( "width" );
- nw = $foo.css("width");
// Disabled, being flaky
//equal( nw, 1, "Stop() reset the animation" );
this.clock.tick( 100 );
+
// Disabled, being flaky
//equal( $foo.queue().length, 2, "The next animation continued" );
- $foo.stop(true);
-});
+ $foo.stop( true );
+} );
test( "stop( queue, ..., ... ) - Stop single queues", function() {
expect( 3 );
var saved,
- foo = jQuery("#foo").css({ width: 200, height: 200 });
+ foo = jQuery( "#foo" ).css( { width: 200, height: 200 } );
- foo.animate({
+ foo.animate( {
width: 400
- },{
+ }, {
duration: 500,
complete: function() {
- equal( parseFloat( foo.css("width") ), 400, "Animation completed for standard queue" );
- equal( parseFloat( foo.css("height") ), saved, "Height was not changed after the second stop");
+ equal( parseFloat( foo.css( "width" ) ), 400, "Animation completed for standard queue" );
+ equal( parseFloat( foo.css( "height" ) ), saved, "Height was not changed after the second stop" );
}
- });
+ } );
- foo.animate({
+ foo.animate( {
height: 400
- },{
+ }, {
duration: 1000,
queue: "height"
- }).dequeue("height").stop( "height", false, true );
+ } ).dequeue( "height" ).stop( "height", false, true );
- equal( parseFloat( foo.css("height") ), 400, "Height was stopped with gotoEnd" );
+ equal( parseFloat( foo.css( "height" ) ), 400, "Height was stopped with gotoEnd" );
- foo.animate({
+ foo.animate( {
height: 200
- },{
+ }, {
duration: 1000,
queue: "height"
- }).dequeue( "height" ).stop( "height", false, false );
- saved = parseFloat( foo.css("height") );
+ } ).dequeue( "height" ).stop( "height", false, false );
+ saved = parseFloat( foo.css( "height" ) );
this.clock.tick( 500 );
-});
+} );
-test("toggle()", function() {
- expect(6);
- var x = jQuery("#foo");
- ok( x.is(":visible"), "is visible" );
+test( "toggle()", function() {
+ expect( 6 );
+ var x = jQuery( "#foo" );
+ ok( x.is( ":visible" ), "is visible" );
x.toggle();
- ok( x.is(":hidden"), "is hidden" );
+ ok( x.is( ":hidden" ), "is hidden" );
x.toggle();
- ok( x.is(":visible"), "is visible again" );
+ ok( x.is( ":visible" ), "is visible again" );
- x.toggle(true);
- ok( x.is(":visible"), "is visible" );
- x.toggle(false);
- ok( x.is(":hidden"), "is hidden" );
- x.toggle(true);
- ok( x.is(":visible"), "is visible again" );
-});
+ x.toggle( true );
+ ok( x.is( ":visible" ), "is visible" );
+ x.toggle( false );
+ ok( x.is( ":hidden" ), "is hidden" );
+ x.toggle( true );
+ ok( x.is( ":visible" ), "is visible again" );
+} );
test( "jQuery.fx.prototype.cur() - <1.8 Back Compat", function() {
expect( 7 );
- var div = jQuery( " " ).appendTo( "#qunit-fixture" ).css({
+ var div = jQuery( " " ).appendTo( "#qunit-fixture" ).css( {
color: "#ABC",
border: "5px solid black",
left: "auto",
marginBottom: "-11000px"
- })[0];
+ } )[ 0 ];
equal(
( new jQuery.fx( div, {}, "color" ) ).cur(),
@@ -846,31 +848,31 @@ test( "jQuery.fx.prototype.cur() - <1.8 Back Compat", function() {
);
jQuery( div ).remove();
-});
+} );
-test("Overflow and Display", function() {
- expect(4);
+test( "Overflow and Display", function() {
+ expect( 4 );
var
- testClass = jQuery.makeTest("Overflow and Display")
- .addClass("overflow inline"),
- testStyle = jQuery.makeTest("Overflow and Display (inline style)")
- .css({ overflow: "visible", display: "inline" }),
+ testClass = jQuery.makeTest( "Overflow and Display" )
+ .addClass( "overflow inline" ),
+ testStyle = jQuery.makeTest( "Overflow and Display (inline style)" )
+ .css( { overflow: "visible", display: "inline" } ),
done = function() {
equal( jQuery.css( this, "overflow" ), "visible", "Overflow should be 'visible'" );
equal( jQuery.css( this, "display" ), "inline", "Display should be 'inline'" );
};
testClass.add( testStyle )
- .addClass("widewidth")
- .text("Some sample text.")
- .before("text before")
- .after("text after")
- .animate({ opacity: 0.5 }, "slow", done );
+ .addClass( "widewidth" )
+ .text( "Some sample text." )
+ .before( "text before" )
+ .after( "text after" )
+ .animate( { opacity: 0.5 }, "slow", done );
this.clock.tick( 600 );
-});
+} );
-jQuery.each({
+jQuery.each( {
"CSS Auto": function( elem, prop ) {
jQuery( elem ).addClass( "auto" + prop )
.text( "This is a long string of text." );
@@ -906,7 +908,7 @@ jQuery.each({
return 0;
}
}, function( fn, f ) {
- jQuery.each({
+ jQuery.each( {
"show": function( elem, prop ) {
jQuery( elem ).hide().addClass( "wide" + prop );
return "show";
@@ -927,7 +929,7 @@ jQuery.each({
return 0;
}
}, function( tn, t ) {
- test(fn + " to " + tn, function() {
+ test( fn + " to " + tn, function() {
var num, anim,
elem = jQuery.makeTest( fn + " to " + tn ),
t_w = t( elem, "width" ),
@@ -942,6 +944,7 @@ jQuery.each({
}
num = 0;
+
// TODO: uncrowd this
if ( t_h === "show" ) { num++; }
if ( t_w === "show" ) { num++; }
@@ -957,9 +960,9 @@ jQuery.each({
anim = { width: t_w, height: t_h, opacity: t_o };
- elem.animate(anim, 50);
+ elem.animate( anim, 50 );
- jQuery.when( elem ).done(function( $elem ) {
+ jQuery.when( elem ).done( function( $elem ) {
var cur_o, cur_w, cur_h, old_h,
elem = $elem[ 0 ];
@@ -976,9 +979,9 @@ jQuery.each({
ok( f_h === "" ? elem.style.height === f_h : elem.style.height.indexOf( f_h ) === 0, "Height must be reset to " + f_h + ": " + elem.style.height );
}
- cur_o = jQuery.style(elem, "opacity");
+ cur_o = jQuery.style( elem, "opacity" );
- if ( f_o !== jQuery.css(elem, "opacity") ) {
+ if ( f_o !== jQuery.css( elem, "opacity" ) ) {
f_o = f( elem, "opacity" );
}
@@ -987,6 +990,7 @@ jQuery.each({
if ( f_o === "" ) {
f_o = 1;
}
+
// See above
if ( cur_o === "" ) {
cur_o = 1;
@@ -1003,13 +1007,13 @@ jQuery.each({
if ( t_o.constructor === Number ) {
equal( cur_o, t_o, "Final opacity should be " + t_o + ": " + cur_o );
- ok( jQuery.css(elem, "opacity") !== "" || cur_o === t_o, "Opacity should be explicitly set to " + t_o + ", is instead: " + cur_o );
+ ok( jQuery.css( elem, "opacity" ) !== "" || cur_o === t_o, "Opacity should be explicitly set to " + t_o + ", is instead: " + cur_o );
}
if ( t_w.constructor === Number ) {
equal( elem.style.width, t_w + "px", "Final width should be " + t_w + ": " + elem.style.width );
- cur_w = jQuery.css( elem,"width" );
+ cur_w = jQuery.css( elem, "width" );
ok( elem.style.width !== "" || cur_w === t_w, "Width should be explicitly set to " + t_w + ", is instead: " + cur_w );
}
@@ -1017,14 +1021,14 @@ jQuery.each({
if ( t_h.constructor === Number ) {
equal( elem.style.height, t_h + "px", "Final height should be " + t_h + ": " + elem.style.height );
- cur_h = jQuery.css( elem,"height" );
+ cur_h = jQuery.css( elem, "height" );
ok( elem.style.height !== "" || cur_h === t_h, "Height should be explicitly set to " + t_h + ", is instead: " + cur_h );
}
if ( t_h === "show" ) {
old_h = jQuery.css( elem, "height" );
- jQuery( elem ).append(" Some more text and some more...");
+ jQuery( elem ).append( " Some more text and some more..." );
if ( /Auto/.test( fn ) ) {
notEqual( jQuery.css( elem, "height" ), old_h, "Make sure height is auto." );
@@ -1036,18 +1040,18 @@ jQuery.each({
// manually remove generated element
jQuery( elem ).remove();
- });
+ } );
this.clock.tick( 50 );
- });
- });
-});
+ } );
+ } );
+} );
-test("Effects chaining", function() {
+test( "Effects chaining", function() {
var remaining = 16,
props = [ "opacity", "height", "width", "display", "overflow" ],
setup = function( name, selector ) {
var $el = jQuery( selector );
- return $el.data( getProps( $el[0] ) ).data( "name", name );
+ return $el.data( getProps( $el[ 0 ] ) ).data( "name", name );
},
assert = function() {
var data = jQuery.data( this ),
@@ -1062,39 +1066,39 @@ test("Effects chaining", function() {
var obj = {};
jQuery.each( props, function( i, prop ) {
obj[ prop ] = prop === "overflow" && hiddenOverflow ? "hidden" : el.style[ prop ] || jQuery.css( el, prop );
- });
+ } );
return obj;
};
expect( remaining );
- setup( ".fadeOut().fadeIn()", "#fadein div" ).fadeOut("fast").fadeIn( "fast", assert );
- setup( ".fadeIn().fadeOut()", "#fadeout div" ).fadeIn("fast").fadeOut( "fast", assert );
- setup( ".hide().show()", "#show div" ).hide("fast").show( "fast", assert );
- setup( ".show().hide()", "#hide div" ).show("fast").hide( "fast", assert );
- setup( ".show().hide(easing)", "#easehide div" ).show("fast").hide( "fast", "linear", assert );
- setup( ".toggle().toggle() - in", "#togglein div" ).toggle("fast").toggle( "fast", assert );
- setup( ".toggle().toggle() - out", "#toggleout div" ).toggle("fast").toggle( "fast", assert );
- setup( ".toggle().toggle(easing) - out", "#easetoggleout div" ).toggle("fast").toggle( "fast", "linear", assert );
- setup( ".slideDown().slideUp()", "#slidedown div" ).slideDown("fast").slideUp( "fast", assert );
- setup( ".slideUp().slideDown()", "#slideup div" ).slideUp("fast").slideDown( "fast", assert );
- setup( ".slideUp().slideDown(easing)", "#easeslideup div" ).slideUp("fast").slideDown( "fast", "linear", assert );
- setup( ".slideToggle().slideToggle() - in", "#slidetogglein div" ).slideToggle("fast").slideToggle( "fast", assert );
- setup( ".slideToggle().slideToggle() - out", "#slidetoggleout div" ).slideToggle("fast").slideToggle( "fast", assert );
- setup( ".fadeToggle().fadeToggle() - in", "#fadetogglein div" ).fadeToggle("fast").fadeToggle( "fast", assert );
- setup( ".fadeToggle().fadeToggle() - out", "#fadetoggleout div" ).fadeToggle("fast").fadeToggle( "fast", assert );
+ setup( ".fadeOut().fadeIn()", "#fadein div" ).fadeOut( "fast" ).fadeIn( "fast", assert );
+ setup( ".fadeIn().fadeOut()", "#fadeout div" ).fadeIn( "fast" ).fadeOut( "fast", assert );
+ setup( ".hide().show()", "#show div" ).hide( "fast" ).show( "fast", assert );
+ setup( ".show().hide()", "#hide div" ).show( "fast" ).hide( "fast", assert );
+ setup( ".show().hide(easing)", "#easehide div" ).show( "fast" ).hide( "fast", "linear", assert );
+ setup( ".toggle().toggle() - in", "#togglein div" ).toggle( "fast" ).toggle( "fast", assert );
+ setup( ".toggle().toggle() - out", "#toggleout div" ).toggle( "fast" ).toggle( "fast", assert );
+ setup( ".toggle().toggle(easing) - out", "#easetoggleout div" ).toggle( "fast" ).toggle( "fast", "linear", assert );
+ setup( ".slideDown().slideUp()", "#slidedown div" ).slideDown( "fast" ).slideUp( "fast", assert );
+ setup( ".slideUp().slideDown()", "#slideup div" ).slideUp( "fast" ).slideDown( "fast", assert );
+ setup( ".slideUp().slideDown(easing)", "#easeslideup div" ).slideUp( "fast" ).slideDown( "fast", "linear", assert );
+ setup( ".slideToggle().slideToggle() - in", "#slidetogglein div" ).slideToggle( "fast" ).slideToggle( "fast", assert );
+ setup( ".slideToggle().slideToggle() - out", "#slidetoggleout div" ).slideToggle( "fast" ).slideToggle( "fast", assert );
+ setup( ".fadeToggle().fadeToggle() - in", "#fadetogglein div" ).fadeToggle( "fast" ).fadeToggle( "fast", assert );
+ setup( ".fadeToggle().fadeToggle() - out", "#fadetoggleout div" ).fadeToggle( "fast" ).fadeToggle( "fast", assert );
setup( ".fadeTo(0.5).fadeTo(1.0, easing)", "#fadeto div" ).fadeTo( "fast", 0.5 ).fadeTo( "fast", 1.0, "linear", assert );
this.clock.tick( 400 );
-});
+} );
-jQuery.makeTest = function( text ){
- var elem = jQuery(" ")
+jQuery.makeTest = function( text ) {
+ var elem = jQuery( " " )
.attr( "id", "test" + jQuery.makeTest.id++ )
- .addClass("box");
+ .addClass( "box" );
- jQuery(" ")
+ jQuery( " " )
.text( text )
- .appendTo("#fx-tests")
+ .appendTo( "#fx-tests" )
.after( elem );
return elem;
@@ -1102,18 +1106,18 @@ jQuery.makeTest = function( text ){
jQuery.makeTest.id = 1;
-test("jQuery.show('fast') doesn't clear radio buttons (bug #1095)", function () {
- expect(4);
+test( "jQuery.show('fast') doesn't clear radio buttons (bug #1095)", function() {
+ expect( 4 );
- var $checkedtest = jQuery("#checkedtest");
- $checkedtest.hide().show("fast", function() {
- ok( jQuery("input[type='radio']", $checkedtest).first().attr("checked"), "Check first radio still checked." );
- ok( !jQuery("input[type='radio']", $checkedtest).last().attr("checked"), "Check last radio still NOT checked." );
- ok( jQuery("input[type='checkbox']", $checkedtest).first().attr("checked"), "Check first checkbox still checked." );
- ok( !jQuery("input[type='checkbox']", $checkedtest).last().attr("checked"), "Check last checkbox still NOT checked." );
- });
+ var $checkedtest = jQuery( "#checkedtest" );
+ $checkedtest.hide().show( "fast", function() {
+ ok( jQuery( "input[type='radio']", $checkedtest ).first().attr( "checked" ), "Check first radio still checked." );
+ ok( !jQuery( "input[type='radio']", $checkedtest ).last().attr( "checked" ), "Check last radio still NOT checked." );
+ ok( jQuery( "input[type='checkbox']", $checkedtest ).first().attr( "checked" ), "Check first checkbox still checked." );
+ ok( !jQuery( "input[type='checkbox']", $checkedtest ).last().attr( "checked" ), "Check last checkbox still NOT checked." );
+ } );
this.clock.tick( 200 );
-});
+} );
test( "interrupt toggle", function() {
expect( 24 );
@@ -1122,13 +1126,14 @@ test( "interrupt toggle", function() {
longDuration = 2000,
shortDuration = 500,
remaining = 0,
- $elems = jQuery(".chain-test"),
+ $elems = jQuery( ".chain-test" ),
clock = this.clock,
finish = function() {
};
jQuery.each( { slideToggle: "height", fadeToggle: "opacity", toggle: "width" }, function( method, prop ) {
- var $methodElems = $elems.filter( "[id^='" + method.toLowerCase() + "']" ).each(function() {
+ var $methodElems = $elems.filter( "[id^='" + method.toLowerCase() + "']" ).each( function() {
+
// Don't end test until we're done with this element
remaining++;
@@ -1137,28 +1142,28 @@ test( "interrupt toggle", function() {
// Expect display data from our .hide() call below
QUnit.expectJqData( env, this, "display" );
- });
+ } );
// Interrupt a hiding toggle
$methodElems[ method ]( longDuration );
- setTimeout(function() {
- $methodElems.stop().each(function() {
+ setTimeout( function() {
+ $methodElems.stop().each( function() {
notEqual( jQuery( this ).css( prop ), jQuery.data( this, "startVal" ), ".stop() before completion of hiding ." + method + "() - #" + this.id );
- });
+ } );
// Restore
$methodElems[ method ]( shortDuration, function() {
var id = this.id,
$elem = jQuery( this ),
- startVal = $elem.data("startVal");
+ startVal = $elem.data( "startVal" );
- $elem.removeData("startVal");
+ $elem.removeData( "startVal" );
equal( $elem.css( prop ), startVal, "original value restored by ." + method + "() - #" + id );
// Interrupt a showing toggle
$elem.hide()[ method ]( longDuration );
- setTimeout(function() {
+ setTimeout( function() {
$elem.stop();
notEqual( $elem.css( prop ), startVal, ".stop() before completion of showing ." + method + "() - #" + id );
@@ -1166,15 +1171,15 @@ test( "interrupt toggle", function() {
$elem[ method ]( shortDuration, function() {
equal( $elem.css( prop ), startVal, "original value restored by ." + method + "() - #" + id );
finish();
- });
+ } );
}, shortDuration );
- });
+ } );
}, shortDuration );
- });
+ } );
clock.tick( longDuration );
// FIXME untangle the set timeouts
-});
+} );
test( "animate with per-property easing", function() {
@@ -1211,34 +1216,34 @@ test( "animate with per-property easing", function() {
ok( defaultTestCalled, "Easing function (_default) called" );
equal( props.a[ 1 ], "_test1", "animate does not change original props (per-property easing would be lost)" );
equal( props.b[ 1 ], "_test2", "animate does not change original props (per-property easing would be lost)" );
- });
+ } );
this.clock.tick( 400 );
-});
+} );
-test("animate with CSS shorthand properties", function(){
- expect(11);
+test( "animate with CSS shorthand properties", function() {
+ expect( 11 );
var easeAnimation_count = 0,
easeProperty_count = 0,
propsBasic = { "padding": "10 20 30" },
propsSpecial = { "padding": [ "1 2 3", "propertyScope" ] };
- jQuery.easing.animationScope = function(p) {
+ jQuery.easing.animationScope = function( p ) {
if ( p >= 1 ) {
easeAnimation_count++;
}
return p;
};
- jQuery.easing.propertyScope = function(p) {
+ jQuery.easing.propertyScope = function( p ) {
if ( p >= 1 ) {
easeProperty_count++;
}
return p;
};
- jQuery("#foo")
+ jQuery( "#foo" )
.animate( propsBasic, 200, "animationScope", function() {
equal( this.style.paddingTop, "10px", "padding-top was animated" );
equal( this.style.paddingLeft, "20px", "padding-left was animated" );
@@ -1246,7 +1251,7 @@ test("animate with CSS shorthand properties", function(){
equal( this.style.paddingBottom, "30px", "padding-bottom was animated" );
equal( easeAnimation_count, 4, "per-animation default easing called for each property" );
easeAnimation_count = 0;
- })
+ } )
.animate( propsSpecial, 200, "animationScope", function() {
equal( this.style.paddingTop, "1px", "padding-top was animated again" );
equal( this.style.paddingLeft, "2px", "padding-left was animated again" );
@@ -1255,38 +1260,37 @@ test("animate with CSS shorthand properties", function(){
equal( easeAnimation_count, 0, "per-animation default easing not called" );
equal( easeProperty_count, 4, "special easing called for each property" );
- jQuery(this).css("padding", "0");
+ jQuery( this ).css( "padding", "0" );
delete jQuery.easing.animationScope;
delete jQuery.easing.propertyScope;
- });
+ } );
this.clock.tick( 400 );
-});
+} );
-test("hide hidden elements, with animation (bug #7141)", function() {
- expect(3);
+test( "hide hidden elements, with animation (bug #7141)", function() {
+ expect( 3 );
-
- var div = jQuery(" ").appendTo("#qunit-fixture");
- equal( div.css("display"), "none", "Element is hidden by default" );
- div.hide(1, function () {
- ok( !jQuery._data(div, "display"), "display data is undefined after hiding an already-hidden element" );
- div.show(1, function () {
- equal( div.css("display"), "block", "Show a double-hidden element" );
- });
- });
+ var div = jQuery( " " ).appendTo( "#qunit-fixture" );
+ equal( div.css( "display" ), "none", "Element is hidden by default" );
+ div.hide( 1, function() {
+ ok( !jQuery._data( div, "display" ), "display data is undefined after hiding an already-hidden element" );
+ div.show( 1, function() {
+ equal( div.css( "display" ), "block", "Show a double-hidden element" );
+ } );
+ } );
this.clock.tick( 10 );
-});
+} );
-test("animate unit-less properties (#4966)", function() {
+test( "animate unit-less properties (#4966)", function() {
expect( 2 );
var div = jQuery( " " ).appendTo( "#qunit-fixture" );
equal( div.css( "z-index" ), "0", "z-index is 0" );
- div.animate({ zIndex: 2 }, function() {
+ div.animate( { zIndex: 2 }, function() {
equal( div.css( "z-index" ), "2", "z-index is 2" );
- });
+ } );
this.clock.tick( 400 );
-});
+} );
test( "animate properties missing px w/ opacity as last (#9074)", function() {
expect( 2 );
@@ -1300,11 +1304,11 @@ test( "animate properties missing px w/ opacity as last (#9074)", function() {
}
equal( cssInt( "marginLeft" ), 0, "Margin left is 0" );
equal( cssInt( "left" ), 0, "Left is 0" );
- div.animate({
+ div.animate( {
left: 200,
marginLeft: 200,
opacity: 0
- }, 2000);
+ }, 2000 );
this.clock.tick( 500 );
@@ -1315,26 +1319,27 @@ test( "animate properties missing px w/ opacity as last (#9074)", function() {
notEqual( l, 0, "Left is not 0 after partial animate" );
notEqual( l, 200, "Left is not 200 after partial animate" );
div.stop().remove();
-});
+} );
-test("callbacks should fire in correct order (#9100)", function() {
+test( "callbacks should fire in correct order (#9100)", function() {
expect( 1 );
var a = 1,
cb = 0;
- jQuery(" ")
- .appendTo("#qunit-fixture")
+ jQuery( " " )
+ .appendTo( "#qunit-fixture" )
+
// The test will always pass if no properties are animated or if the duration is 0
- .animate({ fontSize: 12 }, 13, function() {
- a *= jQuery(this).data("operation") === "*2" ? 2 : a;
+ .animate( { fontSize: 12 }, 13, function() {
+ a *= jQuery( this ).data( "operation" ) === "*2" ? 2 : a;
cb++;
if ( cb === 2 ) {
- equal( a, 4, "test value has been *2 and _then_ ^2");
+ equal( a, 4, "test value has been *2 and _then_ ^2" );
}
- });
+ } );
this.clock.tick( 20 );
-});
+} );
test( "callbacks that throw exceptions will be removed (#5684)", function() {
expect( 2 );
@@ -1344,9 +1349,9 @@ test( "callbacks that throw exceptions will be removed (#5684)", function() {
function TestException() {
}
- foo.animate({ height: 1 }, 1, function() {
+ foo.animate( { height: 1 }, 1, function() {
throw new TestException();
- });
+ } );
// this test thoroughly abuses undocumented methods - please feel free to update
// with any changes internally to these functions.
@@ -1362,39 +1367,40 @@ test( "callbacks that throw exceptions will be removed (#5684)", function() {
ok( true, "Test completed without throwing a second exception" );
-});
+} );
-test("animate will scale margin properties individually", function() {
+test( "animate will scale margin properties individually", function() {
expect( 2 );
- var foo = jQuery( "#foo" ).css({
+ var foo = jQuery( "#foo" ).css( {
"margin": 0,
"marginLeft": 100
- });
+ } );
ok( foo.css( "marginLeft" ) !== foo.css( "marginRight" ), "Sanity Check" );
- foo.animate({
+ foo.animate( {
"margin": 200
- }).stop();
+ } ).stop();
- ok( foo.css( "marginLeft") !== foo.css( "marginRight" ), "The margin properties are different");
+ ok( foo.css( "marginLeft" ) !== foo.css( "marginRight" ), "The margin properties are different" );
// clean up for next test
- foo.css({
+ foo.css( {
"marginLeft": "",
"marginRight": "",
"marginTop": "",
"marginBottom": ""
- });
-});
+ } );
+} );
-test("Do not append px to 'fill-opacity' #9548", function() {
+test( "Do not append px to 'fill-opacity' #9548", function() {
expect( 1 );
- var $div = jQuery(" ").appendTo("#qunit-fixture");
+ var $div = jQuery( " " ).appendTo( "#qunit-fixture" );
+
+ $div.css( "fill-opacity", 0 ).animate( { "fill-opacity": 1.0 }, 0, function() {
- $div.css("fill-opacity", 0).animate({ "fill-opacity": 1.0 }, 0, function () {
// Support: Android 2.3 (no support for fill-opacity)
if ( jQuery( this ).css( "fill-opacity" ) ) {
equal( jQuery( this ).css( "fill-opacity" ), 1, "Do not append px to 'fill-opacity'" );
@@ -1402,10 +1408,10 @@ test("Do not append px to 'fill-opacity' #9548", function() {
ok( true, "No support for fill-opacity CSS property" );
}
$div.remove();
- });
-});
+ } );
+} );
-test("line-height animates correctly (#13855)", function() {
+test( "line-height animates correctly (#13855)", function() {
expect( 12 );
var t0,
@@ -1417,22 +1423,22 @@ test("line-height animates correctly (#13855)", function() {
" px " +
" percent " +
" em "
- ).appendTo("#qunit-fixture"),
+ ).appendTo( "#qunit-fixture" ),
initialHeight = jQuery.map( animated, function( el ) {
return jQuery( el ).height();
- }),
+ } ),
tolerance = 1.5;
// Delay start to improve test stability
- setTimeout(function() {
+ setTimeout( function() {
- t0 = +(new Date());
+ t0 = +( new Date() );
animated.animate( { "line-height": "hide" }, longDuration, "linear" );
- setTimeout(function() {
- var progress = ( (new Date()) - t0 ) / longDuration;
+ setTimeout( function() {
+ var progress = ( ( new Date() ) - t0 ) / longDuration;
- animated.each(function( i ) {
+ animated.each( function( i ) {
var label = jQuery.text( this ),
initial = initialHeight[ i ],
height = jQuery( this ).height(),
@@ -1441,32 +1447,32 @@ test("line-height animates correctly (#13855)", function() {
height + " < " + initial + " @ " + ( progress * 100 ) + "%" );
ok( height > lower, "hide " + label + ": lower bound; " +
height + " > " + lower + " @ " + ( progress * 100 ) + "%" );
- });
+ } );
- t0 = +(new Date());
+ t0 = +( new Date() );
animated.stop( true, true ).hide()
.animate( { "line-height": "show" }, longDuration, "linear" );
- setTimeout(function() {
- var progress = ( (new Date()) - t0 ) / longDuration;
+ setTimeout( function() {
+ var progress = ( ( new Date() ) - t0 ) / longDuration;
- animated.each(function( i ) {
+ animated.each( function( i ) {
var label = jQuery.text( this ),
initial = initialHeight[ i ],
height = jQuery( this ).height(),
upper = initial * progress * tolerance;
ok( height < upper, "show " + label + ": upper bound; " +
height + " < " + upper + " @ " + ( progress * 100 ) + "%" );
- });
+ } );
animated.stop( true, true );
}, shortDuration );
-clock.tick(shortDuration);
+clock.tick( shortDuration );
}, shortDuration );
-clock.tick(shortDuration);
+clock.tick( shortDuration );
}, 50 );
clock.tick( 50 );
-});
+} );
// Start 1.8 Animation tests
test( "jQuery.Animation( object, props, opts )", function() {
@@ -1484,23 +1490,23 @@ test( "jQuery.Animation( object, props, opts )", function() {
"width": 200
};
- animation = jQuery.Animation( testObject, testDest, { "duration": 1 });
- animation.done(function() {
+ animation = jQuery.Animation( testObject, testDest, { "duration": 1 } );
+ animation.done( function() {
for ( var prop in testDest ) {
equal( testObject[ prop ], testDest[ prop ], "Animated: " + prop );
}
- animation.done(function() {
+ animation.done( function() {
deepEqual( testObject, testDest, "No unexpected properties" );
- });
- });
+ } );
+ } );
this.clock.tick( 10 );
-});
+} );
test( "Animate Option: step: function( percent, tween )", function() {
expect( 1 );
var counter = {};
- jQuery( "#foo" ).animate({
+ jQuery( "#foo" ).animate( {
prop1: 1,
prop2: 2,
prop3: 3
@@ -1508,37 +1514,38 @@ test( "Animate Option: step: function( percent, tween )", function() {
duration: 1,
step: function( value, tween ) {
var calls = counter[ tween.prop ] = counter[ tween.prop ] || [];
+
// in case this is called multiple times for either, lets store it in
// 0 or 1 in the array
calls[ value === 0 ? 0 : 1 ] = value;
}
- }).queue( function( next ) {
+ } ).queue( function( next ) {
deepEqual( counter, {
- prop1: [0, 1],
- prop2: [0, 2],
- prop3: [0, 3]
- }, "Step function was called once at 0% and once at 100% for each property");
+ prop1: [ 0, 1 ],
+ prop2: [ 0, 2 ],
+ prop3: [ 0, 3 ]
+ }, "Step function was called once at 0% and once at 100% for each property" );
next();
- });
+ } );
this.clock.tick( 10 );
-});
+} );
test( "Animate callbacks have correct context", function() {
expect( 2 );
var foo = jQuery( "#foo" );
- foo.animate({
+ foo.animate( {
height: 10
}, 10, function() {
equal( foo[ 0 ], this, "Complete callback after stop(true) `this` is element" );
- }).stop( true, true );
- foo.animate({
+ } ).stop( true, true );
+ foo.animate( {
height: 100
}, 10, function() {
equal( foo[ 0 ], this, "Complete callback `this` is element" );
- });
+ } );
this.clock.tick( 10 );
-});
+} );
test( "User supplied callback called after show when fx off (#8892)", function() {
expect( 2 );
@@ -1551,10 +1558,10 @@ test( "User supplied callback called after show when fx off (#8892)", function()
foo.fadeOut( 500, function() {
ok( jQuery( this ).is( ":hidden" ), "Element is hidden in callback" );
jQuery.fx.off = false;
- });
- });
+ } );
+ } );
this.clock.tick( 1000 );
-});
+} );
test( "animate should set display for disconnected nodes", function() {
expect( 20 );
@@ -1566,18 +1573,18 @@ test( "animate should set display for disconnected nodes", function() {
fadeTo: [ "fast", 0.5 ],
slideDown: [ "fast" ],
show: [ 1 ],
- animate: [{ width: "show" }]
+ animate: [ { width: "show" } ]
},
- $divEmpty = jQuery(" "),
- $divTest = jQuery(" test "),
- $divNone = jQuery(" "),
- $divInline = jQuery(" "),
- nullParentDisplay = $divEmpty.css("display"),
- underFragmentDisplay = $divTest.css("display"),
+ $divEmpty = jQuery( " " ),
+ $divTest = jQuery( " test " ),
+ $divNone = jQuery( " " ),
+ $divInline = jQuery( " " ),
+ nullParentDisplay = $divEmpty.css( "display" ),
+ underFragmentDisplay = $divTest.css( "display" ),
clock = this.clock;
strictEqual( $divEmpty[ 0 ].parentNode, null, "Setup: element with null parentNode" );
- strictEqual( ($divTest[ 0 ].parentNode || {}).nodeType, 11, "Setup: element under fragment" );
+ strictEqual( ( $divTest[ 0 ].parentNode || {} ).nodeType, 11, "Setup: element under fragment" );
strictEqual( $divEmpty.show()[ 0 ].style.display, "",
"set display with show() for element with null parentNode" );
@@ -1589,54 +1596,54 @@ test( "animate should set display for disconnected nodes", function() {
"show() should not change display if it already set" );
jQuery.each( methods, function( name, opt ) {
- jQuery.fn[ name ].apply( jQuery(" "), opt.concat( [ function() {
+ jQuery.fn[ name ].apply( jQuery( " " ), opt.concat( [ function() {
strictEqual( jQuery( this ).css( "display" ), nullParentDisplay,
"." + name + " block with null parentNode" );
} ] ) );
- jQuery.fn[ name ].apply( jQuery(" test "), opt.concat( [ function() {
+ jQuery.fn[ name ].apply( jQuery( " test " ), opt.concat( [ function() {
strictEqual( jQuery( this ).css( "display" ), underFragmentDisplay,
"." + name + " block under fragment" );
} ] ) );
- });
+ } );
clock.tick( 400 );
-});
+} );
-test("Animation callback should not show animated element as :animated (#7157)", function() {
+test( "Animation callback should not show animated element as :animated (#7157)", function() {
expect( 1 );
var foo = jQuery( "#foo" );
- foo.animate({
+ foo.animate( {
opacity: 0
}, 100, function() {
- ok( !foo.is(":animated"), "The element is not animated" );
- });
+ ok( !foo.is( ":animated" ), "The element is not animated" );
+ } );
this.clock.tick( 100 );
-});
+} );
-test("Initial step callback should show element as :animated (#14623)", function() {
+test( "Initial step callback should show element as :animated (#14623)", function() {
expect( 1 );
var foo = jQuery( "#foo" );
- foo.animate({
+ foo.animate( {
opacity: 0
}, {
duration: 100,
step: function() {
- ok( foo.is(":animated"), "The element matches :animated inside step function" );
+ ok( foo.is( ":animated" ), "The element matches :animated inside step function" );
}
- });
+ } );
this.clock.tick( 1 );
foo.stop();
-});
+} );
test( "hide called on element within hidden parent should set display to none (#10045)", function() {
expect( 3 );
- var hidden = jQuery(".hidden"),
- elems = jQuery(" hide hide0 hide1 ");
+ var hidden = jQuery( ".hidden" ),
+ elems = jQuery( " hide hide0 hide1 " );
hidden.append( elems );
@@ -1644,25 +1651,25 @@ test( "hide called on element within hidden parent should set display to none (#
elems.eq( 0 ).hide(),
elems.eq( 1 ).hide( 0 ),
elems.eq( 2 ).hide( 1 )
- ).done(function() {
+ ).done( function() {
strictEqual( elems.get( 0 ).style.display, "none", "hide() called on element within hidden parent should set display to none" );
strictEqual( elems.get( 1 ).style.display, "none", "hide( 0 ) called on element within hidden parent should set display to none" );
strictEqual( elems.get( 2 ).style.display, "none", "hide( 1 ) called on element within hidden parent should set display to none" );
elems.remove();
- });
+ } );
this.clock.tick( 10 );
-});
+} );
test( "hide, fadeOut and slideUp called on element width height and width = 0 should set display to none", function() {
expect( 5 );
- var foo = jQuery("#foo"),
+ var foo = jQuery( "#foo" ),
i = 0,
elems = jQuery();
for ( ; i < 5; i++ ) {
- elems = elems.add(" ");
+ elems = elems.add( " " );
}
foo.append( elems );
@@ -1673,7 +1680,7 @@ test( "hide, fadeOut and slideUp called on element width height and width = 0 sh
elems.eq( 2 ).hide( 1 ),
elems.eq( 3 ).fadeOut(),
elems.eq( 4 ).slideUp()
- ).done(function() {
+ ).done( function() {
strictEqual( elems.get( 0 ).style.display, "none", "hide() called on element width height and width = 0 should set display to none" );
strictEqual( elems.get( 1 ).style.display, "none",
"hide( jQuery.noop ) called on element width height and width = 0 should set display to none" );
@@ -1681,24 +1688,24 @@ test( "hide, fadeOut and slideUp called on element width height and width = 0 sh
strictEqual( elems.get( 3 ).style.display, "none", "fadeOut() called on element width height and width = 0 should set display to none" );
strictEqual( elems.get( 4 ).style.display, "none", "slideUp() called on element width height and width = 0 should set display to none" );
- });
+ } );
this.clock.tick( 400 );
-});
+} );
test( "hide should not leave hidden inline elements visible (#14848)", function() {
expect( 2 );
- var el = jQuery("#simon1");
+ var el = jQuery( "#simon1" );
el.hide( 1, function() {
equal( el.css( "display" ), "none", "hidden" );
el.hide( 1, function() {
equal( el.css( "display" ), "none", "still hidden" );
- });
- });
+ } );
+ } );
this.clock.tick( 100 );
-});
+} );
test( "Handle queue:false promises", function() {
expect( 10 );
@@ -1706,7 +1713,7 @@ test( "Handle queue:false promises", function() {
var foo = jQuery( "#foo" ).clone().addBack(),
step = 1;
- foo.animate({
+ foo.animate( {
top: 1
}, {
duration: 10,
@@ -1714,7 +1721,7 @@ test( "Handle queue:false promises", function() {
complete: function() {
ok( step++ <= 2, "Step one or two" );
}
- }).animate({
+ } ).animate( {
bottom: 1
}, {
duration: 10,
@@ -1722,13 +1729,13 @@ test( "Handle queue:false promises", function() {
ok( step > 2 && step < 5, "Step three or four" );
step++;
}
- });
+ } );
this.clock.tick( 10 );
foo.promise().done( function() {
equal( step++, 5, "steps 1-5: queue:false then queue:fx done" );
- foo.animate({
+ foo.animate( {
top: 10
}, {
duration: 10,
@@ -1736,7 +1743,7 @@ test( "Handle queue:false promises", function() {
ok( step > 5 && step < 8, "Step six or seven" );
step++;
}
- }).animate({
+ } ).animate( {
bottom: 10
}, {
duration: 10,
@@ -1745,20 +1752,20 @@ test( "Handle queue:false promises", function() {
ok( step > 7 && step < 10, "Step eight or nine" );
step++;
}
- }).promise().done( function() {
+ } ).promise().done( function() {
equal( step++, 10, "steps 6-10: queue:fx then queue:false" );
- });
+ } );
- });
+ } );
this.clock.tick( 10 );
-});
+} );
test( "multiple unqueued and promise", function() {
expect( 4 );
var foo = jQuery( "#foo" ),
step = 1;
- foo.animate({
+ foo.animate( {
marginLeft: 300
}, {
duration: 500,
@@ -1766,7 +1773,7 @@ test( "multiple unqueued and promise", function() {
complete: function() {
strictEqual( step++, 2, "Step 2" );
}
- }).animate({
+ } ).animate( {
top: 100
}, {
duration: 1000,
@@ -1774,54 +1781,55 @@ test( "multiple unqueued and promise", function() {
complete: function() {
strictEqual( step++, 3, "Step 3" );
}
- }).animate({}, {
+ } ).animate( {}, {
duration: 2000,
queue: false,
complete: function() {
+
// no properties is a non-op and finishes immediately
strictEqual( step++, 1, "Step 1" );
}
- }).promise().done( function() {
+ } ).promise().done( function() {
strictEqual( step++, 4, "Step 4" );
- });
+ } );
this.clock.tick( 1000 );
-});
+} );
test( "animate does not change start value for non-px animation (#7109)", function() {
expect( 1 );
- var parent = jQuery( " " ).css({ width: 284, height: 1 }).appendTo( "#qunit-fixture" ),
- child = parent.children().css({ fontSize: "98.6in", width: "0.01em", height: 1 }),
+ var parent = jQuery( " " ).css( { width: 284, height: 1 } ).appendTo( "#qunit-fixture" ),
+ child = parent.children().css( { fontSize: "98.6in", width: "0.01em", height: 1 } ),
actual = parseFloat( child.css( "width" ) ),
computed = [];
- child.animate({ width: "0%" }, {
+ child.animate( { width: "0%" }, {
duration: 1,
step: function() {
computed.push( parseFloat( child.css( "width" ) ) );
}
- }).queue( function( next ) {
+ } ).queue( function( next ) {
var ratio = computed[ 0 ] / actual;
- ok( ratio > 0.9 && ratio < 1.1 , "Starting width was close enough" );
+ ok( ratio > 0.9 && ratio < 1.1, "Starting width was close enough" );
next();
parent.remove();
- });
+ } );
this.clock.tick( 10 );
-});
+} );
test( "non-px animation handles non-numeric start (#11971)", function() {
expect( 2 );
- var foo = jQuery("#foo"),
- initial = foo.css("backgroundPositionX");
+ var foo = jQuery( "#foo" ),
+ initial = foo.css( "backgroundPositionX" );
if ( !initial ) {
- expect(1);
+ expect( 1 );
ok( true, "Style property not understood" );
return;
}
- foo.animate({ backgroundPositionX: "42%" }, {
+ foo.animate( { backgroundPositionX: "42%" }, {
duration: 1,
progress: function( anim, percent ) {
if ( percent ) {
@@ -1837,14 +1845,14 @@ test( "non-px animation handles non-numeric start (#11971)", function() {
done: function() {
equal( jQuery.style( this, "backgroundPositionX" ), "42%", "End reached" );
}
- });
+ } );
this.clock.tick( 10 );
-});
+} );
-test("Animation callbacks (#11797)", function() {
+test( "Animation callbacks (#11797)", function() {
expect( 15 );
- var targets = jQuery("#foo").children(),
+ var targets = jQuery( "#foo" ).children(),
done = false,
expectedProgress = 0;
@@ -1866,12 +1874,12 @@ test("Animation callbacks (#11797)", function() {
ok( true, "empty: always" );
done = true;
}
- });
+ } );
ok( done, "empty: done immediately" );
done = false;
- targets.eq( 1 ).animate({
+ targets.eq( 1 ).animate( {
opacity: 0
}, {
duration: 1,
@@ -1891,11 +1899,11 @@ test("Animation callbacks (#11797)", function() {
ok( true, "stopped: always" );
done = true;
}
- }).stop();
+ } ).stop();
ok( done, "stopped: stopped immediately" );
- targets.eq( 2 ).animate({
+ targets.eq( 2 ).animate( {
opacity: 0
}, {
duration: 1,
@@ -1903,11 +1911,13 @@ test("Animation callbacks (#11797)", function() {
ok( true, "async: start" );
},
progress: function( anim, percent ) {
+
// occasionally the progress handler is called twice in first frame.... *shrug*
if ( percent === 0 && expectedProgress === 1 ) {
return;
}
equal( percent, expectedProgress, "async: progress " + expectedProgress );
+
// once at 0, once at 1
expectedProgress++;
},
@@ -1920,16 +1930,16 @@ test("Animation callbacks (#11797)", function() {
always: function() {
ok( true, "async: always" );
}
- });
+ } );
this.clock.tick( 10 );
-});
+} );
test( "Animate properly sets overflow hidden when animating width/height (#12117)", function() {
expect( 8 );
jQuery.each( [ "height", "width" ], function( _, prop ) {
jQuery.each( [ 100, 0 ], function( _, value ) {
- var div = jQuery(" ").css( "overflow", "auto" ),
+ var div = jQuery( " " ).css( "overflow", "auto" ),
props = {};
props[ prop ] = value;
div.animate( props, 1 );
@@ -1938,24 +1948,24 @@ test( "Animate properly sets overflow hidden when animating width/height (#12117
div.stop();
equal( div.css( "overflow" ), "auto",
"overflow: auto restored after animating " + prop + " to " + value );
- });
- });
-});
+ } );
+ } );
+} );
test( "Each tick of the timer loop uses a fresh time (#12837)", function() {
var lastVal,
- tmp = jQuery({
+ tmp = jQuery( {
test: 0
- });
+ } );
expect( 3 );
- tmp.animate({
+ tmp.animate( {
test: 100
}, {
step: function( p, fx ) {
ok( fx.now !== lastVal, "Current value is not the last value: " + lastVal + " - " + fx.now );
lastVal = fx.now;
}
- });
+ } );
this.clock.tick( 1 );
// now that we have a new time, run another tick
@@ -1965,7 +1975,7 @@ test( "Each tick of the timer loop uses a fresh time (#12837)", function() {
jQuery.fx.tick();
tmp.stop();
-});
+} );
test( "Animations with 0 duration don't ease (#12273)", function() {
expect( 1 );
@@ -1974,7 +1984,7 @@ test( "Animations with 0 duration don't ease (#12273)", function() {
ok( false, "Called easing" );
};
- jQuery( "#foo" ).animate({
+ jQuery( "#foo" ).animate( {
height: 100
}, {
duration: 0,
@@ -1982,12 +1992,13 @@ test( "Animations with 0 duration don't ease (#12273)", function() {
complete: function() {
equal( jQuery( this ).height(), 100, "Height is 100" );
}
- });
+ } );
delete jQuery.easing.test;
-});
+} );
+
+jQuery.map( [ "toggle", "slideToggle", "fadeToggle" ], function( method ) {
-jQuery.map([ "toggle", "slideToggle", "fadeToggle" ], function ( method ) {
// this test would look a lot better if we were using something to override
// the default timers
var duration = 1500;
@@ -1995,7 +2006,7 @@ jQuery.map([ "toggle", "slideToggle", "fadeToggle" ], function ( method ) {
function secondToggle() {
var stopped = parseFloat( element.css( check ) );
tested = false;
- element[ method ]({
+ element[ method ]( {
duration: duration,
step: function( p, fx ) {
if ( fx.pos > 0.1 && fx.prop === check && !tested ) {
@@ -2005,17 +2016,17 @@ jQuery.map([ "toggle", "slideToggle", "fadeToggle" ], function ( method ) {
element.stop();
}
}
- });
+ } );
}
var tested,
original,
check = method === "slideToggle" ? "height" : "opacity",
- element = jQuery("#foo").height( 200 );
+ element = jQuery( "#foo" ).height( 200 );
expect( 4 );
- element[ method ]({
+ element[ method ]( {
duration: duration,
easing: "linear",
step: function( p, fx ) {
@@ -2028,16 +2039,17 @@ jQuery.map([ "toggle", "slideToggle", "fadeToggle" ], function ( method ) {
}
},
always: secondToggle
- });
+ } );
+
//FIXME figure out why 470
this.clock.tick( 470 );
- });
-});
+ } );
+} );
test( "jQuery.fx.start & jQuery.fx.stop hook points", function() {
var oldStart = jQuery.fx.start,
oldStop = jQuery.fx.stop,
- foo = jQuery({ foo: 0 });
+ foo = jQuery( { foo: 0 } );
expect( 3 );
@@ -2049,17 +2061,19 @@ test( "jQuery.fx.start & jQuery.fx.stop hook points", function() {
};
// calls start
- foo.animate({ foo: 1 }, { queue: false });
+ foo.animate( { foo: 1 }, { queue: false } );
+
// calls start
- foo.animate({ foo: 2 }, { queue: false });
+ foo.animate( { foo: 2 }, { queue: false } );
foo.stop();
+
// calls stop
jQuery.fx.tick();
// cleanup
jQuery.fx.start = oldStart;
jQuery.fx.stop = oldStop;
-});
+} );
test( ".finish() completes all queued animations", function() {
var animations = {
@@ -2068,31 +2082,33 @@ test( ".finish() completes all queued animations", function() {
height: 100,
width: 100
},
- div = jQuery(" ");
+ div = jQuery( " " );
expect( 11 );
jQuery.each( animations, function( prop, value ) {
var anim = {};
anim[ prop ] = value;
+
// the delay shouldn't matter at all!
div.css( prop, 1 ).animate( anim, function() {
ok( true, "Called animation callback for " + prop );
- }).delay( 100 );
- });
+ } ).delay( 100 );
+ } );
equal( div.queue().length, 8, "8 animations in the queue" );
div.finish();
jQuery.each( animations, function( prop, value ) {
equal( parseFloat( div.css( prop ) ), value, prop + " finished at correct value" );
- });
+ } );
equal( div.queue().length, 0, "empty queue when done" );
- equal( div.is(":animated"), false, ":animated doesn't match" );
+ equal( div.is( ":animated" ), false, ":animated doesn't match" );
// cleanup
div.remove();
+
// leaves a "shadow timer" which does nothing around, need to force a tick
jQuery.fx.tick();
-});
+} );
test( ".finish( false ) - unqueued animations", function() {
var animations = {
@@ -2101,7 +2117,7 @@ test( ".finish( false ) - unqueued animations", function() {
height: 100,
width: 100
},
- div = jQuery(" ");
+ div = jQuery( " " );
expect( 10 );
@@ -2113,20 +2129,21 @@ test( ".finish( false ) - unqueued animations", function() {
complete: function() {
ok( true, "Called animation callback for " + prop );
}
- });
- });
+ } );
+ } );
equal( div.queue().length, 0, "0 animations in the queue" );
div.finish( false );
jQuery.each( animations, function( prop, value ) {
equal( parseFloat( div.css( prop ) ), value, prop + " finished at correct value" );
- });
- equal( div.is(":animated"), false, ":animated doesn't match" );
+ } );
+ equal( div.is( ":animated" ), false, ":animated doesn't match" );
// cleanup
div.remove();
+
// leaves a "shadow timer" which does nothing around, need to force a tick
jQuery.fx.tick();
-});
+} );
test( ".finish( \"custom\" ) - custom queue animations", function() {
var animations = {
@@ -2135,7 +2152,7 @@ test( ".finish( \"custom\" ) - custom queue animations", function() {
height: 100,
width: 100
},
- div = jQuery(" ");
+ div = jQuery( " " );
expect( 11 );
@@ -2147,30 +2164,32 @@ test( ".finish( \"custom\" ) - custom queue animations", function() {
complete: function() {
ok( true, "Called animation callback for " + prop );
}
- });
- });
+ } );
+ } );
equal( div.queue( "custom" ).length, 4, "4 animations in the queue" );
+
// start the first animation
div.dequeue( "custom" );
- equal( div.is(":animated"), true, ":animated matches" );
+ equal( div.is( ":animated" ), true, ":animated matches" );
div.finish( "custom" );
jQuery.each( animations, function( prop, value ) {
equal( parseFloat( div.css( prop ) ), value, prop + " finished at correct value" );
- });
- equal( div.is(":animated"), false, ":animated doesn't match" );
+ } );
+ equal( div.is( ":animated" ), false, ":animated doesn't match" );
// cleanup
div.remove();
+
// leaves a "shadow timer" which does nothing around, need to force a tick
jQuery.fx.tick();
-});
+} );
test( ".finish() calls finish of custom queue functions", function() {
function queueTester( next, hooks ) {
hooks.stop = function( gotoEnd ) {
inside++;
- equal( this, div[0] );
- ok( gotoEnd, "hooks.stop(true) called");
+ equal( this, div[ 0 ] );
+ ok( gotoEnd, "hooks.stop(true) called" );
};
}
var div = jQuery( " " ),
@@ -2189,15 +2208,15 @@ test( ".finish() calls finish of custom queue functions", function() {
equal( outside, 2, "2 finish callbacks" );
div.remove();
-});
+} );
test( ".finish() is applied correctly when multiple elements were animated (#13937)", function() {
expect( 3 );
- var elems = jQuery(" 012");
+ var elems = jQuery( " 012" );
elems.animate( { opacity: 0 }, 1500 ).animate( { opacity: 1 }, 1500 );
- setTimeout(function() {
+ setTimeout( function() {
elems.eq( 1 ).finish();
ok( !elems.eq( 1 ).queue().length, "empty queue for .finish()ed element" );
ok( elems.eq( 0 ).queue().length, "non-empty queue for preceding element" );
@@ -2206,13 +2225,13 @@ test( ".finish() is applied correctly when multiple elements were animated (#139
}, 100 );
this.clock.tick( 1500 );
-});
+} );
test( "slideDown() after stop() (#13483)", function() {
expect( 2 );
var ul = jQuery( " " )
- .appendTo("#qunit-fixture"),
+ .appendTo( "#qunit-fixture" ),
origHeight = ul.height(),
clock = this.clock;
@@ -2236,10 +2255,10 @@ test( "slideDown() after stop() (#13483)", function() {
ul.remove();
clock.tick( 10 );
- });
+ } );
clock.tick( 10 );
-});
+} );
test( "Respect display value on inline elements (#14824)", function() {
expect( 2 );
@@ -2250,22 +2269,22 @@ test( "Respect display value on inline elements (#14824)", function() {
jQuery( "#qunit-fixture" ).append( fromStyleSheet, fromStyleAttr );
- fromStyleSheet.slideUp(function() {
+ fromStyleSheet.slideUp( function() {
jQuery( this ).slideDown( function() {
equal( jQuery( this ).css( "display" ), "block",
"Respect previous display value (from stylesheet) on span element" );
- });
- });
+ } );
+ } );
fromStyleAttr.slideUp( function() {
jQuery( this ).slideDown( function() {
equal( jQuery( this ).css( "display" ), "block",
"Respect previous display value (from style attribute) on span element" );
- });
- });
+ } );
+ } );
clock.tick( 800 );
-});
+} );
test( "jQuery.easing._default (gh-2218)", function() {
expect( 2 );
@@ -2277,7 +2296,7 @@ test( "jQuery.easing._default (gh-2218)", function() {
equal( anim.opts.easing, jQuery.easing._default,
"anim.opts.easing should be equal to jQuery.easing._default when the easing argument is not given" );
}
- })
+ } )
.animate( { height: "5px" }, {
duration: 5,
easing: "linear",
@@ -2285,11 +2304,11 @@ test( "jQuery.easing._default (gh-2218)", function() {
equal( anim.opts.easing, "linear",
"anim.opts.easing should be equal to the easing argument" );
}
- })
+ } )
.stop();
this.clock.tick( 25 );
-});
+} );
test( "jQuery.easing._default in Animation (gh-2218", function() {
expect( 3 );
@@ -2314,10 +2333,10 @@ test( "jQuery.easing._default in Animation (gh-2218", function() {
"Animation used custom jQuery.easing._default" );
jQuery.easing._default = defaultEasing;
delete jQuery.easing.custom;
- });
+ } );
this.clock.tick( 10 );
-});
+} );
test( "jQuery.easing._default in Tween (gh-2218)", function() {
expect( 3 );
@@ -2341,33 +2360,33 @@ test( "jQuery.easing._default in Tween (gh-2218)", function() {
"Animation used custom jQuery.easing._default" );
jQuery.easing._default = defaultEasing;
delete jQuery.easing.custom;
-});
+} );
test( "Display value is correct for disconnected nodes (trac-13310)", function() {
expect( 3 );
- var div = jQuery(" ");
+ var div = jQuery( " " );
- equal( div.css( "display", "inline" ).hide().show().appendTo("body").css( "display" ), "inline", "Initialized display value has returned" );
+ equal( div.css( "display", "inline" ).hide().show().appendTo( "body" ).css( "display" ), "inline", "Initialized display value has returned" );
div.remove();
div.css( "display", "none" ).hide();
equal( jQuery._data( div[ 0 ], "display" ), undefined, "display data is undefined after hiding a detached and hidden element" );
div.remove();
- div.css( "display", "inline-block" ).hide().appendTo("body").fadeIn(function() {
+ div.css( "display", "inline-block" ).hide().appendTo( "body" ).fadeIn( function() {
equal( div.css( "display" ), "inline-block", "Initialized display value has returned" );
div.remove();
- });
+ } );
this.clock.tick( 1000 );
-});
+} );
test( "Show/hide/toggle and display: inline", function() {
expect( 40 );
var clock = this.clock;
- jQuery( " " ).each(function() {
+ jQuery( " " ).each( function() {
var completed, interrupted,
N = 100,
fixture = jQuery( "#qunit-fixture" ),
@@ -2376,59 +2395,59 @@ test( "Show/hide/toggle and display: inline", function() {
// Animations allowed to complete
completed = jQuery.map( [
- $el.clone().data({ call: "hide", done: "none" }).appendTo( fixture ).hide( N ),
- $el.clone().data({ call: "toggle", done: "none" }).appendTo( fixture ).toggle( N ),
- $el.clone().data({ call: "hide+show", done: "inline" }).appendTo( fixture )
+ $el.clone().data( { call: "hide", done: "none" } ).appendTo( fixture ).hide( N ),
+ $el.clone().data( { call: "toggle", done: "none" } ).appendTo( fixture ).toggle( N ),
+ $el.clone().data( { call: "hide+show", done: "inline" } ).appendTo( fixture )
.hide().show( N ),
- $el.clone().data({ call: "hide+toggle", done: "inline" }).appendTo( fixture )
+ $el.clone().data( { call: "hide+toggle", done: "inline" } ).appendTo( fixture )
.hide().toggle( N )
], function( $clone ) { return $clone[ 0 ]; } );
// Animations not allowed to complete
interrupted = jQuery.map( [
- $el.clone().data({ call: "hide+stop" }).appendTo( fixture ).hide( N ),
- $el.clone().data({ call: "toggle+stop" }).appendTo( fixture ).toggle( N ),
- $el.clone().data({ call: "hide+show+stop" }).appendTo( fixture ).hide().show( N ),
- $el.clone().data({ call: "hide+toggle+stop" }).appendTo( fixture ).hide().toggle( N )
+ $el.clone().data( { call: "hide+stop" } ).appendTo( fixture ).hide( N ),
+ $el.clone().data( { call: "toggle+stop" } ).appendTo( fixture ).toggle( N ),
+ $el.clone().data( { call: "hide+show+stop" } ).appendTo( fixture ).hide().show( N ),
+ $el.clone().data( { call: "hide+toggle+stop" } ).appendTo( fixture ).hide().toggle( N )
], function( $clone ) { return $clone[ 0 ]; } );
// All elements should be inline-block during the animation
clock.tick( N / 2 );
- jQuery( completed ).each(function() {
+ jQuery( completed ).each( function() {
var $el = jQuery( this ),
call = $el.data( "call" );
strictEqual( $el.css( "display" ), "inline-block", kind + " display during " + call );
- });
+ } );
// Interrupted elements should remain inline-block
jQuery( interrupted ).stop();
clock.tick( N / 2 );
- jQuery( interrupted ).each(function() {
+ jQuery( interrupted ).each( function() {
var $el = jQuery( this ),
call = $el.data( "call" );
strictEqual( $el.css( "display" ), "inline-block", kind + " display after " + call );
- });
+ } );
// Completed elements should not remain inline-block
clock.tick( N / 2 );
- jQuery( completed ).each(function() {
+ jQuery( completed ).each( function() {
var $el = jQuery( this ),
call = $el.data( "call" ),
display = $el.data( "done" );
strictEqual( $el.css( "display" ), display, kind + " display after " + call );
- });
+ } );
// A post-animation toggle should not make any element inline-block
completed = jQuery( completed.concat( interrupted ) );
completed.toggle( N / 2 );
clock.tick( N );
- completed.each(function() {
+ completed.each( function() {
var $el = jQuery( this ),
call = $el.data( "call" );
ok( $el.css( "display" ) !== "inline-block",
kind + " display is not inline-block after " + call + "+toggle" );
- });
- });
-});
+ } );
+ } );
+} );
-})();
+} )();
diff --git a/test/unit/event.js b/test/unit/event.js
index d27db447c..91ab5e08b 100644
--- a/test/unit/event.js
+++ b/test/unit/event.js
@@ -3,28 +3,28 @@ module( "event", {
document.body.focus();
},
teardown: moduleTeardown
-});
+} );
-test("on() with non-null,defined data", function() {
+test( "on() with non-null,defined data", function() {
- expect(2);
+ expect( 2 );
var handler = function( event, data ) {
equal( data, 0, "non-null, defined data (zero) is correctly passed" );
};
- jQuery("#foo").on("foo.on", handler);
- jQuery("div").on("foo.delegate", "#foo", handler);
+ jQuery( "#foo" ).on( "foo.on", handler );
+ jQuery( "div" ).on( "foo.delegate", "#foo", handler );
- jQuery("#foo").trigger("foo", 0);
+ jQuery( "#foo" ).trigger( "foo", 0 );
- jQuery("#foo").off("foo.on", handler);
- jQuery("div").off("foo.delegate", "#foo");
+ jQuery( "#foo" ).off( "foo.on", handler );
+ jQuery( "div" ).off( "foo.delegate", "#foo" );
-});
+} );
-test("Handler changes and .trigger() order", function() {
- expect(1);
+test( "Handler changes and .trigger() order", function() {
+ expect( 1 );
var markup = jQuery(
" "
@@ -34,154 +34,154 @@ test("Handler changes and .trigger() order", function() {
markup
.find( "*" ).addBack().on( "click", function() {
path += this.nodeName.toLowerCase() + " ";
- })
+ } )
.filter( "b" ).on( "click", function( e ) {
+
// Removing span should not stop propagation to original parents
if ( e.target === this ) {
- jQuery(this).parent().remove();
+ jQuery( this ).parent().remove();
}
- });
+ } );
markup.find( "b" ).trigger( "click" );
equal( path, "b p div div ", "Delivered all events" );
markup.remove();
-});
+} );
-test("on(), with data", function() {
- expect(4);
+test( "on(), with data", function() {
+ expect( 4 );
var test, handler, handler2;
- handler = function(event) {
+ handler = function( event ) {
ok( event.data, "on() with data, check passed data exists" );
- equal( event.data["foo"], "bar", "on() with data, Check value of passed data" );
+ equal( event.data[ "foo" ], "bar", "on() with data, Check value of passed data" );
};
- jQuery("#firstp").on("click", {"foo": "bar"}, handler).trigger("click").off("click", handler);
+ jQuery( "#firstp" ).on( "click", { "foo": "bar" }, handler ).trigger( "click" ).off( "click", handler );
- ok( !jQuery._data(jQuery("#firstp")[0], "events"), "Event handler unbound when using data." );
+ ok( !jQuery._data( jQuery( "#firstp" )[ 0 ], "events" ), "Event handler unbound when using data." );
- test = function(){};
- handler2 = function(event) {
+ test = function() {};
+ handler2 = function( event ) {
equal( event.data, test, "on() with function data, Check value of passed data" );
};
- jQuery("#firstp").on("click", test, handler2).trigger("click").off("click", handler2);
-});
+ jQuery( "#firstp" ).on( "click", test, handler2 ).trigger( "click" ).off( "click", handler2 );
+} );
-test("click(), with data", function() {
- expect(3);
- var handler = function(event) {
+test( "click(), with data", function() {
+ expect( 3 );
+ var handler = function( event ) {
ok( event.data, "on() with data, check passed data exists" );
- equal( event.data["foo"], "bar", "on() with data, Check value of passed data" );
+ equal( event.data[ "foo" ], "bar", "on() with data, Check value of passed data" );
};
- jQuery("#firstp").on( "click", {"foo": "bar"}, handler).trigger("click").off("click", handler);
+ jQuery( "#firstp" ).on( "click", { "foo": "bar" }, handler ).trigger( "click" ).off( "click", handler );
- ok( !jQuery._data(jQuery("#firstp")[0], "events"), "Event handler unbound when using data." );
-});
+ ok( !jQuery._data( jQuery( "#firstp" )[ 0 ], "events" ), "Event handler unbound when using data." );
+} );
-test("on(), with data, trigger with data", function() {
- expect(4);
- var handler = function(event, data) {
+test( "on(), with data, trigger with data", function() {
+ expect( 4 );
+ var handler = function( event, data ) {
ok( event.data, "check passed data exists" );
equal( event.data.foo, "bar", "Check value of passed data" );
ok( data, "Check trigger data" );
equal( data.bar, "foo", "Check value of trigger data" );
};
- jQuery("#firstp").on("click", {foo: "bar"}, handler).trigger("click", [{bar: "foo"}]).off("click", handler);
-});
+ jQuery( "#firstp" ).on( "click", { foo: "bar" }, handler ).trigger( "click", [ { bar: "foo" } ] ).off( "click", handler );
+} );
-test("on(), multiple events at once", function() {
- expect(2);
+test( "on(), multiple events at once", function() {
+ expect( 2 );
var handler,
clickCounter = 0,
mouseoverCounter = 0;
- handler = function(event) {
- if (event.type === "click") {
+ handler = function( event ) {
+ if ( event.type === "click" ) {
clickCounter += 1;
- }
- else if (event.type === "mouseover") {
+ } else if ( event.type === "mouseover" ) {
mouseoverCounter += 1;
}
};
- jQuery("#firstp").on("click mouseover", handler).trigger("click").trigger("mouseover");
+ jQuery( "#firstp" ).on( "click mouseover", handler ).trigger( "click" ).trigger( "mouseover" );
equal( clickCounter, 1, "on() with multiple events at once" );
equal( mouseoverCounter, 1, "on() with multiple events at once" );
-});
+} );
-test("on(), five events at once", function() {
- expect(1);
+test( "on(), five events at once", function() {
+ expect( 1 );
var count = 0,
handler = function() {
count++;
};
- jQuery("#firstp").on("click mouseover foo bar baz", handler)
- .trigger("click").trigger("mouseover")
- .trigger("foo").trigger("bar")
- .trigger("baz");
+ jQuery( "#firstp" ).on( "click mouseover foo bar baz", handler )
+ .trigger( "click" ).trigger( "mouseover" )
+ .trigger( "foo" ).trigger( "bar" )
+ .trigger( "baz" );
equal( count, 5, "on() five events at once" );
-});
+} );
-test("on(), multiple events at once and namespaces", function() {
- expect(7);
+test( "on(), multiple events at once and namespaces", function() {
+ expect( 7 );
var cur, div,
obj = {};
- div = jQuery(" ").on("focusin.a", function(e) {
+ div = jQuery( " " ).on( "focusin.a", function( e ) {
equal( e.type, cur, "Verify right single event was fired." );
- });
+ } );
cur = "focusin";
- div.trigger("focusin.a");
+ div.trigger( "focusin.a" );
// manually clean up detached elements
div.remove();
- div = jQuery(" ").on("click mouseover", obj, function(e) {
+ div = jQuery( " " ).on( "click mouseover", obj, function( e ) {
equal( e.type, cur, "Verify right multi event was fired." );
equal( e.data, obj, "Make sure the data came in correctly." );
- });
+ } );
cur = "click";
- div.trigger("click");
+ div.trigger( "click" );
cur = "mouseover";
- div.trigger("mouseover");
+ div.trigger( "mouseover" );
// manually clean up detached elements
div.remove();
- div = jQuery(" ").on("focusin.a focusout.b", function(e) {
+ div = jQuery( " " ).on( "focusin.a focusout.b", function( e ) {
equal( e.type, cur, "Verify right multi event was fired." );
- });
+ } );
cur = "focusin";
- div.trigger("focusin.a");
+ div.trigger( "focusin.a" );
cur = "focusout";
- div.trigger("focusout.b");
+ div.trigger( "focusout.b" );
// manually clean up detached elements
div.remove();
-});
+} );
-test("on(), namespace with special add", function() {
- expect(27);
+test( "on(), namespace with special add", function() {
+ expect( 27 );
var i = 0,
- div = jQuery(" ").appendTo("#qunit-fixture").on( "test", function() {
+ div = jQuery( " " ).appendTo( "#qunit-fixture" ).on( "test", function() {
ok( true, "Test event fired." );
- });
+ } );
- jQuery.event.special["test"] = {
+ jQuery.event.special[ "test" ] = {
_default: function( e, data ) {
equal( e.type, "test", "Make sure we're dealing with a test event." );
ok( data, "And that trigger data was passed." );
- strictEqual( e.target, div[0], "And that the target is correct." );
+ strictEqual( e.target, div[ 0 ], "And that the target is correct." );
equal( this, window, "And that the context is correct." );
},
setup: function() {},
@@ -202,13 +202,13 @@ test("on(), namespace with special add", function() {
div.on( "test.a", { x: 1 }, function( e ) {
ok( !!e.xyz, "Make sure that the data is getting passed through." );
- equal( e.data["x"], 1, "Make sure data is attached properly." );
- });
+ equal( e.data[ "x" ], 1, "Make sure data is attached properly." );
+ } );
div.on( "test.b", { x: 2 }, function( e ) {
ok( !!e.xyz, "Make sure that the data is getting passed through." );
- equal( e.data["x"], 2, "Make sure data is attached properly." );
- });
+ equal( e.data[ "x" ], 2, "Make sure data is attached properly." );
+ } );
// Should trigger 5
div.trigger( "test", 33.33 );
@@ -220,61 +220,63 @@ test("on(), namespace with special add", function() {
div.trigger( "test.b", { year: 1982 } );
// Should trigger 4
- div.off("test");
+ div.off( "test" );
- div = jQuery(" ").on( "test", function() {
+ div = jQuery( " " ).on( "test", function() {
ok( true, "Test event fired." );
- });
+ } );
// Should trigger 2
- div.appendTo("#qunit-fixture").remove();
+ div.appendTo( "#qunit-fixture" ).remove();
- delete jQuery.event.special["test"];
-});
+ delete jQuery.event.special[ "test" ];
+} );
-test("on(), no data", function() {
- expect(1);
- var handler = function(event) {
+test( "on(), no data", function() {
+ expect( 1 );
+ var handler = function( event ) {
ok ( !event.data, "Check that no data is added to the event object" );
};
- jQuery("#firstp").on("click", handler).trigger("click");
-});
+ jQuery( "#firstp" ).on( "click", handler ).trigger( "click" );
+} );
-test("on/one/off(Object)", function(){
- expect(6);
+test( "on/one/off(Object)", function() {
+ expect( 6 );
var $elem,
clickCounter = 0,
mouseoverCounter = 0;
- function handler(event) {
- if (event.type === "click") {
+ function handler( event ) {
+ if ( event.type === "click" ) {
clickCounter++;
- } else if (event.type === "mouseover") {
+ } else if ( event.type === "mouseover" ) {
mouseoverCounter++;
}
}
- function handlerWithData(event) {
- if (event.type === "click") {
+ function handlerWithData( event ) {
+ if ( event.type === "click" ) {
clickCounter += event.data;
- } else if (event.type === "mouseover") {
+ } else if ( event.type === "mouseover" ) {
mouseoverCounter += event.data;
}
}
- function trigger(){
- $elem.trigger("click").trigger("mouseover");
+ function trigger() {
+ $elem.trigger( "click" ).trigger( "mouseover" );
}
- $elem = jQuery("#firstp")
+ $elem = jQuery( "#firstp" )
+
// Regular bind
- .on({
+ .on( {
"click":handler,
"mouseover":handler
- })
+ } )
+
// Bind with data
- .one({
+ .one( {
"click":handlerWithData,
"mouseover":handlerWithData
}, 2 );
@@ -288,24 +290,24 @@ test("on/one/off(Object)", function(){
equal( clickCounter, 4, "on(Object)" );
equal( mouseoverCounter, 4, "on(Object)" );
- jQuery("#firstp").off({
+ jQuery( "#firstp" ).off( {
"click":handler,
"mouseover":handler
- });
+ } );
trigger();
equal( clickCounter, 4, "on(Object)" );
equal( mouseoverCounter, 4, "on(Object)" );
-});
+} );
-test("on/off(Object), on/off(Object, String)", function() {
- expect(6);
+test( "on/off(Object), on/off(Object, String)", function() {
+ expect( 6 );
var events,
clickCounter = 0,
mouseoverCounter = 0,
- $p = jQuery("#firstp"),
- $a = $p.find("a").eq(0);
+ $p = jQuery( "#firstp" ),
+ $a = $p.find( "a" ).eq( 0 );
events = {
"click": function( event ) {
@@ -317,7 +319,7 @@ test("on/off(Object), on/off(Object, String)", function() {
};
function trigger() {
- $a.trigger("click").trigger("mouseover");
+ $a.trigger( "click" ).trigger( "mouseover" );
}
jQuery( document ).on( events, "#firstp a" );
@@ -338,73 +340,74 @@ test("on/off(Object), on/off(Object, String)", function() {
trigger();
equal( clickCounter, 4, "off" );
equal( mouseoverCounter, 4, "off" );
-});
+} );
-test("on immediate propagation", function() {
- expect(2);
+test( "on immediate propagation", function() {
+ expect( 2 );
var lastClick,
- $p = jQuery("#firstp"),
- $a = $p.find("a").eq(0);
+ $p = jQuery( "#firstp" ),
+ $a = $p.find( "a" ).eq( 0 );
lastClick = "";
- jQuery( document ).on( "click", "#firstp a", function(e) {
+ jQuery( document ).on( "click", "#firstp a", function( e ) {
lastClick = "click1";
e.stopImmediatePropagation();
- });
+ } );
jQuery( document ).on( "click", "#firstp a", function() {
lastClick = "click2";
- });
+ } );
$a.trigger( "click" );
equal( lastClick, "click1", "on stopImmediatePropagation" );
jQuery( document ).off( "click", "#firstp a" );
lastClick = "";
- $p.on( "click", "a", function(e) {
+ $p.on( "click", "a", function( e ) {
lastClick = "click1";
e.stopImmediatePropagation();
- });
+ } );
$p.on( "click", "a", function() {
lastClick = "click2";
- });
+ } );
$a.trigger( "click" );
equal( lastClick, "click1", "on stopImmediatePropagation" );
$p.off( "click", "**" );
-});
+} );
-test("on bubbling, isDefaultPrevented, stopImmediatePropagation", function() {
+test( "on bubbling, isDefaultPrevented, stopImmediatePropagation", function() {
expect( 3 );
var $anchor2 = jQuery( "#anchor2" ),
$main = jQuery( "#qunit-fixture" ),
neverCallMe = function() {
ok( false, "immediate propagation should have been stopped" );
},
- fakeClick = function($jq) {
+ fakeClick = function( $jq ) {
+
// Use a native click so we don't get jQuery simulated bubbling
if ( document.createEvent ) {
var e = document.createEvent( "MouseEvents" );
e.initEvent( "click", true, true );
- $jq[0].dispatchEvent(e);
- }
- else if ( $jq[0].click ) {
- $jq[0].click(); // IE
+ $jq[ 0 ].dispatchEvent( e );
+ } else if ( $jq[ 0 ].click ) {
+ $jq[ 0 ].click(); // IE
}
};
- $anchor2.on( "click", function(e) {
+ $anchor2.on( "click", function( e ) {
e.preventDefault();
- });
- $main.on("click", "#foo", function(e) {
+ } );
+ $main.on( "click", "#foo", function( e ) {
equal( e.isDefaultPrevented(), true, "isDefaultPrevented true passed to bubbled event" );
- });
+ } );
fakeClick( $anchor2 );
$anchor2.off( "click" );
$main.off( "click", "**" );
$anchor2.on( "click", function() {
+
// Let the default action occur
- });
- $main.on("click", "#foo", function(e) {
+ } );
+ $main.on( "click", "#foo", function( e ) {
equal( e.isDefaultPrevented(), false, "isDefaultPrevented false passed to bubbled event" );
- });
+ } );
fakeClick( $anchor2 );
$anchor2.off( "click" );
$main.off( "click", "**" );
@@ -418,91 +421,91 @@ test("on bubbling, isDefaultPrevented, stopImmediatePropagation", function() {
$anchor2.on( "click", function( e ) {
e.stopImmediatePropagation();
ok( true, "anchor was clicked and prop stopped" );
- });
- $anchor2[0].addEventListener( "click", neverCallMe, false );
+ } );
+ $anchor2[ 0 ].addEventListener( "click", neverCallMe, false );
fakeClick( $anchor2 );
- $anchor2[0].removeEventListener( "click", neverCallMe );
+ $anchor2[ 0 ].removeEventListener( "click", neverCallMe );
}
-});
+} );
-test("on(), iframes", function() {
+test( "on(), iframes", function() {
expect( 1 );
// events don't work with iframes, see #939 - this test fails in IE because of contentDocument
- var doc = jQuery("#loadediframe").contents();
+ var doc = jQuery( "#loadediframe" ).contents();
- jQuery("div", doc).on("click", function() {
+ jQuery( "div", doc ).on( "click", function() {
ok( true, "Binding to element inside iframe" );
- }).trigger("click").off("click");
-});
+ } ).trigger( "click" ).off( "click" );
+} );
-test("on(), trigger change on select", function() {
- expect(5);
+test( "on(), trigger change on select", function() {
+ expect( 5 );
var counter = 0;
- function selectOnChange(event) {
+ function selectOnChange( event ) {
equal( event.data, counter++, "Event.data is not a global event object" );
}
- jQuery("#form select").each(function(i){
- jQuery(this).on("change", i, selectOnChange);
- }).trigger("change");
-});
+ jQuery( "#form select" ).each( function( i ) {
+ jQuery( this ).on( "change", i, selectOnChange );
+ } ).trigger( "change" );
+} );
-test("on(), namespaced events, cloned events", function() {
+test( "on(), namespaced events, cloned events", function() {
expect( 18 );
var firstp = jQuery( "#firstp" );
- firstp.on("custom.test",function(){
- ok(false, "Custom event triggered");
- });
+ firstp.on( "custom.test", function() {
+ ok( false, "Custom event triggered" );
+ } );
- firstp.on("click",function(e){
- ok(true, "Normal click triggered");
+ firstp.on( "click", function( e ) {
+ ok( true, "Normal click triggered" );
equal( e.type + e.namespace, "click", "Check that only click events trigger this fn" );
- });
+ } );
- firstp.on("click.test",function(e){
+ firstp.on( "click.test", function( e ) {
var check = "click";
ok( true, "Namespaced click triggered" );
if ( e.namespace ) {
check += "test";
}
equal( e.type + e.namespace, check, "Check that only click/click.test events trigger this fn" );
- });
+ } );
//clone(true) element to verify events are cloned correctly
firstp = firstp.add( firstp.clone( true ).attr( "id", "firstp2" ).insertBefore( firstp ) );
// Trigger both bound fn (8)
- firstp.trigger("click");
+ firstp.trigger( "click" );
// Trigger one bound fn (4)
- firstp.trigger("click.test");
+ firstp.trigger( "click.test" );
// Remove only the one fn
- firstp.off("click.test");
+ firstp.off( "click.test" );
// Trigger the remaining fn (4)
- firstp.trigger("click");
+ firstp.trigger( "click" );
// Remove the remaining namespaced fn
- firstp.off(".test");
+ firstp.off( ".test" );
// Try triggering the custom event (0)
- firstp.trigger("custom");
+ firstp.trigger( "custom" );
// using contents will get comments regular, text, and comment nodes
- jQuery("#nonnodes").contents().on("tester", function () {
- equal(this.nodeType, 1, "Check node,textnode,comment on just does real nodes" );
- }).trigger("tester");
+ jQuery( "#nonnodes" ).contents().on( "tester", function() {
+ equal( this.nodeType, 1, "Check node,textnode,comment on just does real nodes" );
+ } ).trigger( "tester" );
// Make sure events stick with appendTo'd elements (which are cloned) #2027
- jQuery(" test").on( "click", function(){ return false; }).appendTo("#qunit-fixture");
- ok( jQuery("a.test").eq(0).triggerHandler("click") === false, "Handler is bound to appendTo'd elements" );
-});
+ jQuery( " test" ).on( "click", function() { return false; } ).appendTo( "#qunit-fixture" );
+ ok( jQuery( "a.test" ).eq( 0 ).triggerHandler( "click" ) === false, "Handler is bound to appendTo'd elements" );
+} );
-test("on(), multi-namespaced events", function() {
- expect(6);
+test( "on(), multi-namespaced events", function() {
+ expect( 6 );
var order = [
"click.test.abc",
@@ -513,120 +516,120 @@ test("on(), multi-namespaced events", function() {
"custom.test2"
];
- function check(name, msg){
+ function check( name, msg ) {
deepEqual( name, order.shift(), msg );
}
- jQuery("#firstp").on("custom.test",function() {
- check("custom.test", "Custom event triggered");
- });
+ jQuery( "#firstp" ).on( "custom.test", function() {
+ check( "custom.test", "Custom event triggered" );
+ } );
- jQuery("#firstp").on("custom.test2",function() {
- check("custom.test2", "Custom event triggered");
- });
+ jQuery( "#firstp" ).on( "custom.test2", function() {
+ check( "custom.test2", "Custom event triggered" );
+ } );
- jQuery("#firstp").on("click.test",function() {
- check("click.test", "Normal click triggered");
- });
+ jQuery( "#firstp" ).on( "click.test", function() {
+ check( "click.test", "Normal click triggered" );
+ } );
- jQuery("#firstp").on("click.test.abc",function() {
- check("click.test.abc", "Namespaced click triggered");
- });
+ jQuery( "#firstp" ).on( "click.test.abc", function() {
+ check( "click.test.abc", "Namespaced click triggered" );
+ } );
// Those would not trigger/off (#5303)
- jQuery("#firstp").trigger("click.a.test");
- jQuery("#firstp").off("click.a.test");
+ jQuery( "#firstp" ).trigger( "click.a.test" );
+ jQuery( "#firstp" ).off( "click.a.test" );
// Trigger both bound fn (1)
- jQuery("#firstp").trigger("click.test.abc");
+ jQuery( "#firstp" ).trigger( "click.test.abc" );
// Trigger one bound fn (1)
- jQuery("#firstp").trigger("click.abc");
+ jQuery( "#firstp" ).trigger( "click.abc" );
// Trigger two bound fn (2)
- jQuery("#firstp").trigger("click.test");
+ jQuery( "#firstp" ).trigger( "click.test" );
// Remove only the one fn
- jQuery("#firstp").off("click.abc");
+ jQuery( "#firstp" ).off( "click.abc" );
// Trigger the remaining fn (1)
- jQuery("#firstp").trigger("click");
+ jQuery( "#firstp" ).trigger( "click" );
// Remove the remaining fn
- jQuery("#firstp").off(".test");
+ jQuery( "#firstp" ).off( ".test" );
// Trigger the remaining fn (1)
- jQuery("#firstp").trigger("custom");
-});
+ jQuery( "#firstp" ).trigger( "custom" );
+} );
-test("namespace-only event binding is a no-op", function(){
- expect(2);
+test( "namespace-only event binding is a no-op", function() {
+ expect( 2 );
- jQuery("#firstp")
+ jQuery( "#firstp" )
.on( ".whoops", function() {
ok( false, "called a namespace-only event" );
- })
+ } )
.on( "whoops", function() {
ok( true, "called whoops" );
- })
- .trigger("whoops") // 1
- .off(".whoops")
- .trigger("whoops") // 2
- .off("whoops");
-});
+ } )
+ .trigger( "whoops" ) // 1
+ .off( ".whoops" )
+ .trigger( "whoops" ) // 2
+ .off( "whoops" );
+} );
-test("Empty namespace is ignored", function(){
+test( "Empty namespace is ignored", function() {
expect( 1 );
- jQuery("#firstp")
+ jQuery( "#firstp" )
.on( "meow.", function( e ) {
equal( e.namespace, "", "triggered a namespace-less meow event" );
- })
- .trigger("meow.")
- .off("meow.");
-});
+ } )
+ .trigger( "meow." )
+ .off( "meow." );
+} );
-test("on(), with same function", function() {
- expect(2);
+test( "on(), with same function", function() {
+ expect( 2 );
- var count = 0, func = function(){
+ var count = 0, func = function() {
count++;
};
- jQuery("#liveHandlerOrder").on("foo.bar", func).on("foo.zar", func);
- jQuery("#liveHandlerOrder").trigger("foo.bar");
+ jQuery( "#liveHandlerOrder" ).on( "foo.bar", func ).on( "foo.zar", func );
+ jQuery( "#liveHandlerOrder" ).trigger( "foo.bar" );
- equal(count, 1, "Verify binding function with multiple namespaces." );
+ equal( count, 1, "Verify binding function with multiple namespaces." );
- jQuery("#liveHandlerOrder").off("foo.bar", func).off("foo.zar", func);
- jQuery("#liveHandlerOrder").trigger("foo.bar");
+ jQuery( "#liveHandlerOrder" ).off( "foo.bar", func ).off( "foo.zar", func );
+ jQuery( "#liveHandlerOrder" ).trigger( "foo.bar" );
- equal(count, 1, "Verify that removing events still work." );
-});
+ equal( count, 1, "Verify that removing events still work." );
+} );
-test("on(), make sure order is maintained", function() {
- expect(1);
+test( "on(), make sure order is maintained", function() {
+ expect( 1 );
- var elem = jQuery("#firstp"), log = [], check = [];
+ var elem = jQuery( "#firstp" ), log = [], check = [];
- jQuery.each( new Array(100), function( i ) {
- elem.on( "click", function(){
+ jQuery.each( new Array( 100 ), function( i ) {
+ elem.on( "click", function() {
log.push( i );
- });
+ } );
check.push( i );
- });
+ } );
- elem.trigger("click");
+ elem.trigger( "click" );
- equal( log.join(","), check.join(","), "Make sure order was maintained." );
+ equal( log.join( "," ), check.join( "," ), "Make sure order was maintained." );
- elem.off("click");
-});
+ elem.off( "click" );
+} );
-test("on(), with different this object", function() {
- expect(4);
+test( "on(), with different this object", function() {
+ expect( 4 );
var thisObject = { myThis: true },
data = { myData: true },
handler1 = function() {
@@ -637,367 +640,369 @@ test("on(), with different this object", function() {
equal( event.data, data, "on() with different this object and data" );
};
- jQuery("#firstp")
- .on("click", jQuery.proxy(handler1, thisObject)).trigger("click").off("click", handler1)
- .on("click", data, jQuery.proxy(handler2, thisObject)).trigger("click").off("click", handler2);
+ jQuery( "#firstp" )
+ .on( "click", jQuery.proxy( handler1, thisObject ) ).trigger( "click" ).off( "click", handler1 )
+ .on( "click", data, jQuery.proxy( handler2, thisObject ) ).trigger( "click" ).off( "click", handler2 );
- ok( !jQuery._data(jQuery("#firstp")[0], "events"), "Event handler unbound when using different this object and data." );
-});
+ ok( !jQuery._data( jQuery( "#firstp" )[ 0 ], "events" ), "Event handler unbound when using different this object and data." );
+} );
-test("on(name, false), off(name, false)", function() {
- expect(3);
+test( "on(name, false), off(name, false)", function() {
+ expect( 3 );
var main = 0;
- jQuery("#qunit-fixture").on("click", function(){ main++; });
- jQuery("#ap").trigger("click");
+ jQuery( "#qunit-fixture" ).on( "click", function() { main++; } );
+ jQuery( "#ap" ).trigger( "click" );
equal( main, 1, "Verify that the trigger happened correctly." );
main = 0;
- jQuery("#ap").on("click", false);
- jQuery("#ap").trigger("click");
+ jQuery( "#ap" ).on( "click", false );
+ jQuery( "#ap" ).trigger( "click" );
equal( main, 0, "Verify that no bubble happened." );
main = 0;
- jQuery("#ap").off("click", false);
- jQuery("#ap").trigger("click");
+ jQuery( "#ap" ).off( "click", false );
+ jQuery( "#ap" ).trigger( "click" );
equal( main, 1, "Verify that the trigger happened correctly." );
// manually clean up events from elements outside the fixture
- jQuery("#qunit-fixture").off("click");
-});
+ jQuery( "#qunit-fixture" ).off( "click" );
+} );
-test("on(name, selector, false), off(name, selector, false)", function() {
- expect(3);
+test( "on(name, selector, false), off(name, selector, false)", function() {
+ expect( 3 );
var main = 0;
- jQuery("#qunit-fixture").on("click", "#ap", function(){ main++; });
- jQuery("#ap").trigger("click");
+ jQuery( "#qunit-fixture" ).on( "click", "#ap", function() { main++; } );
+ jQuery( "#ap" ).trigger( "click" );
equal( main, 1, "Verify that the trigger happened correctly." );
main = 0;
- jQuery("#ap").on("click", "#groups", false);
- jQuery("#groups").trigger("click");
+ jQuery( "#ap" ).on( "click", "#groups", false );
+ jQuery( "#groups" ).trigger( "click" );
equal( main, 0, "Verify that no bubble happened." );
main = 0;
- jQuery("#ap").off("click", "#groups", false);
- jQuery("#groups").trigger("click");
+ jQuery( "#ap" ).off( "click", "#groups", false );
+ jQuery( "#groups" ).trigger( "click" );
equal( main, 1, "Verify that the trigger happened correctly." );
- jQuery("#qunit-fixture").off("click", "#ap");
-});
+ jQuery( "#qunit-fixture" ).off( "click", "#ap" );
+} );
-test("on()/trigger()/off() on plain object", function() {
+test( "on()/trigger()/off() on plain object", function() {
expect( 7 );
var events,
obj = {};
// Make sure it doesn't complain when no events are found
- jQuery(obj).trigger("test");
+ jQuery( obj ).trigger( "test" );
// Make sure it doesn't complain when no events are found
- jQuery(obj).off("test");
+ jQuery( obj ).off( "test" );
- jQuery(obj).on({
+ jQuery( obj ).on( {
"test": function() {
ok( true, "Custom event run." );
},
"submit": function() {
ok( true, "Custom submit event run." );
}
- });
+ } );
- events = jQuery._data(obj, "events");
+ events = jQuery._data( obj, "events" );
ok( events, "Object has events bound." );
- equal( obj["events"], undefined, "Events object on plain objects is not events" );
- equal( obj["test"], undefined, "Make sure that test event is not on the plain object." );
- equal( obj["handle"], undefined, "Make sure that the event handler is not on the plain object." );
+ equal( obj[ "events" ], undefined, "Events object on plain objects is not events" );
+ equal( obj[ "test" ], undefined, "Make sure that test event is not on the plain object." );
+ equal( obj[ "handle" ], undefined, "Make sure that the event handler is not on the plain object." );
// Should trigger 1
- jQuery(obj).trigger("test");
- jQuery(obj).trigger("submit");
+ jQuery( obj ).trigger( "test" );
+ jQuery( obj ).trigger( "submit" );
- jQuery(obj).off("test");
- jQuery(obj).off("submit");
+ jQuery( obj ).off( "test" );
+ jQuery( obj ).off( "submit" );
// Should trigger 0
- jQuery(obj).trigger("test");
+ jQuery( obj ).trigger( "test" );
// Make sure it doesn't complain when no events are found
- jQuery(obj).off("test");
+ jQuery( obj ).off( "test" );
equal( obj && obj[ jQuery.expando ] &&
obj[ jQuery.expando ][ jQuery.expando ] &&
- obj[ jQuery.expando ][ jQuery.expando ]["events"], undefined, "Make sure events object is removed" );
-});
+ obj[ jQuery.expando ][ jQuery.expando ][ "events" ], undefined, "Make sure events object is removed" );
+} );
-test("off(type)", function() {
+test( "off(type)", function() {
expect( 1 );
var message, func,
- $elem = jQuery("#firstp");
+ $elem = jQuery( "#firstp" );
- function error(){
+ function error() {
ok( false, message );
}
message = "unbind passing function";
- $elem.on("error1", error).off("error1", error).triggerHandler("error1");
+ $elem.on( "error1", error ).off( "error1", error ).triggerHandler( "error1" );
message = "unbind all from event";
- $elem.on("error1", error).off("error1").triggerHandler("error1");
+ $elem.on( "error1", error ).off( "error1" ).triggerHandler( "error1" );
message = "unbind all";
- $elem.on("error1", error).off().triggerHandler("error1");
+ $elem.on( "error1", error ).off().triggerHandler( "error1" );
message = "unbind many with function";
- $elem.on("error1 error2",error)
- .off("error1 error2", error )
- .trigger("error1").triggerHandler("error2");
+ $elem.on( "error1 error2", error )
+ .off( "error1 error2", error )
+ .trigger( "error1" ).triggerHandler( "error2" );
message = "unbind many"; // #3538
- $elem.on("error1 error2", error)
- .off("error1 error2")
- .trigger("error1").triggerHandler("error2");
+ $elem.on( "error1 error2", error )
+ .off( "error1 error2" )
+ .trigger( "error1" ).triggerHandler( "error2" );
message = "unbind without a type or handler";
- $elem.on("error1 error2.test",error)
+ $elem.on( "error1 error2.test", error )
.off()
- .trigger("error1").triggerHandler("error2");
+ .trigger( "error1" ).triggerHandler( "error2" );
// Should only unbind the specified function
- jQuery( document ).on( "click", function(){
- ok( true, "called handler after selective removal");
- });
+ jQuery( document ).on( "click", function() {
+ ok( true, "called handler after selective removal" );
+ } );
func = function() {};
jQuery( document )
.on( "click", func )
.off( "click", func )
- .trigger("click")
+ .trigger( "click" )
.off( "click" );
-});
+} );
-test("off(eventObject)", function() {
- expect(4);
+test( "off(eventObject)", function() {
+ expect( 4 );
- var $elem = jQuery("#firstp"),
+ var $elem = jQuery( "#firstp" ),
num;
- function assert( expected ){
+ function assert( expected ) {
num = 0;
- $elem.trigger("foo").triggerHandler("bar");
+ $elem.trigger( "foo" ).triggerHandler( "bar" );
equal( num, expected, "Check the right handlers are triggered" );
}
$elem
+
// This handler shouldn't be unbound
- .on("foo", function(){
+ .on( "foo", function() {
num += 1;
- })
- .on("foo", function(e){
+ } )
+ .on( "foo", function( e ) {
$elem.off( e );
num += 2;
- })
+ } )
+
// Neither this one
- .on("bar", function(){
+ .on( "bar", function() {
num += 4;
- });
+ } );
assert( 7 );
assert( 5 );
- $elem.off("bar");
+ $elem.off( "bar" );
assert( 1 );
$elem.off();
assert( 0 );
-});
+} );
if ( jQuery.fn.hover ) {
- test("hover() mouseenter mouseleave", function() {
- expect(1);
+ test( "hover() mouseenter mouseleave", function() {
+ expect( 1 );
var times = 0,
handler1 = function() { ++times; },
handler2 = function() { ++times; };
- jQuery("#firstp")
- .hover(handler1, handler2)
+ jQuery( "#firstp" )
+ .hover( handler1, handler2 )
.mouseenter().mouseleave()
- .off("mouseenter", handler1)
- .off("mouseleave", handler2)
- .hover(handler1)
+ .off( "mouseenter", handler1 )
+ .off( "mouseleave", handler2 )
+ .hover( handler1 )
.mouseenter().mouseleave()
- .off("mouseenter mouseleave", handler1)
+ .off( "mouseenter mouseleave", handler1 )
.mouseenter().mouseleave();
equal( times, 4, "hover handlers fired" );
- });
+ } );
}
-test("mouseover triggers mouseenter", function() {
- expect(1);
+test( "mouseover triggers mouseenter", function() {
+ expect( 1 );
var count = 0,
- elem = jQuery(" ");
- elem.on( "mouseenter", function () {
+ elem = jQuery( " " );
+ elem.on( "mouseenter", function() {
count++;
- });
- elem.trigger("mouseover");
- equal(count, 1, "make sure mouseover triggers a mouseenter" );
+ } );
+ elem.trigger( "mouseover" );
+ equal( count, 1, "make sure mouseover triggers a mouseenter" );
elem.remove();
-});
+} );
-test("pointerover triggers pointerenter", function() {
- expect(1);
+test( "pointerover triggers pointerenter", function() {
+ expect( 1 );
var count = 0,
- elem = jQuery(" ");
- elem.on( "pointerenter", function () {
+ elem = jQuery( " " );
+ elem.on( "pointerenter", function() {
count++;
- });
- elem.trigger("pointerover");
- equal(count, 1, "make sure pointerover triggers a pointerenter" );
+ } );
+ elem.trigger( "pointerover" );
+ equal( count, 1, "make sure pointerover triggers a pointerenter" );
elem.remove();
-});
+} );
-test("withinElement implemented with jQuery.contains()", function() {
+test( "withinElement implemented with jQuery.contains()", function() {
- expect(1);
+ expect( 1 );
- jQuery("#qunit-fixture").append(" ");
+ jQuery( "#qunit-fixture" ).append( " " );
- jQuery("#jc-outer").on("mouseenter mouseleave", function( event ) {
+ jQuery( "#jc-outer" ).on( "mouseenter mouseleave", function( event ) {
equal( this.id, "jc-outer", this.id + " " + event.type );
- }).trigger("mouseenter");
+ } ).trigger( "mouseenter" );
- jQuery("#jc-inner").trigger("mousenter");
+ jQuery( "#jc-inner" ).trigger( "mousenter" );
- jQuery("#jc-outer").off("mouseenter mouseleave").remove();
- jQuery("#jc-inner").remove();
+ jQuery( "#jc-outer" ).off( "mouseenter mouseleave" ).remove();
+ jQuery( "#jc-inner" ).remove();
-});
+} );
-test("mouseenter, mouseleave don't catch exceptions", function() {
- expect(2);
+test( "mouseenter, mouseleave don't catch exceptions", function() {
+ expect( 2 );
- var elem = jQuery("#firstp").on( "mouseenter mouseleave", function() {
+ var elem = jQuery( "#firstp" ).on( "mouseenter mouseleave", function() {
throw "an Exception";
- });
+ } );
try {
- elem.trigger("mouseenter");
- } catch (e) {
+ elem.trigger( "mouseenter" );
+ } catch ( e ) {
equal( e, "an Exception", "mouseenter doesn't catch exceptions" );
}
try {
- elem.trigger("mouseleave");
- } catch (e) {
+ elem.trigger( "mouseleave" );
+ } catch ( e ) {
equal( e, "an Exception", "mouseleave doesn't catch exceptions" );
}
-});
+} );
if ( jQuery.fn.click ) {
- test("trigger() shortcuts", function() {
- expect(5);
+ test( "trigger() shortcuts", function() {
+ expect( 5 );
var counter, clickCounter,
- elem = jQuery(" Change location").prependTo("#firstUL");
- elem.find("a").on("click", function() {
- var close = jQuery("spanx", this); // same with jQuery(this).find("span");
+ elem = jQuery( " Change location" ).prependTo( "#firstUL" );
+ elem.find( "a" ).on( "click", function() {
+ var close = jQuery( "spanx", this ); // same with jQuery(this).find("span");
equal( 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;
- }).click();
+ } ).click();
// manually clean up detached elements
elem.remove();
- jQuery("#check1").click(function() {
+ jQuery( "#check1" ).click( function() {
ok( true, "click event handler for checkbox gets fired twice, see #815" );
- }).click();
+ } ).click();
counter = 0;
- jQuery("#firstp")[0].onclick = function() {
+ jQuery( "#firstp" )[ 0 ].onclick = function() {
counter++;
};
- jQuery("#firstp").click();
+ jQuery( "#firstp" ).click();
equal( counter, 1, "Check that click, triggers onclick event handler also" );
clickCounter = 0;
- jQuery("#simon1")[0].onclick = function() {
+ jQuery( "#simon1" )[ 0 ].onclick = function() {
clickCounter++;
};
- jQuery("#simon1").click();
+ jQuery( "#simon1" ).click();
equal( clickCounter, 1, "Check that click, triggers onclick event handler on an a tag also" );
// test that special handlers do not blow up with VML elements (#7071)
- jQuery(" ").appendTo("head");
- jQuery(" ").appendTo("#form");
- jQuery("#oval").click().keydown();
- });
+ jQuery( " " ).appendTo( "head" );
+ jQuery( " " ).appendTo( "#form" );
+ jQuery( "#oval" ).click().keydown();
+ } );
}
-test("trigger() bubbling", function() {
- expect(18);
+test( "trigger() bubbling", function() {
+ expect( 18 );
var win = 0, doc = 0, html = 0, body = 0, main = 0, ap = 0;
- jQuery(window).on("click", function(){ win++; });
- jQuery(document).on("click", function( e ){ if ( e.target !== document) { doc++; } });
- jQuery("html").on("click", function(){ html++; });
- jQuery("body").on("click", function(){ body++; });
- jQuery("#qunit-fixture").on("click", function(){ main++; });
- jQuery("#ap").on("click", function(){ ap++; return false; });
+ jQuery( window ).on( "click", function() { win++; } );
+ jQuery( document ).on( "click", function( e ) { if ( e.target !== document ) { doc++; } } );
+ jQuery( "html" ).on( "click", function() { html++; } );
+ jQuery( "body" ).on( "click", function() { body++; } );
+ jQuery( "#qunit-fixture" ).on( "click", function() { main++; } );
+ jQuery( "#ap" ).on( "click", function() { ap++; return false; } );
- jQuery("html").trigger("click");
+ jQuery( "html" ).trigger( "click" );
equal( win, 1, "HTML bubble" );
equal( doc, 1, "HTML bubble" );
equal( html, 1, "HTML bubble" );
- jQuery("body").trigger("click");
+ jQuery( "body" ).trigger( "click" );
equal( win, 2, "Body bubble" );
equal( doc, 2, "Body bubble" );
equal( html, 2, "Body bubble" );
equal( body, 1, "Body bubble" );
- jQuery("#qunit-fixture").trigger("click");
+ jQuery( "#qunit-fixture" ).trigger( "click" );
equal( win, 3, "Main bubble" );
equal( doc, 3, "Main bubble" );
equal( html, 3, "Main bubble" );
equal( body, 2, "Main bubble" );
equal( main, 1, "Main bubble" );
- jQuery("#ap").trigger("click");
+ jQuery( "#ap" ).trigger( "click" );
equal( doc, 3, "ap bubble" );
equal( html, 3, "ap bubble" );
equal( body, 2, "ap bubble" );
equal( main, 1, "ap bubble" );
equal( ap, 1, "ap bubble" );
- jQuery( document ).trigger("click");
+ jQuery( document ).trigger( "click" );
equal( win, 4, "doc bubble" );
// manually clean up events from elements outside the fixture
- jQuery(window).off("click");
- jQuery(document).off("click");
- jQuery("html, body, #qunit-fixture").off("click");
-});
+ jQuery( window ).off( "click" );
+ jQuery( document ).off( "click" );
+ jQuery( "html, body, #qunit-fixture" ).off( "click" );
+} );
-test("trigger(type, [data], [fn])", function() {
- expect(16);
+test( "trigger(type, [data], [fn])", function() {
+ expect( 16 );
var $elem, pass, form, elem2,
- handler = function(event, a, b, c) {
+ handler = function( event, a, b, c ) {
equal( event.type, "click", "check passed data" );
equal( a, 1, "check passed data" );
equal( b, "2", "check passed data" );
@@ -1005,92 +1010,91 @@ test("trigger(type, [data], [fn])", function() {
return "test";
};
- $elem = jQuery("#firstp");
+ $elem = jQuery( "#firstp" );
// Simulate a "native" click
- $elem[0].click = function(){
+ $elem[ 0 ].click = function() {
ok( true, "Native call was triggered" );
};
-
- jQuery( document ).on("mouseenter", "#firstp", function(){
+ jQuery( document ).on( "mouseenter", "#firstp", function() {
ok( true, "Trigger mouseenter bound by on" );
- });
+ } );
- jQuery( document ).on("mouseleave", "#firstp", function(){
+ jQuery( document ).on( "mouseleave", "#firstp", function() {
ok( true, "Trigger mouseleave bound by on" );
- });
+ } );
- $elem.trigger("mouseenter");
+ $elem.trigger( "mouseenter" );
- $elem.trigger("mouseleave");
+ $elem.trigger( "mouseleave" );
- jQuery( document ).off( "mouseenter mouseleave", "#firstp");
+ jQuery( document ).off( "mouseenter mouseleave", "#firstp" );
// Triggers handlers and native
// Trigger 5
- $elem.on("click", handler).trigger("click", [1, "2", "abc"]);
+ $elem.on( "click", handler ).trigger( "click", [ 1, "2", "abc" ] );
// Simulate a "native" click
- $elem[0].click = function(){
+ $elem[ 0 ].click = function() {
ok( false, "Native call was triggered" );
};
// Trigger only the handlers (no native)
// Triggers 5
- equal( $elem.triggerHandler("click", [1, "2", "abc"]), "test", "Verify handler response" );
+ equal( $elem.triggerHandler( "click", [ 1, "2", "abc" ] ), "test", "Verify handler response" );
pass = true;
try {
- elem2 = jQuery("#form input").eq(0);
- elem2.get(0).style.display = "none";
- elem2.trigger("focus");
- } catch( e ) {
+ elem2 = jQuery( "#form input" ).eq( 0 );
+ elem2.get( 0 ).style.display = "none";
+ elem2.trigger( "focus" );
+ } catch ( e ) {
pass = false;
}
ok( pass, "Trigger focus on hidden element" );
pass = true;
try {
- jQuery("#qunit-fixture table").eq(0).on("test:test", function(){}).trigger("test:test");
+ jQuery( "#qunit-fixture table" ).eq( 0 ).on( "test:test", function() {} ).trigger( "test:test" );
} catch ( e ) {
pass = false;
}
ok( pass, "Trigger on a table with a colon in the even type, see #3533" );
- form = jQuery(" ").appendTo("body");
+ form = jQuery( " " ).appendTo( "body" );
// Make sure it can be prevented locally
- form.on( "submit", function(){
+ form.on( "submit", function() {
ok( true, "Local `on` still works." );
return false;
- });
+ } );
// Trigger 1
- form.trigger("submit");
+ form.trigger( "submit" );
- form.off("submit");
+ form.off( "submit" );
- jQuery(document).on( "submit", function(){
+ jQuery( document ).on( "submit", function() {
ok( true, "Make sure bubble works up to document." );
return false;
- });
+ } );
// Trigger 1
- form.trigger("submit");
+ form.trigger( "submit" );
- jQuery(document).off("submit");
+ jQuery( document ).off( "submit" );
form.remove();
-});
+} );
test( "submit event bubbles on copied forms (#11649)", function() {
expect( 3 );
var $formByClone, $formByHTML,
- $testForm = jQuery("#testForm"),
- $fixture = jQuery("#qunit-fixture"),
- $wrapperDiv = jQuery(" ").appendTo( $fixture );
+ $testForm = jQuery( "#testForm" ),
+ $fixture = jQuery( "#qunit-fixture" ),
+ $wrapperDiv = jQuery( " " ).appendTo( $fixture );
function noSubmit( e ) {
e.preventDefault();
@@ -1104,29 +1108,29 @@ test( "submit event bubbles on copied forms (#11649)", function() {
$fixture.on( "submit", "form", delegatedSubmit );
// Trigger form submission to introduce the _submit_attached property
- $testForm.on( "submit", noSubmit ).find("input[name=sub1]").trigger("click");
+ $testForm.on( "submit", noSubmit ).find( "input[name=sub1]" ).trigger( "click" );
// Copy the form via .clone() and .html()
- $formByClone = $testForm.clone( true, true ).removeAttr("id");
- $formByHTML = jQuery( jQuery.parseHTML($fixture.html()) ).filter("#testForm").removeAttr("id");
+ $formByClone = $testForm.clone( true, true ).removeAttr( "id" );
+ $formByHTML = jQuery( jQuery.parseHTML( $fixture.html() ) ).filter( "#testForm" ).removeAttr( "id" );
$wrapperDiv.append( $formByClone, $formByHTML );
// Check submit bubbling on the copied forms
- $wrapperDiv.find("form").on( "submit", noSubmit ).find("input[name=sub1]").trigger("click");
+ $wrapperDiv.find( "form" ).on( "submit", noSubmit ).find( "input[name=sub1]" ).trigger( "click" );
// Clean up
$wrapperDiv.remove();
$fixture.off( "submit", "form", delegatedSubmit );
$testForm.off( "submit", noSubmit );
-});
+} );
-test( "change event bubbles on copied forms (#11796)", function(){
+test( "change event bubbles on copied forms (#11796)", function() {
expect( 3 );
var $formByClone, $formByHTML,
- $form = jQuery("#form"),
- $fixture = jQuery("#qunit-fixture"),
- $wrapperDiv = jQuery(" ").appendTo( $fixture );
+ $form = jQuery( "#form" ),
+ $fixture = jQuery( "#qunit-fixture" ),
+ $wrapperDiv = jQuery( " " ).appendTo( $fixture );
function delegatedChange() {
ok( true, "Make sure change event bubbles up." );
@@ -1137,31 +1141,31 @@ test( "change event bubbles on copied forms (#11796)", function(){
$fixture.on( "change", "form", delegatedChange );
// Trigger change event to introduce the _change_attached property
- $form.find("select[name=select1]").val("1").trigger("change");
+ $form.find( "select[name=select1]" ).val( "1" ).trigger( "change" );
// Copy the form via .clone() and .html()
- $formByClone = $form.clone( true, true ).removeAttr("id");
- $formByHTML = jQuery( jQuery.parseHTML($fixture.html()) ).filter("#form").removeAttr("id");
+ $formByClone = $form.clone( true, true ).removeAttr( "id" );
+ $formByHTML = jQuery( jQuery.parseHTML( $fixture.html() ) ).filter( "#form" ).removeAttr( "id" );
$wrapperDiv.append( $formByClone, $formByHTML );
// Check change bubbling on the copied forms
- $wrapperDiv.find("form select[name=select1]").val("2").trigger("change");
+ $wrapperDiv.find( "form select[name=select1]" ).val( "2" ).trigger( "change" );
// Clean up
$wrapperDiv.remove();
$fixture.off( "change", "form", delegatedChange );
-});
+} );
-test("trigger(eventObject, [data], [fn])", function() {
- expect(28);
+test( "trigger(eventObject, [data], [fn])", function() {
+ expect( 28 );
var event,
- $parent = jQuery(" ").appendTo("body"),
- $child = jQuery(" foo ").appendTo( $parent );
+ $parent = jQuery( " " ).appendTo( "body" ),
+ $child = jQuery( " foo " ).appendTo( $parent );
$parent.get( 0 ).style.display = "none";
- event = jQuery.Event("noNew");
+ event = jQuery.Event( "noNew" );
ok( event !== window, "Instantiate jQuery.Event without the 'new' keyword" );
equal( event.type, "noNew", "Verify its type" );
@@ -1174,40 +1178,41 @@ test("trigger(eventObject, [data], [fn])", function() {
event.stopPropagation();
equal( event.isPropagationStopped(), true, "Verify isPropagationStopped" );
- event.isPropagationStopped = function(){ return false; };
+ event.isPropagationStopped = function() { return false; };
event.stopImmediatePropagation();
equal( event.isPropagationStopped(), true, "Verify isPropagationStopped" );
equal( event.isImmediatePropagationStopped(), true, "Verify isPropagationStopped" );
- $parent.on("foo",function( e ) {
+ $parent.on( "foo", function( e ) {
+
// Tries bubbling
equal( e.type, "foo", "Verify event type when passed passing an event object" );
equal( e.target.id, "child", "Verify event.target when passed passing an event object" );
equal( e.currentTarget.id, "par", "Verify event.currentTarget when passed passing an event object" );
equal( e.secret, "boo!", "Verify event object's custom attribute when passed passing an event object" );
- });
+ } );
// test with an event object
- event = new jQuery.Event("foo");
+ event = new jQuery.Event( "foo" );
event.secret = "boo!";
- $child.trigger(event);
+ $child.trigger( event );
// test with a literal object
- $child.trigger({"type": "foo", "secret": "boo!"});
+ $child.trigger( { "type": "foo", "secret": "boo!" } );
$parent.off();
- function error(){
- ok( false, "This assertion shouldn't be reached");
+ function error() {
+ ok( false, "This assertion shouldn't be reached" );
}
- $parent.on("foo", error );
+ $parent.on( "foo", error );
- $child.on("foo",function(e, a, b, c ){
- equal( arguments.length, 4, "Check arguments length");
- equal( a, 1, "Check first custom argument");
- equal( b, 2, "Check second custom argument");
- equal( c, 3, "Check third custom argument");
+ $child.on( "foo", function( e, a, b, c ) {
+ equal( arguments.length, 4, "Check arguments length" );
+ equal( a, 1, "Check first custom argument" );
+ equal( b, 2, "Check second custom argument" );
+ equal( c, 3, "Check third custom argument" );
equal( e.isDefaultPrevented(), false, "Verify isDefaultPrevented" );
equal( e.isPropagationStopped(), false, "Verify isPropagationStopped" );
@@ -1217,18 +1222,18 @@ test("trigger(eventObject, [data], [fn])", function() {
e.stopImmediatePropagation();
return "result";
- });
+ } );
// We should add this back in when we want to test the order
// in which event handlers are iterated.
//$child.on("foo", error );
- event = new jQuery.Event("foo");
- $child.trigger( event, [1,2,3] ).off();
- equal( event.result, "result", "Check event.result attribute");
+ event = new jQuery.Event( "foo" );
+ $child.trigger( event, [ 1,2,3 ] ).off();
+ equal( event.result, "result", "Check event.result attribute" );
// Will error if it bubbles
- $child.triggerHandler("foo");
+ $child.triggerHandler( "foo" );
$child.off();
$parent.off().remove();
@@ -1239,55 +1244,55 @@ test("trigger(eventObject, [data], [fn])", function() {
equal( event.type, "zowie", "Verify its type" );
equal( event.isPropagationStopped(), false, "propagation not stopped" );
equal( event.isDefaultPrevented(), false, "default not prevented" );
-});
+} );
// Explicitly introduce global variable for oldIE so QUnit doesn't complain if checking globals
window.onclick = undefined;
-test(".trigger() bubbling on disconnected elements (#10489)", function() {
- expect(2);
+test( ".trigger() bubbling on disconnected elements (#10489)", function() {
+ expect( 2 );
- jQuery( window ).on( "click", function(){
+ jQuery( window ).on( "click", function() {
ok( false, "click fired on window" );
- });
+ } );
jQuery( " " )
.on( "click", function() {
ok( true, "click fired on div" );
- })
+ } )
.find( "p" )
.on( "click", function() {
ok( true, "click fired on p" );
- })
- .trigger("click")
+ } )
+ .trigger( "click" )
.off( "click" )
.end()
.off( "click" )
.remove();
jQuery( window ).off( "click" );
-});
+} );
-test(".trigger() doesn't bubble load event (#10717)", function() {
- expect(1);
+test( ".trigger() doesn't bubble load event (#10717)", function() {
+ expect( 1 );
- jQuery( window ).on( "load", function(){
+ jQuery( window ).on( "load", function() {
ok( false, "load fired on window" );
- });
+ } );
// It's not an image, but as long as it fires load...
- jQuery(" ")
+ jQuery( " " )
.appendTo( "body" )
.on( "load", function() {
ok( true, "load fired on img" );
- })
+ } )
.trigger( "load" )
.remove();
jQuery( window ).off( "load" );
-});
+} );
-test("Delegated events in SVG (#10791; #13180)", function() {
- expect(2);
+test( "Delegated events in SVG (#10791; #13180)", function() {
+ expect( 2 );
var useElem, e,
svg = jQuery(
@@ -1299,32 +1304,32 @@ test("Delegated events in SVG (#10791; #13180)", function() {
""
);
- jQuery("#qunit-fixture")
+ jQuery( "#qunit-fixture" )
.append( svg )
.on( "click", "#svg-by-id", function() {
ok( true, "delegated id selector" );
- })
+ } )
.on( "click", "[class~='svg-by-class']", function() {
ok( true, "delegated class selector" );
- })
+ } )
.find( "#svg-by-id, [class~='svg-by-class']" )
- .trigger("click")
+ .trigger( "click" )
.end();
// Fire a native click on an SVGElementInstance (the instance tree of an SVG |