Build: Update jscs and lint files

Fixes gh-2056
This commit is contained in:
Oleg Gaidarenko 2015-08-16 09:59:58 +03:00
parent 7aa46e0df8
commit 10fdad742a
129 changed files with 8640 additions and 7900 deletions

View File

@ -1,6 +1,10 @@
{
"preset": "jquery",
// remove after https://github.com/jscs-dev/node-jscs/issues/1685
// and https://github.com/jscs-dev/node-jscs/issues/1686
"requireCapitalizedComments": null,
"excludeFiles": [ "external", "src/intro.js", "src/outro.js",
"test/node_smoke_tests/lib/ensure_iterability.js" ]
"test/node_smoke_tests/lib/ensure_iterability.js", "node_modules" ]
}

View File

@ -53,6 +53,7 @@ module.exports = function( grunt ) {
"core",
"selector"
],
// Exclude specified modules if the module matching the key is removed
removeWith: {
ajax: [ "manipulation/_evalUrl", "event/ajax" ],
@ -108,7 +109,12 @@ module.exports = function( grunt ) {
gruntfile: "Gruntfile.js",
// Check parts of tests that pass
test: [ "test/data/testrunner.js", "test/unit/animation.js", "test/unit/tween.js" ],
test: [
"test/data/testrunner.js",
"test/unit/animation.js",
"test/unit/tween.js",
"test/unit/wrap.js"
],
release: [ "build/*.js", "!build/release-notes.js" ],
tasks: "build/tasks/*.js"
},
@ -177,7 +183,7 @@ module.exports = function( grunt ) {
grunt.registerTask( "test", [ "test_fast", "promises_aplus_tests" ] );
// Short list as a high frequency watch task
grunt.registerTask( "dev", [ "build:*:*", "lint", "uglify", "remove_map_comment", "dist:*" ] );
grunt.registerTask( "dev", [ "build:*:*", "uglify", "remove_map_comment", "dist:*" ] );
grunt.registerTask( "default", [ "dev", "test_fast", "compare_size" ] );
};

View File

@ -36,6 +36,7 @@ module.exports = function( Release ) {
* for publishing the distribution repo instead
*/
npmTags: function() {
// origRepo is not defined if dist was skipped
Release.dir.repo = Release.dir.origRepo || Release.dir.repo;
return npmTags();

View File

@ -36,6 +36,7 @@ function makeReleaseCopies( Release ) {
releaseFile = cdnFolder + "/" + unpathedFile;
if ( /\.map$/.test( releaseFile ) ) {
// Map files need to reference the new uncompressed name;
// assume that all files reside in the same directory.
// "file":"jquery.min.js","sources":["jquery.js"]

View File

@ -5,6 +5,7 @@ module.exports = function( Release, complete ) {
shell = require( "shelljs" ),
pkg = require( Release.dir.repo + "/package.json" ),
distRemote = Release.remote.replace( "jquery.git", "jquery-dist.git" ),
// These files are included with the distribution
files = [
"src",

View File

@ -34,6 +34,7 @@ function ensureSizzle( Release, callback ) {
version = match ? match[ 1 ] : "Not Found";
if ( version !== latest ) {
// colors is inherited from jquery-release
console.log(
"The Sizzle version in the src folder (" + version.red +

View File

@ -38,7 +38,9 @@ http.request({
console.log( "</ul>" );
}
cur = cat;
console.log( "<h3>" + cat.charAt(0).toUpperCase() + cat.slice(1) + "</h3>" );
console.log(
"<h3>" + cat.charAt( 0 ).toUpperCase() + cat.slice( 1 ) + "</h3>"
);
console.log( "<ul>" );
}

View File

@ -16,12 +16,16 @@ module.exports = function( grunt ) {
baseUrl: "src",
name: "jquery",
out: "dist/jquery.js",
// We have multiple minify steps
optimize: "none",
// Include dependencies loaded with require
findNestedDependencies: true,
// Avoid inserting define() placeholder
skipModuleInsertion: true,
// Avoid breaking semicolons inserted by r.js
skipSemiColonInsertion: true,
wrap: {
@ -47,6 +51,7 @@ module.exports = function( grunt ) {
*/
function convert( name, path, contents ) {
var amdName;
// Convert var modules
if ( /.\/var\//.test( path ) ) {
contents = contents
@ -56,6 +61,7 @@ module.exports = function( grunt ) {
// Sizzle treatment
} else if ( /^sizzle$/.test( name ) ) {
contents = "var Sizzle =\n" + contents
// Remove EXPOSE lines from Sizzle
.replace( /\/\/\s*EXPOSE[\w\W]*\/\/\s*EXPOSE/, "return Sizzle;" );
@ -63,6 +69,7 @@ module.exports = function( grunt ) {
contents = contents
.replace( /\s*return\s+[^\}]+(\}\s*?\);[^\w\}]*)$/, "$1" )
// Multiple exports
.replace( /\s*exports\.\w+\s*=\s*\w+;/g, "" );
@ -82,6 +89,7 @@ module.exports = function( grunt ) {
contents = contents
.replace( /define\(\[[^\]]*\]\)[\W\n]+$/, "" );
}
// AMD Name
if ( ( amdName = grunt.option( "amd" ) ) != null && /^exports\/amd$/.test( name ) ) {
if ( amdName ) {
@ -89,6 +97,7 @@ module.exports = function( grunt ) {
} else {
grunt.log.writeln( "AMD name now anonymous" );
}
// Remove the comma for anonymous defines
contents = contents
.replace( /(\s*)"jquery"(\,\s*)/, amdName ? "$1\"" + amdName + "\"$2" : "" );
@ -122,6 +131,7 @@ module.exports = function( grunt ) {
if ( list ) {
prepend = prepend ? prepend + "/" : "";
list.forEach( function( module ) {
// Exclude var modules as well
if ( module === "var" ) {
excludeList(
@ -130,10 +140,12 @@ module.exports = function( grunt ) {
return;
}
if ( prepend ) {
// Skip if this is not a js file and we're walking files in a dir
if ( !( module = /([\w-\/]+)\.js$/.exec( module ) ) ) {
return;
}
// Prepend folder name if passed
// Remove .js extension
module = prepend + module[ 1 ];
@ -158,12 +170,15 @@ module.exports = function( grunt ) {
module = m[ 2 ];
if ( exclude ) {
// Can't exclude certain modules
if ( minimum.indexOf( module ) === -1 ) {
// Add to excluded
if ( excluded.indexOf( module ) === -1 ) {
grunt.log.writeln( flag );
excluded.push( module );
// Exclude all files in the folder of the same name
// These are the removable dependencies
// It's fine if the directory is not there
@ -173,6 +188,7 @@ module.exports = function( grunt ) {
grunt.verbose.writeln( e );
}
}
// Check removeWith list
excludeList( removeWith[ module ] );
} else {
@ -233,9 +249,11 @@ module.exports = function( grunt ) {
// append excluded modules to version
if ( excluded.length ) {
version += " -" + excluded.join( ",-" );
// set pkg.version to version with excludes, so minified file picks it up
grunt.config.set( "pkg.version", version );
grunt.verbose.writeln( "Version changed to " + version );
// Have to use shallow or core will get excluded since it is a dependency
config.excludeShallow = excluded;
}
@ -247,8 +265,10 @@ module.exports = function( grunt ) {
*/
config.out = function( compiled ) {
compiled = compiled
// Embed Version
.replace( /@VERSION/g, version )
// Embed Date
// yyyy-mm-ddThh:mmZ
.replace( /@DATE/g, ( new Date() ).toISOString().replace( /:\d+\.\d+Z$/, "Z" ) );
@ -259,6 +279,7 @@ module.exports = function( grunt ) {
// Turn off opt-in if necessary
if ( !optIn ) {
// Overwrite the default inclusions with the explicit ones provided
config.rawText.jquery = "define([" +
( included.length ? included.join( "," ) : "" ) +

View File

@ -3,6 +3,7 @@ var fs = require( "fs" );
module.exports = function( grunt ) {
var minLoc = Object.keys( grunt.config( "uglify.all.files" ) )[ 0 ];
grunt.registerTask( "remove_map_comment", function() {
// Remove the source map comment; it causes way too many problems.
// The map file is still generated for manual associations
// https://github.com/jquery/jquery/issues/1707

View File

@ -14,6 +14,7 @@ module.exports = function( grunt ) {
config = grunt.file.readJSON( configFile )[ projectName ];
browserSets = browserSets || config.browserSets;
if ( browserSets[ 0 ] === "[" ) {
// We got an array, parse it
browserSets = JSON.parse( browserSets );
}

View File

@ -32,10 +32,10 @@
"grunt-cli": "0.1.13",
"grunt-compare-size": "0.4.0",
"grunt-contrib-jshint": "0.11.2",
"grunt-contrib-uglify": "0.7.0",
"grunt-contrib-uglify": "0.9.1",
"grunt-contrib-watch": "0.6.1",
"grunt-git-authors": "2.0.1",
"grunt-jscs-checker": "0.8.1",
"grunt-jscs": "2.1.0",
"grunt-jsonlint": "1.0.4",
"grunt-npmcopy": "0.1.0",
"gzip-js": "0.3.2",

View File

@ -15,6 +15,7 @@ var
rhash = /#.*$/,
rts = /([?&])_=[^&]*/,
rheaders = /^(.*?):[ \t]*([^\r\n]*)$/mg,
// #7653, #8125, #8152: local protocol detection
rlocalProtocol = /^(?:about|app|app-storage|.+-extension|file|res|widget):$/,
rnoContent = /^(?:GET|HEAD)$/,
@ -61,8 +62,10 @@ function addToPrefiltersOrTransports( structure ) {
dataTypes = dataTypeExpression.toLowerCase().match( rnotwhite ) || [];
if ( jQuery.isFunction( func ) ) {
// For each dataType in the dataTypeExpression
while ( ( dataType = dataTypes[ i++ ] ) ) {
// Prepend if requested
if ( dataType[ 0 ] === "+" ) {
dataType = dataType.slice( 1 ) || "*";
@ -155,6 +158,7 @@ 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 ] ] ) {
@ -165,6 +169,7 @@ function ajaxHandleResponses( s, jqXHR, responses ) {
firstDataType = type;
}
}
// Or just use first one
finalDataType = finalDataType || firstDataType;
}
@ -186,6 +191,7 @@ function ajaxHandleResponses( s, jqXHR, responses ) {
function ajaxConvert( s, response, jqXHR, isSuccess ) {
var conv2, current, conv, tmp, prev,
converters = {},
// Work with a copy of dataTypes in case we need to modify it for conversion
dataTypes = s.dataTypes.slice();
@ -238,6 +244,7 @@ function ajaxConvert( s, response, jqXHR, isSuccess ) {
conv = converters[ prev + " " + tmp[ 0 ] ] ||
converters[ "* " + tmp[ 0 ] ];
if ( conv ) {
// Condense equivalence converters
if ( conv === true ) {
conv = converters[ conv2 ];
@ -257,7 +264,7 @@ function ajaxConvert( s, response, jqXHR, isSuccess ) {
if ( conv !== true ) {
// Unless errors are allowed to bubble, catch and return them
if ( conv && s[ "throws" ] ) {
if ( conv && s[ "throws" ] ) { // jscs:ignore requireDotNotation
response = conv( response );
} else {
try {
@ -382,40 +389,55 @@ jQuery.extend({
options = options || {};
var transport,
// URL without anti-cache param
cacheURL,
// Response headers
responseHeadersString,
responseHeaders,
// timeout handle
timeoutTimer,
// Url cleanup var
urlAnchor,
// To know if global events are to be dispatched
fireGlobals,
// Loop variable
i,
// 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" ),
// 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,
@ -464,10 +486,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 ] );
}
@ -510,12 +534,14 @@ jQuery.extend({
// IE throws exception if url is malformed, e.g. http://example.com:80x/
try {
urlAnchor.href = s.url;
// Support: IE8-11+
// Anchor's host property isn't correctly set when s.url is relative
urlAnchor.href = urlAnchor.href;
s.crossDomain = originAnchor.protocol + "//" + originAnchor.host !==
urlAnchor.protocol + "//" + urlAnchor.host;
} catch ( e ) {
// If there is an error parsing the URL, assume it is crossDomain,
// it can be rejected by the transport if it is invalid
s.crossDomain = true;
@ -560,6 +586,7 @@ jQuery.extend({
// If data is available, append data to url
if ( s.data ) {
cacheURL = ( s.url += ( rquery.test( cacheURL ) ? "&" : "?" ) + s.data );
// #9682: remove data so that it's not used in an eventual retry
delete s.data;
}
@ -651,9 +678,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;
@ -731,6 +760,7 @@ jQuery.extend({
isSuccess = !error;
}
} else {
// Extract error from statusText and normalize for non-aborts
error = statusText;
if ( status || !statusText ) {
@ -766,6 +796,7 @@ jQuery.extend({
if ( fireGlobals ) {
globalEventContext.trigger( "ajaxComplete", [ jqXHR, s ] );
// Handle the global AJAX counter
if ( !( --jQuery.active ) ) {
jQuery.event.trigger( "ajaxStop" );
@ -787,6 +818,7 @@ jQuery.extend({
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;

View File

@ -53,7 +53,7 @@ jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) {
return responseContainer[ 0 ];
};
// force json dataType
// Force json dataType
s.dataTypes[ 0 ] = "json";
// Install callback
@ -64,6 +64,7 @@ jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) {
// Clean-up function (fires after converters)
jqXHR.always( function() {
// If previous value didn't exist - remove it
if ( overwritten === undefined ) {
jQuery( window ).removeProp( callbackName );
@ -75,10 +76,11 @@ jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) {
// Save back as free
if ( s[ callbackName ] ) {
// make sure that re-using the options doesn't screw things around
// Make sure that re-using the options doesn't screw things around
s.jsonpCallback = originalSettings.jsonpCallback;
// save the callback name for future use
// Save the callback name for future use
oldCallbacks.push( callbackName );
}

View File

@ -33,6 +33,7 @@ jQuery.ajaxPrefilter( "script", function( s ) {
// Bind script tag hack transport
jQuery.ajaxTransport( "script", function( s ) {
// This transport only deals with cross domain requests
if ( s.crossDomain ) {
var script, callback;

View File

@ -11,8 +11,10 @@ jQuery.ajaxSettings.xhr = function() {
};
var xhrSuccessStatus = {
// file protocol always yields status code 0, assume 200
// File protocol always yields status code 0, assume 200
0: 200,
// Support: IE9
// #1450: sometimes IE returns 1223 when it should be 204
1223: 204
@ -76,7 +78,8 @@ jQuery.ajaxTransport(function( options ) {
xhr.abort();
} else if ( type === "error" ) {
complete(
// file: protocol always yields status 0; see #8605, #14207
// File: protocol always yields status 0; see #8605, #14207
xhr.status,
xhr.statusText
);
@ -84,6 +87,7 @@ jQuery.ajaxTransport(function( options ) {
complete(
xhrSuccessStatus[ xhr.status ] || xhr.status,
xhr.statusText,
// Support: IE9
// Accessing binary-data responseText throws an exception
// (#11426)
@ -105,9 +109,11 @@ jQuery.ajaxTransport(function( options ) {
callback = callback( "abort" );
try {
// Do send the request (this may raise an exception)
xhr.send( options.hasContent && options.data || null );
} catch ( e ) {
// #14683: Only rethrow if this hasn't been notified as an error yet
if ( callback ) {
throw e;

View File

@ -111,6 +111,7 @@ jQuery.extend({
boolHook = {
set: function( elem, value, name ) {
if ( value === false ) {
// Remove boolean attributes when set to false
jQuery.removeAttr( elem, name );
} else {
@ -125,6 +126,7 @@ jQuery.each( jQuery.expr.match.bool.source.match( /\w+/g ), function( i, name )
attrHandle[ name ] = function( elem, name, isXML ) {
var ret, handle;
if ( !isXML ) {
// Avoid an infinite loop by temporarily removing this function from the getter
handle = attrHandle[ name ];
attrHandle[ name ] = ret;

View File

@ -25,6 +25,7 @@ jQuery.fn.extend({
}
if ( proceed ) {
// The disjunction here is for better compressibility (see removeClass)
classes = ( value || "" ).match( rnotwhite ) || [];
@ -42,7 +43,7 @@ jQuery.fn.extend({
}
}
// only assign if different to avoid unneeded rendering.
// Only assign if different to avoid unneeded rendering.
finalValue = jQuery.trim( cur );
if ( curValue !== finalValue ) {
elem.setAttribute( "class", finalValue );
@ -79,6 +80,7 @@ jQuery.fn.extend({
if ( cur ) {
j = 0;
while ( ( clazz = classes[ j++ ] ) ) {
// Remove *all* instances
while ( cur.indexOf( " " + clazz + " " ) > -1 ) {
cur = cur.replace( " " + clazz + " ", " " );
@ -138,7 +140,7 @@ jQuery.fn.extend({
className = getClass( this );
if ( className ) {
// store className if set
// Store className if set
dataPriv.set( this, "__className__", className );
}

View File

@ -16,15 +16,20 @@ jQuery.fn.extend({
hooks = jQuery.valHooks[ elem.type ] ||
jQuery.valHooks[ elem.nodeName.toLowerCase() ];
if ( hooks && "get" in hooks && (ret = hooks.get( elem, "value" )) !== undefined ) {
if ( hooks &&
"get" in hooks &&
( ret = hooks.get( elem, "value" ) ) !== undefined
) {
return ret;
}
ret = elem.value;
return typeof ret === "string" ?
// Handle most common string cases
ret.replace( rreturn, "" ) :
// Handle cases where value is null/undef or number
ret == null ? "" : ret;
}
@ -74,6 +79,7 @@ jQuery.extend({
valHooks: {
option: {
get: function( elem ) {
// Support: IE<11
// option.value not trimmed (#14858)
return jQuery.trim( elem.value );
@ -97,6 +103,7 @@ jQuery.extend({
// IE8-9 doesn't update selected after form reset (#2551)
if ( ( option.selected || i === index ) &&
// Don't return options that are disabled or in a disabled optgroup
( support.optDisabled ?
!option.disabled : option.getAttribute( "disabled" ) === null ) &&
@ -127,8 +134,9 @@ jQuery.extend({
while ( i-- ) {
option = options[ i ];
if ( (option.selected =
jQuery.inArray( jQuery.valHooks.option.get( option ), values ) > -1) ) {
if ( option.selected =
jQuery.inArray( jQuery.valHooks.option.get( option ), values ) > -1
) {
optionSet = true;
}
}

View File

@ -44,18 +44,25 @@ jQuery.Callbacks = function( options ) {
var // Flag to know if list is currently firing
firing,
// Last fire value for non-forgettable lists
memory,
// Flag to know if list was already fired
fired,
// Flag to prevent firing
locked,
// Actual callback list
list = [],
// Queue of execution data for repeatable lists
queue = [],
// Index of currently firing callback (modified by add/remove as needed)
firingIndex = -1,
// Fire callbacks
fire = function() {
@ -121,6 +128,7 @@ jQuery.Callbacks = function( options ) {
list.push( arg );
}
} else if ( arg && arg.length && jQuery.type( arg ) !== "string" ) {
// Inspect recursively
add( arg );
}

View File

@ -16,6 +16,7 @@ var
// Define a local copy of jQuery
jQuery = function( selector, context ) {
// The jQuery object is actually just the init constructor 'enhanced'
// Need init if jQuery is called (just allow error to be thrown if not included)
return new jQuery.fn.init( selector, context );
@ -35,6 +36,7 @@ var
};
jQuery.fn = jQuery.prototype = {
// The current version of jQuery being used
jquery: version,
@ -141,8 +143,10 @@ jQuery.extend = jQuery.fn.extend = function() {
}
for ( ; i < length; i++ ) {
// Only deal with non-null/undefined values
if ( ( options = arguments[ i ] ) != null ) {
// Extend the base object
for ( name in options ) {
src = target[ name ];
@ -181,6 +185,7 @@ jQuery.extend = jQuery.fn.extend = function() {
};
jQuery.extend( {
// Unique for each copy of jQuery on the page
expando: "jQuery" + ( version + Math.random() ).replace( /\D/g, "" ),
@ -204,6 +209,7 @@ jQuery.extend({
},
isNumeric: function( obj ) {
// parseFloat NaNs numeric-cast false positives (null|true|false|"")
// ...but misinterprets leading-number strings, particularly hex literals ("0x...")
// subtraction forces infinities to NaN
@ -212,6 +218,7 @@ jQuery.extend({
},
isPlainObject: function( obj ) {
// Not plain objects:
// - Any object or value whose internal [[Class]] property is not "[object Object]"
// - DOM nodes
@ -242,6 +249,7 @@ jQuery.extend({
if ( obj == null ) {
return obj + "";
}
// Support: Android<4.0 (functionish RegExp)
return typeof obj === "object" || typeof obj === "function" ?
class2type[ toString.call( obj ) ] || "object" :

View File

@ -25,6 +25,7 @@ var access = function( elems, fn, key, value, chainable, emptyGet, raw ) {
}
if ( bulk ) {
// Bulk operations run against the entire set
if ( raw ) {
fn.call( elems, value );
@ -41,7 +42,11 @@ var access = function( elems, fn, key, value, chainable, emptyGet, raw ) {
if ( fn ) {
for ( ; i < len; i++ ) {
fn( elems[i], key, raw ? value : value.call( elems[i], i, fn( elems[i], key ) ) );
fn(
elems[ i ], key, raw ?
value :
value.call( elems[ i ], i, fn( elems[ i ], key ) )
);
}
}
}

View File

@ -23,7 +23,7 @@ var rootjQuery,
return this;
}
// init accepts an alternate rootjQuery
// Method init() accepts an alternate rootjQuery
// so migrate can support jQuery.sub (gh-2101)
root = root || rootjQuery;
@ -58,6 +58,7 @@ var rootjQuery,
// HANDLE: $(html, props)
if ( rsingleTag.test( match[ 1 ] ) && jQuery.isPlainObject( context ) ) {
for ( match in context ) {
// Properties of context are called as methods if possible
if ( jQuery.isFunction( this[ match ] ) ) {
this[ match ]( context[ match ] );
@ -76,6 +77,7 @@ var rootjQuery,
elem = document.getElementById( match[ 2 ] );
if ( elem ) {
// Inject the element directly into the jQuery object
this[ 0 ] = elem;
this.length = 1;
@ -104,6 +106,7 @@ var rootjQuery,
} else if ( jQuery.isFunction( selector ) ) {
return root.ready !== undefined ?
root.ready( selector ) :
// Execute immediately if ready is not present
selector( jQuery );
}

View File

@ -8,7 +8,7 @@ define([
"./support"
], function( jQuery, document, rsingleTag, buildFragment, support ) {
// data: string of html
// Argument "data" should be string of html
// context (optional): If specified, the fragment will be created in this context,
// defaults to document
// keepScripts (optional): If true, will include scripts passed in the html string
@ -20,8 +20,9 @@ jQuery.parseHTML = function( data, context, keepScripts ) {
keepScripts = context;
context = false;
}
// document.implementation stops scripts or inline event handlers from
// being executed immediately
// Stop scripts or inline event handlers from being executed immediately
// by using document.implementation
context = context || ( support.createHTMLDocument ?
document.implementation.createHTMLDocument( "" ) :
document );

View File

@ -8,6 +8,7 @@ define([
var readyList;
jQuery.fn.ready = function( fn ) {
// Add the callback
jQuery.ready.promise().done( fn );
@ -15,6 +16,7 @@ jQuery.fn.ready = function( fn ) {
};
jQuery.extend( {
// Is the DOM ready to be used? Set to true once it occurs.
isReady: false,
@ -72,6 +74,7 @@ jQuery.ready.promise = function( obj ) {
// but it caused issues like the one
// discovered by ChrisS here: http://bugs.jquery.com/ticket/12282#comment:15
if ( document.readyState === "complete" ) {
// Handle it asynchronously to allow scripts the opportunity to delay ready
window.setTimeout( jQuery.ready );

View File

@ -1,4 +1,5 @@
define( function() {
// Match a standalone tag
return ( /^<([\w-]+)\s*\/?>(?:<\/\1>|)$/ );
} );

View File

@ -23,6 +23,7 @@ define([
isHidden, getStyles, swap, curCSS, adjustCSS, addGetHookIf, support, showHide ) {
var
// Swappable if display is none or starts with table
// except "table", "table-cell", or "table-caption"
// See here for display values: https://developer.mozilla.org/en-US/docs/CSS/display
@ -61,6 +62,7 @@ function vendorPropName( name ) {
function setPositiveNumber( elem, value, subtract ) {
var matches = rnumsplit.exec( value );
return matches ?
// Guard against undefined "subtract", e.g., when used as in cssHooks
Math.max( 0, matches[ 1 ] - ( subtract || 0 ) ) + ( matches[ 2 ] || "px" ) :
value;
@ -68,20 +70,24 @@ function setPositiveNumber( elem, value, subtract ) {
function augmentWidthOrHeight( elem, name, extra, isBorderBox, styles ) {
var i = extra === ( isBorderBox ? "border" : "content" ) ?
// If we already have the right measurement, avoid augmentation
4 :
// Otherwise initialize for horizontal or vertical properties
name === "width" ? 1 : 0,
val = 0;
for ( ; i < 4; i += 2 ) {
// Both box models exclude margin, so add it if we want it
if ( extra === "margin" ) {
val += jQuery.css( elem, extra + cssExpand[ i ], true, styles );
}
if ( isBorderBox ) {
// border-box includes padding, so remove it if we want content
if ( extra === "content" ) {
val -= jQuery.css( elem, "padding" + cssExpand[ i ], true, styles );
@ -92,6 +98,7 @@ function augmentWidthOrHeight( elem, name, extra, isBorderBox, styles ) {
val -= jQuery.css( elem, "border" + cssExpand[ i ] + "Width", true, styles );
}
} else {
// At this point, extra isn't content, so add padding
val += jQuery.css( elem, "padding" + cssExpand[ i ], true, styles );
@ -131,6 +138,7 @@ function getWidthOrHeight( elem, name, extra ) {
// svg - https://bugzilla.mozilla.org/show_bug.cgi?id=649285
// MathML - https://bugzilla.mozilla.org/show_bug.cgi?id=491668
if ( val <= 0 || val == null ) {
// Fall back to computed then uncomputed css if necessary
val = curCSS( elem, name, styles );
if ( val < 0 || val == null ) {
@ -228,6 +236,7 @@ jQuery.extend({
// Convert "+=" or "-=" to relative numbers (#7345)
if ( type === "string" && ( ret = rcssNum.exec( value ) ) && ret[ 1 ] ) {
value = adjustCSS( elem, name, ret );
// Fixes bug #9237
type = "number";
}
@ -256,6 +265,7 @@ jQuery.extend({
}
} else {
// If a hook was provided get the non-computed value from there
if ( hooks && "get" in hooks &&
( ret = hooks.get( elem, false, extra ) ) !== undefined ) {
@ -311,6 +321,7 @@ jQuery.each([ "height", "width" ], function( i, name ) {
// Certain elements can have dimension info if we invisibly show them
// but it must have a current display style that would benefit
return rdisplayswap.test( jQuery.css( elem, "display" ) ) &&
// Support: Safari 8+
// Table columns in Safari have non-zero offsetWidth & zero
// getBoundingClientRect().width unless display is changed.

View File

@ -1,10 +1,12 @@
define( function() {
function addGetHookIf( conditionFn, hookFn ) {
// Define the hook, we'll check on the first run if it's really needed.
return {
get: function() {
if ( conditionFn() ) {
// Hook not needed (or it's not possible to use it due
// to missing dependency), remove it.
delete this.get;

View File

@ -12,11 +12,13 @@ function adjustCSS( elem, prop, valueParts, tween ) {
function() { return jQuery.css( elem, prop, "" ); },
initial = currentValue(),
unit = valueParts && valueParts[ 3 ] || ( jQuery.cssNumber[ prop ] ? "" : "px" ),
// Starting value computation is required for potential unit mismatches
initialInUnit = ( jQuery.cssNumber[ prop ] || unit !== "px" && +initial ) &&
rcssNum.exec( jQuery.css( elem, prop ) );
if ( initialInUnit && initialInUnit[ 3 ] !== unit ) {
// Trust units reported by jQuery.css
unit = unit || initialInUnit[ 3 ];
@ -27,6 +29,7 @@ function adjustCSS( elem, prop, valueParts, tween ) {
initialInUnit = +initial || 1;
do {
// If previous iteration zeroed out, double until we get *something*.
// Use string for doubling so we don't accidentally see scale as unchanged below
scale = scale || ".5";
@ -44,6 +47,7 @@ function adjustCSS( elem, prop, valueParts, tween ) {
if ( valueParts ) {
initialInUnit = +initialInUnit || +initial || 0;
// Apply relative offset (+=/-=) if specified
adjusted = valueParts[ 1 ] ?
initialInUnit + ( valueParts[ 1 ] + 1 ) * valueParts[ 2 ] :

View File

@ -4,7 +4,7 @@ define([
"./var/rmargin",
"./var/getStyles",
"./support",
"../selector" // contains
"../selector" // Get jQuery.contains
], function( jQuery, rnumnonpx, rmargin, getStyles, support ) {
function curCSS( elem, name, computed ) {
@ -46,6 +46,7 @@ function curCSS( elem, name, computed ) {
}
return ret !== undefined ?
// Support: IE9-11+
// IE returns zIndex value as an integer.
ret + "" :

View File

@ -18,6 +18,7 @@ function showHide( elements, show ) {
display = elem.style.display;
if ( show ) {
if ( display === "none" ) {
// Restore a pre-hide() value if we have one
values[ index ] = dataPriv.get( elem, "display" ) || "";
}

View File

@ -29,6 +29,7 @@ define([
// so they're executed at the same time to save the second computation.
function computeStyleTests() {
div.style.cssText =
// Support: Android 2.3
// Vendor-prefix box-sizing
"-webkit-box-sizing:border-box;box-sizing:border-box;" +
@ -49,6 +50,7 @@ define([
jQuery.extend( support, {
pixelPosition: function() {
// This test is executed only once but we still do memoizing
// since we can use the boxSizingReliable pre-computing.
// No need to check if the test was already performed, though.
@ -62,6 +64,7 @@ define([
return boxSizingReliableVal;
},
pixelMarginRight: function() {
// Support: Android 4.0-4.3
// We're checking for boxSizingReliableVal here instead of pixelMarginRightVal
// since that compresses better and they're computed together anyway.
@ -82,6 +85,7 @@ define([
// Reset CSS: box-sizing; display; margin; border; padding
marginDiv.style.cssText = div.style.cssText =
// Support: Android 2.3
// Vendor-prefix box-sizing
"-webkit-box-sizing:content-box;box-sizing:content-box;" +

View File

@ -1,10 +1,12 @@
define( [
"../../core",
"../../selector"
// css is assumed
], function( jQuery ) {
return function( elem, el ) {
// isHidden might be called from jQuery#filter function;
// in that case, element will be second argument
elem = el || elem;

View File

@ -32,6 +32,7 @@ function dataAttr( elem, key, data ) {
data = data === "true" ? true :
data === "false" ? false :
data === "null" ? null :
// Only convert to a number if it doesn't change the string
+data + "" === data ? +data :
rbrace.test( data ) ? jQuery.parseJSON( data ) :

View File

@ -100,7 +100,7 @@ Data.prototype = {
return this.get( owner, key );
}
// [*]When the key is not a string, or both a key and value
// When the key is not a string, or both a key and value
// are specified, set or extend (existing objects) with either:
//
// 1. An object of properties

View File

@ -6,6 +6,7 @@ define([
* Determines whether an object can have data
*/
jQuery.acceptData = function( owner ) {
// Accepts only:
// - Node
// - Node.ELEMENT_NODE

View File

@ -15,6 +15,7 @@ jQuery.extend({
Deferred: function( func ) {
var tuples = [
// action, add listener, callbacks,
// ... .then handlers, argument index, [final state]
[ "notify", "progress", jQuery.Callbacks( "memory" ),
@ -36,12 +37,14 @@ jQuery.extend({
"catch": function( fn ) {
return promise.then( null, fn );
},
// Keep pipe for back-compat
pipe: function( /* fnDone, fnFail, fnProgress */ ) {
var fns = arguments;
return jQuery.Deferred( function( newDefer ) {
jQuery.each( tuples, function( i, tuple ) {
// Map tuples (progress, done, fail) to arguments (done, fail, progress)
var fn = jQuery.isFunction( fns[ tuple[ 4 ] ] ) && fns[ tuple[ 4 ] ];
@ -105,6 +108,7 @@ jQuery.extend({
// Handle a returned thenable
if ( jQuery.isFunction( then ) ) {
// Special processors (notify) just wait for resolution
if ( special ) {
then.call(
@ -130,6 +134,7 @@ jQuery.extend({
// Handle all other returned values
} else {
// Only substitue handlers pass on context
// and multiple values (non-spec behavior)
if ( handler !== Identity ) {
@ -156,6 +161,7 @@ jQuery.extend({
// https://promisesaplus.com/#point-61
// Ignore post-resolution exceptions
if ( depth + 1 >= maxDepth ) {
// Only substitue handlers pass on context
// and multiple values (non-spec behavior)
if ( handler !== Thrower ) {
@ -182,6 +188,7 @@ jQuery.extend({
}
return jQuery.Deferred( function( newDefer ) {
// progress_handlers.add( ... )
tuples[ 0 ][ 3 ].add(
resolve(
@ -217,6 +224,7 @@ jQuery.extend({
);
} ).promise();
},
// Get a promise for this deferred
// If obj is provided, the promise aspect is added to the object
promise: function( obj ) {
@ -239,6 +247,7 @@ jQuery.extend({
if ( stateString ) {
list.add(
function() {
// state = "resolved" (i.e., fulfilled)
// state = "rejected"
state = stateString;

View File

@ -18,6 +18,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
@ -38,6 +39,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 ) :

9
src/effects.js vendored
View File

@ -100,6 +100,7 @@ function defaultPrefilter( elem, props, opts ) {
hooks.unqueued++;
anim.always( function() {
// Ensure the complete handler is called before this completes
anim.always( function() {
hooks.unqueued--;
@ -140,6 +141,7 @@ function defaultPrefilter( elem, props, opts ) {
// Restrict "overflow" and "display" styles during box animations
if ( isBox && elem.nodeType === 1 ) {
// Support: IE 9 - 11
// Record all 3 overflow attributes because IE does not infer the shorthand
// from identically-valued overflowX and overflowY
@ -211,6 +213,7 @@ function defaultPrefilter( elem, props, opts ) {
/* jshint -W083 */
anim.done( function() {
// The final step of a "hide" animation is actually hiding the element
if ( !hidden ) {
showHide( [ elem ] );
@ -277,6 +280,7 @@ function Animation( elem, properties, options ) {
index = 0,
length = Animation.prefilters.length,
deferred = jQuery.Deferred().always( function() {
// Don't match elem in the :animated selector
delete tick.elem;
} ),
@ -286,6 +290,7 @@ function Animation( elem, properties, options ) {
}
var currentTime = fxNow || createFxNow(),
remaining = Math.max( 0, animation.startTime + animation.duration - currentTime ),
// Support: Android 2.3
// Archaic crash bug won't allow us to use `1 - ( 0.5 || 0 )` (#12497)
temp = remaining / animation.duration || 0,
@ -326,6 +331,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;
@ -474,6 +480,7 @@ jQuery.fn.extend({
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 );
@ -616,6 +623,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 );
@ -659,6 +667,7 @@ jQuery.fx.stop = function() {
jQuery.fx.speeds = {
slow: 600,
fast: 200,
// Default speed
_default: 400
};

View File

@ -71,10 +71,12 @@ Tween.propHooks = {
// 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 available and use plain properties where available.

View File

@ -39,8 +39,10 @@ function on( elem, types, selector, data, fn, one ) {
// Types can be a map of types/handlers
if ( typeof types === "object" ) {
// ( types-Object, selector, data )
if ( typeof selector !== "string" ) {
// ( types-Object, data )
data = data || selector;
selector = undefined;
@ -52,15 +54,18 @@ function on( elem, types, selector, data, fn, one ) {
}
if ( data == null && fn == null ) {
// ( types, fn )
fn = selector;
data = selector = undefined;
} else if ( fn == null ) {
if ( typeof selector === "string" ) {
// ( types, selector, fn )
fn = data;
data = undefined;
} else {
// ( types, data, fn )
fn = data;
data = selector;
@ -74,10 +79,12 @@ function on( elem, types, selector, data, fn, one ) {
if ( one === 1 ) {
origFn = fn;
fn = function( event ) {
// Can use an empty set, since event contains the info
jQuery().off( event );
return origFn.apply( this, arguments );
};
// Use same guid so caller can remove using origFn
fn.guid = origFn.guid || ( origFn.guid = jQuery.guid++ );
}
@ -124,6 +131,7 @@ jQuery.event = {
}
if ( !( eventHandle = elemData.handle ) ) {
eventHandle = elemData.handle = function( e ) {
// Discard the second event of a jQuery.event.trigger() and
// when an event is called after a page has unloaded
return typeof jQuery !== "undefined" && jQuery.event.triggered !== e.type ?
@ -232,7 +240,8 @@ jQuery.event = {
special = jQuery.event.special[ type ] || {};
type = ( selector ? special.delegateType : special.bindType ) || type;
handlers = events[ type ] || [];
tmp = tmp[2] && new RegExp( "(^|\\.)" + namespaces.join("\\.(?:.*\\.|)") + "(\\.|$)" );
tmp = tmp[ 2 ] &&
new RegExp( "(^|\\.)" + namespaces.join( "\\.(?:.*\\.|)" ) + "(\\.|$)" );
// Remove matching events
origCount = j = handlers.length;
@ -294,6 +303,7 @@ jQuery.event = {
}
if ( type.indexOf( "." ) > -1 ) {
// Namespaced trigger; create a regexp to match event type in handle()
namespaces = type.split( "." );
type = namespaces.shift();
@ -378,7 +388,8 @@ jQuery.event = {
// If nobody prevented the default action, do it now
if ( !onlyHandlers && !event.isDefaultPrevented() ) {
if ( (!special._default || special._default.apply( eventPath.pop(), data ) === false) &&
if ( ( !special._default ||
special._default.apply( eventPath.pop(), data ) === false ) &&
jQuery.acceptData( elem ) ) {
// Call a native DOM method on the target with the same name name as the event.
@ -605,10 +616,12 @@ jQuery.event = {
special: {
load: {
// Prevent triggered image.load events from bubbling to window.load
noBubble: true
},
focus: {
// Fire native event if possible so blur/focus sequence is correct
trigger: function() {
if ( this !== safeActiveElement() && this.focus ) {
@ -628,6 +641,7 @@ jQuery.event = {
delegateType: "focusout"
},
click: {
// For checkbox, fire native event so checked state will be right
trigger: function() {
if ( this.type === "checkbox" && this.click && jQuery.nodeName( this, "input" ) ) {
@ -662,6 +676,7 @@ jQuery.event = {
{
type: type,
isSimulated: true
// Previously, `originalEvent: {}` was set here, so stopPropagation call
// would not be triggered on donor event, since in our own
// jQuery.event.stopPropagation function we had a check for existence of
@ -694,6 +709,7 @@ jQuery.removeEvent = function( elem, type, handle ) {
};
jQuery.Event = function( src, props ) {
// Allow instantiation without the 'new' keyword
if ( !( this instanceof jQuery.Event ) ) {
return new jQuery.Event( src, props );
@ -708,6 +724,7 @@ jQuery.Event = function( src, props ) {
// by a handler lower down the tree; reflect the correct value.
this.isDefaultPrevented = src.defaultPrevented ||
src.defaultPrevented === undefined &&
// Support: Android<4.0
src.returnValue === false ?
returnTrue :
@ -858,6 +875,7 @@ jQuery.fn.extend({
off: function( types, selector, fn ) {
var handleObj, type;
if ( types && types.preventDefault && types.handleObj ) {
// ( event ) dispatched jQuery.Event
handleObj = types.handleObj;
jQuery( types.delegateTarget ).off(
@ -870,6 +888,7 @@ jQuery.fn.extend({
return this;
}
if ( typeof types === "object" ) {
// ( types-object [, selector] )
for ( type in types ) {
this.off( type, selector, types[ type ] );
@ -877,6 +896,7 @@ jQuery.fn.extend({
return this;
}
if ( selector === false || typeof selector === "function" ) {
// ( types [, fn] )
fn = selector;
selector = undefined;

View File

@ -32,6 +32,7 @@ jQuery.fn.extend({
return this.on( types, selector, data, fn );
},
undelegate: function( selector, types, fn ) {
// ( namespace ) or ( selector, types [, fn] )
return arguments.length === 1 ?
this.off( selector, "**" ) :

View File

@ -1,4 +1,5 @@
var
// Map over jQuery in case of overwrite
_jQuery = window.jQuery,

View File

@ -28,6 +28,7 @@ define([
var
rxhtmlTag = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:-]+)[^>]*)\/>/gi,
rnoInnerhtml = /<(?:script|style|link)/i,
// checked="checked" or checked
rchecked = /checked\s*(?:[^=]|=\s*.checked.)/i,
rscriptTypeMasked = /^true\/(.*)/,
@ -157,6 +158,7 @@ function domManip( collection, args, callback, ignored ) {
// Keep references to cloned scripts for later restoration
if ( hasScripts ) {
// Support: Android<4.1, PhantomJS<2
// push.apply(_, arraylike) throws on ancient WebKit
jQuery.merge( scripts, getAll( node, "script" ) );
@ -180,6 +182,7 @@ function domManip( collection, args, callback, ignored ) {
jQuery.contains( doc, node ) ) {
if ( node.src ) {
// Optional AJAX dependency, but won't run scripts if not present
if ( jQuery._evalUrl ) {
jQuery._evalUrl( node.src );

View File

@ -23,6 +23,7 @@ function buildFragment( elems, context, scripts, selection, ignored ) {
// Add nodes directly
if ( jQuery.type( elem ) === "object" ) {
// Support: Android<4.1, PhantomJS<2
// push.apply(_, arraylike) throws on ancient WebKit
jQuery.merge( nodes, elem.nodeType ? [ elem ] : elem );

View File

@ -3,6 +3,7 @@ define([
], function( jQuery ) {
function getAll( context, tag ) {
// Support: IE9-11+
// Use typeof to avoid zero-argument method invocation on host objects (#15151)
var ret = typeof context.getElementsByTagName !== "undefined" ?

View File

@ -74,6 +74,7 @@ jQuery.offset = {
jQuery.fn.extend( {
offset: function( options ) {
// Preserve chaining for setter
if ( arguments.length ) {
return options === undefined ?
@ -127,10 +128,12 @@ jQuery.fn.extend({
// Fixed elements are offset from window (parentOffset = {top:0, left: 0},
// because it is its only offset parent
if ( jQuery.css( elem, "position" ) === "fixed" ) {
// Assume getBoundingClientRect is there when computed position is fixed
offset = elem.getBoundingClientRect();
} else {
// Get *real* offsetParent
offsetParent = this.offsetParent();
@ -214,6 +217,7 @@ jQuery.each( [ "top", "left" ], function( i, prop ) {
function( elem, computed ) {
if ( computed ) {
computed = curCSS( elem, prop );
// If curCSS returns percentage, fallback to offset
return rnumnonpx.test( computed ) ?
jQuery( elem ).position()[ prop ] + "px" :

View File

@ -106,6 +106,7 @@ jQuery.fn.extend({
clearQueue: function( type ) {
return this.queue( type || "fx", [] );
},
// Get a promise resolved when queues of a certain type
// are emptied (fx is the type by default)
promise: function( type, obj ) {

View File

@ -36,6 +36,7 @@ var hasDuplicate,
documentElement.oMatchesSelector ||
documentElement.msMatchesSelector,
sortOrder = function( a, b ) {
// Flag for duplicate removal
if ( a === b ) {
hasDuplicate = true;
@ -47,6 +48,7 @@ var hasDuplicate,
a.compareDocumentPosition( b );
if ( compare ) {
// Disconnected nodes
if ( compare & 1 ) {
@ -130,17 +132,21 @@ jQuery.extend({
nodeType = elem.nodeType;
if ( !nodeType ) {
// If no nodeType, this is expected to be an array
while ( ( node = elem[ i++ ] ) ) {
// Do not traverse comment nodes
ret += jQuery.text( node );
}
} else if ( nodeType === 1 || nodeType === 9 || nodeType === 11 ) {
// Use textContent for elements
return elem.textContent;
} else if ( nodeType === 3 || nodeType === 4 ) {
return elem.nodeValue;
}
// Do not include comment or processing instruction nodes
return ret;

View File

@ -16,13 +16,16 @@ function buildParams( prefix, obj, traditional, add ) {
var name;
if ( jQuery.isArray( obj ) ) {
// Serialize array item.
jQuery.each( obj, function( i, v ) {
if ( traditional || rbracket.test( prefix ) ) {
// Treat each array item as a scalar.
add( prefix, v );
} else {
// Item is non-scalar (array or object), encode its numeric index.
buildParams(
prefix + "[" + ( typeof v === "object" ? i : "" ) + "]",
@ -34,12 +37,14 @@ function buildParams( prefix, obj, traditional, add ) {
} );
} else if ( !traditional && jQuery.type( obj ) === "object" ) {
// Serialize object item.
for ( name in obj ) {
buildParams( prefix + "[" + name + "]", obj[ name ], traditional, add );
}
} else {
// Serialize scalar item.
add( prefix, obj );
}
@ -51,6 +56,7 @@ jQuery.param = function( a, traditional ) {
var prefix,
s = [],
add = function( key, value ) {
// If value is a function, invoke it and return its value
value = jQuery.isFunction( value ) ? value() : ( value == null ? "" : value );
s[ s.length ] = encodeURIComponent( key ) + "=" + encodeURIComponent( value );
@ -63,12 +69,14 @@ jQuery.param = function( a, traditional ) {
// If an array was passed in, assume that it is an array of form elements.
if ( jQuery.isArray( a ) || ( a.jquery && !jQuery.isPlainObject( a ) ) ) {
// Serialize the form elements
jQuery.each( a, function() {
add( this.name, this.value );
} );
} else {
// If traditional, encode the "old" way (the way 1.3.2 or older
// did it), otherwise encode params recursively.
for ( prefix in a ) {
@ -86,6 +94,7 @@ jQuery.fn.extend({
},
serializeArray: function() {
return this.map( function() {
// Can add propHook for "elements" to filter or add form elements
var elements = jQuery.prop( this, "elements" );
return elements ? jQuery.makeArray( elements ) : this;

View File

@ -8,6 +8,7 @@ define([
], function( jQuery, indexOf, rneedsContext ) {
var rparentsprev = /^(?:parents|prev(?:Until|All))/,
// Methods guaranteed to produce a unique set when starting from a unique set
guaranteedUnique = {
children: true,
@ -71,6 +72,7 @@ jQuery.fn.extend({
for ( ; i < l; i++ ) {
for ( cur = this[ i ]; cur && cur !== context; cur = cur.parentNode ) {
// Always skip document fragments
if ( cur.nodeType < 11 && ( pos ?
pos.index( cur ) > -1 :
@ -180,6 +182,7 @@ jQuery.each({
}
if ( this.length > 1 ) {
// Remove duplicates
if ( !guaranteedUnique[ name ] ) {
jQuery.uniqueSort( matched );

View File

@ -1,4 +1,5 @@
define( function() {
// [[Class]] -> type pairs
return {};
} );

View File

@ -1,4 +1,5 @@
define( function() {
// All support tests are defined in their respective modules.
return {};
} );

File diff suppressed because it is too large Load Diff

View File

@ -3,6 +3,7 @@
var fireNative, originaljQuery, original$,
baseURL = "",
supportjQuery = this.jQuery,
// see RFC 2606
externalHost = "example.com";

View File

@ -49,6 +49,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;
}
@ -56,6 +57,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.
@ -106,6 +108,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(
@ -151,6 +154,7 @@ window.moduleTeardown = function() {
};
QUnit.done( function() {
// Remove our own fixtures outside #qunit-fixture
supportjQuery( "#qunit ~ *" ).remove();
} );
@ -159,6 +163,7 @@ QUnit.testDone(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();

View File

@ -270,6 +270,7 @@ QUnit.module( "ajax", {
url: url( "data/headers.php?keys=content-type" ),
contentType: false,
success: function( data ) {
// Some server/interpreter combinations always supply a Content-Type to scripts
data = data || "content-type: \n";
assert.strictEqual( data, "content-type: \n", "Test content-type is not set when options.contentType===false" );
@ -880,7 +881,6 @@ QUnit.module( "ajax", {
];
} );
ajaxTest( "jQuery.ajax() - JSONP - POST" + label, 3, function( assert ) {
return [
{
@ -1138,6 +1138,7 @@ QUnit.module( "ajax", {
ajaxTest( "jQuery.ajax() - failing cross-domain (non-existing)", 1, function( assert ) {
return {
// see RFC 2606
url: "http://example.invalid",
error: function( xhr, _, e ) {
@ -1561,6 +1562,7 @@ QUnit.module( "ajax", {
} );
QUnit.asyncTest( "#11743 - jQuery.ajax() - script, throws exception", 1, function( assert ) {
// Support: Android 2.3 only
// Android 2.3 doesn't fire the window.onerror handler, just accept the reality there.
if ( /android 2\.3/i.test( navigator.userAgent ) ) {
@ -1629,6 +1631,7 @@ QUnit.module( "ajax", {
var parsedXML = jQuery( jQuery.parseXML( "<tab title=\"Added\">blibli</tab>" ) ).find( "tab" );
ajaxXML = jQuery( ajaxXML );
try {
// Android 2.3 doesn't automatically adopt nodes from foreign documents.
// (see the comment in test/manipulation.js)
// Support: Android 2.3
@ -1749,6 +1752,7 @@ QUnit.module( "ajax", {
return {
dataType: "prefix",
setup: function() {
// Ensure prefix does not throw an error
jQuery.ajaxPrefilter( "+prefix", function( options, _, jqXHR ) {
if ( options.abortInPrefilter ) {

View File

@ -79,6 +79,7 @@ QUnit.test( "attr(String)", function( assert ) {
assert.equal( jQuery( "#testForm" ).attr( "target" ), undefined, "Retrieving target does not equal the input with name=target" );
assert.equal( jQuery( "#testForm" ).attr( "target", "newTarget" ).attr( "target" ), "newTarget", "Set target successfully on a form" );
assert.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")
assert.equal( jQuery( "#testForm" ).attr( "name" ), undefined, "Retrieving name does not retrieve input with name=name" );
extras.remove();
@ -810,13 +811,13 @@ QUnit.test( "val() after modification", function( assert ) {
assert.equal( jQuery( "#text1" ).val(), "bla", "Check for modified value of input element" );
} );
QUnit.test( "val()", function( assert ) {
assert.expect( 20 + ( jQuery.fn.serialize ? 6 : 0 ) );
var checks, $button;
assert.equal( jQuery( "#text1" ).val(), "Test", "Check for value of input element" );
// ticket #1714 this caused a JS error in IE
assert.equal( jQuery( "#first" ).val(), "", "Check a paragraph element to see if it has a value" );
assert.ok( jQuery( [] ).val() === undefined, "Check an empty jQuery object will return undefined from val" );
@ -1161,7 +1162,6 @@ var testRemoveClass = function( valueObj, assert ) {
$set.removeClass( valueObj( "asdf" ) );
assert.ok( !$set.hasClass( "asdf" ), "Check node,textnode,comment for removeClass" );
jQuery( div ).removeClass( valueObj( "foo" ) );
assert.strictEqual( jQuery( div ).attr( "class" ), undefined, "removeClass doesn't create a class attribute" );

View File

@ -515,6 +515,7 @@ QUnit.test("XSS via location.hash", function( assert ) {
QUnit.start();
};
try {
// This throws an error because it's processed like an id
jQuery( "#<img id='check9521' src='no-such-.gif' onerror='jQuery._check9521(false)'>" ).appendTo( "#qunit-fixture" );
} catch ( err ) {
@ -585,6 +586,7 @@ QUnit.test("jQuery('html')", function( assert ) {
assert.equal( jQuery( "element[attribute='<div></div>']" ).length, 0,
"When html is within brackets, do not recognize as html." );
//equal( jQuery( "element[attribute=<div></div>]" ).length, 0,
// "When html is within brackets, do not recognize as html." );
assert.equal( jQuery( "element:not(<div></div>)" ).length, 0,
@ -634,6 +636,7 @@ QUnit.test("jQuery(selector, xml).text(str) - loaded via xml document", function
assert.expect( 2 );
var xml = createDashboardXML(),
// tests for #1419 where ie was a problem
tab = jQuery( "tab", xml ).eq( 0 );
assert.equal( tab.text(), "blabla", "verify initial text correct" );
@ -692,6 +695,7 @@ QUnit.test("inArray()", function( assert ) {
jQuery.each( tests, function( key, obj ) {
assert.equal( jQuery.inArray( obj.elem, selections[ key ] ), obj.index, "elem is in the array of selections of its tag" );
// Third argument (fromIndex)
assert.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" );
assert.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" );
@ -1080,8 +1084,10 @@ QUnit.test("jQuery.extend(true,{},{a:[], o:{}}); deep copy with array, followed
assert.expect( 2 );
var result, initial = {
// This will make "copyIsArray" true
array: [ 1, 2, 3, 4 ],
// If "copyIsArray" doesn't get reset to false, the check
// will evaluate true and enter the array copy block
// instead of the object copy block. Since the ternary in the

View File

@ -742,6 +742,7 @@ QUnit.test("jQuery.cssProps behavior, (bug #8402)", function( assert ) {
assert.equal( div.css( "top" ), "10px", "the fixed property is used when accessing the computed style" );
div.css( "top", "100px" );
assert.equal( div[ 0 ].style.left, "100px", "the fixed property is used when setting the style" );
// cleanup jQuery.cssProps
jQuery.cssProps.top = undefined;
} );
@ -814,6 +815,7 @@ QUnit.test("Do not append px (#9548, #12990)", function( assert ) {
var $div = jQuery( "<div>" ).appendTo( "#qunit-fixture" );
$div.css( "fill-opacity", 1 );
// Support: Android 2.3 (no support for fill-opacity)
if ( $div.css( "fill-opacity" ) ) {
assert.equal( $div.css( "fill-opacity" ), 1, "Do not append px to 'fill-opacity'" );
@ -1032,6 +1034,7 @@ QUnit.test( "Keep the last style if the new one isn't recognized by the browser
QUnit.test( "Reset the style if set to an empty string", function( assert ) {
assert.expect( 1 );
var el = jQuery( "<div></div>" ).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.
assert.equal( el.css( "position" ) || "static", "static",
@ -1049,6 +1052,7 @@ QUnit.asyncTest( "Clearing a Cloned Element's Style Shouldn't Clear the Original
value: [ "rgb(255, 0, 0)", "rgb(255,0,0)", "#ff0000" ],
expected: [ "transparent" ]
}, {
// Firefox returns auto's value
name: "backgroundImage",
value: [ "url('test.png')", "url(" + baseUrl + "test.png)", "url(\"" + baseUrl + "test.png\")" ],
@ -1058,6 +1062,7 @@ QUnit.asyncTest( "Clearing a Cloned Element's Style Shouldn't Clear the Original
value: [ "5% 5%" ],
expected: [ "0% 0%", "-1000px 0px", "-1000px 0%" ]
}, {
// Firefox returns no-repeat
name: "backgroundRepeat",
value: [ "repeat-y" ],
@ -1186,6 +1191,7 @@ QUnit.test( "Do not throw on frame elements from css method (#15098)", function(
}
QUnit.test( "Don't default to a cached previously used wrong prefixed name (gh-2015)", function( assert ) {
// 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.

View File

@ -651,6 +651,7 @@ QUnit.test(".data supports interoperable hyphenated/camelCase get/set of 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
@ -681,6 +682,7 @@ QUnit.test(".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
@ -713,6 +715,7 @@ QUnit.test(".data supports interoperable removal of properties SET TWICE #13850"
"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
@ -741,8 +744,10 @@ QUnit.test( ".removeData supports removal of hyphenated properties via array (#1
// 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
};
@ -770,6 +775,7 @@ QUnit.test(".removeData should not throw exceptions. (#10080)", function( assert
assert.ok( true, "called unload" );
QUnit.start();
} );
// change the url to trigger unload
frame.attr( "src", "data/iframe.html?param=true" );
} );

View File

@ -77,7 +77,6 @@ jQuery.each( [ "", " - new operator" ], function( _, withNew ) {
} );
} );
QUnit.test( "jQuery.Deferred - chainability", function( assert ) {
var defer = jQuery.Deferred();
@ -643,6 +642,7 @@ QUnit.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();

26
test/unit/effects.js vendored
View File

@ -308,7 +308,6 @@ QUnit.test("animate negative padding", function( assert ) {
QUnit.test( "animate block as inline width/height", function( assert ) {
assert.expect( 3 );
jQuery( "#foo" ).css( { display: "inline", width: "", height: "" } ).animate( { width: 42, height: 42 }, 100, function() {
assert.equal( jQuery( this ).css( "display" ), "inline-block", "inline-block was set on non-floated inline element when animating width/height" );
assert.equal( this.offsetWidth, 42, "width was animated" );
@ -506,7 +505,6 @@ QUnit.test( "animate option { queue: 'name' }", function( assert ) {
assert.deepEqual( order, [ 1, 2 ], "Callbacks in expected order" );
} );
// this is the first callback function that should be called
order.push( 1 );
assert.equal( parseFloat( foo.css( "width" ) ), origWidth, "Animation does not start on its own." );
@ -530,7 +528,6 @@ QUnit.test("animate with no properties", function( assert ) {
assert.equal( divs.length, count, "Make sure that callback is called for each element in the set." );
foo = jQuery( "#foo" );
foo.animate( {} );
@ -543,7 +540,6 @@ QUnit.test("animate with no properties", function( assert ) {
QUnit.test( "animate duration 0", function( assert ) {
assert.expect( 11 );
var $elem,
$elems = jQuery( [ { a:0 },{ a:0 } ] ),
counter = 0;
@ -573,6 +569,7 @@ QUnit.test("animate duration 0", function( assert ) {
} );
$elems.eq( 1 ).animate( { a:3 }, 200, function() {
counter++;
// Failed until [6115]
assert.equal( counter, 5, "One synchronic and one asynchronic" );
} );
@ -598,6 +595,7 @@ QUnit.test("animate hyphenated properties", function( assert ) {
.animate( { "font-size": 20 }, 200, function() {
assert.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 );
@ -647,6 +645,7 @@ QUnit.test("stop()", function( assert ) {
this.clock.tick( 100 );
$two.fadeTo( 100, 0, function() {
assert.equal( $two.css( "opacity" ), "0", "Stop does not interfere with animations on other elements (#6641)" );
// Reset styles
$one.add( $two ).css( "opacity", "" );
} );
@ -725,10 +724,12 @@ QUnit.test("stop(clearQueue, gotoEnd)", function( assert ) {
$foo.stop( false, true );
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 );
@ -935,6 +936,7 @@ jQuery.each({
}
num = 0;
// TODO: uncrowd this
if ( t_h === "show" ) { num++; }
if ( t_w === "show" ) { num++; }
@ -1113,6 +1115,7 @@ QUnit.test( "interrupt toggle", function( assert ) {
jQuery.each( { slideToggle: "height", fadeToggle: "opacity", toggle: "width" }, function( method, prop ) {
var $methodElems = $elems.filter( "[id^='" + method.toLowerCase() + "']" ).each( function() {
// Don't end test until we're done with this element
remaining++;
@ -1306,6 +1309,7 @@ QUnit.test("callbacks should fire in correct order (#9100)", function( assert )
cb = 0;
jQuery( "<p data-operation='*2'></p><p data-operation='^2'></p>" ).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;
@ -1376,6 +1380,7 @@ QUnit.test("Do not append px to 'fill-opacity' #9548", function( assert ) {
var $div = jQuery( "<div>" ).appendTo( "#qunit-fixture" );
$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" ) ) {
assert.equal( jQuery( this ).css( "fill-opacity" ), 1, "Do not append px to 'fill-opacity'" );
@ -1489,6 +1494,7 @@ QUnit.test( "Animate Option: step: function( percent, tween )", function( assert
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;
@ -1762,6 +1768,7 @@ QUnit.test( "multiple unqueued and promise", function( assert ) {
duration: 2000,
queue: false,
complete: function() {
// no properties is a non-op and finishes immediately
assert.strictEqual( step++, 1, "Step 1" );
}
@ -1887,11 +1894,13 @@ QUnit.test("Animation callbacks (#11797)", function( assert ) {
assert.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;
}
assert.equal( percent, expectedProgress, "async: progress " + expectedProgress );
// once at 0, once at 1
expectedProgress++;
},
@ -1972,6 +1981,7 @@ QUnit.test( "Animations with 0 duration don't ease (#12273)", function( assert )
} );
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;
@ -2013,6 +2023,7 @@ jQuery.map([ "toggle", "slideToggle", "fadeToggle" ], function ( method ) {
},
always: secondToggle
} );
//FIXME figure out why 470
this.clock.tick( 470 );
} );
@ -2034,9 +2045,11 @@ QUnit.test( "jQuery.fx.start & jQuery.fx.stop hook points", function( assert ) {
// calls start
foo.animate( { foo: 1 }, { queue: false } );
// calls start
foo.animate( { foo: 2 }, { queue: false } );
foo.stop();
// calls stop
jQuery.fx.tick();
@ -2059,6 +2072,7 @@ QUnit.test( ".finish() completes all queued animations", function( assert ) {
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() {
assert.ok( true, "Called animation callback for " + prop );
@ -2074,6 +2088,7 @@ QUnit.test( ".finish() completes all queued animations", function( assert ) {
// cleanup
div.remove();
// leaves a "shadow timer" which does nothing around, need to force a tick
jQuery.fx.tick();
} );
@ -2108,6 +2123,7 @@ QUnit.test( ".finish( false ) - unqueued animations", function( assert ) {
// cleanup
div.remove();
// leaves a "shadow timer" which does nothing around, need to force a tick
jQuery.fx.tick();
} );
@ -2134,6 +2150,7 @@ QUnit.test( ".finish( \"custom\" ) - custom queue animations", function( assert
} );
} );
assert.equal( div.queue( "custom" ).length, 4, "4 animations in the queue" );
// start the first animation
div.dequeue( "custom" );
assert.equal( div.is( ":animated" ), true, ":animated matches" );
@ -2145,6 +2162,7 @@ QUnit.test( ".finish( \"custom\" ) - custom queue animations", function( assert
// cleanup
div.remove();
// leaves a "shadow timer" which does nothing around, need to force a tick
jQuery.fx.tick();
} );

View File

@ -36,6 +36,7 @@ QUnit.test("Handler changes and .trigger() order", function( assert ) {
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();
@ -98,8 +99,7 @@ QUnit.test("on(), multiple events at once", function( assert ) {
handler = function( event ) {
if ( event.type === "click" ) {
clickCounter += 1;
}
else if (event.type === "mouseover") {
} else if ( event.type === "mouseover" ) {
mouseoverCounter += 1;
}
};
@ -268,11 +268,13 @@ QUnit.test("on/one/off(Object)", function( assert ){
}
$elem = jQuery( "#firstp" )
// Regular bind
.on( {
"click":handler,
"mouseover":handler
} )
// Bind with data
.one( {
"click":handlerWithData,
@ -381,6 +383,7 @@ QUnit.test("on bubbling, isDefaultPrevented, stopImmediatePropagation", function
assert.ok( false, "immediate propagation should have been stopped" );
},
fakeClick = function( $jq ) {
// Use a native click so we don't get jQuery simulated bubbling
var e = document.createEvent( "MouseEvents" );
e.initEvent( "click", true, true );
@ -396,6 +399,7 @@ QUnit.test("on bubbling, isDefaultPrevented, stopImmediatePropagation", function
$anchor2.off( "click" );
$main.off( "click", "**" );
$anchor2.on( "click", function() {
// Let the default action occur
} );
$main.on( "click", "#foo", function( e ) {
@ -787,6 +791,7 @@ QUnit.test("off(eventObject)", function( assert ) {
}
$elem
// This handler shouldn't be unbound
.on( "foo", function() {
num += 1;
@ -795,6 +800,7 @@ QUnit.test("off(eventObject)", function( assert ) {
$elem.off( e );
num += 2;
} )
// Neither this one
.on( "bar", function() {
num += 4;
@ -1008,7 +1014,6 @@ QUnit.test("trigger(type, [data], [fn])", function( assert ) {
assert.ok( true, "Native call was triggered" );
};
jQuery( document ).on( "mouseenter", "#firstp", function() {
assert.ok( true, "Trigger mouseenter bound by on" );
} );
@ -1176,6 +1181,7 @@ QUnit.test("trigger(eventObject, [data], [fn])", function( assert ) {
assert.equal( event.isImmediatePropagationStopped(), true, "Verify isPropagationStopped" );
$parent.on( "foo", function( e ) {
// Tries bubbling
assert.equal( e.type, "foo", "Verify event type when passed passing an event object" );
assert.equal( e.target.id, "child", "Verify event.target when passed passing an event object" );
@ -2159,7 +2165,6 @@ QUnit.test(".on and .off", function( assert ) {
.off( "click", "em" );
assert.equal( counter, 54, "delegated event bindings with data" );
// Mixed event bindings and types
counter = 0;
mixfn = function( e, trig ) {
@ -2255,6 +2260,7 @@ QUnit.test("special on name mapping", function( assert ) {
delegateType: "click",
handle: function( event ) {
assert.equal( event.handleObj.origType, "gutfeeling", "got a gutfeeling" );
// Need to call the handler since .one() uses it to unbind
return event.handleObj.handler.call( this, event );
}
@ -2395,6 +2401,7 @@ QUnit.test( "event object properties on natively-triggered event", function( ass
// IE9+ requires element to be in the body before it will dispatch
$link.appendTo( "body" ).on( "click", function( e ) {
// Not trying to assert specific values here, just ensure the property exists
assert.equal( "detail" in e, true, "has .detail" );
assert.equal( "cancelable" in e, true, "has .cancelable" );
@ -2569,6 +2576,7 @@ QUnit.test("trigger click on checkbox, fires change event", function( assert ) {
var done = assert.async();
check.on( "change", function() {
// get it?
check.off( "change" );
assert.ok( true, "Change event fired as a result of triggered click" );

View File

@ -529,6 +529,7 @@ QUnit.test( "append(xml)", function( assert ) {
var xmlDoc, xml1, xml2;
function createXMLDoc() {
// Initialize DOM based upon latest installed MSXML or Netscape
var elem, n, len,
aActiveX =
@ -541,6 +542,7 @@ QUnit.test( "append(xml)", function( assert ) {
if ( document.implementation && "createDocument" in document.implementation ) {
return document.implementation.createDocument( "", "", null );
} else {
// IE
for ( n = 0, len = aActiveX.length; n < len; n++ ) {
try {
@ -1185,7 +1187,6 @@ function testReplaceWith( val, assert ) {
jQuery( "#anchor1" ).contents().replaceWith( val( tmp ) );
assert.deepEqual( jQuery( "#anchor1" ).contents().get(), [ tmp ], "Replace text node with element" );
tmp = jQuery( "<div/>" ).appendTo( "#qunit-fixture" ).on( "click", function() {
assert.ok( true, "Newly bound click run." );
} );
@ -1203,7 +1204,6 @@ function testReplaceWith( val, assert ) {
y.trigger( "click" ); // Shouldn't be run
child.trigger( "click" ); // Shouldn't be run
y = jQuery( "<div/>" ).appendTo( "#qunit-fixture" ).on( "click", function() {
assert.ok( false, "Previously bound click run." );
} );
@ -1216,13 +1216,11 @@ function testReplaceWith( val, assert ) {
child2.trigger( "click" );
set = jQuery( "<div/>" ).replaceWith( val( "<span>test</span>" ) );
assert.equal( set[ 0 ].nodeName.toLowerCase(), "div", "No effect on a disconnected node." );
assert.equal( set.length, 1, "No effect on a disconnected node." );
assert.equal( set[ 0 ].childNodes.length, 0, "No effect on a disconnected node." );
child = jQuery( "#qunit-fixture" ).children().first();
$div = jQuery( "<div class='pathological'/>" ).insertBefore( child );
$div.replaceWith( $div );
@ -1234,7 +1232,6 @@ function testReplaceWith( val, assert ) {
assert.deepEqual( jQuery( ".pathological", "#qunit-fixture" ).get(), [],
"Replacement with following sibling (context removed)" );
non_existent = jQuery( "#does-not-exist" ).replaceWith( val( "<b>should not throw an error</b>" ) );
assert.equal( non_existent.length, 0, "Length of non existent element." );
@ -1466,6 +1463,7 @@ QUnit.test( "clone()", function( assert ) {
assert.equal( clone[ 0 ].nodeName.toUpperCase(), "DIV", "DIV element cloned" );
div = div.find( "object" );
clone = clone.find( "object" );
// oldIE adds extra attributes and <param> elements, so just test for existence of the defined set
jQuery.each( [ "height", "width", "classid" ], function( i, attr ) {
assert.equal( clone.attr( attr ), div.attr( attr ), "<object> attribute cloned: " + attr );
@ -2268,6 +2266,7 @@ QUnit.test( "Ensure oldIE creates a new set on appendTo (#8894)", function( asse
} );
QUnit.asyncTest( "html() - script exceptions bubble (#11743)", 2, function( assert ) {
// Support: Android 2.3 only
// Android 2.3 doesn't fire the window.onerror handler, just accept the reality there.
if ( /android 2\.3/i.test( navigator.userAgent ) ) {

View File

@ -7,6 +7,7 @@ if ( !jQuery.fn.offset ) {
var supportsScroll, supportsFixedPosition,
forceScroll = jQuery( "<div/>" ).css( { width: 2000, height: 2000 } ),
checkSupport = function() {
// Only run once
checkSupport = false;
@ -89,7 +90,6 @@ testIframe("offset/absolute", "absolute", function( $, iframe, document, assert
assert.equal( jQuery( this[ "id" ], doc ).offset().left, this[ "left" ], "jQuery('" + this[ "id" ] + "').offset().left" );
} );
// get position
tests = [
{ "id": "#absolute-1", "top": 0, "left": 0 }
@ -117,7 +117,6 @@ testIframe("offset/absolute", "absolute", function( $, window, document, assert
assert.equal( $( this[ "id" ] ).offset().left, this[ "left" ], "jQuery('" + this[ "id" ] + "').offset().left" );
} );
// get position
tests = [
{ "id": "#absolute-1", "top": 0, "left": 0 },
@ -135,7 +134,6 @@ testIframe("offset/absolute", "absolute", function( $, window, document, assert
assert.equal( offset.top, 10, "Setting offset on element with position absolute but 'auto' values." );
assert.equal( offset.left, 10, "Setting offset on element with position absolute but 'auto' values." );
// set offset
tests = [
{ "id": "#absolute-2", "top": 30, "left": 30 },
@ -201,7 +199,6 @@ testIframe("offset/relative", "relative", function( $, window, document, assert
assert.equal( $( this[ "id" ] ).offset().left, this[ "left" ], "jQuery('" + this[ "id" ] + "').offset().left" );
} );
// get position
tests = [
{ "id": "#relative-1", "top": 6, "left": 6 },
@ -213,7 +210,6 @@ testIframe("offset/relative", "relative", function( $, window, document, assert
assert.equal( $( this[ "id" ] ).position().left, this[ "left" ], "jQuery('" + this[ "id" ] + "').position().left" );
} );
// set offset
tests = [
{ "id": "#relative-2", "top": 200, "left": 50 },
@ -260,7 +256,6 @@ testIframe("offset/static", "static", function( $, window, document, assert ) {
assert.equal( $( this[ "id" ] ).offset().left, this[ "left" ], "jQuery('" + this[ "id" ] + "').offset().left" );
} );
// get position
tests = [
{ "id": "#static-1", "top": 6, "left": 6 },
@ -273,7 +268,6 @@ testIframe("offset/static", "static", function( $, window, document, assert ) {
assert.equal( $( this[ "id" ] ).position().left, this[ "left" ], "jQuery('" + this[ "left" ] + "').position().left" );
} );
// set offset
tests = [
{ "id": "#static-2", "top": 200, "left": 200 },
@ -344,6 +338,7 @@ testIframe("offset/fixed", "fixed", function( $, window, document, assert ) {
assert.equal( $( this[ "id" ] ).offset().left, this[ "offsetLeft" ], "jQuery('" + this[ "id" ] + "').offset().left" );
assert.equal( $( this[ "id" ] ).position().left, this[ "positionLeft" ], "jQuery('" + this[ "id" ] + "').position().left" );
} else {
// need to have same number of assertions
assert.ok( true, "Fixed position is not supported" );
assert.ok( true, "Fixed position is not supported" );
@ -376,6 +371,7 @@ testIframe("offset/fixed", "fixed", function( $, window, document, assert ) {
assert.equal( $( this[ "id" ] ).offset().top, this[ "top" ] + 1, "jQuery('" + this[ "id" ] + "').offset({ top: " + ( this[ "top" ] + 1 ) + ", using: fn })" );
assert.equal( $( this[ "id" ] ).offset().left, this[ "left" ] + 1, "jQuery('" + this[ "id" ] + "').offset({ left: " + ( this[ "left" ] + 1 ) + ", using: fn })" );
} else {
// need to have same number of assertions
assert.ok( true, "Fixed position is not supported" );
assert.ok( true, "Fixed position is not supported" );
@ -390,6 +386,7 @@ testIframe("offset/fixed", "fixed", function( $, window, document, assert ) {
assert.equal( $noTopLeft.offset().top, 1007, "Check offset top for fixed element with no top set" );
assert.equal( $noTopLeft.offset().left, 1007, "Check offset left for fixed element with no left set" );
} else {
// need to have same number of assertions
assert.ok( true, "Fixed position is not supported" );
assert.ok( true, "Fixed position is not supported" );
@ -572,6 +569,7 @@ QUnit.test("iframe scrollTop/Left (see gh-1945)", function( assert ) {
assert.equal( true, true, "Can't scroll iframes in this environment" );
} else {
// Tests scrollTop/Left with iframes
jQuery( "#iframe" ).css( "width", "50px" ).css( "height", "50px" );
ifDoc.write( "<div style='width: 1000px; height: 1000px;'></div>" );

View File

@ -196,6 +196,7 @@ QUnit.asyncTest( "fn.promise() - called when fx queue is empty", 3, function( as
promised = false;
foo.queue( function( next ) {
// called twice!
assert.ok( !promised, "Promised hasn't been called" );
setTimeout( next, 10 );
@ -261,7 +262,6 @@ QUnit.test( ".promise(obj)", function( assert ) {
assert.strictEqual( promise, obj, ".promise(type, obj) returns obj" );
} );
if ( jQuery.fn.stop ) {
QUnit.test( "delay() can be stopped", function( assert ) {
assert.expect( 3 );

View File

@ -111,6 +111,7 @@ testIframeWithCallback(
"reliableMarginRight": true
};
} else if ( /chrome/i.test( userAgent ) ) {
// Catches Chrome on Android as well (i.e. the default
// Android browser on Android >= 4.4).
expected = {
@ -270,6 +271,7 @@ testIframeWithCallback(
assert.expect( j );
for ( i in expected ) {
// TODO check for all modules containing support properties
if ( jQuery.ajax || i !== "ajax" && i !== "cors" ) {
assert.equal( computedSupport[ i ], expected[ i ],

View File

@ -279,7 +279,6 @@ QUnit.test("filter(jQuery)", function( assert ) {
assert.deepEqual( jQuery( "#form input" ).filter( elements ).get(), q( "text1" ), "filter(Element)" );
} );
QUnit.test( "filter() with positional selectors", function( assert ) {
assert.expect( 19 );
@ -734,7 +733,6 @@ QUnit.test("add(String html)", function( assert ) {
assert.ok( !divs[ 1 ].parentNode, "Sort with the disconnected node last." );
x = jQuery( [] ).add( "<p id='x1'>xxx</p>" ).add( "<p id='x2'>xxx</p>" );
assert.equal( x[ 0 ].id, "x1", "Check detached element1" );
assert.equal( x[ 1 ].id, "x2", "Check detached element2" );

View File

@ -28,27 +28,45 @@ function testWrap( val , assert ) {
defaultText = "Try them out:";
result = jQuery( "#first" ).wrap( val( "<div class='red'><span></span></div>" ) ).text();
assert.equal( defaultText, result, "Check for wrapping of on-the-fly html" );
assert.ok( jQuery("#first").parent().parent().is(".red"), "Check if wrapper has class 'red'" );
assert.equal(
defaultText, result, "Check for wrapping of on-the-fly html"
);
assert.ok(
jQuery( "#first" ).parent().parent().is( ".red" ), "Check if wrapper has class 'red'"
);
result = jQuery( "#first" ).wrap( val( document.getElementById( "empty" ) ) ).parent();
assert.ok( result.is("ol"), "Check for element wrapping" );
assert.equal( result.text(), defaultText, "Check for element wrapping" );
assert.ok(
result.is( "ol" ), "Check for element wrapping"
);
assert.equal(
result.text(), defaultText, "Check for element wrapping"
);
jQuery( "#check1" ).on( "click", function() {
var checkbox = this;
assert.ok( checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" );
assert.ok(
checkbox.checked, "Checkbox's state is erased after wrap() action, see #769"
);
jQuery( checkbox ).wrap( val( "<div id='c1' style='display:none;'></div>" ) );
assert.ok( checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" );
assert.ok(
checkbox.checked, "Checkbox's state is erased after wrap() action, see #769"
);
} ).prop( "checked", false )[ 0 ].click();
// using contents will get comments regular, text, and comment nodes
j = jQuery( "#nonnodes" ).contents();
j.wrap( val( "<i></i>" ) );
assert.equal( jQuery("#nonnodes > i").length, jQuery("#nonnodes")[ 0 ].childNodes.length, "Check node,textnode,comment wraps ok" );
assert.equal( jQuery("#nonnodes > i").text(), j.text(), "Check node,textnode,comment wraps doesn't hurt text" );
assert.equal(
jQuery( "#nonnodes > i" ).length, jQuery( "#nonnodes" )[ 0 ].childNodes.length,
"Check node,textnode,comment wraps ok"
);
assert.equal(
jQuery( "#nonnodes > i" ).text(), j.text(),
"Check node,textnode,comment wraps doesn't hurt text"
);
// Try wrapping a disconnected node
cacheLength = 0;
@ -57,32 +75,53 @@ function testWrap( val , assert ) {
}
j = jQuery( "<label/>" ).wrap( val( "<li/>" ) );
assert.equal( j[ 0 ] .nodeName.toUpperCase(), "LABEL", "Element is a label" );
assert.equal( j[ 0 ].parentNode.nodeName.toUpperCase(), "LI", "Element has been wrapped" );
assert.equal(
j[ 0 ] .nodeName.toUpperCase(), "LABEL", "Element is a label"
);
assert.equal(
j[ 0 ].parentNode.nodeName.toUpperCase(), "LI", "Element has been wrapped"
);
for ( i in jQuery.cache ) {
cacheLength--;
}
assert.equal( cacheLength, 0, "No memory leak in jQuery.cache (bug #7165)" );
assert.equal(
cacheLength, 0, "No memory leak in jQuery.cache (bug #7165)"
);
// Wrap an element containing a text node
j = jQuery( "<span/>" ).wrap( "<div>test</div>" );
assert.equal( j[ 0 ].previousSibling.nodeType, 3, "Make sure the previous node is a text element" );
assert.equal( j[ 0 ].parentNode.nodeName.toUpperCase(), "DIV", "And that we're in the div element." );
assert.equal(
j[ 0 ].previousSibling.nodeType, 3, "Make sure the previous node is a text element"
);
assert.equal(
j[ 0 ].parentNode.nodeName.toUpperCase(), "DIV", "And that we're in the div element."
);
// Try to wrap an element with multiple elements (should fail)
j = jQuery( "<div><span></span></div>" ).children().wrap( "<p></p><div></div>" );
assert.equal( j[ 0 ].parentNode.parentNode.childNodes.length, 1, "There should only be one element wrapping." );
assert.equal( j.length, 1, "There should only be one element (no cloning)." );
assert.equal( j[ 0 ].parentNode.nodeName.toUpperCase(), "P", "The span should be in the paragraph." );
assert.equal(
j[ 0 ].parentNode.parentNode.childNodes.length, 1,
"There should only be one element wrapping."
);
assert.equal(
j.length, 1, "There should only be one element (no cloning)."
);
assert.equal(
j[ 0 ].parentNode.nodeName.toUpperCase(), "P", "The span should be in the paragraph."
);
// Wrap an element with a jQuery set
j = jQuery( "<span/>" ).wrap( jQuery( "<div></div>" ) );
assert.equal( j[ 0 ].parentNode.nodeName.toLowerCase(), "div", "Wrapping works." );
assert.equal(
j[ 0 ].parentNode.nodeName.toLowerCase(), "div", "Wrapping works."
);
// Wrap an element with a jQuery set and event
result = jQuery( "<div></div>" ).on( "click", function() {
assert.ok( true, "Event triggered." );
assert.ok(
true, "Event triggered."
);
// Remove handlers on detached elements
result.off();
@ -90,7 +129,9 @@ function testWrap( val , assert ) {
} );
j = jQuery( "<span/>" ).wrap( result );
assert.equal( j[ 0 ].parentNode.nodeName.toLowerCase(), "div", "Wrapping works." );
assert.equal(
j[ 0 ].parentNode.nodeName.toLowerCase(), "div", "Wrapping works."
);
j.parent().trigger( "click" );
}
@ -109,7 +150,10 @@ QUnit.test( "wrap(Function) with index (#10177)", function( assert ) {
assert.expect( targets.length );
targets.wrap( function( i ) {
assert.equal( i, expectedIndex, "Check if the provided index (" + i + ") is as expected (" + expectedIndex + ")" );
assert.equal(
i, expectedIndex,
"Check if the provided index (" + i + ") is as expected (" + expectedIndex + ")"
);
expectedIndex++;
return "<div id='wrap_index_'" + i + "'></div>";
@ -125,8 +169,12 @@ QUnit.test( "wrap(String) consecutive elements (#10177)", function( assert ) {
targets.each( function() {
var $this = jQuery( this );
assert.ok( $this.parent().is(".wrapper"), "Check each elements parent is correct (.wrapper)" );
assert.equal( $this.siblings().length, 0, "Each element should be wrapped individually" );
assert.ok(
$this.parent().is( ".wrapper" ), "Check each elements parent is correct (.wrapper)"
);
assert.equal(
$this.siblings().length, 0, "Each element should be wrapped individually"
);
} );
} );
@ -140,11 +188,21 @@ QUnit.test( "wrapAll(String)", function( assert ) {
p = jQuery( "#firstp,#first" )[ 0 ].parentNode;
result = jQuery( "#firstp,#first" ).wrapAll( "<div class='red'><div class='tmp'></div></div>" );
assert.equal( result.parent().length, 1, "Check for wrapping of on-the-fly html" );
assert.ok( jQuery("#first").parent().parent().is(".red"), "Check if wrapper has class 'red'" );
assert.ok( jQuery("#firstp").parent().parent().is(".red"), "Check if wrapper has class 'red'" );
assert.equal( jQuery("#first").parent().parent()[ 0 ].previousSibling, prev, "Correct Previous Sibling" );
assert.equal( jQuery("#first").parent().parent()[ 0 ].parentNode, p, "Correct Parent" );
assert.equal(
result.parent().length, 1, "Check for wrapping of on-the-fly html"
);
assert.ok(
jQuery( "#first" ).parent().parent().is( ".red" ), "Check if wrapper has class 'red'"
);
assert.ok(
jQuery( "#firstp" ).parent().parent().is( ".red" ), "Check if wrapper has class 'red'"
);
assert.equal(
jQuery( "#first" ).parent().parent()[ 0 ].previousSibling, prev, "Correct Previous Sibling"
);
assert.equal(
jQuery( "#first" ).parent().parent()[ 0 ].parentNode, p, "Correct Parent"
);
} );
@ -157,11 +215,21 @@ QUnit.test( "wrapAll(Function)", function( assert ) {
return "<div class='red'><div class='tmp'></div></div>";
} );
assert.equal( result.parent().length, 1, "Check for wrapping of on-the-fly html" );
assert.ok( jQuery( "#first" ).parent().parent().is( ".red" ), "Check if wrapper has class 'red'" );
assert.ok( jQuery( "#firstp" ).parent().parent().is( ".red" ), "Check if wrapper has class 'red'" );
assert.ok( jQuery( "#first" ).parent().parent().parent().is( p ), "Correct Parent" );
assert.strictEqual( jQuery( "#first" ).parent().parent()[ 0 ].previousSibling, prev, "Correct Previous Sibling" );
assert.equal(
result.parent().length, 1, "Check for wrapping of on-the-fly html"
);
assert.ok(
jQuery( "#first" ).parent().parent().is( ".red" ), "Check if wrapper has class 'red'"
);
assert.ok(
jQuery( "#firstp" ).parent().parent().is( ".red" ), "Check if wrapper has class 'red'"
);
assert.ok(
jQuery( "#first" ).parent().parent().parent().is( p ), "Correct Parent"
);
assert.strictEqual(
jQuery( "#first" ).parent().parent()[ 0 ].previousSibling, prev, "Correct Previous Sibling"
);
} );
QUnit.test( "wrapAll(Function) check execution characteristics", function( assert ) {
@ -174,11 +242,17 @@ QUnit.test( "wrapAll(Function) check execution characteristics", function( asser
return "";
} );
assert.ok( !i, "should not execute function argument if target element does not exist" );
assert.ok(
!i, "should not execute function argument if target element does not exist"
);
jQuery( "#firstp" ).wrapAll( function( index ) {
assert.strictEqual( this, jQuery( "#firstp" )[ 0 ], "context must be the first found element" );
assert.strictEqual( index, undefined, "index argument should not be included in function execution" );
assert.strictEqual(
this, jQuery( "#firstp" )[ 0 ], "context must be the first found element"
);
assert.strictEqual(
index, undefined, "index argument should not be included in function execution"
);
} );
} );
@ -191,9 +265,15 @@ QUnit.test( "wrapAll(Element)", function( assert ) {
p = jQuery( "#first" )[ 0 ].parentNode;
jQuery( "#firstp,#first" ).wrapAll( document.getElementById( "empty" ) );
assert.equal( jQuery("#first").parent()[ 0 ], jQuery("#firstp").parent()[ 0 ], "Same Parent" );
assert.equal( jQuery("#first").parent()[ 0 ].previousSibling, prev, "Correct Previous Sibling" );
assert.equal( jQuery("#first").parent()[ 0 ].parentNode, p, "Correct Parent" );
assert.equal(
jQuery( "#first" ).parent()[ 0 ], jQuery( "#firstp" ).parent()[ 0 ], "Same Parent"
);
assert.equal(
jQuery( "#first" ).parent()[ 0 ].previousSibling, prev, "Correct Previous Sibling"
);
assert.equal(
jQuery( "#first" ).parent()[ 0 ].parentNode, p, "Correct Parent"
);
} );
QUnit.test( "wrapInner(String)", function( assert ) {
@ -205,15 +285,27 @@ QUnit.test( "wrapInner(String)", function( assert ) {
num = jQuery( "#first" ).children().length;
jQuery( "#first" ).wrapInner( "<div class='red'><div id='tmp'></div></div>" );
assert.equal( jQuery("#first").children().length, 1, "Only one child" );
assert.ok( jQuery("#first").children().is(".red"), "Verify Right Element" );
assert.equal( jQuery("#first").children().children().children().length, num, "Verify Elements Intact" );
assert.equal(
jQuery( "#first" ).children().length, 1, "Only one child"
);
assert.ok(
jQuery( "#first" ).children().is( ".red" ), "Verify Right Element"
);
assert.equal(
jQuery( "#first" ).children().children().children().length, num, "Verify Elements Intact"
);
num = jQuery( "#first" ).html( "foo<div>test</div><div>test2</div>" ).children().length;
jQuery( "#first" ).wrapInner( "<div class='red'><div id='tmp'></div></div>" );
assert.equal( jQuery("#first").children().length, 1, "Only one child" );
assert.ok( jQuery("#first").children().is(".red"), "Verify Right Element" );
assert.equal( jQuery("#first").children().children().children().length, num, "Verify Elements Intact" );
assert.equal(
jQuery( "#first" ).children().length, 1, "Only one child"
);
assert.ok(
jQuery( "#first" ).children().is( ".red" ), "Verify Right Element"
);
assert.equal(
jQuery( "#first" ).children().children().children().length, num, "Verify Elements Intact"
);
} );
QUnit.test( "wrapInner(Element)", function( assert ) {
@ -225,13 +317,23 @@ QUnit.test( "wrapInner(Element)", function( assert ) {
num = jQuery( "#first" ).children().length;
jQuery( "#first" ).wrapInner( document.getElementById( "empty" ) );
assert.equal( jQuery("#first").children().length, 1, "Only one child" );
assert.ok( jQuery("#first").children().is("#empty"), "Verify Right Element" );
assert.equal( jQuery("#first").children().children().length, num, "Verify Elements Intact" );
assert.equal(
jQuery( "#first" ).children().length, 1, "Only one child"
);
assert.ok(
jQuery( "#first" ).children().is( "#empty" ), "Verify Right Element"
);
assert.equal(
jQuery( "#first" ).children().children().length, num, "Verify Elements Intact"
);
div.wrapInner( "<span></span>" );
assert.equal( div.children().length, 1, "The contents were wrapped." );
assert.equal( div.children()[ 0 ].nodeName.toLowerCase(), "span", "A span was inserted." );
assert.equal(
div.children().length, 1, "The contents were wrapped."
);
assert.equal(
div.children()[ 0 ].nodeName.toLowerCase(), "span", "A span was inserted."
);
} );
QUnit.test( "wrapInner(Function) returns String", function( assert ) {
@ -244,15 +346,27 @@ QUnit.test( "wrapInner(Function) returns String", function( assert ) {
num = jQuery( "#first" ).children().length;
jQuery( "#first" ).wrapInner( val( "<div class='red'><div id='tmp'></div></div>" ) );
assert.equal( jQuery("#first").children().length, 1, "Only one child" );
assert.ok( jQuery("#first").children().is(".red"), "Verify Right Element" );
assert.equal( jQuery("#first").children().children().children().length, num, "Verify Elements Intact" );
assert.equal(
jQuery( "#first" ).children().length, 1, "Only one child"
);
assert.ok(
jQuery( "#first" ).children().is( ".red" ), "Verify Right Element"
);
assert.equal(
jQuery( "#first" ).children().children().children().length, num, "Verify Elements Intact"
);
num = jQuery( "#first" ).html( "foo<div>test</div><div>test2</div>" ).children().length;
jQuery( "#first" ).wrapInner( val( "<div class='red'><div id='tmp'></div></div>" ) );
assert.equal( jQuery("#first").children().length, 1, "Only one child" );
assert.ok( jQuery("#first").children().is(".red"), "Verify Right Element" );
assert.equal( jQuery("#first").children().children().children().length, num, "Verify Elements Intact" );
assert.equal(
jQuery( "#first" ).children().length, 1, "Only one child"
);
assert.ok(
jQuery( "#first" ).children().is( ".red" ), "Verify Right Element"
);
assert.equal(
jQuery( "#first" ).children().children().children().length, num, "Verify Elements Intact"
);
} );
QUnit.test( "wrapInner(Function) returns Element", function( assert ) {
@ -265,39 +379,78 @@ QUnit.test( "wrapInner(Function) returns Element", function( assert ) {
num = jQuery( "#first" ).children().length;
jQuery( "#first" ).wrapInner( val( document.getElementById( "empty" ) ) );
assert.equal( jQuery("#first").children().length, 1, "Only one child" );
assert.ok( jQuery("#first").children().is("#empty"), "Verify Right Element" );
assert.equal( jQuery("#first").children().children().length, num, "Verify Elements Intact" );
assert.equal(
jQuery( "#first" ).children().length, 1, "Only one child"
);
assert.ok(
jQuery( "#first" ).children().is( "#empty" ), "Verify Right Element"
);
assert.equal(
jQuery( "#first" ).children().children().length, num, "Verify Elements Intact"
);
div.wrapInner( val( "<span></span>" ) );
assert.equal( div.children().length, 1, "The contents were wrapped." );
assert.equal( div.children()[ 0 ].nodeName.toLowerCase(), "span", "A span was inserted." );
assert.equal(
div.children().length, 1, "The contents were wrapped."
);
assert.equal(
div.children()[ 0 ].nodeName.toLowerCase(), "span", "A span was inserted."
);
} );
QUnit.test( "unwrap()", function( assert ) {
assert.expect( 9 );
jQuery("body").append(" <div id='unwrap' style='display: none;'> <div id='unwrap1'> <span class='unwrap'>a</span> <span class='unwrap'>b</span> </div> <div id='unwrap2'> <span class='unwrap'>c</span> <span class='unwrap'>d</span> </div> <div id='unwrap3'> <b><span class='unwrap unwrap3'>e</span></b> <b><span class='unwrap unwrap3'>f</span></b> </div> </div>");
jQuery( "body" ).append(
" <div id='unwrap' style='display: none;'> <div id='unwrap1'>" +
" <span class='unwrap'>a</span> <span class='unwrap'>b</span> </div> <div id='unwrap2'>" +
" <span class='unwrap'>c</span> <span class='unwrap'>d</span> </div> <div id='unwrap3'>" +
" <b><span class='unwrap unwrap3'>e</span></b>" +
" <b><span class='unwrap unwrap3'>f</span></b> </div> </div>"
);
var abcd = jQuery( "#unwrap1 > span, #unwrap2 > span" ).get(),
abcdef = jQuery( "#unwrap span" ).get();
assert.equal( jQuery("#unwrap1 span").add("#unwrap2 span:first-child").unwrap().length, 3, "make #unwrap1 and #unwrap2 go away" );
assert.deepEqual( jQuery("#unwrap > span").get(), abcd, "all four spans should still exist" );
assert.equal(
jQuery( "#unwrap1 span" ).add( "#unwrap2 span:first-child" ).unwrap().length, 3,
"make #unwrap1 and #unwrap2 go away"
);
assert.deepEqual(
jQuery( "#unwrap > span" ).get(), abcd, "all four spans should still exist"
);
assert.deepEqual( jQuery("#unwrap3 span").unwrap().get(), jQuery("#unwrap3 > span").get(), "make all b in #unwrap3 go away" );
assert.deepEqual(
jQuery( "#unwrap3 span" ).unwrap().get(), jQuery( "#unwrap3 > span" ).get(),
"make all b in #unwrap3 go away"
);
assert.deepEqual( jQuery("#unwrap3 span").unwrap().get(), jQuery("#unwrap > span.unwrap3").get(), "make #unwrap3 go away" );
assert.deepEqual(
jQuery( "#unwrap3 span" ).unwrap().get(), jQuery( "#unwrap > span.unwrap3" ).get(),
"make #unwrap3 go away"
);
assert.deepEqual( jQuery("#unwrap").children().get(), abcdef, "#unwrap only contains 6 child spans" );
assert.deepEqual(
jQuery( "#unwrap" ).children().get(), abcdef, "#unwrap only contains 6 child spans"
);
assert.deepEqual( jQuery("#unwrap > span").unwrap().get(), jQuery("body > span.unwrap").get(), "make the 6 spans become children of body" );
assert.deepEqual(
jQuery( "#unwrap > span" ).unwrap().get(), jQuery( "body > span.unwrap" ).get(),
"make the 6 spans become children of body"
);
assert.deepEqual( jQuery("body > span.unwrap").unwrap().get(), jQuery("body > span.unwrap").get(), "can't unwrap children of body" );
assert.deepEqual( jQuery("body > span.unwrap").unwrap().get(), abcdef, "can't unwrap children of body" );
assert.deepEqual(
jQuery( "body > span.unwrap" ).unwrap().get(), jQuery( "body > span.unwrap" ).get(),
"can't unwrap children of body"
);
assert.deepEqual(
jQuery( "body > span.unwrap" ).unwrap().get(), abcdef, "can't unwrap children of body"
);
assert.deepEqual( jQuery("body > span.unwrap").get(), abcdef, "body contains 6 .unwrap child spans" );
assert.deepEqual(
jQuery( "body > span.unwrap" ).get(), abcdef, "body contains 6 .unwrap child spans"
);
jQuery( "body > span.unwrap" ).remove();
} );
@ -306,23 +459,40 @@ QUnit.test( "unwrap( selector )", function( assert ) {
assert.expect( 5 );
jQuery( "body" ).append( " <div id='unwrap' style='display: none;'> <div id='unwrap1'> <span class='unwrap'>a</span> <span class='unwrap'>b</span> </div> <div id='unwrap2'> <span class='unwrap'>c</span> <span class='unwrap'>d</span> </div> </div>" );
jQuery( "body" ).append(
" <div id='unwrap' style='display: none;'> <div id='unwrap1'>" +
"<span class='unwrap'>a</span> <span class='unwrap'>b</span> </div>" +
" <div id='unwrap2'> <span class='unwrap'>c</span> <span class='unwrap'>d</span>" +
" </div> </div>"
);
// Shouldn't unwrap, no match
jQuery( "#unwrap1 span" ) .unwrap( "#unwrap2" );
assert.equal( jQuery("#unwrap1").length, 1, "still wrapped" );
assert.equal(
jQuery( "#unwrap1" ).length, 1, "still wrapped"
);
// Shouldn't unwrap, no match
jQuery( "#unwrap1 span" ) .unwrap( "span" );
assert.equal( jQuery("#unwrap1").length, 1, "still wrapped" );
assert.equal(
jQuery( "#unwrap1" ).length, 1, "still wrapped"
);
// Unwraps
jQuery( "#unwrap1 span" ) .unwrap( "#unwrap1" );
assert.equal( jQuery("#unwrap1").length, 0, "unwrapped match" );
assert.equal(
jQuery( "#unwrap1" ).length, 0, "unwrapped match"
);
// Check return values
assert.deepEqual( jQuery( "#unwrap2 span" ).get(), jQuery( "#unwrap2 span" ).unwrap( "quote" ).get(), "return on unmatched unwrap" );
assert.deepEqual( jQuery( "#unwrap2 span" ).get(), jQuery( "#unwrap2 span" ).unwrap( "#unwrap2" ).get(), "return on matched unwrap" );
assert.deepEqual(
jQuery( "#unwrap2 span" ).get(), jQuery( "#unwrap2 span" ).unwrap( "quote" ).get(),
"return on unmatched unwrap"
);
assert.deepEqual(
jQuery( "#unwrap2 span" ).get(), jQuery( "#unwrap2 span" ).unwrap( "#unwrap2" ).get(),
"return on matched unwrap"
);
jQuery( "body > span.unwrap" ).remove();
} );
@ -336,8 +506,14 @@ QUnit.test( "jQuery(<tag>) & wrap[Inner/All]() handle unknown elems (#10667)", f
$wraptarget.wrapAll( "<aside style='background-color:green'></aside>" );
assert.notEqual( $wraptarget.parent("aside").get( 0 ).style.backgroundColor, "transparent", "HTML5 elements created with wrapAll inherit styles" );
assert.notEqual( $section.get( 0 ).style.backgroundColor, "transparent", "HTML5 elements create with jQuery( string ) inherit styles" );
assert.notEqual(
$wraptarget.parent( "aside" ).get( 0 ).style.backgroundColor, "transparent",
"HTML5 elements created with wrapAll inherit styles"
);
assert.notEqual(
$section.get( 0 ).style.backgroundColor, "transparent",
"HTML5 elements create with jQuery( string ) inherit styles"
);
} );
QUnit.test( "wrapping scripts (#10470)", function( assert ) {
@ -345,12 +521,15 @@ QUnit.test( "wrapping scripts (#10470)", function( assert ) {
assert.expect( 2 );
var script = document.createElement( "script" );
script.text = script.textContent = "ok( !document.eval10470, 'script evaluated once' ); document.eval10470 = true;";
script.text = script.textContent =
"ok( !document.eval10470, 'script evaluated once' ); document.eval10470 = true;";
document.eval10470 = false;
jQuery( "#qunit-fixture" ).empty()[ 0 ].appendChild( script );
jQuery( "#qunit-fixture script" ).wrap( "<b></b>" );
assert.strictEqual( script.parentNode, jQuery("#qunit-fixture > b")[ 0 ], "correctly wrapped" );
assert.strictEqual(
script.parentNode, jQuery( "#qunit-fixture > b" )[ 0 ], "correctly wrapped"
);
jQuery( script ).remove();
} );