diff options
129 files changed, 8708 insertions, 7968 deletions
@@ -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" ] } diff --git a/Gruntfile.js b/Gruntfile.js index 0fe64d7e6..53a195ee8 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -20,7 +20,7 @@ module.exports = function( grunt ) { // But our modules can delete srcHintOptions.onevar; - grunt.initConfig({ + grunt.initConfig( { pkg: grunt.file.readJSON( "package.json" ), dst: readOptionalJSON( "dist/.destination.json" ), "compare_size": { @@ -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" }, @@ -162,7 +168,7 @@ module.exports = function( grunt ) { } } } - }); + } ); // Load grunt tasks from NPM packages require( "load-grunt-tasks" )( grunt ); @@ -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" ] ); }; diff --git a/build/release.js b/build/release.js index 231e2c4c3..7fd00bd8c 100644 --- a/build/release.js +++ b/build/release.js @@ -9,7 +9,7 @@ module.exports = function( Release ) { npmTags = Release.npmTags; - Release.define({ + Release.define( { npmPublish: true, issueTracker: "github", /** @@ -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(); @@ -47,9 +48,9 @@ module.exports = function( Release ) { dist: function( callback ) { cdn.makeArchives( Release, function() { dist( Release, callback ); - }); + } ); } - }); + } ); }; module.exports.dependencies = [ diff --git a/build/release/cdn.js b/build/release/cdn.js index 6c497ee0b..07285a56d 100644 --- a/build/release/cdn.js +++ b/build/release/cdn.js @@ -29,13 +29,14 @@ var function makeReleaseCopies( Release ) { shell.mkdir( "-p", cdnFolder ); - Object.keys( releaseFiles ).forEach(function( key ) { + Object.keys( releaseFiles ).forEach( function( key ) { var text, builtFile = releaseFiles[ key ], unpathedFile = key.replace( /VER/g, Release.newVersion ), 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"] @@ -47,7 +48,7 @@ function makeReleaseCopies( Release ) { } else if ( builtFile !== releaseFile ) { shell.cp( "-f", builtFile, releaseFile ); } - }); + } ); } function makeArchives( Release, callback ) { @@ -75,23 +76,23 @@ function makeArchives( Release, callback ) { output.on( "error", function( err ) { throw err; - }); + } ); archiver.pipe( output ); - files = files.map(function( item ) { + files = files.map( function( item ) { return "dist" + ( rver.test( item ) ? "/cdn" : "" ) + "/" + item.replace( rver, Release.newVersion ); - }); + } ); sum = Release.exec( "md5sum " + files.join( " " ), "Error retrieving md5sum" ); fs.writeFileSync( md5file, sum ); files.push( md5file ); - files.forEach(function( file ) { + files.forEach( function( file ) { archiver.append( fs.createReadStream( file ), { name: path.basename( file ) } ); - }); + } ); archiver.finalize(); } @@ -104,9 +105,9 @@ function makeArchives( Release, callback ) { makeArchive( "mscdn", msFilesCDN, callback ); } - buildGoogleCDN(function() { + buildGoogleCDN( function() { buildMicrosoftCDN( callback ); - }); + } ); } module.exports = { diff --git a/build/release/dist.js b/build/release/dist.js index 8ef6faf86..32053eafb 100644 --- a/build/release/dist.js +++ b/build/release/dist.js @@ -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", @@ -34,7 +35,7 @@ module.exports = function( Release, complete ) { * Generate bower file for jquery-dist */ function generateBower() { - return JSON.stringify({ + return JSON.stringify( { name: pkg.name, main: pkg.main, license: "MIT", @@ -42,7 +43,7 @@ module.exports = function( Release, complete ) { "package.json" ], keywords: pkg.keywords - }, null, 2); + }, null, 2 ); } /** @@ -57,14 +58,14 @@ module.exports = function( Release, complete ) { "dist/jquery.js", "dist/jquery.min.js", "dist/jquery.min.map" - ].forEach(function( file ) { + ].forEach( function( file ) { shell.cp( Release.dir.repo + "/" + file, distFolder ); - }); + } ); // Copy other files - files.forEach(function( file ) { + files.forEach( function( file ) { shell.cp( "-r", Release.dir.repo + "/" + file, Release.dir.dist ); - }); + } ); // Write generated bower file fs.writeFileSync( Release.dir.dist + "/bower.json", generateBower() ); diff --git a/build/release/ensure-sizzle.js b/build/release/ensure-sizzle.js index c3e4ed159..795760643 100644 --- a/build/release/ensure-sizzle.js +++ b/build/release/ensure-sizzle.js @@ -8,7 +8,7 @@ var fs = require( "fs" ), * @param {Function(string)} callback */ function getLatestSizzle( callback ) { - npm.load(function( err, npm ) { + npm.load( function( err, npm ) { if ( err ) { throw err; } @@ -17,8 +17,8 @@ function getLatestSizzle( callback ) { throw err; } callback( Object.keys( info )[ 0 ] ); - }); - }); + } ); + } ); } /** @@ -29,11 +29,12 @@ function getLatestSizzle( callback ) { function ensureSizzle( Release, callback ) { console.log(); console.log( "Checking Sizzle version..." ); - getLatestSizzle(function( latest ) { + getLatestSizzle( function( latest ) { var match = rversion.exec( fs.readFileSync( sizzleLoc, "utf8" ) ), 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 + @@ -44,7 +45,7 @@ function ensureSizzle( Release, callback ) { console.log( "Sizzle is latest (" + latest.green + ")" ); callback(); } - }); + } ); } module.exports = ensureSizzle; diff --git a/build/release/release-notes.js b/build/release/release-notes.js index 00cdc8659..f3f6a6ff2 100644 --- a/build/release/release-notes.js +++ b/build/release/release-notes.js @@ -3,16 +3,16 @@ * jQuery Release Note Generator */ -var http = require("http"), +var http = require( "http" ), extract = /<a href="\/ticket\/(\d+)" title="View ticket">(.*?)<[^"]+"component">\s*(\S+)/g, - version = process.argv[2]; + version = process.argv[ 2 ]; if ( !/^\d+\.\d+/.test( version ) ) { console.error( "Invalid version number: " + version ); process.exit( 1 ); } -http.request({ +http.request( { host: "bugs.jquery.com", port: 80, method: "GET", @@ -23,34 +23,36 @@ http.request({ res.on( "data", function( chunk ) { data.push( chunk ); - }); + } ); res.on( "end", function() { var match, cur, cat, - file = data.join(""); + file = data.join( "" ); - while ( (match = extract.exec( file )) ) { - if ( "#" + match[1] !== match[2] ) { - cat = match[3]; + while ( ( match = extract.exec( file ) ) ) { + if ( "#" + match[ 1 ] !== match[ 2 ] ) { + cat = match[ 3 ]; if ( !cur || cur !== cat ) { if ( cur ) { - console.log("</ul>"); + console.log( "</ul>" ); } cur = cat; - console.log( "<h3>" + cat.charAt(0).toUpperCase() + cat.slice(1) + "</h3>" ); - console.log("<ul>"); + console.log( + "<h3>" + cat.charAt( 0 ).toUpperCase() + cat.slice( 1 ) + "</h3>" + ); + console.log( "<ul>" ); } console.log( - " <li><a href=\"http://bugs.jquery.com/ticket/" + match[1] + "\">#" + - match[1] + ": " + match[2] + "</a></li>" + " <li><a href=\"http://bugs.jquery.com/ticket/" + match[ 1 ] + "\">#" + + match[ 1 ] + ": " + match[ 2 ] + "</a></li>" ); } } if ( cur ) { - console.log("</ul>"); + console.log( "</ul>" ); } - }); -}).end(); + } ); +} ).end(); diff --git a/build/tasks/build.js b/build/tasks/build.js index ead3deb19..750bac5b7 100644 --- a/build/tasks/build.js +++ b/build/tasks/build.js @@ -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,15 +51,17 @@ module.exports = function( grunt ) { */ function convert( name, path, contents ) { var amdName; + // Convert var modules if ( /.\/var\//.test( path ) ) { contents = contents - .replace( /define\([\w\W]*?return/, "var " + (/var\/([\w-]+)/.exec(name)[1]) + " =" ) + .replace( /define\([\w\W]*?return/, "var " + ( /var\/([\w-]+)/.exec( name )[ 1 ] ) + " =" ) .replace( rdefineEnd, "" ); // 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,13 +89,15 @@ module.exports = function( grunt ) { contents = contents .replace( /define\(\[[^\]]*\]\)[\W\n]+$/, "" ); } + // AMD Name - if ( (amdName = grunt.option( "amd" )) != null && /^exports\/amd$/.test( name ) ) { - if (amdName) { + if ( ( amdName = grunt.option( "amd" ) ) != null && /^exports\/amd$/.test( name ) ) { + if ( amdName ) { grunt.log.writeln( "Naming jQuery with AMD name: " + amdName ); } else { grunt.log.writeln( "AMD name now anonymous" ); } + // Remove the comma for anonymous defines contents = contents .replace( /(\s*)"jquery"(\,\s*)/, amdName ? "$1\"" + amdName + "\"$2" : "" ); @@ -121,7 +130,8 @@ module.exports = function( grunt ) { excludeList = function( list, prepend ) { if ( list ) { prepend = prepend ? prepend + "/" : ""; - list.forEach(function( module ) { + list.forEach( function( module ) { + // Exclude var modules as well if ( module === "var" ) { excludeList( @@ -130,20 +140,22 @@ 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 )) ) { + if ( !( module = /([\w-\/]+)\.js$/.exec( module ) ) ) { return; } + // Prepend folder name if passed // Remove .js extension - module = prepend + module[1]; + module = prepend + module[ 1 ]; } // Avoid infinite recursion if ( excluded.indexOf( module ) === -1 ) { excluder( "-" + module ); } - }); + } ); } }, /** @@ -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,10 +188,11 @@ module.exports = function( grunt ) { grunt.verbose.writeln( e ); } } + // Check removeWith list excludeList( removeWith[ module ] ); } else { - grunt.log.error( "Module \"" + module + "\" is a minimum requirement."); + grunt.log.error( "Module \"" + module + "\" is a minimum requirement." ); if ( module === "selector" ) { grunt.log.error( "If you meant to replace Sizzle, use -sizzle instead." @@ -215,13 +231,13 @@ module.exports = function( grunt ) { // Handle Sizzle exclusion // Replace with selector-native - if ( (index = excluded.indexOf( "sizzle" )) > -1 ) { + if ( ( index = excluded.indexOf( "sizzle" ) ) > -1 ) { config.rawText.selector = "define(['./selector-native']);"; excluded.splice( index, 1 ); } // Replace exports/global with a noop noConflict - if ( (index = excluded.indexOf( "exports/global" )) > -1 ) { + if ( ( index = excluded.indexOf( "exports/global" ) ) > -1 ) { config.rawText[ "exports/global" ] = "define(['../core']," + "function( jQuery ) {\njQuery.noConflict = function() {};\n});"; excluded.splice( index, 1 ); @@ -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,9 +279,10 @@ 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(",") : "") + + ( included.length ? included.join( "," ) : "" ) + "]);"; } @@ -272,8 +293,8 @@ module.exports = function( grunt ) { done(); }, function( err ) { done( err ); - }); - }); + } ); + } ); // Special "alias" task to make custom build creation less grawlix-y // Translation example @@ -289,6 +310,6 @@ module.exports = function( grunt ) { grunt.log.writeln( "Creating custom build...\n" ); - grunt.task.run([ "build:*:*" + (modules ? ":" + modules : ""), "uglify", "dist" ]); - }); + grunt.task.run( [ "build:*:*" + ( modules ? ":" + modules : "" ), "uglify", "dist" ] ); + } ); }; diff --git a/build/tasks/dist.js b/build/tasks/dist.js index 13e56336a..78ce2f254 100644 --- a/build/tasks/dist.js +++ b/build/tasks/dist.js @@ -21,14 +21,14 @@ module.exports = function( grunt ) { flags = Object.keys( this.flags ); // Combine all output target paths - paths = [].concat( stored, flags ).filter(function( path ) { + paths = [].concat( stored, flags ).filter( function( path ) { return path !== "*"; - }); + } ); // Ensure the dist files are pure ASCII nonascii = false; - distpaths.forEach(function( filename ) { + distpaths.forEach( function( filename ) { var i, c, text = fs.readFileSync( filename, "utf8" ); @@ -53,7 +53,7 @@ module.exports = function( grunt ) { } // Optionally copy dist files to other locations - paths.forEach(function( path ) { + paths.forEach( function( path ) { var created; if ( !/\/$/.test( path ) ) { @@ -63,9 +63,9 @@ module.exports = function( grunt ) { created = path + filename.replace( "dist/", "" ); grunt.file.write( created, text ); grunt.log.writeln( "File '" + created + "' created." ); - }); - }); + } ); + } ); return !nonascii; - }); + } ); }; diff --git a/build/tasks/install_jsdom.js b/build/tasks/install_jsdom.js index 21d67eb0e..73142b654 100644 --- a/build/tasks/install_jsdom.js +++ b/build/tasks/install_jsdom.js @@ -23,5 +23,5 @@ module.exports = function( grunt ) { args: [ "install", "jsdom@" + version ], opts: { stdio: "inherit" } }, this.async() ); - }); + } ); }; diff --git a/build/tasks/sourcemap.js b/build/tasks/sourcemap.js index 5f4d5232f..3e4144de0 100644 --- a/build/tasks/sourcemap.js +++ b/build/tasks/sourcemap.js @@ -3,11 +3,12 @@ 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 var text = fs.readFileSync( minLoc, "utf8" ) .replace( /\/\/# sourceMappingURL=\S+/, "" ); fs.writeFileSync( minLoc, text ); - }); + } ); }; diff --git a/build/tasks/testswarm.js b/build/tasks/testswarm.js index 473bc9e72..902b33428 100644 --- a/build/tasks/testswarm.js +++ b/build/tasks/testswarm.js @@ -14,11 +14,12 @@ 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 ); } timeout = timeout || 1000 * 60 * 15; - tests = grunt.config([ this.name, "tests" ]); + tests = grunt.config( [ this.name, "tests" ] ); if ( pull ) { jobName = "Pull <a href='https://github.com/jquery/jquery/pull/" + @@ -28,18 +29,18 @@ module.exports = function( grunt ) { commit + "'>" + commit.substr( 0, 10 ) + "</a>"; } - tests.forEach(function( test ) { + tests.forEach( function( test ) { runs[ test ] = config.testUrl + commit + "/test/index.html?module=" + test; - }); + } ); - testswarm.createClient({ + testswarm.createClient( { url: config.swarmUrl } ) .addReporter( testswarm.reporters.cli ) .auth( { id: config.authUsername, token: config.authToken - }) + } ) .addjob( { name: jobName, @@ -54,5 +55,5 @@ module.exports = function( grunt ) { done( passed ); } ); - }); + } ); }; diff --git a/package.json b/package.json index 43d24ba5d..f1d517209 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/ajax.js b/src/ajax.js index 9c1d6ca85..84ddc304a 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -1,4 +1,4 @@ -define([ +define( [ "./core", "./var/document", "./var/rnotwhite", @@ -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,16 +62,18 @@ function addToPrefiltersOrTransports( structure ) { dataTypes = dataTypeExpression.toLowerCase().match( rnotwhite ) || []; if ( jQuery.isFunction( func ) ) { + // For each dataType in the dataTypeExpression - while ( (dataType = dataTypes[i++]) ) { + while ( ( dataType = dataTypes[ i++ ] ) ) { + // Prepend if requested - if ( dataType[0] === "+" ) { + if ( dataType[ 0 ] === "+" ) { dataType = dataType.slice( 1 ) || "*"; - (structure[ dataType ] = structure[ dataType ] || []).unshift( func ); + ( structure[ dataType ] = structure[ dataType ] || [] ).unshift( func ); // Otherwise append } else { - (structure[ dataType ] = structure[ dataType ] || []).push( func ); + ( structure[ dataType ] = structure[ dataType ] || [] ).push( func ); } } } @@ -97,7 +100,7 @@ function inspectPrefiltersOrTransports( structure, options, originalOptions, jqX } else if ( seekingTransport ) { return !( selected = dataTypeOrTransport ); } - }); + } ); return selected; } @@ -113,7 +116,7 @@ function ajaxExtend( target, src ) { for ( key in src ) { if ( src[ key ] !== undefined ) { - ( flatOptions[ key ] ? target : ( deep || (deep = {}) ) )[ key ] = src[ key ]; + ( flatOptions[ key ] ? target : ( deep || ( deep = {} ) ) )[ key ] = src[ key ]; } } if ( deep ) { @@ -137,7 +140,7 @@ function ajaxHandleResponses( s, jqXHR, responses ) { while ( dataTypes[ 0 ] === "*" ) { dataTypes.shift(); if ( ct === undefined ) { - ct = s.mimeType || jqXHR.getResponseHeader("Content-Type"); + ct = s.mimeType || jqXHR.getResponseHeader( "Content-Type" ); } } @@ -155,9 +158,10 @@ function ajaxHandleResponses( s, jqXHR, responses ) { if ( dataTypes[ 0 ] in responses ) { finalDataType = dataTypes[ 0 ]; } else { + // Try convertible dataTypes for ( type in responses ) { - if ( !dataTypes[ 0 ] || s.converters[ type + " " + dataTypes[0] ] ) { + if ( !dataTypes[ 0 ] || s.converters[ type + " " + dataTypes[ 0 ] ] ) { finalDataType = type; break; } @@ -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 { @@ -277,7 +284,7 @@ function ajaxConvert( s, response, jqXHR, isSuccess ) { return { state: "success", data: response }; } -jQuery.extend({ +jQuery.extend( { // Counter for holding the number of active queries active: 0, @@ -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"), + 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, @@ -426,8 +448,8 @@ jQuery.extend({ if ( state === 2 ) { if ( !responseHeaders ) { responseHeaders = {}; - while ( (match = rheaders.exec( responseHeadersString )) ) { - responseHeaders[ match[1].toLowerCase() ] = match[ 2 ]; + while ( ( match = rheaders.exec( responseHeadersString ) ) ) { + responseHeaders[ match[ 1 ].toLowerCase() ] = match[ 2 ]; } } match = responseHeaders[ key.toLowerCase() ]; @@ -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; @@ -541,7 +567,7 @@ jQuery.extend({ // Watch for a new set of requests if ( fireGlobals && jQuery.active++ === 0 ) { - jQuery.event.trigger("ajaxStart"); + jQuery.event.trigger( "ajaxStart" ); } // Uppercase the type @@ -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; } @@ -594,8 +621,8 @@ jQuery.extend({ // Set the Accepts header for the server, depending on the dataType jqXHR.setRequestHeader( "Accept", - s.dataTypes[ 0 ] && s.accepts[ s.dataTypes[0] ] ? - s.accepts[ s.dataTypes[0] ] + + s.dataTypes[ 0 ] && s.accepts[ s.dataTypes[ 0 ] ] ? + s.accepts[ s.dataTypes[ 0 ] ] + ( s.dataTypes[ 0 ] !== "*" ? ", " + allTypes + "; q=0.01" : "" ) : s.accepts[ "*" ] ); @@ -642,8 +669,8 @@ jQuery.extend({ // Timeout if ( s.async && s.timeout > 0 ) { - timeoutTimer = window.setTimeout(function() { - jqXHR.abort("timeout"); + timeoutTimer = window.setTimeout( function() { + jqXHR.abort( "timeout" ); }, s.timeout ); } @@ -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; @@ -705,11 +734,11 @@ jQuery.extend({ // Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode. if ( s.ifModified ) { - modified = jqXHR.getResponseHeader("Last-Modified"); + modified = jqXHR.getResponseHeader( "Last-Modified" ); if ( modified ) { jQuery.lastModified[ cacheURL ] = modified; } - modified = jqXHR.getResponseHeader("etag"); + modified = jqXHR.getResponseHeader( "etag" ); if ( modified ) { jQuery.etag[ cacheURL ] = modified; } @@ -731,6 +760,7 @@ jQuery.extend({ isSuccess = !error; } } else { + // Extract error from statusText and normalize for non-aborts error = statusText; if ( status || !statusText ) { @@ -766,9 +796,10 @@ jQuery.extend({ if ( fireGlobals ) { globalEventContext.trigger( "ajaxComplete", [ jqXHR, s ] ); + // Handle the global AJAX counter if ( !( --jQuery.active ) ) { - jQuery.event.trigger("ajaxStop"); + jQuery.event.trigger( "ajaxStop" ); } } } @@ -783,10 +814,11 @@ jQuery.extend({ getScript: function( url, callback ) { return jQuery.get( url, undefined, callback, "script" ); } -}); +} ); 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; @@ -795,7 +827,7 @@ jQuery.each( [ "get", "post" ], function( i, method ) { } // The url can be an options object (which then must have .url) - return jQuery.ajax( jQuery.extend({ + return jQuery.ajax( jQuery.extend( { url: url, type: method, dataType: type, @@ -803,7 +835,7 @@ jQuery.each( [ "get", "post" ], function( i, method ) { success: callback }, jQuery.isPlainObject( url ) && url ) ); }; -}); +} ); return jQuery; -}); +} ); diff --git a/src/ajax/jsonp.js b/src/ajax/jsonp.js index f469344e0..666e5d1e6 100644 --- a/src/ajax/jsonp.js +++ b/src/ajax/jsonp.js @@ -1,4 +1,4 @@ -define([ +define( [ "../core", "./var/nonce", "./var/rquery", @@ -9,14 +9,14 @@ var oldCallbacks = [], rjsonp = /(=)\?(?=&|$)|\?\?/; // Default jsonp settings -jQuery.ajaxSetup({ +jQuery.ajaxSetup( { jsonp: "callback", jsonpCallback: function() { var callback = oldCallbacks.pop() || ( jQuery.expando + "_" + ( nonce++ ) ); this[ callback ] = true; return callback; } -}); +} ); // Detect, normalize options and install callbacks for jsonp requests jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) { @@ -26,7 +26,7 @@ jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) { "url" : typeof s.data === "string" && ( s.contentType || "" ) - .indexOf("application/x-www-form-urlencoded") === 0 && + .indexOf( "application/x-www-form-urlencoded" ) === 0 && rjsonp.test( s.data ) && "data" ); @@ -46,14 +46,14 @@ jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) { } // Use data converter to retrieve json after script execution - s.converters["script json"] = function() { + s.converters[ "script json" ] = function() { if ( !responseContainer ) { jQuery.error( callbackName + " was not called" ); } return responseContainer[ 0 ]; }; - // force json dataType + // Force json dataType s.dataTypes[ 0 ] = "json"; // Install callback @@ -63,7 +63,8 @@ jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) { }; // Clean-up function (fires after converters) - jqXHR.always(function() { + 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 ); } @@ -88,11 +90,11 @@ jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) { } responseContainer = overwritten = undefined; - }); + } ); // Delegate to script return "script"; } -}); +} ); -}); +} ); diff --git a/src/ajax/load.js b/src/ajax/load.js index 8326e9287..82f0cf308 100644 --- a/src/ajax/load.js +++ b/src/ajax/load.js @@ -1,4 +1,4 @@ -define([ +define( [ "../core", "../core/parseHTML", "../ajax", @@ -13,7 +13,7 @@ define([ jQuery.fn.load = function( url, params, callback ) { var selector, type, response, self = this, - off = url.indexOf(" "); + off = url.indexOf( " " ); if ( off > -1 ) { selector = jQuery.trim( url.slice( off ) ); @@ -34,7 +34,7 @@ jQuery.fn.load = function( url, params, callback ) { // If we have elements to modify, make the request if ( self.length > 0 ) { - jQuery.ajax({ + jQuery.ajax( { url: url, // If "type" variable is undefined, then "GET" method will be used. @@ -43,7 +43,7 @@ jQuery.fn.load = function( url, params, callback ) { type: type || "GET", dataType: "html", data: params - }).done(function( responseText ) { + } ).done( function( responseText ) { // Save response for use in complete callback response = arguments; @@ -52,7 +52,7 @@ jQuery.fn.load = function( url, params, callback ) { // If a selector was specified, locate the right elements in a dummy div // Exclude scripts to avoid IE 'Permission Denied' errors - jQuery("<div>").append( jQuery.parseHTML( responseText ) ).find( selector ) : + jQuery( "<div>" ).append( jQuery.parseHTML( responseText ) ).find( selector ) : // Otherwise use the full result responseText ); @@ -60,14 +60,14 @@ jQuery.fn.load = function( url, params, callback ) { // If the request succeeds, this function gets "data", "status", "jqXHR" // but they are ignored because response was set above. // If it fails, this function gets "jqXHR", "status", "error" - }).always( callback && function( jqXHR, status ) { + } ).always( callback && function( jqXHR, status ) { self.each( function() { callback.apply( self, response || [ jqXHR.responseText, status, jqXHR ] ); - }); - }); + } ); + } ); } return this; }; -}); +} ); diff --git a/src/ajax/parseJSON.js b/src/ajax/parseJSON.js index 3a96d15b9..11918b06d 100644 --- a/src/ajax/parseJSON.js +++ b/src/ajax/parseJSON.js @@ -1,4 +1,4 @@ -define([ +define( [ "../core" ], function( jQuery ) { @@ -10,4 +10,4 @@ jQuery.parseJSON = function( data ) { return jQuery.parseJSON; -}); +} ); diff --git a/src/ajax/parseXML.js b/src/ajax/parseXML.js index 962dc8887..6599aaf5b 100644 --- a/src/ajax/parseXML.js +++ b/src/ajax/parseXML.js @@ -1,4 +1,4 @@ -define([ +define( [ "../core" ], function( jQuery ) { @@ -24,4 +24,4 @@ jQuery.parseXML = function( data ) { return jQuery.parseXML; -}); +} ); diff --git a/src/ajax/script.js b/src/ajax/script.js index ede551708..60b1fb6b0 100644 --- a/src/ajax/script.js +++ b/src/ajax/script.js @@ -1,11 +1,11 @@ -define([ +define( [ "../core", "../var/document", "../ajax" ], function( jQuery, document ) { // Install script dataType -jQuery.ajaxSetup({ +jQuery.ajaxSetup( { accepts: { script: "text/javascript, application/javascript, " + "application/ecmascript, application/x-ecmascript" @@ -19,7 +19,7 @@ jQuery.ajaxSetup({ return text; } } -}); +} ); // Handle cache's special case and crossDomain jQuery.ajaxPrefilter( "script", function( s ) { @@ -29,19 +29,20 @@ jQuery.ajaxPrefilter( "script", function( s ) { if ( s.crossDomain ) { s.type = "GET"; } -}); +} ); // Bind script tag hack transport jQuery.ajaxTransport( "script", function( s ) { + // This transport only deals with cross domain requests if ( s.crossDomain ) { var script, callback; return { send: function( _, complete ) { - script = jQuery("<script>").prop({ + script = jQuery( "<script>" ).prop( { charset: s.scriptCharset, src: s.url - }).on( + } ).on( "load error", callback = function( evt ) { script.remove(); @@ -62,6 +63,6 @@ jQuery.ajaxTransport( "script", function( s ) { } }; } -}); +} ); -}); +} ); diff --git a/src/ajax/var/location.js b/src/ajax/var/location.js index 4c9cf4a4c..ff9578e99 100644 --- a/src/ajax/var/location.js +++ b/src/ajax/var/location.js @@ -1,3 +1,3 @@ -define(function() { +define( function() { return window.location; -}); +} ); diff --git a/src/ajax/var/nonce.js b/src/ajax/var/nonce.js index 0871aae88..83fd557c8 100644 --- a/src/ajax/var/nonce.js +++ b/src/ajax/var/nonce.js @@ -1,5 +1,5 @@ -define([ +define( [ "../../core" ], function( jQuery ) { return jQuery.now(); -}); +} ); diff --git a/src/ajax/var/rquery.js b/src/ajax/var/rquery.js index 500a77a08..0502146ca 100644 --- a/src/ajax/var/rquery.js +++ b/src/ajax/var/rquery.js @@ -1,3 +1,3 @@ -define(function() { - return (/\?/); -}); +define( function() { + return ( /\?/ ); +} ); diff --git a/src/ajax/xhr.js b/src/ajax/xhr.js index 545bb26c9..7ac141e64 100644 --- a/src/ajax/xhr.js +++ b/src/ajax/xhr.js @@ -1,4 +1,4 @@ -define([ +define( [ "../core", "../var/support", "../ajax" @@ -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 @@ -22,7 +24,7 @@ var xhrSuccessStatus = { support.cors = !!xhrSupported && ( "withCredentials" in xhrSupported ); support.ajax = xhrSupported = !!xhrSupported; -jQuery.ajaxTransport(function( options ) { +jQuery.ajaxTransport( function( options ) { var callback; // Cross domain only allowed if supported through XMLHttpRequest @@ -57,8 +59,8 @@ jQuery.ajaxTransport(function( options ) { // akin to a jigsaw puzzle, we simply never set it to be sure. // (it can always be set on a per-request basis or even using ajaxSetup) // For same-domain requests, won't change header if already provided. - if ( !options.crossDomain && !headers["X-Requested-With"] ) { - headers["X-Requested-With"] = "XMLHttpRequest"; + if ( !options.crossDomain && !headers[ "X-Requested-With" ] ) { + headers[ "X-Requested-With" ] = "XMLHttpRequest"; } // Set headers @@ -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) @@ -99,15 +103,17 @@ jQuery.ajaxTransport(function( options ) { // Listen to events xhr.onload = callback(); - xhr.onerror = callback("error"); + xhr.onerror = callback( "error" ); // Create the abort callback - callback = callback("abort"); + 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; @@ -122,6 +128,6 @@ jQuery.ajaxTransport(function( options ) { } }; } -}); +} ); -}); +} ); diff --git a/src/attributes.js b/src/attributes.js index fa2ef1ede..691e0c034 100644 --- a/src/attributes.js +++ b/src/attributes.js @@ -1,4 +1,4 @@ -define([ +define( [ "./core", "./attributes/attr", "./attributes/prop", @@ -8,4 +8,4 @@ define([ // Return jQuery for attributes-only inclusion return jQuery; -}); +} ); diff --git a/src/attributes/attr.js b/src/attributes/attr.js index 07576738a..f88808324 100644 --- a/src/attributes/attr.js +++ b/src/attributes/attr.js @@ -1,4 +1,4 @@ -define([ +define( [ "../core", "../core/access", "./support", @@ -9,19 +9,19 @@ define([ var boolHook, attrHandle = jQuery.expr.attrHandle; -jQuery.fn.extend({ +jQuery.fn.extend( { attr: function( name, value ) { return access( this, jQuery.attr, name, value, arguments.length > 1 ); }, removeAttr: function( name ) { - return this.each(function() { + return this.each( function() { jQuery.removeAttr( this, name ); - }); + } ); } -}); +} ); -jQuery.extend({ +jQuery.extend( { attr: function( elem, name, value ) { var ret, hooks, nType = elem.nodeType; @@ -91,7 +91,7 @@ jQuery.extend({ attrNames = value && value.match( rnotwhite ); if ( attrNames && elem.nodeType === 1 ) { - while ( ( name = attrNames[i++] ) ) { + while ( ( name = attrNames[ i++ ] ) ) { propName = jQuery.propFix[ name ] || name; // Boolean attributes get special treatment (#10870) @@ -105,12 +105,13 @@ jQuery.extend({ } } } -}); +} ); // Hooks for boolean attributes 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; @@ -135,6 +137,6 @@ jQuery.each( jQuery.expr.match.bool.source.match( /\w+/g ), function( i, name ) } return ret; }; -}); +} ); -}); +} ); diff --git a/src/attributes/classes.js b/src/attributes/classes.js index d0d1d989f..0ba7b86af 100644 --- a/src/attributes/classes.js +++ b/src/attributes/classes.js @@ -1,4 +1,4 @@ -define([ +define( [ "../core", "../var/rnotwhite", "../data/var/dataPriv", @@ -11,7 +11,7 @@ function getClass( elem ) { return elem.getAttribute && elem.getAttribute( "class" ) || ""; } -jQuery.fn.extend({ +jQuery.fn.extend( { addClass: function( value ) { var classes, elem, cur, curValue, clazz, j, finalValue, proceed = typeof value === "string" && value, @@ -19,12 +19,13 @@ jQuery.fn.extend({ len = this.length; if ( jQuery.isFunction( value ) ) { - return this.each(function( j ) { + return this.each( function( j ) { jQuery( this ).addClass( value.call( this, j, getClass( this ) ) ); - }); + } ); } if ( proceed ) { + // The disjunction here is for better compressibility (see removeClass) classes = ( value || "" ).match( rnotwhite ) || []; @@ -36,13 +37,13 @@ jQuery.fn.extend({ if ( cur ) { j = 0; - while ( (clazz = classes[j++]) ) { + while ( ( clazz = classes[ j++ ] ) ) { if ( cur.indexOf( " " + clazz + " " ) < 0 ) { cur += clazz + " "; } } - // 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 ); @@ -61,9 +62,9 @@ jQuery.fn.extend({ len = this.length; if ( jQuery.isFunction( value ) ) { - return this.each(function( j ) { + return this.each( function( j ) { jQuery( this ).removeClass( value.call( this, j, getClass( this ) ) ); - }); + } ); } if ( proceed ) { classes = ( value || "" ).match( rnotwhite ) || []; @@ -78,7 +79,8 @@ jQuery.fn.extend({ if ( cur ) { j = 0; - while ( (clazz = classes[j++]) ) { + while ( ( clazz = classes[ j++ ] ) ) { + // Remove *all* instances while ( cur.indexOf( " " + clazz + " " ) > -1 ) { cur = cur.replace( " " + clazz + " ", " " ); @@ -105,15 +107,15 @@ jQuery.fn.extend({ } if ( jQuery.isFunction( value ) ) { - return this.each(function( i ) { + return this.each( function( i ) { jQuery( this ).toggleClass( value.call( this, i, getClass( this ), stateVal ), stateVal ); - }); + } ); } - return this.each(function() { + return this.each( function() { var className, i, self, classNames; if ( type === "string" ) { @@ -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 ); } @@ -154,7 +156,7 @@ jQuery.fn.extend({ ); } } - }); + } ); }, hasClass: function( selector ) { @@ -162,8 +164,8 @@ jQuery.fn.extend({ i = 0, l = this.length; for ( ; i < l; i++ ) { - if ( this[i].nodeType === 1 && - ( " " + getClass( this[i] ) + " " ).replace( rclass, " " ) + if ( this[ i ].nodeType === 1 && + ( " " + getClass( this[ i ] ) + " " ).replace( rclass, " " ) .indexOf( className ) > -1 ) { return true; @@ -172,6 +174,6 @@ jQuery.fn.extend({ return false; } -}); +} ); -}); +} ); diff --git a/src/attributes/prop.js b/src/attributes/prop.js index 4c7b51e8c..06528b0a5 100644 --- a/src/attributes/prop.js +++ b/src/attributes/prop.js @@ -1,4 +1,4 @@ -define([ +define( [ "../core", "../core/access", "./support", @@ -7,19 +7,19 @@ define([ var rfocusable = /^(?:input|select|textarea|button)$/i; -jQuery.fn.extend({ +jQuery.fn.extend( { prop: function( name, value ) { return access( this, jQuery.prop, name, value, arguments.length > 1 ); }, removeProp: function( name ) { - return this.each(function() { + return this.each( function() { delete this[ jQuery.propFix[ name ] || name ]; - }); + } ); } -}); +} ); -jQuery.extend({ +jQuery.extend( { prop: function( elem, name, value ) { var ret, hooks, nType = elem.nodeType; @@ -67,7 +67,7 @@ jQuery.extend({ "for": "htmlFor", "class": "className" } -}); +} ); if ( !support.optSelected ) { jQuery.propHooks.selected = { @@ -81,7 +81,7 @@ if ( !support.optSelected ) { }; } -jQuery.each([ +jQuery.each( [ "tabIndex", "readOnly", "maxLength", @@ -94,6 +94,6 @@ jQuery.each([ "contentEditable" ], function() { jQuery.propFix[ this.toLowerCase() ] = this; -}); +} ); -}); +} ); diff --git a/src/attributes/support.js b/src/attributes/support.js index 68c96492c..13bcd4572 100644 --- a/src/attributes/support.js +++ b/src/attributes/support.js @@ -1,9 +1,9 @@ -define([ +define( [ "../var/document", "../var/support" ], function( document, support ) { -(function() { +( function() { var input = document.createElement( "input" ), select = document.createElement( "select" ), opt = select.appendChild( document.createElement( "option" ) ); @@ -29,8 +29,8 @@ define([ input.value = "t"; input.type = "radio"; support.radioValue = input.value === "t"; -})(); +} )(); return support; -}); +} ); diff --git a/src/attributes/val.js b/src/attributes/val.js index 1bb9072e6..9999d985b 100644 --- a/src/attributes/val.js +++ b/src/attributes/val.js @@ -1,4 +1,4 @@ -define([ +define( [ "../core", "./support", "../core/init" @@ -6,25 +6,30 @@ define([ var rreturn = /\r/g; -jQuery.fn.extend({ +jQuery.fn.extend( { val: function( value ) { var hooks, ret, isFunction, - elem = this[0]; + elem = this[ 0 ]; if ( !arguments.length ) { if ( elem ) { 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, "") : + ret.replace( rreturn, "" ) : + // Handle cases where value is null/undef or number ret == null ? "" : ret; } @@ -34,7 +39,7 @@ jQuery.fn.extend({ isFunction = jQuery.isFunction( value ); - return this.each(function( i ) { + return this.each( function( i ) { var val; if ( this.nodeType !== 1 ) { @@ -57,23 +62,24 @@ jQuery.fn.extend({ } else if ( jQuery.isArray( val ) ) { val = jQuery.map( val, function( value ) { return value == null ? "" : value + ""; - }); + } ); } hooks = jQuery.valHooks[ this.type ] || jQuery.valHooks[ this.nodeName.toLowerCase() ]; // If set returns undefined, fall back to normal setting - if ( !hooks || !("set" in hooks) || hooks.set( this, val, "value" ) === undefined ) { + if ( !hooks || !( "set" in hooks ) || hooks.set( this, val, "value" ) === undefined ) { this.value = val; } - }); + } ); } -}); +} ); -jQuery.extend({ +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; } } @@ -141,22 +149,22 @@ jQuery.extend({ } } } -}); +} ); // Radios and checkboxes getter/setter -jQuery.each([ "radio", "checkbox" ], function() { +jQuery.each( [ "radio", "checkbox" ], function() { jQuery.valHooks[ this ] = { set: function( elem, value ) { if ( jQuery.isArray( value ) ) { - return ( elem.checked = jQuery.inArray( jQuery(elem).val(), value ) > -1 ); + return ( elem.checked = jQuery.inArray( jQuery( elem ).val(), value ) > -1 ); } } }; if ( !support.checkOn ) { jQuery.valHooks[ this ].get = function( elem ) { - return elem.getAttribute("value") === null ? "on" : elem.value; + return elem.getAttribute( "value" ) === null ? "on" : elem.value; }; } -}); +} ); -}); +} ); diff --git a/src/callbacks.js b/src/callbacks.js index bec37ef54..b032c8f1c 100644 --- a/src/callbacks.js +++ b/src/callbacks.js @@ -1,4 +1,4 @@ -define([ +define( [ "./core", "./var/rnotwhite" ], function( jQuery, rnotwhite ) { @@ -8,7 +8,7 @@ function createOptions( options ) { var object = {}; jQuery.each( options.match( rnotwhite ) || [], function( _, flag ) { object[ flag ] = true; - }); + } ); return object; } @@ -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() { @@ -114,18 +121,19 @@ jQuery.Callbacks = function( options ) { queue.push( memory ); } - (function add( args ) { + ( function add( args ) { jQuery.each( args, function( _, arg ) { if ( jQuery.isFunction( arg ) ) { if ( !options.unique || !self.has( arg ) ) { list.push( arg ); } } else if ( arg && arg.length && jQuery.type( arg ) !== "string" ) { + // Inspect recursively add( arg ); } - }); - })( arguments ); + } ); + } )( arguments ); if ( memory && !firing ) { fire(); @@ -146,7 +154,7 @@ jQuery.Callbacks = function( options ) { firingIndex--; } } - }); + } ); return this; }, @@ -221,4 +229,4 @@ jQuery.Callbacks = function( options ) { }; return jQuery; -}); +} ); diff --git a/src/core.js b/src/core.js index e8024aaf1..3fec8f1cb 100644 --- a/src/core.js +++ b/src/core.js @@ -1,4 +1,4 @@ -define([ +define( [ "./var/arr", "./var/document", "./var/slice", @@ -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, @@ -79,9 +81,9 @@ jQuery.fn = jQuery.prototype = { }, map: function( callback ) { - return this.pushStack( jQuery.map(this, function( elem, i ) { + return this.pushStack( jQuery.map( this, function( elem, i ) { return callback.call( elem, i, elem ); - })); + } ) ); }, slice: function() { @@ -99,11 +101,11 @@ jQuery.fn = jQuery.prototype = { eq: function( i ) { var len = this.length, j = +i + ( i < 0 ? len : 0 ); - return this.pushStack( j >= 0 && j < len ? [ this[j] ] : [] ); + return this.pushStack( j >= 0 && j < len ? [ this[ j ] ] : [] ); }, end: function() { - return this.prevObject || this.constructor(null); + return this.prevObject || this.constructor( null ); }, // For internal use only. @@ -115,7 +117,7 @@ jQuery.fn = jQuery.prototype = { jQuery.extend = jQuery.fn.extend = function() { var options, name, src, copy, copyIsArray, clone, - target = arguments[0] || {}, + target = arguments[ 0 ] || {}, i = 1, length = arguments.length, deep = false; @@ -130,7 +132,7 @@ jQuery.extend = jQuery.fn.extend = function() { } // Handle case when target is a string or something (possible in deep copy) - if ( typeof target !== "object" && !jQuery.isFunction(target) ) { + if ( typeof target !== "object" && !jQuery.isFunction( target ) ) { target = {}; } @@ -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 ) { + if ( ( options = arguments[ i ] ) != null ) { + // Extend the base object for ( name in options ) { src = target[ name ]; @@ -154,15 +158,15 @@ jQuery.extend = jQuery.fn.extend = function() { } // Recurse if we're merging plain objects or arrays - if ( deep && copy && ( jQuery.isPlainObject(copy) || - (copyIsArray = jQuery.isArray(copy)) ) ) { + if ( deep && copy && ( jQuery.isPlainObject( copy ) || + ( copyIsArray = jQuery.isArray( copy ) ) ) ) { if ( copyIsArray ) { copyIsArray = false; - clone = src && jQuery.isArray(src) ? src : []; + clone = src && jQuery.isArray( src ) ? src : []; } else { - clone = src && jQuery.isPlainObject(src) ? src : {}; + clone = src && jQuery.isPlainObject( src ) ? src : {}; } // Never move original objects, clone them @@ -180,7 +184,8 @@ jQuery.extend = jQuery.fn.extend = function() { return target; }; -jQuery.extend({ +jQuery.extend( { + // Unique for each copy of jQuery on the page expando: "jQuery" + ( version + Math.random() ).replace( /\D/g, "" ), @@ -194,7 +199,7 @@ jQuery.extend({ noop: function() {}, isFunction: function( obj ) { - return jQuery.type(obj) === "function"; + return jQuery.type( obj ) === "function"; }, isArray: Array.isArray, @@ -204,14 +209,16 @@ 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 // adding 1 corrects loss of precision from parseFloat (#15100) - return !jQuery.isArray( obj ) && (obj - parseFloat( obj ) + 1) >= 0; + return !jQuery.isArray( obj ) && ( obj - parseFloat( obj ) + 1 ) >= 0; }, isPlainObject: function( obj ) { + // Not plain objects: // - Any object or value whose internal [[Class]] property is not "[object Object]" // - DOM nodes @@ -242,9 +249,10 @@ 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" : + class2type[ toString.call( obj ) ] || "object" : typeof obj; }, @@ -421,7 +429,7 @@ jQuery.extend({ // jQuery.support is not used in Core but other projects attach their // properties to it so it needs to exist. support: support -}); +} ); // JSHint would error on this code due to the Symbol not being defined in ES5. // Defining this global in .jshintrc would create a danger of using the global @@ -434,10 +442,10 @@ if ( typeof Symbol === "function" ) { /* jshint ignore: end */ // Populate the class2type map -jQuery.each("Boolean Number String Function Array Date RegExp Object Error".split(" "), -function(i, name) { +jQuery.each( "Boolean Number String Function Array Date RegExp Object Error".split( " " ), +function( i, name ) { class2type[ "[object " + name + "]" ] = name.toLowerCase(); -}); +} ); function isArrayLike( obj ) { @@ -457,4 +465,4 @@ function isArrayLike( obj ) { } return jQuery; -}); +} ); diff --git a/src/core/access.js b/src/core/access.js index a006ed919..19f79efa4 100644 --- a/src/core/access.js +++ b/src/core/access.js @@ -1,4 +1,4 @@ -define([ +define( [ "../core" ], function( jQuery ) { @@ -13,7 +13,7 @@ var access = function( elems, fn, key, value, chainable, emptyGet, raw ) { if ( jQuery.type( key ) === "object" ) { chainable = true; for ( i in key ) { - access( elems, fn, i, key[i], true, emptyGet, raw ); + access( elems, fn, i, key[ i ], true, emptyGet, raw ); } // Sets one value @@ -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 ) ) + ); } } } @@ -52,9 +57,9 @@ var access = function( elems, fn, key, value, chainable, emptyGet, raw ) { // Gets bulk ? fn.call( elems ) : - len ? fn( elems[0], key ) : emptyGet; + len ? fn( elems[ 0 ], key ) : emptyGet; }; return access; -}); +} ); diff --git a/src/core/init.js b/src/core/init.js index 861cb8351..a00d58791 100644 --- a/src/core/init.js +++ b/src/core/init.js @@ -1,5 +1,5 @@ // Initialize a jQuery object -define([ +define( [ "../core", "../var/document", "./var/rsingleTag", @@ -23,13 +23,13 @@ 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; // Handle HTML strings if ( typeof selector === "string" ) { - if ( selector[0] === "<" && + if ( selector[ 0 ] === "<" && selector[ selector.length - 1 ] === ">" && selector.length >= 3 ) { @@ -41,23 +41,24 @@ var rootjQuery, } // Match html or make sure no context is specified for #id - if ( match && (match[1] || !context) ) { + if ( match && ( match[ 1 ] || !context ) ) { // HANDLE: $(html) -> $(array) - if ( match[1] ) { - context = context instanceof jQuery ? context[0] : context; + if ( match[ 1 ] ) { + context = context instanceof jQuery ? context[ 0 ] : context; // Option to run scripts is true for back-compat // Intentionally let the error be thrown if parseHTML is not present jQuery.merge( this, jQuery.parseHTML( - match[1], + match[ 1 ], context && context.nodeType ? context.ownerDocument || context : document, true ) ); // HANDLE: $(html, props) - if ( rsingleTag.test( match[1] ) && jQuery.isPlainObject( context ) ) { + 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 ] ); @@ -73,11 +74,12 @@ var rootjQuery, // HANDLE: $(#id) } else { - elem = document.getElementById( match[2] ); + elem = document.getElementById( match[ 2 ] ); if ( elem ) { + // Inject the element directly into the jQuery object - this[0] = elem; + this[ 0 ] = elem; this.length = 1; } return this; @@ -95,7 +97,7 @@ var rootjQuery, // HANDLE: $(DOMElement) } else if ( selector.nodeType ) { - this[0] = selector; + this[ 0 ] = selector; this.length = 1; return this; @@ -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 ); } @@ -119,4 +122,4 @@ rootjQuery = jQuery( document ); return init; -}); +} ); diff --git a/src/core/parseHTML.js b/src/core/parseHTML.js index e7d7c63c8..30405363c 100644 --- a/src/core/parseHTML.js +++ b/src/core/parseHTML.js @@ -1,4 +1,4 @@ -define([ +define( [ "../core", "../var/document", "./var/rsingleTag", @@ -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 ); @@ -31,7 +32,7 @@ jQuery.parseHTML = function( data, context, keepScripts ) { // Single tag if ( parsed ) { - return [ context.createElement( parsed[1] ) ]; + return [ context.createElement( parsed[ 1 ] ) ]; } parsed = buildFragment( [ data ], context, scripts ); @@ -45,4 +46,4 @@ jQuery.parseHTML = function( data, context, keepScripts ) { return jQuery.parseHTML; -}); +} ); diff --git a/src/core/ready.js b/src/core/ready.js index 085d19a93..7a7ef5869 100644 --- a/src/core/ready.js +++ b/src/core/ready.js @@ -1,4 +1,4 @@ -define([ +define( [ "../core", "../var/document", "../deferred" @@ -8,13 +8,15 @@ define([ var readyList; jQuery.fn.ready = function( fn ) { + // Add the callback jQuery.ready.promise().done( fn ); return this; }; -jQuery.extend({ +jQuery.extend( { + // Is the DOM ready to be used? Set to true once it occurs. isReady: false, @@ -50,7 +52,7 @@ jQuery.extend({ // If there are functions bound, to execute readyList.resolveWith( document, [ jQuery ] ); } -}); +} ); /** * The ready event handler and self cleanup method @@ -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 ); @@ -90,4 +93,4 @@ jQuery.ready.promise = function( obj ) { // Kick off the DOM ready check even if the user does not jQuery.ready.promise(); -}); +} ); diff --git a/src/core/support.js b/src/core/support.js index 68d20e353..0609a700b 100644 --- a/src/core/support.js +++ b/src/core/support.js @@ -1,4 +1,4 @@ -define([ +define( [ "../var/document", "../var/support" ], function( document, support ) { @@ -8,11 +8,11 @@ define([ // collapse sibling forms: the second one becomes a child of the first one. // Because of that, this security measure has to be disabled in Safari 8. // https://bugs.webkit.org/show_bug.cgi?id=137337 -support.createHTMLDocument = (function() { +support.createHTMLDocument = ( function() { var body = document.implementation.createHTMLDocument( "" ).body; body.innerHTML = "<form></form><form></form>"; return body.childNodes.length === 2; -})(); +} )(); return support; -}); +} ); diff --git a/src/core/var/rsingleTag.js b/src/core/var/rsingleTag.js index a8176dc64..1a55ee39d 100644 --- a/src/core/var/rsingleTag.js +++ b/src/core/var/rsingleTag.js @@ -1,4 +1,5 @@ -define(function() { +define( function() { + // Match a standalone tag - return (/^<([\w-]+)\s*\/?>(?:<\/\1>|)$/); -}); + return ( /^<([\w-]+)\s*\/?>(?:<\/\1>|)$/ ); +} ); diff --git a/src/css.js b/src/css.js index 859985f9d..8a86ef55c 100644 --- a/src/css.js +++ b/src/css.js @@ -1,4 +1,4 @@ -define([ +define( [ "./core", "./var/pnum", "./core/access", @@ -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 @@ -47,7 +48,7 @@ function vendorPropName( name ) { } // Check for vendor prefixed names - var capName = name[0].toUpperCase() + name.slice(1), + var capName = name[ 0 ].toUpperCase() + name.slice( 1 ), i = cssPrefixes.length; while ( i-- ) { @@ -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 ) { @@ -138,7 +146,7 @@ function getWidthOrHeight( elem, name, extra ) { } // Computed unit is not pixels. Stop here and return. - if ( rnumnonpx.test(val) ) { + if ( rnumnonpx.test( val ) ) { return val; } @@ -163,7 +171,7 @@ function getWidthOrHeight( elem, name, extra ) { ) + "px"; } -jQuery.extend({ +jQuery.extend( { // Add in style property hooks for overriding the default // behavior of getting and setting a style property @@ -226,8 +234,9 @@ jQuery.extend({ type = typeof value; // Convert "+=" or "-=" to relative numbers (#7345) - if ( type === "string" && (ret = rcssNum.exec( value )) && ret[ 1 ] ) { + if ( type === "string" && ( ret = rcssNum.exec( value ) ) && ret[ 1 ] ) { value = adjustCSS( elem, name, ret ); + // Fixes bug #9237 type = "number"; } @@ -249,16 +258,17 @@ jQuery.extend({ } // If a hook was provided, use that value, otherwise just set the specified value - if ( !hooks || !("set" in hooks) || - (value = hooks.set( elem, value, extra )) !== undefined ) { + if ( !hooks || !( "set" in hooks ) || + ( value = hooks.set( elem, value, extra ) ) !== undefined ) { style[ name ] = value; } } 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 ) { + ( ret = hooks.get( elem, false, extra ) ) !== undefined ) { return ret; } @@ -301,9 +311,9 @@ jQuery.extend({ } return val; } -}); +} ); -jQuery.each([ "height", "width" ], function( i, name ) { +jQuery.each( [ "height", "width" ], function( i, name ) { jQuery.cssHooks[ name ] = { get: function( elem, computed, extra ) { if ( computed ) { @@ -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. @@ -320,7 +331,7 @@ jQuery.each([ "height", "width" ], function( i, name ) { ( !elem.getClientRects().length || !elem.getBoundingClientRect().width ) ? swap( elem, cssShow, function() { return getWidthOrHeight( elem, name, extra ); - }) : + } ) : getWidthOrHeight( elem, name, extra ); } }, @@ -338,7 +349,7 @@ jQuery.each([ "height", "width" ], function( i, name ) { ); } }; -}); +} ); // Support: Android 2.3 jQuery.cssHooks.marginRight = addGetHookIf( support.reliableMarginRight, @@ -351,7 +362,7 @@ jQuery.cssHooks.marginRight = addGetHookIf( support.reliableMarginRight, ); // These hooks are used by animate to expand properties -jQuery.each({ +jQuery.each( { margin: "", padding: "", border: "Width" @@ -362,7 +373,7 @@ jQuery.each({ expanded = {}, // Assumes a single number if not a string - parts = typeof value === "string" ? value.split(" ") : [ value ]; + parts = typeof value === "string" ? value.split( " " ) : [ value ]; for ( ; i < 4; i++ ) { expanded[ prefix + cssExpand[ i ] + suffix ] = @@ -376,9 +387,9 @@ jQuery.each({ if ( !rmargin.test( prefix ) ) { jQuery.cssHooks[ prefix + suffix ].set = setPositiveNumber; } -}); +} ); -jQuery.fn.extend({ +jQuery.fn.extend( { css: function( name, value ) { return access( this, function( elem, name, value ) { var styles, len, @@ -412,15 +423,15 @@ jQuery.fn.extend({ return state ? this.show() : this.hide(); } - return this.each(function() { + return this.each( function() { if ( isHidden( this ) ) { jQuery( this ).show(); } else { jQuery( this ).hide(); } - }); + } ); } -}); +} ); return jQuery; -}); +} ); diff --git a/src/css/addGetHookIf.js b/src/css/addGetHookIf.js index e12f3598d..9cd21f683 100644 --- a/src/css/addGetHookIf.js +++ b/src/css/addGetHookIf.js @@ -1,10 +1,12 @@ -define(function() { +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; @@ -12,11 +14,11 @@ function addGetHookIf( conditionFn, hookFn ) { } // Hook needed; redefine it so that the support test is not executed again. - return (this.get = hookFn).apply( this, arguments ); + return ( this.get = hookFn ).apply( this, arguments ); } }; } return addGetHookIf; -}); +} ); diff --git a/src/css/adjustCSS.js b/src/css/adjustCSS.js index 05fddd15b..48fcfec05 100644 --- a/src/css/adjustCSS.js +++ b/src/css/adjustCSS.js @@ -1,4 +1,4 @@ -define([ +define( [ "../core", "../var/rcssNum" ], function( jQuery, rcssNum ) { @@ -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"; @@ -38,12 +41,13 @@ function adjustCSS( elem, prop, valueParts, tween ) { // Update scale, tolerating zero or NaN from tween.cur() // Break the loop if scale is unchanged or perfect, or if we've just had enough. } while ( - scale !== (scale = currentValue() / initial) && scale !== 1 && --maxIterations + scale !== ( scale = currentValue() / initial ) && scale !== 1 && --maxIterations ); } if ( valueParts ) { initialInUnit = +initialInUnit || +initial || 0; + // Apply relative offset (+=/-=) if specified adjusted = valueParts[ 1 ] ? initialInUnit + ( valueParts[ 1 ] + 1 ) * valueParts[ 2 ] : @@ -58,4 +62,4 @@ function adjustCSS( elem, prop, valueParts, tween ) { } return adjustCSS; -}); +} ); diff --git a/src/css/curCSS.js b/src/css/curCSS.js index f60ab94de..be643ab54 100644 --- a/src/css/curCSS.js +++ b/src/css/curCSS.js @@ -1,10 +1,10 @@ -define([ +define( [ "../core", "./var/rnumnonpx", "./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 + "" : @@ -53,4 +54,4 @@ function curCSS( elem, name, computed ) { } return curCSS; -}); +} ); diff --git a/src/css/hiddenVisibleSelectors.js b/src/css/hiddenVisibleSelectors.js index b4d7482e8..9a8a28cf8 100644 --- a/src/css/hiddenVisibleSelectors.js +++ b/src/css/hiddenVisibleSelectors.js @@ -1,4 +1,4 @@ -define([ +define( [ "../core", "../selector" ], function( jQuery ) { @@ -10,4 +10,4 @@ jQuery.expr.filters.visible = function( elem ) { return !!( elem.offsetWidth || elem.offsetHeight || elem.getClientRects().length ); }; -}); +} ); diff --git a/src/css/showHide.js b/src/css/showHide.js index d0cca589b..35e15bde8 100644 --- a/src/css/showHide.js +++ b/src/css/showHide.js @@ -1,4 +1,4 @@ -define([ +define( [ "../data/var/dataPriv" ], function( dataPriv ) { @@ -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" ) || ""; } @@ -44,4 +45,4 @@ function showHide( elements, show ) { return showHide; -}); +} ); diff --git a/src/css/support.js b/src/css/support.js index 522406943..0758fa8a4 100644 --- a/src/css/support.js +++ b/src/css/support.js @@ -1,11 +1,11 @@ -define([ +define( [ "../core", "../var/document", "../var/documentElement", "../var/support" ], function( jQuery, document, documentElement, support ) { -(function() { +( function() { var pixelPositionVal, boxSizingReliableVal, pixelMarginRightVal, container = document.createElement( "div" ), div = document.createElement( "div" ); @@ -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;" + @@ -97,9 +101,9 @@ define([ return ret; } - }); -})(); + } ); +} )(); return support; -}); +} ); diff --git a/src/css/var/cssExpand.js b/src/css/var/cssExpand.js index 91e90a88a..9f8194dc8 100644 --- a/src/css/var/cssExpand.js +++ b/src/css/var/cssExpand.js @@ -1,3 +1,3 @@ -define(function() { +define( function() { return [ "Top", "Right", "Bottom", "Left" ]; -}); +} ); diff --git a/src/css/var/getStyles.js b/src/css/var/getStyles.js index 31dfc298e..1fa915d58 100644 --- a/src/css/var/getStyles.js +++ b/src/css/var/getStyles.js @@ -1,4 +1,4 @@ -define(function() { +define( function() { return function( elem ) { // Support: IE<=11+, Firefox<=30+ (#15098, #14150) @@ -12,4 +12,4 @@ define(function() { return view.getComputedStyle( elem ); }; -}); +} ); diff --git a/src/css/var/isHidden.js b/src/css/var/isHidden.js index c29f527ae..7997efff1 100644 --- a/src/css/var/isHidden.js +++ b/src/css/var/isHidden.js @@ -1,14 +1,16 @@ -define([ +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; return jQuery.css( elem, "display" ) === "none" || !jQuery.contains( elem.ownerDocument, elem ); }; -}); +} ); diff --git a/src/css/var/rmargin.js b/src/css/var/rmargin.js index da0438db6..9be221243 100644 --- a/src/css/var/rmargin.js +++ b/src/css/var/rmargin.js @@ -1,3 +1,3 @@ -define(function() { - return (/^margin/); -}); +define( function() { + return ( /^margin/ ); +} ); diff --git a/src/css/var/rnumnonpx.js b/src/css/var/rnumnonpx.js index c93be2850..ed13f0b98 100644 --- a/src/css/var/rnumnonpx.js +++ b/src/css/var/rnumnonpx.js @@ -1,5 +1,5 @@ -define([ +define( [ "../../var/pnum" ], function( pnum ) { return new RegExp( "^(" + pnum + ")(?!px)[a-z%]+$", "i" ); -}); +} ); diff --git a/src/css/var/swap.js b/src/css/var/swap.js index dbf639729..b6d3b679f 100644 --- a/src/css/var/swap.js +++ b/src/css/var/swap.js @@ -1,4 +1,4 @@ -define(function() { +define( function() { // A method for quickly swapping in/out CSS properties to get correct calculations. return function( elem, options, callback, args ) { @@ -21,4 +21,4 @@ return function( elem, options, callback, args ) { return ret; }; -}); +} ); diff --git a/src/data.js b/src/data.js index 80117d12e..d2855dde1 100644 --- a/src/data.js +++ b/src/data.js @@ -1,4 +1,4 @@ -define([ +define( [ "./core", "./core/access", "./data/var/dataPriv", @@ -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 ) : @@ -47,7 +48,7 @@ function dataAttr( elem, key, data ) { return data; } -jQuery.extend({ +jQuery.extend( { hasData: function( elem ) { return dataUser.hasData( elem ) || dataPriv.hasData( elem ); }, @@ -69,9 +70,9 @@ jQuery.extend({ _removeData: function( elem, name ) { dataPriv.remove( elem, name ); } -}); +} ); -jQuery.fn.extend({ +jQuery.fn.extend( { data: function( key, value ) { var i, name, data, elem = this[ 0 ], @@ -91,7 +92,7 @@ jQuery.fn.extend({ if ( attrs[ i ] ) { name = attrs[ i ].name; if ( name.indexOf( "data-" ) === 0 ) { - name = jQuery.camelCase( name.slice(5) ); + name = jQuery.camelCase( name.slice( 5 ) ); dataAttr( elem, name, data[ name ] ); } } @@ -105,9 +106,9 @@ jQuery.fn.extend({ // Sets multiple values if ( typeof key === "object" ) { - return this.each(function() { + return this.each( function() { dataUser.set( this, key ); - }); + } ); } return access( this, function( value ) { @@ -139,20 +140,20 @@ jQuery.fn.extend({ } // Set the data... - this.each(function() { + this.each( function() { // We always store the camelCased key dataUser.set( this, key, value ); - }); + } ); }, null, value, arguments.length > 1, null, true ); }, removeData: function( key ) { - return this.each(function() { + return this.each( function() { dataUser.remove( this, key ); - }); + } ); } -}); +} ); return jQuery; -}); +} ); diff --git a/src/data/Data.js b/src/data/Data.js index 5268f3f2c..476b3e1e2 100644 --- a/src/data/Data.js +++ b/src/data/Data.js @@ -1,4 +1,4 @@ -define([ +define( [ "../core", "../var/rnotwhite", "./accepts" @@ -29,7 +29,7 @@ Data.prototype = { value: value, writable: true, configurable: true - }); + } ); } return owner[ this.expando ]; }, @@ -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 @@ -157,4 +157,4 @@ Data.prototype = { }; return Data; -}); +} ); diff --git a/src/data/accepts.js b/src/data/accepts.js index 291c7b475..24e2f0ef0 100644 --- a/src/data/accepts.js +++ b/src/data/accepts.js @@ -1,4 +1,4 @@ -define([ +define( [ "../core" ], function( jQuery ) { @@ -6,6 +6,7 @@ define([ * Determines whether an object can have data */ jQuery.acceptData = function( owner ) { + // Accepts only: // - Node // - Node.ELEMENT_NODE @@ -17,4 +18,4 @@ jQuery.acceptData = function( owner ) { }; return jQuery.acceptData; -}); +} ); diff --git a/src/data/var/dataPriv.js b/src/data/var/dataPriv.js index 24399e468..9a1343ce1 100644 --- a/src/data/var/dataPriv.js +++ b/src/data/var/dataPriv.js @@ -1,5 +1,5 @@ -define([ +define( [ "../Data" ], function( Data ) { return new Data(); -}); +} ); diff --git a/src/data/var/dataUser.js b/src/data/var/dataUser.js index 24399e468..9a1343ce1 100644 --- a/src/data/var/dataUser.js +++ b/src/data/var/dataUser.js @@ -1,5 +1,5 @@ -define([ +define( [ "../Data" ], function( Data ) { return new Data(); -}); +} ); diff --git a/src/deferred.js b/src/deferred.js index 216baabb0..e1af425d4 100644 --- a/src/deferred.js +++ b/src/deferred.js @@ -1,4 +1,4 @@ -define([ +define( [ "./core", "./var/slice", "./callbacks" @@ -11,18 +11,19 @@ function Thrower( ex ) { throw ex; } -jQuery.extend({ +jQuery.extend( { Deferred: function( func ) { var tuples = [ + // action, add listener, callbacks, // ... .then handlers, argument index, [final state] - [ "notify", "progress", jQuery.Callbacks("memory"), - jQuery.Callbacks("memory"), 2 ], - [ "resolve", "done", jQuery.Callbacks("once memory"), - jQuery.Callbacks("once memory"), 0, "resolved" ], - [ "reject", "fail", jQuery.Callbacks("once memory"), - jQuery.Callbacks("once memory"), 1, "rejected" ] + [ "notify", "progress", jQuery.Callbacks( "memory" ), + jQuery.Callbacks( "memory" ), 2 ], + [ "resolve", "done", jQuery.Callbacks( "once memory" ), + jQuery.Callbacks( "once memory" ), 0, "resolved" ], + [ "reject", "fail", jQuery.Callbacks( "once memory" ), + jQuery.Callbacks( "once memory" ), 1, "rejected" ] ], state = "pending", promise = { @@ -36,19 +37,21 @@ 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 ) { + 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 ] ]; // deferred.progress(function() { bind to newDefer or newDefer.notify }) // deferred.done(function() { bind to newDefer or newDefer.resolve }) // deferred.fail(function() { bind to newDefer or newDefer.reject }) - deferred[ tuple[1] ](function() { + deferred[ tuple[ 1 ] ]( function() { var returned = fn && fn.apply( this, arguments ); if ( returned && jQuery.isFunction( returned.promise ) ) { returned.promise() @@ -61,10 +64,10 @@ jQuery.extend({ fn ? [ returned ] : arguments ); } - }); - }); + } ); + } ); fns = null; - }).promise(); + } ).promise(); }, then: function( onFulfilled, onRejected, onProgress ) { var maxDepth = 0; @@ -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 ) { @@ -181,7 +187,8 @@ jQuery.extend({ }; } - return jQuery.Deferred(function( newDefer ) { + return jQuery.Deferred( function( newDefer ) { + // progress_handlers.add( ... ) tuples[ 0 ][ 3 ].add( resolve( @@ -215,8 +222,9 @@ jQuery.extend({ Thrower ) ); - }).promise(); + } ).promise(); }, + // Get a promise for this deferred // If obj is provided, the promise aspect is added to the object promise: function( obj ) { @@ -233,12 +241,13 @@ jQuery.extend({ // promise.progress = list.add // promise.done = list.add // promise.fail = list.add - promise[ tuple[1] ] = list.add; + promise[ tuple[ 1 ] ] = list.add; // Handle state if ( stateString ) { list.add( function() { + // state = "resolved" (i.e., fulfilled) // state = "rejected" state = stateString; @@ -261,16 +270,16 @@ jQuery.extend({ // deferred.notify = function() { deferred.notifyWith(...) } // deferred.resolve = function() { deferred.resolveWith(...) } // deferred.reject = function() { deferred.rejectWith(...) } - deferred[ tuple[0] ] = function() { - deferred[ tuple[0] + "With" ]( this === deferred ? promise : this, arguments ); + deferred[ tuple[ 0 ] ] = function() { + deferred[ tuple[ 0 ] + "With" ]( this === deferred ? promise : this, arguments ); return this; }; // deferred.notifyWith = list.fireWith // deferred.resolveWith = list.fireWith // deferred.rejectWith = list.fireWith - deferred[ tuple[0] + "With" ] = list.fireWith; - }); + deferred[ tuple[ 0 ] + "With" ] = list.fireWith; + } ); // Make the deferred a promise promise.promise( deferred ); @@ -320,14 +329,14 @@ jQuery.extend({ resolveContexts = new Array( length ); for ( ; i < length; i++ ) { if ( resolveValues[ i ] && - jQuery.isFunction( (method = resolveValues[ i ].promise) ) ) { + jQuery.isFunction( ( method = resolveValues[ i ].promise ) ) ) { method.call( resolveValues[ i ] ) .progress( updateFunc( i, progressContexts, progressValues ) ) .done( updateFunc( i, resolveContexts, resolveValues ) ) .fail( master.reject ); } else if ( resolveValues[ i ] && - jQuery.isFunction( (method = resolveValues[ i ].then) ) ) { + jQuery.isFunction( ( method = resolveValues[ i ].then ) ) ) { method.call( resolveValues[ i ], @@ -348,7 +357,7 @@ jQuery.extend({ return master.promise(); } -}); +} ); return jQuery; -}); +} ); diff --git a/src/deprecated.js b/src/deprecated.js index 994b22848..dfb13e4ae 100644 --- a/src/deprecated.js +++ b/src/deprecated.js @@ -1,2 +1,2 @@ -define(function() { -}); +define( function() { +} ); diff --git a/src/dimensions.js b/src/dimensions.js index fa389bccf..30b55fbc0 100644 --- a/src/dimensions.js +++ b/src/dimensions.js @@ -1,4 +1,4 @@ -define([ +define( [ "./core", "./core/access", "./css" @@ -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 ) : @@ -45,8 +47,8 @@ jQuery.each( { Height: "height", Width: "width" }, function( name, type ) { jQuery.style( elem, type, value, extra ); }, type, chainable ? margin : undefined, chainable, null ); }; - }); -}); + } ); +} ); return jQuery; -}); +} ); diff --git a/src/effects.js b/src/effects.js index 40da88705..90ac4b1e6 100644 --- a/src/effects.js +++ b/src/effects.js @@ -1,4 +1,4 @@ -define([ +define( [ "./core", "./var/document", "./var/rcssNum", @@ -34,9 +34,9 @@ function raf() { // Animations created synchronously will run synchronously function createFxNow() { - window.setTimeout(function() { + window.setTimeout( function() { fxNow = undefined; - }); + } ); return ( fxNow = jQuery.now() ); } @@ -67,7 +67,7 @@ function createTween( value, prop, animation ) { index = 0, length = collection.length; for ( ; index < length; index++ ) { - if ( (tween = collection[ index ].call( animation, prop, value )) ) { + if ( ( tween = collection[ index ].call( animation, prop, value ) ) ) { // We're done with this property return tween; @@ -99,15 +99,16 @@ function defaultPrefilter( elem, props, opts ) { } hooks.unqueued++; - anim.always(function() { + anim.always( function() { + // Ensure the complete handler is called before this completes - anim.always(function() { + anim.always( function() { hooks.unqueued--; if ( !jQuery.queue( elem, "fx" ).length ) { hooks.empty.fire(); } - }); - }); + } ); + } ); } // Detect show/hide animations @@ -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 @@ -163,9 +165,9 @@ function defaultPrefilter( elem, props, opts ) { // Restore the original display value at the end of pure show/hide animations if ( !propTween ) { - anim.done(function() { + anim.done( function() { style.display = restoreDisplay; - }); + } ); if ( restoreDisplay == null ) { display = style.display; restoreDisplay = display === "none" ? "" : display; @@ -178,11 +180,11 @@ function defaultPrefilter( elem, props, opts ) { if ( opts.overflow ) { style.overflow = "hidden"; - anim.always(function() { + anim.always( function() { style.overflow = opts.overflow[ 0 ]; style.overflowX = opts.overflow[ 1 ]; style.overflowY = opts.overflow[ 2 ]; - }); + } ); } // Implement show/hide animations @@ -210,7 +212,8 @@ function defaultPrefilter( elem, props, opts ) { } /* jshint -W083 */ - anim.done(function() { + anim.done( function() { + // The final step of a "hide" animation is actually hiding the element if ( !hidden ) { showHide( [ elem ] ); @@ -219,7 +222,7 @@ function defaultPrefilter( elem, props, opts ) { for ( prop in orig ) { jQuery.style( elem, prop, orig[ prop ] ); } - }); + } ); } // Per-property setup @@ -277,15 +280,17 @@ 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; - }), + } ), tick = function() { if ( stopped ) { return false; } 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, @@ -297,7 +302,7 @@ function Animation( elem, properties, options ) { animation.tweens[ index ].run( percent ); } - deferred.notifyWith( elem, [ animation, percent, remaining ]); + deferred.notifyWith( elem, [ animation, percent, remaining ] ); if ( percent < 1 && length ) { return remaining; @@ -306,7 +311,7 @@ function Animation( elem, properties, options ) { return false; } }, - animation = deferred.promise({ + animation = deferred.promise( { elem: elem, props: jQuery.extend( {}, properties ), opts: jQuery.extend( true, { @@ -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; @@ -345,7 +351,7 @@ function Animation( elem, properties, options ) { } return this; } - }), + } ), props = animation.props; propFilter( props, animation.opts.specialEasing ); @@ -372,7 +378,7 @@ function Animation( elem, properties, options ) { elem: elem, anim: animation, queue: animation.opts.queue - }) + } ) ); // attach callbacks from options @@ -420,7 +426,7 @@ jQuery.Animation = jQuery.extend( Animation, { Animation.prefilters.push( callback ); } } -}); +} ); jQuery.speed = function( speed, easing, fn ) { var opt = speed && typeof speed === "object" ? jQuery.extend( {}, speed ) : { @@ -461,19 +467,20 @@ jQuery.speed = function( speed, easing, fn ) { return opt; }; -jQuery.fn.extend({ +jQuery.fn.extend( { fadeTo: function( speed, to, easing, callback ) { // Show any hidden elements after setting opacity to 0 return this.filter( isHidden ).css( "opacity", 0 ).show() // Animate to the value specified - .end().animate({ opacity: to }, speed, easing, callback ); + .end().animate( { opacity: to }, speed, easing, callback ); }, animate: function( prop, speed, easing, callback ) { var empty = jQuery.isEmptyObject( prop ), optall = jQuery.speed( speed, easing, callback ), doAnimation = function() { + // Operate on a copy of prop so per-property easing won't be lost var anim = Animation( this, jQuery.extend( {}, prop ), optall ); @@ -504,7 +511,7 @@ jQuery.fn.extend({ this.queue( type || "fx", [] ); } - return this.each(function() { + return this.each( function() { var dequeue = true, index = type != null && type + "queueHooks", timers = jQuery.timers, @@ -524,7 +531,7 @@ jQuery.fn.extend({ for ( index = timers.length; index--; ) { if ( timers[ index ].elem === this && - (type == null || timers[ index ].queue === type) ) { + ( type == null || timers[ index ].queue === type ) ) { timers[ index ].anim.stop( gotoEnd ); dequeue = false; @@ -538,13 +545,13 @@ jQuery.fn.extend({ if ( dequeue || !gotoEnd ) { jQuery.dequeue( this, type ); } - }); + } ); }, finish: function( type ) { if ( type !== false ) { type = type || "fx"; } - return this.each(function() { + return this.each( function() { var index, data = dataPriv.get( this ), queue = data[ type + "queue" ], @@ -579,24 +586,24 @@ jQuery.fn.extend({ // Turn off finishing flag delete data.finish; - }); + } ); } -}); +} ); -jQuery.each([ "toggle", "show", "hide" ], function( i, name ) { +jQuery.each( [ "toggle", "show", "hide" ], function( i, name ) { var cssFn = jQuery.fn[ name ]; jQuery.fn[ name ] = function( speed, easing, callback ) { return speed == null || typeof speed === "boolean" ? cssFn.apply( this, arguments ) : this.animate( genFx( name, true ), speed, easing, callback ); }; -}); +} ); // Generate shortcuts for custom animations -jQuery.each({ - slideDown: genFx("show"), - slideUp: genFx("hide"), - slideToggle: genFx("toggle"), +jQuery.each( { + slideDown: genFx( "show" ), + slideUp: genFx( "hide" ), + slideToggle: genFx( "toggle" ), fadeIn: { opacity: "show" }, fadeOut: { opacity: "hide" }, fadeToggle: { opacity: "toggle" } @@ -604,7 +611,7 @@ jQuery.each({ jQuery.fn[ name ] = function( speed, easing, callback ) { return this.animate( props, speed, easing, callback ); }; -}); +} ); jQuery.timers = []; jQuery.fx.tick = function() { @@ -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,9 +667,10 @@ jQuery.fx.stop = function() { jQuery.fx.speeds = { slow: 600, fast: 200, + // Default speed _default: 400 }; return jQuery; -}); +} ); diff --git a/src/effects/Tween.js b/src/effects/Tween.js index d7cd8e606..d26ddd918 100644 --- a/src/effects/Tween.js +++ b/src/effects/Tween.js @@ -1,4 +1,4 @@ -define([ +define( [ "../core", "../css" ], function( jQuery ) { @@ -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. @@ -116,4 +118,4 @@ jQuery.fx = Tween.prototype.init; // Back Compat <1.8 extension point jQuery.fx.step = {}; -}); +} ); diff --git a/src/effects/animatedSelector.js b/src/effects/animatedSelector.js index bc5a3d6c1..d84c9c703 100644 --- a/src/effects/animatedSelector.js +++ b/src/effects/animatedSelector.js @@ -1,13 +1,13 @@ -define([ +define( [ "../core", "../selector", "../effects" ], function( jQuery ) { jQuery.expr.filters.animated = function( elem ) { - return jQuery.grep(jQuery.timers, function( fn ) { + return jQuery.grep( jQuery.timers, function( fn ) { return elem === fn.elem; - }).length; + } ).length; }; -}); +} ); diff --git a/src/event.js b/src/event.js index 156bc016a..8a059ca8a 100644 --- a/src/event.js +++ b/src/event.js @@ -1,4 +1,4 @@ -define([ +define( [ "./core", "./var/document", "./var/rnotwhite", @@ -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,16 +79,18 @@ 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++ ); } return elem.each( function() { jQuery.event.add( this, types, fn, data, selector ); - }); + } ); } /* @@ -119,11 +126,12 @@ jQuery.event = { } // Init the element's event structure and main handler, if this is the first - if ( !(events = elemData.events) ) { + if ( !( events = elemData.events ) ) { events = elemData.events = {}; } - if ( !(eventHandle = elemData.handle) ) { + 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 ? @@ -135,9 +143,9 @@ jQuery.event = { types = ( types || "" ).match( rnotwhite ) || [ "" ]; t = types.length; while ( t-- ) { - tmp = rtypenamespace.exec( types[t] ) || []; - type = origType = tmp[1]; - namespaces = ( tmp[2] || "" ).split( "." ).sort(); + tmp = rtypenamespace.exec( types[ t ] ) || []; + type = origType = tmp[ 1 ]; + namespaces = ( tmp[ 2 ] || "" ).split( "." ).sort(); // There *must* be a type, no attaching namespace-only handlers if ( !type ) { @@ -154,7 +162,7 @@ jQuery.event = { special = jQuery.event.special[ type ] || {}; // handleObj is passed to all event handlers - handleObj = jQuery.extend({ + handleObj = jQuery.extend( { type: type, origType: origType, data: data, @@ -162,11 +170,11 @@ jQuery.event = { guid: handler.guid, selector: selector, needsContext: selector && jQuery.expr.match.needsContext.test( selector ), - namespace: namespaces.join(".") + namespace: namespaces.join( "." ) }, handleObjIn ); // Init the event handler queue if we're the first - if ( !(handlers = events[ type ]) ) { + if ( !( handlers = events[ type ] ) ) { handlers = events[ type ] = []; handlers.delegateCount = 0; @@ -209,7 +217,7 @@ jQuery.event = { special, handlers, type, namespaces, origType, elemData = dataPriv.hasData( elem ) && dataPriv.get( elem ); - if ( !elemData || !(events = elemData.events) ) { + if ( !elemData || !( events = elemData.events ) ) { return; } @@ -217,9 +225,9 @@ jQuery.event = { types = ( types || "" ).match( rnotwhite ) || [ "" ]; t = types.length; while ( t-- ) { - tmp = rtypenamespace.exec( types[t] ) || []; - type = origType = tmp[1]; - namespaces = ( tmp[2] || "" ).split( "." ).sort(); + tmp = rtypenamespace.exec( types[ t ] ) || []; + type = origType = tmp[ 1 ]; + namespaces = ( tmp[ 2 ] || "" ).split( "." ).sort(); // Unbind all events (on this namespace, if provided) for the element if ( !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; @@ -279,7 +288,7 @@ jQuery.event = { var i, cur, tmp, bubbleType, ontype, handle, special, eventPath = [ elem || document ], type = hasOwn.call( event, "type" ) ? event.type : event, - namespaces = hasOwn.call( event, "namespace" ) ? event.namespace.split(".") : []; + namespaces = hasOwn.call( event, "namespace" ) ? event.namespace.split( "." ) : []; cur = tmp = elem = elem || document; @@ -293,13 +302,14 @@ jQuery.event = { return; } - if ( type.indexOf(".") > -1 ) { + if ( type.indexOf( "." ) > -1 ) { + // Namespaced trigger; create a regexp to match event type in handle() - namespaces = type.split("."); + namespaces = type.split( "." ); type = namespaces.shift(); namespaces.sort(); } - ontype = type.indexOf(":") < 0 && "on" + type; + ontype = type.indexOf( ":" ) < 0 && "on" + type; // Caller can pass in a jQuery.Event object, Object, or just an event type string event = event[ jQuery.expando ] ? @@ -308,9 +318,9 @@ jQuery.event = { // Trigger bitmask: & 1 for native handlers; & 2 for jQuery (always true) event.isTrigger = onlyHandlers ? 2 : 3; - event.namespace = namespaces.join("."); + event.namespace = namespaces.join( "." ); event.rnamespace = event.namespace ? - new RegExp( "(^|\\.)" + namespaces.join("\\.(?:.*\\.|)") + "(\\.|$)" ) : + new RegExp( "(^|\\.)" + namespaces.join( "\\.(?:.*\\.|)" ) + "(\\.|$)" ) : null; // Clean up the event in case it is being reused @@ -344,14 +354,14 @@ jQuery.event = { } // Only add window if we got to document (e.g., not plain obj or detached DOM) - if ( tmp === (elem.ownerDocument || document) ) { + if ( tmp === ( elem.ownerDocument || document ) ) { eventPath.push( tmp.defaultView || tmp.parentWindow || window ); } } // Fire handlers on the event path i = 0; - while ( (cur = eventPath[i++]) && !event.isPropagationStopped() ) { + while ( ( cur = eventPath[ i++ ] ) && !event.isPropagationStopped() ) { event.type = i > 1 ? bubbleType : @@ -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. @@ -419,7 +430,7 @@ jQuery.event = { special = jQuery.event.special[ event.type ] || {}; // Use the fix-ed jQuery.Event rather than the (read-only) native event - args[0] = event; + args[ 0 ] = event; event.delegateTarget = this; // Call the preDispatch hook for the mapped type, and let it bail if desired @@ -432,11 +443,11 @@ jQuery.event = { // Run delegates first; they may want to stop propagation beneath us i = 0; - while ( (matched = handlerQueue[ i++ ]) && !event.isPropagationStopped() ) { + while ( ( matched = handlerQueue[ i++ ] ) && !event.isPropagationStopped() ) { event.currentTarget = matched.elem; j = 0; - while ( (handleObj = matched.handlers[ j++ ]) && + while ( ( handleObj = matched.handlers[ j++ ] ) && !event.isImmediatePropagationStopped() ) { // Triggered event must either 1) have no namespace, or 2) have namespace(s) @@ -446,11 +457,11 @@ jQuery.event = { event.handleObj = handleObj; event.data = handleObj.data; - ret = ( (jQuery.event.special[ handleObj.origType ] || {}).handle || + ret = ( ( jQuery.event.special[ handleObj.origType ] || {} ).handle || handleObj.handler ).apply( matched.elem, args ); if ( ret !== undefined ) { - if ( (event.result = ret) === false ) { + if ( ( event.result = ret ) === false ) { event.preventDefault(); event.stopPropagation(); } @@ -479,13 +490,13 @@ jQuery.event = { // // Support: Firefox // Avoid non-left-click bubbling in Firefox (#3861) - if ( delegateCount && cur.nodeType && (!event.button || event.type !== "click") ) { + if ( delegateCount && cur.nodeType && ( !event.button || event.type !== "click" ) ) { for ( ; cur !== this; cur = cur.parentNode || this ) { // Don't check non-elements (#13208) // Don't process clicks on disabled elements (#6911, #8165, #11382, #11764) - if ( cur.nodeType === 1 && (cur.disabled !== true || event.type !== "click") ) { + if ( cur.nodeType === 1 && ( cur.disabled !== true || event.type !== "click" ) ) { matches = []; for ( i = 0; i < delegateCount; i++ ) { handleObj = handlers[ i ]; @@ -503,7 +514,7 @@ jQuery.event = { } } if ( matches.length ) { - handlerQueue.push({ elem: cur, handlers: matches }); + handlerQueue.push( { elem: cur, handlers: matches } ); } } } @@ -511,7 +522,7 @@ jQuery.event = { // Add the remaining (directly-bound) handlers if ( delegateCount < handlers.length ) { - handlerQueue.push({ elem: this, handlers: handlers.slice( delegateCount ) }); + handlerQueue.push( { elem: this, handlers: handlers.slice( delegateCount ) } ); } return handlerQueue; @@ -519,12 +530,12 @@ jQuery.event = { // Includes some event props shared by KeyEvent and MouseEvent props: ( "altKey bubbles cancelable ctrlKey currentTarget detail eventPhase " + - "metaKey relatedTarget shiftKey target timeStamp view which" ).split(" "), + "metaKey relatedTarget shiftKey target timeStamp view which" ).split( " " ), fixHooks: {}, keyHooks: { - props: "char charCode key keyCode".split(" "), + props: "char charCode key keyCode".split( " " ), filter: function( event, original ) { // Add which for key events @@ -538,7 +549,7 @@ jQuery.event = { mouseHooks: { props: ( "button buttons clientX clientY offsetX offsetY pageX pageY " + - "screenX screenY toElement" ).split(" "), + "screenX screenY toElement" ).split( " " ), filter: function( event, original ) { var eventDoc, doc, body, button = original.button; @@ -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,8 +709,9 @@ jQuery.removeEvent = function( elem, type, handle ) { }; jQuery.Event = function( src, props ) { + // Allow instantiation without the 'new' keyword - if ( !(this instanceof jQuery.Event) ) { + 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 : @@ -777,7 +794,7 @@ jQuery.Event.prototype = { // Safari sends mouseenter too often; see: // https://code.google.com/p/chromium/issues/detail?id=470258 // for the description of the bug (it existed in older Chrome versions as well). -jQuery.each({ +jQuery.each( { mouseenter: "mouseover", mouseleave: "mouseout", pointerenter: "pointerover", @@ -795,7 +812,7 @@ jQuery.each({ // For mousenter/leave call the handler if related is outside the target. // NB: No relatedTarget if the mouse left/entered the browser window - if ( !related || (related !== target && !jQuery.contains( target, related )) ) { + if ( !related || ( related !== target && !jQuery.contains( target, related ) ) ) { event.type = handleObj.origType; ret = handleObj.handler.apply( this, arguments ); event.type = fix; @@ -803,7 +820,7 @@ jQuery.each({ return ret; } }; -}); +} ); // Support: Firefox // Firefox doesn't have focus(in | out) events @@ -814,7 +831,7 @@ jQuery.each({ // which is spec violation - http://www.w3.org/TR/DOM-Level-3-Events/#events-focusevent-event-order // Related ticket - https://code.google.com/p/chromium/issues/detail?id=449857 if ( !support.focusin ) { - jQuery.each({ focus: "focusin", blur: "focusout" }, function( orig, fix ) { + jQuery.each( { focus: "focusin", blur: "focusout" }, function( orig, fix ) { // Attach a single capturing handler on the document while someone wants focusin/focusout var handler = function( event ) { @@ -844,10 +861,10 @@ if ( !support.focusin ) { } } }; - }); + } ); } -jQuery.fn.extend({ +jQuery.fn.extend( { on: function( types, selector, data, fn ) { return on( this, types, selector, data, fn ); @@ -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; @@ -884,23 +904,23 @@ jQuery.fn.extend({ if ( fn === false ) { fn = returnFalse; } - return this.each(function() { + return this.each( function() { jQuery.event.remove( this, types, fn, selector ); - }); + } ); }, trigger: function( type, data ) { - return this.each(function() { + return this.each( function() { jQuery.event.trigger( type, data, this ); - }); + } ); }, triggerHandler: function( type, data ) { - var elem = this[0]; + var elem = this[ 0 ]; if ( elem ) { return jQuery.event.trigger( type, data, elem, true ); } } -}); +} ); return jQuery; -}); +} ); diff --git a/src/event/ajax.js b/src/event/ajax.js index c808b583e..98e194bf0 100644 --- a/src/event/ajax.js +++ b/src/event/ajax.js @@ -1,10 +1,10 @@ -define([ +define( [ "../core", "../event" ], function( jQuery ) { // Attach a bunch of functions for handling common AJAX events -jQuery.each([ +jQuery.each( [ "ajaxStart", "ajaxStop", "ajaxComplete", @@ -15,6 +15,6 @@ jQuery.each([ jQuery.fn[ type ] = function( fn ) { return this.on( type, fn ); }; -}); +} ); -}); +} ); diff --git a/src/event/alias.js b/src/event/alias.js index eb43537ff..d2bdc5bb8 100644 --- a/src/event/alias.js +++ b/src/event/alias.js @@ -1,11 +1,11 @@ -define([ +define( [ "../core", "../event" ], function( jQuery ) { -jQuery.each( ("blur focus focusin focusout resize scroll click dblclick " + +jQuery.each( ( "blur focus focusin focusout resize scroll click dblclick " + "mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave " + - "change select submit keydown keypress keyup contextmenu").split(" "), + "change select submit keydown keypress keyup contextmenu" ).split( " " ), function( i, name ) { // Handle event binding @@ -14,9 +14,9 @@ jQuery.each( ("blur focus focusin focusout resize scroll click dblclick " + this.on( name, null, data, fn ) : this.trigger( name ); }; -}); +} ); -jQuery.fn.extend({ +jQuery.fn.extend( { hover: function( fnOver, fnOut ) { return this.mouseenter( fnOver ).mouseleave( fnOut || fnOver ); }, @@ -32,11 +32,12 @@ 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, "**" ) : this.off( types, selector || "**", fn ); } -}); +} ); -}); +} ); diff --git a/src/event/support.js b/src/event/support.js index 7ddca6a8d..1c4d416e5 100644 --- a/src/event/support.js +++ b/src/event/support.js @@ -1,4 +1,4 @@ -define([ +define( [ "../var/support" ], function( support ) { @@ -6,4 +6,4 @@ support.focusin = "onfocusin" in window; return support; -}); +} ); diff --git a/src/exports/amd.js b/src/exports/amd.js index 9a9846f9f..add6eb9bd 100644 --- a/src/exports/amd.js +++ b/src/exports/amd.js @@ -1,4 +1,4 @@ -define([ +define( [ "../core" ], function( jQuery ) { @@ -18,7 +18,7 @@ define([ if ( typeof define === "function" && define.amd ) { define( "jquery", [], function() { return jQuery; - }); + } ); } -}); +} ); diff --git a/src/exports/global.js b/src/exports/global.js index 5d4d050fe..be9cbfb3a 100644 --- a/src/exports/global.js +++ b/src/exports/global.js @@ -1,4 +1,5 @@ var + // Map over jQuery in case of overwrite _jQuery = window.jQuery, diff --git a/src/jquery.js b/src/jquery.js index 1d56c4b15..66a42808e 100644 --- a/src/jquery.js +++ b/src/jquery.js @@ -1,4 +1,4 @@ -define([ +define( [ "./core", "./selector", "./traversing", @@ -31,6 +31,6 @@ define([ "./exports/amd" ], function( jQuery ) { -return (window.jQuery = window.$ = jQuery); +return ( window.jQuery = window.$ = jQuery ); -}); +} ); diff --git a/src/manipulation.js b/src/manipulation.js index 00d65de5a..55a77f4e8 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -1,4 +1,4 @@ -define([ +define( [ "./core", "./var/concat", "./var/push", @@ -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\/(.*)/, @@ -45,7 +46,7 @@ function manipulationTarget( elem, content ) { // Replace/restore the type attribute of script elements for safe DOM manipulation function disableScript( elem ) { - elem.type = (elem.getAttribute("type") !== null) + "/" + elem.type; + elem.type = ( elem.getAttribute( "type" ) !== null ) + "/" + elem.type; return elem; } function restoreScript( elem ) { @@ -54,7 +55,7 @@ function restoreScript( elem ) { if ( match ) { elem.type = match[ 1 ]; } else { - elem.removeAttribute("type"); + elem.removeAttribute( "type" ); } return elem; @@ -124,13 +125,13 @@ function domManip( collection, args, callback, ignored ) { if ( isFunction || ( l > 1 && typeof value === "string" && !support.checkClone && rchecked.test( value ) ) ) { - return collection.each(function( index ) { + return collection.each( function( index ) { var self = collection.eq( index ); if ( isFunction ) { args[ 0 ] = value.call( this, index, self.html() ); } domManip( self, args, callback, ignored ); - }); + } ); } if ( l ) { @@ -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 ); @@ -201,7 +204,7 @@ function remove( elem, selector, keepData ) { nodes = selector ? jQuery.filter( selector, elem ) : elem, i = 0; - for ( ; (node = nodes[i]) != null; i++ ) { + for ( ; ( node = nodes[ i ] ) != null; i++ ) { if ( !keepData && node.nodeType === 1 ) { jQuery.cleanData( getAll( node ) ); } @@ -217,7 +220,7 @@ function remove( elem, selector, keepData ) { return elem; } -jQuery.extend({ +jQuery.extend( { htmlPrefilter: function( html ) { return html.replace( rxhtmlTag, "<$1></$2>" ); }, @@ -269,9 +272,9 @@ jQuery.extend({ special = jQuery.event.special, i = 0; - for ( ; (elem = elems[ i ]) !== undefined; i++ ) { + for ( ; ( elem = elems[ i ] ) !== undefined; i++ ) { if ( jQuery.acceptData( elem ) ) { - if ( (data = elem[ dataPriv.expando ] ) ) { + if ( ( data = elem[ dataPriv.expando ] ) ) { if ( data.events ) { for ( type in data.events ) { if ( special[ type ] ) { @@ -291,9 +294,9 @@ jQuery.extend({ } } } -}); +} ); -jQuery.fn.extend({ +jQuery.fn.extend( { detach: function( selector ) { return remove( this, selector, true ); }, @@ -306,11 +309,11 @@ jQuery.fn.extend({ return access( this, function( value ) { return value === undefined ? jQuery.text( this ) : - this.empty().each(function() { + this.empty().each( function() { if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) { this.textContent = value; } - }); + } ); }, null, value, arguments.length ); }, @@ -320,7 +323,7 @@ jQuery.fn.extend({ var target = manipulationTarget( this, elem ); target.appendChild( elem ); } - }); + } ); }, prepend: function() { @@ -329,7 +332,7 @@ jQuery.fn.extend({ var target = manipulationTarget( this, elem ); target.insertBefore( elem, target.firstChild ); } - }); + } ); }, before: function() { @@ -337,7 +340,7 @@ jQuery.fn.extend({ if ( this.parentNode ) { this.parentNode.insertBefore( elem, this ); } - }); + } ); }, after: function() { @@ -345,14 +348,14 @@ jQuery.fn.extend({ if ( this.parentNode ) { this.parentNode.insertBefore( elem, this.nextSibling ); } - }); + } ); }, empty: function() { var elem, i = 0; - for ( ; (elem = this[i]) != null; i++ ) { + for ( ; ( elem = this[ i ] ) != null; i++ ) { if ( elem.nodeType === 1 ) { // Prevent memory leaks @@ -370,9 +373,9 @@ jQuery.fn.extend({ dataAndEvents = dataAndEvents == null ? false : dataAndEvents; deepDataAndEvents = deepDataAndEvents == null ? dataAndEvents : deepDataAndEvents; - return this.map(function() { + return this.map( function() { return jQuery.clone( this, dataAndEvents, deepDataAndEvents ); - }); + } ); }, html: function( value ) { @@ -431,9 +434,9 @@ jQuery.fn.extend({ // Force callback invocation }, ignored ); } -}); +} ); -jQuery.each({ +jQuery.each( { appendTo: "append", prependTo: "prepend", insertBefore: "before", @@ -458,7 +461,7 @@ jQuery.each({ return this.pushStack( ret ); }; -}); +} ); return jQuery; -}); +} ); diff --git a/src/manipulation/_evalUrl.js b/src/manipulation/_evalUrl.js index 59464bcd9..572fe30c7 100644 --- a/src/manipulation/_evalUrl.js +++ b/src/manipulation/_evalUrl.js @@ -1,9 +1,9 @@ -define([ +define( [ "../ajax" ], function( jQuery ) { jQuery._evalUrl = function( url ) { - return jQuery.ajax({ + return jQuery.ajax( { url: url, // Make this explicit, since user can override this through ajaxSetup (#11264) @@ -13,9 +13,9 @@ jQuery._evalUrl = function( url ) { async: false, global: false, "throws": true - }); + } ); }; return jQuery._evalUrl; -}); +} ); diff --git a/src/manipulation/buildFragment.js b/src/manipulation/buildFragment.js index d5cb4062a..cfdd1c0e6 100644 --- a/src/manipulation/buildFragment.js +++ b/src/manipulation/buildFragment.js @@ -1,4 +1,4 @@ -define([ +define( [ "../core", "./var/rtagName", "./var/rscriptType", @@ -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 ); @@ -98,4 +99,4 @@ function buildFragment( elems, context, scripts, selection, ignored ) { } return buildFragment; -}); +} ); diff --git a/src/manipulation/getAll.js b/src/manipulation/getAll.js index d08470b48..cc913f29e 100644 --- a/src/manipulation/getAll.js +++ b/src/manipulation/getAll.js @@ -1,8 +1,9 @@ -define([ +define( [ "../core" ], 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" ? @@ -17,4 +18,4 @@ function getAll( context, tag ) { } return getAll; -}); +} ); diff --git a/src/manipulation/setGlobalEval.js b/src/manipulation/setGlobalEval.js index 2eab9cf53..8ca69a03a 100644 --- a/src/manipulation/setGlobalEval.js +++ b/src/manipulation/setGlobalEval.js @@ -1,4 +1,4 @@ -define([ +define( [ "../data/var/dataPriv" ], function( dataPriv ) { @@ -17,4 +17,4 @@ function setGlobalEval( elems, refElements ) { } return setGlobalEval; -}); +} ); diff --git a/src/manipulation/support.js b/src/manipulation/support.js index ddea2ff98..4f6b9de87 100644 --- a/src/manipulation/support.js +++ b/src/manipulation/support.js @@ -1,9 +1,9 @@ -define([ +define( [ "../var/document", "../var/support" ], function( document, support ) { -(function() { +( function() { var fragment = document.createDocumentFragment(), div = fragment.appendChild( document.createElement( "div" ) ), input = document.createElement( "input" ); @@ -26,8 +26,8 @@ define([ // Make sure textarea (and checkbox) defaultValue is properly cloned div.innerHTML = "<textarea>x</textarea>"; support.noCloneChecked = !!div.cloneNode( true ).lastChild.defaultValue; -})(); +} )(); return support; -}); +} ); diff --git a/src/manipulation/var/rcheckableType.js b/src/manipulation/var/rcheckableType.js index c27a15dc4..4c95394ac 100644 --- a/src/manipulation/var/rcheckableType.js +++ b/src/manipulation/var/rcheckableType.js @@ -1,3 +1,3 @@ -define(function() { - return (/^(?:checkbox|radio)$/i); -}); +define( function() { + return ( /^(?:checkbox|radio)$/i ); +} ); diff --git a/src/manipulation/var/rscriptType.js b/src/manipulation/var/rscriptType.js index 60ef70ac8..0c77c8a58 100644 --- a/src/manipulation/var/rscriptType.js +++ b/src/manipulation/var/rscriptType.js @@ -1,3 +1,3 @@ -define(function() { +define( function() { return ( /^$|\/(?:java|ecma)script/i ); -}); +} ); diff --git a/src/manipulation/var/rtagName.js b/src/manipulation/var/rtagName.js index cd0b768e0..9e542694a 100644 --- a/src/manipulation/var/rtagName.js +++ b/src/manipulation/var/rtagName.js @@ -1,3 +1,3 @@ -define(function() { +define( function() { return ( /<([\w:-]+)/ ); -}); +} ); diff --git a/src/manipulation/wrapMap.js b/src/manipulation/wrapMap.js index 7080bf996..3fa5f913e 100644 --- a/src/manipulation/wrapMap.js +++ b/src/manipulation/wrapMap.js @@ -1,4 +1,4 @@ -define(function() { +define( function() { // We have to close these tags to support XHTML (#13200) var wrapMap = { @@ -32,4 +32,4 @@ wrapMap.tbody = wrapMap.tfoot = wrapMap.colgroup = wrapMap.caption = wrapMap.the wrapMap.th = wrapMap.td; return wrapMap; -}); +} ); diff --git a/src/offset.js b/src/offset.js index 23a4b2a18..bef2a8fa0 100644 --- a/src/offset.js +++ b/src/offset.js @@ -1,4 +1,4 @@ -define([ +define( [ "./core", "./core/access", "./var/document", @@ -36,7 +36,7 @@ jQuery.offset = { curCSSTop = jQuery.css( elem, "top" ); curCSSLeft = jQuery.css( elem, "left" ); calculatePosition = ( position === "absolute" || position === "fixed" ) && - ( curCSSTop + curCSSLeft ).indexOf("auto") > -1; + ( curCSSTop + curCSSLeft ).indexOf( "auto" ) > -1; // Need to be able to calculate position if either // top or left is auto and position is either absolute or fixed @@ -72,15 +72,16 @@ jQuery.offset = { } }; -jQuery.fn.extend({ +jQuery.fn.extend( { offset: function( options ) { + // Preserve chaining for setter if ( arguments.length ) { return options === undefined ? this : - this.each(function( i ) { + this.each( function( i ) { jQuery.offset.setOffset( this, options, i ); - }); + } ); } var docElem, win, rect, doc, @@ -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(); @@ -166,7 +169,7 @@ jQuery.fn.extend({ // // This logic, however, is not guaranteed and can change at any point in the future offsetParent: function() { - return this.map(function() { + return this.map( function() { var offsetParent = this.offsetParent; while ( offsetParent && jQuery.css( offsetParent, "position" ) === "static" ) { @@ -174,9 +177,9 @@ jQuery.fn.extend({ } return offsetParent || documentElement; - }); + } ); } -}); +} ); // Create scrollLeft and scrollTop methods jQuery.each( { scrollLeft: "pageXOffset", scrollTop: "pageYOffset" }, function( method, prop ) { @@ -201,7 +204,7 @@ jQuery.each( { scrollLeft: "pageXOffset", scrollTop: "pageYOffset" }, function( } }, method, val, arguments.length, null ); }; -}); +} ); // Support: Safari<7-8+, Chrome<37-44+ // Add the top/left cssHooks using jQuery.fn.position @@ -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" : @@ -221,7 +225,7 @@ jQuery.each( [ "top", "left" ], function( i, prop ) { } } ); -}); +} ); return jQuery; -}); +} ); diff --git a/src/queue.js b/src/queue.js index 235439fa6..813c41cd3 100644 --- a/src/queue.js +++ b/src/queue.js @@ -1,11 +1,11 @@ -define([ +define( [ "./core", "./data/var/dataPriv", "./deferred", "./callbacks" ], function( jQuery, dataPriv ) { -jQuery.extend({ +jQuery.extend( { queue: function( elem, type, data ) { var queue; @@ -16,7 +16,7 @@ jQuery.extend({ // Speed up dequeue by getting out quickly if this is just a lookup if ( data ) { if ( !queue || jQuery.isArray( data ) ) { - queue = dataPriv.access( elem, type, jQuery.makeArray(data) ); + queue = dataPriv.access( elem, type, jQuery.makeArray( data ) ); } else { queue.push( data ); } @@ -64,14 +64,14 @@ jQuery.extend({ _queueHooks: function( elem, type ) { var key = type + "queueHooks"; return dataPriv.get( elem, key ) || dataPriv.access( elem, key, { - empty: jQuery.Callbacks("once memory").add(function() { + empty: jQuery.Callbacks( "once memory" ).add( function() { dataPriv.remove( elem, [ type + "queue", key ] ); - }) - }); + } ) + } ); } -}); +} ); -jQuery.fn.extend({ +jQuery.fn.extend( { queue: function( type, data ) { var setter = 2; @@ -82,30 +82,31 @@ jQuery.fn.extend({ } if ( arguments.length < setter ) { - return jQuery.queue( this[0], type ); + return jQuery.queue( this[ 0 ], type ); } return data === undefined ? this : - this.each(function() { + this.each( function() { var queue = jQuery.queue( this, type, data ); // Ensure a hooks for this queue jQuery._queueHooks( this, type ); - if ( type === "fx" && queue[0] !== "inprogress" ) { + if ( type === "fx" && queue[ 0 ] !== "inprogress" ) { jQuery.dequeue( this, type ); } - }); + } ); }, dequeue: function( type ) { - return this.each(function() { + return this.each( function() { jQuery.dequeue( this, type ); - }); + } ); }, 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 ) { @@ -136,7 +137,7 @@ jQuery.fn.extend({ resolve(); return defer.promise( obj ); } -}); +} ); return jQuery; -}); +} ); diff --git a/src/queue/delay.js b/src/queue/delay.js index 93abd0bf2..8d5844d6b 100644 --- a/src/queue/delay.js +++ b/src/queue/delay.js @@ -1,4 +1,4 @@ -define([ +define( [ "../core", "../queue", "../effects" // Delay is optional because of this dependency @@ -15,8 +15,8 @@ jQuery.fn.delay = function( time, type ) { hooks.stop = function() { window.clearTimeout( timeout ); }; - }); + } ); }; return jQuery.fn.delay; -}); +} ); diff --git a/src/selector-native.js b/src/selector-native.js index 2d5cb3026..121a6a603 100644 --- a/src/selector-native.js +++ b/src/selector-native.js @@ -1,4 +1,4 @@ -define([ +define( [ "./core", "./var/document", "./var/documentElement" @@ -36,6 +36,7 @@ var hasDuplicate, documentElement.oMatchesSelector || documentElement.msMatchesSelector, sortOrder = function( a, b ) { + // Flag for duplicate removal if ( a === b ) { hasDuplicate = true; @@ -47,14 +48,15 @@ var hasDuplicate, a.compareDocumentPosition( b ); if ( compare ) { + // Disconnected nodes if ( compare & 1 ) { // Choose the first element that is related to our document - if ( a === document || jQuery.contains(document, a) ) { + if ( a === document || jQuery.contains( document, a ) ) { return -1; } - if ( b === document || jQuery.contains(document, b) ) { + if ( b === document || jQuery.contains( document, b ) ) { return 1; } @@ -78,7 +80,7 @@ var hasDuplicate, results.sort( sortOrder ); if ( hasDuplicate ) { - while ( (elem = results[i++]) ) { + while ( ( elem = results[ i++ ] ) ) { if ( elem === results[ i ] ) { j = duplicates.push( i ); } @@ -91,7 +93,7 @@ var hasDuplicate, return results; }; -jQuery.extend({ +jQuery.extend( { find: function( selector, context, results, seed ) { var elem, nodeType, i = 0; @@ -105,18 +107,18 @@ jQuery.extend({ } // Early return if context is not an element or document - if ( (nodeType = context.nodeType) !== 1 && nodeType !== 9 ) { + if ( ( nodeType = context.nodeType ) !== 1 && nodeType !== 9 ) { return []; } if ( seed ) { - while ( (elem = seed[i++]) ) { - if ( jQuery.find.matchesSelector(elem, selector) ) { + while ( ( elem = seed[ i++ ] ) ) { + if ( jQuery.find.matchesSelector( elem, selector ) ) { results.push( elem ); } } } else { - jQuery.merge( results, context.querySelectorAll(selector) ); + jQuery.merge( results, context.querySelectorAll( selector ) ); } return results; @@ -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++]) ) { + 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; @@ -148,10 +154,10 @@ jQuery.extend({ contains: function( a, b ) { var adown = a.nodeType === 9 ? a.documentElement : a, bup = b && b.parentNode; - return a === bup || !!( bup && bup.nodeType === 1 && adown.contains(bup) ); + return a === bup || !!( bup && bup.nodeType === 1 && adown.contains( bup ) ); }, isXMLDoc: function( elem ) { - return (elem.ownerDocument || elem).documentElement.nodeName !== "HTML"; + return ( elem.ownerDocument || elem ).documentElement.nodeName !== "HTML"; }, expr: { attrHandle: {}, @@ -161,7 +167,7 @@ jQuery.extend({ needsContext: /^[\x20\t\r\n\f]*[>+~]/ } } -}); +} ); jQuery.extend( jQuery.find, { matches: function( expr, elements ) { @@ -173,6 +179,6 @@ jQuery.extend( jQuery.find, { attr: function( elem, name ) { return elem.getAttribute( name ); } -}); +} ); -}); +} ); diff --git a/src/selector-sizzle.js b/src/selector-sizzle.js index c091f1821..dcee45f37 100644 --- a/src/selector-sizzle.js +++ b/src/selector-sizzle.js @@ -1,14 +1,14 @@ -define([ +define( [ "./core", "sizzle" ], function( jQuery, Sizzle ) { jQuery.find = Sizzle; jQuery.expr = Sizzle.selectors; -jQuery.expr[":"] = jQuery.expr.pseudos; +jQuery.expr[ ":" ] = jQuery.expr.pseudos; jQuery.uniqueSort = jQuery.unique = Sizzle.uniqueSort; jQuery.text = Sizzle.getText; jQuery.isXMLDoc = Sizzle.isXML; jQuery.contains = Sizzle.contains; -}); +} ); diff --git a/src/selector.js b/src/selector.js index ea71c33e6..e13f585ae 100644 --- a/src/selector.js +++ b/src/selector.js @@ -1 +1 @@ -define([ "./selector-sizzle" ], function() {}); +define( [ "./selector-sizzle" ], function() {} ); diff --git a/src/serialize.js b/src/serialize.js index d6fedb6a1..76c43ea15 100644 --- a/src/serialize.js +++ b/src/serialize.js @@ -1,4 +1,4 @@ -define([ +define( [ "./core", "./manipulation/var/rcheckableType", "./core/init", @@ -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 : "" ) + "]", @@ -31,15 +34,17 @@ function buildParams( prefix, obj, traditional, add ) { 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 ) { @@ -80,25 +88,26 @@ jQuery.param = function( a, traditional ) { return s.join( "&" ).replace( r20, "+" ); }; -jQuery.fn.extend({ +jQuery.fn.extend( { serialize: function() { return jQuery.param( this.serializeArray() ); }, serializeArray: function() { - return this.map(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; - }) - .filter(function() { + } ) + .filter( function() { var type = this.type; // Use .is( ":disabled" ) so that fieldset[disabled] works return this.name && !jQuery( this ).is( ":disabled" ) && rsubmittable.test( this.nodeName ) && !rsubmitterTypes.test( type ) && ( this.checked || !rcheckableType.test( type ) ); - }) - .map(function( i, elem ) { + } ) + .map( function( i, elem ) { var val = jQuery( this ).val(); return val == null ? @@ -106,11 +115,11 @@ jQuery.fn.extend({ jQuery.isArray( val ) ? jQuery.map( val, function( val ) { return { name: elem.name, value: val.replace( rCRLF, "\r\n" ) }; - }) : + } ) : { name: elem.name, value: val.replace( rCRLF, "\r\n" ) }; - }).get(); + } ).get(); } -}); +} ); return jQuery; -}); +} ); diff --git a/src/traversing.js b/src/traversing.js index 19f8d24e7..a47b048ba 100644 --- a/src/traversing.js +++ b/src/traversing.js @@ -1,4 +1,4 @@ -define([ +define( [ "./core", "./var/indexOf", "./traversing/var/rneedsContext", @@ -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, @@ -16,12 +17,12 @@ var rparentsprev = /^(?:parents|prev(?:Until|All))/, prev: true }; -jQuery.extend({ +jQuery.extend( { dir: function( elem, dir, until ) { var matched = [], truncate = until !== undefined; - while ( (elem = elem[ dir ]) && elem.nodeType !== 9 ) { + while ( ( elem = elem[ dir ] ) && elem.nodeType !== 9 ) { if ( elem.nodeType === 1 ) { if ( truncate && jQuery( elem ).is( until ) ) { break; @@ -43,21 +44,21 @@ jQuery.extend({ return matched; } -}); +} ); -jQuery.fn.extend({ +jQuery.fn.extend( { has: function( target ) { var targets = jQuery( target, this ), l = targets.length; - return this.filter(function() { + return this.filter( function() { var i = 0; for ( ; i < l; i++ ) { - if ( jQuery.contains( this, targets[i] ) ) { + if ( jQuery.contains( this, targets[ i ] ) ) { return true; } } - }); + } ); }, closest: function( selectors, context ) { @@ -70,14 +71,15 @@ jQuery.fn.extend({ 0; for ( ; i < l; i++ ) { - for ( cur = this[i]; cur && cur !== context; cur = cur.parentNode ) { + for ( cur = this[ i ]; cur && cur !== context; cur = cur.parentNode ) { + // Always skip document fragments - if ( cur.nodeType < 11 && (pos ? - pos.index(cur) > -1 : + if ( cur.nodeType < 11 && ( pos ? + pos.index( cur ) > -1 : // Don't pass non-elements to Sizzle cur.nodeType === 1 && - jQuery.find.matchesSelector(cur, selectors)) ) { + jQuery.find.matchesSelector( cur, selectors ) ) ) { matched.push( cur ); break; @@ -119,17 +121,17 @@ jQuery.fn.extend({ addBack: function( selector ) { return this.add( selector == null ? - this.prevObject : this.prevObject.filter(selector) + this.prevObject : this.prevObject.filter( selector ) ); } -}); +} ); function sibling( cur, dir ) { - while ( (cur = cur[dir]) && cur.nodeType !== 1 ) {} + while ( ( cur = cur[ dir ] ) && cur.nodeType !== 1 ) {} return cur; } -jQuery.each({ +jQuery.each( { parent: function( elem ) { var parent = elem.parentNode; return parent && parent.nodeType !== 11 ? parent : null; @@ -180,6 +182,7 @@ jQuery.each({ } if ( this.length > 1 ) { + // Remove duplicates if ( !guaranteedUnique[ name ] ) { jQuery.uniqueSort( matched ); @@ -193,7 +196,7 @@ jQuery.each({ return this.pushStack( matched ); }; -}); +} ); return jQuery; -}); +} ); diff --git a/src/traversing/findFilter.js b/src/traversing/findFilter.js index 128df2cb4..ee76a57a7 100644 --- a/src/traversing/findFilter.js +++ b/src/traversing/findFilter.js @@ -1,4 +1,4 @@ -define([ +define( [ "../core", "../var/indexOf", "./var/rneedsContext", @@ -13,14 +13,14 @@ function winnow( elements, qualifier, not ) { return jQuery.grep( elements, function( elem, i ) { /* jshint -W018 */ return !!qualifier.call( elem, i, elem ) !== not; - }); + } ); } if ( qualifier.nodeType ) { return jQuery.grep( elements, function( elem ) { return ( elem === qualifier ) !== not; - }); + } ); } @@ -34,7 +34,7 @@ function winnow( elements, qualifier, not ) { return jQuery.grep( elements, function( elem ) { return ( indexOf.call( qualifier, elem ) > -1 ) !== not; - }); + } ); } jQuery.filter = function( expr, elems, not ) { @@ -48,10 +48,10 @@ jQuery.filter = function( expr, elems, not ) { jQuery.find.matchesSelector( elem, expr ) ? [ elem ] : [] : jQuery.find.matches( expr, jQuery.grep( elems, function( elem ) { return elem.nodeType === 1; - })); + } ) ); }; -jQuery.fn.extend({ +jQuery.fn.extend( { find: function( selector ) { var i, len = this.length, @@ -59,13 +59,13 @@ jQuery.fn.extend({ self = this; if ( typeof selector !== "string" ) { - return this.pushStack( jQuery( selector ).filter(function() { + return this.pushStack( jQuery( selector ).filter( function() { for ( i = 0; i < len; i++ ) { if ( jQuery.contains( self[ i ], this ) ) { return true; } } - }) ); + } ) ); } for ( i = 0; i < len; i++ ) { @@ -75,10 +75,10 @@ jQuery.fn.extend({ return this.pushStack( len > 1 ? jQuery.uniqueSort( ret ) : ret ); }, filter: function( selector ) { - return this.pushStack( winnow(this, selector || [], false) ); + return this.pushStack( winnow( this, selector || [], false ) ); }, not: function( selector ) { - return this.pushStack( winnow(this, selector || [], true) ); + return this.pushStack( winnow( this, selector || [], true ) ); }, is: function( selector ) { return !!winnow( @@ -92,6 +92,6 @@ jQuery.fn.extend({ false ).length; } -}); +} ); -}); +} ); diff --git a/src/traversing/var/rneedsContext.js b/src/traversing/var/rneedsContext.js index 3d6ae4038..f57fd9de2 100644 --- a/src/traversing/var/rneedsContext.js +++ b/src/traversing/var/rneedsContext.js @@ -1,6 +1,6 @@ -define([ +define( [ "../../core", "../../selector" ], function( jQuery ) { return jQuery.expr.match.needsContext; -}); +} ); diff --git a/src/var/arr.js b/src/var/arr.js index b18fc9ce0..3fd364000 100644 --- a/src/var/arr.js +++ b/src/var/arr.js @@ -1,3 +1,3 @@ -define(function() { +define( function() { return []; -}); +} ); diff --git a/src/var/class2type.js b/src/var/class2type.js index e674c3ba6..3a6932e11 100644 --- a/src/var/class2type.js +++ b/src/var/class2type.js @@ -1,4 +1,5 @@ -define(function() { +define( function() { + // [[Class]] -> type pairs return {}; -}); +} ); diff --git a/src/var/concat.js b/src/var/concat.js index 7dcf77e3c..9787bead6 100644 --- a/src/var/concat.js +++ b/src/var/concat.js @@ -1,5 +1,5 @@ -define([ +define( [ "./arr" ], function( arr ) { return arr.concat; -}); +} ); diff --git a/src/var/document.js b/src/var/document.js index ded014f1a..bb9428484 100644 --- a/src/var/document.js +++ b/src/var/document.js @@ -1,3 +1,3 @@ -define(function() { +define( function() { return window.document; -}); +} ); diff --git a/src/var/documentElement.js b/src/var/documentElement.js index c639670f1..e0c0aea6b 100644 --- a/src/var/documentElement.js +++ b/src/var/documentElement.js @@ -1,5 +1,5 @@ -define([ +define( [ "./document" ], function( document ) { return document.documentElement; -}); +} ); diff --git a/src/var/hasOwn.js b/src/var/hasOwn.js index 32c002aff..92f323e04 100644 --- a/src/var/hasOwn.js +++ b/src/var/hasOwn.js @@ -1,5 +1,5 @@ -define([ +define( [ "./class2type" ], function( class2type ) { return class2type.hasOwnProperty; -}); +} ); diff --git a/src/var/indexOf.js b/src/var/indexOf.js index cdbe3c742..5283841b2 100644 --- a/src/var/indexOf.js +++ b/src/var/indexOf.js @@ -1,5 +1,5 @@ -define([ +define( [ "./arr" ], function( arr ) { return arr.indexOf; -}); +} ); diff --git a/src/var/pnum.js b/src/var/pnum.js index 407044724..7fd9f6677 100644 --- a/src/var/pnum.js +++ b/src/var/pnum.js @@ -1,3 +1,3 @@ -define(function() { - return (/[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/).source; -}); +define( function() { + return ( /[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/ ).source; +} ); diff --git a/src/var/push.js b/src/var/push.js index ad6f0a179..bca1a58ed 100644 --- a/src/var/push.js +++ b/src/var/push.js @@ -1,5 +1,5 @@ -define([ +define( [ "./arr" ], function( arr ) { return arr.push; -}); +} ); diff --git a/src/var/rcssNum.js b/src/var/rcssNum.js index 2fc3938a5..408f5e26d 100644 --- a/src/var/rcssNum.js +++ b/src/var/rcssNum.js @@ -1,7 +1,7 @@ -define([ +define( [ "../var/pnum" ], function( pnum ) { return new RegExp( "^(?:([+-])=|)(" + pnum + ")([a-z%]*)$", "i" ); -}); +} ); diff --git a/src/var/rnotwhite.js b/src/var/rnotwhite.js index 7c69bec53..6067728ee 100644 --- a/src/var/rnotwhite.js +++ b/src/var/rnotwhite.js @@ -1,3 +1,3 @@ -define(function() { - return (/\S+/g); -}); +define( function() { + return ( /\S+/g ); +} ); diff --git a/src/var/slice.js b/src/var/slice.js index 614d46ca5..d8206d30a 100644 --- a/src/var/slice.js +++ b/src/var/slice.js @@ -1,5 +1,5 @@ -define([ +define( [ "./arr" ], function( arr ) { return arr.slice; -}); +} ); diff --git a/src/var/support.js b/src/var/support.js index b25dbc74b..3db9b67bc 100644 --- a/src/var/support.js +++ b/src/var/support.js @@ -1,4 +1,5 @@ -define(function() { +define( function() { + // All support tests are defined in their respective modules. return {}; -}); +} ); diff --git a/src/var/toString.js b/src/var/toString.js index ca92d2222..80ac7f13f 100644 --- a/src/var/toString.js +++ b/src/var/toString.js @@ -1,5 +1,5 @@ -define([ +define( [ "./class2type" ], function( class2type ) { return class2type.toString; -}); +} ); diff --git a/src/wrap.js b/src/wrap.js index 0d9bf0f2e..69c7cbf23 100644 --- a/src/wrap.js +++ b/src/wrap.js @@ -1,11 +1,11 @@ -define([ +define( [ "./core", "./core/init", "./manipulation", // clone "./traversing" // parent, contents ], function( jQuery ) { -jQuery.fn.extend({ +jQuery.fn.extend( { wrapAll: function( html ) { var wrap; @@ -21,7 +21,7 @@ jQuery.fn.extend({ wrap.insertBefore( this[ 0 ] ); } - wrap.map(function() { + wrap.map( function() { var elem = this; while ( elem.firstElementChild ) { @@ -29,7 +29,7 @@ jQuery.fn.extend({ } return elem; - }).append( this ); + } ).append( this ); } return this; @@ -37,12 +37,12 @@ jQuery.fn.extend({ wrapInner: function( html ) { if ( jQuery.isFunction( html ) ) { - return this.each(function( i ) { - jQuery( this ).wrapInner( html.call(this, i) ); - }); + return this.each( function( i ) { + jQuery( this ).wrapInner( html.call( this, i ) ); + } ); } - return this.each(function() { + return this.each( function() { var self = jQuery( this ), contents = self.contents(); @@ -52,24 +52,24 @@ jQuery.fn.extend({ } else { self.append( html ); } - }); + } ); }, wrap: function( html ) { var isFunction = jQuery.isFunction( html ); - return this.each(function( i ) { - jQuery( this ).wrapAll( isFunction ? html.call(this, i) : html ); - }); + return this.each( function( i ) { + jQuery( this ).wrapAll( isFunction ? html.call( this, i ) : html ); + } ); }, unwrap: function( selector ) { - this.parent( selector ).not( "body" ).each(function() { + this.parent( selector ).not( "body" ).each( function() { jQuery( this ).replaceWith( this.childNodes ); - }); + } ); return this; } -}); +} ); return jQuery; -}); +} ); diff --git a/test/data/jquery-1.9.1.js b/test/data/jquery-1.9.1.js index e2c203fe9..80c97a226 100644 --- a/test/data/jquery-1.9.1.js +++ b/test/data/jquery-1.9.1.js @@ -11,7 +11,7 @@ * * Date: 2013-2-4 */ -(function( window, undefined ) { +( function( window, undefined ) { // Can't do this because several apps including ASP.NET trace // the stack via arguments.caller.callee and Firefox dies if @@ -19,6 +19,7 @@ // Support: Firefox 18+ //"use strict"; var + // The deferred used on DOM ready readyList, @@ -58,6 +59,7 @@ var // Define a local copy of jQuery jQuery = function( selector, context ) { + // The jQuery object is actually just the init constructor 'enhanced' return new jQuery.fn.init( selector, context, rootjQuery ); }, @@ -103,6 +105,7 @@ var jQuery.ready(); } }, + // Clean-up method for dom ready events detach = function() { if ( document.addEventListener ) { @@ -116,6 +119,7 @@ var }; jQuery.fn = jQuery.prototype = { + // The current version of jQuery being used jquery: core_version, @@ -130,7 +134,8 @@ jQuery.fn = jQuery.prototype = { // Handle HTML strings if ( typeof selector === "string" ) { - if ( selector.charAt(0) === "<" && selector.charAt( selector.length - 1 ) === ">" && selector.length >= 3 ) { + if ( selector.charAt( 0 ) === "<" && selector.charAt( selector.length - 1 ) === ">" && selector.length >= 3 ) { + // Assume that strings that start and end with <> are HTML and skip the regex check match = [ null, selector, null ]; @@ -139,22 +144,23 @@ jQuery.fn = jQuery.prototype = { } // Match html or make sure no context is specified for #id - if ( match && (match[1] || !context) ) { + if ( match && ( match[ 1 ] || !context ) ) { // HANDLE: $(html) -> $(array) - if ( match[1] ) { - context = context instanceof jQuery ? context[0] : context; + if ( match[ 1 ] ) { + context = context instanceof jQuery ? context[ 0 ] : context; // scripts is true for back-compat jQuery.merge( this, jQuery.parseHTML( - match[1], + match[ 1 ], context && context.nodeType ? context.ownerDocument || context : document, true ) ); // HANDLE: $(html, props) - if ( rsingleTag.test( match[1] ) && jQuery.isPlainObject( context ) ) { + 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 ] ); @@ -170,20 +176,21 @@ jQuery.fn = jQuery.prototype = { // HANDLE: $(#id) } else { - elem = document.getElementById( match[2] ); + elem = document.getElementById( match[ 2 ] ); // Check parentNode to catch when Blackberry 4.6 returns // nodes that are no longer in the document #6963 if ( elem && elem.parentNode ) { + // Handle the case where IE and Opera return items // by name instead of ID - if ( elem.id !== match[2] ) { + if ( elem.id !== match[ 2 ] ) { return rootjQuery.find( selector ); } // Otherwise, we inject the element directly into the jQuery object this.length = 1; - this[0] = elem; + this[ 0 ] = elem; } this.context = document; @@ -203,7 +210,7 @@ jQuery.fn = jQuery.prototype = { // HANDLE: $(DOMElement) } else if ( selector.nodeType ) { - this.context = this[0] = selector; + this.context = this[ 0 ] = selector; this.length = 1; return this; @@ -271,6 +278,7 @@ jQuery.fn = jQuery.prototype = { }, ready: function( fn ) { + // Add the callback jQuery.ready.promise().done( fn ); @@ -292,17 +300,17 @@ jQuery.fn = jQuery.prototype = { eq: function( i ) { var len = this.length, j = +i + ( i < 0 ? len : 0 ); - return this.pushStack( j >= 0 && j < len ? [ this[j] ] : [] ); + return this.pushStack( j >= 0 && j < len ? [ this[ j ] ] : [] ); }, map: function( callback ) { - return this.pushStack( jQuery.map(this, function( elem, i ) { + return this.pushStack( jQuery.map( this, function( elem, i ) { return callback.call( elem, i, elem ); - })); + } ) ); }, end: function() { - return this.prevObject || this.constructor(null); + return this.prevObject || this.constructor( null ); }, // For internal use only. @@ -317,7 +325,7 @@ jQuery.fn.init.prototype = jQuery.fn; jQuery.extend = jQuery.fn.extend = function() { var src, copyIsArray, copy, name, options, clone, - target = arguments[0] || {}, + target = arguments[ 0 ] || {}, i = 1, length = arguments.length, deep = false; @@ -325,13 +333,14 @@ jQuery.extend = jQuery.fn.extend = function() { // Handle a deep copy situation if ( typeof target === "boolean" ) { deep = target; - target = arguments[1] || {}; + target = arguments[ 1 ] || {}; + // skip the boolean and the target i = 2; } // Handle case when target is a string or something (possible in deep copy) - if ( typeof target !== "object" && !jQuery.isFunction(target) ) { + if ( typeof target !== "object" && !jQuery.isFunction( target ) ) { target = {}; } @@ -342,8 +351,10 @@ jQuery.extend = jQuery.fn.extend = function() { } for ( ; i < length; i++ ) { + // Only deal with non-null/undefined values - if ( (options = arguments[ i ]) != null ) { + if ( ( options = arguments[ i ] ) != null ) { + // Extend the base object for ( name in options ) { src = target[ name ]; @@ -355,13 +366,13 @@ jQuery.extend = jQuery.fn.extend = function() { } // Recurse if we're merging plain objects or arrays - if ( deep && copy && ( jQuery.isPlainObject(copy) || (copyIsArray = jQuery.isArray(copy)) ) ) { + if ( deep && copy && ( jQuery.isPlainObject( copy ) || ( copyIsArray = jQuery.isArray( copy ) ) ) ) { if ( copyIsArray ) { copyIsArray = false; - clone = src && jQuery.isArray(src) ? src : []; + clone = src && jQuery.isArray( src ) ? src : []; } else { - clone = src && jQuery.isPlainObject(src) ? src : {}; + clone = src && jQuery.isPlainObject( src ) ? src : {}; } // Never move original objects, clone them @@ -379,7 +390,7 @@ jQuery.extend = jQuery.fn.extend = function() { return target; }; -jQuery.extend({ +jQuery.extend( { noConflict: function( deep ) { if ( window.$ === jQuery ) { window.$ = _$; @@ -434,7 +445,7 @@ jQuery.extend({ // Trigger any bound ready events if ( jQuery.fn.trigger ) { - jQuery( document ).trigger("ready").off("ready"); + jQuery( document ).trigger( "ready" ).off( "ready" ); } }, @@ -442,11 +453,11 @@ jQuery.extend({ // Since version 1.3, DOM methods and functions like alert // aren't supported. They return false on IE (#2968). isFunction: function( obj ) { - return jQuery.type(obj) === "function"; + return jQuery.type( obj ) === "function"; }, isArray: Array.isArray || function( obj ) { - return jQuery.type(obj) === "array"; + return jQuery.type( obj ) === "array"; }, isWindow: function( obj ) { @@ -454,7 +465,7 @@ jQuery.extend({ }, isNumeric: function( obj ) { - return !isNaN( parseFloat(obj) ) && isFinite( obj ); + return !isNaN( parseFloat( obj ) ) && isFinite( obj ); }, type: function( obj ) { @@ -462,26 +473,29 @@ jQuery.extend({ return String( obj ); } return typeof obj === "object" || typeof obj === "function" ? - class2type[ core_toString.call(obj) ] || "object" : + class2type[ core_toString.call( obj ) ] || "object" : typeof obj; }, isPlainObject: function( obj ) { + // Must be an Object. // Because of IE, we also have to check the presence of the constructor property. // Make sure that DOM nodes and window objects don't pass through, as well - if ( !obj || jQuery.type(obj) !== "object" || obj.nodeType || jQuery.isWindow( obj ) ) { + if ( !obj || jQuery.type( obj ) !== "object" || obj.nodeType || jQuery.isWindow( obj ) ) { return false; } try { + // Not own constructor property must be Object if ( obj.constructor && - !core_hasOwn.call(obj, "constructor") && - !core_hasOwn.call(obj.constructor.prototype, "isPrototypeOf") ) { + !core_hasOwn.call( obj, "constructor" ) && + !core_hasOwn.call( obj.constructor.prototype, "isPrototypeOf" ) ) { return false; } } catch ( e ) { + // IE8,9 Will throw exceptions on certain host objects #9897 return false; } @@ -525,7 +539,7 @@ jQuery.extend({ // Single tag if ( parsed ) { - return [ context.createElement( parsed[1] ) ]; + return [ context.createElement( parsed[ 1 ] ) ]; } parsed = jQuery.buildFragment( [ data ], context, scripts ); @@ -536,6 +550,7 @@ jQuery.extend({ }, parseJSON: function( data ) { + // Attempt to parse using the native JSON parser first if ( window.JSON && window.JSON.parse ) { return window.JSON.parse( data ); @@ -551,11 +566,12 @@ jQuery.extend({ data = jQuery.trim( data ); if ( data ) { + // Make sure the incoming data is actual JSON // Logic borrowed from http://json.org/json2.js if ( rvalidchars.test( data.replace( rvalidescape, "@" ) .replace( rvalidtokens, "]" ) - .replace( rvalidbraces, "")) ) { + .replace( rvalidbraces, "" ) ) ) { return ( new Function( "return " + data ) )(); } @@ -574,13 +590,13 @@ jQuery.extend({ try { if ( window.DOMParser ) { // Standard tmp = new DOMParser(); - xml = tmp.parseFromString( data , "text/xml" ); + xml = tmp.parseFromString( data, "text/xml" ); } else { // IE xml = new ActiveXObject( "Microsoft.XMLDOM" ); xml.async = "false"; xml.loadXML( data ); } - } catch( e ) { + } catch ( e ) { xml = undefined; } if ( !xml || !xml.documentElement || xml.getElementsByTagName( "parsererror" ).length ) { @@ -596,6 +612,7 @@ jQuery.extend({ // http://weblogs.java.net/blog/driscoll/archive/2009/09/08/eval-javascript-global-context globalEval: function( data ) { if ( data && jQuery.trim( data ) ) { + // We use execScript on Internet Explorer // We use an anonymous function so that context is window // rather than jQuery in Firefox @@ -666,7 +683,7 @@ jQuery.extend({ }, // Use native String.trim function wherever possible - trim: core_trim && !core_trim.call("\uFEFF\xA0") ? + trim: core_trim && !core_trim.call( "\uFEFF\xA0" ) ? function( text ) { return text == null ? "" : @@ -685,7 +702,7 @@ jQuery.extend({ var ret = results || []; if ( arr != null ) { - if ( isArraylike( Object(arr) ) ) { + if ( isArraylike( Object( arr ) ) ) { jQuery.merge( ret, typeof arr === "string" ? [ arr ] : arr @@ -710,6 +727,7 @@ jQuery.extend({ i = i ? i < 0 ? Math.max( 0, len + i ) : i : 0; for ( ; i < len; i++ ) { + // Skip accessing in sparse arrays if ( i in arr && arr[ i ] === elem ) { return i; @@ -730,7 +748,7 @@ jQuery.extend({ first[ i++ ] = second[ j ]; } } else { - while ( second[j] !== undefined ) { + while ( second[ j ] !== undefined ) { first[ i++ ] = second[ j++ ]; } } @@ -835,7 +853,7 @@ jQuery.extend({ if ( jQuery.type( key ) === "object" ) { chainable = true; for ( i in key ) { - jQuery.access( elems, fn, i, key[i], true, emptyGet, raw ); + jQuery.access( elems, fn, i, key[ i ], true, emptyGet, raw ); } // Sets one value @@ -847,6 +865,7 @@ jQuery.extend({ } if ( bulk ) { + // Bulk operations run against the entire set if ( raw ) { fn.call( elems, value ); @@ -863,7 +882,7 @@ jQuery.extend({ if ( fn ) { for ( ; i < length; 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 ) ) ); } } } @@ -874,13 +893,13 @@ jQuery.extend({ // Gets bulk ? fn.call( elems ) : - length ? fn( elems[0], key ) : emptyGet; + length ? fn( elems[ 0 ], key ) : emptyGet; }, now: function() { return ( new Date() ).getTime(); } -}); +} ); jQuery.ready.promise = function( obj ) { if ( !readyList ) { @@ -891,11 +910,13 @@ jQuery.ready.promise = function( obj ) { // we once tried to use readyState "interactive" here, 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 setTimeout( jQuery.ready ); // Standards-based browsers support DOMContentLoaded } else if ( document.addEventListener ) { + // Use the handy event callback document.addEventListener( "DOMContentLoaded", completed, false ); @@ -904,6 +925,7 @@ jQuery.ready.promise = function( obj ) { // If IE event model is used } else { + // Ensure firing before onload, maybe late but safe also for iframes document.attachEvent( "onreadystatechange", completed ); @@ -916,17 +938,18 @@ jQuery.ready.promise = function( obj ) { try { top = window.frameElement == null && document.documentElement; - } catch(e) {} + } catch ( e ) {} if ( top && top.doScroll ) { - (function doScrollCheck() { + ( function doScrollCheck() { if ( !jQuery.isReady ) { try { + // Use the trick by Diego Perini // http://javascript.nwbox.com/IEContentLoaded/ - top.doScroll("left"); - } catch(e) { + top.doScroll( "left" ); + } catch ( e ) { return setTimeout( doScrollCheck, 50 ); } @@ -936,7 +959,7 @@ jQuery.ready.promise = function( obj ) { // and execute any waiting functions jQuery.ready(); } - })(); + } )(); } } } @@ -944,9 +967,9 @@ jQuery.ready.promise = function( obj ) { }; // Populate the class2type map -jQuery.each("Boolean Number String Function Array Date RegExp Object Error".split(" "), function(i, name) { +jQuery.each( "Boolean Number String Function Array Date RegExp Object Error".split( " " ), function( i, name ) { class2type[ "[object " + name + "]" ] = name.toLowerCase(); -}); +} ); function isArraylike( obj ) { var length = obj.length, @@ -966,7 +989,8 @@ function isArraylike( obj ) { } // All jQuery objects should point back to these -rootjQuery = jQuery(document); +rootjQuery = jQuery( document ); + // String to Object options format cache var optionsCache = {}; @@ -975,7 +999,7 @@ function createOptions( options ) { var object = optionsCache[ options ] = {}; jQuery.each( options.match( core_rnotwhite ) || [], function( _, flag ) { object[ flag ] = true; - }); + } ); return object; } @@ -1011,20 +1035,28 @@ 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, + // End of the loop when firing firingLength, + // Index of currently firing callback (modified by remove if needed) firingIndex, + // First callback to fire (used internally by add and fireWith) firingStart, + // Actual callback list list = [], + // Stack of fire calls for repeatable lists stack = !options.once && [], + // Fire callbacks fire = function( data ) { memory = options.memory && data; @@ -1052,14 +1084,17 @@ jQuery.Callbacks = function( options ) { } } }, + // Actual Callbacks object self = { + // Add a callback or a collection of callbacks to the list add: function() { if ( list ) { + // First, we save the current length var start = list.length; - (function add( args ) { + ( function add( args ) { jQuery.each( args, function( _, arg ) { var type = jQuery.type( arg ); if ( type === "function" ) { @@ -1067,15 +1102,18 @@ jQuery.Callbacks = function( options ) { list.push( arg ); } } else if ( arg && arg.length && type !== "string" ) { + // Inspect recursively add( arg ); } - }); - })( arguments ); + } ); + } )( arguments ); + // Do we need to add the callbacks to the // current firing batch? if ( firing ) { firingLength = list.length; + // With memory, if we're not firing then // we should call right away } else if ( memory ) { @@ -1085,13 +1123,15 @@ jQuery.Callbacks = function( options ) { } return this; }, + // Remove a callback from the list remove: function() { if ( list ) { jQuery.each( arguments, function( _, arg ) { var index; - while( ( index = jQuery.inArray( arg, list, index ) ) > -1 ) { + while ( ( index = jQuery.inArray( arg, list, index ) ) > -1 ) { list.splice( index, 1 ); + // Handle firing indexes if ( firing ) { if ( index <= firingLength ) { @@ -1102,29 +1142,34 @@ jQuery.Callbacks = function( options ) { } } } - }); + } ); } return this; }, + // Check if a given callback is in the list. // If no argument is given, return whether or not list has callbacks attached. has: function( fn ) { return fn ? jQuery.inArray( fn, list ) > -1 : !!( list && list.length ); }, + // Remove all callbacks from the list empty: function() { list = []; return this; }, + // Have the list do nothing anymore disable: function() { list = stack = memory = undefined; return this; }, + // Is it disabled? disabled: function() { return !list; }, + // Lock the list in its current state lock: function() { stack = undefined; @@ -1133,10 +1178,12 @@ jQuery.Callbacks = function( options ) { } return this; }, + // Is it locked? locked: function() { return !stack; }, + // Call all callbacks with the given context and arguments fireWith: function( context, args ) { args = args || []; @@ -1150,11 +1197,13 @@ jQuery.Callbacks = function( options ) { } return this; }, + // Call all the callbacks with the given arguments fire: function() { self.fireWith( this, arguments ); return this; }, + // To know if the callbacks have already been called at least once fired: function() { return !!fired; @@ -1163,14 +1212,15 @@ jQuery.Callbacks = function( options ) { return self; }; -jQuery.extend({ +jQuery.extend( { Deferred: function( func ) { var tuples = [ + // action, add listener, listener list, final state - [ "resolve", "done", jQuery.Callbacks("once memory"), "resolved" ], - [ "reject", "fail", jQuery.Callbacks("once memory"), "rejected" ], - [ "notify", "progress", jQuery.Callbacks("memory") ] + [ "resolve", "done", jQuery.Callbacks( "once memory" ), "resolved" ], + [ "reject", "fail", jQuery.Callbacks( "once memory" ), "rejected" ], + [ "notify", "progress", jQuery.Callbacks( "memory" ) ] ], state = "pending", promise = { @@ -1183,12 +1233,13 @@ jQuery.extend({ }, then: function( /* fnDone, fnFail, fnProgress */ ) { var fns = arguments; - return jQuery.Deferred(function( newDefer ) { + return jQuery.Deferred( function( newDefer ) { jQuery.each( tuples, function( i, tuple ) { var action = tuple[ 0 ], fn = jQuery.isFunction( fns[ i ] ) && fns[ i ]; + // deferred[ done | fail | progress ] for forwarding actions to newDefer - deferred[ tuple[1] ](function() { + deferred[ tuple[ 1 ] ]( function() { var returned = fn && fn.apply( this, arguments ); if ( returned && jQuery.isFunction( returned.promise ) ) { returned.promise() @@ -1198,11 +1249,12 @@ jQuery.extend({ } else { newDefer[ action + "With" ]( this === promise ? newDefer.promise() : this, fn ? [ returned ] : arguments ); } - }); - }); + } ); + } ); fns = null; - }).promise(); + } ).promise(); }, + // Get a promise for this deferred // If obj is provided, the promise aspect is added to the object promise: function( obj ) { @@ -1220,11 +1272,12 @@ jQuery.extend({ stateString = tuple[ 3 ]; // promise[ done | fail | progress ] = list.add - promise[ tuple[1] ] = list.add; + promise[ tuple[ 1 ] ] = list.add; // Handle state if ( stateString ) { - list.add(function() { + list.add( function() { + // state = [ resolved | rejected ] state = stateString; @@ -1233,12 +1286,12 @@ jQuery.extend({ } // deferred[ resolve | reject | notify ] - deferred[ tuple[0] ] = function() { - deferred[ tuple[0] + "With" ]( this === deferred ? promise : this, arguments ); + deferred[ tuple[ 0 ] ] = function() { + deferred[ tuple[ 0 ] + "With" ]( this === deferred ? promise : this, arguments ); return this; }; - deferred[ tuple[0] + "With" ] = list.fireWith; - }); + deferred[ tuple[ 0 ] + "With" ] = list.fireWith; + } ); // Make the deferred a promise promise.promise( deferred ); @@ -1269,7 +1322,7 @@ jQuery.extend({ return function( value ) { contexts[ i ] = this; values[ i ] = arguments.length > 1 ? core_slice.call( arguments ) : value; - if( values === progressValues ) { + if ( values === progressValues ) { deferred.notifyWith( contexts, values ); } else if ( !( --remaining ) ) { deferred.resolveWith( contexts, values ); @@ -1303,32 +1356,33 @@ jQuery.extend({ return deferred.promise(); } -}); -jQuery.support = (function() { +} ); +jQuery.support = ( function() { var support, all, a, input, select, fragment, opt, eventName, isSupported, i, - div = document.createElement("div"); + div = document.createElement( "div" ); // Setup div.setAttribute( "className", "t" ); div.innerHTML = " <link/><table></table><a href='/a'>a</a><input type='checkbox'/>"; // Support tests won't run in some limited or non-browser environments - all = div.getElementsByTagName("*"); - a = div.getElementsByTagName("a")[ 0 ]; + all = div.getElementsByTagName( "*" ); + a = div.getElementsByTagName( "a" )[ 0 ]; if ( !all || !a || !all.length ) { return {}; } // First batch of tests - select = document.createElement("select"); - opt = select.appendChild( document.createElement("option") ); - input = div.getElementsByTagName("input")[ 0 ]; + select = document.createElement( "select" ); + opt = select.appendChild( document.createElement( "option" ) ); + input = div.getElementsByTagName( "input" )[ 0 ]; a.style.cssText = "top:1px;float:left;opacity:.5"; support = { + // Test setAttribute on camelCase class. If it works, we need attrFixes when doing get/setAttribute (ie6/7) getSetAttribute: div.className !== "t", @@ -1337,19 +1391,19 @@ jQuery.support = (function() { // Make sure that tbody elements aren't automatically inserted // IE will insert them into empty tables - tbody: !div.getElementsByTagName("tbody").length, + tbody: !div.getElementsByTagName( "tbody" ).length, // Make sure that link elements get serialized correctly by innerHTML // This requires a wrapper element in IE - htmlSerialize: !!div.getElementsByTagName("link").length, + htmlSerialize: !!div.getElementsByTagName( "link" ).length, // Get the style information from getAttribute // (IE uses .cssText instead) - style: /top/.test( a.getAttribute("style") ), + style: /top/.test( a.getAttribute( "style" ) ), // Make sure that URLs aren't manipulated // (IE normalizes it by default) - hrefNormalized: a.getAttribute("href") === "/a", + hrefNormalized: a.getAttribute( "href" ) === "/a", // Make sure that element opacity exists // (IE uses filter instead) @@ -1368,11 +1422,11 @@ jQuery.support = (function() { optSelected: opt.selected, // Tests for enctype support on a form (#6743) - enctype: !!document.createElement("form").enctype, + enctype: !!document.createElement( "form" ).enctype, // Makes sure cloning an html5 element does not cause problems // Where outerHTML is undefined, this still works - html5Clone: document.createElement("nav").cloneNode( true ).outerHTML !== "<:nav></:nav>", + html5Clone: document.createElement( "nav" ).cloneNode( true ).outerHTML !== "<:nav></:nav>", // jQuery.support.boxModel DEPRECATED in 1.8 since we don't support Quirks Mode boxModel: document.compatMode === "CSS1Compat", @@ -1399,12 +1453,12 @@ jQuery.support = (function() { // Support: IE<9 try { delete div.test; - } catch( e ) { + } catch ( e ) { support.deleteExpando = false; } // Check if we can trust getAttribute("value") - input = document.createElement("input"); + input = document.createElement( "input" ); input.setAttribute( "value", "" ); support.input = input.getAttribute( "value" ) === ""; @@ -1433,14 +1487,14 @@ jQuery.support = (function() { if ( div.attachEvent ) { div.attachEvent( "onclick", function() { support.noCloneEvent = false; - }); + } ); div.cloneNode( true ).click(); } // Support: IE<9 (lack submit/change bubble), Firefox 17+ (lack focusin event) // Beware of CSP restrictions (https://developer.mozilla.org/en/Security/CSP), test/csp.php - for ( i in { submit: true, change: true, focusin: true }) { + for ( i in { submit: true, change: true, focusin: true } ) { div.setAttribute( eventName = "on" + i, "t" ); support[ i + "Bubbles" ] = eventName in window || div.attributes[ eventName ].expando === false; @@ -1451,17 +1505,18 @@ jQuery.support = (function() { support.clearCloneStyle = div.style.backgroundClip === "content-box"; // Run tests that need a body at doc ready - jQuery(function() { + jQuery( function() { var container, marginDiv, tds, divReset = "padding:0;margin:0;border:0;display:block;box-sizing:content-box;-moz-box-sizing:content-box;-webkit-box-sizing:content-box;", - body = document.getElementsByTagName("body")[0]; + body = document.getElementsByTagName( "body" )[ 0 ]; if ( !body ) { + // Return for frameset docs that don't have a body return; } - container = document.createElement("div"); + container = document.createElement( "div" ); container.style.cssText = "border:0;width:0;height:0;position:absolute;top:0;left:-9999px;margin-top:1px"; body.appendChild( container ).appendChild( div ); @@ -1474,7 +1529,7 @@ jQuery.support = (function() { // display:none (it is still safe to use offsets if a parent element is // hidden; don safety goggles and see bug #4512 for more information). div.innerHTML = "<table><tr><td></td><td>t</td></tr></table>"; - tds = div.getElementsByTagName("td"); + tds = div.getElementsByTagName( "td" ); tds[ 0 ].style.cssText = "padding:0;margin:0;border:0;display:none"; isSupported = ( tds[ 0 ].offsetHeight === 0 ); @@ -1500,7 +1555,7 @@ jQuery.support = (function() { // gets computed margin-right based on width of container. (#3333) // Fails in WebKit before Feb 2011 nightlies // WebKit Bug 13343 - getComputedStyle returns wrong value for margin-right - marginDiv = div.appendChild( document.createElement("div") ); + marginDiv = div.appendChild( document.createElement( "div" ) ); marginDiv.style.cssText = div.style.cssText = divReset; marginDiv.style.marginRight = marginDiv.style.width = "0"; div.style.width = "1px"; @@ -1510,6 +1565,7 @@ jQuery.support = (function() { } if ( typeof div.style.zoom !== core_strundefined ) { + // Support: IE<8 // Check if natively block-level elements act like inline-block // elements when setting their display to 'inline' and giving @@ -1526,6 +1582,7 @@ jQuery.support = (function() { support.shrinkWrapBlocks = ( div.offsetWidth !== 3 ); if ( support.inlineBlockNeedsLayout ) { + // Prevent IE 6 from affecting layout for positioned elements #11048 // Prevent IE from shrinking the body in IE 7 mode #12869 // Support: IE<8 @@ -1537,18 +1594,18 @@ jQuery.support = (function() { // Null elements to avoid leaks in IE container = div = tds = marginDiv = null; - }); + } ); // Null elements to avoid leaks in IE all = select = fragment = opt = a = input = null; return support; -})(); +} )(); var rbrace = /(?:\{[\s\S]*\}|\[[\s\S]*\])$/, rmultiDash = /([A-Z])/g; -function internalData( elem, name, data, pvt /* Internal Use Only */ ){ +function internalData( elem, name, data, pvt /* Internal Use Only */ ) { if ( !jQuery.acceptData( elem ) ) { return; } @@ -1571,11 +1628,12 @@ function internalData( elem, name, data, pvt /* Internal Use Only */ ){ // Avoid doing any more work than we need to when trying to get data on an // object that has no data at all - if ( (!id || !cache[id] || (!pvt && !cache[id].data)) && getByName && data === undefined ) { + if ( ( !id || !cache[ id ] || ( !pvt && !cache[ id ].data ) ) && getByName && data === undefined ) { return; } if ( !id ) { + // Only DOM nodes need a new unique ID for each element since their data // ends up in the global cache if ( isNode ) { @@ -1679,10 +1737,11 @@ function internalRemoveData( elem, name, pvt ) { if ( name in thisCache ) { name = [ name ]; } else { - name = name.split(" "); + name = name.split( " " ); } } } else { + // If "name" is an array of keys... // When data is initially created, via ("key", "val") signature, // keys will be converted to camelCase. @@ -1693,7 +1752,7 @@ function internalRemoveData( elem, name, pvt ) { } for ( i = 0, l = name.length; i < l; i++ ) { - delete thisCache[ name[i] ]; + delete thisCache[ name[ i ] ]; } // If there is no data left in the cache, we want to continue @@ -1729,7 +1788,7 @@ function internalRemoveData( elem, name, pvt ) { } } -jQuery.extend({ +jQuery.extend( { cache: {}, // Unique for each copy of jQuery on the page @@ -1740,13 +1799,14 @@ jQuery.extend({ // attempt to add expando properties to them. noData: { "embed": true, + // Ban all objects except for Flash (which handle expandos) "object": "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000", "applet": true }, hasData: function( elem ) { - elem = elem.nodeType ? jQuery.cache[ elem[jQuery.expando] ] : elem[ jQuery.expando ]; + elem = elem.nodeType ? jQuery.cache[ elem[ jQuery.expando ] ] : elem[ jQuery.expando ]; return !!elem && !isEmptyDataObject( elem ); }, @@ -1769,6 +1829,7 @@ jQuery.extend({ // A method for determining if a DOM node can handle the data expando acceptData: function( elem ) { + // Do not set data on non-element because it will not be cleared (#8335). if ( elem.nodeType && elem.nodeType !== 1 && elem.nodeType !== 9 ) { return false; @@ -1777,14 +1838,14 @@ jQuery.extend({ var noData = elem.nodeName && jQuery.noData[ elem.nodeName.toLowerCase() ]; // nodes accept data unless otherwise specified; rejection can be conditional - return !noData || noData !== true && elem.getAttribute("classid") === noData; + return !noData || noData !== true && elem.getAttribute( "classid" ) === noData; } -}); +} ); -jQuery.fn.extend({ +jQuery.fn.extend( { data: function( key, value ) { var attrs, name, - elem = this[0], + elem = this[ 0 ], i = 0, data = null; @@ -1796,10 +1857,10 @@ jQuery.fn.extend({ if ( elem.nodeType === 1 && !jQuery._data( elem, "parsedAttrs" ) ) { attrs = elem.attributes; for ( ; i < attrs.length; i++ ) { - name = attrs[i].name; + name = attrs[ i ].name; if ( !name.indexOf( "data-" ) ) { - name = jQuery.camelCase( name.slice(5) ); + name = jQuery.camelCase( name.slice( 5 ) ); dataAttr( elem, name, data[ name ] ); } @@ -1813,32 +1874,34 @@ jQuery.fn.extend({ // Sets multiple values if ( typeof key === "object" ) { - return this.each(function() { + return this.each( function() { jQuery.data( this, key ); - }); + } ); } return jQuery.access( this, function( value ) { if ( value === undefined ) { + // Try to fetch any internally stored data first return elem ? dataAttr( elem, key, jQuery.data( elem, key ) ) : null; } - this.each(function() { + this.each( function() { jQuery.data( this, key, value ); - }); + } ); }, null, value, arguments.length > 1, null, true ); }, removeData: function( key ) { - return this.each(function() { + return this.each( function() { jQuery.removeData( this, key ); - }); + } ); } -}); +} ); function dataAttr( elem, key, data ) { + // If nothing was found internally, try to fetch any // data from the HTML5 data-* attribute if ( data === undefined && elem.nodeType === 1 ) { @@ -1852,11 +1915,12 @@ 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 ) : data; - } catch( e ) {} + } catch ( e ) {} // Make sure we set the data so it isn't changed later jQuery.data( elem, key, data ); @@ -1875,7 +1939,7 @@ function isEmptyDataObject( obj ) { for ( name in obj ) { // if the public data object is empty, the private is still empty - if ( name === "data" && jQuery.isEmptyObject( obj[name] ) ) { + if ( name === "data" && jQuery.isEmptyObject( obj[ name ] ) ) { continue; } if ( name !== "toJSON" ) { @@ -1885,7 +1949,7 @@ function isEmptyDataObject( obj ) { return true; } -jQuery.extend({ +jQuery.extend( { queue: function( elem, type, data ) { var queue; @@ -1895,8 +1959,8 @@ jQuery.extend({ // Speed up dequeue by getting out quickly if this is just a lookup if ( data ) { - if ( !queue || jQuery.isArray(data) ) { - queue = jQuery._data( elem, type, jQuery.makeArray(data) ); + if ( !queue || jQuery.isArray( data ) ) { + queue = jQuery._data( elem, type, jQuery.makeArray( data ) ); } else { queue.push( data ); } @@ -1945,15 +2009,15 @@ jQuery.extend({ _queueHooks: function( elem, type ) { var key = type + "queueHooks"; return jQuery._data( elem, key ) || jQuery._data( elem, key, { - empty: jQuery.Callbacks("once memory").add(function() { + empty: jQuery.Callbacks( "once memory" ).add( function() { jQuery._removeData( elem, type + "queue" ); jQuery._removeData( elem, key ); - }) - }); + } ) + } ); } -}); +} ); -jQuery.fn.extend({ +jQuery.fn.extend( { queue: function( type, data ) { var setter = 2; @@ -1964,27 +2028,28 @@ jQuery.fn.extend({ } if ( arguments.length < setter ) { - return jQuery.queue( this[0], type ); + return jQuery.queue( this[ 0 ], type ); } return data === undefined ? this : - this.each(function() { + this.each( function() { var queue = jQuery.queue( this, type, data ); // ensure a hooks for this queue jQuery._queueHooks( this, type ); - if ( type === "fx" && queue[0] !== "inprogress" ) { + if ( type === "fx" && queue[ 0 ] !== "inprogress" ) { jQuery.dequeue( this, type ); } - }); + } ); }, dequeue: function( type ) { - return this.each(function() { + return this.each( function() { jQuery.dequeue( this, type ); - }); + } ); }, + // Based off of the plugin by Clint Helfers, with permission. // http://blindsignals.com/index.php/2009/07/jquery-delay/ delay: function( time, type ) { @@ -1996,11 +2061,12 @@ jQuery.fn.extend({ hooks.stop = function() { clearTimeout( timeout ); }; - }); + } ); }, 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 ) { @@ -2021,7 +2087,7 @@ jQuery.fn.extend({ } type = type || "fx"; - while( i-- ) { + while ( i-- ) { tmp = jQuery._data( elements[ i ], type + "queueHooks" ); if ( tmp && tmp.empty ) { count++; @@ -2031,7 +2097,7 @@ jQuery.fn.extend({ resolve(); return defer.promise( obj ); } -}); +} ); var nodeHook, boolHook, rclass = /[\t\r\n]/g, rreturn = /\r/g, @@ -2042,15 +2108,15 @@ var nodeHook, boolHook, getSetAttribute = jQuery.support.getSetAttribute, getSetInput = jQuery.support.input; -jQuery.fn.extend({ +jQuery.fn.extend( { attr: function( name, value ) { return jQuery.access( this, jQuery.attr, name, value, arguments.length > 1 ); }, removeAttr: function( name ) { - return this.each(function() { + return this.each( function() { jQuery.removeAttr( this, name ); - }); + } ); }, prop: function( name, value ) { @@ -2059,13 +2125,14 @@ jQuery.fn.extend({ removeProp: function( name ) { name = jQuery.propFix[ name ] || name; - return this.each(function() { + return this.each( function() { + // try/catch handles cases where IE balks (such as removing a property on window) try { this[ name ] = undefined; delete this[ name ]; - } catch( e ) {} - }); + } catch ( e ) {} + } ); }, addClass: function( value ) { @@ -2075,12 +2142,13 @@ jQuery.fn.extend({ proceed = typeof value === "string" && value; if ( jQuery.isFunction( value ) ) { - return this.each(function( j ) { + return this.each( function( j ) { jQuery( this ).addClass( value.call( this, j, this.className ) ); - }); + } ); } if ( proceed ) { + // The disjunction here is for better compressibility (see removeClass) classes = ( value || "" ).match( core_rnotwhite ) || []; @@ -2093,7 +2161,7 @@ jQuery.fn.extend({ if ( cur ) { j = 0; - while ( (clazz = classes[j++]) ) { + while ( ( clazz = classes[ j++ ] ) ) { if ( cur.indexOf( " " + clazz + " " ) < 0 ) { cur += clazz + " "; } @@ -2114,15 +2182,16 @@ jQuery.fn.extend({ proceed = arguments.length === 0 || typeof value === "string" && value; if ( jQuery.isFunction( value ) ) { - return this.each(function( j ) { + return this.each( function( j ) { jQuery( this ).removeClass( value.call( this, j, this.className ) ); - }); + } ); } if ( proceed ) { classes = ( value || "" ).match( core_rnotwhite ) || []; for ( ; i < len; i++ ) { elem = this[ i ]; + // This expression is here for better compressibility (see addClass) cur = elem.nodeType === 1 && ( elem.className ? ( " " + elem.className + " " ).replace( rclass, " " ) : @@ -2131,7 +2200,8 @@ jQuery.fn.extend({ if ( cur ) { j = 0; - while ( (clazz = classes[j++]) ) { + while ( ( clazz = classes[ j++ ] ) ) { + // Remove *all* instances while ( cur.indexOf( " " + clazz + " " ) >= 0 ) { cur = cur.replace( " " + clazz + " ", " " ); @@ -2150,13 +2220,14 @@ jQuery.fn.extend({ isBool = typeof stateVal === "boolean"; if ( jQuery.isFunction( value ) ) { - return this.each(function( i ) { - jQuery( this ).toggleClass( value.call(this, i, this.className, stateVal), stateVal ); - }); + return this.each( function( i ) { + jQuery( this ).toggleClass( value.call( this, i, this.className, stateVal ), stateVal ); + } ); } - return this.each(function() { + return this.each( function() { if ( type === "string" ) { + // toggle individual class names var className, i = 0, @@ -2164,7 +2235,8 @@ jQuery.fn.extend({ state = stateVal, classNames = value.match( core_rnotwhite ) || []; - while ( (className = classNames[ i++ ]) ) { + while ( ( className = classNames[ i++ ] ) ) { + // check each className given, space separated list state = isBool ? state : !self.hasClass( className ); self[ state ? "addClass" : "removeClass" ]( className ); @@ -2173,6 +2245,7 @@ jQuery.fn.extend({ // Toggle whole class name } else if ( type === core_strundefined || type === "boolean" ) { if ( this.className ) { + // store className if set jQuery._data( this, "__className__", this.className ); } @@ -2183,7 +2256,7 @@ jQuery.fn.extend({ // falling back to the empty string if nothing was stored. this.className = this.className || value === false ? "" : jQuery._data( this, "__className__" ) || ""; } - }); + } ); }, hasClass: function( selector ) { @@ -2191,7 +2264,7 @@ jQuery.fn.extend({ i = 0, l = this.length; for ( ; i < l; i++ ) { - if ( this[i].nodeType === 1 && (" " + this[i].className + " ").replace(rclass, " ").indexOf( className ) >= 0 ) { + if ( this[ i ].nodeType === 1 && ( " " + this[ i ].className + " " ).replace( rclass, " " ).indexOf( className ) >= 0 ) { return true; } } @@ -2201,21 +2274,23 @@ jQuery.fn.extend({ val: function( value ) { var ret, hooks, isFunction, - elem = this[0]; + elem = this[ 0 ]; if ( !arguments.length ) { if ( elem ) { 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, "") : + ret.replace( rreturn, "" ) : + // handle cases where value is null/undef or number ret == null ? "" : ret; } @@ -2225,9 +2300,9 @@ jQuery.fn.extend({ isFunction = jQuery.isFunction( value ); - return this.each(function( i ) { + return this.each( function( i ) { var val, - self = jQuery(this); + self = jQuery( this ); if ( this.nodeType !== 1 ) { return; @@ -2245,25 +2320,26 @@ jQuery.fn.extend({ } else if ( typeof val === "number" ) { val += ""; } else if ( jQuery.isArray( val ) ) { - val = jQuery.map(val, function ( value ) { + val = jQuery.map( val, function( value ) { return value == null ? "" : value + ""; - }); + } ); } hooks = jQuery.valHooks[ this.type ] || jQuery.valHooks[ this.nodeName.toLowerCase() ]; // If set returns undefined, fall back to normal setting - if ( !hooks || !("set" in hooks) || hooks.set( this, val, "value" ) === undefined ) { + if ( !hooks || !( "set" in hooks ) || hooks.set( this, val, "value" ) === undefined ) { this.value = val; } - }); + } ); } -}); +} ); -jQuery.extend({ +jQuery.extend( { valHooks: { option: { get: function( elem ) { + // attributes.value is undefined in Blackberry 4.7 but // uses .value. See #6932 var val = elem.attributes.value; @@ -2288,8 +2364,9 @@ jQuery.extend({ // oldIE 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 - ( jQuery.support.optDisabled ? !option.disabled : option.getAttribute("disabled") === null ) && + ( jQuery.support.optDisabled ? !option.disabled : option.getAttribute( "disabled" ) === null ) && ( !option.parentNode.disabled || !jQuery.nodeName( option.parentNode, "optgroup" ) ) ) { // Get the specific value for the option @@ -2311,9 +2388,9 @@ jQuery.extend({ set: function( elem, value ) { var values = jQuery.makeArray( value ); - jQuery(elem).find("option").each(function() { - this.selected = jQuery.inArray( jQuery(this).val(), values ) >= 0; - }); + jQuery( elem ).find( "option" ).each( function() { + this.selected = jQuery.inArray( jQuery( this ).val(), values ) >= 0; + } ); if ( !values.length ) { elem.selectedIndex = -1; @@ -2351,7 +2428,7 @@ jQuery.extend({ if ( value === null ) { jQuery.removeAttr( elem, name ); - } else if ( hooks && notxml && "set" in hooks && (ret = hooks.set( elem, value, name )) !== undefined ) { + } else if ( hooks && notxml && "set" in hooks && ( ret = hooks.set( elem, value, name ) ) !== undefined ) { return ret; } else { @@ -2359,7 +2436,7 @@ jQuery.extend({ return value; } - } else if ( hooks && notxml && "get" in hooks && (ret = hooks.get( elem, name )) !== null ) { + } else if ( hooks && notxml && "get" in hooks && ( ret = hooks.get( elem, name ) ) !== null ) { return ret; } else { @@ -2383,11 +2460,12 @@ jQuery.extend({ attrNames = value && value.match( core_rnotwhite ); if ( attrNames && elem.nodeType === 1 ) { - while ( (name = attrNames[i++]) ) { + while ( ( name = attrNames[ i++ ] ) ) { propName = jQuery.propFix[ name ] || name; // Boolean attributes get special treatment (#10870) if ( rboolean.test( name ) ) { + // Set corresponding property to false for boolean attributes // Also clear defaultChecked/defaultSelected (if appropriate) for IE<8 if ( !getSetAttribute && ruseDefault.test( name ) ) { @@ -2410,7 +2488,8 @@ jQuery.extend({ attrHooks: { type: { set: function( elem, value ) { - if ( !jQuery.support.radioValue && value === "radio" && jQuery.nodeName(elem, "input") ) { + if ( !jQuery.support.radioValue && value === "radio" && jQuery.nodeName( elem, "input" ) ) { + // Setting the type on a radio button after the value resets the value in IE6-9 // Reset value to default in case type is set after value during creation var val = elem.value; @@ -2451,13 +2530,14 @@ jQuery.extend({ notxml = nType !== 1 || !jQuery.isXMLDoc( elem ); if ( notxml ) { + // Fix name and attach hooks name = jQuery.propFix[ name ] || name; hooks = jQuery.propHooks[ name ]; } if ( value !== undefined ) { - if ( hooks && "set" in hooks && (ret = hooks.set( elem, value, name )) !== undefined ) { + if ( hooks && "set" in hooks && ( ret = hooks.set( elem, value, name ) ) !== undefined ) { return ret; } else { @@ -2465,7 +2545,7 @@ jQuery.extend({ } } else { - if ( hooks && "get" in hooks && (ret = hooks.get( elem, name )) !== null ) { + if ( hooks && "get" in hooks && ( ret = hooks.get( elem, name ) ) !== null ) { return ret; } else { @@ -2477,9 +2557,10 @@ jQuery.extend({ propHooks: { tabIndex: { get: function( elem ) { + // elem.tabIndex doesn't always return the correct value when it hasn't been explicitly set // http://fluidproject.org/blog/2008/01/09/getting-setting-and-removing-tabindex-values-with-javascript/ - var attributeNode = elem.getAttributeNode("tabindex"); + var attributeNode = elem.getAttributeNode( "tabindex" ); return attributeNode && attributeNode.specified ? parseInt( attributeNode.value, 10 ) : @@ -2489,12 +2570,13 @@ jQuery.extend({ } } } -}); +} ); // Hook for boolean attributes boolHook = { get: function( elem, name ) { var + // Use .prop to determine if this attribute is understood as boolean prop = jQuery.prop( elem, name ), @@ -2504,6 +2586,7 @@ boolHook = { getSetInput && getSetAttribute ? attr != null : + // oldIE fabricates an empty string for missing boolean attributes // and conflates checked/selected into attroperties ruseDefault.test( name ) ? @@ -2519,9 +2602,11 @@ boolHook = { }, set: function( elem, value, name ) { if ( value === false ) { + // Remove boolean attributes when set to false jQuery.removeAttr( elem, name ); } else if ( getSetInput && getSetAttribute || !ruseDefault.test( name ) ) { + // IE<8 needs the *property* name elem.setAttribute( !getSetAttribute && jQuery.propFix[ name ] || name, name ); @@ -2548,9 +2633,11 @@ if ( !getSetInput || !getSetAttribute ) { }, set: function( elem, value, name ) { if ( jQuery.nodeName( elem, "input" ) ) { + // Does not return so that setAttribute is also used elem.defaultValue = value; } else { + // Use nodeHook if defined (#1954); otherwise setAttribute is fine return nodeHook && nodeHook.set( elem, value, name ); } @@ -2571,11 +2658,12 @@ if ( !getSetAttribute ) { undefined; }, set: function( elem, value, name ) { + // Set the existing or create a new attribute node var ret = elem.getAttributeNode( name ); if ( !ret ) { elem.setAttributeNode( - (ret = elem.ownerDocument.createAttribute( name )) + ( ret = elem.ownerDocument.createAttribute( name ) ) ); } @@ -2599,7 +2687,7 @@ if ( !getSetAttribute ) { // Set width and height to auto instead of 0 on empty string( Bug #8150 ) // This is for removals - jQuery.each([ "width", "height" ], function( i, name ) { + jQuery.each( [ "width", "height" ], function( i, name ) { jQuery.attrHooks[ name ] = jQuery.extend( jQuery.attrHooks[ name ], { set: function( elem, value ) { if ( value === "" ) { @@ -2607,36 +2695,36 @@ if ( !getSetAttribute ) { return value; } } - }); - }); + } ); + } ); } - // Some attributes require a special call on IE // http://msdn.microsoft.com/en-us/library/ms536429%28VS.85%29.aspx if ( !jQuery.support.hrefNormalized ) { - jQuery.each([ "href", "src", "width", "height" ], function( i, name ) { + jQuery.each( [ "href", "src", "width", "height" ], function( i, name ) { jQuery.attrHooks[ name ] = jQuery.extend( jQuery.attrHooks[ name ], { get: function( elem ) { var ret = elem.getAttribute( name, 2 ); return ret == null ? undefined : ret; } - }); - }); + } ); + } ); // href/src property should get the full normalized URL (#10299/#12915) - jQuery.each([ "href", "src" ], function( i, name ) { + jQuery.each( [ "href", "src" ], function( i, name ) { jQuery.propHooks[ name ] = { get: function( elem ) { return elem.getAttribute( name, 4 ); } }; - }); + } ); } if ( !jQuery.support.style ) { jQuery.attrHooks.style = { get: function( elem ) { + // Return undefined in the case of empty string // Note: IE uppercases css property names, but if we were to .toLowerCase() // .cssText, that would destroy case senstitivity in URL's, like in "background" @@ -2665,7 +2753,7 @@ if ( !jQuery.support.optSelected ) { } return null; } - }); + } ); } // IE6/7 call enctype encoding @@ -2675,24 +2763,25 @@ if ( !jQuery.support.enctype ) { // Radios and checkboxes getter/setter if ( !jQuery.support.checkOn ) { - jQuery.each([ "radio", "checkbox" ], function() { + jQuery.each( [ "radio", "checkbox" ], function() { jQuery.valHooks[ this ] = { get: function( elem ) { + // Handle the case where in Webkit "" is returned instead of "on" if a value isn't specified - return elem.getAttribute("value") === null ? "on" : elem.value; + return elem.getAttribute( "value" ) === null ? "on" : elem.value; } }; - }); + } ); } -jQuery.each([ "radio", "checkbox" ], function() { +jQuery.each( [ "radio", "checkbox" ], function() { jQuery.valHooks[ this ] = jQuery.extend( jQuery.valHooks[ this ], { set: function( elem, value ) { if ( jQuery.isArray( value ) ) { - return ( elem.checked = jQuery.inArray( jQuery(elem).val(), value ) >= 0 ); + return ( elem.checked = jQuery.inArray( jQuery( elem ).val(), value ) >= 0 ); } } - }); -}); + } ); +} ); var rformElems = /^(?:input|select|textarea)$/i, rkeyEvent = /^key/, rmouseEvent = /^(?:mouse|contextmenu)|click/, @@ -2739,29 +2828,31 @@ jQuery.event = { } // Init the element's event structure and main handler, if this is the first - if ( !(events = elemData.events) ) { + if ( !( events = elemData.events ) ) { events = elemData.events = {}; } - if ( !(eventHandle = elemData.handle) ) { + 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 !== core_strundefined && (!e || jQuery.event.triggered !== e.type) ? + return typeof jQuery !== core_strundefined && ( !e || jQuery.event.triggered !== e.type ) ? jQuery.event.dispatch.apply( eventHandle.elem, arguments ) : undefined; }; + // Add elem as a property of the handle fn to prevent a memory leak with IE non-native events eventHandle.elem = elem; } // Handle multiple events separated by a space // jQuery(...).bind("mouseover mouseout", fn); - types = ( types || "" ).match( core_rnotwhite ) || [""]; + types = ( types || "" ).match( core_rnotwhite ) || [ "" ]; t = types.length; while ( t-- ) { - tmp = rtypenamespace.exec( types[t] ) || []; - type = origType = tmp[1]; - namespaces = ( tmp[2] || "" ).split( "." ).sort(); + tmp = rtypenamespace.exec( types[ t ] ) || []; + type = origType = tmp[ 1 ]; + namespaces = ( tmp[ 2 ] || "" ).split( "." ).sort(); // If event changes its type, use the special event handlers for the changed type special = jQuery.event.special[ type ] || {}; @@ -2773,7 +2864,7 @@ jQuery.event = { special = jQuery.event.special[ type ] || {}; // handleObj is passed to all event handlers - handleObj = jQuery.extend({ + handleObj = jQuery.extend( { type: type, origType: origType, data: data, @@ -2781,16 +2872,17 @@ jQuery.event = { guid: handler.guid, selector: selector, needsContext: selector && jQuery.expr.match.needsContext.test( selector ), - namespace: namespaces.join(".") + namespace: namespaces.join( "." ) }, handleObjIn ); // Init the event handler queue if we're the first - if ( !(handlers = events[ type ]) ) { + if ( !( handlers = events[ type ] ) ) { handlers = events[ type ] = []; handlers.delegateCount = 0; // Only use addEventListener/attachEvent if the special events handler returns false if ( !special.setup || special.setup.call( elem, data, namespaces, eventHandle ) === false ) { + // Bind the global event handler to the element if ( elem.addEventListener ) { elem.addEventListener( type, eventHandle, false ); @@ -2832,17 +2924,17 @@ jQuery.event = { namespaces, origType, elemData = jQuery.hasData( elem ) && jQuery._data( elem ); - if ( !elemData || !(events = elemData.events) ) { + if ( !elemData || !( events = elemData.events ) ) { return; } // Once for each type.namespace in types; type may be omitted - types = ( types || "" ).match( core_rnotwhite ) || [""]; + types = ( types || "" ).match( core_rnotwhite ) || [ "" ]; t = types.length; while ( t-- ) { - tmp = rtypenamespace.exec( types[t] ) || []; - type = origType = tmp[1]; - namespaces = ( tmp[2] || "" ).split( "." ).sort(); + tmp = rtypenamespace.exec( types[ t ] ) || []; + type = origType = tmp[ 1 ]; + namespaces = ( tmp[ 2 ] || "" ).split( "." ).sort(); // Unbind all events (on this namespace, if provided) for the element if ( !type ) { @@ -2855,7 +2947,7 @@ 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; @@ -2903,7 +2995,7 @@ jQuery.event = { bubbleType, special, tmp, i, eventPath = [ elem || document ], type = core_hasOwn.call( event, "type" ) ? event.type : event, - namespaces = core_hasOwn.call( event, "namespace" ) ? event.namespace.split(".") : []; + namespaces = core_hasOwn.call( event, "namespace" ) ? event.namespace.split( "." ) : []; cur = tmp = elem = elem || document; @@ -2917,13 +3009,14 @@ jQuery.event = { return; } - if ( type.indexOf(".") >= 0 ) { + if ( type.indexOf( "." ) >= 0 ) { + // Namespaced trigger; create a regexp to match event type in handle() - namespaces = type.split("."); + namespaces = type.split( "." ); type = namespaces.shift(); namespaces.sort(); } - ontype = type.indexOf(":") < 0 && "on" + type; + ontype = type.indexOf( ":" ) < 0 && "on" + type; // Caller can pass in a jQuery.Event object, Object, or just an event type string event = event[ jQuery.expando ] ? @@ -2931,9 +3024,9 @@ jQuery.event = { new jQuery.Event( type, typeof event === "object" && event ); event.isTrigger = true; - event.namespace = namespaces.join("."); + event.namespace = namespaces.join( "." ); event.namespace_re = event.namespace ? - new RegExp( "(^|\\.)" + namespaces.join("\\.(?:.*\\.|)") + "(\\.|$)" ) : + new RegExp( "(^|\\.)" + namespaces.join( "\\.(?:.*\\.|)" ) + "(\\.|$)" ) : null; // Clean up the event in case it is being reused @@ -2967,14 +3060,14 @@ jQuery.event = { } // Only add window if we got to document (e.g., not plain obj or detached DOM) - if ( tmp === (elem.ownerDocument || document) ) { + if ( tmp === ( elem.ownerDocument || document ) ) { eventPath.push( tmp.defaultView || tmp.parentWindow || window ); } } // Fire handlers on the event path i = 0; - while ( (cur = eventPath[i++]) && !event.isPropagationStopped() ) { + while ( ( cur = eventPath[ i++ ] ) && !event.isPropagationStopped() ) { event.type = i > 1 ? bubbleType : @@ -2997,8 +3090,8 @@ jQuery.event = { // If nobody prevented the default action, do it now if ( !onlyHandlers && !event.isDefaultPrevented() ) { - if ( (!special._default || special._default.apply( elem.ownerDocument, data ) === false) && - !(type === "click" && jQuery.nodeName( elem, "a" )) && jQuery.acceptData( elem ) ) { + if ( ( !special._default || special._default.apply( elem.ownerDocument, data ) === false ) && + !( type === "click" && jQuery.nodeName( elem, "a" ) ) && jQuery.acceptData( elem ) ) { // Call a native DOM method on the target with the same name name as the event. // Can't use an .isFunction() check here because IE6/7 fails that test. @@ -3017,6 +3110,7 @@ jQuery.event = { try { elem[ type ](); } catch ( e ) { + // IE<9 dies on focus/blur to hidden element (#1486,#12518) // only reproducible on winXP IE8 native, not IE9 in IE8 mode } @@ -3044,7 +3138,7 @@ jQuery.event = { special = jQuery.event.special[ event.type ] || {}; // Use the fix-ed jQuery.Event rather than the (read-only) native event - args[0] = event; + args[ 0 ] = event; event.delegateTarget = this; // Call the preDispatch hook for the mapped type, and let it bail if desired @@ -3057,11 +3151,11 @@ jQuery.event = { // Run delegates first; they may want to stop propagation beneath us i = 0; - while ( (matched = handlerQueue[ i++ ]) && !event.isPropagationStopped() ) { + while ( ( matched = handlerQueue[ i++ ] ) && !event.isPropagationStopped() ) { event.currentTarget = matched.elem; j = 0; - while ( (handleObj = matched.handlers[ j++ ]) && !event.isImmediatePropagationStopped() ) { + while ( ( handleObj = matched.handlers[ j++ ] ) && !event.isImmediatePropagationStopped() ) { // Triggered event must either 1) have no namespace, or // 2) have namespace(s) a subset or equal to those in the bound event (both can have no namespace). @@ -3070,11 +3164,11 @@ jQuery.event = { event.handleObj = handleObj; event.data = handleObj.data; - ret = ( (jQuery.event.special[ handleObj.origType ] || {}).handle || handleObj.handler ) + ret = ( ( jQuery.event.special[ handleObj.origType ] || {} ).handle || handleObj.handler ) .apply( matched.elem, args ); if ( ret !== undefined ) { - if ( (event.result = ret) === false ) { + if ( ( event.result = ret ) === false ) { event.preventDefault(); event.stopPropagation(); } @@ -3100,13 +3194,13 @@ jQuery.event = { // Find delegate handlers // Black-hole SVG <use> instance trees (#13180) // Avoid non-left-click bubbling in Firefox (#3861) - if ( delegateCount && cur.nodeType && (!event.button || event.type !== "click") ) { + if ( delegateCount && cur.nodeType && ( !event.button || event.type !== "click" ) ) { for ( ; cur != this; cur = cur.parentNode || this ) { // Don't check non-elements (#13208) // Don't process clicks on disabled elements (#6911, #8165, #11382, #11764) - if ( cur.nodeType === 1 && (cur.disabled !== true || event.type !== "click") ) { + if ( cur.nodeType === 1 && ( cur.disabled !== true || event.type !== "click" ) ) { matches = []; for ( i = 0; i < delegateCount; i++ ) { handleObj = handlers[ i ]; @@ -3124,7 +3218,7 @@ jQuery.event = { } } if ( matches.length ) { - handlerQueue.push({ elem: cur, handlers: matches }); + handlerQueue.push( { elem: cur, handlers: matches } ); } } } @@ -3132,7 +3226,7 @@ jQuery.event = { // Add the remaining (directly-bound) handlers if ( delegateCount < handlers.length ) { - handlerQueue.push({ elem: this, handlers: handlers.slice( delegateCount ) }); + handlerQueue.push( { elem: this, handlers: handlers.slice( delegateCount ) } ); } return handlerQueue; @@ -3185,12 +3279,12 @@ jQuery.event = { }, // Includes some event props shared by KeyEvent and MouseEvent - props: "altKey bubbles cancelable ctrlKey currentTarget eventPhase metaKey relatedTarget shiftKey target timeStamp view which".split(" "), + props: "altKey bubbles cancelable ctrlKey currentTarget eventPhase metaKey relatedTarget shiftKey target timeStamp view which".split( " " ), fixHooks: {}, keyHooks: { - props: "char charCode key keyCode".split(" "), + props: "char charCode key keyCode".split( " " ), filter: function( event, original ) { // Add which for key events @@ -3203,7 +3297,7 @@ jQuery.event = { }, mouseHooks: { - props: "button buttons clientX clientY fromElement offsetX offsetY pageX pageY screenX screenY toElement".split(" "), + props: "button buttons clientX clientY fromElement offsetX offsetY pageX pageY screenX screenY toElement".split( " " ), filter: function( event, original ) { var body, eventDoc, doc, button = original.button, @@ -3236,10 +3330,12 @@ jQuery.event = { special: { load: { + // Prevent triggered image.load events from bubbling to window.load noBubble: true }, click: { + // For checkbox, fire native event so checked state will be right trigger: function() { if ( jQuery.nodeName( this, "input" ) && this.type === "checkbox" && this.click ) { @@ -3249,6 +3345,7 @@ jQuery.event = { } }, focus: { + // Fire native event if possible so blur/focus sequence is correct trigger: function() { if ( this !== document.activeElement && this.focus ) { @@ -3256,6 +3353,7 @@ jQuery.event = { this.focus(); return false; } catch ( e ) { + // Support: IE<9 // If we error on focus to hidden element (#1486, #12518), // let .trigger() run the handlers @@ -3286,6 +3384,7 @@ jQuery.event = { }, simulate: function( type, elem, event, bubble ) { + // Piggyback on a donor event to simulate a different one. // Fake originalEvent to avoid donor's stopPropagation, but if the // simulated event prevents default then we do the same on the donor. @@ -3330,8 +3429,9 @@ jQuery.removeEvent = document.removeEventListener ? }; jQuery.Event = function( src, props ) { + // Allow instantiation without the 'new' keyword - if ( !(this instanceof jQuery.Event) ) { + if ( !( this instanceof jQuery.Event ) ) { return new jQuery.Event( src, props ); } @@ -3394,6 +3494,7 @@ jQuery.Event.prototype = { if ( !e ) { return; } + // If stopPropagation exists, run it on the original event if ( e.stopPropagation ) { e.stopPropagation(); @@ -3410,7 +3511,7 @@ jQuery.Event.prototype = { }; // Create mouseenter/leave events using mouseover/out and event-time checks -jQuery.each({ +jQuery.each( { mouseenter: "mouseover", mouseleave: "mouseout" }, function( orig, fix ) { @@ -3426,7 +3527,7 @@ jQuery.each({ // For mousenter/leave call the handler if related is outside the target. // NB: No relatedTarget if the mouse left/entered the browser window - if ( !related || (related !== target && !jQuery.contains( target, related )) ) { + if ( !related || ( related !== target && !jQuery.contains( target, related ) ) ) { event.type = handleObj.origType; ret = handleObj.handler.apply( this, arguments ); event.type = fix; @@ -3434,13 +3535,14 @@ jQuery.each({ return ret; } }; -}); +} ); // IE submit delegation if ( !jQuery.support.submitBubbles ) { jQuery.event.special.submit = { setup: function() { + // Only need this for delegated form submit events if ( jQuery.nodeName( this, "form" ) ) { return false; @@ -3448,20 +3550,23 @@ if ( !jQuery.support.submitBubbles ) { // Lazy-add a submit handler when a descendant form may potentially be submitted jQuery.event.add( this, "click._submit keypress._submit", function( e ) { + // Node name check avoids a VML-related crash in IE (#9807) var elem = e.target, form = jQuery.nodeName( elem, "input" ) || jQuery.nodeName( elem, "button" ) ? elem.form : undefined; if ( form && !jQuery._data( form, "submitBubbles" ) ) { jQuery.event.add( form, "submit._submit", function( event ) { event._submit_bubble = true; - }); + } ); jQuery._data( form, "submitBubbles", true ); } - }); + } ); + // return undefined since we don't need an event listener }, postDispatch: function( event ) { + // If form was submitted by the user, bubble the event up the tree if ( event._submit_bubble ) { delete event._submit_bubble; @@ -3472,6 +3577,7 @@ if ( !jQuery.support.submitBubbles ) { }, teardown: function() { + // Only need this for delegated form submit events if ( jQuery.nodeName( this, "form" ) ) { return false; @@ -3491,6 +3597,7 @@ if ( !jQuery.support.changeBubbles ) { setup: function() { if ( rformElems.test( this.nodeName ) ) { + // IE doesn't fire change on a check/radio until blur; trigger it on click // after a propertychange. Eat the blur-change in special.change.handle. // This still fires onchange a second time for check/radio after blur. @@ -3499,17 +3606,19 @@ if ( !jQuery.support.changeBubbles ) { if ( event.originalEvent.propertyName === "checked" ) { this._just_changed = true; } - }); + } ); jQuery.event.add( this, "click._change", function( event ) { if ( this._just_changed && !event.isTrigger ) { this._just_changed = false; } + // Allow triggered, simulated change events (#11500) jQuery.event.simulate( "change", this, event, true ); - }); + } ); } return false; } + // Delegated event; lazy-add a change handler on descendant inputs jQuery.event.add( this, "beforeactivate._change", function( e ) { var elem = e.target; @@ -3519,17 +3628,17 @@ if ( !jQuery.support.changeBubbles ) { if ( this.parentNode && !event.isSimulated && !event.isTrigger ) { jQuery.event.simulate( "change", this.parentNode, event, true ); } - }); + } ); jQuery._data( elem, "changeBubbles", true ); } - }); + } ); }, handle: function( event ) { var elem = event.target; // Swallow native change events from checkbox/radio, we already triggered them above - if ( this !== elem || event.isSimulated || event.isTrigger || (elem.type !== "radio" && elem.type !== "checkbox") ) { + if ( this !== elem || event.isSimulated || event.isTrigger || ( elem.type !== "radio" && elem.type !== "checkbox" ) ) { return event.handleObj.handler.apply( this, arguments ); } }, @@ -3544,7 +3653,7 @@ if ( !jQuery.support.changeBubbles ) { // Create "bubbling" focus and blur events if ( !jQuery.support.focusinBubbles ) { - jQuery.each({ focus: "focusin", blur: "focusout" }, function( orig, fix ) { + jQuery.each( { focus: "focusin", blur: "focusout" }, function( orig, fix ) { // Attach a single capturing handler while someone wants focusin/focusout var attaches = 0, @@ -3564,18 +3673,20 @@ if ( !jQuery.support.focusinBubbles ) { } } }; - }); + } ); } -jQuery.fn.extend({ +jQuery.fn.extend( { on: function( types, selector, data, fn, /*INTERNAL*/ one ) { var type, origFn; // 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; @@ -3587,15 +3698,18 @@ jQuery.fn.extend({ } 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; @@ -3611,16 +3725,18 @@ jQuery.fn.extend({ 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++ ); } return this.each( function() { jQuery.event.add( this, types, fn, data, selector ); - }); + } ); }, one: function( types, selector, data, fn ) { return this.on( types, selector, data, fn, 1 ); @@ -3628,6 +3744,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( @@ -3638,6 +3755,7 @@ jQuery.fn.extend({ return this; } if ( typeof types === "object" ) { + // ( types-object [, selector] ) for ( type in types ) { this.off( type, selector, types[ type ] ); @@ -3645,6 +3763,7 @@ jQuery.fn.extend({ return this; } if ( selector === false || typeof selector === "function" ) { + // ( types [, fn] ) fn = selector; selector = undefined; @@ -3652,9 +3771,9 @@ jQuery.fn.extend({ if ( fn === false ) { fn = returnFalse; } - return this.each(function() { + return this.each( function() { jQuery.event.remove( this, types, fn, selector ); - }); + } ); }, bind: function( types, data, fn ) { @@ -3668,29 +3787,30 @@ 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, "**" ) : this.off( types, selector || "**", fn ); }, trigger: function( type, data ) { - return this.each(function() { + return this.each( function() { jQuery.event.trigger( type, data, this ); - }); + } ); }, triggerHandler: function( type, data ) { - var elem = this[0]; + var elem = this[ 0 ]; if ( elem ) { return jQuery.event.trigger( type, data, elem, true ); } } -}); +} ); /*! * Sizzle CSS Selector Engine * Copyright 2012 jQuery Foundation and other contributors * Released under the MIT license * http://sizzlejs.com/ */ -(function( window, undefined ) { +( function( window, undefined ) { var i, cachedruns, @@ -3713,7 +3833,7 @@ var i, sortOrder, // Instance-specific data - expando = "sizzle" + -(new Date()), + expando = "sizzle" + -( new Date() ), preferredDoc = window.document, support = {}, dirruns = 0, @@ -3731,23 +3851,24 @@ var i, pop = arr.pop, push = arr.push, slice = arr.slice, + // Use a stripped-down indexOf if we can't use a native one indexOf = arr.indexOf || function( elem ) { var i = 0, len = this.length; for ( ; i < len; i++ ) { - if ( this[i] === elem ) { + if ( this[ i ] === elem ) { return i; } } return -1; }, - // Regular expressions // Whitespace characters http://www.w3.org/TR/css3-selectors/#whitespace whitespace = "[\\x20\\t\\r\\n\\f]", + // http://www.w3.org/TR/css3-syntax/#characters characterEncoding = "(?:\\\\.|[\\w-]|[^\\x00-\\xa0])+", @@ -3787,6 +3908,7 @@ var i, "CHILD": new RegExp( "^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\(" + whitespace + "*(even|odd|(([+-]|)(\\d*)n|)" + whitespace + "*(?:([+-]|)" + whitespace + "*(\\d+)|))" + whitespace + "*\\)|)", "i" ), + // For use in libraries implementing .is() // We use this for POS matching in `select` "needsContext": new RegExp( "^" + whitespace + "*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\(" + @@ -3810,24 +3932,27 @@ var i, runescape = /\\([\da-fA-F]{1,6}[\x20\t\r\n\f]?|.)/g, funescape = function( _, escaped ) { var high = "0x" + escaped - 0x10000; + // NaN means non-codepoint return high !== high ? escaped : + // BMP codepoint high < 0 ? String.fromCharCode( high + 0x10000 ) : + // Supplemental Plane codepoint (surrogate pair) String.fromCharCode( high >> 10 | 0xD800, high & 0x3FF | 0xDC00 ); }; // Use a stripped-down slice if we can't use a native one try { - slice.call( preferredDoc.documentElement.childNodes, 0 )[0].nodeType; + slice.call( preferredDoc.documentElement.childNodes, 0 )[ 0 ].nodeType; } catch ( e ) { slice = function( i ) { var elem, results = []; - while ( (elem = this[i++]) ) { + while ( ( elem = this[ i++ ] ) ) { results.push( elem ); } return results; @@ -3852,14 +3977,16 @@ function createCache() { var cache, keys = []; - return (cache = function( key, value ) { + return ( cache = function( key, value ) { + // Use (key + " ") to avoid collision with native prototype properties (see Issue #157) if ( keys.push( key += " " ) > Expr.cacheLength ) { + // Only keep the most recent entries delete cache[ keys.shift() ]; } - return (cache[ key ] = value); - }); + return ( cache[ key ] = value ); + } ); } /** @@ -3876,13 +4003,14 @@ function markFunction( fn ) { * @param {Function} fn Passed the created div and expects a boolean result */ function assert( fn ) { - var div = document.createElement("div"); + var div = document.createElement( "div" ); try { return fn( div ); - } catch (e) { + } catch ( e ) { return false; } finally { + // release memory in IE div = null; } @@ -3890,6 +4018,7 @@ function assert( fn ) { function Sizzle( selector, context, results, seed ) { var match, elem, m, nodeType, + // QSA vars i, groups, old, nid, newContext, newSelector; @@ -3904,21 +4033,24 @@ function Sizzle( selector, context, results, seed ) { return results; } - if ( (nodeType = context.nodeType) !== 1 && nodeType !== 9 ) { + if ( ( nodeType = context.nodeType ) !== 1 && nodeType !== 9 ) { return []; } if ( !documentIsXML && !seed ) { // Shortcuts - if ( (match = rquickExpr.exec( selector )) ) { + if ( ( match = rquickExpr.exec( selector ) ) ) { + // Speed-up: Sizzle("#ID") - if ( (m = match[1]) ) { + if ( ( m = match[ 1 ] ) ) { if ( nodeType === 9 ) { elem = context.getElementById( m ); + // Check parentNode to catch when Blackberry 4.6 returns // nodes that are no longer in the document #6963 if ( elem && elem.parentNode ) { + // Handle the case where IE, Opera, and Webkit return items // by name instead of ID if ( elem.id === m ) { @@ -3929,8 +4061,9 @@ function Sizzle( selector, context, results, seed ) { return results; } } else { + // Context is not a document - if ( context.ownerDocument && (elem = context.ownerDocument.getElementById( m )) && + if ( context.ownerDocument && ( elem = context.ownerDocument.getElementById( m ) ) && contains( context, elem ) && elem.id === m ) { results.push( elem ); return results; @@ -3938,19 +4071,19 @@ function Sizzle( selector, context, results, seed ) { } // Speed-up: Sizzle("TAG") - } else if ( match[2] ) { - push.apply( results, slice.call(context.getElementsByTagName( selector ), 0) ); + } else if ( match[ 2 ] ) { + push.apply( results, slice.call( context.getElementsByTagName( selector ), 0 ) ); return results; // Speed-up: Sizzle(".CLASS") - } else if ( (m = match[3]) && support.getByClassName && context.getElementsByClassName ) { - push.apply( results, slice.call(context.getElementsByClassName( m ), 0) ); + } else if ( ( m = match[ 3 ] ) && support.getByClassName && context.getElementsByClassName ) { + push.apply( results, slice.call( context.getElementsByClassName( m ), 0 ) ); return results; } } // QSA path - if ( support.qsa && !rbuggyQSA.test(selector) ) { + if ( support.qsa && !rbuggyQSA.test( selector ) ) { old = true; nid = expando; newContext = context; @@ -3963,7 +4096,7 @@ function Sizzle( selector, context, results, seed ) { if ( nodeType === 1 && context.nodeName.toLowerCase() !== "object" ) { groups = tokenize( selector ); - if ( (old = context.getAttribute("id")) ) { + if ( ( old = context.getAttribute( "id" ) ) ) { nid = old.replace( rescape, "\\$&" ); } else { context.setAttribute( "id", nid ); @@ -3972,10 +4105,10 @@ function Sizzle( selector, context, results, seed ) { i = groups.length; while ( i-- ) { - groups[i] = nid + toSelector( groups[i] ); + groups[ i ] = nid + toSelector( groups[ i ] ); } newContext = rsibling.test( selector ) && context.parentNode || context; - newSelector = groups.join(","); + newSelector = groups.join( "," ); } if ( newSelector ) { @@ -3984,10 +4117,10 @@ function Sizzle( selector, context, results, seed ) { newSelector ), 0 ) ); return results; - } catch(qsaError) { + } catch ( qsaError ) { } finally { if ( !old ) { - context.removeAttribute("id"); + context.removeAttribute( "id" ); } } } @@ -4003,9 +4136,10 @@ function Sizzle( selector, context, results, seed ) { * @param {Element|Object} elem An element or a document */ isXML = Sizzle.isXML = function( elem ) { + // documentElement is verified for cases where it doesn't yet exist // (such as loading iframes in IE - #4833) - var documentElement = elem && (elem.ownerDocument || elem).documentElement; + var documentElement = elem && ( elem.ownerDocument || elem ).documentElement; return documentElement ? documentElement.nodeName !== "HTML" : false; }; @@ -4030,35 +4164,38 @@ setDocument = Sizzle.setDocument = function( node ) { documentIsXML = isXML( doc ); // Check if getElementsByTagName("*") returns only elements - support.tagNameNoComments = assert(function( div ) { - div.appendChild( doc.createComment("") ); - return !div.getElementsByTagName("*").length; - }); + support.tagNameNoComments = assert( function( div ) { + div.appendChild( doc.createComment( "" ) ); + return !div.getElementsByTagName( "*" ).length; + } ); // Check if attributes should be retrieved by attribute nodes - support.attributes = assert(function( div ) { + support.attributes = assert( function( div ) { div.innerHTML = "<select></select>"; - var type = typeof div.lastChild.getAttribute("multiple"); + var type = typeof div.lastChild.getAttribute( "multiple" ); + // IE8 returns a string for some attributes even when not present return type !== "boolean" && type !== "string"; - }); + } ); // Check if getElementsByClassName can be trusted - support.getByClassName = assert(function( div ) { + support.getByClassName = assert( function( div ) { + // Opera can't find a second classname (in 9.6) div.innerHTML = "<div class='hidden e'></div><div class='hidden'></div>"; - if ( !div.getElementsByClassName || !div.getElementsByClassName("e").length ) { + if ( !div.getElementsByClassName || !div.getElementsByClassName( "e" ).length ) { return false; } // Safari 3.2 caches class attributes and doesn't catch changes div.lastChild.className = "e"; - return div.getElementsByClassName("e").length === 2; - }); + return div.getElementsByClassName( "e" ).length === 2; + } ); // Check if getElementById returns elements by name // Check if getElementsByName privileges form controls or returns elements by ID - support.getByName = assert(function( div ) { + support.getByName = assert( function( div ) { + // Inject content div.id = expando + 0; div.innerHTML = "<a name='" + expando + "'></a><div name='" + expando + "'></div>"; @@ -4066,8 +4203,10 @@ setDocument = Sizzle.setDocument = function( node ) { // Test var pass = doc.getElementsByName && + // buggy browsers will return fewer than the correct 2 doc.getElementsByName( expando ).length === 2 + + // buggy browsers will return more than the correct 0 doc.getElementsByName( expando + 0 ).length; support.getIdNotName = !doc.getElementById( expando ); @@ -4076,63 +4215,64 @@ setDocument = Sizzle.setDocument = function( node ) { docElem.removeChild( div ); return pass; - }); + } ); // IE6/7 return modified attributes - Expr.attrHandle = assert(function( div ) { + Expr.attrHandle = assert( function( div ) { div.innerHTML = "<a href='#'></a>"; return div.firstChild && typeof div.firstChild.getAttribute !== strundefined && - div.firstChild.getAttribute("href") === "#"; - }) ? + div.firstChild.getAttribute( "href" ) === "#"; + } ) ? {} : { "href": function( elem ) { return elem.getAttribute( "href", 2 ); }, "type": function( elem ) { - return elem.getAttribute("type"); + return elem.getAttribute( "type" ); } }; // ID find and filter if ( support.getIdNotName ) { - Expr.find["ID"] = function( id, context ) { + Expr.find[ "ID" ] = function( id, context ) { if ( typeof context.getElementById !== strundefined && !documentIsXML ) { var m = context.getElementById( id ); + // Check parentNode to catch when Blackberry 4.6 returns // nodes that are no longer in the document #6963 - return m && m.parentNode ? [m] : []; + return m && m.parentNode ? [ m ] : []; } }; - Expr.filter["ID"] = function( id ) { + Expr.filter[ "ID" ] = function( id ) { var attrId = id.replace( runescape, funescape ); return function( elem ) { - return elem.getAttribute("id") === attrId; + return elem.getAttribute( "id" ) === attrId; }; }; } else { - Expr.find["ID"] = function( id, context ) { + Expr.find[ "ID" ] = function( id, context ) { if ( typeof context.getElementById !== strundefined && !documentIsXML ) { var m = context.getElementById( id ); return m ? - m.id === id || typeof m.getAttributeNode !== strundefined && m.getAttributeNode("id").value === id ? - [m] : + m.id === id || typeof m.getAttributeNode !== strundefined && m.getAttributeNode( "id" ).value === id ? + [ m ] : undefined : []; } }; - Expr.filter["ID"] = function( id ) { + Expr.filter[ "ID" ] = function( id ) { var attrId = id.replace( runescape, funescape ); return function( elem ) { - var node = typeof elem.getAttributeNode !== strundefined && elem.getAttributeNode("id"); + var node = typeof elem.getAttributeNode !== strundefined && elem.getAttributeNode( "id" ); return node && node.value === attrId; }; }; } // Tag - Expr.find["TAG"] = support.tagNameNoComments ? + Expr.find[ "TAG" ] = support.tagNameNoComments ? function( tag, context ) { if ( typeof context.getElementsByTagName !== strundefined ) { return context.getElementsByTagName( tag ); @@ -4146,7 +4286,7 @@ setDocument = Sizzle.setDocument = function( node ) { // Filter out possible comments if ( tag === "*" ) { - while ( (elem = results[i++]) ) { + while ( ( elem = results[ i++ ] ) ) { if ( elem.nodeType === 1 ) { tmp.push( elem ); } @@ -4158,14 +4298,14 @@ setDocument = Sizzle.setDocument = function( node ) { }; // Name - Expr.find["NAME"] = support.getByName && function( tag, context ) { + Expr.find[ "NAME" ] = support.getByName && function( tag, context ) { if ( typeof context.getElementsByName !== strundefined ) { return context.getElementsByName( name ); } }; // Class - Expr.find["CLASS"] = support.getByClassName && function( className, context ) { + Expr.find[ "CLASS" ] = support.getByClassName && function( className, context ) { if ( typeof context.getElementsByClassName !== strundefined && !documentIsXML ) { return context.getElementsByClassName( className ); } @@ -4181,10 +4321,12 @@ setDocument = Sizzle.setDocument = function( node ) { // A support test would require too much code (would include document ready) rbuggyQSA = [ ":focus" ]; - if ( (support.qsa = isNative(doc.querySelectorAll)) ) { + if ( ( support.qsa = isNative( doc.querySelectorAll ) ) ) { + // Build QSA regex // Regex strategy adopted from Diego Perini - assert(function( div ) { + assert( function( div ) { + // Select is set to empty string on purpose // This is to test IE's treatment of not explictly // setting a boolean content attribute, @@ -4193,46 +4335,47 @@ setDocument = Sizzle.setDocument = function( node ) { div.innerHTML = "<select><option selected=''></option></select>"; // IE8 - Some boolean attributes are not treated correctly - if ( !div.querySelectorAll("[selected]").length ) { + if ( !div.querySelectorAll( "[selected]" ).length ) { rbuggyQSA.push( "\\[" + whitespace + "*(?:checked|disabled|ismap|multiple|readonly|selected|value)" ); } // Webkit/Opera - :checked should return selected option elements // http://www.w3.org/TR/2011/REC-css3-selectors-20110929/#checked // IE8 throws error here and will not see later tests - if ( !div.querySelectorAll(":checked").length ) { - rbuggyQSA.push(":checked"); + if ( !div.querySelectorAll( ":checked" ).length ) { + rbuggyQSA.push( ":checked" ); } - }); + } ); - assert(function( div ) { + assert( function( div ) { // Opera 10-12/IE8 - ^= $= *= and empty values // Should not select anything div.innerHTML = "<input type='hidden' i=''/>"; - if ( div.querySelectorAll("[i^='']").length ) { + if ( div.querySelectorAll( "[i^='']" ).length ) { rbuggyQSA.push( "[*^$]=" + whitespace + "*(?:\"\"|'')" ); } // FF 3.5 - :enabled/:disabled and hidden elements (hidden elements are still enabled) // IE8 throws error here and will not see later tests - if ( !div.querySelectorAll(":enabled").length ) { + if ( !div.querySelectorAll( ":enabled" ).length ) { rbuggyQSA.push( ":enabled", ":disabled" ); } // Opera 10-11 does not throw on post-comma invalid pseudos - div.querySelectorAll("*,:x"); - rbuggyQSA.push(",.*:"); - }); + div.querySelectorAll( "*,:x" ); + rbuggyQSA.push( ",.*:" ); + } ); } - if ( (support.matchesSelector = isNative( (matches = docElem.matchesSelector || + if ( ( support.matchesSelector = isNative( ( matches = docElem.matchesSelector || docElem.mozMatchesSelector || docElem.webkitMatchesSelector || docElem.oMatchesSelector || - docElem.msMatchesSelector) )) ) { + docElem.msMatchesSelector ) ) ) ) { + + assert( function( div ) { - assert(function( div ) { // Check to see if it's possible to do matchesSelector // on a disconnected node (IE 9) support.disconnectedMatch = matches.call( div, "div" ); @@ -4241,16 +4384,16 @@ setDocument = Sizzle.setDocument = function( node ) { // Gecko does not error, returns false instead matches.call( div, "[s!='']:x" ); rbuggyMatches.push( "!=", pseudos ); - }); + } ); } - rbuggyQSA = new RegExp( rbuggyQSA.join("|") ); - rbuggyMatches = new RegExp( rbuggyMatches.join("|") ); + rbuggyQSA = new RegExp( rbuggyQSA.join( "|" ) ); + rbuggyMatches = new RegExp( rbuggyMatches.join( "|" ) ); // Element contains another // Purposefully does not implement inclusive descendent // As in, an element does not contain itself - contains = isNative(docElem.contains) || docElem.compareDocumentPosition ? + contains = isNative( docElem.contains ) || docElem.compareDocumentPosition ? function( a, b ) { var adown = a.nodeType === 9 ? a.documentElement : a, bup = b && b.parentNode; @@ -4258,11 +4401,11 @@ setDocument = Sizzle.setDocument = function( node ) { adown.contains ? adown.contains( bup ) : a.compareDocumentPosition && a.compareDocumentPosition( bup ) & 16 - )); + ) ); } : function( a, b ) { if ( b ) { - while ( (b = b.parentNode) ) { + while ( ( b = b.parentNode ) ) { if ( b === a ) { return true; } @@ -4281,7 +4424,7 @@ setDocument = Sizzle.setDocument = function( node ) { return 0; } - if ( (compare = b.compareDocumentPosition && a.compareDocumentPosition && a.compareDocumentPosition( b )) ) { + if ( ( compare = b.compareDocumentPosition && a.compareDocumentPosition && a.compareDocumentPosition( b ) ) ) { if ( compare & 1 || a.parentNode && a.parentNode.nodeType === 11 ) { if ( a === doc || contains( preferredDoc, a ) ) { return -1; @@ -4324,33 +4467,34 @@ setDocument = Sizzle.setDocument = function( node ) { // Otherwise we need full lists of their ancestors for comparison cur = a; - while ( (cur = cur.parentNode) ) { + while ( ( cur = cur.parentNode ) ) { ap.unshift( cur ); } cur = b; - while ( (cur = cur.parentNode) ) { + while ( ( cur = cur.parentNode ) ) { bp.unshift( cur ); } // Walk down the tree looking for a discrepancy - while ( ap[i] === bp[i] ) { + while ( ap[ i ] === bp[ i ] ) { i++; } return i ? + // Do a sibling check if the nodes have a common ancestor - siblingCheck( ap[i], bp[i] ) : + siblingCheck( ap[ i ], bp[ i ] ) : // Otherwise nodes in our document sort first - ap[i] === preferredDoc ? -1 : - bp[i] === preferredDoc ? 1 : + ap[ i ] === preferredDoc ? -1 : + bp[ i ] === preferredDoc ? 1 : 0; }; // Always assume the presence of duplicates if sort doesn't // pass them to our comparison function (as in Google Chrome). hasDuplicate = false; - [0, 0].sort( sortOrder ); + [ 0, 0 ].sort( sortOrder ); support.detectDuplicates = hasDuplicate; return document; @@ -4361,6 +4505,7 @@ Sizzle.matches = function( expr, elements ) { }; Sizzle.matchesSelector = function( elem, expr ) { + // Set document vars if needed if ( ( elem.ownerDocument || elem ) !== document ) { setDocument( elem ); @@ -4370,24 +4515,26 @@ Sizzle.matchesSelector = function( elem, expr ) { expr = expr.replace( rattributeQuotes, "='$1']" ); // rbuggyQSA always contains :focus, so no need for an existence check - if ( support.matchesSelector && !documentIsXML && (!rbuggyMatches || !rbuggyMatches.test(expr)) && !rbuggyQSA.test(expr) ) { + if ( support.matchesSelector && !documentIsXML && ( !rbuggyMatches || !rbuggyMatches.test( expr ) ) && !rbuggyQSA.test( expr ) ) { try { var ret = matches.call( elem, expr ); // IE 9's matchesSelector returns false on disconnected nodes if ( ret || support.disconnectedMatch || + // As well, disconnected nodes are said to be in a document // fragment in IE 9 elem.document && elem.document.nodeType !== 11 ) { return ret; } - } catch(e) {} + } catch ( e ) {} } - return Sizzle( expr, document, null, [elem] ).length > 0; + return Sizzle( expr, document, null, [ elem ] ).length > 0; }; Sizzle.contains = function( context, elem ) { + // Set document vars if needed if ( ( context.ownerDocument || context ) !== document ) { setDocument( context ); @@ -4406,13 +4553,13 @@ Sizzle.attr = function( elem, name ) { if ( !documentIsXML ) { name = name.toLowerCase(); } - if ( (val = Expr.attrHandle[ name ]) ) { + if ( ( val = Expr.attrHandle[ name ] ) ) { return val( elem ); } if ( documentIsXML || support.attributes ) { return elem.getAttribute( name ); } - return ( (val = elem.getAttributeNode( name )) || elem.getAttribute( name ) ) && elem[ name ] === true ? + return ( ( val = elem.getAttributeNode( name ) ) || elem.getAttribute( name ) ) && elem[ name ] === true ? name : val && val.specified ? val.value : null; }; @@ -4433,7 +4580,7 @@ Sizzle.uniqueSort = function( results ) { results.sort( sortOrder ); if ( hasDuplicate ) { - for ( ; (elem = results[i]); i++ ) { + for ( ; ( elem = results[ i ] ); i++ ) { if ( elem === results[ i - 1 ] ) { j = duplicates.push( i ); } @@ -4457,7 +4604,7 @@ function siblingCheck( a, b ) { // Check if b follows a if ( cur ) { - while ( (cur = cur.nextSibling) ) { + while ( ( cur = cur.nextSibling ) ) { if ( cur === b ) { return -1; } @@ -4479,27 +4626,27 @@ function createInputPseudo( type ) { function createButtonPseudo( type ) { return function( elem ) { var name = elem.nodeName.toLowerCase(); - return (name === "input" || name === "button") && elem.type === type; + return ( name === "input" || name === "button" ) && elem.type === type; }; } // Returns a function to use in pseudos for positionals function createPositionalPseudo( fn ) { - return markFunction(function( argument ) { + return markFunction( function( argument ) { argument = +argument; - return markFunction(function( seed, matches ) { + return markFunction( function( seed, matches ) { var j, matchIndexes = fn( [], seed.length, argument ), i = matchIndexes.length; // Match elements found at the specified indexes while ( i-- ) { - if ( seed[ (j = matchIndexes[i]) ] ) { - seed[j] = !(matches[j] = seed[j]); + if ( seed[ ( j = matchIndexes[ i ] ) ] ) { + seed[ j ] = !( matches[ j ] = seed[ j ] ); } } - }); - }); + } ); + } ); } /** @@ -4513,17 +4660,21 @@ getText = Sizzle.getText = function( elem ) { nodeType = elem.nodeType; if ( !nodeType ) { + // If no nodeType, this is expected to be an array - for ( ; (node = elem[i]); i++ ) { + for ( ; ( node = elem[ i ] ); i++ ) { + // Do not traverse comment nodes ret += getText( node ); } } else if ( nodeType === 1 || nodeType === 9 || nodeType === 11 ) { + // Use textContent for elements // innerText usage removed for consistency of new lines (see #11153) if ( typeof elem.textContent === "string" ) { return elem.textContent; } else { + // Traverse its children for ( elem = elem.firstChild; elem; elem = elem.nextSibling ) { ret += getText( elem ); @@ -4532,6 +4683,7 @@ getText = Sizzle.getText = function( elem ) { } else if ( nodeType === 3 || nodeType === 4 ) { return elem.nodeValue; } + // Do not include comment or processing instruction nodes return ret; @@ -4557,13 +4709,13 @@ Expr = Sizzle.selectors = { preFilter: { "ATTR": function( match ) { - match[1] = match[1].replace( runescape, funescape ); + match[ 1 ] = match[ 1 ].replace( runescape, funescape ); // Move the given value to match[3] whether quoted or unquoted - match[3] = ( match[4] || match[5] || "" ).replace( runescape, funescape ); + match[ 3 ] = ( match[ 4 ] || match[ 5 ] || "" ).replace( runescape, funescape ); - if ( match[2] === "~=" ) { - match[3] = " " + match[3] + " "; + if ( match[ 2 ] === "~=" ) { + match[ 3 ] = " " + match[ 3 ] + " "; } return match.slice( 0, 4 ); @@ -4580,22 +4732,23 @@ Expr = Sizzle.selectors = { 7 sign of y-component 8 y of y-component */ - match[1] = match[1].toLowerCase(); + match[ 1 ] = match[ 1 ].toLowerCase(); + + if ( match[ 1 ].slice( 0, 3 ) === "nth" ) { - if ( match[1].slice( 0, 3 ) === "nth" ) { // nth-* requires argument - if ( !match[3] ) { - Sizzle.error( match[0] ); + if ( !match[ 3 ] ) { + Sizzle.error( match[ 0 ] ); } // numeric x and y parameters for Expr.filter.CHILD // remember that false/true cast respectively to 0/1 - match[4] = +( match[4] ? match[5] + (match[6] || 1) : 2 * ( match[3] === "even" || match[3] === "odd" ) ); - match[5] = +( ( match[7] + match[8] ) || match[3] === "odd" ); + match[ 4 ] = +( match[ 4 ] ? match[ 5 ] + ( match[ 6 ] || 1 ) : 2 * ( match[ 3 ] === "even" || match[ 3 ] === "odd" ) ); + match[ 5 ] = +( ( match[ 7 ] + match[ 8 ] ) || match[ 3 ] === "odd" ); // other types prohibit arguments - } else if ( match[3] ) { - Sizzle.error( match[0] ); + } else if ( match[ 3 ] ) { + Sizzle.error( match[ 0 ] ); } return match; @@ -4603,26 +4756,28 @@ Expr = Sizzle.selectors = { "PSEUDO": function( match ) { var excess, - unquoted = !match[5] && match[2]; + unquoted = !match[ 5 ] && match[ 2 ]; - if ( matchExpr["CHILD"].test( match[0] ) ) { + if ( matchExpr[ "CHILD" ].test( match[ 0 ] ) ) { return null; } // Accept quoted arguments as-is - if ( match[4] ) { - match[2] = match[4]; + if ( match[ 4 ] ) { + match[ 2 ] = match[ 4 ]; // Strip excess characters from unquoted arguments } else if ( unquoted && rpseudo.test( unquoted ) && + // Get excess from tokenize (recursively) - (excess = tokenize( unquoted, true )) && + ( excess = tokenize( unquoted, true ) ) && + // advance to the next closing parenthesis - (excess = unquoted.indexOf( ")", unquoted.length - excess ) - unquoted.length) ) { + ( excess = unquoted.indexOf( ")", unquoted.length - excess ) - unquoted.length ) ) { // excess is a negative index - match[0] = match[0].slice( 0, excess ); - match[2] = unquoted.slice( 0, excess ); + match[ 0 ] = match[ 0 ].slice( 0, excess ); + match[ 2 ] = unquoted.slice( 0, excess ); } // Return only captures needed by the pseudo filter method (type and argument) @@ -4647,10 +4802,10 @@ Expr = Sizzle.selectors = { var pattern = classCache[ className + " " ]; return pattern || - (pattern = new RegExp( "(^|" + whitespace + ")" + className + "(" + whitespace + "|$)" )) && + ( pattern = new RegExp( "(^|" + whitespace + ")" + className + "(" + whitespace + "|$)" ) ) && classCache( className, function( elem ) { - return pattern.test( elem.className || (typeof elem.getAttribute !== strundefined && elem.getAttribute("class")) || "" ); - }); + return pattern.test( elem.className || ( typeof elem.getAttribute !== strundefined && elem.getAttribute( "class" ) ) || "" ); + } ); }, "ATTR": function( name, operator, check ) { @@ -4702,11 +4857,12 @@ Expr = Sizzle.selectors = { if ( simple ) { while ( dir ) { node = elem; - while ( (node = node[ dir ]) ) { + while ( ( node = node[ dir ] ) ) { if ( ofType ? node.nodeName.toLowerCase() === name : node.nodeType === 1 ) { return false; } } + // Reverse direction for :only-* (if we haven't yet done so) start = dir = type === "only" && !start && "nextSibling"; } @@ -4717,17 +4873,18 @@ Expr = Sizzle.selectors = { // non-xml :nth-child(...) stores cache data on `parent` if ( forward && useCache ) { + // Seek `elem` from a previously-cached index - outerCache = parent[ expando ] || (parent[ expando ] = {}); + outerCache = parent[ expando ] || ( parent[ expando ] = {} ); cache = outerCache[ type ] || []; - nodeIndex = cache[0] === dirruns && cache[1]; - diff = cache[0] === dirruns && cache[2]; + nodeIndex = cache[ 0 ] === dirruns && cache[ 1 ]; + diff = cache[ 0 ] === dirruns && cache[ 2 ]; node = nodeIndex && parent.childNodes[ nodeIndex ]; - while ( (node = ++nodeIndex && node && node[ dir ] || + while ( ( node = ++nodeIndex && node && node[ dir ] || // Fallback to seeking `elem` from the start - (diff = nodeIndex = 0) || start.pop()) ) { + ( diff = nodeIndex = 0 ) || start.pop() ) ) { // When found, cache indexes on `parent` and break if ( node.nodeType === 1 && ++diff && node === elem ) { @@ -4737,19 +4894,21 @@ Expr = Sizzle.selectors = { } // Use previously-cached element index if available - } else if ( useCache && (cache = (elem[ expando ] || (elem[ expando ] = {}))[ type ]) && cache[0] === dirruns ) { - diff = cache[1]; + } else if ( useCache && ( cache = ( elem[ expando ] || ( elem[ expando ] = {} ) )[ type ] ) && cache[ 0 ] === dirruns ) { + diff = cache[ 1 ]; // xml :nth-child(...) or :nth-last-child(...) or :nth(-last)?-of-type(...) } else { + // Use the same loop as above to seek `elem` from the start - while ( (node = ++nodeIndex && node && node[ dir ] || - (diff = nodeIndex = 0) || start.pop()) ) { + while ( ( node = ++nodeIndex && node && node[ dir ] || + ( diff = nodeIndex = 0 ) || start.pop() ) ) { if ( ( ofType ? node.nodeName.toLowerCase() === name : node.nodeType === 1 ) && ++diff ) { + // Cache the index of each encountered element if ( useCache ) { - (node[ expando ] || (node[ expando ] = {}))[ type ] = [ dirruns, diff ]; + ( node[ expando ] || ( node[ expando ] = {} ) )[ type ] = [ dirruns, diff ]; } if ( node === elem ) { @@ -4767,6 +4926,7 @@ Expr = Sizzle.selectors = { }, "PSEUDO": function( pseudo, argument ) { + // pseudo-class names are case-insensitive // http://www.w3.org/TR/selectors/#pseudo-classes // Prioritize by case sensitivity in case custom pseudos are added with uppercase letters @@ -4786,15 +4946,15 @@ Expr = Sizzle.selectors = { if ( fn.length > 1 ) { args = [ pseudo, pseudo, "", argument ]; return Expr.setFilters.hasOwnProperty( pseudo.toLowerCase() ) ? - markFunction(function( seed, matches ) { + markFunction( function( seed, matches ) { var idx, matched = fn( seed, argument ), i = matched.length; while ( i-- ) { - idx = indexOf.call( seed, matched[i] ); - seed[ idx ] = !( matches[ idx ] = matched[i] ); + idx = indexOf.call( seed, matched[ i ] ); + seed[ idx ] = !( matches[ idx ] = matched[ i ] ); } - }) : + } ) : function( elem ) { return fn( elem, 0, args ); }; @@ -4805,8 +4965,10 @@ Expr = Sizzle.selectors = { }, pseudos: { + // Potentially complex pseudos - "not": markFunction(function( selector ) { + "not": markFunction( function( selector ) { + // Trim the selector passed to compile // to avoid treating leading and trailing // spaces as combinators @@ -4815,36 +4977,36 @@ Expr = Sizzle.selectors = { matcher = compile( selector.replace( rtrim, "$1" ) ); return matcher[ expando ] ? - markFunction(function( seed, matches, context, xml ) { + markFunction( function( seed, matches, context, xml ) { var elem, unmatched = matcher( seed, null, xml, [] ), i = seed.length; // Match elements unmatched by `matcher` while ( i-- ) { - if ( (elem = unmatched[i]) ) { - seed[i] = !(matches[i] = elem); + if ( ( elem = unmatched[ i ] ) ) { + seed[ i ] = !( matches[ i ] = elem ); } } - }) : + } ) : function( elem, context, xml ) { - input[0] = elem; + input[ 0 ] = elem; matcher( input, null, xml, results ); return !results.pop(); }; - }), + } ), - "has": markFunction(function( selector ) { + "has": markFunction( function( selector ) { return function( elem ) { return Sizzle( selector, elem ).length > 0; }; - }), + } ), - "contains": markFunction(function( text ) { + "contains": markFunction( function( text ) { return function( elem ) { return ( elem.textContent || elem.innerText || getText( elem ) ).indexOf( text ) > -1; }; - }), + } ), // "Whether an element is represented by a :lang() selector // is based solely on the element's language value @@ -4854,25 +5016,26 @@ Expr = Sizzle.selectors = { // The identifier C does not have to be a valid language name." // http://www.w3.org/TR/selectors/#lang-pseudo "lang": markFunction( function( lang ) { + // lang value must be a valid identifider - if ( !ridentifier.test(lang || "") ) { + if ( !ridentifier.test( lang || "" ) ) { Sizzle.error( "unsupported lang: " + lang ); } lang = lang.replace( runescape, funescape ).toLowerCase(); return function( elem ) { var elemLang; do { - if ( (elemLang = documentIsXML ? - elem.getAttribute("xml:lang") || elem.getAttribute("lang") : - elem.lang) ) { + if ( ( elemLang = documentIsXML ? + elem.getAttribute( "xml:lang" ) || elem.getAttribute( "lang" ) : + elem.lang ) ) { elemLang = elemLang.toLowerCase(); return elemLang === lang || elemLang.indexOf( lang + "-" ) === 0; } - } while ( (elem = elem.parentNode) && elem.nodeType === 1 ); + } while ( ( elem = elem.parentNode ) && elem.nodeType === 1 ); return false; }; - }), + } ), // Miscellaneous "target": function( elem ) { @@ -4885,7 +5048,7 @@ Expr = Sizzle.selectors = { }, "focus": function( elem ) { - return elem === document.activeElement && (!document.hasFocus || document.hasFocus()) && !!(elem.type || elem.href || ~elem.tabIndex); + return elem === document.activeElement && ( !document.hasFocus || document.hasFocus() ) && !!( elem.type || elem.href || ~elem.tabIndex ); }, // Boolean properties @@ -4898,13 +5061,15 @@ Expr = Sizzle.selectors = { }, "checked": function( elem ) { + // In CSS3, :checked should return both checked and selected elements // http://www.w3.org/TR/2011/REC-css3-selectors-20110929/#checked var nodeName = elem.nodeName.toLowerCase(); - return (nodeName === "input" && !!elem.checked) || (nodeName === "option" && !!elem.selected); + return ( nodeName === "input" && !!elem.checked ) || ( nodeName === "option" && !!elem.selected ); }, "selected": function( elem ) { + // Accessing this property makes selected-by-default // options in Safari work properly if ( elem.parentNode ) { @@ -4916,6 +5081,7 @@ Expr = Sizzle.selectors = { // Contents "empty": function( elem ) { + // http://www.w3.org/TR/selectors/#empty-pseudo // :empty is only affected by element nodes and content nodes(including text(3), cdata(4)), // not comment, processing instructions, or others @@ -4930,7 +5096,7 @@ Expr = Sizzle.selectors = { }, "parent": function( elem ) { - return !Expr.pseudos["empty"]( elem ); + return !Expr.pseudos[ "empty" ]( elem ); }, // Element/input types @@ -4949,57 +5115,58 @@ Expr = Sizzle.selectors = { "text": function( elem ) { var attr; + // IE6 and 7 will map elem.type to 'text' for new HTML5 types (search, etc) // use getAttribute instead to test this case return elem.nodeName.toLowerCase() === "input" && elem.type === "text" && - ( (attr = elem.getAttribute("type")) == null || attr.toLowerCase() === elem.type ); + ( ( attr = elem.getAttribute( "type" ) ) == null || attr.toLowerCase() === elem.type ); }, // Position-in-collection - "first": createPositionalPseudo(function() { + "first": createPositionalPseudo( function() { return [ 0 ]; - }), + } ), - "last": createPositionalPseudo(function( matchIndexes, length ) { + "last": createPositionalPseudo( function( matchIndexes, length ) { return [ length - 1 ]; - }), + } ), - "eq": createPositionalPseudo(function( matchIndexes, length, argument ) { + "eq": createPositionalPseudo( function( matchIndexes, length, argument ) { return [ argument < 0 ? argument + length : argument ]; - }), + } ), - "even": createPositionalPseudo(function( matchIndexes, length ) { + "even": createPositionalPseudo( function( matchIndexes, length ) { var i = 0; for ( ; i < length; i += 2 ) { matchIndexes.push( i ); } return matchIndexes; - }), + } ), - "odd": createPositionalPseudo(function( matchIndexes, length ) { + "odd": createPositionalPseudo( function( matchIndexes, length ) { var i = 1; for ( ; i < length; i += 2 ) { matchIndexes.push( i ); } return matchIndexes; - }), + } ), - "lt": createPositionalPseudo(function( matchIndexes, length, argument ) { + "lt": createPositionalPseudo( function( matchIndexes, length, argument ) { var i = argument < 0 ? argument + length : argument; for ( ; --i >= 0; ) { matchIndexes.push( i ); } return matchIndexes; - }), + } ), - "gt": createPositionalPseudo(function( matchIndexes, length, argument ) { + "gt": createPositionalPseudo( function( matchIndexes, length, argument ) { var i = argument < 0 ? argument + length : argument; for ( ; ++i < length; ) { matchIndexes.push( i ); } return matchIndexes; - }) + } ) } }; @@ -5027,10 +5194,11 @@ function tokenize( selector, parseOnly ) { while ( soFar ) { // Comma and first run - if ( !matched || (match = rcomma.exec( soFar )) ) { + if ( !matched || ( match = rcomma.exec( soFar ) ) ) { if ( match ) { + // Don't consume trailing commas as valid - soFar = soFar.slice( match[0].length ) || soFar; + soFar = soFar.slice( match[ 0 ].length ) || soFar; } groups.push( tokens = [] ); } @@ -5038,20 +5206,21 @@ function tokenize( selector, parseOnly ) { matched = false; // Combinators - if ( (match = rcombinators.exec( soFar )) ) { + if ( ( match = rcombinators.exec( soFar ) ) ) { matched = match.shift(); tokens.push( { value: matched, + // Cast descendant combinators to space - type: match[0].replace( rtrim, " " ) + type: match[ 0 ].replace( rtrim, " " ) } ); soFar = soFar.slice( matched.length ); } // Filters for ( type in Expr.filter ) { - if ( (match = matchExpr[ type ].exec( soFar )) && (!preFilters[ type ] || - (match = preFilters[ type ]( match ))) ) { + if ( ( match = matchExpr[ type ].exec( soFar ) ) && ( !preFilters[ type ] || + ( match = preFilters[ type ]( match ) ) ) ) { matched = match.shift(); tokens.push( { value: matched, @@ -5074,6 +5243,7 @@ function tokenize( selector, parseOnly ) { soFar.length : soFar ? Sizzle.error( selector ) : + // Cache the tokens tokenCache( selector, groups ).slice( 0 ); } @@ -5083,7 +5253,7 @@ function toSelector( tokens ) { len = tokens.length, selector = ""; for ( ; i < len; i++ ) { - selector += tokens[i].value; + selector += tokens[ i ].value; } return selector; } @@ -5094,9 +5264,10 @@ function addCombinator( matcher, combinator, base ) { doneName = done++; return combinator.first ? + // Check against closest ancestor/preceding element function( elem, context, xml ) { - while ( (elem = elem[ dir ]) ) { + while ( ( elem = elem[ dir ] ) ) { if ( elem.nodeType === 1 || checkNonElements ) { return matcher( elem, context, xml ); } @@ -5110,7 +5281,7 @@ function addCombinator( matcher, combinator, base ) { // We can't set arbitrary data on XML nodes, so they don't benefit from dir caching if ( xml ) { - while ( (elem = elem[ dir ]) ) { + while ( ( elem = elem[ dir ] ) ) { if ( elem.nodeType === 1 || checkNonElements ) { if ( matcher( elem, context, xml ) ) { return true; @@ -5118,17 +5289,17 @@ function addCombinator( matcher, combinator, base ) { } } } else { - while ( (elem = elem[ dir ]) ) { + while ( ( elem = elem[ dir ] ) ) { if ( elem.nodeType === 1 || checkNonElements ) { - outerCache = elem[ expando ] || (elem[ expando ] = {}); - if ( (cache = outerCache[ dir ]) && cache[0] === dirkey ) { - if ( (data = cache[1]) === true || data === cachedruns ) { + outerCache = elem[ expando ] || ( elem[ expando ] = {} ); + if ( ( cache = outerCache[ dir ] ) && cache[ 0 ] === dirkey ) { + if ( ( data = cache[ 1 ] ) === true || data === cachedruns ) { return data === true; } } else { cache = outerCache[ dir ] = [ dirkey ]; - cache[1] = matcher( elem, context, xml ) || cachedruns; - if ( cache[1] === true ) { + cache[ 1 ] = matcher( elem, context, xml ) || cachedruns; + if ( cache[ 1 ] === true ) { return true; } } @@ -5143,13 +5314,13 @@ function elementMatcher( matchers ) { function( elem, context, xml ) { var i = matchers.length; while ( i-- ) { - if ( !matchers[i]( elem, context, xml ) ) { + if ( !matchers[ i ]( elem, context, xml ) ) { return false; } } return true; } : - matchers[0]; + matchers[ 0 ]; } function condense( unmatched, map, filter, context, xml ) { @@ -5160,7 +5331,7 @@ function condense( unmatched, map, filter, context, xml ) { mapped = map != null; for ( ; i < len; i++ ) { - if ( (elem = unmatched[i]) ) { + if ( ( elem = unmatched[ i ] ) ) { if ( !filter || filter( elem, context, xml ) ) { newUnmatched.push( elem ); if ( mapped ) { @@ -5180,7 +5351,7 @@ function setMatcher( preFilter, selector, matcher, postFilter, postFinder, postS if ( postFinder && !postFinder[ expando ] ) { postFinder = setMatcher( postFinder, postSelector ); } - return markFunction(function( seed, results, context, xml ) { + return markFunction( function( seed, results, context, xml ) { var temp, i, elem, preMap = [], postMap = [], @@ -5195,6 +5366,7 @@ function setMatcher( preFilter, selector, matcher, postFilter, postFinder, postS elems, matcherOut = matcher ? + // If we have a postFinder, or filtered seed, or non-seed postFilter or preexisting results, postFinder || ( seed ? preFilter : preexisting || postFilter ) ? @@ -5218,8 +5390,8 @@ function setMatcher( preFilter, selector, matcher, postFilter, postFinder, postS // Un-match failing elements by moving them back to matcherIn i = temp.length; while ( i-- ) { - if ( (elem = temp[i]) ) { - matcherOut[ postMap[i] ] = !(matcherIn[ postMap[i] ] = elem); + if ( ( elem = temp[ i ] ) ) { + matcherOut[ postMap[ i ] ] = !( matcherIn[ postMap[ i ] ] = elem ); } } } @@ -5227,25 +5399,27 @@ function setMatcher( preFilter, selector, matcher, postFilter, postFinder, postS if ( seed ) { if ( postFinder || preFilter ) { if ( postFinder ) { + // Get the final matcherOut by condensing this intermediate into postFinder contexts temp = []; i = matcherOut.length; while ( i-- ) { - if ( (elem = matcherOut[i]) ) { + if ( ( elem = matcherOut[ i ] ) ) { + // Restore matcherIn since elem is not yet a final match - temp.push( (matcherIn[i] = elem) ); + temp.push( ( matcherIn[ i ] = elem ) ); } } - postFinder( null, (matcherOut = []), temp, xml ); + postFinder( null, ( matcherOut = [] ), temp, xml ); } // Move matched elements from seed to results to keep them synchronized i = matcherOut.length; while ( i-- ) { - if ( (elem = matcherOut[i]) && - (temp = postFinder ? indexOf.call( seed, elem ) : preMap[i]) > -1 ) { + if ( ( elem = matcherOut[ i ] ) && + ( temp = postFinder ? indexOf.call( seed, elem ) : preMap[ i ] ) > -1 ) { - seed[temp] = !(results[temp] = elem); + seed[ temp ] = !( results[ temp ] = elem ); } } } @@ -5263,14 +5437,14 @@ function setMatcher( preFilter, selector, matcher, postFilter, postFinder, postS push.apply( results, matcherOut ); } } - }); + } ); } function matcherFromTokens( tokens ) { var checkContext, matcher, j, len = tokens.length, - leadingRelative = Expr.relative[ tokens[0].type ], - implicitRelative = leadingRelative || Expr.relative[" "], + leadingRelative = Expr.relative[ tokens[ 0 ].type ], + implicitRelative = leadingRelative || Expr.relative[ " " ], i = leadingRelative ? 1 : 0, // The foundational matcher ensures that elements are reachable from top-level context(s) @@ -5282,23 +5456,24 @@ function matcherFromTokens( tokens ) { }, implicitRelative, true ), matchers = [ function( elem, context, xml ) { return ( !leadingRelative && ( xml || context !== outermostContext ) ) || ( - (checkContext = context).nodeType ? + ( checkContext = context ).nodeType ? matchContext( elem, context, xml ) : matchAnyContext( elem, context, xml ) ); } ]; for ( ; i < len; i++ ) { - if ( (matcher = Expr.relative[ tokens[i].type ]) ) { - matchers = [ addCombinator(elementMatcher( matchers ), matcher) ]; + if ( ( matcher = Expr.relative[ tokens[ i ].type ] ) ) { + matchers = [ addCombinator( elementMatcher( matchers ), matcher ) ]; } else { - matcher = Expr.filter[ tokens[i].type ].apply( null, tokens[i].matches ); + matcher = Expr.filter[ tokens[ i ].type ].apply( null, tokens[ i ].matches ); // Return special upon seeing a positional matcher if ( matcher[ expando ] ) { + // Find the next relative operator (if any) for proper handling j = ++i; for ( ; j < len; j++ ) { - if ( Expr.relative[ tokens[j].type ] ) { + if ( Expr.relative[ tokens[ j ].type ] ) { break; } } @@ -5307,7 +5482,7 @@ function matcherFromTokens( tokens ) { i > 1 && toSelector( tokens.slice( 0, i - 1 ) ).replace( rtrim, "$1" ), matcher, i < j && matcherFromTokens( tokens.slice( i, j ) ), - j < len && matcherFromTokens( (tokens = tokens.slice( j )) ), + j < len && matcherFromTokens( ( tokens = tokens.slice( j ) ) ), j < len && toSelector( tokens ) ); } @@ -5319,6 +5494,7 @@ function matcherFromTokens( tokens ) { } function matcherFromGroupMatchers( elementMatchers, setMatchers ) { + // A counter to specify which element is currently being matched var matcherCachedRuns = 0, bySet = setMatchers.length > 0, @@ -5331,10 +5507,12 @@ function matcherFromGroupMatchers( elementMatchers, setMatchers ) { unmatched = seed && [], outermost = expandContext != null, contextBackup = outermostContext, + // We must always have either seed elements or context - elems = seed || byElement && Expr.find["TAG"]( "*", expandContext && context.parentNode || context ), + elems = seed || byElement && Expr.find[ "TAG" ]( "*", expandContext && context.parentNode || context ), + // Use integer dirruns iff this is the outermost matcher - dirrunsUnique = (dirruns += contextBackup == null ? 1 : Math.random() || 0.1); + dirrunsUnique = ( dirruns += contextBackup == null ? 1 : Math.random() || 0.1 ); if ( outermost ) { outermostContext = context !== document && context; @@ -5343,10 +5521,10 @@ function matcherFromGroupMatchers( elementMatchers, setMatchers ) { // Add elements passing elementMatchers directly to results // Keep `i` a string if there are no elements so `matchedCount` will be "00" below - for ( ; (elem = elems[i]) != null; i++ ) { + for ( ; ( elem = elems[ i ] ) != null; i++ ) { if ( byElement && elem ) { j = 0; - while ( (matcher = elementMatchers[j++]) ) { + while ( ( matcher = elementMatchers[ j++ ] ) ) { if ( matcher( elem, context, xml ) ) { results.push( elem ); break; @@ -5360,8 +5538,9 @@ function matcherFromGroupMatchers( elementMatchers, setMatchers ) { // Track unmatched elements for set filters if ( bySet ) { + // They will have gone through all possible matchers - if ( (elem = !matcher && elem) ) { + if ( ( elem = !matcher && elem ) ) { matchedCount--; } @@ -5376,16 +5555,17 @@ function matcherFromGroupMatchers( elementMatchers, setMatchers ) { matchedCount += i; if ( bySet && i !== matchedCount ) { j = 0; - while ( (matcher = setMatchers[j++]) ) { + while ( ( matcher = setMatchers[ j++ ] ) ) { matcher( unmatched, setMatched, context, xml ); } if ( seed ) { + // Reintegrate element matches to eliminate the need for sorting if ( matchedCount > 0 ) { while ( i-- ) { - if ( !(unmatched[i] || setMatched[i]) ) { - setMatched[i] = pop.call( results ); + if ( !( unmatched[ i ] || setMatched[ i ] ) ) { + setMatched[ i ] = pop.call( results ); } } } @@ -5426,13 +5606,14 @@ compile = Sizzle.compile = function( selector, group /* Internal Use Only */ ) { cached = compilerCache[ selector + " " ]; if ( !cached ) { + // Generate a function of recursive functions that can be used to check each element if ( !group ) { group = tokenize( selector ); } i = group.length; while ( i-- ) { - cached = matcherFromTokens( group[i] ); + cached = matcherFromTokens( group[ i ] ); if ( cached[ expando ] ) { setMatchers.push( cached ); } else { @@ -5450,7 +5631,7 @@ function multipleContexts( selector, contexts, results ) { var i = 0, len = contexts.length; for ( ; i < len; i++ ) { - Sizzle( selector, contexts[i], results ); + Sizzle( selector, contexts[ i ], results ); } return results; } @@ -5460,16 +5641,17 @@ function select( selector, context, results, seed ) { match = tokenize( selector ); if ( !seed ) { + // Try to minimize operations if there is only one group if ( match.length === 1 ) { // Take a shortcut and set the context if the root selector is an ID - tokens = match[0] = match[0].slice( 0 ); - if ( tokens.length > 2 && (token = tokens[0]).type === "ID" && + tokens = match[ 0 ] = match[ 0 ].slice( 0 ); + if ( tokens.length > 2 && ( token = tokens[ 0 ] ).type === "ID" && context.nodeType === 9 && !documentIsXML && - Expr.relative[ tokens[1].type ] ) { + Expr.relative[ tokens[ 1 ].type ] ) { - context = Expr.find["ID"]( token.matches[0].replace( runescape, funescape ), context )[0]; + context = Expr.find[ "ID" ]( token.matches[ 0 ].replace( runescape, funescape ), context )[ 0 ]; if ( !context ) { return results; } @@ -5478,20 +5660,21 @@ function select( selector, context, results, seed ) { } // Fetch a seed set for right-to-left matching - i = matchExpr["needsContext"].test( selector ) ? 0 : tokens.length; + i = matchExpr[ "needsContext" ].test( selector ) ? 0 : tokens.length; while ( i-- ) { - token = tokens[i]; + token = tokens[ i ]; // Abort if we hit a combinator - if ( Expr.relative[ (type = token.type) ] ) { + if ( Expr.relative[ ( type = token.type ) ] ) { break; } - if ( (find = Expr.find[ type ]) ) { + if ( ( find = Expr.find[ type ] ) ) { + // Search, expanding context for leading sibling combinators - if ( (seed = find( - token.matches[0].replace( runescape, funescape ), - rsibling.test( tokens[0].type ) && context.parentNode || context - )) ) { + if ( ( seed = find( + token.matches[ 0 ].replace( runescape, funescape ), + rsibling.test( tokens[ 0 ].type ) && context.parentNode || context + ) ) ) { // If seed is empty or no tokens remain, we can return early tokens.splice( i, 1 ); @@ -5521,7 +5704,7 @@ function select( selector, context, results, seed ) { } // Deprecated -Expr.pseudos["nth"] = Expr.pseudos["eq"]; +Expr.pseudos[ "nth" ] = Expr.pseudos[ "eq" ]; // Easy API for creating new setFilters function setFilters() {} @@ -5535,18 +5718,18 @@ setDocument(); Sizzle.attr = jQuery.attr; jQuery.find = Sizzle; jQuery.expr = Sizzle.selectors; -jQuery.expr[":"] = jQuery.expr.pseudos; +jQuery.expr[ ":" ] = jQuery.expr.pseudos; jQuery.unique = Sizzle.uniqueSort; jQuery.text = Sizzle.getText; jQuery.isXMLDoc = Sizzle.isXML; jQuery.contains = Sizzle.contains; - -})( window ); +} )( window ); var runtil = /Until$/, rparentsprev = /^(?:parents|prev(?:Until|All))/, isSimple = /^.[^:#\[\.,]*$/, rneedsContext = jQuery.expr.match.needsContext, + // methods guaranteed to produce a unique set when starting from a unique set guaranteedUnique = { children: true, @@ -5555,20 +5738,20 @@ var runtil = /Until$/, prev: true }; -jQuery.fn.extend({ +jQuery.fn.extend( { find: function( selector ) { var i, ret, self, len = this.length; if ( typeof selector !== "string" ) { self = this; - return this.pushStack( jQuery( selector ).filter(function() { + return this.pushStack( jQuery( selector ).filter( function() { for ( i = 0; i < len; i++ ) { if ( jQuery.contains( self[ i ], this ) ) { return true; } } - }) ); + } ) ); } ret = []; @@ -5587,30 +5770,31 @@ jQuery.fn.extend({ targets = jQuery( target, this ), len = targets.length; - return this.filter(function() { + return this.filter( function() { for ( i = 0; i < len; i++ ) { - if ( jQuery.contains( this, targets[i] ) ) { + if ( jQuery.contains( this, targets[ i ] ) ) { return true; } } - }); + } ); }, not: function( selector ) { - return this.pushStack( winnow(this, selector, false) ); + return this.pushStack( winnow( this, selector, false ) ); }, filter: function( selector ) { - return this.pushStack( winnow(this, selector, true) ); + return this.pushStack( winnow( this, selector, true ) ); }, is: function( selector ) { return !!selector && ( typeof selector === "string" ? + // If this is a positional/relative selector, check membership in the returned set // so $("p:first").is("p:last") won't return true for a doc with two "p". rneedsContext.test( selector ) ? - jQuery( selector, this.context ).index( this[0] ) >= 0 : + jQuery( selector, this.context ).index( this[ 0 ] ) >= 0 : jQuery.filter( selector, this ).length > 0 : this.filter( selector ).length > 0 ); }, @@ -5625,10 +5809,10 @@ jQuery.fn.extend({ 0; for ( ; i < l; i++ ) { - cur = this[i]; + cur = this[ i ]; while ( cur && cur.ownerDocument && cur !== context && cur.nodeType !== 11 ) { - if ( pos ? pos.index(cur) > -1 : jQuery.find.matchesSelector(cur, selectors) ) { + if ( pos ? pos.index( cur ) > -1 : jQuery.find.matchesSelector( cur, selectors ) ) { ret.push( cur ); break; } @@ -5645,18 +5829,19 @@ jQuery.fn.extend({ // No argument, return index in parent if ( !elem ) { - return ( this[0] && this[0].parentNode ) ? this.first().prevAll().length : -1; + return ( this[ 0 ] && this[ 0 ].parentNode ) ? this.first().prevAll().length : -1; } // index in selector if ( typeof elem === "string" ) { - return jQuery.inArray( this[0], jQuery( elem ) ); + return jQuery.inArray( this[ 0 ], jQuery( elem ) ); } // Locate the position of the desired element return jQuery.inArray( + // If it receives a jQuery object, the first element is used - elem.jquery ? elem[0] : elem, this ); + elem.jquery ? elem[ 0 ] : elem, this ); }, add: function( selector, context ) { @@ -5665,15 +5850,15 @@ jQuery.fn.extend({ jQuery.makeArray( selector && selector.nodeType ? [ selector ] : selector ), all = jQuery.merge( this.get(), set ); - return this.pushStack( jQuery.unique(all) ); + return this.pushStack( jQuery.unique( all ) ); }, addBack: function( selector ) { return this.add( selector == null ? - this.prevObject : this.prevObject.filter(selector) + this.prevObject : this.prevObject.filter( selector ) ); } -}); +} ); jQuery.fn.andSelf = jQuery.fn.addBack; @@ -5685,7 +5870,7 @@ function sibling( cur, dir ) { return cur; } -jQuery.each({ +jQuery.each( { parent: function( elem ) { var parent = elem.parentNode; return parent && parent.nodeType !== 11 ? parent : null; @@ -5745,28 +5930,28 @@ jQuery.each({ return this.pushStack( ret ); }; -}); +} ); -jQuery.extend({ +jQuery.extend( { filter: function( expr, elems, not ) { if ( not ) { expr = ":not(" + expr + ")"; } return elems.length === 1 ? - jQuery.find.matchesSelector(elems[0], expr) ? [ elems[0] ] : [] : - jQuery.find.matches(expr, elems); + jQuery.find.matchesSelector( elems[ 0 ], expr ) ? [ elems[ 0 ] ] : [] : + jQuery.find.matches( expr, elems ); }, dir: function( elem, dir, until ) { var matched = [], cur = elem[ dir ]; - while ( cur && cur.nodeType !== 9 && (until === undefined || cur.nodeType !== 1 || !jQuery( cur ).is( until )) ) { + while ( cur && cur.nodeType !== 9 && ( until === undefined || cur.nodeType !== 1 || !jQuery( cur ).is( until ) ) ) { if ( cur.nodeType === 1 ) { matched.push( cur ); } - cur = cur[dir]; + cur = cur[ dir ]; } return matched; }, @@ -5782,7 +5967,7 @@ jQuery.extend({ return r; } -}); +} ); // Implement the identical functionality for filter and not function winnow( elements, qualifier, keep ) { @@ -5792,31 +5977,31 @@ function winnow( elements, qualifier, keep ) { qualifier = qualifier || 0; if ( jQuery.isFunction( qualifier ) ) { - return jQuery.grep(elements, function( elem, i ) { + return jQuery.grep( elements, function( elem, i ) { var retVal = !!qualifier.call( elem, i, elem ); return retVal === keep; - }); + } ); } else if ( qualifier.nodeType ) { - return jQuery.grep(elements, function( elem ) { + return jQuery.grep( elements, function( elem ) { return ( elem === qualifier ) === keep; - }); + } ); } else if ( typeof qualifier === "string" ) { - var filtered = jQuery.grep(elements, function( elem ) { + var filtered = jQuery.grep( elements, function( elem ) { return elem.nodeType === 1; - }); + } ); if ( isSimple.test( qualifier ) ) { - return jQuery.filter(qualifier, filtered, !keep); + return jQuery.filter( qualifier, filtered, !keep ); } else { qualifier = jQuery.filter( qualifier, filtered ); } } - return jQuery.grep(elements, function( elem ) { + return jQuery.grep( elements, function( elem ) { return ( jQuery.inArray( elem, qualifier ) >= 0 ) === keep; - }); + } ); } function createSafeFragment( document ) { var list = nodeNames.split( "|" ), @@ -5835,7 +6020,7 @@ function createSafeFragment( document ) { var nodeNames = "abbr|article|aside|audio|bdi|canvas|data|datalist|details|figcaption|figure|footer|" + "header|hgroup|mark|meter|nav|output|progress|section|summary|time|video", rinlinejQuery = / jQuery\d+="(?:null|\d+)"/g, - rnoshimcache = new RegExp("<(?:" + nodeNames + ")[\\s/>]", "i"), + rnoshimcache = new RegExp( "<(?:" + nodeNames + ")[\\s/>]", "i" ), rleadingWhitespace = /^\s+/, rxhtmlTag = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi, rtagName = /<([\w:]+)/, @@ -5843,6 +6028,7 @@ var nodeNames = "abbr|article|aside|audio|bdi|canvas|data|datalist|details|figca rhtml = /<|&#?\w+;/, rnoInnerhtml = /<(?:script|style|link)/i, manipulation_rcheckableType = /^(?:checkbox|radio)$/i, + // checked="checked" or checked rchecked = /checked\s*(?:[^=]|=\s*.checked.)/i, rscriptType = /^$|\/(?:java|ecma)script/i, @@ -5862,40 +6048,41 @@ var nodeNames = "abbr|article|aside|audio|bdi|canvas|data|datalist|details|figca // IE6-8 can't serialize link, script, style, or any html5 (NoScope) tags, // unless wrapped in a div with non-breaking characters in front of it. - _default: jQuery.support.htmlSerialize ? [ 0, "", "" ] : [ 1, "X<div>", "</div>" ] + _default: jQuery.support.htmlSerialize ? [ 0, "", "" ] : [ 1, "X<div>", "</div>" ] }, safeFragment = createSafeFragment( document ), - fragmentDiv = safeFragment.appendChild( document.createElement("div") ); + fragmentDiv = safeFragment.appendChild( document.createElement( "div" ) ); wrapMap.optgroup = wrapMap.option; wrapMap.tbody = wrapMap.tfoot = wrapMap.colgroup = wrapMap.caption = wrapMap.thead; wrapMap.th = wrapMap.td; -jQuery.fn.extend({ +jQuery.fn.extend( { text: function( value ) { return jQuery.access( this, function( value ) { return value === undefined ? jQuery.text( this ) : - this.empty().append( ( this[0] && this[0].ownerDocument || document ).createTextNode( value ) ); + this.empty().append( ( this[ 0 ] && this[ 0 ].ownerDocument || document ).createTextNode( value ) ); }, null, value, arguments.length ); }, wrapAll: function( html ) { if ( jQuery.isFunction( html ) ) { - return this.each(function(i) { - jQuery(this).wrapAll( html.call(this, i) ); - }); + return this.each( function( i ) { + jQuery( this ).wrapAll( html.call( this, i ) ); + } ); } - if ( this[0] ) { + if ( this[ 0 ] ) { + // The elements to wrap the target around - var wrap = jQuery( html, this[0].ownerDocument ).eq(0).clone(true); + var wrap = jQuery( html, this[ 0 ].ownerDocument ).eq( 0 ).clone( true ); - if ( this[0].parentNode ) { - wrap.insertBefore( this[0] ); + if ( this[ 0 ].parentNode ) { + wrap.insertBefore( this[ 0 ] ); } - wrap.map(function() { + wrap.map( function() { var elem = this; while ( elem.firstChild && elem.firstChild.nodeType === 1 ) { @@ -5903,7 +6090,7 @@ jQuery.fn.extend({ } return elem; - }).append( this ); + } ).append( this ); } return this; @@ -5911,12 +6098,12 @@ jQuery.fn.extend({ wrapInner: function( html ) { if ( jQuery.isFunction( html ) ) { - return this.each(function(i) { - jQuery(this).wrapInner( html.call(this, i) ); - }); + return this.each( function( i ) { + jQuery( this ).wrapInner( html.call( this, i ) ); + } ); } - return this.each(function() { + return this.each( function() { var self = jQuery( this ), contents = self.contents(); @@ -5926,39 +6113,39 @@ jQuery.fn.extend({ } else { self.append( html ); } - }); + } ); }, wrap: function( html ) { var isFunction = jQuery.isFunction( html ); - return this.each(function(i) { - jQuery( this ).wrapAll( isFunction ? html.call(this, i) : html ); - }); + return this.each( function( i ) { + jQuery( this ).wrapAll( isFunction ? html.call( this, i ) : html ); + } ); }, unwrap: function() { - return this.parent().each(function() { + return this.parent().each( function() { if ( !jQuery.nodeName( this, "body" ) ) { jQuery( this ).replaceWith( this.childNodes ); } - }).end(); + } ).end(); }, append: function() { - return this.domManip(arguments, true, function( elem ) { + return this.domManip( arguments, true, function( elem ) { if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) { this.appendChild( elem ); } - }); + } ); }, prepend: function() { - return this.domManip(arguments, true, function( elem ) { + return this.domManip( arguments, true, function( elem ) { if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) { this.insertBefore( elem, this.firstChild ); } - }); + } ); }, before: function() { @@ -5966,7 +6153,7 @@ jQuery.fn.extend({ if ( this.parentNode ) { this.parentNode.insertBefore( elem, this ); } - }); + } ); }, after: function() { @@ -5974,7 +6161,7 @@ jQuery.fn.extend({ if ( this.parentNode ) { this.parentNode.insertBefore( elem, this.nextSibling ); } - }); + } ); }, // keepData is for internal use only--do not document @@ -5982,7 +6169,7 @@ jQuery.fn.extend({ var elem, i = 0; - for ( ; (elem = this[i]) != null; i++ ) { + for ( ; ( elem = this[ i ] ) != null; i++ ) { if ( !selector || jQuery.filter( selector, [ elem ] ).length > 0 ) { if ( !keepData && elem.nodeType === 1 ) { jQuery.cleanData( getAll( elem ) ); @@ -6004,7 +6191,8 @@ jQuery.fn.extend({ var elem, i = 0; - for ( ; (elem = this[i]) != null; i++ ) { + for ( ; ( elem = this[ i ] ) != null; i++ ) { + // Remove element nodes and prevent memory leaks if ( elem.nodeType === 1 ) { jQuery.cleanData( getAll( elem, false ) ); @@ -6029,14 +6217,14 @@ jQuery.fn.extend({ dataAndEvents = dataAndEvents == null ? false : dataAndEvents; deepDataAndEvents = deepDataAndEvents == null ? dataAndEvents : deepDataAndEvents; - return this.map( function () { + return this.map( function() { return jQuery.clone( this, dataAndEvents, deepDataAndEvents ); - }); + } ); }, html: function( value ) { return jQuery.access( this, function( value ) { - var elem = this[0] || {}, + var elem = this[ 0 ] || {}, i = 0, l = this.length; @@ -6050,14 +6238,15 @@ jQuery.fn.extend({ if ( typeof value === "string" && !rnoInnerhtml.test( value ) && ( jQuery.support.htmlSerialize || !rnoshimcache.test( value ) ) && ( jQuery.support.leadingWhitespace || !rleadingWhitespace.test( value ) ) && - !wrapMap[ ( rtagName.exec( value ) || ["", ""] )[1].toLowerCase() ] ) { + !wrapMap[ ( rtagName.exec( value ) || [ "", "" ] )[ 1 ].toLowerCase() ] ) { value = value.replace( rxhtmlTag, "<$1></$2>" ); try { - for (; i < l; i++ ) { + for ( ; i < l; i++ ) { + // Remove element nodes and prevent memory leaks - elem = this[i] || {}; + elem = this[ i ] || {}; if ( elem.nodeType === 1 ) { jQuery.cleanData( getAll( elem, false ) ); elem.innerHTML = value; @@ -6067,7 +6256,7 @@ jQuery.fn.extend({ elem = 0; // If using innerHTML throws an exception, use the fallback method - } catch(e) {} + } catch ( e ) {} } if ( elem ) { @@ -6093,7 +6282,7 @@ jQuery.fn.extend({ jQuery( this ).remove(); parent.insertBefore( elem, next ); } - }); + } ); }, detach: function( selector ) { @@ -6111,18 +6300,18 @@ jQuery.fn.extend({ l = this.length, set = this, iNoClone = l - 1, - value = args[0], + value = args[ 0 ], isFunction = jQuery.isFunction( value ); // We can't cloneNode fragments that contain checked, in WebKit if ( isFunction || !( l <= 1 || typeof value !== "string" || jQuery.support.checkClone || !rchecked.test( value ) ) ) { - return this.each(function( index ) { + return this.each( function( index ) { var self = set.eq( index ); if ( isFunction ) { - args[0] = value.call( this, index, table ? self.html() : undefined ); + args[ 0 ] = value.call( this, index, table ? self.html() : undefined ); } self.domManip( args, table, callback ); - }); + } ); } if ( l ) { @@ -6153,9 +6342,9 @@ jQuery.fn.extend({ } callback.call( - table && jQuery.nodeName( this[i], "table" ) ? - findOrAppend( this[i], "tbody" ) : - this[i], + table && jQuery.nodeName( this[ i ], "table" ) ? + findOrAppend( this[ i ], "tbody" ) : + this[ i ], node, i ); @@ -6174,15 +6363,16 @@ jQuery.fn.extend({ !jQuery._data( node, "globalEval" ) && jQuery.contains( doc, node ) ) { if ( node.src ) { + // Hope ajax is available... - jQuery.ajax({ + jQuery.ajax( { url: node.src, type: "GET", dataType: "script", async: false, global: false, "throws": true - }); + } ); } else { jQuery.globalEval( ( node.text || node.textContent || node.innerHTML || "" ).replace( rcleanScript, "" ) ); } @@ -6197,24 +6387,24 @@ jQuery.fn.extend({ return this; } -}); +} ); function findOrAppend( elem, tag ) { - return elem.getElementsByTagName( tag )[0] || elem.appendChild( elem.ownerDocument.createElement( tag ) ); + return elem.getElementsByTagName( tag )[ 0 ] || elem.appendChild( elem.ownerDocument.createElement( tag ) ); } // Replace/restore the type attribute of script elements for safe DOM manipulation function disableScript( elem ) { - var attr = elem.getAttributeNode("type"); + var attr = elem.getAttributeNode( "type" ); elem.type = ( attr && attr.specified ) + "/" + elem.type; return elem; } function restoreScript( elem ) { var match = rscriptTypeMasked.exec( elem.type ); if ( match ) { - elem.type = match[1]; + elem.type = match[ 1 ]; } else { - elem.removeAttribute("type"); + elem.removeAttribute( "type" ); } return elem; } @@ -6223,8 +6413,8 @@ function restoreScript( elem ) { function setGlobalEval( elems, refElements ) { var elem, i = 0; - for ( ; (elem = elems[i]) != null; i++ ) { - jQuery._data( elem, "globalEval", !refElements || jQuery._data( refElements[i], "globalEval" ) ); + for ( ; ( elem = elems[ i ] ) != null; i++ ) { + jQuery._data( elem, "globalEval", !refElements || jQuery._data( refElements[ i ], "globalEval" ) ); } } @@ -6294,11 +6484,12 @@ function fixCloneNodeIssues( src, dest ) { // element in IE9, the outerHTML strategy above is not sufficient. // If the src has innerHTML and the destination does not, // copy the src.innerHTML into the dest.innerHTML. #10324 - if ( jQuery.support.html5Clone && ( src.innerHTML && !jQuery.trim(dest.innerHTML) ) ) { + if ( jQuery.support.html5Clone && ( src.innerHTML && !jQuery.trim( dest.innerHTML ) ) ) { dest.innerHTML = src.innerHTML; } } else if ( nodeName === "input" && manipulation_rcheckableType.test( src.type ) ) { + // IE6-8 fails to persist the checked state of a cloned checkbox // or radio button. Worse, IE6-7 fail to give the cloned element // a checked appearance if the defaultChecked value isn't also set @@ -6323,7 +6514,7 @@ function fixCloneNodeIssues( src, dest ) { } } -jQuery.each({ +jQuery.each( { appendTo: "append", prependTo: "prepend", insertBefore: "before", @@ -6338,8 +6529,8 @@ jQuery.each({ last = insert.length - 1; for ( ; i <= last; i++ ) { - elems = i === last ? this : this.clone(true); - jQuery( insert[i] )[ original ]( elems ); + elems = i === last ? this : this.clone( true ); + jQuery( insert[ i ] )[ original ]( elems ); // Modern browsers can apply jQuery collections as arrays, but oldIE needs a .get() core_push.apply( ret, elems.get() ); @@ -6347,7 +6538,7 @@ jQuery.each({ return this.pushStack( ret ); }; -}); +} ); function getAll( context, tag ) { var elems, elem, @@ -6357,7 +6548,7 @@ function getAll( context, tag ) { undefined; if ( !found ) { - for ( found = [], elems = context.childNodes || context; (elem = elems[i]) != null; i++ ) { + for ( found = [], elems = context.childNodes || context; ( elem = elems[ i ] ) != null; i++ ) { if ( !tag || jQuery.nodeName( elem, tag ) ) { found.push( elem ); } else { @@ -6378,12 +6569,12 @@ function fixDefaultChecked( elem ) { } } -jQuery.extend({ +jQuery.extend( { clone: function( elem, dataAndEvents, deepDataAndEvents ) { var destElements, node, clone, i, srcElements, inPage = jQuery.contains( elem.ownerDocument, elem ); - if ( jQuery.support.html5Clone || jQuery.isXMLDoc(elem) || !rnoshimcache.test( "<" + elem.nodeName + ">" ) ) { + if ( jQuery.support.html5Clone || jQuery.isXMLDoc( elem ) || !rnoshimcache.test( "<" + elem.nodeName + ">" ) ) { clone = elem.cloneNode( true ); // IE<=8 does not properly clone detached, unknown element nodes @@ -6392,18 +6583,19 @@ jQuery.extend({ fragmentDiv.removeChild( clone = fragmentDiv.firstChild ); } - if ( (!jQuery.support.noCloneEvent || !jQuery.support.noCloneChecked) && - (elem.nodeType === 1 || elem.nodeType === 11) && !jQuery.isXMLDoc(elem) ) { + if ( ( !jQuery.support.noCloneEvent || !jQuery.support.noCloneChecked ) && + ( elem.nodeType === 1 || elem.nodeType === 11 ) && !jQuery.isXMLDoc( elem ) ) { // We eschew Sizzle here for performance reasons: http://jsperf.com/getall-vs-sizzle/2 destElements = getAll( clone ); srcElements = getAll( elem ); // Fix all IE cloning issues - for ( i = 0; (node = srcElements[i]) != null; ++i ) { + for ( i = 0; ( node = srcElements[ i ] ) != null; ++i ) { + // Ensure that the destination node is not null; Fixes #9587 - if ( destElements[i] ) { - fixCloneNodeIssues( node, destElements[i] ); + if ( destElements[ i ] ) { + fixCloneNodeIssues( node, destElements[ i ] ); } } } @@ -6414,8 +6606,8 @@ jQuery.extend({ srcElements = srcElements || getAll( elem ); destElements = destElements || getAll( clone ); - for ( i = 0; (node = srcElements[i]) != null; i++ ) { - cloneCopyEvent( node, destElements[i] ); + for ( i = 0; ( node = srcElements[ i ] ) != null; i++ ) { + cloneCopyEvent( node, destElements[ i ] ); } } else { cloneCopyEvent( elem, clone ); @@ -6460,23 +6652,23 @@ jQuery.extend({ // Convert html into DOM nodes } else { - tmp = tmp || safe.appendChild( context.createElement("div") ); + tmp = tmp || safe.appendChild( context.createElement( "div" ) ); // Deserialize a standard representation - tag = ( rtagName.exec( elem ) || ["", ""] )[1].toLowerCase(); + tag = ( rtagName.exec( elem ) || [ "", "" ] )[ 1 ].toLowerCase(); wrap = wrapMap[ tag ] || wrapMap._default; - tmp.innerHTML = wrap[1] + elem.replace( rxhtmlTag, "<$1></$2>" ) + wrap[2]; + tmp.innerHTML = wrap[ 1 ] + elem.replace( rxhtmlTag, "<$1></$2>" ) + wrap[ 2 ]; // Descend through wrappers to the right content - j = wrap[0]; + j = wrap[ 0 ]; while ( j-- ) { tmp = tmp.lastChild; } // Manually add leading whitespace removed by IE if ( !jQuery.support.leadingWhitespace && rleadingWhitespace.test( elem ) ) { - nodes.push( context.createTextNode( rleadingWhitespace.exec( elem )[0] ) ); + nodes.push( context.createTextNode( rleadingWhitespace.exec( elem )[ 0 ] ) ); } // Remove IE's autoinserted <tbody> from table fragments @@ -6487,13 +6679,13 @@ jQuery.extend({ tmp.firstChild : // String was a bare <thead> or <tfoot> - wrap[1] === "<table>" && !rtbody.test( elem ) ? + wrap[ 1 ] === "<table>" && !rtbody.test( elem ) ? tmp : 0; j = elem && elem.childNodes.length; while ( j-- ) { - if ( jQuery.nodeName( (tbody = elem.childNodes[j]), "tbody" ) && !tbody.childNodes.length ) { + if ( jQuery.nodeName( ( tbody = elem.childNodes[ j ] ), "tbody" ) && !tbody.childNodes.length ) { elem.removeChild( tbody ); } } @@ -6527,7 +6719,7 @@ jQuery.extend({ } i = 0; - while ( (elem = nodes[ i++ ]) ) { + while ( ( elem = nodes[ i++ ] ) ) { // #4087 - If origin and destination elements are the same, and this is // that element, do not do anything @@ -6548,7 +6740,7 @@ jQuery.extend({ // Capture executables if ( scripts ) { j = 0; - while ( (elem = tmp[ j++ ]) ) { + while ( ( elem = tmp[ j++ ] ) ) { if ( rscriptType.test( elem.type || "" ) ) { scripts.push( elem ); } @@ -6569,7 +6761,7 @@ jQuery.extend({ deleteExpando = jQuery.support.deleteExpando, special = jQuery.event.special; - for ( ; (elem = elems[i]) != null; i++ ) { + for ( ; ( elem = elems[ i ] ) != null; i++ ) { if ( acceptData || jQuery.acceptData( elem ) ) { @@ -6613,11 +6805,12 @@ jQuery.extend({ } } } -}); +} ); var iframe, getStyles, curCSS, ralpha = /alpha\([^)]*\)/i, ropacity = /opacity\s*=\s*([^)]*)/, rposition = /^(top|right|bottom|left)$/, + // 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 rdisplayswap = /^(none|table(?!-c[ea]).+)/, @@ -6645,7 +6838,7 @@ function vendorPropName( style, name ) { } // check for vendor prefixed names - var capName = name.charAt(0).toUpperCase() + name.slice(1), + var capName = name.charAt( 0 ).toUpperCase() + name.slice( 1 ), origName = name, i = cssPrefixes.length; @@ -6660,6 +6853,7 @@ function vendorPropName( style, name ) { } function isHidden( elem, el ) { + // isHidden might be called from jQuery#filter function; // in that case, element will be second argument elem = el || elem; @@ -6681,6 +6875,7 @@ function showHide( elements, show ) { values[ index ] = jQuery._data( elem, "olddisplay" ); display = elem.style.display; if ( show ) { + // Reset the inline display of this element to learn if it is // being hidden by cascaded rules or not if ( !values[ index ] && display === "none" ) { @@ -6691,7 +6886,7 @@ function showHide( elements, show ) { // in a stylesheet to whatever the default browser style is // for such an element if ( elem.style.display === "" && isHidden( elem ) ) { - values[ index ] = jQuery._data( elem, "olddisplay", css_defaultDisplay(elem.nodeName) ); + values[ index ] = jQuery._data( elem, "olddisplay", css_defaultDisplay( elem.nodeName ) ); } } else { @@ -6720,7 +6915,7 @@ function showHide( elements, show ) { return elements; } -jQuery.fn.extend({ +jQuery.fn.extend( { css: function( name, value ) { return jQuery.access( this, function( elem, name, value ) { var len, styles, @@ -6752,23 +6947,25 @@ jQuery.fn.extend({ toggle: function( state ) { var bool = typeof state === "boolean"; - return this.each(function() { + return this.each( function() { if ( bool ? state : isHidden( this ) ) { jQuery( this ).show(); } else { jQuery( this ).hide(); } - }); + } ); } -}); +} ); + +jQuery.extend( { -jQuery.extend({ // Add in style property hooks for overriding the default // behavior of getting and setting a style property cssHooks: { opacity: { get: function( elem, computed ) { if ( computed ) { + // We should always get a number back from opacity var ret = curCSS( elem, "opacity" ); return ret === "" ? "1" : ret; @@ -6793,12 +6990,14 @@ jQuery.extend({ // Add in properties whose names you wish to fix before // setting or getting the value cssProps: { + // normalize float css property "float": jQuery.support.cssFloat ? "cssFloat" : "styleFloat" }, // Get and set the style property on a DOM Node style: function( elem, name, value, extra ) { + // Don't set styles on text and comment nodes if ( !elem || elem.nodeType === 3 || elem.nodeType === 8 || !elem.style ) { return; @@ -6820,8 +7019,9 @@ jQuery.extend({ type = typeof value; // convert relative number strings (+= or -=) to relative numbers. #7345 - if ( type === "string" && (ret = rrelNum.exec( value )) ) { - value = ( ret[1] + 1 ) * ret[2] + parseFloat( jQuery.css( elem, name ) ); + if ( type === "string" && ( ret = rrelNum.exec( value ) ) ) { + value = ( ret[ 1 ] + 1 ) * ret[ 2 ] + parseFloat( jQuery.css( elem, name ) ); + // Fixes bug #9237 type = "number"; } @@ -6838,23 +7038,24 @@ jQuery.extend({ // Fixes #8908, it can be done more correctly by specifing setters in cssHooks, // but it would mean to define eight (for every problematic property) identical functions - if ( !jQuery.support.clearCloneStyle && value === "" && name.indexOf("background") === 0 ) { + if ( !jQuery.support.clearCloneStyle && value === "" && name.indexOf( "background" ) === 0 ) { style[ name ] = "inherit"; } // If a hook was provided, use that value, otherwise just set the specified value - if ( !hooks || !("set" in hooks) || (value = hooks.set( elem, value, extra )) !== undefined ) { + if ( !hooks || !( "set" in hooks ) || ( value = hooks.set( elem, value, extra ) ) !== undefined ) { // Wrapped to prevent IE from throwing errors when 'invalid' values are provided // Fixes bug #5509 try { style[ name ] = value; - } catch(e) {} + } catch ( e ) {} } } 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 ) { + if ( hooks && "get" in hooks && ( ret = hooks.get( elem, false, extra ) ) !== undefined ) { return ret; } @@ -6917,7 +7118,7 @@ jQuery.extend({ return ret; } -}); +} ); // NOTE: we've included the "window" in window.getComputedStyle // because jsdom on node.js will break without it. @@ -7016,6 +7217,7 @@ if ( window.getComputedStyle ) { 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; @@ -7023,20 +7225,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 ); @@ -7047,6 +7253,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 ); @@ -7072,6 +7279,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 ) { @@ -7079,7 +7287,7 @@ function getWidthOrHeight( elem, name, extra ) { } // Computed unit is not pixels. Stop here and return. - if ( rnumnonpx.test(val) ) { + if ( rnumnonpx.test( val ) ) { return val; } @@ -7113,15 +7321,16 @@ function css_defaultDisplay( nodeName ) { // If the simple way fails, read from inside an iframe if ( display === "none" || !display ) { + // Use the already-created iframe if possible iframe = ( iframe || - jQuery("<iframe frameborder='0' width='0' height='0'/>") + jQuery( "<iframe frameborder='0' width='0' height='0'/>" ) .css( "cssText", "display:block !important" ) ).appendTo( doc.documentElement ); // Always write a new HTML skeleton so Webkit and Firefox don't choke on reuse - doc = ( iframe[0].contentWindow || iframe[0].contentDocument ).document; - doc.write("<!doctype html><html><body>"); + doc = ( iframe[ 0 ].contentWindow || iframe[ 0 ].contentDocument ).document; + doc.write( "<!doctype html><html><body>" ); doc.close(); display = actualDisplay( nodeName, doc ); @@ -7138,21 +7347,22 @@ function css_defaultDisplay( nodeName ) { // Called ONLY from within css_defaultDisplay function actualDisplay( name, doc ) { var elem = jQuery( doc.createElement( name ) ).appendTo( doc.body ), - display = jQuery.css( elem[0], "display" ); + display = jQuery.css( elem[ 0 ], "display" ); elem.remove(); return display; } -jQuery.each([ "height", "width" ], function( i, name ) { +jQuery.each( [ "height", "width" ], function( i, name ) { jQuery.cssHooks[ name ] = { get: function( elem, computed, extra ) { if ( computed ) { + // certain elements can have dimension info if we invisibly show them // however, it must have a current display style that would benefit from this return elem.offsetWidth === 0 && rdisplayswap.test( jQuery.css( elem, "display" ) ) ? jQuery.swap( elem, cssShow, function() { return getWidthOrHeight( elem, name, extra ); - }) : + } ) : getWidthOrHeight( elem, name, extra ); } }, @@ -7170,13 +7380,14 @@ jQuery.each([ "height", "width" ], function( i, name ) { ); } }; -}); +} ); if ( !jQuery.support.opacity ) { jQuery.cssHooks.opacity = { get: function( elem, computed ) { + // IE uses filters for opacity - return ropacity.test( (computed && elem.currentStyle ? elem.currentStyle.filter : elem.style.filter) || "" ) ? + return ropacity.test( ( computed && elem.currentStyle ? elem.currentStyle.filter : elem.style.filter ) || "" ) ? ( 0.01 * parseFloat( RegExp.$1 ) ) + "" : computed ? "1" : ""; }, @@ -7218,11 +7429,12 @@ if ( !jQuery.support.opacity ) { // These hooks cannot be added until DOM ready because the support test // for it is not run until after DOM ready -jQuery(function() { +jQuery( function() { if ( !jQuery.support.reliableMarginRight ) { jQuery.cssHooks.marginRight = { get: function( elem, computed ) { if ( computed ) { + // WebKit Bug 13343 - getComputedStyle returns wrong value for margin-right // Work around by temporarily setting element display to inline-block return jQuery.swap( elem, { "display": "inline-block" }, @@ -7241,6 +7453,7 @@ jQuery(function() { get: 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" : @@ -7248,17 +7461,18 @@ jQuery(function() { } } }; - }); + } ); } -}); +} ); if ( jQuery.expr && jQuery.expr.filters ) { jQuery.expr.filters.hidden = function( elem ) { + // Support: Opera <= 12.12 // Opera reports offsetWidths and offsetHeights less than zero on some elements return elem.offsetWidth <= 0 && elem.offsetHeight <= 0 || - (!jQuery.support.reliableHiddenOffsets && ((elem.style && elem.style.display) || jQuery.css( elem, "display" )) === "none"); + ( !jQuery.support.reliableHiddenOffsets && ( ( elem.style && elem.style.display ) || jQuery.css( elem, "display" ) ) === "none" ); }; jQuery.expr.filters.visible = function( elem ) { @@ -7267,7 +7481,7 @@ if ( jQuery.expr && jQuery.expr.filters ) { } // These hooks are used by animate to expand properties -jQuery.each({ +jQuery.each( { margin: "", padding: "", border: "Width" @@ -7278,7 +7492,7 @@ jQuery.each({ expanded = {}, // assumes a single number if not a string - parts = typeof value === "string" ? value.split(" ") : [ value ]; + parts = typeof value === "string" ? value.split( " " ) : [ value ]; for ( ; i < 4; i++ ) { expanded[ prefix + cssExpand[ i ] + suffix ] = @@ -7292,43 +7506,45 @@ jQuery.each({ if ( !rmargin.test( prefix ) ) { jQuery.cssHooks[ prefix + suffix ].set = setPositiveNumber; } -}); +} ); var r20 = /%20/g, rbracket = /\[\]$/, rCRLF = /\r?\n/g, rsubmitterTypes = /^(?:submit|button|image|reset|file)$/i, rsubmittable = /^(?:input|select|textarea|keygen)/i; -jQuery.fn.extend({ +jQuery.fn.extend( { serialize: function() { return jQuery.param( this.serializeArray() ); }, serializeArray: function() { - return this.map(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; - }) - .filter(function(){ + } ) + .filter( function() { var type = this.type; + // Use .is(":disabled") so that fieldset[disabled] works return this.name && !jQuery( this ).is( ":disabled" ) && rsubmittable.test( this.nodeName ) && !rsubmitterTypes.test( type ) && ( this.checked || !manipulation_rcheckableType.test( type ) ); - }) - .map(function( i, elem ){ + } ) + .map( function( i, elem ) { var val = jQuery( this ).val(); return val == null ? null : jQuery.isArray( val ) ? - jQuery.map( val, function( val ){ + jQuery.map( val, function( val ) { return { name: elem.name, value: val.replace( rCRLF, "\r\n" ) }; - }) : + } ) : { name: elem.name, value: val.replace( rCRLF, "\r\n" ) }; - }).get(); + } ).get(); } -}); +} ); //Serialize an array of form elements or a set of //key/values into a query string @@ -7336,6 +7552,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 ); @@ -7348,12 +7565,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 ) { @@ -7369,32 +7588,37 @@ 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 : "" ) + "]", v, 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 ); } } -jQuery.each( ("blur focus focusin focusout load resize scroll unload click dblclick " + +jQuery.each( ( "blur focus focusin focusout load resize scroll unload click dblclick " + "mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave " + - "change select submit keydown keypress keyup error contextmenu").split(" "), function( i, name ) { + "change select submit keydown keypress keyup error contextmenu" ).split( " " ), function( i, name ) { // Handle event binding jQuery.fn[ name ] = function( data, fn ) { @@ -7402,12 +7626,13 @@ jQuery.each( ("blur focus focusin focusout load resize scroll unload click dblcl this.on( name, null, data, fn ) : this.trigger( name ); }; -}); +} ); jQuery.fn.hover = function( fnOver, fnOut ) { return this.mouseenter( fnOver ).mouseleave( fnOut || fnOver ); }; var + // Document location ajaxLocParts, ajaxLocation, @@ -7445,13 +7670,14 @@ var transports = {}, // Avoid comment-prolog char sequence (#10098); must appease lint and evade compression - allTypes = "*/".concat("*"); + allTypes = "*/".concat( "*" ); // #8138, IE may throw an exception when accessing // a field from window.location if document.domain has been set try { ajaxLocation = location.href; -} catch( e ) { +} catch ( e ) { + // Use the href attribute of an A element // since IE will modify it given document.location ajaxLocation = document.createElement( "a" ); @@ -7478,16 +7704,18 @@ function addToPrefiltersOrTransports( structure ) { dataTypes = dataTypeExpression.toLowerCase().match( core_rnotwhite ) || []; if ( jQuery.isFunction( func ) ) { + // For each dataType in the dataTypeExpression - while ( (dataType = dataTypes[i++]) ) { + while ( ( dataType = dataTypes[ i++ ] ) ) { + // Prepend if requested - if ( dataType[0] === "+" ) { + if ( dataType[ 0 ] === "+" ) { dataType = dataType.slice( 1 ) || "*"; - (structure[ dataType ] = structure[ dataType ] || []).unshift( func ); + ( structure[ dataType ] = structure[ dataType ] || [] ).unshift( func ); // Otherwise append } else { - (structure[ dataType ] = structure[ dataType ] || []).push( func ); + ( structure[ dataType ] = structure[ dataType ] || [] ).push( func ); } } } @@ -7505,14 +7733,14 @@ function inspectPrefiltersOrTransports( structure, options, originalOptions, jqX inspected[ dataType ] = true; jQuery.each( structure[ dataType ] || [], function( _, prefilterOrFactory ) { var dataTypeOrTransport = prefilterOrFactory( options, originalOptions, jqXHR ); - if( typeof dataTypeOrTransport === "string" && !seekingTransport && !inspected[ dataTypeOrTransport ] ) { + if ( typeof dataTypeOrTransport === "string" && !seekingTransport && !inspected[ dataTypeOrTransport ] ) { options.dataTypes.unshift( dataTypeOrTransport ); inspect( dataTypeOrTransport ); return false; } else if ( seekingTransport ) { return !( selected = dataTypeOrTransport ); } - }); + } ); return selected; } @@ -7528,7 +7756,7 @@ function ajaxExtend( target, src ) { for ( key in src ) { if ( src[ key ] !== undefined ) { - ( flatOptions[ key ] ? target : ( deep || (deep = {}) ) )[ key ] = src[ key ]; + ( flatOptions[ key ] ? target : ( deep || ( deep = {} ) ) )[ key ] = src[ key ]; } } if ( deep ) { @@ -7545,7 +7773,7 @@ jQuery.fn.load = function( url, params, callback ) { var selector, response, type, self = this, - off = url.indexOf(" "); + off = url.indexOf( " " ); if ( off >= 0 ) { selector = url.slice( off, url.length ); @@ -7566,14 +7794,14 @@ jQuery.fn.load = function( url, params, callback ) { // If we have elements to modify, make the request if ( self.length > 0 ) { - jQuery.ajax({ + jQuery.ajax( { url: url, // if "type" variable is undefined, then "GET" method will be used type: type, dataType: "html", data: params - }).done(function( responseText ) { + } ).done( function( responseText ) { // Save response for use in complete callback response = arguments; @@ -7582,28 +7810,29 @@ jQuery.fn.load = function( url, params, callback ) { // If a selector was specified, locate the right elements in a dummy div // Exclude scripts to avoid IE 'Permission Denied' errors - jQuery("<div>").append( jQuery.parseHTML( responseText ) ).find( selector ) : + jQuery( "<div>" ).append( jQuery.parseHTML( responseText ) ).find( selector ) : // Otherwise use the full result responseText ); - }).complete( callback && function( jqXHR, status ) { + } ).complete( callback && function( jqXHR, status ) { self.each( callback, response || [ jqXHR.responseText, status, jqXHR ] ); - }); + } ); } return this; }; // Attach a bunch of functions for handling common AJAX events -jQuery.each( [ "ajaxStart", "ajaxStop", "ajaxComplete", "ajaxError", "ajaxSuccess", "ajaxSend" ], function( i, type ){ - jQuery.fn[ type ] = function( fn ){ +jQuery.each( [ "ajaxStart", "ajaxStop", "ajaxComplete", "ajaxError", "ajaxSuccess", "ajaxSend" ], function( i, type ) { + jQuery.fn[ type ] = function( fn ) { return this.on( type, fn ); }; -}); +} ); jQuery.each( [ "get", "post" ], function( i, method ) { jQuery[ method ] = function( url, data, callback, type ) { + // shift arguments if data argument was omitted if ( jQuery.isFunction( data ) ) { type = type || callback; @@ -7611,17 +7840,17 @@ jQuery.each( [ "get", "post" ], function( i, method ) { data = undefined; } - return jQuery.ajax({ + return jQuery.ajax( { url: url, type: method, dataType: type, data: data, success: callback - }); + } ); }; -}); +} ); -jQuery.extend({ +jQuery.extend( { // Counter for holding the number of active queries active: 0, @@ -7726,12 +7955,16 @@ jQuery.extend({ var // Cross-domain detection vars parts, + // Loop variable i, + // URL without anti-cache param cacheURL, + // Response headers as string responseHeadersString, + // timeout handle timeoutTimer, @@ -7739,28 +7972,38 @@ jQuery.extend({ fireGlobals, transport, + // Response headers responseHeaders, + // Create the final options object s = jQuery.ajaxSetup( {}, options ), + // Callbacks context callbackContext = s.context || s, + // Context for global events is callbackContext if it is a DOM node or jQuery collection globalEventContext = s.context && ( callbackContext.nodeType || callbackContext.jquery ) ? jQuery( callbackContext ) : jQuery.event, + // Deferreds deferred = jQuery.Deferred(), - completeDeferred = jQuery.Callbacks("once memory"), + completeDeferred = jQuery.Callbacks( "once memory" ), + // Status-dependent callbacks statusCode = s.statusCode || {}, + // Headers (they are sent all at once) requestHeaders = {}, requestHeadersNames = {}, + // The jqXHR state state = 0, + // Default abort message strAbort = "canceled", + // Fake xhr jqXHR = { readyState: 0, @@ -7771,8 +8014,8 @@ jQuery.extend({ if ( state === 2 ) { if ( !responseHeaders ) { responseHeaders = {}; - while ( (match = rheaders.exec( responseHeadersString )) ) { - responseHeaders[ match[1].toLowerCase() ] = match[ 2 ]; + while ( ( match = rheaders.exec( responseHeadersString ) ) ) { + responseHeaders[ match[ 1 ].toLowerCase() ] = match[ 2 ]; } } match = responseHeaders[ key.toLowerCase() ]; @@ -7809,10 +8052,12 @@ jQuery.extend({ if ( map ) { if ( state < 2 ) { for ( code in map ) { + // Lazy-add the new callback in a way that preserves old ones statusCode[ code ] = [ statusCode[ code ], map[ code ] ]; } } else { + // Execute the appropriate callbacks jqXHR.always( map[ jqXHR.status ] ); } @@ -7846,7 +8091,7 @@ jQuery.extend({ s.type = options.method || options.type || s.method || s.type; // Extract dataTypes list - s.dataTypes = jQuery.trim( s.dataType || "*" ).toLowerCase().match( core_rnotwhite ) || [""]; + s.dataTypes = jQuery.trim( s.dataType || "*" ).toLowerCase().match( core_rnotwhite ) || [ "" ]; // A cross-domain request is in order when we have a protocol:host:port mismatch if ( s.crossDomain == null ) { @@ -7876,7 +8121,7 @@ jQuery.extend({ // Watch for a new set of requests if ( fireGlobals && jQuery.active++ === 0 ) { - jQuery.event.trigger("ajaxStart"); + jQuery.event.trigger( "ajaxStart" ); } // Uppercase the type @@ -7895,6 +8140,7 @@ jQuery.extend({ // If data is available, append data to url if ( s.data ) { cacheURL = ( s.url += ( ajax_rquery.test( cacheURL ) ? "&" : "?" ) + s.data ); + // #9682: remove data so that it's not used in an eventual retry delete s.data; } @@ -7929,8 +8175,8 @@ jQuery.extend({ // Set the Accepts header for the server, depending on the dataType jqXHR.setRequestHeader( "Accept", - s.dataTypes[ 0 ] && s.accepts[ s.dataTypes[0] ] ? - s.accepts[ s.dataTypes[0] ] + ( s.dataTypes[ 0 ] !== "*" ? ", " + allTypes + "; q=0.01" : "" ) : + s.dataTypes[ 0 ] && s.accepts[ s.dataTypes[ 0 ] ] ? + s.accepts[ s.dataTypes[ 0 ] ] + ( s.dataTypes[ 0 ] !== "*" ? ", " + allTypes + "; q=0.01" : "" ) : s.accepts[ "*" ] ); @@ -7941,6 +8187,7 @@ jQuery.extend({ // Allow custom headers/mimetypes and early abort if ( s.beforeSend && ( s.beforeSend.call( callbackContext, jqXHR, s ) === false || state === 2 ) ) { + // Abort if not done already and return return jqXHR.abort(); } @@ -7966,10 +8213,11 @@ jQuery.extend({ if ( fireGlobals ) { globalEventContext.trigger( "ajaxSend", [ jqXHR, s ] ); } + // Timeout if ( s.async && s.timeout > 0 ) { - timeoutTimer = setTimeout(function() { - jqXHR.abort("timeout"); + timeoutTimer = setTimeout( function() { + jqXHR.abort( "timeout" ); }, s.timeout ); } @@ -7977,9 +8225,11 @@ jQuery.extend({ state = 1; transport.send( requestHeaders, done ); } catch ( e ) { + // Propagate exception as error if not done if ( state < 2 ) { done( -1, e ); + // Simply rethrow otherwise } else { throw e; @@ -8025,11 +8275,11 @@ jQuery.extend({ // Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode. if ( s.ifModified ) { - modified = jqXHR.getResponseHeader("Last-Modified"); + modified = jqXHR.getResponseHeader( "Last-Modified" ); if ( modified ) { jQuery.lastModified[ cacheURL ] = modified; } - modified = jqXHR.getResponseHeader("etag"); + modified = jqXHR.getResponseHeader( "etag" ); if ( modified ) { jQuery.etag[ cacheURL ] = modified; } @@ -8054,6 +8304,7 @@ jQuery.extend({ isSuccess = !error; } } else { + // We extract error from statusText // then normalize statusText and status for non-aborts error = statusText; @@ -8090,9 +8341,10 @@ jQuery.extend({ if ( fireGlobals ) { globalEventContext.trigger( "ajaxComplete", [ jqXHR, s ] ); + // Handle the global AJAX counter if ( !( --jQuery.active ) ) { - jQuery.event.trigger("ajaxStop"); + jQuery.event.trigger( "ajaxStop" ); } } } @@ -8107,7 +8359,7 @@ jQuery.extend({ getJSON: function( url, data, callback ) { return jQuery.get( url, data, callback, "json" ); } -}); +} ); /* Handles responses to an ajax request: * - sets all responseXXX fields accordingly @@ -8123,15 +8375,15 @@ function ajaxHandleResponses( s, jqXHR, responses ) { // Fill responseXXX fields for ( type in responseFields ) { if ( type in responses ) { - jqXHR[ responseFields[type] ] = responses[ type ]; + jqXHR[ responseFields[ type ] ] = responses[ type ]; } } // Remove auto dataType and get content-type in the process - while( dataTypes[ 0 ] === "*" ) { + while ( dataTypes[ 0 ] === "*" ) { dataTypes.shift(); if ( ct === undefined ) { - ct = s.mimeType || jqXHR.getResponseHeader("Content-Type"); + ct = s.mimeType || jqXHR.getResponseHeader( "Content-Type" ); } } @@ -8149,9 +8401,10 @@ function ajaxHandleResponses( s, jqXHR, responses ) { if ( dataTypes[ 0 ] in responses ) { finalDataType = dataTypes[ 0 ]; } else { + // Try convertible dataTypes for ( type in responses ) { - if ( !dataTypes[ 0 ] || s.converters[ type + " " + dataTypes[0] ] ) { + if ( !dataTypes[ 0 ] || s.converters[ type + " " + dataTypes[ 0 ] ] ) { finalDataType = type; break; } @@ -8159,6 +8412,7 @@ function ajaxHandleResponses( s, jqXHR, responses ) { firstDataType = type; } } + // Or just use first one finalDataType = finalDataType || firstDataType; } @@ -8179,6 +8433,7 @@ function ajaxConvert( s, response ) { var conv2, current, conv, tmp, converters = {}, i = 0, + // Work with a copy of dataTypes in case we need to modify it for conversion dataTypes = s.dataTypes.slice(), prev = dataTypes[ 0 ]; @@ -8196,7 +8451,7 @@ function ajaxConvert( s, response ) { } // Convert to each sequential dataType, tolerating list modification - for ( ; (current = dataTypes[++i]); ) { + for ( ; ( current = dataTypes[ ++i ] ); ) { // There's only work to do if current dataType is non-auto if ( current !== "*" ) { @@ -8212,13 +8467,14 @@ function ajaxConvert( s, response ) { for ( conv2 in converters ) { // If conv2 outputs current - tmp = conv2.split(" "); + tmp = conv2.split( " " ); if ( tmp[ 1 ] === current ) { // If prev can be converted to accepted input conv = converters[ prev + " " + tmp[ 0 ] ] || converters[ "* " + tmp[ 0 ] ]; if ( conv ) { + // Condense equivalence converters if ( conv === true ) { conv = converters[ conv2 ]; @@ -8239,7 +8495,7 @@ function ajaxConvert( s, response ) { if ( conv !== true ) { // Unless errors are allowed to bubble, catch and return them - if ( conv && s["throws"] ) { + if ( conv && s[ "throws" ] ) { response = conv( response ); } else { try { @@ -8258,8 +8514,9 @@ function ajaxConvert( s, response ) { return { state: "success", data: response }; } + // Install script dataType -jQuery.ajaxSetup({ +jQuery.ajaxSetup( { accepts: { script: "text/javascript, application/javascript, application/ecmascript, application/x-ecmascript" }, @@ -8272,7 +8529,7 @@ jQuery.ajaxSetup({ return text; } } -}); +} ); // Handle cache's special case and global jQuery.ajaxPrefilter( "script", function( s ) { @@ -8283,22 +8540,22 @@ jQuery.ajaxPrefilter( "script", function( s ) { s.type = "GET"; s.global = false; } -}); +} ); // Bind script tag hack transport -jQuery.ajaxTransport( "script", function(s) { +jQuery.ajaxTransport( "script", function( s ) { // This transport only deals with cross domain requests if ( s.crossDomain ) { var script, - head = document.head || jQuery("head")[0] || document.documentElement; + head = document.head || jQuery( "head" )[ 0 ] || document.documentElement; return { send: function( _, callback ) { - script = document.createElement("script"); + script = document.createElement( "script" ); script.async = true; @@ -8343,19 +8600,19 @@ jQuery.ajaxTransport( "script", function(s) { } }; } -}); +} ); var oldCallbacks = [], rjsonp = /(=)\?(?=&|$)|\?\?/; // Default jsonp settings -jQuery.ajaxSetup({ +jQuery.ajaxSetup( { jsonp: "callback", jsonpCallback: function() { var callback = oldCallbacks.pop() || ( jQuery.expando + "_" + ( ajax_nonce++ ) ); this[ callback ] = true; return callback; } -}); +} ); // Detect, normalize options and install callbacks for jsonp requests jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) { @@ -8363,7 +8620,7 @@ jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) { var callbackName, overwritten, responseContainer, jsonProp = s.jsonp !== false && ( rjsonp.test( s.url ) ? "url" : - typeof s.data === "string" && !( s.contentType || "" ).indexOf("application/x-www-form-urlencoded") && rjsonp.test( s.data ) && "data" + typeof s.data === "string" && !( s.contentType || "" ).indexOf( "application/x-www-form-urlencoded" ) && rjsonp.test( s.data ) && "data" ); // Handle iff the expected data type is "jsonp" or we have a parameter to set @@ -8382,7 +8639,7 @@ jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) { } // Use data converter to retrieve json after script execution - s.converters["script json"] = function() { + s.converters[ "script json" ] = function() { if ( !responseContainer ) { jQuery.error( callbackName + " was not called" ); } @@ -8399,12 +8656,14 @@ jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) { }; // Clean-up function (fires after converters) - jqXHR.always(function() { + jqXHR.always( function() { + // Restore preexisting value window[ callbackName ] = overwritten; // Save back as free if ( s[ callbackName ] ) { + // make sure that re-using the options doesn't screw things around s.jsonpCallback = originalSettings.jsonpCallback; @@ -8418,16 +8677,18 @@ jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) { } responseContainer = overwritten = undefined; - }); + } ); // Delegate to script return "script"; } -}); +} ); var xhrCallbacks, xhrSupported, xhrId = 0, + // #5280: Internet Explorer will keep connections alive if we don't abort on unload xhrOnUnloadAbort = window.ActiveXObject && function() { + // Abort all pending requests var key; for ( key in xhrCallbacks ) { @@ -8439,13 +8700,13 @@ var xhrCallbacks, xhrSupported, function createStandardXHR() { try { return new window.XMLHttpRequest(); - } catch( e ) {} + } catch ( e ) {} } function createActiveXHR() { try { - return new window.ActiveXObject("Microsoft.XMLHTTP"); - } catch( e ) {} + return new window.ActiveXObject( "Microsoft.XMLHTTP" ); + } catch ( e ) {} } // Create the request object @@ -8460,6 +8721,7 @@ jQuery.ajaxSettings.xhr = window.ActiveXObject ? function() { return !this.isLocal && createStandardXHR() || createActiveXHR(); } : + // For all other browsers, use the standard XMLHttpRequest object createStandardXHR; @@ -8471,7 +8733,8 @@ xhrSupported = jQuery.support.ajax = !!xhrSupported; // Create transport if the browser can provide an xhr if ( xhrSupported ) { - jQuery.ajaxTransport(function( s ) { + jQuery.ajaxTransport( function( s ) { + // Cross domain only allowed if supported through XMLHttpRequest if ( !s.crossDomain || jQuery.support.cors ) { @@ -8509,8 +8772,8 @@ if ( xhrSupported ) { // akin to a jigsaw puzzle, we simply never set it to be sure. // (it can always be set on a per-request basis or even using ajaxSetup) // For same-domain requests, won't change header if already provided. - if ( !s.crossDomain && !headers["X-Requested-With"] ) { - headers["X-Requested-With"] = "XMLHttpRequest"; + if ( !s.crossDomain && !headers[ "X-Requested-With" ] ) { + headers[ "X-Requested-With" ] = "XMLHttpRequest"; } // Need an extra try/catch for cross domain requests in Firefox 3 @@ -8518,7 +8781,7 @@ if ( xhrSupported ) { for ( i in headers ) { xhr.setRequestHeader( i, headers[ i ] ); } - } catch( err ) {} + } catch ( err ) {} // Do send the request // This may raise an exception which is actually @@ -8550,6 +8813,7 @@ if ( xhrSupported ) { // If it's an abort if ( isAbort ) { + // Abort it manually if needed if ( xhr.readyState !== 4 ) { xhr.abort(); @@ -8569,7 +8833,8 @@ if ( xhrSupported ) { // statusText for faulty cross-domain requests try { statusText = xhr.statusText; - } catch( e ) { + } catch ( e ) { + // We normalize with Webkit giving an empty statusText statusText = ""; } @@ -8581,13 +8846,14 @@ if ( xhrSupported ) { // can do given current implementations) if ( !status && s.isLocal && !s.crossDomain ) { status = responses.text ? 200 : 404; + // IE - #1450: sometimes returns 1223 when it should be 204 } else if ( status === 1223 ) { status = 204; } } } - } catch( firefoxAccessException ) { + } catch ( firefoxAccessException ) { if ( !isAbort ) { complete( -1, firefoxAccessException ); } @@ -8600,21 +8866,25 @@ if ( xhrSupported ) { }; if ( !s.async ) { + // if we're in sync mode we fire the callback callback(); } else if ( xhr.readyState === 4 ) { + // (IE6 & IE7) if it's in cache and has been // retrieved directly we need to fire the callback setTimeout( callback ); } else { handle = ++xhrId; if ( xhrOnUnloadAbort ) { + // Create the active xhrs callbacks list if needed // and attach the unload handler if ( !xhrCallbacks ) { xhrCallbacks = {}; jQuery( window ).unload( xhrOnUnloadAbort ); } + // Add to list of active xhrs callbacks xhrCallbacks[ handle ] = callback; } @@ -8629,7 +8899,7 @@ if ( xhrSupported ) { } }; } - }); + } ); } var fxNow, timerId, rfxtypes = /^(?:toggle|show|hide)$/, @@ -8637,7 +8907,7 @@ var fxNow, timerId, rrun = /queueHooks$/, animationPrefilters = [ defaultPrefilter ], tweeners = { - "*": [function( prop, value ) { + "*": [ function( prop, value ) { var end, unit, tween = this.createTween( prop, value ), parts = rfxnum.exec( value ), @@ -8647,17 +8917,19 @@ var fxNow, timerId, maxIterations = 20; if ( parts ) { - end = +parts[2]; - unit = parts[3] || ( jQuery.cssNumber[ prop ] ? "" : "px" ); + end = +parts[ 2 ]; + unit = parts[ 3 ] || ( jQuery.cssNumber[ prop ] ? "" : "px" ); // We need to compute starting value if ( unit !== "px" && start ) { + // Iteratively approximate from a nonzero starting point // Prefer the current property, because this process will be trivial if it uses the same units // Fallback to end or a simple constant start = jQuery.css( tween.elem, prop, true ) || end || 1; do { + // If previous iteration zeroed out, double until we get *something* // Use a string for doubling factor so we don't accidentally see scale as unchanged below scale = scale || ".5"; @@ -8668,23 +8940,24 @@ var fxNow, timerId, // Update scale, tolerating zero or NaN from tween.cur() // And breaking the loop if scale is unchanged or perfect, or if we've just had enough - } while ( scale !== (scale = tween.cur() / target) && scale !== 1 && --maxIterations ); + } while ( scale !== ( scale = tween.cur() / target ) && scale !== 1 && --maxIterations ); } tween.unit = unit; tween.start = start; + // If a +=/-= token was provided, we're doing a relative animation - tween.end = parts[1] ? start + ( parts[1] + 1 ) * end : end; + tween.end = parts[ 1 ] ? start + ( parts[ 1 ] + 1 ) * end : end; } return tween; - }] + } ] }; // Animations created synchronously will run synchronously function createFxNow() { - setTimeout(function() { + setTimeout( function() { fxNow = undefined; - }); + } ); return ( fxNow = jQuery.now() ); } @@ -8700,7 +8973,7 @@ function createTweens( animation, props ) { return; } } - }); + } ); } function Animation( elem, properties, options ) { @@ -8709,15 +8982,17 @@ function Animation( elem, properties, options ) { index = 0, length = animationPrefilters.length, deferred = jQuery.Deferred().always( function() { + // don't match elem in the :animated selector delete tick.elem; - }), + } ), tick = function() { if ( stopped ) { return false; } var currentTime = fxNow || createFxNow(), remaining = Math.max( 0, animation.startTime + animation.duration - currentTime ), + // archaic crash bug won't allow us to use 1 - ( 0.5 || 0 ) (#12497) temp = remaining / animation.duration || 0, percent = 1 - temp, @@ -8728,7 +9003,7 @@ function Animation( elem, properties, options ) { animation.tweens[ index ].run( percent ); } - deferred.notifyWith( elem, [ animation, percent, remaining ]); + deferred.notifyWith( elem, [ animation, percent, remaining ] ); if ( percent < 1 && length ) { return remaining; @@ -8737,7 +9012,7 @@ function Animation( elem, properties, options ) { return false; } }, - animation = deferred.promise({ + animation = deferred.promise( { elem: elem, props: jQuery.extend( {}, properties ), opts: jQuery.extend( true, { specialEasing: {} }, options ), @@ -8754,6 +9029,7 @@ function Animation( elem, properties, options ) { }, stop: function( gotoEnd ) { var index = 0, + // if we are going to the end, we want to run all the tweens // otherwise we skip this part length = gotoEnd ? animation.tweens.length : 0; @@ -8774,7 +9050,7 @@ function Animation( elem, properties, options ) { } return this; } - }), + } ), props = animation.props; propFilter( props, animation.opts.specialEasing ); @@ -8797,7 +9073,7 @@ function Animation( elem, properties, options ) { elem: elem, anim: animation, queue: animation.opts.queue - }) + } ) ); // attach callbacks from options @@ -8851,7 +9127,7 @@ jQuery.Animation = jQuery.extend( Animation, { callback = props; props = [ "*" ]; } else { - props = props.split(" "); + props = props.split( " " ); } var prop, @@ -8872,7 +9148,7 @@ jQuery.Animation = jQuery.extend( Animation, { animationPrefilters.push( callback ); } } -}); +} ); function defaultPrefilter( elem, props, opts ) { /*jshint validthis:true */ @@ -8899,20 +9175,22 @@ function defaultPrefilter( elem, props, opts ) { } hooks.unqueued++; - anim.always(function() { + anim.always( function() { + // doing this makes sure that the complete handler will be called // before this completes - anim.always(function() { + anim.always( function() { hooks.unqueued--; if ( !jQuery.queue( elem, "fx" ).length ) { hooks.empty.fire(); } - }); - }); + } ); + } ); } // height/width overflow pass if ( elem.nodeType === 1 && ( "height" in props || "width" in props ) ) { + // Make sure that nothing sneaks out // Record all 3 overflow attributes because IE does not // change the overflow attribute when overflowX and @@ -8938,15 +9216,14 @@ function defaultPrefilter( elem, props, opts ) { if ( opts.overflow ) { style.overflow = "hidden"; if ( !jQuery.support.shrinkWrapBlocks ) { - anim.always(function() { + anim.always( function() { style.overflow = opts.overflow[ 0 ]; style.overflowX = opts.overflow[ 1 ]; style.overflowY = opts.overflow[ 2 ]; - }); + } ); } } - // show/hide pass for ( index in props ) { value = props[ index ]; @@ -8974,17 +9251,17 @@ function defaultPrefilter( elem, props, opts ) { if ( hidden ) { jQuery( elem ).show(); } else { - anim.done(function() { + anim.done( function() { jQuery( elem ).hide(); - }); + } ); } - anim.done(function() { + anim.done( function() { var prop; jQuery._removeData( elem, "fxshow" ); for ( prop in orig ) { jQuery.style( elem, prop, orig[ prop ] ); } - }); + } ); for ( index = 0 ; index < length ; index++ ) { prop = handled[ index ]; tween = anim.createTween( prop, hidden ? dataShow[ prop ] : 0 ); @@ -9058,7 +9335,7 @@ Tween.propHooks = { var result; if ( tween.elem[ tween.prop ] != null && - (!tween.elem.style || tween.elem.style[ tween.prop ] == null) ) { + ( !tween.elem.style || tween.elem.style[ tween.prop ] == null ) ) { return tween.elem[ tween.prop ]; } @@ -9067,10 +9344,12 @@ Tween.propHooks = { // so, simple values such as "10px" are parsed to Float. // complex values such as "rotate(1rad)" are returned as is. result = jQuery.css( tween.elem, tween.prop, "" ); + // Empty strings, null, undefined and "auto" are converted to 0. return !result || result === "auto" ? 0 : result; }, set: function( tween ) { + // use step hook for back compat - use cssHook if its there - use .style if its // available and use plain properties where available if ( jQuery.fx.step[ tween.prop ] ) { @@ -9095,33 +9374,35 @@ Tween.propHooks.scrollTop = Tween.propHooks.scrollLeft = { } }; -jQuery.each([ "toggle", "show", "hide" ], function( i, name ) { +jQuery.each( [ "toggle", "show", "hide" ], function( i, name ) { var cssFn = jQuery.fn[ name ]; jQuery.fn[ name ] = function( speed, easing, callback ) { return speed == null || typeof speed === "boolean" ? cssFn.apply( this, arguments ) : this.animate( genFx( name, true ), speed, easing, callback ); }; -}); +} ); -jQuery.fn.extend({ +jQuery.fn.extend( { fadeTo: function( speed, to, easing, callback ) { // show any hidden elements after setting opacity to 0 return this.filter( isHidden ).css( "opacity", 0 ).show() // animate to the value specified - .end().animate({ opacity: to }, speed, easing, callback ); + .end().animate( { opacity: to }, speed, easing, callback ); }, animate: function( prop, speed, easing, callback ) { var empty = jQuery.isEmptyObject( prop ), optall = jQuery.speed( speed, easing, callback ), doAnimation = function() { + // Operate on a copy of prop so per-property easing won't be lost var anim = Animation( this, jQuery.extend( {}, prop ), optall ); doAnimation.finish = function() { anim.stop( true ); }; + // Empty animations, or finishing resolves immediately if ( empty || jQuery._data( this, "finish" ) ) { anim.stop( true ); @@ -9149,7 +9430,7 @@ jQuery.fn.extend({ this.queue( type || "fx", [] ); } - return this.each(function() { + return this.each( function() { var dequeue = true, index = type != null && type + "queueHooks", timers = jQuery.timers, @@ -9168,7 +9449,7 @@ jQuery.fn.extend({ } for ( index = timers.length; index--; ) { - if ( timers[ index ].elem === this && (type == null || timers[ index ].queue === type) ) { + if ( timers[ index ].elem === this && ( type == null || timers[ index ].queue === type ) ) { timers[ index ].anim.stop( gotoEnd ); dequeue = false; timers.splice( index, 1 ); @@ -9181,13 +9462,13 @@ jQuery.fn.extend({ if ( dequeue || !gotoEnd ) { jQuery.dequeue( this, type ); } - }); + } ); }, finish: function( type ) { if ( type !== false ) { type = type || "fx"; } - return this.each(function() { + return this.each( function() { var index, data = jQuery._data( this ), queue = data[ type + "queue" ], @@ -9222,9 +9503,9 @@ jQuery.fn.extend({ // turn off finishing flag delete data.finish; - }); + } ); } -}); +} ); // Generate parameters to create a standard animation function genFx( type, includeWidth ) { @@ -9234,8 +9515,8 @@ function genFx( type, includeWidth ) { // if we include width, step value is 1 to do all cssExpand values, // if we don't include width, step value is 2 to skip over Left and Right - includeWidth = includeWidth? 1 : 0; - for( ; i < 4 ; i += 2 - includeWidth ) { + includeWidth = includeWidth ? 1 : 0; + for ( ; i < 4 ; i += 2 - includeWidth ) { which = cssExpand[ i ]; attrs[ "margin" + which ] = attrs[ "padding" + which ] = type; } @@ -9248,10 +9529,10 @@ function genFx( type, includeWidth ) { } // Generate shortcuts for custom animations -jQuery.each({ - slideDown: genFx("show"), - slideUp: genFx("hide"), - slideToggle: genFx("toggle"), +jQuery.each( { + slideDown: genFx( "show" ), + slideUp: genFx( "hide" ), + slideToggle: genFx( "toggle" ), fadeIn: { opacity: "show" }, fadeOut: { opacity: "hide" }, fadeToggle: { opacity: "toggle" } @@ -9259,7 +9540,7 @@ jQuery.each({ jQuery.fn[ name ] = function( speed, easing, callback ) { return this.animate( props, speed, easing, callback ); }; -}); +} ); jQuery.speed = function( speed, easing, fn ) { var opt = speed && typeof speed === "object" ? jQuery.extend( {}, speed ) : { @@ -9298,7 +9579,7 @@ jQuery.easing = { return p; }, swing: function( p ) { - return 0.5 - Math.cos( p*Math.PI ) / 2; + return 0.5 - Math.cos( p * Math.PI ) / 2; } }; @@ -9313,6 +9594,7 @@ jQuery.fx.tick = function() { for ( ; i < timers.length; i++ ) { timer = timers[ i ]; + // Checks the timer has not already been removed if ( !timer() && timers[ i ] === timer ) { timers.splice( i--, 1 ); @@ -9347,6 +9629,7 @@ jQuery.fx.stop = function() { jQuery.fx.speeds = { slow: 600, fast: 200, + // Default speed _default: 400 }; @@ -9356,18 +9639,18 @@ jQuery.fx.step = {}; if ( jQuery.expr && jQuery.expr.filters ) { jQuery.expr.filters.animated = function( elem ) { - return jQuery.grep(jQuery.timers, function( fn ) { + return jQuery.grep( jQuery.timers, function( fn ) { return elem === fn.elem; - }).length; + } ).length; }; } jQuery.fn.offset = function( options ) { if ( arguments.length ) { return options === undefined ? this : - this.each(function( i ) { + this.each( function( i ) { jQuery.offset.setOffset( this, options, i ); - }); + } ); } var docElem, win, @@ -9412,7 +9695,7 @@ jQuery.offset = { curOffset = curElem.offset(), curCSSTop = jQuery.css( elem, "top" ), curCSSLeft = jQuery.css( elem, "left" ), - calculatePosition = ( position === "absolute" || position === "fixed" ) && jQuery.inArray("auto", [curCSSTop, curCSSLeft]) > -1, + calculatePosition = ( position === "absolute" || position === "fixed" ) && jQuery.inArray( "auto", [ curCSSTop, curCSSLeft ] ) > -1, props = {}, curPosition = {}, curTop, curLeft; // need to be able to calculate position if either top or left is auto and position is either absolute or fixed @@ -9444,8 +9727,7 @@ jQuery.offset = { } }; - -jQuery.fn.extend({ +jQuery.fn.extend( { position: function() { if ( !this[ 0 ] ) { @@ -9458,9 +9740,11 @@ jQuery.fn.extend({ // fixed elements are offset from window (parentOffset = {top:0, left: 0}, because it is it's only offset parent if ( jQuery.css( elem, "position" ) === "fixed" ) { + // we assume that getBoundingClientRect is available when computed position is fixed offset = elem.getBoundingClientRect(); } else { + // Get *real* offsetParent offsetParent = this.offsetParent(); @@ -9480,24 +9764,23 @@ jQuery.fn.extend({ // are the same in Safari causing offset.left to incorrectly be 0 return { top: offset.top - parentOffset.top - jQuery.css( elem, "marginTop", true ), - left: offset.left - parentOffset.left - jQuery.css( elem, "marginLeft", true) + left: offset.left - parentOffset.left - jQuery.css( elem, "marginLeft", true ) }; }, offsetParent: function() { - return this.map(function() { + return this.map( function() { var offsetParent = this.offsetParent || document.documentElement; - while ( offsetParent && ( !jQuery.nodeName( offsetParent, "html" ) && jQuery.css( offsetParent, "position") === "static" ) ) { + while ( offsetParent && ( !jQuery.nodeName( offsetParent, "html" ) && jQuery.css( offsetParent, "position" ) === "static" ) ) { offsetParent = offsetParent.offsetParent; } return offsetParent || document.documentElement; - }); + } ); } -}); - +} ); // Create scrollLeft and scrollTop methods -jQuery.each( {scrollLeft: "pageXOffset", scrollTop: "pageYOffset"}, function( method, prop ) { +jQuery.each( { scrollLeft: "pageXOffset", scrollTop: "pageYOffset" }, function( method, prop ) { var top = /Y/.test( prop ); jQuery.fn[ method ] = function( val ) { @@ -9505,7 +9788,7 @@ jQuery.each( {scrollLeft: "pageXOffset", scrollTop: "pageYOffset"}, function( me var win = getWindow( elem ); if ( val === undefined ) { - return win ? (prop in win) ? win[ prop ] : + return win ? ( prop in win ) ? win[ prop ] : win.document.documentElement[ method ] : elem[ method ]; } @@ -9521,7 +9804,7 @@ jQuery.each( {scrollLeft: "pageXOffset", scrollTop: "pageYOffset"}, function( me } }, method, val, arguments.length, null ); }; -}); +} ); function getWindow( elem ) { return jQuery.isWindow( elem ) ? @@ -9530,9 +9813,11 @@ function getWindow( elem ) { elem.defaultView || elem.parentWindow : false; } + // Create innerHeight, innerWidth, height, width, outerHeight and outerWidth methods jQuery.each( { Height: "height", Width: "width" }, function( name, type ) { jQuery.each( { padding: "inner" + name, content: type, "": "outer" + name }, function( defaultExtra, funcName ) { + // margin is only for outerHeight, outerWidth jQuery.fn[ funcName ] = function( margin, value ) { var chainable = arguments.length && ( defaultExtra || typeof margin !== "boolean" ), @@ -9542,6 +9827,7 @@ jQuery.each( { Height: "height", Width: "width" }, function( name, type ) { var doc; if ( jQuery.isWindow( elem ) ) { + // As of 5/8/2012 this will yield incorrect results for Mobile Safari, but there // isn't a whole lot we can do. See pull request at this URL for discussion: // https://github.com/jquery/jquery/pull/764 @@ -9562,6 +9848,7 @@ jQuery.each( { Height: "height", Width: "width" }, function( name, type ) { } return value === undefined ? + // Get width or height on the element, requesting but not forcing parseFloat jQuery.css( elem, type, extra ) : @@ -9569,8 +9856,9 @@ jQuery.each( { Height: "height", Width: "width" }, function( name, type ) { jQuery.style( elem, type, value, extra ); }, type, chainable ? margin : undefined, chainable, null ); }; - }); -}); + } ); +} ); + // Limit scope pollution from any deprecated API // (function() { @@ -9591,7 +9879,7 @@ window.jQuery = window.$ = jQuery; // Do this after creating the global so that if an AMD module wants to call // noConflict to hide this version of jQuery, it will work. if ( typeof define === "function" && define.amd && define.amd.jQuery ) { - define( "jquery", [], function () { return jQuery; } ); + define( "jquery", [], function() { return jQuery; } ); } -})( window ); +} )( window ); diff --git a/test/data/readywaitloader.js b/test/data/readywaitloader.js index e07dac7a9..8f4a3452e 100644 --- a/test/data/readywaitloader.js +++ b/test/data/readywaitloader.js @@ -1,19 +1,19 @@ // Simple script loader that uses jQuery.readyWait via jQuery.holdReady() //Hold on jQuery! -jQuery.holdReady(true); +jQuery.holdReady( true ); var readyRegExp = /^(complete|loaded)$/; -function assetLoaded( evt ){ +function assetLoaded( evt ) { var node = evt.currentTarget || evt.srcElement; - if ( evt.type === "load" || readyRegExp.test(node.readyState) ) { - jQuery.holdReady(false); + if ( evt.type === "load" || readyRegExp.test( node.readyState ) ) { + jQuery.holdReady( false ); } } setTimeout( function() { - var script = document.createElement("script"); + var script = document.createElement( "script" ); script.type = "text/javascript"; if ( script.addEventListener ) { script.addEventListener( "load", assetLoaded, false ); @@ -21,5 +21,5 @@ setTimeout( function() { script.attachEvent( "onreadystatechange", assetLoaded ); } script.src = "data/readywaitasset.js"; - document.getElementsByTagName("head")[0].appendChild(script); + document.getElementsByTagName( "head" )[ 0 ].appendChild( script ); }, 2000 ); diff --git a/test/data/testinit.js b/test/data/testinit.js index 0dcb4f871..491440e19 100644 --- a/test/data/testinit.js +++ b/test/data/testinit.js @@ -3,6 +3,7 @@ var fireNative, originaljQuery, original$, baseURL = "", supportjQuery = this.jQuery, + // see RFC 2606 externalHost = "example.com"; @@ -24,7 +25,7 @@ this.q = function() { i = 0; for ( ; i < arguments.length; i++ ) { - r.push( document.getElementById( arguments[i] ) ); + r.push( document.getElementById( arguments[ i ] ) ); } return r; }; @@ -62,7 +63,7 @@ this.createDashboardXML = function() { </locations> \ </dashboard>'; - return jQuery.parseXML(string); + return jQuery.parseXML( string ); }; this.createWithFriesXML = function() { @@ -131,7 +132,7 @@ fireNative = document.createEvent ? * @result "data/test.php?foo=bar&10538358345554" */ function url( value ) { - return baseURL + value + (/\?/.test( value ) ? "&" : "?") + + return baseURL + value + ( /\?/.test( value ) ? "&" : "?" ) + new Date().getTime() + "" + parseInt( Math.random() * 100000, 10 ); } @@ -166,7 +167,7 @@ this.ajaxTest = function( title, expect, options ) { } // Make sure all events will be called before done() - setTimeout(done); + setTimeout( done ); } }, requests = jQuery.map( requestOptions, function( options ) { @@ -192,7 +193,7 @@ this.ajaxTest = function( title, expect, options ) { .done( callIfDefined( "done", "success" ) ) .fail( callIfDefined( "fail", "error" ) ) .always( complete ); - }); + } ); ajaxTest.abort = function( reason ) { if ( !completed ) { @@ -201,20 +202,20 @@ this.ajaxTest = function( title, expect, options ) { ok( false, "aborted " + reason ); jQuery.each( requests, function( i, request ) { request.abort(); - }); + } ); } }; - }); + } ); }; this.testIframe = function( fileName, name, fn ) { - QUnit.test(name, function( assert ) { + QUnit.test( name, function( assert ) { var done = assert.async(); // load fixture in iframe var iframe = loadFixture(), win = iframe.contentWindow, - interval = setInterval(function() { + interval = setInterval( function() { if ( win && win.jQuery && win.jQuery.isReady ) { clearInterval( interval ); @@ -225,7 +226,7 @@ this.testIframe = function( fileName, name, fn ) { iframe = null; } }, 15 ); - }); + } ); function loadFixture() { var src = url( "./data/" + fileName + ".html" ), @@ -248,7 +249,7 @@ this.testIframeWithCallback = function( title, fileName, func ) { args.push( assert ); - setTimeout(function() { + setTimeout( function() { this.iframeCallback = undefined; iframe.remove(); @@ -256,12 +257,12 @@ this.testIframeWithCallback = function( title, fileName, func ) { func = function() {}; done(); - }); + } ); }; - iframe = jQuery( "<div/>" ).css({ position: "absolute", width: "500px", left: "-600px" }) + iframe = jQuery( "<div/>" ).css( { position: "absolute", width: "500px", left: "-600px" } ) .append( jQuery( "<iframe/>" ).attr( "src", url( "./data/" + fileName ) ) ) .appendTo( "#qunit-fixture" ); - }); + } ); }; this.iframeCallback = undefined; @@ -275,7 +276,7 @@ this.loadTests = function() { loadSwarm = url && url.indexOf( "http" ) === 0; // Get testSubproject from testrunner first - require([ "data/testrunner.js" ], function() { + require( [ "data/testrunner.js" ], function() { var tests = [ "unit/core.js", "unit/callbacks.js", @@ -300,7 +301,7 @@ this.loadTests = function() { ]; // Ensure load order (to preserve test numbers) - (function loadDep() { + ( function loadDep() { var dep = tests.shift(); if ( dep ) { @@ -318,14 +319,14 @@ this.loadTests = function() { // Load the TestSwarm listener if swarmURL is in the address. if ( loadSwarm ) { - require( [ "http://swarm.jquery.org/js/inject.js?" + (new Date()).getTime() ], + require( [ "http://swarm.jquery.org/js/inject.js?" + ( new Date() ).getTime() ], function() { QUnit.start(); - }); + } ); } else { QUnit.start(); } } - })(); - }); + } )(); + } ); }; diff --git a/test/data/testrunner.js b/test/data/testrunner.js index 3701870ad..454e8035e 100644 --- a/test/data/testrunner.js +++ b/test/data/testrunner.js @@ -1,4 +1,4 @@ -(function() { +( function() { // Store the old counts so that we only assert on tests that have actually leaked, // instead of asserting every time a test has leaked sometime in the past @@ -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. @@ -79,12 +81,12 @@ QUnit.expectJqData = function( env, elems, key ) { } }; -QUnit.config.urlConfig.push({ +QUnit.config.urlConfig.push( { id: "jqdata", label: "Always check jQuery.data", tooltip: "Trigger QUnit.expectJqData detection for all tests " + "instead of just the ones that call it" -}); +} ); /** * Ensures that tests have cleaned up properly after themselves. Should be passed as the @@ -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( @@ -129,7 +132,7 @@ window.moduleTeardown = function() { if ( jQuery.active !== undefined && jQuery.active !== oldActive ) { equal( jQuery.active, oldActive, "No AJAX requests are still active" ); if ( ajaxTest.abort ) { - ajaxTest.abort("active requests"); + ajaxTest.abort( "active requests" ); } oldActive = jQuery.active; } @@ -150,15 +153,17 @@ window.moduleTeardown = function() { } }; -QUnit.done(function() { +QUnit.done( function() { + // Remove our own fixtures outside #qunit-fixture supportjQuery( "#qunit ~ *" ).remove(); -}); +} ); -QUnit.testDone(function() { +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(); @@ -172,10 +177,10 @@ QUnit.testDone(function() { // Cleanup globals Globals.cleanup(); -}); +} ); // Register globals for cleanup and the cleanup code itself -window.Globals = (function() { +window.Globals = ( function() { var globals = {}; return { @@ -193,6 +198,6 @@ window.Globals = (function() { globals = {}; } }; -})(); +} )(); -})(); +} )(); diff --git a/test/node_smoke_tests/document_missing.js b/test/node_smoke_tests/document_missing.js index 4a0ad2e2b..348e9a4ef 100644 --- a/test/node_smoke_tests/document_missing.js +++ b/test/node_smoke_tests/document_missing.js @@ -4,7 +4,7 @@ var assert = require( "assert" ), ensureGlobalNotCreated = require( "./lib/ensure_global_not_created" ), jQueryFactory = require( "../../dist/jquery.js" ); -assert.throws( function () { +assert.throws( function() { jQueryFactory( {} ); }, /jQuery requires a window with a document/ ); diff --git a/test/unit/ajax.js b/test/unit/ajax.js index 2f8334147..0cc799800 100644 --- a/test/unit/ajax.js +++ b/test/unit/ajax.js @@ -3,15 +3,15 @@ QUnit.module( "ajax", { jQuery( document ).off( "ajaxStart ajaxStop ajaxSend ajaxComplete ajaxError ajaxSuccess" ); moduleTeardown.apply( this, arguments ); } -}); +} ); -(function() { - QUnit.test("Unit Testing Environment", function( assert ) { +( function() { + QUnit.test( "Unit Testing Environment", function( assert ) { assert.expect( 2 ); assert.ok( hasPHP, "Running in an environment with PHP support. The AJAX tests only run if the environment supports PHP!" ); assert.ok( !isLocal, "Unit tests are not ran from file:// (especially in Chrome. If you must test from file:// with Chrome, run it with the --allow-file-access-from-files flag!)" ); - }); + } ); if ( !jQuery.ajax || ( isLocal && !hasPHP ) ) { return; @@ -21,8 +21,8 @@ QUnit.module( "ajax", { return function() { expected = expected || ""; jQuery( document ).on( "ajaxStart ajaxStop ajaxSend ajaxComplete ajaxError ajaxSuccess", function( e ) { - assert.ok( expected.indexOf(e.type) !== -1, e.type ); - }); + assert.ok( expected.indexOf( e.type ) !== -1, e.type ); + } ); }; } @@ -40,7 +40,7 @@ QUnit.module( "ajax", { ajaxTest( "jQuery.ajax() - success callbacks", 8, function( assert ) { return { setup: addGlobalEvents( "ajaxStart ajaxStop ajaxSend ajaxComplete ajaxSuccess", assert ), - url: url("data/name.html"), + url: url( "data/name.html" ), beforeSend: function() { assert.ok( true, "beforeSend" ); }, @@ -48,16 +48,16 @@ QUnit.module( "ajax", { assert.ok( true, "success" ); }, complete: function() { - assert.ok( true, "complete"); + assert.ok( true, "complete" ); } }; - }); + } ); ajaxTest( "jQuery.ajax() - success callbacks - (url, options) syntax", 8, function( assert ) { return { - setup: addGlobalEvents("ajaxStart ajaxStop ajaxSend ajaxComplete ajaxSuccess", assert ), + setup: addGlobalEvents( "ajaxStart ajaxStop ajaxSend ajaxComplete ajaxSuccess", assert ), create: function( options ) { - return jQuery.ajax( url("data/name.html"), options ); + return jQuery.ajax( url( "data/name.html" ), options ); }, beforeSend: function() { assert.ok( true, "beforeSend" ); @@ -69,52 +69,52 @@ QUnit.module( "ajax", { assert.ok( true, "complete" ); } }; - }); + } ); ajaxTest( "jQuery.ajax() - success callbacks (late binding)", 8, function( assert ) { return { - setup: addGlobalEvents("ajaxStart ajaxStop ajaxSend ajaxComplete ajaxSuccess", assert ), - url: url("data/name.html"), + setup: addGlobalEvents( "ajaxStart ajaxStop ajaxSend ajaxComplete ajaxSuccess", assert ), + url: url( "data/name.html" ), beforeSend: function() { assert.ok( true, "beforeSend" ); }, success: true, afterSend: function( request ) { - request.always(function() { + request.always( function() { assert.ok( true, "complete" ); - }).done(function() { + } ).done( function() { assert.ok( true, "success" ); - }).fail(function() { + } ).fail( function() { assert.ok( false, "error" ); - }); + } ); } }; - }); + } ); ajaxTest( "jQuery.ajax() - success callbacks (oncomplete binding)", 8, function( assert ) { return { - setup: addGlobalEvents("ajaxStart ajaxStop ajaxSend ajaxComplete ajaxSuccess", assert ), - url: url("data/name.html"), + setup: addGlobalEvents( "ajaxStart ajaxStop ajaxSend ajaxComplete ajaxSuccess", assert ), + url: url( "data/name.html" ), beforeSend: function() { assert.ok( true, "beforeSend" ); }, success: true, complete: function( xhr ) { - xhr.always(function() { + xhr.always( function() { assert.ok( true, "complete" ); - }).done(function() { + } ).done( function() { assert.ok( true, "success" ); - }).fail(function() { + } ).fail( function() { assert.ok( false, "error" ); - }); + } ); } }; - }); + } ); ajaxTest( "jQuery.ajax() - error callbacks", 8, function( assert ) { return { - setup: addGlobalEvents("ajaxStart ajaxStop ajaxSend ajaxComplete ajaxError", assert ), - url: url("data/name.php?wait=5"), + setup: addGlobalEvents( "ajaxStart ajaxStop ajaxSend ajaxComplete ajaxError", assert ), + url: url( "data/name.php?wait=5" ), beforeSend: function() { assert.ok( true, "beforeSend" ); }, @@ -128,11 +128,11 @@ QUnit.module( "ajax", { assert.ok( true, "complete" ); } }; - }); + } ); ajaxTest( "jQuery.ajax() - textStatus and errorThrown values", 4, function( assert ) { - return [{ - url: url("data/name.php?wait=5"), + return [ { + url: url( "data/name.php?wait=5" ), error: function( _, textStatus, errorThrown ) { assert.strictEqual( textStatus, "abort", "textStatus is 'abort' for abort" ); assert.strictEqual( errorThrown, "abort", "errorThrown is 'abort' for abort" ); @@ -142,39 +142,39 @@ QUnit.module( "ajax", { } }, { - url: url("data/name.php?wait=5"), + url: url( "data/name.php?wait=5" ), error: function( _, textStatus, errorThrown ) { assert.strictEqual( textStatus, "mystatus", "textStatus is 'mystatus' for abort('mystatus')" ); assert.strictEqual( errorThrown, "mystatus", "errorThrown is 'mystatus' for abort('mystatus')" ); }, afterSend: function( request ) { - request.abort("mystatus"); + request.abort( "mystatus" ); } - }]; - }); + } ]; + } ); ajaxTest( "jQuery.ajax() - responseText on error", 1, function( assert ) { return { - url: url("data/errorWithText.php"), + url: url( "data/errorWithText.php" ), error: function( xhr ) { assert.strictEqual( xhr.responseText, "plain text message", "Test jqXHR.responseText is filled for HTTP errors" ); } }; - }); + } ); QUnit.asyncTest( "jQuery.ajax() - retry with jQuery.ajax( this )", 2, function( assert ) { var previousUrl, firstTime = true; - jQuery.ajax({ - url: url("data/errorWithText.php"), + jQuery.ajax( { + url: url( "data/errorWithText.php" ), error: function() { if ( firstTime ) { firstTime = false; jQuery.ajax( this ); } else { ok ( true, "Test retrying with jQuery.ajax(this) works" ); - jQuery.ajax({ - url: url("data/errorWithText.php"), + jQuery.ajax( { + url: url( "data/errorWithText.php" ), data: { "x": 1 }, @@ -190,20 +190,20 @@ QUnit.module( "ajax", { error: function() { jQuery.ajax( this ); } - }); + } ); } } - }); - }); + } ); + } ); ajaxTest( "jQuery.ajax() - headers", 5, function( assert ) { return { setup: function() { - jQuery( document ).ajaxSend(function( evt, xhr ) { + jQuery( document ).ajaxSend( function( evt, xhr ) { xhr.setRequestHeader( "ajax-send", "test" ); - }); + } ); }, - url: url("data/headers.php?keys=siMPle_SometHing-elsE_OthEr_Nullable_undefined_Empty_ajax-send"), + url: url( "data/headers.php?keys=siMPle_SometHing-elsE_OthEr_Nullable_undefined_Empty_ajax-send" ), headers: { "siMPle": "value", "SometHing-elsE": "other value", @@ -220,63 +220,64 @@ QUnit.module( "ajax", { var i, emptyHeader, requestHeaders = jQuery.extend( this.headers, { "ajax-send": "test" - }), + } ), tmp = []; for ( i in requestHeaders ) { tmp.push( i, ": ", requestHeaders[ i ] + "", "\n" ); } - tmp = tmp.join(""); + tmp = tmp.join( "" ); assert.strictEqual( data, tmp, "Headers were sent" ); - assert.strictEqual( xhr.getResponseHeader("Sample-Header"), "Hello World", "Sample header received" ); - assert.ok( data.indexOf( "undefined" ) < 0 , "Undefined header value was not sent" ); + assert.strictEqual( xhr.getResponseHeader( "Sample-Header" ), "Hello World", "Sample header received" ); + assert.ok( data.indexOf( "undefined" ) < 0, "Undefined header value was not sent" ); - emptyHeader = xhr.getResponseHeader("Empty-Header"); + emptyHeader = xhr.getResponseHeader( "Empty-Header" ); if ( emptyHeader === null ) { assert.ok( true, "Firefox doesn't support empty headers" ); } else { assert.strictEqual( emptyHeader, "", "Empty header received" ); } - assert.strictEqual( xhr.getResponseHeader("Sample-Header2"), "Hello World 2", "Second sample header received" ); + assert.strictEqual( xhr.getResponseHeader( "Sample-Header2" ), "Hello World 2", "Second sample header received" ); } }; - }); + } ); ajaxTest( "jQuery.ajax() - Accept header", 1, function( assert ) { return { - url: url("data/headers.php?keys=accept"), + url: url( "data/headers.php?keys=accept" ), headers: { Accept: "very wrong accept value" }, beforeSend: function( xhr ) { - xhr.setRequestHeader("Accept", "*/*"); + xhr.setRequestHeader( "Accept", "*/*" ); }, success: function( data ) { assert.strictEqual( data, "accept: */*\n", "Test Accept header is set to last value provided" ); } }; - }); + } ); ajaxTest( "jQuery.ajax() - contentType", 2, function( assert ) { return [ { - url: url("data/headers.php?keys=content-type"), + url: url( "data/headers.php?keys=content-type" ), contentType: "test", success: function( data ) { assert.strictEqual( data, "content-type: test\n", "Test content-type is sent when options.contentType is set" ); } }, { - url: url("data/headers.php?keys=content-type"), + 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" ); } } ]; - }); + } ); ajaxTest( "jQuery.ajax() - protocol-less urls", 1, function( assert ) { return { @@ -287,7 +288,7 @@ QUnit.module( "ajax", { }, error: true }; - }); + } ); ajaxTest( "jQuery.ajax() - hash", 3, function( assert ) { return [ @@ -319,7 +320,7 @@ QUnit.module( "ajax", { error: true } ]; - }); + } ); ajaxTest( "jQuery.ajax() - cross-domain detection", 8, function( assert ) { function request( url, title, crossDomainOrOptions ) { @@ -377,12 +378,12 @@ QUnit.module( "ajax", { "Cross-domain url with leading space is detected as cross-domain" ) ]; - }); + } ); ajaxTest( "jQuery.ajax() - abort", 9, function( assert ) { return { - setup: addGlobalEvents("ajaxStart ajaxStop ajaxSend ajaxError ajaxComplete", assert ), - url: url("data/name.php?wait=5"), + setup: addGlobalEvents( "ajaxStart ajaxStop ajaxSend ajaxError ajaxComplete", assert ), + url: url( "data/name.php?wait=5" ), beforeSend: function() { assert.ok( true, "beforeSend" ); }, @@ -396,10 +397,10 @@ QUnit.module( "ajax", { assert.ok( true, "complete" ); } }; - }); + } ); ajaxTest( "jQuery.ajax() - events with context", 12, function( assert ) { - var context = document.createElement("div"); + var context = document.createElement( "div" ); function event( e ) { assert.equal( this, context, e.type ); @@ -413,27 +414,27 @@ QUnit.module( "ajax", { return { setup: function() { - jQuery( context ).appendTo("#foo") + jQuery( context ).appendTo( "#foo" ) .ajaxSend( event ) .ajaxComplete( event ) .ajaxError( event ) .ajaxSuccess( event ); }, - requests: [{ - url: url("data/name.html"), + requests: [ { + url: url( "data/name.html" ), context: context, - beforeSend: callback("beforeSend"), - success: callback("success"), - complete: callback("complete") + beforeSend: callback( "beforeSend" ), + success: callback( "success" ), + complete: callback( "complete" ) }, { - url: url("data/404.html"), + url: url( "data/404.html" ), context: context, - beforeSend: callback("beforeSend"), - error: callback("error"), - complete: callback("complete") - }] + beforeSend: callback( "beforeSend" ), + error: callback( "error" ), + complete: callback( "complete" ) + } ] }; - }); + } ); ajaxTest( "jQuery.ajax() - events without context", 3, function( assert ) { function nocallback( msg ) { @@ -442,12 +443,12 @@ QUnit.module( "ajax", { }; } return { - url: url("data/404.html"), - beforeSend: nocallback("beforeSend"), - error: nocallback("error"), - complete: nocallback("complete") + url: url( "data/404.html" ), + beforeSend: nocallback( "beforeSend" ), + error: nocallback( "error" ), + complete: nocallback( "complete" ) }; - }); + } ); ajaxTest( "#15118 - jQuery.ajax() - function without jQuery.event", 1, function( assert ) { var holder; @@ -463,30 +464,30 @@ QUnit.module( "ajax", { }, success: true }; - }); + } ); ajaxTest( "#15160 - jQuery.ajax() - request manually aborted in ajaxSend", 3, function( assert ) { return { setup: function() { jQuery( document ).on( "ajaxSend", function( e, jqXHR ) { jqXHR.abort(); - }); + } ); jQuery( document ).on( "ajaxError ajaxComplete", function( e, jqXHR ) { assert.equal( jqXHR.statusText, "abort", "jqXHR.statusText equals abort on global ajaxComplete and ajaxError events" ); - }); + } ); }, - url: url("data/name.html"), + url: url( "data/name.html" ), error: true, complete: function() { assert.ok( true, "complete" ); } }; - }); + } ); ajaxTest( "jQuery.ajax() - context modification", 1, function( assert ) { return { - url: url("data/name.html"), + url: url( "data/name.html" ), context: {}, beforeSend: function() { this.test = "foo"; @@ -496,37 +497,37 @@ QUnit.module( "ajax", { }, success: true }; - }); + } ); ajaxTest( "jQuery.ajax() - context modification through ajaxSetup", 3, function( assert ) { var obj = {}; return { setup: function() { - jQuery.ajaxSetup({ + jQuery.ajaxSetup( { context: obj - }); + } ); assert.strictEqual( jQuery.ajaxSettings.context, obj, "Make sure the context is properly set in ajaxSettings." ); }, - requests: [{ - url: url("data/name.html"), + requests: [ { + url: url( "data/name.html" ), success: function() { assert.strictEqual( this, obj, "Make sure the original object is maintained." ); } }, { - url: url("data/name.html"), + url: url( "data/name.html" ), context: {}, success: function() { assert.ok( this !== obj, "Make sure overriding context is possible." ); } - }] + } ] }; - }); + } ); ajaxTest( "jQuery.ajax() - disabled globals", 3, function( assert ) { return { setup: addGlobalEvents( "", assert ), global: false, - url: url("data/name.html"), + url: url( "data/name.html" ), beforeSend: function() { assert.ok( true, "beforeSend" ); }, @@ -537,11 +538,11 @@ QUnit.module( "ajax", { assert.ok( true, "complete" ); } }; - }); + } ); ajaxTest( "jQuery.ajax() - xml: non-namespace elements inside namespaced elements", 3, function( assert ) { return { - url: url("data/with_fries.xml"), + url: url( "data/with_fries.xml" ), dataType: "xml", success: function( resp ) { assert.equal( jQuery( "properties", resp ).length, 1, "properties in responseXML" ); @@ -549,11 +550,11 @@ QUnit.module( "ajax", { assert.equal( jQuery( "thing", resp ).length, 2, "things in responseXML" ); } }; - }); + } ); ajaxTest( "jQuery.ajax() - xml: non-namespace elements inside namespaced elements (over JSONP)", 3, function( assert ) { return { - url: url("data/with_fries_over_jsonp.php"), + url: url( "data/with_fries_over_jsonp.php" ), dataType: "jsonp xml", success: function( resp ) { assert.equal( jQuery( "properties", resp ).length, 1, "properties in responseXML" ); @@ -561,19 +562,19 @@ QUnit.module( "ajax", { assert.equal( jQuery( "thing", resp ).length, 2, "things in responseXML" ); } }; - }); + } ); ajaxTest( "jQuery.ajax() - HEAD requests", 2, function( assert ) { return [ { - url: url("data/name.html"), + url: url( "data/name.html" ), type: "HEAD", success: function( data, status, xhr ) { assert.ok( /Date/i.test( xhr.getAllResponseHeaders() ), "No Date in HEAD response" ); } }, { - url: url("data/name.html"), + url: url( "data/name.html" ), data: { "whip_it": "good" }, @@ -583,11 +584,11 @@ QUnit.module( "ajax", { } } ]; - }); + } ); ajaxTest( "jQuery.ajax() - beforeSend", 1, function( assert ) { return { - url: url("data/name.html"), + url: url( "data/name.html" ), beforeSend: function() { this.check = true; }, @@ -595,13 +596,13 @@ QUnit.module( "ajax", { assert.ok( this.check, "check beforeSend was executed" ); } }; - }); + } ); ajaxTest( "jQuery.ajax() - beforeSend, cancel request manually", 2, function( assert ) { return { create: function() { - return jQuery.ajax({ - url: url("data/name.html"), + return jQuery.ajax( { + url: url( "data/name.html" ), beforeSend: function( xhr ) { assert.ok( true, "beforeSend got called, canceling" ); xhr.abort(); @@ -615,34 +616,34 @@ QUnit.module( "ajax", { error: function() { assert.ok( false, "request didn't get canceled" ); } - }); + } ); }, fail: function( _, reason ) { assert.strictEqual( reason, "canceled", "canceled request must fail with 'canceled' status text" ); } }; - }); + } ); ajaxTest( "jQuery.ajax() - dataType html", 5, function( assert ) { return { setup: function() { - Globals.register("testFoo"); - Globals.register("testBar"); + Globals.register( "testFoo" ); + Globals.register( "testBar" ); }, dataType: "html", - url: url("data/test.html"), + url: url( "data/test.html" ), success: function( data ) { assert.ok( data.match( /^html text/ ), "Check content for datatype html" ); - jQuery("#ap").html( data ); - assert.strictEqual( window["testFoo"], "foo", "Check if script was evaluated for datatype html" ); - assert.strictEqual( window["testBar"], "bar", "Check if script src was evaluated for datatype html" ); + jQuery( "#ap" ).html( data ); + assert.strictEqual( window[ "testFoo" ], "foo", "Check if script was evaluated for datatype html" ); + assert.strictEqual( window[ "testBar" ], "bar", "Check if script src was evaluated for datatype html" ); } }; - }); + } ); ajaxTest( "jQuery.ajax() - synchronous request", 1, function( assert ) { return { - url: url("data/json_obj.js"), + url: url( "data/json_obj.js" ), dataType: "text", async: false, success: true, @@ -650,24 +651,24 @@ QUnit.module( "ajax", { assert.ok( /^\{ "data"/.test( xhr.responseText ), "check returned text" ); } }; - }); + } ); ajaxTest( "jQuery.ajax() - synchronous request with callbacks", 2, function( assert ) { return { - url: url("data/json_obj.js"), + url: url( "data/json_obj.js" ), async: false, dataType: "text", success: true, afterSend: function( xhr ) { var result; - xhr.done(function( data ) { + xhr.done( function( data ) { assert.ok( true, "success callback executed" ); result = data; - }); + } ); assert.ok( /^\{ "data"/.test( result ), "check returned text" ); } }; - }); + } ); QUnit.asyncTest( "jQuery.ajax(), jQuery.get[Script|JSON](), jQuery.post(), pass-through request object", 8, function( assert ) { var target = "data/name.html", @@ -680,24 +681,24 @@ QUnit.module( "ajax", { jQuery( document ).on( "ajaxError.passthru", function( e, xml ) { errorCount++; errorEx += ": " + xml.status; - }); + } ); jQuery( document ).one( "ajaxStop", function() { assert.equal( successCount, 5, "Check all ajax calls successful" ); assert.equal( errorCount, 0, "Check no ajax errors (status" + errorEx + ")" ); - jQuery( document ).off("ajaxError.passthru"); + jQuery( document ).off( "ajaxError.passthru" ); QUnit.start(); - }); - Globals.register("testBar"); - - assert.ok( jQuery.get( url(target), success ), "get" ); - assert.ok( jQuery.post( url(target), success ), "post" ); - assert.ok( jQuery.getScript( url("data/testbar.php"), success ), "script" ); - assert.ok( jQuery.getJSON( url("data/json_obj.js"), success ), "json" ); - assert.ok( jQuery.ajax({ + } ); + Globals.register( "testBar" ); + + assert.ok( jQuery.get( url( target ), success ), "get" ); + assert.ok( jQuery.post( url( target ), success ), "post" ); + assert.ok( jQuery.getScript( url( "data/testbar.php" ), success ), "script" ); + assert.ok( jQuery.getJSON( url( "data/json_obj.js" ), success ), "json" ); + assert.ok( jQuery.ajax( { url: url( target ), success: success - }), "generic" ); - }); + } ), "generic" ); + } ); ajaxTest( "jQuery.ajax() - cache", 12, function( assert ) { var re = /_=(.*?)(&|$)/g; @@ -708,7 +709,7 @@ QUnit.module( "ajax", { cache: false, beforeSend: function() { var parameter, tmp; - while(( tmp = re.exec( this.url ) )) { + while ( ( tmp = re.exec( this.url ) ) ) { assert.strictEqual( parameter, undefined, title + ": only one 'no-cache' parameter" ); parameter = tmp[ 1 ]; assert.notStrictEqual( parameter, "tobereplaced555", title + ": parameter (if it was there) was replaced" ); @@ -745,7 +746,7 @@ QUnit.module( "ajax", { "2 parameters surrounding _=" ) ]; - }); + } ); jQuery.each( [ " - Same Domain", " - Cross Domain" ], function( crossDomain, label ) { @@ -784,25 +785,25 @@ QUnit.module( "ajax", { } } ]; - }); + } ); ajaxTest( "jQuery.ajax() - JSONP - Explicit callback param" + label, 10, function( assert ) { return { setup: function() { - Globals.register("functionToCleanUp"); - Globals.register("XXX"); - Globals.register("jsonpResults"); - window["jsonpResults"] = function( data ) { - assert.ok( data["data"], "JSON results returned (GET, custom callback function)" ); + Globals.register( "functionToCleanUp" ); + Globals.register( "XXX" ); + Globals.register( "jsonpResults" ); + window[ "jsonpResults" ] = function( data ) { + assert.ok( data[ "data" ], "JSON results returned (GET, custom callback function)" ); }; }, - requests: [{ + requests: [ { url: "data/jsonp.php", dataType: "jsonp", crossDomain: crossDomain, jsonp: "callback", success: function( data ) { - assert.ok( data["data"], "JSON results returned (GET, data obj callback)" ); + assert.ok( data[ "data" ], "JSON results returned (GET, data obj callback)" ); } }, { url: "data/jsonp.php", @@ -823,10 +824,10 @@ QUnit.module( "ajax", { crossDomain: crossDomain, jsonpCallback: "functionToCleanUp", success: function( data ) { - assert.ok( data["data"], "JSON results returned (GET, custom callback name to be cleaned up)" ); - assert.strictEqual( window["functionToCleanUp"], true, "Callback was removed (GET, custom callback name to be cleaned up)" ); + assert.ok( data[ "data" ], "JSON results returned (GET, custom callback name to be cleaned up)" ); + assert.strictEqual( window[ "functionToCleanUp" ], true, "Callback was removed (GET, custom callback name to be cleaned up)" ); var xhr; - jQuery.ajax({ + jQuery.ajax( { url: "data/jsonp.php", dataType: "jsonp", crossDomain: crossDomain, @@ -835,11 +836,11 @@ QUnit.module( "ajax", { xhr = jqXHR; return false; } - }); - xhr.fail(function() { + } ); + xhr.fail( function() { assert.ok( true, "Ajax error JSON (GET, custom callback name to be cleaned up)" ); - assert.strictEqual( window["functionToCleanUp"], true, "Callback was removed after early abort (GET, custom callback name to be cleaned up)" ); - }); + assert.strictEqual( window[ "functionToCleanUp" ], true, "Callback was removed after early abort (GET, custom callback name to be cleaned up)" ); + } ); } }, { url: "data/jsonp.php?callback=XXX", @@ -851,11 +852,11 @@ QUnit.module( "ajax", { assert.ok( /^data\/jsonp.php\?callback=XXX&_=\d+$/.test( this.url ), "The URL wasn't messed with (GET, custom callback name with no url manipulation)" ); }, success: function( data ) { - assert.ok( data["data"], "JSON results returned (GET, custom callback name with no url manipulation)" ); + assert.ok( data[ "data" ], "JSON results returned (GET, custom callback name with no url manipulation)" ); } - }] + } ] }; - }); + } ); ajaxTest( "jQuery.ajax() - JSONP - Callback in data" + label, 2, function( assert ) { return [ @@ -878,8 +879,7 @@ QUnit.module( "ajax", { } } ]; - }); - + } ); ajaxTest( "jQuery.ajax() - JSONP - POST" + label, 3, function( assert ) { return [ @@ -889,7 +889,7 @@ QUnit.module( "ajax", { dataType: "jsonp", crossDomain: crossDomain, success: function( data ) { - assert.ok( data["data"], "JSON results returned (POST, no callback)" ); + assert.ok( data[ "data" ], "JSON results returned (POST, no callback)" ); } }, { @@ -899,7 +899,7 @@ QUnit.module( "ajax", { dataType: "jsonp", crossDomain: crossDomain, success: function( data ) { - assert.ok( data["data"], "JSON results returned (POST, data callback)" ); + assert.ok( data[ "data" ], "JSON results returned (POST, data callback)" ); } }, { @@ -909,11 +909,11 @@ QUnit.module( "ajax", { dataType: "jsonp", crossDomain: crossDomain, success: function( data ) { - assert.ok( data["data"], "JSON results returned (POST, data obj callback)" ); + assert.ok( data[ "data" ], "JSON results returned (POST, data obj callback)" ); } } ]; - }); + } ); ajaxTest( "jQuery.ajax() - JSONP" + label, 3, function( assert ) { return [ @@ -928,14 +928,14 @@ QUnit.module( "ajax", { { create: function( options ) { var request = jQuery.ajax( options ), - promise = request.then(function( data ) { + promise = request.then( function( data ) { assert.ok( data.data, "first request: JSON results returned (GET, no callback)" ); - request = jQuery.ajax( this ).done(function( data ) { + request = jQuery.ajax( this ).done( function( data ) { assert.ok( data.data, "this re-used: JSON results returned (GET, no callback)" ); - }); + } ); promise.abort = request.abort; return request; - }); + } ); promise.abort = request.abort; return promise; }, @@ -945,50 +945,50 @@ QUnit.module( "ajax", { success: true } ]; - }); + } ); - }); + } ); ajaxTest( "jQuery.ajax() - script, Remote", 2, function( assert ) { return { setup: function() { - Globals.register("testBar"); + Globals.register( "testBar" ); }, url: window.location.href.replace( /[^\/]*$/, "" ) + "data/testbar.php", dataType: "script", success: function() { - assert.strictEqual( window["testBar"], "bar", "Script results returned (GET, no callback)" ); + assert.strictEqual( window[ "testBar" ], "bar", "Script results returned (GET, no callback)" ); } }; - }); + } ); ajaxTest( "jQuery.ajax() - script, Remote with POST", 3, function( assert ) { return { setup: function() { - Globals.register("testBar"); + Globals.register( "testBar" ); }, url: window.location.href.replace( /[^\/]*$/, "" ) + "data/testbar.php", type: "POST", dataType: "script", success: function( data, status ) { - assert.strictEqual( window["testBar"], "bar", "Script results returned (POST, no callback)" ); + assert.strictEqual( window[ "testBar" ], "bar", "Script results returned (POST, no callback)" ); assert.strictEqual( status, "success", "Script results returned (POST, no callback)" ); } }; - }); + } ); ajaxTest( "jQuery.ajax() - script, Remote with scheme-less URL", 2, function( assert ) { return { setup: function() { - Globals.register("testBar"); + Globals.register( "testBar" ); }, url: window.location.href.replace( /[^\/]*$/, "" ).replace( /^.*?\/\//, "//" ) + "data/testbar.php", dataType: "script", success: function() { - assert.strictEqual( window["testBar"], "bar", "Script results returned (GET, no callback)" ); + assert.strictEqual( window[ "testBar" ], "bar", "Script results returned (GET, no callback)" ); } }; - }); + } ); ajaxTest( "jQuery.ajax() - malformed JSON", 2, function( assert ) { return { @@ -999,7 +999,7 @@ QUnit.module( "ajax", { assert.ok( /(invalid|error|exception)/i.test( detailedMsg ), "Detailed parsererror message provided" ); } }; - }); + } ); ajaxTest( "jQuery.ajax() - script by content-type", 2, function() { return [ @@ -1018,7 +1018,7 @@ QUnit.module( "ajax", { success: true } ]; - }); + } ); ajaxTest( "jQuery.ajax() - JSON by content-type", 5, function( assert ) { return { @@ -1029,17 +1029,17 @@ QUnit.module( "ajax", { }, success: function( json ) { assert.ok( json.length >= 2, "Check length" ); - assert.strictEqual( json[ 0 ]["name"], "John", "Check JSON: first, name" ); - assert.strictEqual( json[ 0 ]["age"], 21, "Check JSON: first, age" ); - assert.strictEqual( json[ 1 ]["name"], "Peter", "Check JSON: second, name" ); - assert.strictEqual( json[ 1 ]["age"], 25, "Check JSON: second, age" ); + assert.strictEqual( json[ 0 ][ "name" ], "John", "Check JSON: first, name" ); + assert.strictEqual( json[ 0 ][ "age" ], 21, "Check JSON: first, age" ); + assert.strictEqual( json[ 1 ][ "name" ], "Peter", "Check JSON: second, name" ); + assert.strictEqual( json[ 1 ][ "age" ], 25, "Check JSON: second, age" ); } }; - }); + } ); ajaxTest( "jQuery.ajax() - JSON by content-type disabled with options", 6, function( assert ) { return { - url: url("data/json.php"), + url: url( "data/json.php" ), data: { "header": "json", "json": "array" @@ -1050,35 +1050,35 @@ QUnit.module( "ajax", { success: function( text ) { assert.strictEqual( typeof text, "string", "json wasn't auto-determined" ); var json = jQuery.parseJSON( text ); - assert.ok( json.length >= 2, "Check length"); - assert.strictEqual( json[ 0 ]["name"], "John", "Check JSON: first, name" ); - assert.strictEqual( json[ 0 ]["age"], 21, "Check JSON: first, age" ); - assert.strictEqual( json[ 1 ]["name"], "Peter", "Check JSON: second, name" ); - assert.strictEqual( json[ 1 ]["age"], 25, "Check JSON: second, age" ); + assert.ok( json.length >= 2, "Check length" ); + assert.strictEqual( json[ 0 ][ "name" ], "John", "Check JSON: first, name" ); + assert.strictEqual( json[ 0 ][ "age" ], 21, "Check JSON: first, age" ); + assert.strictEqual( json[ 1 ][ "name" ], "Peter", "Check JSON: second, name" ); + assert.strictEqual( json[ 1 ][ "age" ], 25, "Check JSON: second, age" ); } }; - }); + } ); ajaxTest( "jQuery.ajax() - simple get", 1, function( assert ) { return { type: "GET", - url: url("data/name.php?name=foo"), + url: url( "data/name.php?name=foo" ), success: function( msg ) { assert.strictEqual( msg, "bar", "Check for GET" ); } }; - }); + } ); ajaxTest( "jQuery.ajax() - simple post", 1, function( assert ) { return { type: "POST", - url: url("data/name.php"), + url: url( "data/name.php" ), data: "name=peter", success: function( msg ) { assert.strictEqual( msg, "pan", "Check for POST" ); } }; - }); + } ); ajaxTest( "jQuery.ajax() - data option - empty bodies for non-GET requests", 1, function( assert ) { return { @@ -1089,7 +1089,7 @@ QUnit.module( "ajax", { assert.strictEqual( result, "" ); } }; - }); + } ); var ifModifiedNow = new Date(); @@ -1108,13 +1108,13 @@ QUnit.module( "ajax", { function( type, url ) { url = "data/" + url + "?ts=" + ifModifiedNow++; QUnit.asyncTest( "jQuery.ajax() - " + type + " support" + label, 4, function( assert ) { - jQuery.ajax({ + jQuery.ajax( { url: url, ifModified: true, cache: cache, success: function( _, status ) { assert.strictEqual( status, "success", "Initial status is 'success'" ); - jQuery.ajax({ + jQuery.ajax( { url: url, ifModified: true, cache: cache, @@ -1126,10 +1126,10 @@ QUnit.module( "ajax", { complete: function() { QUnit.start(); } - }); + } ); } - }); - }); + } ); + } ); } ); } @@ -1138,13 +1138,14 @@ 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 ) { assert.ok( true, "file not found: " + xhr.status + " => " + e ); } }; - }); + } ); ajaxTest( "jQuery.ajax() - failing cross-domain", 1, function( assert ) { return { @@ -1153,34 +1154,34 @@ QUnit.module( "ajax", { assert.ok( true, "access denied: " + xhr.status + " => " + e ); } }; - }); + } ); ajaxTest( "jQuery.ajax() - atom+xml", 1, function( assert ) { return { - url: url("data/atom+xml.php"), + url: url( "data/atom+xml.php" ), success: function() { assert.ok( true, "success" ); } }; - }); + } ); QUnit.asyncTest( "jQuery.ajax() - statusText", 3, function( assert ) { - jQuery.ajax( url("data/statusText.php?status=200&text=Hello") ).done(function( _, statusText, jqXHR ) { + jQuery.ajax( url( "data/statusText.php?status=200&text=Hello" ) ).done( function( _, statusText, jqXHR ) { assert.strictEqual( statusText, "success", "callback status text ok for success" ); assert.ok( jqXHR.statusText === "Hello" || jqXHR.statusText === "OK", "jqXHR status text ok for success (" + jqXHR.statusText + ")" ); - jQuery.ajax( url("data/statusText.php?status=404&text=World") ).fail(function( jqXHR, statusText ) { + jQuery.ajax( url( "data/statusText.php?status=404&text=World" ) ).fail( function( jqXHR, statusText ) { assert.strictEqual( statusText, "error", "callback status text ok for error" ); QUnit.start(); - }); - }); - }); + } ); + } ); + } ); QUnit.asyncTest( "jQuery.ajax() - statusCode", 20, function( assert ) { var count = 12; function countComplete() { - if ( ! --count ) { + if ( !--count ) { QUnit.start(); } } @@ -1205,45 +1206,45 @@ QUnit.module( "ajax", { }, function( uri, isSuccess ) { - jQuery.ajax( url(uri), { + jQuery.ajax( url( uri ), { statusCode: createStatusCodes( "in options", isSuccess ), complete: countComplete - }); + } ); - jQuery.ajax( url(uri), { + jQuery.ajax( url( uri ), { complete: countComplete - }).statusCode( createStatusCodes("immediately with method", isSuccess) ); + } ).statusCode( createStatusCodes( "immediately with method", isSuccess ) ); - jQuery.ajax( url(uri), { + jQuery.ajax( url( uri ), { complete: function( jqXHR ) { - jqXHR.statusCode( createStatusCodes("on complete", isSuccess) ); + jqXHR.statusCode( createStatusCodes( "on complete", isSuccess ) ); countComplete(); } - }); + } ); - jQuery.ajax( url(uri), { + jQuery.ajax( url( uri ), { complete: function( jqXHR ) { - setTimeout(function() { - jqXHR.statusCode( createStatusCodes("very late binding", isSuccess) ); + setTimeout( function() { + jqXHR.statusCode( createStatusCodes( "very late binding", isSuccess ) ); countComplete(); }, 100 ); } - }); + } ); - jQuery.ajax( url(uri), { + jQuery.ajax( url( uri ), { statusCode: createStatusCodes( "all (options)", isSuccess ), complete: function( jqXHR ) { - jqXHR.statusCode( createStatusCodes("all (on complete)", isSuccess) ); - setTimeout(function() { - jqXHR.statusCode( createStatusCodes("all (very late binding)", isSuccess) ); + jqXHR.statusCode( createStatusCodes( "all (on complete)", isSuccess ) ); + setTimeout( function() { + jqXHR.statusCode( createStatusCodes( "all (very late binding)", isSuccess ) ); countComplete(); }, 100 ); } - }).statusCode( createStatusCodes("all (immediately with method)", isSuccess) ); + } ).statusCode( createStatusCodes( "all (immediately with method)", isSuccess ) ); var testString = ""; - jQuery.ajax( url(uri), { + jQuery.ajax( url( uri ), { success: function( a, b, jqXHR ) { assert.ok( isSuccess, "success" ); var statusCode = {}; @@ -1270,17 +1271,17 @@ QUnit.module( "ajax", { ); countComplete(); } - }); + } ); } /* jQuery.each arguments end*/ ); - }); + } ); ajaxTest( "jQuery.ajax() - transitive conversions", 8, function( assert ) { return [ { - url: url("data/json.php"), + url: url( "data/json.php" ), converters: { "json myJson": function( data ) { assert.ok( true, "converter called" ); @@ -1295,7 +1296,7 @@ QUnit.module( "ajax", { } }, { - url: url("data/json.php"), + url: url( "data/json.php" ), converters: { "json myJson": function( data ) { assert.ok( true, "converter called (*)" ); @@ -1311,12 +1312,12 @@ QUnit.module( "ajax", { } } ]; - }); + } ); ajaxTest( "jQuery.ajax() - overrideMimeType", 2, function( assert ) { return [ { - url: url("data/json.php"), + url: url( "data/json.php" ), beforeSend: function( xhr ) { xhr.overrideMimeType( "application/json" ); }, @@ -1325,30 +1326,30 @@ QUnit.module( "ajax", { } }, { - url: url("data/json.php"), + url: url( "data/json.php" ), mimeType: "application/json", success: function( json ) { assert.ok( json.data, "Mimetype overridden using mimeType option" ); } } ]; - }); + } ); ajaxTest( "jQuery.ajax() - empty json gets to error callback instead of success callback.", 1, function( assert ) { return { - url: url("data/echoData.php"), + url: url( "data/echoData.php" ), error: function( _, __, error ) { assert.equal( typeof error === "object", true, "Didn't get back error object for empty json response" ); }, dataType: "json" }; - }); + } ); ajaxTest( "#2688 - jQuery.ajax() - beforeSend, cancel request", 2, function( assert ) { return { create: function() { - return jQuery.ajax({ - url: url("data/name.html"), + return jQuery.ajax( { + url: url( "data/name.html" ), beforeSend: function() { assert.ok( true, "beforeSend got called, canceling" ); return false; @@ -1362,13 +1363,13 @@ QUnit.module( "ajax", { error: function() { assert.ok( false, "request didn't get canceled" ); } - }); + } ); }, fail: function( _, reason ) { assert.strictEqual( reason, "canceled", "canceled request must fail with 'canceled' status text" ); } }; - }); + } ); ajaxTest( "#2806 - jQuery.ajax() - data option - evaluate function values", 1, function( assert ) { return { @@ -1382,7 +1383,7 @@ QUnit.module( "ajax", { assert.strictEqual( result, "key=value" ); } }; - }); + } ); QUnit.test( "#7531 - jQuery.ajax() - Location object as url", function( assert ) { assert.expect( 1 ); @@ -1390,16 +1391,16 @@ QUnit.module( "ajax", { var xhr, success = false; try { - xhr = jQuery.ajax({ + xhr = jQuery.ajax( { url: window.location - }); + } ); success = true; xhr.abort(); - } catch (e) { + } catch ( e ) { } assert.ok( success, "document.location did not generate exception" ); - }); + } ); jQuery.each( [ " - Same Domain", " - Cross Domain" ], function( crossDomain, label ) { ajaxTest( "#7578 - jQuery.ajax() - JSONP - default for cache option" + label, 1, function( assert ) { @@ -1413,8 +1414,8 @@ QUnit.module( "ajax", { }, error: true }; - }); - }); + } ); + } ); ajaxTest( "#8107 - jQuery.ajax() - multiple method signatures introduced in 1.5", 4, function( assert ) { return [ @@ -1428,7 +1429,7 @@ QUnit.module( "ajax", { }, { create: function() { - return jQuery.ajax("data/name.html"); + return jQuery.ajax( "data/name.html" ); }, done: function() { assert.ok( true, "With only string URL argument" ); @@ -1436,7 +1437,7 @@ QUnit.module( "ajax", { }, { create: function() { - return jQuery.ajax( "data/name.html", {}); + return jQuery.ajax( "data/name.html", {} ); }, done: function() { assert.ok( true, "With string URL param and map" ); @@ -1452,7 +1453,7 @@ QUnit.module( "ajax", { } } ]; - }); + } ); jQuery.each( [ " - Same Domain", " - Cross Domain" ], function( crossDomain, label ) { ajaxTest( "#8205 - jQuery.ajax() - JSONP - re-use callbacks name" + label, 4, function( assert ) { @@ -1479,7 +1480,7 @@ QUnit.module( "ajax", { "JSONP callback name was removed from the window" ); - jQuery.ajax({ + jQuery.ajax( { url: "data/jsonp.php", dataType: "jsonp", crossDomain: crossDomain, @@ -1487,11 +1488,11 @@ QUnit.module( "ajax", { assert.strictEqual( this.jsonpCallback, previous.callback, "JSONP callback name is re-used" ); return false; } - }); + } ); } }; - }); - }); + } ); + } ); QUnit.test( "#9887 - jQuery.ajax() - Context with circular references (#9887)", function( assert ) { assert.expect( 2 ); @@ -1506,13 +1507,13 @@ QUnit.module( "ajax", { assert.ok( this === context, "context was not deep extended" ); return false; } - }); + } ); success = true; } catch ( e ) { console.log( e ); } assert.ok( success, "context with circular reference did not generate an exception" ); - }); + } ); jQuery.each( [ "as argument", "in settings object" ], function( inSetting, title ) { @@ -1534,12 +1535,12 @@ QUnit.module( "ajax", { request( assert, null ), request( assert, undefined ) ]; - }); - }); + } ); + } ); ajaxTest( "#11151 - jQuery.ajax() - parse error body", 2, function( assert ) { return { - url: url("data/errorWithJSON.php"), + url: url( "data/errorWithJSON.php" ), dataFilter: function( string ) { assert.ok( false, "dataFilter called" ); return string; @@ -1549,18 +1550,19 @@ QUnit.module( "ajax", { assert.deepEqual( jqXHR.responseJSON, { code: 40, message: "Bad Request" }, "Error body properly parsed" ); } }; - }); + } ); ajaxTest( "#11426 - jQuery.ajax() - loading binary data shouldn't throw an exception in IE", 1, function( assert ) { return { - url: url("data/1x1.jpg"), + url: url( "data/1x1.jpg" ), success: function( data ) { assert.ok( data === undefined || /JFIF/.test( data ), "success callback reached" ); } }; - }); + } ); 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 ) ) { @@ -1576,17 +1578,17 @@ QUnit.module( "ajax", { window.onerror = onerror; QUnit.start(); }; - jQuery.ajax({ + jQuery.ajax( { url: "data/badjson.js", dataType: "script", throws: true - }); - }); + } ); + } ); jQuery.each( [ "method", "type" ], function( _, globalOption ) { function request( assert, option ) { var options = { - url: url("data/echoData.php"), + url: url( "data/echoData.php" ), data: "hello", success: function( msg ) { assert.strictEqual( msg, "hello", "Check for POST (no override)" ); @@ -1612,38 +1614,39 @@ QUnit.module( "ajax", { jQuery.ajaxSetup( options ); }, requests: [ - request(assert, "type"), - request(assert, "method"), - request(assert ) + request( assert, "type" ), + request( assert, "method" ), + request( assert ) ] }; } ); - }); + } ); ajaxTest( "#13276 - jQuery.ajax() - compatibility between XML documents from ajax requests and parsed string", 1, function( assert ) { return { url: "data/dashboard.xml", dataType: "xml", success: function( ajaxXML ) { - var parsedXML = jQuery( jQuery.parseXML("<tab title=\"Added\">blibli</tab>") ).find("tab"); + 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 if ( /android 2\.3/i.test( navigator.userAgent ) ) { parsedXML = jQuery( ajaxXML[ 0 ].adoptNode( parsedXML[ 0 ] ) ); } - ajaxXML.find("infowindowtab").append( parsedXML ); - } catch( e ) { + ajaxXML.find( "infowindowtab" ).append( parsedXML ); + } catch ( e ) { assert.strictEqual( e, undefined, "error" ); return; } - assert.strictEqual( ajaxXML.find("tab").length, 3, "Parsed node was added properly" ); + assert.strictEqual( ajaxXML.find( "tab" ).length, 3, "Parsed node was added properly" ); } }; - }); + } ); ajaxTest( "#13292 - jQuery.ajax() - converter is bypassed for 204 requests", 3, function( assert ) { return { @@ -1665,11 +1668,11 @@ QUnit.module( "ajax", { assert.strictEqual( error, "converter was called", "Converter was called" ); } }; - }); + } ); ajaxTest( "#13388 - jQuery.ajax() - responseXML", 3, function( assert ) { return { - url: url("data/with_fries.xml"), + url: url( "data/with_fries.xml" ), dataType: "xml", success: function( resp, _, jqXHR ) { assert.notStrictEqual( resp, undefined, "XML document exists" ); @@ -1677,7 +1680,7 @@ QUnit.module( "ajax", { assert.strictEqual( resp, jqXHR.responseXML, "jqXHR.responseXML is set correctly" ); } }; - }); + } ); ajaxTest( "#13922 - jQuery.ajax() - converter is bypassed for HEAD requests", 3, function( assert ) { return { @@ -1702,7 +1705,7 @@ QUnit.module( "ajax", { assert.strictEqual( error, "converter was called", "Converter was called" ); } }; - }); + } ); testIframeWithCallback( "#14379 - jQuery.ajax() on unload", @@ -1714,7 +1717,7 @@ QUnit.module( "ajax", { ); ajaxTest( "#14683 - jQuery.ajax() - Exceptions thrown synchronously by xhr.send should be caught", 4, function( assert ) { - return [{ + return [ { url: "data/params_html.php", method: "POST", data: { @@ -1739,7 +1742,7 @@ QUnit.module( "ajax", { fail: function( _, status, error ) { assert.ok( true, "fail: " + status + " - " + error ); } - }]; + } ]; } ); @@ -1749,12 +1752,13 @@ QUnit.module( "ajax", { return { dataType: "prefix", setup: function() { + // Ensure prefix does not throw an error - jQuery.ajaxPrefilter("+prefix", function( options, _, jqXHR ) { + jQuery.ajaxPrefilter( "+prefix", function( options, _, jqXHR ) { if ( options.abortInPrefilter ) { jqXHR.abort(); } - }); + } ); }, abortInPrefilter: true, error: function() { @@ -1764,27 +1768,27 @@ QUnit.module( "ajax", { assert.strictEqual( reason, "canceled", "Request aborted by the prefilter must fail with 'canceled' status text" ); } }; - }); + } ); //----------- jQuery.ajaxSetup() QUnit.asyncTest( "jQuery.ajaxSetup()", 1, function( assert ) { - jQuery.ajaxSetup({ - url: url("data/name.php?name=foo"), + jQuery.ajaxSetup( { + url: url( "data/name.php?name=foo" ), success: function( msg ) { assert.strictEqual( msg, "bar", "Check for GET" ); QUnit.start(); } - }); + } ); jQuery.ajax(); - }); + } ); QUnit.asyncTest( "jQuery.ajaxSetup({ timeout: Number }) - with global timeout", 2, function( assert ) { var passed = 0, pass = function() { assert.ok( passed++ < 2, "Error callback executed" ); if ( passed === 2 ) { - jQuery( document ).off("ajaxError.setupTest"); + jQuery( document ).off( "ajaxError.setupTest" ); QUnit.start(); } }, @@ -1795,26 +1799,26 @@ QUnit.module( "ajax", { jQuery( document ).on( "ajaxError.setupTest", pass ); - jQuery.ajaxSetup({ + jQuery.ajaxSetup( { timeout: 1000 - }); + } ); - jQuery.ajax({ + jQuery.ajax( { type: "GET", - url: url("data/name.php?wait=5"), + url: url( "data/name.php?wait=5" ), error: pass, success: fail - }); - }); + } ); + } ); QUnit.asyncTest( "jQuery.ajaxSetup({ timeout: Number }) with localtimeout", 1, function( assert ) { - jQuery.ajaxSetup({ + jQuery.ajaxSetup( { timeout: 50 - }); - jQuery.ajax({ + } ); + jQuery.ajax( { type: "GET", timeout: 15000, - url: url("data/name.php?wait=1"), + url: url( "data/name.php?wait=1" ), error: function() { assert.ok( false, "Check for local timeout failed" ); QUnit.start(); @@ -1823,137 +1827,137 @@ QUnit.module( "ajax", { assert.ok( true, "Check for local timeout" ); QUnit.start(); } - }); - }); + } ); + } ); //----------- jQuery.domManip() QUnit.test( "#11264 - jQuery.domManip() - no side effect because of ajaxSetup or global events", function( assert ) { assert.expect( 1 ); - jQuery.ajaxSetup({ + jQuery.ajaxSetup( { type: "POST" - }); + } ); jQuery( document ).on( "ajaxStart ajaxStop", function() { assert.ok( false, "Global event triggered" ); - }); + } ); - jQuery("#qunit-fixture").append("<script src='data/ajax/evalScript.php'></script>"); + jQuery( "#qunit-fixture" ).append( "<script src='data/ajax/evalScript.php'></script>" ); - jQuery( document ).off("ajaxStart ajaxStop"); - }); + jQuery( document ).off( "ajaxStart ajaxStop" ); + } ); QUnit.asyncTest( "jQuery#load() - always use GET method even if it overrided through ajaxSetup (#11264)", 1, function( assert ) { - jQuery.ajaxSetup({ + jQuery.ajaxSetup( { type: "POST" - }); + } ); jQuery( "#qunit-fixture" ).load( "data/ajax/method.php", function( method ) { assert.equal( method, "GET" ); QUnit.start(); - }); - }); + } ); + } ); QUnit.asyncTest( "#11402 - jQuery.domManip() - script in comments are properly evaluated", 2, function() { - jQuery("#qunit-fixture").load( "data/cleanScript.html", start ); - }); + jQuery( "#qunit-fixture" ).load( "data/cleanScript.html", start ); + } ); //----------- jQuery.get() QUnit.asyncTest( "jQuery.get( String, Hash, Function ) - parse xml and use text() on nodes", 2, function( assert ) { - jQuery.get( url("data/dashboard.xml"), function( xml ) { + jQuery.get( url( "data/dashboard.xml" ), function( xml ) { var content = []; - jQuery( "tab", xml ).each(function() { + jQuery( "tab", xml ).each( function() { content.push( jQuery( this ).text() ); - }); + } ); assert.strictEqual( content[ 0 ], "blabla", "Check first tab" ); assert.strictEqual( content[ 1 ], "blublu", "Check second tab" ); QUnit.start(); - }); - }); + } ); + } ); QUnit.asyncTest( "#8277 - jQuery.get( String, Function ) - data in ajaxSettings", 1, function( assert ) { - jQuery.ajaxSetup({ + jQuery.ajaxSetup( { data: "helloworld" - }); - jQuery.get( url("data/echoQuery.php"), function( data ) { + } ); + jQuery.get( url( "data/echoQuery.php" ), function( data ) { assert.ok( /helloworld$/.test( data ), "Data from ajaxSettings was used" ); QUnit.start(); - }); - }); + } ); + } ); //----------- jQuery.getJSON() QUnit.asyncTest( "jQuery.getJSON( String, Hash, Function ) - JSON array", 5, function( assert ) { jQuery.getJSON( - url("data/json.php"), + url( "data/json.php" ), { "json": "array" }, function( json ) { assert.ok( json.length >= 2, "Check length" ); - assert.strictEqual( json[ 0 ]["name"], "John", "Check JSON: first, name" ); - assert.strictEqual( json[ 0 ]["age"], 21, "Check JSON: first, age" ); - assert.strictEqual( json[ 1 ]["name"], "Peter", "Check JSON: second, name" ); - assert.strictEqual( json[ 1 ]["age"], 25, "Check JSON: second, age" ); + assert.strictEqual( json[ 0 ][ "name" ], "John", "Check JSON: first, name" ); + assert.strictEqual( json[ 0 ][ "age" ], 21, "Check JSON: first, age" ); + assert.strictEqual( json[ 1 ][ "name" ], "Peter", "Check JSON: second, name" ); + assert.strictEqual( json[ 1 ][ "age" ], 25, "Check JSON: second, age" ); QUnit.start(); } ); - }); + } ); QUnit.asyncTest( "jQuery.getJSON( String, Function ) - JSON object", 2, function( assert ) { - jQuery.getJSON( url("data/json.php"), function( json ) { - if ( json && json["data"] ) { - assert.strictEqual( json["data"]["lang"], "en", "Check JSON: lang" ); - assert.strictEqual( json["data"].length, 25, "Check JSON: length" ); + jQuery.getJSON( url( "data/json.php" ), function( json ) { + if ( json && json[ "data" ] ) { + assert.strictEqual( json[ "data" ][ "lang" ], "en", "Check JSON: lang" ); + assert.strictEqual( json[ "data" ].length, 25, "Check JSON: length" ); QUnit.start(); } - }); - }); + } ); + } ); QUnit.asyncTest( "jQuery.getJSON( String, Function ) - JSON object with absolute url to local content", 2, function( assert ) { jQuery.getJSON( url( window.location.href.replace( /[^\/]*$/, "" ) + "data/json.php" ), function( json ) { assert.strictEqual( json.data.lang, "en", "Check JSON: lang" ); assert.strictEqual( json.data.length, 25, "Check JSON: length" ); QUnit.start(); - }); - }); + } ); + } ); //----------- jQuery.getScript() QUnit.asyncTest( "jQuery.getScript( String, Function ) - with callback", 2, function( assert ) { - Globals.register("testBar"); - jQuery.getScript( url("data/testbar.php"), function() { - assert.strictEqual( window["testBar"], "bar", "Check if script was evaluated" ); + Globals.register( "testBar" ); + jQuery.getScript( url( "data/testbar.php" ), function() { + assert.strictEqual( window[ "testBar" ], "bar", "Check if script was evaluated" ); QUnit.start(); - }); - }); + } ); + } ); QUnit.asyncTest( "jQuery.getScript( String, Function ) - no callback", 1, function() { - Globals.register("testBar"); - jQuery.getScript( url("data/testbar.php") ).done( start ); - }); + Globals.register( "testBar" ); + jQuery.getScript( url( "data/testbar.php" ) ).done( start ); + } ); QUnit.asyncTest( "#8082 - jQuery.getScript( String, Function ) - source as responseText", 2, function( assert ) { - Globals.register("testBar"); - jQuery.getScript( url("data/testbar.php"), function( data, _, jqXHR ) { + Globals.register( "testBar" ); + jQuery.getScript( url( "data/testbar.php" ), function( data, _, jqXHR ) { assert.strictEqual( data, jqXHR.responseText, "Same-domain script requests returns the source of the script" ); QUnit.start(); - }); - }); + } ); + } ); // //----------- jQuery.fn.load() // check if load can be called with only url QUnit.asyncTest( "jQuery.fn.load( String )", 2, function( assert ) { - jQuery.ajaxSetup({ + jQuery.ajaxSetup( { beforeSend: function() { assert.strictEqual( this.type, "GET", "no data means GET request" ); } - }); - jQuery("#first").load( "data/name.html", start ); - }); + } ); + jQuery( "#first" ).load( "data/name.html", start ); + } ); QUnit.test( "jQuery.fn.load() - 404 error callbacks", function( assert ) { assert.expect( 6 ); @@ -1961,134 +1965,134 @@ QUnit.module( "ajax", { addGlobalEvents( "ajaxStart ajaxStop ajaxSend ajaxComplete ajaxError", assert )(); jQuery( document ).ajaxStop( done ); - jQuery("<div/>").load( "data/404.html", function() { + jQuery( "<div/>" ).load( "data/404.html", function() { assert.ok( true, "complete" ); - }); - }); + } ); + } ); // check if load can be called with url and null data QUnit.asyncTest( "jQuery.fn.load( String, null )", 2, function( assert ) { - jQuery.ajaxSetup({ + jQuery.ajaxSetup( { beforeSend: function() { assert.strictEqual( this.type, "GET", "no data means GET request" ); } - }); - jQuery("#first").load( "data/name.html", null, start ); - }); + } ); + jQuery( "#first" ).load( "data/name.html", null, start ); + } ); // check if load can be called with url and undefined data QUnit.asyncTest( "jQuery.fn.load( String, undefined )", 2, function( assert ) { - jQuery.ajaxSetup({ + jQuery.ajaxSetup( { beforeSend: function() { assert.strictEqual( this.type, "GET", "no data means GET request" ); } - }); - jQuery("#first").load( "data/name.html", undefined, start ); - }); + } ); + jQuery( "#first" ).load( "data/name.html", undefined, start ); + } ); // check if load can be called with only url QUnit.asyncTest( "jQuery.fn.load( URL_SELECTOR )", 1, function( assert ) { - jQuery("#first").load( "data/test3.html div.user", function() { - assert.strictEqual( jQuery( this ).children("div").length, 2, "Verify that specific elements were injected" ); + jQuery( "#first" ).load( "data/test3.html div.user", function() { + assert.strictEqual( jQuery( this ).children( "div" ).length, 2, "Verify that specific elements were injected" ); QUnit.start(); - }); - }); + } ); + } ); // Selector should be trimmed to avoid leading spaces (#14773) QUnit.asyncTest( "jQuery.fn.load( URL_SELECTOR with spaces )", 1, function( assert ) { - jQuery("#first").load( "data/test3.html #superuser ", function() { - assert.strictEqual( jQuery( this ).children("div").length, 1, "Verify that specific elements were injected" ); + jQuery( "#first" ).load( "data/test3.html #superuser ", function() { + assert.strictEqual( jQuery( this ).children( "div" ).length, 1, "Verify that specific elements were injected" ); QUnit.start(); - }); - }); + } ); + } ); QUnit.asyncTest( "jQuery.fn.load( String, Function ) - simple: inject text into DOM", 2, function( assert ) { - jQuery("#first").load( url("data/name.html"), function() { - assert.ok( /^ERROR/.test(jQuery("#first").text()), "Check if content was injected into the DOM" ); + jQuery( "#first" ).load( url( "data/name.html" ), function() { + assert.ok( /^ERROR/.test( jQuery( "#first" ).text() ), "Check if content was injected into the DOM" ); QUnit.start(); - }); - }); + } ); + } ); QUnit.asyncTest( "jQuery.fn.load( String, Function ) - check scripts", 7, function( assert ) { var verifyEvaluation = function() { - assert.strictEqual( window["testBar"], "bar", "Check if script src was evaluated after load" ); - assert.strictEqual( jQuery("#ap").html(), "bar", "Check if script evaluation has modified DOM"); + assert.strictEqual( window[ "testBar" ], "bar", "Check if script src was evaluated after load" ); + assert.strictEqual( jQuery( "#ap" ).html(), "bar", "Check if script evaluation has modified DOM" ); QUnit.start(); }; - Globals.register("testFoo"); - Globals.register("testBar"); + Globals.register( "testFoo" ); + Globals.register( "testBar" ); - jQuery("#first").load( url("data/test.html"), function() { - assert.ok( jQuery("#first").html().match( /^html text/ ), "Check content after loading html" ); - assert.strictEqual( jQuery("#foo").html(), "foo", "Check if script evaluation has modified DOM" ); - assert.strictEqual( window["testFoo"], "foo", "Check if script was evaluated after load" ); + jQuery( "#first" ).load( url( "data/test.html" ), function() { + assert.ok( jQuery( "#first" ).html().match( /^html text/ ), "Check content after loading html" ); + assert.strictEqual( jQuery( "#foo" ).html(), "foo", "Check if script evaluation has modified DOM" ); + assert.strictEqual( window[ "testFoo" ], "foo", "Check if script was evaluated after load" ); setTimeout( verifyEvaluation, 600 ); - }); - }); + } ); + } ); QUnit.asyncTest( "jQuery.fn.load( String, Function ) - check file with only a script tag", 3, function( assert ) { - Globals.register("testFoo"); + Globals.register( "testFoo" ); - jQuery("#first").load( url("data/test2.html"), function() { - assert.strictEqual( jQuery("#foo").html(), "foo", "Check if script evaluation has modified DOM"); - assert.strictEqual( window["testFoo"], "foo", "Check if script was evaluated after load" ); + jQuery( "#first" ).load( url( "data/test2.html" ), function() { + assert.strictEqual( jQuery( "#foo" ).html(), "foo", "Check if script evaluation has modified DOM" ); + assert.strictEqual( window[ "testFoo" ], "foo", "Check if script was evaluated after load" ); QUnit.start(); - }); - }); + } ); + } ); QUnit.asyncTest( "jQuery.fn.load( String, Function ) - dataFilter in ajaxSettings", 2, function( assert ) { - jQuery.ajaxSetup({ + jQuery.ajaxSetup( { dataFilter: function() { return "Hello World"; } - }); - jQuery("<div/>").load( url("data/name.html"), function( responseText ) { + } ); + jQuery( "<div/>" ).load( url( "data/name.html" ), function( responseText ) { assert.strictEqual( jQuery( this ).html(), "Hello World", "Test div was filled with filtered data" ); assert.strictEqual( responseText, "Hello World", "Test callback receives filtered data" ); QUnit.start(); - }); - }); + } ); + } ); QUnit.asyncTest( "jQuery.fn.load( String, Object, Function )", 2, function( assert ) { - jQuery("<div />").load( url("data/params_html.php"), { + jQuery( "<div />" ).load( url( "data/params_html.php" ), { "foo": 3, "bar": "ok" }, function() { - var $post = jQuery( this ).find("#post"); - assert.strictEqual( $post.find("#foo").text(), "3", "Check if a hash of data is passed correctly" ); - assert.strictEqual( $post.find("#bar").text(), "ok", "Check if a hash of data is passed correctly" ); + var $post = jQuery( this ).find( "#post" ); + assert.strictEqual( $post.find( "#foo" ).text(), "3", "Check if a hash of data is passed correctly" ); + assert.strictEqual( $post.find( "#bar" ).text(), "ok", "Check if a hash of data is passed correctly" ); QUnit.start(); - }); - }); + } ); + } ); QUnit.test( "jQuery.fn.load( String, String, Function )", 2, function( assert ) { var done = assert.async(); - jQuery("<div />").load( url("data/params_html.php"), "foo=3&bar=ok", function() { - var $get = jQuery( this ).find("#get"); - assert.strictEqual( $get.find("#foo").text(), "3", "Check if a string of data is passed correctly" ); - assert.strictEqual( $get.find("#bar").text(), "ok", "Check if a of data is passed correctly" ); + jQuery( "<div />" ).load( url( "data/params_html.php" ), "foo=3&bar=ok", function() { + var $get = jQuery( this ).find( "#get" ); + assert.strictEqual( $get.find( "#foo" ).text(), "3", "Check if a string of data is passed correctly" ); + assert.strictEqual( $get.find( "#bar" ).text(), "ok", "Check if a of data is passed correctly" ); done(); - }); - }); + } ); + } ); QUnit.test( "jQuery.fn.load() - callbacks get the correct parameters", 8, function( assert ) { var completeArgs = {}; var done = assert.async(); - jQuery.ajaxSetup({ + jQuery.ajaxSetup( { success: function( _, status, jqXHR ) { completeArgs[ this.url ] = [ jqXHR.responseText, status, jqXHR ]; }, error: function( jqXHR, status ) { completeArgs[ this.url ] = [ jqXHR.responseText, status, jqXHR ]; } - }); + } ); jQuery.when.apply( jQuery, - jQuery.map([ + jQuery.map( [ { type: "success", url: "data/echoQuery.php?arg=pop" @@ -2099,33 +2103,33 @@ QUnit.module( "ajax", { } ], function( options ) { - return jQuery.Deferred(function( defer ) { - jQuery("#foo").load( options.url, function() { + return jQuery.Deferred( function( defer ) { + jQuery( "#foo" ).load( options.url, function() { var args = arguments; assert.strictEqual( completeArgs[ options.url ].length, args.length, "same number of arguments (" + options.type + ")" ); jQuery.each( completeArgs[ options.url ], function( i, value ) { assert.strictEqual( args[ i ], value, "argument #" + i + " is the same (" + options.type + ")" ); - }); + } ); defer.resolve(); - }); - }); - }) + } ); + } ); + } ) ).always( done ); - }); + } ); QUnit.test( "#2046 - jQuery.fn.load( String, Function ) with ajaxSetup on dataType json", 1, function( assert ) { var done = assert.async(); - jQuery.ajaxSetup({ + jQuery.ajaxSetup( { dataType: "json" - }); - jQuery( document ).ajaxComplete(function( e, xml, s ) { + } ); + jQuery( document ).ajaxComplete( function( e, xml, s ) { assert.strictEqual( s.dataType, "html", "Verify the load() dataType was html" ); - jQuery( document ).off("ajaxComplete"); + jQuery( document ).off( "ajaxComplete" ); done(); - }); - jQuery("#first").load("data/test3.html"); - }); + } ); + jQuery( "#first" ).load( "data/test3.html" ); + } ); QUnit.test( "#10524 - jQuery.fn.load() - data specified in ajaxSettings is merged in", 1, function( assert ) { var done = assert.async(); @@ -2133,17 +2137,17 @@ QUnit.module( "ajax", { var data = { "baz": 1 }; - jQuery.ajaxSetup({ + jQuery.ajaxSetup( { data: { "foo": "bar" } - }); - jQuery("#foo").load( "data/echoQuery.php", data ); - jQuery( document ).ajaxComplete(function( event, jqXHR, options ) { - assert.ok( ~options.data.indexOf("foo=bar"), "Data from ajaxSettings was used" ); + } ); + jQuery( "#foo" ).load( "data/echoQuery.php", data ); + jQuery( document ).ajaxComplete( function( event, jqXHR, options ) { + assert.ok( ~options.data.indexOf( "foo=bar" ), "Data from ajaxSettings was used" ); done(); - }); - }); + } ); + } ); // //----------- jQuery.post() @@ -2152,20 +2156,20 @@ QUnit.module( "ajax", { jQuery.when( jQuery.post( - url("data/name.php"), + url( "data/name.php" ), { xml: "5-2", length: 3 }, function( xml ) { - jQuery( "math", xml ).each(function() { + jQuery( "math", xml ).each( function() { assert.strictEqual( jQuery( "calculation", this ).text(), "5-2", "Check for XML" ); assert.strictEqual( jQuery( "result", this ).text(), "3", "Check for XML" ); - }); + } ); } ), - jQuery.ajax({ - url: url("data/echoData.php"), + jQuery.ajax( { + url: url( "data/echoData.php" ), type: "POST", data: { "test": { @@ -2176,66 +2180,66 @@ QUnit.module( "ajax", { success: function( data ) { assert.strictEqual( data, "test%5Blength%5D=7&test%5Bfoo%5D=bar", "Check if a sub-object with a length param is serialized correctly" ); } - }) - ).always(function() { + } ) + ).always( function() { done(); - }); - }); + } ); + } ); QUnit.test( "jQuery.post( String, Hash, Function ) - simple with xml", 4, function( assert ) { var done = assert.async(); jQuery.when( jQuery.post( - url("data/name.php"), + url( "data/name.php" ), { "xml": "5-2" }, function( xml ) { - jQuery( "math", xml ).each(function() { + jQuery( "math", xml ).each( function() { assert.strictEqual( jQuery( "calculation", this ).text(), "5-2", "Check for XML" ); assert.strictEqual( jQuery( "result", this ).text(), "3", "Check for XML" ); - }); + } ); } ), - jQuery.post( url("data/name.php?xml=5-2"), {}, function( xml ) { - jQuery( "math", xml ).each(function() { + jQuery.post( url( "data/name.php?xml=5-2" ), {}, function( xml ) { + jQuery( "math", xml ).each( function() { assert.strictEqual( jQuery( "calculation", this ).text(), "5-2", "Check for XML" ); assert.strictEqual( jQuery( "result", this ).text(), "3", "Check for XML" ); - }); - }) - ).always(function() { + } ); + } ) + ).always( function() { done(); - }); - }); + } ); + } ); QUnit.test( "jQuery[get|post]( options ) - simple with xml", 2, function( assert ) { var done = assert.async(); jQuery.when.apply( jQuery, - jQuery.map( [ "get", "post" ] , function( method ) { - return jQuery[ method ]({ + jQuery.map( [ "get", "post" ], function( method ) { + return jQuery[ method ]( { url: url( "data/name.php" ), data: { "xml": "5-2" }, success: function( xml ) { - jQuery( "math", xml ).each(function() { + jQuery( "math", xml ).each( function() { assert.strictEqual( jQuery( "result", this ).text(), "3", "Check for XML" ); - }); + } ); } - }); - }) - ).always(function() { + } ); + } ) + ).always( function() { done(); - }); - }); + } ); + } ); //----------- jQuery.active QUnit.test( "jQuery.active", function( assert ) { assert.expect( 1 ); assert.ok( jQuery.active === 0, "ajax active counter should be zero: " + jQuery.active ); - }); + } ); -})(); +} )(); diff --git a/test/unit/attributes.js b/test/unit/attributes.js index 6d8848a3e..59c8ec50b 100644 --- a/test/unit/attributes.js +++ b/test/unit/attributes.js @@ -1,6 +1,6 @@ QUnit.module( "attributes", { teardown: moduleTeardown -}); +} ); function bareObj( value ) { return value; @@ -47,7 +47,7 @@ QUnit.test( "jQuery.propFix integrity test", function( assert ) { }; assert.deepEqual( props, jQuery.propFix, "jQuery.propFix passes integrity check" ); -}); +} ); QUnit.test( "attr(String)", function( assert ) { assert.expect( 50 ); @@ -56,199 +56,200 @@ QUnit.test( "attr(String)", function( assert ) { select, optgroup, option, $img, styleElem, $button, $form, $a; - assert.equal( jQuery("#text1").attr("type"), "text", "Check for type attribute" ); - assert.equal( jQuery("#radio1").attr("type"), "radio", "Check for type attribute" ); - assert.equal( jQuery("#check1").attr("type"), "checkbox", "Check for type attribute" ); - assert.equal( jQuery("#simon1").attr("rel"), "bookmark", "Check for rel attribute" ); - assert.equal( jQuery("#google").attr("title"), "Google!", "Check for title attribute" ); - assert.equal( jQuery("#mark").attr("hreflang"), "en", "Check for hreflang attribute" ); - assert.equal( jQuery("#en").attr("lang"), "en", "Check for lang attribute" ); - assert.equal( jQuery("#simon").attr("class"), "blog link", "Check for class attribute" ); - assert.equal( jQuery("#name").attr("name"), "name", "Check for name attribute" ); - assert.equal( jQuery("#text1").attr("name"), "action", "Check for name attribute" ); - assert.ok( jQuery("#form").attr("action").indexOf("formaction") >= 0, "Check for action attribute" ); - assert.equal( jQuery("#text1").attr("value", "t").attr("value"), "t", "Check setting the value attribute" ); - assert.equal( jQuery("#text1").attr("value", "").attr("value"), "", "Check setting the value attribute to empty string" ); - assert.equal( jQuery("<div value='t'></div>").attr("value"), "t", "Check setting custom attr named 'value' on a div" ); - assert.equal( jQuery("#form").attr("blah", "blah").attr("blah"), "blah", "Set non-existent attribute on a form" ); - assert.equal( jQuery("#foo").attr("height"), undefined, "Non existent height attribute should return undefined" ); + assert.equal( jQuery( "#text1" ).attr( "type" ), "text", "Check for type attribute" ); + assert.equal( jQuery( "#radio1" ).attr( "type" ), "radio", "Check for type attribute" ); + assert.equal( jQuery( "#check1" ).attr( "type" ), "checkbox", "Check for type attribute" ); + assert.equal( jQuery( "#simon1" ).attr( "rel" ), "bookmark", "Check for rel attribute" ); + assert.equal( jQuery( "#google" ).attr( "title" ), "Google!", "Check for title attribute" ); + assert.equal( jQuery( "#mark" ).attr( "hreflang" ), "en", "Check for hreflang attribute" ); + assert.equal( jQuery( "#en" ).attr( "lang" ), "en", "Check for lang attribute" ); + assert.equal( jQuery( "#simon" ).attr( "class" ), "blog link", "Check for class attribute" ); + assert.equal( jQuery( "#name" ).attr( "name" ), "name", "Check for name attribute" ); + assert.equal( jQuery( "#text1" ).attr( "name" ), "action", "Check for name attribute" ); + assert.ok( jQuery( "#form" ).attr( "action" ).indexOf( "formaction" ) >= 0, "Check for action attribute" ); + assert.equal( jQuery( "#text1" ).attr( "value", "t" ).attr( "value" ), "t", "Check setting the value attribute" ); + assert.equal( jQuery( "#text1" ).attr( "value", "" ).attr( "value" ), "", "Check setting the value attribute to empty string" ); + assert.equal( jQuery( "<div value='t'></div>" ).attr( "value" ), "t", "Check setting custom attr named 'value' on a div" ); + assert.equal( jQuery( "#form" ).attr( "blah", "blah" ).attr( "blah" ), "blah", "Set non-existent attribute on a form" ); + assert.equal( jQuery( "#foo" ).attr( "height" ), undefined, "Non existent height attribute should return undefined" ); // [7472] & [3113] (form contains an input with name="action" or name="id") - extras = jQuery("<input id='id' name='id' /><input id='name' name='name' /><input id='target' name='target' />").appendTo("#testForm"); - assert.equal( jQuery("#form").attr("action","newformaction").attr("action"), "newformaction", "Check that action attribute was changed" ); - 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]" ); + extras = jQuery( "<input id='id' name='id' /><input id='name' name='name' /><input id='target' name='target' />" ).appendTo( "#testForm" ); + assert.equal( jQuery( "#form" ).attr( "action", "newformaction" ).attr( "action" ), "newformaction", "Check that action attribute was changed" ); + 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" ); + assert.equal( jQuery( "#testForm" ).attr( "name" ), undefined, "Retrieving name does not retrieve input with name=name" ); extras.remove(); - assert.equal( jQuery("#text1").attr("maxlength"), "30", "Check for maxlength attribute" ); - assert.equal( jQuery("#text1").attr("maxLength"), "30", "Check for maxLength attribute" ); - assert.equal( jQuery("#area1").attr("maxLength"), "30", "Check for maxLength attribute" ); + assert.equal( jQuery( "#text1" ).attr( "maxlength" ), "30", "Check for maxlength attribute" ); + assert.equal( jQuery( "#text1" ).attr( "maxLength" ), "30", "Check for maxLength attribute" ); + assert.equal( jQuery( "#area1" ).attr( "maxLength" ), "30", "Check for maxLength attribute" ); // using innerHTML in IE causes href attribute to be serialized to the full path - jQuery("<a/>").attr({ + jQuery( "<a/>" ).attr( { "id": "tAnchor5", "href": "#5" - }).appendTo("#qunit-fixture"); - assert.equal( jQuery("#tAnchor5").attr("href"), "#5", "Check for non-absolute href (an anchor)" ); - jQuery("<a id='tAnchor6' href='#5' />").appendTo("#qunit-fixture"); - assert.equal( jQuery("#tAnchor5").prop("href"), jQuery("#tAnchor6").prop("href"), "Check for absolute href prop on an anchor" ); + } ).appendTo( "#qunit-fixture" ); + assert.equal( jQuery( "#tAnchor5" ).attr( "href" ), "#5", "Check for non-absolute href (an anchor)" ); + jQuery( "<a id='tAnchor6' href='#5' />" ).appendTo( "#qunit-fixture" ); + assert.equal( jQuery( "#tAnchor5" ).prop( "href" ), jQuery( "#tAnchor6" ).prop( "href" ), "Check for absolute href prop on an anchor" ); - jQuery("<script type='jquery/test' src='#5' id='scriptSrc'></script>").appendTo("#qunit-fixture"); - assert.equal( jQuery("#tAnchor5").prop("href"), jQuery("#scriptSrc").prop("src"), "Check for absolute src prop on a script" ); + jQuery( "<script type='jquery/test' src='#5' id='scriptSrc'></script>" ).appendTo( "#qunit-fixture" ); + assert.equal( jQuery( "#tAnchor5" ).prop( "href" ), jQuery( "#scriptSrc" ).prop( "src" ), "Check for absolute src prop on a script" ); // list attribute is readonly by default in browsers that support it - jQuery("#list-test").attr( "list", "datalist" ); - assert.equal( jQuery("#list-test").attr("list"), "datalist", "Check setting list attribute" ); + jQuery( "#list-test" ).attr( "list", "datalist" ); + assert.equal( jQuery( "#list-test" ).attr( "list" ), "datalist", "Check setting list attribute" ); // Related to [5574] and [5683] body = document.body; $body = jQuery( body ); - assert.strictEqual( $body.attr("foo"), undefined, "Make sure that a non existent attribute returns undefined" ); + assert.strictEqual( $body.attr( "foo" ), undefined, "Make sure that a non existent attribute returns undefined" ); body.setAttribute( "foo", "baz" ); - assert.equal( $body.attr("foo"), "baz", "Make sure the dom attribute is retrieved when no expando is found" ); + assert.equal( $body.attr( "foo" ), "baz", "Make sure the dom attribute is retrieved when no expando is found" ); - $body.attr( "foo","cool" ); - assert.equal( $body.attr("foo"), "cool", "Make sure that setting works well when both expando and dom attribute are available" ); + $body.attr( "foo", "cool" ); + assert.equal( $body.attr( "foo" ), "cool", "Make sure that setting works well when both expando and dom attribute are available" ); - body.removeAttribute("foo"); // Cleanup + body.removeAttribute( "foo" ); // Cleanup - select = document.createElement("select"); - optgroup = document.createElement("optgroup"); - option = document.createElement("option"); + select = document.createElement( "select" ); + optgroup = document.createElement( "optgroup" ); + option = document.createElement( "option" ); optgroup.appendChild( option ); select.appendChild( optgroup ); - assert.equal( jQuery( option ).prop("selected"), true, "Make sure that a single option is selected, even when in an optgroup." ); + assert.equal( jQuery( option ).prop( "selected" ), true, "Make sure that a single option is selected, even when in an optgroup." ); - $img = jQuery("<img style='display:none' width='215' height='53' src='data/1x1.jpg'/>").appendTo("body"); - assert.equal( $img.attr("width"), "215", "Retrieve width attribute an an element with display:none." ); - assert.equal( $img.attr("height"), "53", "Retrieve height attribute an an element with display:none." ); + $img = jQuery( "<img style='display:none' width='215' height='53' src='data/1x1.jpg'/>" ).appendTo( "body" ); + assert.equal( $img.attr( "width" ), "215", "Retrieve width attribute an an element with display:none." ); + assert.equal( $img.attr( "height" ), "53", "Retrieve height attribute an an element with display:none." ); // Check for style support - styleElem = jQuery("<div/>").appendTo("#qunit-fixture").css({ + styleElem = jQuery( "<div/>" ).appendTo( "#qunit-fixture" ).css( { background: "url(UPPERlower.gif)" - }); - assert.ok( !!~styleElem.attr("style").indexOf("UPPERlower.gif"), "Check style attribute getter" ); - assert.ok( !!~styleElem.attr("style", "position:absolute;").attr("style").indexOf("absolute"), "Check style setter" ); + } ); + assert.ok( !!~styleElem.attr( "style" ).indexOf( "UPPERlower.gif" ), "Check style attribute getter" ); + assert.ok( !!~styleElem.attr( "style", "position:absolute;" ).attr( "style" ).indexOf( "absolute" ), "Check style setter" ); // Check value on button element (#1954) - $button = jQuery("<button>text</button>").insertAfter("#button"); - assert.strictEqual( $button.attr("value"), undefined, "Absence of value attribute on a button" ); - assert.equal( $button.attr( "value", "foobar" ).attr("value"), "foobar", "Value attribute on a button does not return innerHTML" ); - assert.equal( $button.attr("value", "baz").html(), "text", "Setting the value attribute does not change innerHTML" ); + $button = jQuery( "<button>text</button>" ).insertAfter( "#button" ); + assert.strictEqual( $button.attr( "value" ), undefined, "Absence of value attribute on a button" ); + assert.equal( $button.attr( "value", "foobar" ).attr( "value" ), "foobar", "Value attribute on a button does not return innerHTML" ); + assert.equal( $button.attr( "value", "baz" ).html(), "text", "Setting the value attribute does not change innerHTML" ); // Attributes with a colon on a table element (#1591) - assert.equal( jQuery("#table").attr("test:attrib"), undefined, "Retrieving a non-existent attribute on a table with a colon does not throw an error." ); - assert.equal( jQuery("#table").attr( "test:attrib", "foobar" ).attr("test:attrib"), "foobar", "Setting an attribute on a table with a colon does not throw an error." ); + assert.equal( jQuery( "#table" ).attr( "test:attrib" ), undefined, "Retrieving a non-existent attribute on a table with a colon does not throw an error." ); + assert.equal( jQuery( "#table" ).attr( "test:attrib", "foobar" ).attr( "test:attrib" ), "foobar", "Setting an attribute on a table with a colon does not throw an error." ); - $form = jQuery("<form class='something'></form>").appendTo("#qunit-fixture"); - assert.equal( $form.attr("class"), "something", "Retrieve the class attribute on a form." ); + $form = jQuery( "<form class='something'></form>" ).appendTo( "#qunit-fixture" ); + assert.equal( $form.attr( "class" ), "something", "Retrieve the class attribute on a form." ); - $a = jQuery("<a href='#' onclick='something()'>Click</a>").appendTo("#qunit-fixture"); - assert.equal( $a.attr("onclick"), "something()", "Retrieve ^on attribute without anonymous function wrapper." ); + $a = jQuery( "<a href='#' onclick='something()'>Click</a>" ).appendTo( "#qunit-fixture" ); + assert.equal( $a.attr( "onclick" ), "something()", "Retrieve ^on attribute without anonymous function wrapper." ); - assert.ok( jQuery("<div/>").attr("doesntexist") === undefined, "Make sure undefined is returned when no attribute is found." ); - assert.ok( jQuery("<div/>").attr("title") === undefined, "Make sure undefined is returned when no attribute is found." ); - assert.equal( jQuery("<div/>").attr( "title", "something" ).attr("title"), "something", "Set the title attribute." ); - assert.ok( jQuery().attr("doesntexist") === undefined, "Make sure undefined is returned when no element is there." ); - assert.equal( jQuery("<div/>").attr("value"), undefined, "An unset value on a div returns undefined." ); - assert.strictEqual( jQuery("<select><option value='property'></option></select>").attr("value"), undefined, "An unset value on a select returns undefined." ); + assert.ok( jQuery( "<div/>" ).attr( "doesntexist" ) === undefined, "Make sure undefined is returned when no attribute is found." ); + assert.ok( jQuery( "<div/>" ).attr( "title" ) === undefined, "Make sure undefined is returned when no attribute is found." ); + assert.equal( jQuery( "<div/>" ).attr( "title", "something" ).attr( "title" ), "something", "Set the title attribute." ); + assert.ok( jQuery().attr( "doesntexist" ) === undefined, "Make sure undefined is returned when no element is there." ); + assert.equal( jQuery( "<div/>" ).attr( "value" ), undefined, "An unset value on a div returns undefined." ); + assert.strictEqual( jQuery( "<select><option value='property'></option></select>" ).attr( "value" ), undefined, "An unset value on a select returns undefined." ); - $form = jQuery("#form").attr( "enctype", "multipart/form-data" ); - assert.equal( $form.prop("enctype"), "multipart/form-data", "Set the enctype of a form (encoding in IE6/7 #6743)" ); + $form = jQuery( "#form" ).attr( "enctype", "multipart/form-data" ); + assert.equal( $form.prop( "enctype" ), "multipart/form-data", "Set the enctype of a form (encoding in IE6/7 #6743)" ); -}); +} ); QUnit.test( "attr(String) on cloned elements, #9646", function( assert ) { assert.expect( 4 ); var div, - input = jQuery("<input name='tester' />"); + input = jQuery( "<input name='tester' />" ); - input.attr("name"); + input.attr( "name" ); assert.strictEqual( input.clone( true ).attr( "name", "test" )[ 0 ].name, "test", "Name attribute should be changed on cloned element" ); - div = jQuery("<div id='tester' />"); - div.attr("id"); + div = jQuery( "<div id='tester' />" ); + div.attr( "id" ); assert.strictEqual( div.clone( true ).attr( "id", "test" )[ 0 ].id, "test", "Id attribute should be changed on cloned element" ); - input = jQuery("<input value='tester' />"); - input.attr("value"); + input = jQuery( "<input value='tester' />" ); + input.attr( "value" ); assert.strictEqual( input.clone( true ).attr( "value", "test" )[ 0 ].value, "test", "Value attribute should be changed on cloned element" ); assert.strictEqual( input.clone( true ).attr( "value", 42 )[ 0 ].value, "42", "Value attribute should be changed on cloned element" ); -}); +} ); QUnit.test( "attr(String) in XML Files", function( assert ) { assert.expect( 3 ); var xml = createDashboardXML(); - assert.equal( jQuery( "locations", xml ).attr("class"), "foo", "Check class attribute in XML document" ); - assert.equal( jQuery( "location", xml ).attr("for"), "bar", "Check for attribute in XML document" ); - assert.equal( jQuery( "location", xml ).attr("checked"), "different", "Check that hooks are not attached in XML document" ); -}); + assert.equal( jQuery( "locations", xml ).attr( "class" ), "foo", "Check class attribute in XML document" ); + assert.equal( jQuery( "location", xml ).attr( "for" ), "bar", "Check for attribute in XML document" ); + assert.equal( jQuery( "location", xml ).attr( "checked" ), "different", "Check that hooks are not attached in XML document" ); +} ); QUnit.test( "attr(String, Function)", function( assert ) { assert.expect( 2 ); assert.equal( - jQuery("#text1").attr( "value", function() { + jQuery( "#text1" ).attr( "value", function() { return this.id; - }).attr("value"), + } ).attr( "value" ), "text1", "Set value from id" ); assert.equal( - jQuery("#text1").attr( "title", function(i) { + jQuery( "#text1" ).attr( "title", function( i ) { return i; - }).attr("title"), + } ).attr( "title" ), "0", "Set value with an index" ); -}); +} ); QUnit.test( "attr(Hash)", function( assert ) { assert.expect( 3 ); var pass = true; - jQuery("div").attr({ + jQuery( "div" ).attr( { "foo": "baz", "zoo": "ping" - }).each(function() { - if ( this.getAttribute("foo") !== "baz" && this.getAttribute("zoo") !== "ping" ) { + } ).each( function() { + if ( this.getAttribute( "foo" ) !== "baz" && this.getAttribute( "zoo" ) !== "ping" ) { pass = false; } - }); + } ); assert.ok( pass, "Set Multiple Attributes" ); assert.equal( - jQuery("#text1").attr({ + jQuery( "#text1" ).attr( { "value": function() { - return this["id"]; - }}).attr("value"), + return this[ "id" ]; + } } ).attr( "value" ), "text1", "Set attribute to computed value #1" ); assert.equal( - jQuery("#text1").attr({ - "title": function(i) { + jQuery( "#text1" ).attr( { + "title": function( i ) { return i; } - }).attr("title"), + } ).attr( "title" ), "0", "Set attribute to computed value #2" ); -}); +} ); QUnit.test( "attr(String, Object)", function( assert ) { assert.expect( 71 ); @@ -257,12 +258,12 @@ QUnit.test( "attr(String, Object)", function( assert ) { attributeNode, commentNode, textNode, obj, table, td, j, type, check, thrown, button, $radio, $radios, $svg, - div = jQuery("div").attr("foo", "bar"), + div = jQuery( "div" ).attr( "foo", "bar" ), i = 0, fail = false; for ( ; i < div.length; i++ ) { - if ( div[ i ].getAttribute("foo") !== "bar" ) { + if ( div[ i ].getAttribute( "foo" ) !== "bar" ) { fail = i; break; } @@ -271,187 +272,187 @@ QUnit.test( "attr(String, Object)", function( assert ) { assert.equal( fail, false, "Set Attribute, the #" + fail + " element didn't get the attribute 'foo'" ); assert.ok( - jQuery("#foo").attr({ + jQuery( "#foo" ).attr( { "width": null - }), + } ), "Try to set an attribute to nothing" ); - jQuery("#name").attr( "name", "something" ); - assert.equal( jQuery("#name").attr("name"), "something", "Set name attribute" ); - jQuery("#name").attr( "name", null ); - assert.equal( jQuery("#name").attr("name"), undefined, "Remove name attribute" ); + jQuery( "#name" ).attr( "name", "something" ); + assert.equal( jQuery( "#name" ).attr( "name" ), "something", "Set name attribute" ); + jQuery( "#name" ).attr( "name", null ); + assert.equal( jQuery( "#name" ).attr( "name" ), undefined, "Remove name attribute" ); $input = jQuery( "<input>", { name: "something", id: "specified" - }); - assert.equal( $input.attr("name"), "something", "Check element creation gets/sets the name attribute." ); - assert.equal( $input.attr("id"), "specified", "Check element creation gets/sets the id attribute." ); + } ); + assert.equal( $input.attr( "name" ), "something", "Check element creation gets/sets the name attribute." ); + assert.equal( $input.attr( "id" ), "specified", "Check element creation gets/sets the id attribute." ); // As of fixing #11115, we only guarantee boolean property update for checked and selected - $input = jQuery("<input type='checkbox'/>").attr( "checked", true ); - assert.equal( $input.prop("checked"), true, "Setting checked updates property (verified by .prop)" ); - assert.equal( $input[0].checked, true, "Setting checked updates property (verified by native property)" ); - $input = jQuery("<option/>").attr( "selected", true ); - assert.equal( $input.prop("selected"), true, "Setting selected updates property (verified by .prop)" ); - assert.equal( $input[0].selected, true, "Setting selected updates property (verified by native property)" ); - - $input = jQuery("#check2"); + $input = jQuery( "<input type='checkbox'/>" ).attr( "checked", true ); + assert.equal( $input.prop( "checked" ), true, "Setting checked updates property (verified by .prop)" ); + assert.equal( $input[ 0 ].checked, true, "Setting checked updates property (verified by native property)" ); + $input = jQuery( "<option/>" ).attr( "selected", true ); + assert.equal( $input.prop( "selected" ), true, "Setting selected updates property (verified by .prop)" ); + assert.equal( $input[ 0 ].selected, true, "Setting selected updates property (verified by native property)" ); + + $input = jQuery( "#check2" ); $input.prop( "checked", true ).prop( "checked", false ).attr( "checked", true ); - assert.equal( $input.attr("checked"), "checked", "Set checked (verified by .attr)" ); + assert.equal( $input.attr( "checked" ), "checked", "Set checked (verified by .attr)" ); $input.prop( "checked", false ).prop( "checked", true ).attr( "checked", false ); - assert.equal( $input.attr("checked"), undefined, "Remove checked (verified by .attr)" ); + assert.equal( $input.attr( "checked" ), undefined, "Remove checked (verified by .attr)" ); - $input = jQuery("#text1").prop( "readOnly", true ).prop( "readOnly", false ).attr( "readonly", true ); - assert.equal( $input.attr("readonly"), "readonly", "Set readonly (verified by .attr)" ); + $input = jQuery( "#text1" ).prop( "readOnly", true ).prop( "readOnly", false ).attr( "readonly", true ); + assert.equal( $input.attr( "readonly" ), "readonly", "Set readonly (verified by .attr)" ); $input.prop( "readOnly", false ).prop( "readOnly", true ).attr( "readonly", false ); - assert.equal( $input.attr("readonly"), undefined, "Remove readonly (verified by .attr)" ); + assert.equal( $input.attr( "readonly" ), undefined, "Remove readonly (verified by .attr)" ); - $input = jQuery("#check2").attr( "checked", true ).attr( "checked", false ).prop( "checked", true ); - assert.equal( $input[0].checked, true, "Set checked property (verified by native property)" ); - assert.equal( $input.prop("checked"), true, "Set checked property (verified by .prop)" ); - assert.equal( $input.attr("checked"), undefined, "Setting checked property doesn't affect checked attribute" ); + $input = jQuery( "#check2" ).attr( "checked", true ).attr( "checked", false ).prop( "checked", true ); + assert.equal( $input[ 0 ].checked, true, "Set checked property (verified by native property)" ); + assert.equal( $input.prop( "checked" ), true, "Set checked property (verified by .prop)" ); + assert.equal( $input.attr( "checked" ), undefined, "Setting checked property doesn't affect checked attribute" ); $input.attr( "checked", false ).attr( "checked", true ).prop( "checked", false ); - assert.equal( $input[0].checked, false, "Clear checked property (verified by native property)" ); - assert.equal( $input.prop("checked"), false, "Clear checked property (verified by .prop)" ); - assert.equal( $input.attr("checked"), "checked", "Clearing checked property doesn't affect checked attribute" ); + assert.equal( $input[ 0 ].checked, false, "Clear checked property (verified by native property)" ); + assert.equal( $input.prop( "checked" ), false, "Clear checked property (verified by .prop)" ); + assert.equal( $input.attr( "checked" ), "checked", "Clearing checked property doesn't affect checked attribute" ); - $input = jQuery("#check2").attr( "checked", false ).attr( "checked", "checked" ); - assert.equal( $input.attr("checked"), "checked", "Set checked to 'checked' (verified by .attr)" ); + $input = jQuery( "#check2" ).attr( "checked", false ).attr( "checked", "checked" ); + assert.equal( $input.attr( "checked" ), "checked", "Set checked to 'checked' (verified by .attr)" ); - $radios = jQuery("#checkedtest").find("input[type='radio']"); - $radios.eq( 1 ).trigger("click"); - assert.equal( $radios.eq( 1 ).prop("checked"), true, "Second radio was checked when clicked" ); - assert.equal( $radios.eq( 0 ).attr("checked"), "checked", "First radio is still [checked]" ); + $radios = jQuery( "#checkedtest" ).find( "input[type='radio']" ); + $radios.eq( 1 ).trigger( "click" ); + assert.equal( $radios.eq( 1 ).prop( "checked" ), true, "Second radio was checked when clicked" ); + assert.equal( $radios.eq( 0 ).attr( "checked" ), "checked", "First radio is still [checked]" ); - $input = jQuery("#text1").attr( "readonly", false ).prop( "readOnly", true ); - assert.equal( $input[0].readOnly, true, "Set readonly property (verified by native property)" ); - assert.equal( $input.prop("readOnly"), true, "Set readonly property (verified by .prop)" ); + $input = jQuery( "#text1" ).attr( "readonly", false ).prop( "readOnly", true ); + assert.equal( $input[ 0 ].readOnly, true, "Set readonly property (verified by native property)" ); + assert.equal( $input.prop( "readOnly" ), true, "Set readonly property (verified by .prop)" ); $input.attr( "readonly", true ).prop( "readOnly", false ); - assert.equal( $input[0].readOnly, false, "Clear readonly property (verified by native property)" ); - assert.equal( $input.prop("readOnly"), false, "Clear readonly property (verified by .prop)" ); + assert.equal( $input[ 0 ].readOnly, false, "Clear readonly property (verified by native property)" ); + assert.equal( $input.prop( "readOnly" ), false, "Clear readonly property (verified by .prop)" ); - $input = jQuery("#name").attr( "maxlength", "5" ); - assert.equal( $input[0].maxLength, 5, "Set maxlength (verified by native property)" ); + $input = jQuery( "#name" ).attr( "maxlength", "5" ); + assert.equal( $input[ 0 ].maxLength, 5, "Set maxlength (verified by native property)" ); $input.attr( "maxLength", "10" ); - assert.equal( $input[0].maxLength, 10, "Set maxlength (verified by native property)" ); + assert.equal( $input[ 0 ].maxLength, 10, "Set maxlength (verified by native property)" ); // HTML5 boolean attributes - $text = jQuery("#text1").attr({ + $text = jQuery( "#text1" ).attr( { "autofocus": true, "required": true - }); - assert.equal( $text.attr("autofocus"), "autofocus", "Reading autofocus attribute yields 'autofocus'" ); - assert.equal( $text.attr( "autofocus", false ).attr("autofocus"), undefined, "Setting autofocus to false removes it" ); - assert.equal( $text.attr("required"), "required", "Reading required attribute yields 'required'" ); - assert.equal( $text.attr( "required", false ).attr("required"), undefined, "Setting required attribute to false removes it" ); + } ); + assert.equal( $text.attr( "autofocus" ), "autofocus", "Reading autofocus attribute yields 'autofocus'" ); + assert.equal( $text.attr( "autofocus", false ).attr( "autofocus" ), undefined, "Setting autofocus to false removes it" ); + assert.equal( $text.attr( "required" ), "required", "Reading required attribute yields 'required'" ); + assert.equal( $text.attr( "required", false ).attr( "required" ), undefined, "Setting required attribute to false removes it" ); - $details = jQuery("<details open></details>").appendTo("#qunit-fixture"); - assert.equal( $details.attr("open"), "open", "open attribute presence indicates true" ); - assert.equal( $details.attr( "open", false ).attr("open"), undefined, "Setting open attribute to false removes it" ); + $details = jQuery( "<details open></details>" ).appendTo( "#qunit-fixture" ); + assert.equal( $details.attr( "open" ), "open", "open attribute presence indicates true" ); + assert.equal( $details.attr( "open", false ).attr( "open" ), undefined, "Setting open attribute to false removes it" ); $text.attr( "data-something", true ); - assert.equal( $text.attr("data-something"), "true", "Set data attributes"); - assert.equal( $text.data("something"), true, "Setting data attributes are not affected by boolean settings"); + assert.equal( $text.attr( "data-something" ), "true", "Set data attributes" ); + assert.equal( $text.data( "something" ), true, "Setting data attributes are not affected by boolean settings" ); $text.attr( "data-another", false ); - assert.equal( $text.attr("data-another"), "false", "Set data attributes"); - assert.equal( $text.data("another"), false, "Setting data attributes are not affected by boolean settings" ); - assert.equal( $text.attr( "aria-disabled", false ).attr("aria-disabled"), "false", "Setting aria attributes are not affected by boolean settings" ); - $text.removeData("something").removeData("another").removeAttr("aria-disabled"); + assert.equal( $text.attr( "data-another" ), "false", "Set data attributes" ); + assert.equal( $text.data( "another" ), false, "Setting data attributes are not affected by boolean settings" ); + assert.equal( $text.attr( "aria-disabled", false ).attr( "aria-disabled" ), "false", "Setting aria attributes are not affected by boolean settings" ); + $text.removeData( "something" ).removeData( "another" ).removeAttr( "aria-disabled" ); - jQuery("#foo").attr("contenteditable", true); - assert.equal( jQuery("#foo").attr("contenteditable"), "true", "Enumerated attributes are set properly" ); + jQuery( "#foo" ).attr( "contenteditable", true ); + assert.equal( jQuery( "#foo" ).attr( "contenteditable" ), "true", "Enumerated attributes are set properly" ); - attributeNode = document.createAttribute("irrelevant"); - commentNode = document.createComment("some comment"); - textNode = document.createTextNode("some text"); + attributeNode = document.createAttribute( "irrelevant" ); + commentNode = document.createComment( "some comment" ); + textNode = document.createTextNode( "some text" ); obj = {}; jQuery.each( [ commentNode, textNode, attributeNode ], function( i, elem ) { var $elem = jQuery( elem ); $elem.attr( "nonexisting", "foo" ); - assert.strictEqual( $elem.attr("nonexisting"), undefined, "attr(name, value) works correctly on comment and text nodes (bug #7500)." ); - }); + assert.strictEqual( $elem.attr( "nonexisting" ), undefined, "attr(name, value) works correctly on comment and text nodes (bug #7500)." ); + } ); jQuery.each( [ window, document, obj, "#firstp" ], function( i, elem ) { var oldVal = elem.nonexisting, $elem = jQuery( elem ); - assert.strictEqual( $elem.attr("nonexisting"), undefined, "attr works correctly for non existing attributes (bug #7500)." ); - assert.equal( $elem.attr( "nonexisting", "foo" ).attr("nonexisting"), "foo", "attr falls back to prop on unsupported arguments" ); + assert.strictEqual( $elem.attr( "nonexisting" ), undefined, "attr works correctly for non existing attributes (bug #7500)." ); + assert.equal( $elem.attr( "nonexisting", "foo" ).attr( "nonexisting" ), "foo", "attr falls back to prop on unsupported arguments" ); elem.nonexisting = oldVal; - }); + } ); // Register the property on the window for the previous assertion so it will be clean up Globals.register( "nonexisting" ); - table = jQuery("#table").append("<tr><td>cell</td></tr><tr><td>cell</td><td>cell</td></tr><tr><td>cell</td><td>cell</td></tr>"); - td = table.find("td").eq(0); + table = jQuery( "#table" ).append( "<tr><td>cell</td></tr><tr><td>cell</td><td>cell</td></tr><tr><td>cell</td><td>cell</td></tr>" ); + td = table.find( "td" ).eq( 0 ); td.attr( "rowspan", "2" ); - assert.equal( td[ 0 ]["rowSpan"], 2, "Check rowspan is correctly set" ); + assert.equal( td[ 0 ][ "rowSpan" ], 2, "Check rowspan is correctly set" ); td.attr( "colspan", "2" ); - assert.equal( td[ 0 ]["colSpan"], 2, "Check colspan is correctly set" ); - table.attr("cellspacing", "2"); - assert.equal( table[ 0 ]["cellSpacing"], "2", "Check cellspacing is correctly set" ); + assert.equal( td[ 0 ][ "colSpan" ], 2, "Check colspan is correctly set" ); + table.attr( "cellspacing", "2" ); + assert.equal( table[ 0 ][ "cellSpacing" ], "2", "Check cellspacing is correctly set" ); - assert.equal( jQuery("#area1").attr("value"), undefined, "Value attribute is distinct from value property." ); + assert.equal( jQuery( "#area1" ).attr( "value" ), undefined, "Value attribute is distinct from value property." ); // for #1070 - jQuery("#name").attr( "someAttr", "0" ); - assert.equal( jQuery("#name").attr("someAttr"), "0", "Set attribute to a string of '0'" ); - jQuery("#name").attr( "someAttr", 0 ); - assert.equal( jQuery("#name").attr("someAttr"), "0", "Set attribute to the number 0" ); - jQuery("#name").attr( "someAttr", 1 ); - assert.equal( jQuery("#name").attr("someAttr"), "1", "Set attribute to the number 1" ); + jQuery( "#name" ).attr( "someAttr", "0" ); + assert.equal( jQuery( "#name" ).attr( "someAttr" ), "0", "Set attribute to a string of '0'" ); + jQuery( "#name" ).attr( "someAttr", 0 ); + assert.equal( jQuery( "#name" ).attr( "someAttr" ), "0", "Set attribute to the number 0" ); + jQuery( "#name" ).attr( "someAttr", 1 ); + assert.equal( jQuery( "#name" ).attr( "someAttr" ), "1", "Set attribute to the number 1" ); // using contents will get comments regular, text, and comment nodes - j = jQuery("#nonnodes").contents(); + j = jQuery( "#nonnodes" ).contents(); j.attr( "name", "attrvalue" ); - assert.equal( j.attr("name"), "attrvalue", "Check node,textnode,comment for attr" ); - j.removeAttr("name"); + assert.equal( j.attr( "name" ), "attrvalue", "Check node,textnode,comment for attr" ); + j.removeAttr( "name" ); // Type - type = jQuery("#check2").attr("type"); + type = jQuery( "#check2" ).attr( "type" ); try { - jQuery("#check2").attr( "type", "hidden" ); + jQuery( "#check2" ).attr( "type", "hidden" ); assert.ok( true, "No exception thrown on input type change" ); - } catch( e ) { + } catch ( e ) { assert.ok( true, "Exception thrown on input type change: " + e ); } - check = document.createElement("input"); + check = document.createElement( "input" ); thrown = true; try { jQuery( check ).attr( "type", "checkbox" ); - } catch( e ) { + } catch ( e ) { thrown = false; } assert.ok( thrown, "Exception thrown when trying to change type property" ); - assert.equal( "checkbox", jQuery( check ).attr("type"), "Verify that you can change the type of an input element that isn't in the DOM" ); + assert.equal( "checkbox", jQuery( check ).attr( "type" ), "Verify that you can change the type of an input element that isn't in the DOM" ); - check = jQuery("<input />"); + check = jQuery( "<input />" ); thrown = true; try { check.attr( "type", "checkbox" ); - } catch( e ) { + } catch ( e ) { thrown = false; } assert.ok( thrown, "Exception thrown when trying to change type property" ); - assert.equal( "checkbox", check.attr("type"), "Verify that you can change the type of an input element that isn't in the DOM" ); + assert.equal( "checkbox", check.attr( "type" ), "Verify that you can change the type of an input element that isn't in the DOM" ); - button = jQuery("#button"); + button = jQuery( "#button" ); try { button.attr( "type", "submit" ); assert.ok( true, "No exception thrown on button type change" ); - } catch( e ) { + } catch ( e ) { assert.ok( true, "Exception thrown on button type change: " + e ); } $radio = jQuery( "<input>", { "value": "sup", "type": "radio" - }).appendTo("#testForm"); + } ).appendTo( "#testForm" ); assert.equal( $radio.val(), "sup", "Value is not reset when type is set after value on a radio" ); // Setting attributes on svg elements (bug #3116) @@ -460,16 +461,16 @@ QUnit.test( "attr(String, Object)", function( assert ) { "<circle cx='200' cy='200' r='150' />" + "</svg>" - ).appendTo("body"); - assert.equal( $svg.attr( "cx", 100 ).attr("cx"), "100", "Set attribute on svg element" ); + ).appendTo( "body" ); + assert.equal( $svg.attr( "cx", 100 ).attr( "cx" ), "100", "Set attribute on svg element" ); $svg.remove(); // undefined values are chainable - jQuery("#name").attr( "maxlength", "5" ).removeAttr("nonexisting"); - assert.equal( typeof jQuery("#name").attr( "maxlength", undefined ), "object", ".attr('attribute', undefined) is chainable (#5571)" ); - assert.equal( jQuery("#name").attr( "maxlength", undefined ).attr("maxlength"), "5", ".attr('attribute', undefined) does not change value (#5571)" ); - assert.equal( jQuery("#name").attr( "nonexisting", undefined ).attr("nonexisting"), undefined, ".attr('attribute', undefined) does not create attribute (#5571)" ); -}); + jQuery( "#name" ).attr( "maxlength", "5" ).removeAttr( "nonexisting" ); + assert.equal( typeof jQuery( "#name" ).attr( "maxlength", undefined ), "object", ".attr('attribute', undefined) is chainable (#5571)" ); + assert.equal( jQuery( "#name" ).attr( "maxlength", undefined ).attr( "maxlength" ), "5", ".attr('attribute', undefined) does not change value (#5571)" ); + assert.equal( jQuery( "#name" ).attr( "nonexisting", undefined ).attr( "nonexisting" ), undefined, ".attr('attribute', undefined) does not create attribute (#5571)" ); +} ); QUnit.test( "attr - extending the boolean attrHandle", function( assert ) { assert.expect( 1 ); @@ -483,18 +484,18 @@ QUnit.test( "attr - extending the boolean attrHandle", function( assert ) { called = false; jQuery( "input" ).attr( "checked" ); assert.ok( called, "The boolean attrHandle does not drop custom attrHandles" ); -}); +} ); QUnit.test( "attr(String, Object) - Loaded via XML document", function( assert ) { assert.expect( 2 ); var xml = createDashboardXML(), titles = []; - jQuery( "tab", xml ).each(function() { - titles.push( jQuery( this ).attr("title") ); - }); + jQuery( "tab", xml ).each( function() { + titles.push( jQuery( this ).attr( "title" ) ); + } ); assert.equal( titles[ 0 ], "Location", "attr() in XML context: Check first title" ); assert.equal( titles[ 1 ], "Users", "attr() in XML context: Check second title" ); -}); +} ); QUnit.test( "attr(String, Object) - Loaded via XML fragment", function( assert ) { assert.expect( 2 ); @@ -502,121 +503,121 @@ QUnit.test( "attr(String, Object) - Loaded via XML fragment", function( assert ) $frag = jQuery( frag ); $frag.attr( "test", "some value" ); - assert.equal( $frag.attr("test"), "some value", "set attribute" ); + assert.equal( $frag.attr( "test" ), "some value", "set attribute" ); $frag.attr( "test", null ); - assert.equal( $frag.attr("test"), undefined, "remove attribute" ); -}); + assert.equal( $frag.attr( "test" ), undefined, "remove attribute" ); +} ); QUnit.test( "attr('tabindex')", function( assert ) { assert.expect( 8 ); // elements not natively tabbable - assert.equal( jQuery("#listWithTabIndex").attr("tabindex"), "5", "not natively tabbable, with tabindex set to 0" ); - assert.equal( jQuery("#divWithNoTabIndex").attr("tabindex"), undefined, "not natively tabbable, no tabindex set" ); + assert.equal( jQuery( "#listWithTabIndex" ).attr( "tabindex" ), "5", "not natively tabbable, with tabindex set to 0" ); + assert.equal( jQuery( "#divWithNoTabIndex" ).attr( "tabindex" ), undefined, "not natively tabbable, no tabindex set" ); // anchor with href - assert.equal( jQuery("#linkWithNoTabIndex").attr("tabindex"), undefined, "anchor with href, no tabindex set" ); - assert.equal( jQuery("#linkWithTabIndex").attr("tabindex"), "2", "anchor with href, tabindex set to 2" ); - assert.equal( jQuery("#linkWithNegativeTabIndex").attr("tabindex"), "-1", "anchor with href, tabindex set to -1" ); + assert.equal( jQuery( "#linkWithNoTabIndex" ).attr( "tabindex" ), undefined, "anchor with href, no tabindex set" ); + assert.equal( jQuery( "#linkWithTabIndex" ).attr( "tabindex" ), "2", "anchor with href, tabindex set to 2" ); + assert.equal( jQuery( "#linkWithNegativeTabIndex" ).attr( "tabindex" ), "-1", "anchor with href, tabindex set to -1" ); // anchor without href - assert.equal( jQuery("#linkWithNoHrefWithNoTabIndex").attr("tabindex"), undefined, "anchor without href, no tabindex set" ); - assert.equal( jQuery("#linkWithNoHrefWithTabIndex").attr("tabindex"), "1", "anchor without href, tabindex set to 2" ); - assert.equal( jQuery("#linkWithNoHrefWithNegativeTabIndex").attr("tabindex"), "-1", "anchor without href, no tabindex set" ); -}); + assert.equal( jQuery( "#linkWithNoHrefWithNoTabIndex" ).attr( "tabindex" ), undefined, "anchor without href, no tabindex set" ); + assert.equal( jQuery( "#linkWithNoHrefWithTabIndex" ).attr( "tabindex" ), "1", "anchor without href, tabindex set to 2" ); + assert.equal( jQuery( "#linkWithNoHrefWithNegativeTabIndex" ).attr( "tabindex" ), "-1", "anchor without href, no tabindex set" ); +} ); QUnit.test( "attr('tabindex', value)", function( assert ) { assert.expect( 9 ); - var element = jQuery("#divWithNoTabIndex"); - assert.equal( element.attr("tabindex"), undefined, "start with no tabindex" ); + var element = jQuery( "#divWithNoTabIndex" ); + assert.equal( element.attr( "tabindex" ), undefined, "start with no tabindex" ); // set a positive string element.attr( "tabindex", "1" ); - assert.equal( element.attr("tabindex"), "1", "set tabindex to 1 (string)" ); + assert.equal( element.attr( "tabindex" ), "1", "set tabindex to 1 (string)" ); // set a zero string element.attr( "tabindex", "0" ); - assert.equal( element.attr("tabindex"), "0", "set tabindex to 0 (string)" ); + assert.equal( element.attr( "tabindex" ), "0", "set tabindex to 0 (string)" ); // set a negative string element.attr( "tabindex", "-1" ); - assert.equal( element.attr("tabindex"), "-1", "set tabindex to -1 (string)" ); + assert.equal( element.attr( "tabindex" ), "-1", "set tabindex to -1 (string)" ); // set a positive number element.attr( "tabindex", 1 ); - assert.equal( element.attr("tabindex"), "1", "set tabindex to 1 (number)" ); + assert.equal( element.attr( "tabindex" ), "1", "set tabindex to 1 (number)" ); // set a zero number element.attr( "tabindex", 0 ); - assert.equal(element.attr("tabindex"), "0", "set tabindex to 0 (number)"); + assert.equal( element.attr( "tabindex" ), "0", "set tabindex to 0 (number)" ); // set a negative number element.attr( "tabindex", -1 ); - assert.equal( element.attr("tabindex"), "-1", "set tabindex to -1 (number)" ); + assert.equal( element.attr( "tabindex" ), "-1", "set tabindex to -1 (number)" ); - element = jQuery("#linkWithTabIndex"); - assert.equal( element.attr("tabindex"), "2", "start with tabindex 2" ); + element = jQuery( "#linkWithTabIndex" ); + assert.equal( element.attr( "tabindex" ), "2", "start with tabindex 2" ); element.attr( "tabindex", -1 ); - assert.equal( element.attr("tabindex"), "-1", "set negative tabindex" ); -}); + assert.equal( element.attr( "tabindex" ), "-1", "set negative tabindex" ); +} ); QUnit.test( "removeAttr(String)", function( assert ) { assert.expect( 12 ); var $first; - assert.equal( jQuery("#mark").removeAttr("class").attr("class"), undefined, "remove class" ); - assert.equal( jQuery("#form").removeAttr("id").attr("id"), undefined, "Remove id" ); - assert.equal( jQuery("#foo").attr( "style", "position:absolute;" ).removeAttr("style").attr("style"), undefined, "Check removing style attribute" ); - assert.equal( jQuery("#form").attr( "style", "position:absolute;" ).removeAttr("style").attr("style"), undefined, "Check removing style attribute on a form" ); - assert.equal( jQuery("<div style='position: absolute'></div>").appendTo("#foo").removeAttr("style").prop("style").cssText, "", "Check removing style attribute (#9699 Webkit)" ); - assert.equal( jQuery("#fx-test-group").attr( "height", "3px" ).removeAttr("height").get( 0 ).style.height, "1px", "Removing height attribute has no effect on height set with style attribute" ); + assert.equal( jQuery( "#mark" ).removeAttr( "class" ).attr( "class" ), undefined, "remove class" ); + assert.equal( jQuery( "#form" ).removeAttr( "id" ).attr( "id" ), undefined, "Remove id" ); + assert.equal( jQuery( "#foo" ).attr( "style", "position:absolute;" ).removeAttr( "style" ).attr( "style" ), undefined, "Check removing style attribute" ); + assert.equal( jQuery( "#form" ).attr( "style", "position:absolute;" ).removeAttr( "style" ).attr( "style" ), undefined, "Check removing style attribute on a form" ); + assert.equal( jQuery( "<div style='position: absolute'></div>" ).appendTo( "#foo" ).removeAttr( "style" ).prop( "style" ).cssText, "", "Check removing style attribute (#9699 Webkit)" ); + assert.equal( jQuery( "#fx-test-group" ).attr( "height", "3px" ).removeAttr( "height" ).get( 0 ).style.height, "1px", "Removing height attribute has no effect on height set with style attribute" ); - jQuery("#check1").removeAttr("checked").prop( "checked", true ).removeAttr("checked"); - assert.equal( document.getElementById("check1").checked, false, "removeAttr sets boolean properties to false" ); - jQuery("#text1").prop( "readOnly", true ).removeAttr("readonly"); - assert.equal( document.getElementById("text1").readOnly, false, "removeAttr sets boolean properties to false" ); + jQuery( "#check1" ).removeAttr( "checked" ).prop( "checked", true ).removeAttr( "checked" ); + assert.equal( document.getElementById( "check1" ).checked, false, "removeAttr sets boolean properties to false" ); + jQuery( "#text1" ).prop( "readOnly", true ).removeAttr( "readonly" ); + assert.equal( document.getElementById( "text1" ).readOnly, false, "removeAttr sets boolean properties to false" ); - jQuery("#option2c").removeAttr("selected"); - assert.equal( jQuery("#option2d").attr("selected"), "selected", "Removing `selected` from an option that is not selected does not remove selected from the currently selected option (#10870)" ); + jQuery( "#option2c" ).removeAttr( "selected" ); + assert.equal( jQuery( "#option2d" ).attr( "selected" ), "selected", "Removing `selected` from an option that is not selected does not remove selected from the currently selected option (#10870)" ); try { - $first = jQuery("#first").attr( "contenteditable", "true" ).removeAttr("contenteditable"); - assert.equal( $first.attr("contenteditable"), undefined, "Remove the contenteditable attribute" ); - } catch( e ) { + $first = jQuery( "#first" ).attr( "contenteditable", "true" ).removeAttr( "contenteditable" ); + assert.equal( $first.attr( "contenteditable" ), undefined, "Remove the contenteditable attribute" ); + } catch ( e ) { assert.ok( false, "Removing contenteditable threw an error (#10429)" ); } - $first = jQuery("<div Case='mixed'></div>"); - assert.equal( $first.attr("Case"), "mixed", "case of attribute doesn't matter" ); - $first.removeAttr("Case"); + $first = jQuery( "<div Case='mixed'></div>" ); + assert.equal( $first.attr( "Case" ), "mixed", "case of attribute doesn't matter" ); + $first.removeAttr( "Case" ); assert.equal( $first.attr( "Case" ), undefined, "mixed-case attribute was removed" ); -}); +} ); QUnit.test( "removeAttr(String) in XML", function( assert ) { assert.expect( 7 ); var xml = createDashboardXML(), iwt = jQuery( "infowindowtab", xml ); - assert.equal( iwt.attr("normal"), "ab", "Check initial value" ); - iwt.removeAttr("Normal"); - assert.equal( iwt.attr("normal"), "ab", "Should still be there" ); - iwt.removeAttr("normal"); - assert.equal( iwt.attr("normal"), undefined, "Removed" ); + assert.equal( iwt.attr( "normal" ), "ab", "Check initial value" ); + iwt.removeAttr( "Normal" ); + assert.equal( iwt.attr( "normal" ), "ab", "Should still be there" ); + iwt.removeAttr( "normal" ); + assert.equal( iwt.attr( "normal" ), undefined, "Removed" ); - assert.equal( iwt.attr("mixedCase"), "yes", "Check initial value" ); - assert.equal( iwt.attr("mixedcase"), undefined, "toLowerCase not work good" ); - iwt.removeAttr("mixedcase"); - assert.equal( iwt.attr("mixedCase"), "yes", "Should still be there" ); - iwt.removeAttr("mixedCase"); - assert.equal( iwt.attr("mixedCase"), undefined, "Removed" ); -}); + assert.equal( iwt.attr( "mixedCase" ), "yes", "Check initial value" ); + assert.equal( iwt.attr( "mixedcase" ), undefined, "toLowerCase not work good" ); + iwt.removeAttr( "mixedcase" ); + assert.equal( iwt.attr( "mixedCase" ), "yes", "Should still be there" ); + iwt.removeAttr( "mixedCase" ); + assert.equal( iwt.attr( "mixedCase" ), undefined, "Removed" ); +} ); QUnit.test( "removeAttr(Multi String, variable space width)", function( assert ) { assert.expect( 8 ); - var div = jQuery("<div id='a' alt='b' title='c' rel='d'></div>"), + var div = jQuery( "<div id='a' alt='b' title='c' rel='d'></div>" ), tests = { id: "a", alt: "b", @@ -626,46 +627,46 @@ QUnit.test( "removeAttr(Multi String, variable space width)", function( assert ) jQuery.each( tests, function( key, val ) { assert.equal( div.attr( key ), val, "Attribute `" + key + "` exists, and has a value of `" + val + "`" ); - }); + } ); div.removeAttr( "id alt title rel " ); jQuery.each( tests, function( key ) { assert.equal( div.attr( key ), undefined, "Attribute `" + key + "` was removed" ); - }); -}); + } ); +} ); QUnit.test( "prop(String, Object)", function( assert ) { assert.expect( 17 ); - assert.equal( jQuery("#text1").prop("value"), "Test", "Check for value attribute" ); - assert.equal( jQuery("#text1").prop( "value", "Test2" ).prop("defaultValue"), "Test", "Check for defaultValue attribute" ); - assert.equal( jQuery("#select2").prop("selectedIndex"), 3, "Check for selectedIndex attribute" ); - assert.equal( jQuery("#foo").prop("nodeName").toUpperCase(), "DIV", "Check for nodeName attribute" ); - assert.equal( jQuery("#foo").prop("tagName").toUpperCase(), "DIV", "Check for tagName attribute" ); - assert.equal( jQuery("<option/>").prop("selected"), false, "Check selected attribute on disconnected element." ); - - assert.equal( jQuery("#listWithTabIndex").prop("tabindex"), 5, "Check retrieving tabindex" ); - jQuery("#text1").prop( "readonly", true ); - assert.equal( document.getElementById("text1").readOnly, true, "Check setting readOnly property with 'readonly'" ); - assert.equal( jQuery("#label-for").prop("for"), "action", "Check retrieving htmlFor" ); - jQuery("#text1").prop("class", "test"); - assert.equal( document.getElementById("text1").className, "test", "Check setting className with 'class'" ); - assert.equal( jQuery("#text1").prop("maxlength"), 30, "Check retrieving maxLength" ); - jQuery("#table").prop( "cellspacing", 1 ); - assert.equal( jQuery("#table").prop("cellSpacing"), "1", "Check setting and retrieving cellSpacing" ); - jQuery("#table").prop( "cellpadding", 1 ); - assert.equal( jQuery("#table").prop("cellPadding"), "1", "Check setting and retrieving cellPadding" ); - jQuery("#table").prop( "rowspan", 1 ); - assert.equal( jQuery("#table").prop("rowSpan"), 1, "Check setting and retrieving rowSpan" ); - jQuery("#table").prop( "colspan", 1 ); - assert.equal( jQuery("#table").prop("colSpan"), 1, "Check setting and retrieving colSpan" ); - jQuery("#table").prop( "usemap", 1 ); - assert.equal( jQuery("#table").prop("useMap"), 1, "Check setting and retrieving useMap" ); - jQuery("#table").prop( "frameborder", 1 ); - assert.equal( jQuery("#table").prop("frameBorder"), 1, "Check setting and retrieving frameBorder" ); -}); + assert.equal( jQuery( "#text1" ).prop( "value" ), "Test", "Check for value attribute" ); + assert.equal( jQuery( "#text1" ).prop( "value", "Test2" ).prop( "defaultValue" ), "Test", "Check for defaultValue attribute" ); + assert.equal( jQuery( "#select2" ).prop( "selectedIndex" ), 3, "Check for selectedIndex attribute" ); + assert.equal( jQuery( "#foo" ).prop( "nodeName" ).toUpperCase(), "DIV", "Check for nodeName attribute" ); + assert.equal( jQuery( "#foo" ).prop( "tagName" ).toUpperCase(), "DIV", "Check for tagName attribute" ); + assert.equal( jQuery( "<option/>" ).prop( "selected" ), false, "Check selected attribute on disconnected element." ); + + assert.equal( jQuery( "#listWithTabIndex" ).prop( "tabindex" ), 5, "Check retrieving tabindex" ); + jQuery( "#text1" ).prop( "readonly", true ); + assert.equal( document.getElementById( "text1" ).readOnly, true, "Check setting readOnly property with 'readonly'" ); + assert.equal( jQuery( "#label-for" ).prop( "for" ), "action", "Check retrieving htmlFor" ); + jQuery( "#text1" ).prop( "class", "test" ); + assert.equal( document.getElementById( "text1" ).className, "test", "Check setting className with 'class'" ); + assert.equal( jQuery( "#text1" ).prop( "maxlength" ), 30, "Check retrieving maxLength" ); + jQuery( "#table" ).prop( "cellspacing", 1 ); + assert.equal( jQuery( "#table" ).prop( "cellSpacing" ), "1", "Check setting and retrieving cellSpacing" ); + jQuery( "#table" ).prop( "cellpadding", 1 ); + assert.equal( jQuery( "#table" ).prop( "cellPadding" ), "1", "Check setting and retrieving cellPadding" ); + jQuery( "#table" ).prop( "rowspan", 1 ); + assert.equal( jQuery( "#table" ).prop( "rowSpan" ), 1, "Check setting and retrieving rowSpan" ); + jQuery( "#table" ).prop( "colspan", 1 ); + assert.equal( jQuery( "#table" ).prop( "colSpan" ), 1, "Check setting and retrieving colSpan" ); + jQuery( "#table" ).prop( "usemap", 1 ); + assert.equal( jQuery( "#table" ).prop( "useMap" ), 1, "Check setting and retrieving useMap" ); + jQuery( "#table" ).prop( "frameborder", 1 ); + assert.equal( jQuery( "#table" ).prop( "frameBorder" ), 1, "Check setting and retrieving frameBorder" ); +} ); QUnit.test( "prop(String, Object) on null/undefined", function( assert ) { @@ -675,243 +676,243 @@ QUnit.test( "prop(String, Object) on null/undefined", function( assert ) { body = document.body, $body = jQuery( body ); - assert.ok( $body.prop("nextSibling") === null, "Make sure a null expando returns null" ); - body["foo"] = "bar"; - assert.equal( $body.prop("foo"), "bar", "Make sure the expando is preferred over the dom attribute" ); - body["foo"] = undefined; - assert.ok( $body.prop("foo") === undefined, "Make sure the expando is preferred over the dom attribute, even if undefined" ); + assert.ok( $body.prop( "nextSibling" ) === null, "Make sure a null expando returns null" ); + body[ "foo" ] = "bar"; + assert.equal( $body.prop( "foo" ), "bar", "Make sure the expando is preferred over the dom attribute" ); + body[ "foo" ] = undefined; + assert.ok( $body.prop( "foo" ) === undefined, "Make sure the expando is preferred over the dom attribute, even if undefined" ); - select = document.createElement("select"); - optgroup = document.createElement("optgroup"); - option = document.createElement("option"); + select = document.createElement( "select" ); + optgroup = document.createElement( "optgroup" ); + option = document.createElement( "option" ); optgroup.appendChild( option ); select.appendChild( optgroup ); - assert.equal( jQuery( option ).prop("selected"), true, "Make sure that a single option is selected, even when in an optgroup." ); - assert.equal( jQuery( document ).prop("nodeName"), "#document", "prop works correctly on document nodes (bug #7451)." ); + assert.equal( jQuery( option ).prop( "selected" ), true, "Make sure that a single option is selected, even when in an optgroup." ); + assert.equal( jQuery( document ).prop( "nodeName" ), "#document", "prop works correctly on document nodes (bug #7451)." ); - attributeNode = document.createAttribute("irrelevant"); - commentNode = document.createComment("some comment"); - textNode = document.createTextNode("some text"); + attributeNode = document.createAttribute( "irrelevant" ); + commentNode = document.createComment( "some comment" ); + textNode = document.createTextNode( "some text" ); obj = {}; jQuery.each( [ document, attributeNode, commentNode, textNode, obj, "#firstp" ], function( i, ele ) { - assert.strictEqual( jQuery( ele ).prop("nonexisting"), undefined, "prop works correctly for non existing attributes (bug #7500)." ); - }); + assert.strictEqual( jQuery( ele ).prop( "nonexisting" ), undefined, "prop works correctly for non existing attributes (bug #7500)." ); + } ); obj = {}; jQuery.each( [ document, obj ], function( i, ele ) { var $ele = jQuery( ele ); $ele.prop( "nonexisting", "foo" ); - assert.equal( $ele.prop("nonexisting"), "foo", "prop(name, value) works correctly for non existing attributes (bug #7500)." ); - }); - jQuery( document ).removeProp("nonexisting"); + assert.equal( $ele.prop( "nonexisting" ), "foo", "prop(name, value) works correctly for non existing attributes (bug #7500)." ); + } ); + jQuery( document ).removeProp( "nonexisting" ); - $form = jQuery("#form").prop( "enctype", "multipart/form-data" ); - assert.equal( $form.prop("enctype"), "multipart/form-data", "Set the enctype of a form (encoding in IE6/7 #6743)" ); -}); + $form = jQuery( "#form" ).prop( "enctype", "multipart/form-data" ); + assert.equal( $form.prop( "enctype" ), "multipart/form-data", "Set the enctype of a form (encoding in IE6/7 #6743)" ); +} ); QUnit.test( "prop('tabindex')", function( assert ) { assert.expect( 11 ); // inputs without tabIndex attribute - assert.equal( jQuery("#inputWithoutTabIndex").prop("tabindex"), 0, "input without tabindex" ); - assert.equal( jQuery("#buttonWithoutTabIndex").prop("tabindex"), 0, "button without tabindex" ); - assert.equal( jQuery("#textareaWithoutTabIndex").prop("tabindex"), 0, "textarea without tabindex" ); + assert.equal( jQuery( "#inputWithoutTabIndex" ).prop( "tabindex" ), 0, "input without tabindex" ); + assert.equal( jQuery( "#buttonWithoutTabIndex" ).prop( "tabindex" ), 0, "button without tabindex" ); + assert.equal( jQuery( "#textareaWithoutTabIndex" ).prop( "tabindex" ), 0, "textarea without tabindex" ); // elements not natively tabbable - assert.equal( jQuery("#listWithTabIndex").prop("tabindex"), 5, "not natively tabbable, with tabindex set to 0" ); - assert.equal( jQuery("#divWithNoTabIndex").prop("tabindex"), -1, "not natively tabbable, no tabindex set" ); + assert.equal( jQuery( "#listWithTabIndex" ).prop( "tabindex" ), 5, "not natively tabbable, with tabindex set to 0" ); + assert.equal( jQuery( "#divWithNoTabIndex" ).prop( "tabindex" ), -1, "not natively tabbable, no tabindex set" ); // anchor with href - assert.equal( jQuery("#linkWithNoTabIndex").prop("tabindex"), 0, "anchor with href, no tabindex set" ); - assert.equal( jQuery("#linkWithTabIndex").prop("tabindex"), 2, "anchor with href, tabindex set to 2" ); - assert.equal( jQuery("#linkWithNegativeTabIndex").prop("tabindex"), -1, "anchor with href, tabindex set to -1" ); + assert.equal( jQuery( "#linkWithNoTabIndex" ).prop( "tabindex" ), 0, "anchor with href, no tabindex set" ); + assert.equal( jQuery( "#linkWithTabIndex" ).prop( "tabindex" ), 2, "anchor with href, tabindex set to 2" ); + assert.equal( jQuery( "#linkWithNegativeTabIndex" ).prop( "tabindex" ), -1, "anchor with href, tabindex set to -1" ); // anchor without href - assert.equal( jQuery("#linkWithNoHrefWithNoTabIndex").prop("tabindex"), -1, "anchor without href, no tabindex set" ); - assert.equal( jQuery("#linkWithNoHrefWithTabIndex").prop("tabindex"), 1, "anchor without href, tabindex set to 2" ); - assert.equal( jQuery("#linkWithNoHrefWithNegativeTabIndex").prop("tabindex"), -1, "anchor without href, no tabindex set" ); -}); + assert.equal( jQuery( "#linkWithNoHrefWithNoTabIndex" ).prop( "tabindex" ), -1, "anchor without href, no tabindex set" ); + assert.equal( jQuery( "#linkWithNoHrefWithTabIndex" ).prop( "tabindex" ), 1, "anchor without href, tabindex set to 2" ); + assert.equal( jQuery( "#linkWithNoHrefWithNegativeTabIndex" ).prop( "tabindex" ), -1, "anchor without href, no tabindex set" ); +} ); QUnit.test( "prop('tabindex', value)", function( assert ) { assert.expect( 10 ); var clone, - element = jQuery("#divWithNoTabIndex"); + element = jQuery( "#divWithNoTabIndex" ); - assert.equal( element.prop("tabindex"), -1, "start with no tabindex" ); + assert.equal( element.prop( "tabindex" ), -1, "start with no tabindex" ); // set a positive string element.prop( "tabindex", "1" ); - assert.equal( element.prop("tabindex"), 1, "set tabindex to 1 (string)" ); + assert.equal( element.prop( "tabindex" ), 1, "set tabindex to 1 (string)" ); // set a zero string element.prop( "tabindex", "0" ); - assert.equal( element.prop("tabindex"), 0, "set tabindex to 0 (string)" ); + assert.equal( element.prop( "tabindex" ), 0, "set tabindex to 0 (string)" ); // set a negative string element.prop( "tabindex", "-1" ); - assert.equal( element.prop("tabindex"), -1, "set tabindex to -1 (string)" ); + assert.equal( element.prop( "tabindex" ), -1, "set tabindex to -1 (string)" ); // set a positive number element.prop( "tabindex", 1 ); - assert.equal( element.prop("tabindex"), 1, "set tabindex to 1 (number)" ); + assert.equal( element.prop( "tabindex" ), 1, "set tabindex to 1 (number)" ); // set a zero number element.prop( "tabindex", 0 ); - assert.equal( element.prop("tabindex"), 0, "set tabindex to 0 (number)" ); + assert.equal( element.prop( "tabindex" ), 0, "set tabindex to 0 (number)" ); // set a negative number element.prop( "tabindex", -1 ); - assert.equal( element.prop("tabindex"), -1, "set tabindex to -1 (number)" ); + assert.equal( element.prop( "tabindex" ), -1, "set tabindex to -1 (number)" ); - element = jQuery("#linkWithTabIndex"); - assert.equal( element.prop("tabindex"), 2, "start with tabindex 2" ); + element = jQuery( "#linkWithTabIndex" ); + assert.equal( element.prop( "tabindex" ), 2, "start with tabindex 2" ); element.prop( "tabindex", -1 ); - assert.equal( element.prop("tabindex"), -1, "set negative tabindex" ); + assert.equal( element.prop( "tabindex" ), -1, "set negative tabindex" ); clone = element.clone(); clone.prop( "tabindex", 1 ); - assert.equal( clone[ 0 ].getAttribute("tabindex"), "1", "set tabindex on cloned element" ); -}); + assert.equal( clone[ 0 ].getAttribute( "tabindex" ), "1", "set tabindex on cloned element" ); +} ); QUnit.test( "removeProp(String)", function( assert ) { assert.expect( 6 ); - var attributeNode = document.createAttribute("irrelevant"), - commentNode = document.createComment("some comment"), - textNode = document.createTextNode("some text"), + var attributeNode = document.createAttribute( "irrelevant" ), + commentNode = document.createComment( "some comment" ), + textNode = document.createTextNode( "some text" ), obj = {}; assert.strictEqual( - jQuery( "#firstp" ).prop( "nonexisting", "foo" ).removeProp( "nonexisting" )[ 0 ]["nonexisting"], + jQuery( "#firstp" ).prop( "nonexisting", "foo" ).removeProp( "nonexisting" )[ 0 ][ "nonexisting" ], undefined, "removeprop works correctly on DOM element nodes" ); jQuery.each( [ document, obj ], function( i, ele ) { var $ele = jQuery( ele ); - $ele.prop( "nonexisting", "foo" ).removeProp("nonexisting"); - assert.strictEqual( ele["nonexisting"], undefined, "removeProp works correctly on non DOM element nodes (bug #7500)." ); - }); + $ele.prop( "nonexisting", "foo" ).removeProp( "nonexisting" ); + assert.strictEqual( ele[ "nonexisting" ], undefined, "removeProp works correctly on non DOM element nodes (bug #7500)." ); + } ); jQuery.each( [ commentNode, textNode, attributeNode ], function( i, ele ) { var $ele = jQuery( ele ); - $ele.prop( "nonexisting", "foo" ).removeProp("nonexisting"); - assert.strictEqual( ele["nonexisting"], undefined, "removeProp works correctly on non DOM element nodes (bug #7500)." ); - }); -}); + $ele.prop( "nonexisting", "foo" ).removeProp( "nonexisting" ); + assert.strictEqual( ele[ "nonexisting" ], undefined, "removeProp works correctly on non DOM element nodes (bug #7500)." ); + } ); +} ); QUnit.test( "val() after modification", function( assert ) { assert.expect( 1 ); - document.getElementById("text1").value = "bla"; - assert.equal( jQuery("#text1").val(), "bla", "Check for modified value of input element" ); -}); - + document.getElementById( "text1" ).value = "bla"; + 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" ); + 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" ); + 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" ); - assert.equal( jQuery("#select2").val(), "3", "Call val() on a single='single' select" ); + assert.equal( jQuery( "#select2" ).val(), "3", "Call val() on a single='single' select" ); - assert.deepEqual( jQuery("#select3").val(), [ "1", "2" ], "Call val() on a multiple='multiple' select" ); + assert.deepEqual( jQuery( "#select3" ).val(), [ "1", "2" ], "Call val() on a multiple='multiple' select" ); - assert.equal( jQuery("#option3c").val(), "2", "Call val() on a option element with value" ); + assert.equal( jQuery( "#option3c" ).val(), "2", "Call val() on a option element with value" ); - assert.equal( jQuery("#option3a").val(), "", "Call val() on a option element with empty value" ); + assert.equal( jQuery( "#option3a" ).val(), "", "Call val() on a option element with empty value" ); - assert.equal( jQuery("#option3e").val(), "no value", "Call val() on a option element with no value attribute" ); + assert.equal( jQuery( "#option3e" ).val(), "no value", "Call val() on a option element with no value attribute" ); - assert.equal( jQuery("#option3a").val(), "", "Call val() on a option element with no value attribute" ); + assert.equal( jQuery( "#option3a" ).val(), "", "Call val() on a option element with no value attribute" ); - jQuery("#select3").val(""); - assert.deepEqual( jQuery("#select3").val(), [""], "Call val() on a multiple='multiple' select" ); + jQuery( "#select3" ).val( "" ); + assert.deepEqual( jQuery( "#select3" ).val(), [ "" ], "Call val() on a multiple='multiple' select" ); - assert.deepEqual( jQuery("#select4").val(), [], "Call val() on multiple='multiple' select with all disabled options" ); + assert.deepEqual( jQuery( "#select4" ).val(), [], "Call val() on multiple='multiple' select with all disabled options" ); - jQuery("#select4 optgroup").add("#select4 > [disabled]").attr( "disabled", false ); - assert.deepEqual( jQuery("#select4").val(), [ "2", "3" ], "Call val() on multiple='multiple' select with some disabled options" ); + jQuery( "#select4 optgroup" ).add( "#select4 > [disabled]" ).attr( "disabled", false ); + assert.deepEqual( jQuery( "#select4" ).val(), [ "2", "3" ], "Call val() on multiple='multiple' select with some disabled options" ); - jQuery("#select4").attr( "disabled", true ); - assert.deepEqual( jQuery("#select4").val(), [ "2", "3" ], "Call val() on disabled multiple='multiple' select" ); + jQuery( "#select4" ).attr( "disabled", true ); + assert.deepEqual( jQuery( "#select4" ).val(), [ "2", "3" ], "Call val() on disabled multiple='multiple' select" ); - assert.equal( jQuery("#select5").val(), "3", "Check value on ambiguous select." ); + assert.equal( jQuery( "#select5" ).val(), "3", "Check value on ambiguous select." ); - jQuery("#select5").val( 1 ); - assert.equal( jQuery("#select5").val(), "1", "Check value on ambiguous select." ); + jQuery( "#select5" ).val( 1 ); + assert.equal( jQuery( "#select5" ).val(), "1", "Check value on ambiguous select." ); - jQuery("#select5").val( 3 ); - assert.equal( jQuery("#select5").val(), "3", "Check value on ambiguous select." ); + jQuery( "#select5" ).val( 3 ); + assert.equal( jQuery( "#select5" ).val(), "3", "Check value on ambiguous select." ); assert.strictEqual( - jQuery("<select name='select12584' id='select12584'><option value='1' disabled='disabled'>1</option></select>").val(), + jQuery( "<select name='select12584' id='select12584'><option value='1' disabled='disabled'>1</option></select>" ).val(), null, "Select-one with only option disabled (#12584)" ); if ( jQuery.fn.serialize ) { - checks = jQuery("<input type='checkbox' name='test' value='1'/><input type='checkbox' name='test' value='2'/><input type='checkbox' name='test' value=''/><input type='checkbox' name='test'/>").appendTo("#form"); + checks = jQuery( "<input type='checkbox' name='test' value='1'/><input type='checkbox' name='test' value='2'/><input type='checkbox' name='test' value=''/><input type='checkbox' name='test'/>" ).appendTo( "#form" ); assert.deepEqual( checks.serialize(), "", "Get unchecked values." ); assert.equal( checks.eq( 3 ).val(), "on", "Make sure a value of 'on' is provided if none is specified." ); - checks.val([ "2" ]); + checks.val( [ "2" ] ); assert.deepEqual( checks.serialize(), "test=2", "Get a single checked value." ); - checks.val([ "1", "" ]); + checks.val( [ "1", "" ] ); assert.deepEqual( checks.serialize(), "test=1&test=", "Get multiple checked values." ); - checks.val([ "", "2" ]); + checks.val( [ "", "2" ] ); assert.deepEqual( checks.serialize(), "test=2&test=", "Get multiple checked values." ); - checks.val([ "1", "on" ]); + checks.val( [ "1", "on" ] ); assert.deepEqual( checks.serialize(), "test=1&test=on", "Get multiple checked values." ); checks.remove(); } - $button = jQuery("<button value='foobar'>text</button>").insertAfter("#button"); + $button = jQuery( "<button value='foobar'>text</button>" ).insertAfter( "#button" ); assert.equal( $button.val(), "foobar", "Value retrieval on a button does not return innerHTML" ); - assert.equal( $button.val("baz").html(), "text", "Setting the value does not change innerHTML" ); + assert.equal( $button.val( "baz" ).html(), "text", "Setting the value does not change innerHTML" ); - assert.equal( jQuery("<option/>").val("test").attr("value"), "test", "Setting value sets the value attribute" ); -}); + assert.equal( jQuery( "<option/>" ).val( "test" ).attr( "value" ), "test", "Setting value sets the value attribute" ); +} ); -QUnit.test("val() with non-matching values on dropdown list", function( assert ) { +QUnit.test( "val() with non-matching values on dropdown list", function( assert ) { assert.expect( 3 ); - jQuery("#select5").val( "" ); - assert.equal( jQuery("#select5").val(), null, "Non-matching set on select-one" ); + jQuery( "#select5" ).val( "" ); + assert.equal( jQuery( "#select5" ).val(), null, "Non-matching set on select-one" ); - var select6 = jQuery("<select multiple id=\"select6\"><option value=\"1\">A</option><option value=\"2\">B</option></select>").appendTo("#form"); - jQuery(select6).val( "nothing" ); - assert.equal( jQuery(select6).val(), null, "Non-matching set (single value) on select-multiple" ); + var select6 = jQuery( "<select multiple id=\"select6\"><option value=\"1\">A</option><option value=\"2\">B</option></select>" ).appendTo( "#form" ); + jQuery( select6 ).val( "nothing" ); + assert.equal( jQuery( select6 ).val(), null, "Non-matching set (single value) on select-multiple" ); - jQuery(select6).val( ["nothing1", "nothing2"] ); - assert.equal( jQuery(select6).val(), null, "Non-matching set (array of values) on select-multiple" ); + jQuery( select6 ).val( [ "nothing1", "nothing2" ] ); + assert.equal( jQuery( select6 ).val(), null, "Non-matching set (array of values) on select-multiple" ); select6.remove(); -}); +} ); -if ( "value" in document.createElement("meter") && - "value" in document.createElement("progress") ) { +if ( "value" in document.createElement( "meter" ) && + "value" in document.createElement( "progress" ) ) { QUnit.test( "val() respects numbers without exception (Bug #9319)", function( assert ) { assert.expect( 4 ); - var $meter = jQuery("<meter min='0' max='10' value='5.6'></meter>"), - $progress = jQuery("<progress max='10' value='1.5'></progress>"); + var $meter = jQuery( "<meter min='0' max='10' value='5.6'></meter>" ), + $progress = jQuery( "<progress max='10' value='1.5'></progress>" ); try { assert.equal( typeof $meter.val(), "number", "meter, returns a number and does not throw exception" ); @@ -920,47 +921,47 @@ if ( "value" in document.createElement("meter") && assert.equal( typeof $progress.val(), "number", "progress, returns a number and does not throw exception" ); assert.equal( $progress.val(), $progress[ 0 ].value, "progress, api matches host and does not throw exception" ); - } catch( e ) {} + } catch ( e ) {} $meter.remove(); $progress.remove(); - }); + } ); } var testVal = function( valueObj, assert ) { assert.expect( 9 ); - jQuery("#text1").val( valueObj("test") ); - assert.equal( document.getElementById("text1").value, "test", "Check for modified (via val(String)) value of input element" ); + jQuery( "#text1" ).val( valueObj( "test" ) ); + assert.equal( document.getElementById( "text1" ).value, "test", "Check for modified (via val(String)) value of input element" ); - jQuery("#text1").val( valueObj( undefined ) ); - assert.equal( document.getElementById("text1").value, "", "Check for modified (via val(undefined)) value of input element" ); + jQuery( "#text1" ).val( valueObj( undefined ) ); + assert.equal( document.getElementById( "text1" ).value, "", "Check for modified (via val(undefined)) value of input element" ); - jQuery("#text1").val( valueObj( 67 ) ); - assert.equal( document.getElementById("text1").value, "67", "Check for modified (via val(Number)) value of input element" ); + jQuery( "#text1" ).val( valueObj( 67 ) ); + assert.equal( document.getElementById( "text1" ).value, "67", "Check for modified (via val(Number)) value of input element" ); - jQuery("#text1").val( valueObj( null ) ); - assert.equal( document.getElementById("text1").value, "", "Check for modified (via val(null)) value of input element" ); + jQuery( "#text1" ).val( valueObj( null ) ); + assert.equal( document.getElementById( "text1" ).value, "", "Check for modified (via val(null)) value of input element" ); var j, $select = jQuery( "<select multiple><option value='1'/><option value='2'/></select>" ), - $select1 = jQuery("#select1"); + $select1 = jQuery( "#select1" ); - $select1.val( valueObj("3") ); + $select1.val( valueObj( "3" ) ); assert.equal( $select1.val(), "3", "Check for modified (via val(String)) value of select element" ); $select1.val( valueObj( 2 ) ); assert.equal( $select1.val(), "2", "Check for modified (via val(Number)) value of select element" ); - $select1.append("<option value='4'>four</option>"); + $select1.append( "<option value='4'>four</option>" ); $select1.val( valueObj( 4 ) ); assert.equal( $select1.val(), "4", "Should be possible to set the val() to a newly created option" ); // using contents will get comments regular, text, and comment nodes - j = jQuery("#nonnodes").contents(); + j = jQuery( "#nonnodes" ).contents(); j.val( valueObj( "asdf" ) ); assert.equal( j.val(), "asdf", "Check node,textnode,comment with val()" ); - j.removeAttr("value"); + j.removeAttr( "value" ); $select.val( valueObj( [ "1", "2" ] ) ); assert.deepEqual( $select.val(), [ "1", "2" ], "Should set array of values" ); @@ -968,407 +969,406 @@ var testVal = function( valueObj, assert ) { QUnit.test( "val(String/Number)", function( assert ) { testVal( bareObj, assert ); -}); +} ); QUnit.test( "val(Function)", function( assert ) { testVal( functionReturningObj, assert ); -}); +} ); QUnit.test( "val(Array of Numbers) (Bug #7123)", function( assert ) { assert.expect( 4 ); - jQuery("#form").append("<input type='checkbox' name='arrayTest' value='1' /><input type='checkbox' name='arrayTest' value='2' /><input type='checkbox' name='arrayTest' value='3' checked='checked' /><input type='checkbox' name='arrayTest' value='4' />"); - var elements = jQuery("input[name=arrayTest]").val([ 1, 2 ]); + jQuery( "#form" ).append( "<input type='checkbox' name='arrayTest' value='1' /><input type='checkbox' name='arrayTest' value='2' /><input type='checkbox' name='arrayTest' value='3' checked='checked' /><input type='checkbox' name='arrayTest' value='4' />" ); + var elements = jQuery( "input[name=arrayTest]" ).val( [ 1, 2 ] ); assert.ok( elements[ 0 ].checked, "First element was checked" ); assert.ok( elements[ 1 ].checked, "Second element was checked" ); assert.ok( !elements[ 2 ].checked, "Third element was unchecked" ); assert.ok( !elements[ 3 ].checked, "Fourth element remained unchecked" ); elements.remove(); -}); +} ); QUnit.test( "val(Function) with incoming value", function( assert ) { assert.expect( 10 ); - var oldVal = jQuery("#text1").val(); + var oldVal = jQuery( "#text1" ).val(); - jQuery("#text1").val(function( i, val ) { + jQuery( "#text1" ).val( function( i, val ) { assert.equal( val, oldVal, "Make sure the incoming value is correct." ); return "test"; - }); + } ); - assert.equal( document.getElementById("text1").value, "test", "Check for modified (via val(String)) value of input element" ); + assert.equal( document.getElementById( "text1" ).value, "test", "Check for modified (via val(String)) value of input element" ); - oldVal = jQuery("#text1").val(); + oldVal = jQuery( "#text1" ).val(); - jQuery("#text1").val(function( i, val ) { + jQuery( "#text1" ).val( function( i, val ) { assert.equal( val, oldVal, "Make sure the incoming value is correct." ); return 67; - }); + } ); - assert.equal( document.getElementById("text1").value, "67", "Check for modified (via val(Number)) value of input element" ); + assert.equal( document.getElementById( "text1" ).value, "67", "Check for modified (via val(Number)) value of input element" ); - oldVal = jQuery("#select1").val(); + oldVal = jQuery( "#select1" ).val(); - jQuery("#select1").val(function( i, val ) { + jQuery( "#select1" ).val( function( i, val ) { assert.equal( val, oldVal, "Make sure the incoming value is correct." ); return "3"; - }); + } ); - assert.equal( jQuery("#select1").val(), "3", "Check for modified (via val(String)) value of select element" ); + assert.equal( jQuery( "#select1" ).val(), "3", "Check for modified (via val(String)) value of select element" ); - oldVal = jQuery("#select1").val(); + oldVal = jQuery( "#select1" ).val(); - jQuery("#select1").val(function( i, val ) { + jQuery( "#select1" ).val( function( i, val ) { assert.equal( val, oldVal, "Make sure the incoming value is correct." ); return 2; - }); + } ); - assert.equal( jQuery("#select1").val(), "2", "Check for modified (via val(Number)) value of select element" ); + assert.equal( jQuery( "#select1" ).val(), "2", "Check for modified (via val(Number)) value of select element" ); - jQuery("#select1").append("<option value='4'>four</option>"); + jQuery( "#select1" ).append( "<option value='4'>four</option>" ); - oldVal = jQuery("#select1").val(); + oldVal = jQuery( "#select1" ).val(); - jQuery("#select1").val(function( i, val ) { + jQuery( "#select1" ).val( function( i, val ) { assert.equal( val, oldVal, "Make sure the incoming value is correct." ); return 4; - }); + } ); - assert.equal( jQuery("#select1").val(), "4", "Should be possible to set the val() to a newly created option" ); -}); + assert.equal( jQuery( "#select1" ).val(), "4", "Should be possible to set the val() to a newly created option" ); +} ); // testing if a form.reset() breaks a subsequent call to a select element's .val() (in IE only) QUnit.test( "val(select) after form.reset() (Bug #2551)", function( assert ) { assert.expect( 3 ); - jQuery("<form id='kk' name='kk'><select id='kkk'><option value='cf'>cf</option><option value='gf'>gf</option></select></form>").appendTo("#qunit-fixture"); + jQuery( "<form id='kk' name='kk'><select id='kkk'><option value='cf'>cf</option><option value='gf'>gf</option></select></form>" ).appendTo( "#qunit-fixture" ); - jQuery("#kkk").val("gf"); + jQuery( "#kkk" ).val( "gf" ); - document["kk"].reset(); + document[ "kk" ].reset(); - assert.equal( jQuery("#kkk")[ 0 ].value, "cf", "Check value of select after form reset." ); - assert.equal( jQuery("#kkk").val(), "cf", "Check value of select after form reset." ); + assert.equal( jQuery( "#kkk" )[ 0 ].value, "cf", "Check value of select after form reset." ); + assert.equal( jQuery( "#kkk" ).val(), "cf", "Check value of select after form reset." ); // re-verify the multi-select is not broken (after form.reset) by our fix for single-select - assert.deepEqual( jQuery("#select3").val(), ["1", "2"], "Call val() on a multiple='multiple' select" ); + assert.deepEqual( jQuery( "#select3" ).val(), [ "1", "2" ], "Call val() on a multiple='multiple' select" ); - jQuery("#kk").remove(); -}); + jQuery( "#kk" ).remove(); +} ); var testAddClass = function( valueObj, assert ) { assert.expect( 9 ); var pass, j, i, - div = jQuery("#qunit-fixture div"); - div.addClass( valueObj("test") ); + div = jQuery( "#qunit-fixture div" ); + div.addClass( valueObj( "test" ) ); pass = true; for ( i = 0; i < div.length; i++ ) { - if ( !~div.get( i ).className.indexOf("test") ) { + if ( !~div.get( i ).className.indexOf( "test" ) ) { pass = false; } } assert.ok( pass, "Add Class" ); // using contents will get regular, text, and comment nodes - j = jQuery("#nonnodes").contents(); - j.addClass( valueObj("asdf") ); - assert.ok( j.hasClass("asdf"), "Check node,textnode,comment for addClass" ); + j = jQuery( "#nonnodes" ).contents(); + j.addClass( valueObj( "asdf" ) ); + assert.ok( j.hasClass( "asdf" ), "Check node,textnode,comment for addClass" ); - div = jQuery("<div/>"); + div = jQuery( "<div/>" ); - div.addClass( valueObj("test") ); - assert.equal( div.attr("class"), "test", "Make sure there's no extra whitespace." ); + div.addClass( valueObj( "test" ) ); + assert.equal( div.attr( "class" ), "test", "Make sure there's no extra whitespace." ); div.attr( "class", " foo" ); - div.addClass( valueObj("test") ); - assert.equal( div.attr("class"), "foo test", "Make sure there's no extra whitespace." ); + div.addClass( valueObj( "test" ) ); + assert.equal( div.attr( "class" ), "foo test", "Make sure there's no extra whitespace." ); div.attr( "class", "foo" ); - div.addClass( valueObj("bar baz") ); - assert.equal( div.attr("class"), "foo bar baz", "Make sure there isn't too much trimming." ); + div.addClass( valueObj( "bar baz" ) ); + assert.equal( div.attr( "class" ), "foo bar baz", "Make sure there isn't too much trimming." ); div.removeClass(); - div.addClass( valueObj("foo") ).addClass( valueObj("foo") ); - assert.equal( div.attr("class"), "foo", "Do not add the same class twice in separate calls." ); + div.addClass( valueObj( "foo" ) ).addClass( valueObj( "foo" ) ); + assert.equal( div.attr( "class" ), "foo", "Do not add the same class twice in separate calls." ); - div.addClass( valueObj("fo") ); - assert.equal( div.attr("class"), "foo fo", "Adding a similar class does not get interrupted." ); - div.removeClass().addClass("wrap2"); - assert.ok( div.addClass("wrap").hasClass("wrap"), "Can add similarly named classes"); + div.addClass( valueObj( "fo" ) ); + assert.equal( div.attr( "class" ), "foo fo", "Adding a similar class does not get interrupted." ); + div.removeClass().addClass( "wrap2" ); + assert.ok( div.addClass( "wrap" ).hasClass( "wrap" ), "Can add similarly named classes" ); div.removeClass(); - div.addClass( valueObj("bar bar") ); - assert.equal( div.attr("class"), "bar", "Do not add the same class twice in the same call." ); + div.addClass( valueObj( "bar bar" ) ); + assert.equal( div.attr( "class" ), "bar", "Do not add the same class twice in the same call." ); }; QUnit.test( "addClass(String)", function( assert ) { testAddClass( bareObj, assert ); -}); +} ); QUnit.test( "addClass(Function)", function( assert ) { testAddClass( functionReturningObj, assert ); -}); +} ); QUnit.test( "addClass(Function) with incoming value", function( assert ) { assert.expect( 52 ); var pass, i, - div = jQuery("#qunit-fixture div"), - old = div.map(function() { - return jQuery(this).attr("class") || ""; - }); + div = jQuery( "#qunit-fixture div" ), + old = div.map( function() { + return jQuery( this ).attr( "class" ) || ""; + } ); - div.addClass(function( i, val ) { + div.addClass( function( i, val ) { if ( this.id !== "_firebugConsole" ) { assert.equal( val, old[ i ], "Make sure the incoming value is correct." ); return "test"; } - }); + } ); pass = true; for ( i = 0; i < div.length; i++ ) { - if ( div.get(i).className.indexOf("test") === -1 ) { + if ( div.get( i ).className.indexOf( "test" ) === -1 ) { pass = false; } } assert.ok( pass, "Add Class" ); -}); +} ); var testRemoveClass = function( valueObj, assert ) { assert.expect( 8 ); - var $set = jQuery("#qunit-fixture div"), - div = document.createElement("div"); + var $set = jQuery( "#qunit-fixture div" ), + div = document.createElement( "div" ); - $set.addClass("test").removeClass( valueObj("test") ); + $set.addClass( "test" ).removeClass( valueObj( "test" ) ); - assert.ok( !$set.is(".test"), "Remove Class" ); + assert.ok( !$set.is( ".test" ), "Remove Class" ); - $set.addClass("test").addClass("foo").addClass("bar"); - $set.removeClass( valueObj("test") ).removeClass( valueObj("bar") ).removeClass( valueObj("foo") ); + $set.addClass( "test" ).addClass( "foo" ).addClass( "bar" ); + $set.removeClass( valueObj( "test" ) ).removeClass( valueObj( "bar" ) ).removeClass( valueObj( "foo" ) ); - assert.ok( !$set.is(".test,.bar,.foo"), "Remove multiple classes" ); + assert.ok( !$set.is( ".test,.bar,.foo" ), "Remove multiple classes" ); // Make sure that a null value doesn't cause problems - $set.eq( 0 ).addClass("expected").removeClass( valueObj( null ) ); - assert.ok( $set.eq( 0 ).is(".expected"), "Null value passed to removeClass" ); + $set.eq( 0 ).addClass( "expected" ).removeClass( valueObj( null ) ); + assert.ok( $set.eq( 0 ).is( ".expected" ), "Null value passed to removeClass" ); - $set.eq( 0 ).addClass("expected").removeClass( valueObj("") ); - assert.ok( $set.eq( 0 ).is(".expected"), "Empty string passed to removeClass" ); + $set.eq( 0 ).addClass( "expected" ).removeClass( valueObj( "" ) ); + assert.ok( $set.eq( 0 ).is( ".expected" ), "Empty string passed to removeClass" ); // using contents will get regular, text, and comment nodes - $set = jQuery("#nonnodes").contents(); - $set.removeClass( valueObj("asdf") ); - assert.ok( !$set.hasClass("asdf"), "Check node,textnode,comment for removeClass" ); - + $set = jQuery( "#nonnodes" ).contents(); + $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" ); + jQuery( div ).removeClass( valueObj( "foo" ) ); + assert.strictEqual( jQuery( div ).attr( "class" ), undefined, "removeClass doesn't create a class attribute" ); div.className = " test foo "; - jQuery( div ).removeClass( valueObj("foo") ); + jQuery( div ).removeClass( valueObj( "foo" ) ); assert.equal( div.className, "test", "Make sure remaining className is trimmed." ); div.className = " test "; - jQuery( div ).removeClass( valueObj("test") ); + jQuery( div ).removeClass( valueObj( "test" ) ); assert.equal( div.className, "", "Make sure there is nothing left after everything is removed." ); }; QUnit.test( "removeClass(String) - simple", function( assert ) { testRemoveClass( bareObj, assert ); -}); +} ); QUnit.test( "removeClass(Function) - simple", function( assert ) { testRemoveClass( functionReturningObj, assert ); -}); +} ); QUnit.test( "removeClass(Function) with incoming value", function( assert ) { assert.expect( 52 ); - var $divs = jQuery("#qunit-fixture div").addClass("test"), old = $divs.map(function() { - return jQuery( this ).attr("class"); - }); + var $divs = jQuery( "#qunit-fixture div" ).addClass( "test" ), old = $divs.map( function() { + return jQuery( this ).attr( "class" ); + } ); - $divs.removeClass(function( i, val ) { + $divs.removeClass( function( i, val ) { if ( this.id !== "_firebugConsole" ) { assert.equal( val, old[ i ], "Make sure the incoming value is correct." ); return "test"; } - }); + } ); - assert.ok( !$divs.is(".test"), "Remove Class" ); -}); + assert.ok( !$divs.is( ".test" ), "Remove Class" ); +} ); QUnit.test( "removeClass() removes duplicates", function( assert ) { assert.expect( 1 ); - var $div = jQuery( jQuery.parseHTML("<div class='x x x'></div>") ); + var $div = jQuery( jQuery.parseHTML( "<div class='x x x'></div>" ) ); - $div.removeClass("x"); + $div.removeClass( "x" ); - assert.ok( !$div.hasClass("x"), "Element with multiple same classes does not escape the wrath of removeClass()" ); -}); + assert.ok( !$div.hasClass( "x" ), "Element with multiple same classes does not escape the wrath of removeClass()" ); +} ); -QUnit.test("removeClass(undefined) is a no-op", function( assert ) { +QUnit.test( "removeClass(undefined) is a no-op", function( assert ) { assert.expect( 1 ); - var $div = jQuery("<div class='base second'></div>"); + var $div = jQuery( "<div class='base second'></div>" ); $div.removeClass( undefined ); - assert.ok( $div.hasClass("base") && $div.hasClass("second"), "Element still has classes after removeClass(undefined)" ); -}); + assert.ok( $div.hasClass( "base" ) && $div.hasClass( "second" ), "Element still has classes after removeClass(undefined)" ); +} ); var testToggleClass = function( valueObj, assert ) { assert.expect( 17 ); - var e = jQuery("#firstp"); - assert.ok( !e.is(".test"), "Assert class not present" ); - e.toggleClass( valueObj("test") ); - assert.ok( e.is(".test"), "Assert class present" ); - e.toggleClass( valueObj("test") ); - assert.ok( !e.is(".test"), "Assert class not present" ); + var e = jQuery( "#firstp" ); + assert.ok( !e.is( ".test" ), "Assert class not present" ); + e.toggleClass( valueObj( "test" ) ); + assert.ok( e.is( ".test" ), "Assert class present" ); + e.toggleClass( valueObj( "test" ) ); + assert.ok( !e.is( ".test" ), "Assert class not present" ); // class name with a boolean - e.toggleClass( valueObj("test"), false ); - assert.ok( !e.is(".test"), "Assert class not present" ); - e.toggleClass( valueObj("test"), true ); - assert.ok( e.is(".test"), "Assert class present" ); - e.toggleClass( valueObj("test"), false ); - assert.ok( !e.is(".test"), "Assert class not present" ); + e.toggleClass( valueObj( "test" ), false ); + assert.ok( !e.is( ".test" ), "Assert class not present" ); + e.toggleClass( valueObj( "test" ), true ); + assert.ok( e.is( ".test" ), "Assert class present" ); + e.toggleClass( valueObj( "test" ), false ); + assert.ok( !e.is( ".test" ), "Assert class not present" ); // multiple class names - e.addClass("testA testB"); - assert.ok( e.is(".testA.testB"), "Assert 2 different classes present" ); - e.toggleClass( valueObj("testB testC") ); - assert.ok( (e.is(".testA.testC") && !e.is(".testB")), "Assert 1 class added, 1 class removed, and 1 class kept" ); - e.toggleClass( valueObj("testA testC") ); - assert.ok( (!e.is(".testA") && !e.is(".testB") && !e.is(".testC")), "Assert no class present" ); + e.addClass( "testA testB" ); + assert.ok( e.is( ".testA.testB" ), "Assert 2 different classes present" ); + e.toggleClass( valueObj( "testB testC" ) ); + assert.ok( ( e.is( ".testA.testC" ) && !e.is( ".testB" ) ), "Assert 1 class added, 1 class removed, and 1 class kept" ); + e.toggleClass( valueObj( "testA testC" ) ); + assert.ok( ( !e.is( ".testA" ) && !e.is( ".testB" ) && !e.is( ".testC" ) ), "Assert no class present" ); // toggleClass storage e.toggleClass( true ); assert.ok( e[ 0 ].className === "", "Assert class is empty (data was empty)" ); - e.addClass("testD testE"); - assert.ok( e.is(".testD.testE"), "Assert class present" ); + e.addClass( "testD testE" ); + assert.ok( e.is( ".testD.testE" ), "Assert class present" ); e.toggleClass(); - assert.ok( !e.is(".testD.testE"), "Assert class not present" ); - assert.ok( jQuery._data(e[ 0 ], "__className__") === "testD testE", "Assert data was stored" ); + assert.ok( !e.is( ".testD.testE" ), "Assert class not present" ); + assert.ok( jQuery._data( e[ 0 ], "__className__" ) === "testD testE", "Assert data was stored" ); e.toggleClass(); - assert.ok( e.is(".testD.testE"), "Assert class present (restored from data)" ); + assert.ok( e.is( ".testD.testE" ), "Assert class present (restored from data)" ); e.toggleClass( false ); - assert.ok( !e.is(".testD.testE"), "Assert class not present" ); + assert.ok( !e.is( ".testD.testE" ), "Assert class not present" ); e.toggleClass( true ); - assert.ok( e.is(".testD.testE"), "Assert class present (restored from data)" ); + assert.ok( e.is( ".testD.testE" ), "Assert class present (restored from data)" ); e.toggleClass(); e.toggleClass( false ); e.toggleClass(); - assert.ok( e.is(".testD.testE"), "Assert class present (restored from data)" ); + assert.ok( e.is( ".testD.testE" ), "Assert class present (restored from data)" ); // Cleanup - e.removeClass("testD"); + e.removeClass( "testD" ); QUnit.expectJqData( this, e[ 0 ], "__className__" ); }; QUnit.test( "toggleClass(String|boolean|undefined[, boolean])", function( assert ) { testToggleClass( bareObj, assert ); -}); +} ); QUnit.test( "toggleClass(Function[, boolean])", function( assert ) { testToggleClass( functionReturningObj, assert ); -}); +} ); QUnit.test( "toggleClass(Function[, boolean]) with incoming value", function( assert ) { assert.expect( 14 ); - var e = jQuery("#firstp"), - old = e.attr("class") || ""; + var e = jQuery( "#firstp" ), + old = e.attr( "class" ) || ""; - assert.ok( !e.is(".test"), "Assert class not present" ); + assert.ok( !e.is( ".test" ), "Assert class not present" ); - e.toggleClass(function( i, val ) { + e.toggleClass( function( i, val ) { assert.equal( old, val, "Make sure the incoming value is correct." ); return "test"; - }); - assert.ok( e.is(".test"), "Assert class present" ); + } ); + assert.ok( e.is( ".test" ), "Assert class present" ); - old = e.attr("class"); + old = e.attr( "class" ); - e.toggleClass(function( i, val ) { + e.toggleClass( function( i, val ) { assert.equal( old, val, "Make sure the incoming value is correct." ); return "test"; - }); - assert.ok( !e.is(".test"), "Assert class not present" ); + } ); + assert.ok( !e.is( ".test" ), "Assert class not present" ); - old = e.attr("class") || ""; + old = e.attr( "class" ) || ""; // class name with a boolean - e.toggleClass(function( i, val, state ) { + e.toggleClass( function( i, val, state ) { assert.equal( old, val, "Make sure the incoming value is correct." ); assert.equal( state, false, "Make sure that the state is passed in." ); return "test"; }, false ); - assert.ok( !e.is(".test"), "Assert class not present" ); + assert.ok( !e.is( ".test" ), "Assert class not present" ); - old = e.attr("class") || ""; + old = e.attr( "class" ) || ""; - e.toggleClass(function( i, val, state ) { + e.toggleClass( function( i, val, state ) { assert.equal( old, val, "Make sure the incoming value is correct." ); assert.equal( state, true, "Make sure that the state is passed in." ); return "test"; }, true ); - assert.ok( e.is(".test"), "Assert class present" ); + assert.ok( e.is( ".test" ), "Assert class present" ); - old = e.attr("class"); + old = e.attr( "class" ); - e.toggleClass(function( i, val, state ) { + e.toggleClass( function( i, val, state ) { assert.equal( old, val, "Make sure the incoming value is correct." ); assert.equal( state, false, "Make sure that the state is passed in." ); return "test"; }, false ); - assert.ok( !e.is(".test"), "Assert class not present" ); -}); + assert.ok( !e.is( ".test" ), "Assert class not present" ); +} ); QUnit.test( "addClass, removeClass, hasClass", function( assert ) { assert.expect( 17 ); - var jq = jQuery("<p>Hi</p>"), x = jq[ 0 ]; + var jq = jQuery( "<p>Hi</p>" ), x = jq[ 0 ]; - jq.addClass("hi"); + jq.addClass( "hi" ); assert.equal( x.className, "hi", "Check single added class" ); - jq.addClass("foo bar"); + jq.addClass( "foo bar" ); assert.equal( x.className, "hi foo bar", "Check more added classes" ); jq.removeClass(); assert.equal( x.className, "", "Remove all classes" ); - jq.addClass("hi foo bar"); - jq.removeClass("foo"); + jq.addClass( "hi foo bar" ); + jq.removeClass( "foo" ); assert.equal( x.className, "hi bar", "Check removal of one class" ); - assert.ok( jq.hasClass("hi"), "Check has1" ); - assert.ok( jq.hasClass("bar"), "Check has2" ); - - jq = jQuery("<p class='class1\nclass2\tcla.ss3\n\rclass4'></p>"); - - assert.ok( jq.hasClass("class1"), "Check hasClass with line feed" ); - assert.ok( jq.is(".class1"), "Check is with line feed" ); - assert.ok( jq.hasClass("class2"), "Check hasClass with tab" ); - assert.ok( jq.is(".class2"), "Check is with tab" ); - assert.ok( jq.hasClass("cla.ss3"), "Check hasClass with dot" ); - assert.ok( jq.hasClass("class4"), "Check hasClass with carriage return" ); - assert.ok( jq.is(".class4"), "Check is with carriage return" ); - - jq.removeClass("class2"); - assert.ok( jq.hasClass("class2") === false, "Check the class has been properly removed" ); - jq.removeClass("cla"); - assert.ok( jq.hasClass("cla.ss3"), "Check the dotted class has not been removed" ); - jq.removeClass("cla.ss3"); - assert.ok( jq.hasClass("cla.ss3") === false, "Check the dotted class has been removed" ); - jq.removeClass("class4"); - assert.ok( jq.hasClass("class4") === false, "Check the class has been properly removed" ); -}); + assert.ok( jq.hasClass( "hi" ), "Check has1" ); + assert.ok( jq.hasClass( "bar" ), "Check has2" ); + + jq = jQuery( "<p class='class1\nclass2\tcla.ss3\n\rclass4'></p>" ); + + assert.ok( jq.hasClass( "class1" ), "Check hasClass with line feed" ); + assert.ok( jq.is( ".class1" ), "Check is with line feed" ); + assert.ok( jq.hasClass( "class2" ), "Check hasClass with tab" ); + assert.ok( jq.is( ".class2" ), "Check is with tab" ); + assert.ok( jq.hasClass( "cla.ss3" ), "Check hasClass with dot" ); + assert.ok( jq.hasClass( "class4" ), "Check hasClass with carriage return" ); + assert.ok( jq.is( ".class4" ), "Check is with carriage return" ); + + jq.removeClass( "class2" ); + assert.ok( jq.hasClass( "class2" ) === false, "Check the class has been properly removed" ); + jq.removeClass( "cla" ); + assert.ok( jq.hasClass( "cla.ss3" ), "Check the dotted class has not been removed" ); + jq.removeClass( "cla.ss3" ); + assert.ok( jq.hasClass( "cla.ss3" ) === false, "Check the dotted class has been removed" ); + jq.removeClass( "class4" ); + assert.ok( jq.hasClass( "class4" ) === false, "Check the class has been properly removed" ); +} ); QUnit.test( "addClass, removeClass, hasClass on many elements", function( assert ) { assert.expect( 19 ); @@ -1411,17 +1411,17 @@ QUnit.test( "addClass, removeClass, hasClass on many elements", function( assert assert.ok( !jQuery( "<p class='hi0'>p0</p><p class='hi1'>p1</p><p class='hi2'>p2</p>" ).hasClass( "hi" ), "Did not find a class when not present" ); -}); +} ); QUnit.test( "contents().hasClass() returns correct values", function( assert ) { assert.expect( 2 ); - var $div = jQuery("<div><span class='foo'></span><!-- comment -->text</div>"), + var $div = jQuery( "<div><span class='foo'></span><!-- comment -->text</div>" ), $contents = $div.contents(); - assert.ok( $contents.hasClass("foo"), "Found 'foo' in $contents" ); - assert.ok( !$contents.hasClass("undefined"), "Did not find 'undefined' in $contents (correctly)" ); -}); + assert.ok( $contents.hasClass( "foo" ), "Found 'foo' in $contents" ); + assert.ok( !$contents.hasClass( "undefined" ), "Did not find 'undefined' in $contents (correctly)" ); +} ); QUnit.test( "hasClass correctly interprets non-space separators (#13835)", function( assert ) { assert.expect( 4 ); @@ -1435,23 +1435,23 @@ QUnit.test( "hasClass correctly interprets non-space separators (#13835)", funct }, classes = jQuery.map( map, function( separator, label ) { return " " + separator + label + separator + " "; - }), + } ), $div = jQuery( "<div class='" + classes + "'></div>" ); jQuery.each( map, function( label ) { assert.ok( $div.hasClass( label ), label.replace( "-", " " ) ); - }); -}); + } ); +} ); QUnit.test( "coords returns correct values in IE6/IE7, see #10828", function( assert ) { assert.expect( 1 ); var area, - map = jQuery("<map />"); + map = jQuery( "<map />" ); - area = map.html("<area shape='rect' coords='0,0,0,0' href='#' alt='a' />").find("area"); - assert.equal( area.attr("coords"), "0,0,0,0", "did not retrieve coords correctly" ); -}); + area = map.html( "<area shape='rect' coords='0,0,0,0' href='#' alt='a' />" ).find( "area" ); + assert.equal( area.attr( "coords" ), "0,0,0,0", "did not retrieve coords correctly" ); +} ); QUnit.test( "should not throw at $(option).val() (#14686)", function( assert ) { assert.expect( 1 ); @@ -1462,12 +1462,12 @@ QUnit.test( "should not throw at $(option).val() (#14686)", function( assert ) { } catch ( _ ) { assert.ok( false ); } -}); +} ); QUnit.test( "option value not trimmed when setting via parent select", function( assert ) { assert.expect( 1 ); assert.equal( jQuery( "<select><option> 2</option></select>" ).val( "2" ).val(), "2" ); -}); +} ); QUnit.test( "Insignificant white space returned for $(option).val() (#14858)", function( assert ) { expect ( 3 ); @@ -1480,7 +1480,7 @@ QUnit.test( "Insignificant white space returned for $(option).val() (#14858)", f val = jQuery( "<option> test </option>" ).val(); assert.equal( val.length, 4, "insignificant white-space returned for value" ); -}); +} ); QUnit.test( "SVG class manipulation (gh-2199)", function( assert ) { assert.expect( 12 ); @@ -1489,7 +1489,7 @@ QUnit.test( "SVG class manipulation (gh-2199)", function( assert ) { return document.createElementNS( "http://www.w3.org/2000/svg", nodeName ); } - jQuery.each([ + jQuery.each( [ "svg", "rect", "g" @@ -1507,5 +1507,5 @@ QUnit.test( "SVG class manipulation (gh-2199)", function( assert ) { elem.toggleClass( "awesome" ); assert.ok( !elem.hasClass( "awesome" ), "SVG element (" + this + ") toggles the class off" ); - }); -}); + } ); +} ); diff --git a/test/unit/callbacks.js b/test/unit/callbacks.js index af33174d4..c6c379ded 100644 --- a/test/unit/callbacks.js +++ b/test/unit/callbacks.js @@ -1,8 +1,8 @@ QUnit.module( "callbacks", { teardown: moduleTeardown -}); +} ); -(function() { +( function() { var output, addToOutput = function( string ) { @@ -10,9 +10,9 @@ var output, output += string; }; }, - outputA = addToOutput("A"), - outputB = addToOutput("B"), - outputC = addToOutput("C"), + outputA = addToOutput( "A" ), + outputB = addToOutput( "B" ), + outputC = addToOutput( "C" ), tests = { "": "XABC X XABCABCC X XBB X XABA X XX", "once": "XABC X X X X X XABA X XX", @@ -54,11 +54,11 @@ jQuery.each( tests, function( strFlags, resultString ) { if ( this.length ) { objectFlags[ this ] = true; } - }); + } ); jQuery.each( filters, function( filterLabel ) { - jQuery.each({ + jQuery.each( { "string": strFlags, "object": objectFlags }, function( flagsTypes, flags ) { @@ -76,20 +76,20 @@ jQuery.each( tests, function( strFlags, resultString ) { assert.strictEqual( cblist.locked(), false, ".locked() initially false" ); assert.strictEqual( cblist.disabled(), false, ".disabled() initially false" ); assert.strictEqual( cblist.fired(), false, ".fired() initially false" ); - cblist.add(function( str ) { + cblist.add( function( str ) { output += str; - }); + } ); assert.strictEqual( cblist.fired(), false, ".fired() still false after .add" ); cblist.fire( "A" ); assert.strictEqual( output, "XA", "Basic binding and firing" ); assert.strictEqual( cblist.fired(), true, ".fired() detects firing" ); output = "X"; cblist.disable(); - cblist.add(function( str ) { + cblist.add( function( str ) { output += str; - }); + } ); assert.strictEqual( output, "X", "Adding a callback after disabling" ); - cblist.fire("A"); + cblist.fire( "A" ); assert.strictEqual( output, "X", "Firing after disabling" ); assert.strictEqual( cblist.disabled(), true, ".disabled() becomes true" ); assert.strictEqual( cblist.locked(), true, "disabling locks" ); @@ -113,20 +113,20 @@ jQuery.each( tests, function( strFlags, resultString ) { // Basic binding and firing (context, arguments) output = "X"; cblist = jQuery.Callbacks( flags ); - cblist.add(function() { + cblist.add( function() { assert.equal( this, window, "Basic binding and firing (context)" ); output += Array.prototype.join.call( arguments, "" ); - }); + } ); cblist.fireWith( window, [ "A", "B" ] ); assert.strictEqual( output, "XAB", "Basic binding and firing (arguments)" ); // fireWith with no arguments output = ""; cblist = jQuery.Callbacks( flags ); - cblist.add(function() { + cblist.add( function() { assert.equal( this, window, "fireWith with no arguments (context is window)" ); assert.strictEqual( arguments.length, 0, "fireWith with no arguments (no arguments)" ); - }); + } ); cblist.fireWith(); // Basic binding, removing and firing @@ -150,17 +150,17 @@ jQuery.each( tests, function( strFlags, resultString ) { // Locking output = "X"; cblist = jQuery.Callbacks( flags ); - cblist.add(function( str ) { + cblist.add( function( str ) { output += str; - }); + } ); cblist.lock(); - cblist.add(function( str ) { + cblist.add( function( str ) { output += str; - }); - cblist.fire("A"); - cblist.add(function( str ) { + } ); + cblist.fire( "A" ); + cblist.add( function( str ) { output += str; - }); + } ); assert.strictEqual( output, "X", "Lock early" ); assert.strictEqual( cblist.locked(), true, "Locking reflected in accessor" ); @@ -168,16 +168,16 @@ jQuery.each( tests, function( strFlags, resultString ) { output = "X"; cblist = jQuery.Callbacks( flags ); cblist.add( cblist.lock ); - cblist.add(function( str ) { + cblist.add( function( str ) { output += str; - }); + } ); cblist.fire( "A" ); assert.strictEqual( output, "XA", "Locking doesn't abort execution (gh-1990)" ); // Ordering output = "X"; cblist = jQuery.Callbacks( flags ); - cblist.add(function() { + cblist.add( function() { cblist.add( outputC ); outputA(); }, outputB ); @@ -186,7 +186,7 @@ jQuery.each( tests, function( strFlags, resultString ) { // Add and fire again output = "X"; - cblist.add(function() { + cblist.add( function() { cblist.add( outputC ); outputA(); }, outputB ); @@ -199,23 +199,23 @@ jQuery.each( tests, function( strFlags, resultString ) { // Multiple fire output = "X"; cblist = jQuery.Callbacks( flags ); - cblist.add(function( str ) { + cblist.add( function( str ) { output += str; - }); - cblist.fire("A"); + } ); + cblist.fire( "A" ); assert.strictEqual( output, "XA", "Multiple fire (first fire)" ); output = "X"; - cblist.add(function( str ) { + cblist.add( function( str ) { output += str; - }); + } ); assert.strictEqual( output, results.shift(), "Multiple fire (first new callback)" ); output = "X"; - cblist.fire("B"); + cblist.fire( "B" ); assert.strictEqual( output, results.shift(), "Multiple fire (second fire)" ); output = "X"; - cblist.add(function( str ) { + cblist.add( function( str ) { output += str; - }); + } ); assert.strictEqual( output, results.shift(), "Multiple fire (second new callback)" ); // Return false @@ -244,12 +244,12 @@ jQuery.each( tests, function( strFlags, resultString ) { cblist.add( handler ); cblist.fire(); assert.strictEqual( output, results.shift(), "No callback iteration" ); - }); - }); - }); -}); + } ); + } ); + } ); +} ); -})(); +} )(); QUnit.test( "jQuery.Callbacks( options ) - options are copied", function( assert ) { @@ -263,25 +263,25 @@ QUnit.test( "jQuery.Callbacks( options ) - options are copied", function( assert fn = function() { assert.ok( !( count++ ), "called once" ); }; - options["unique"] = false; + options[ "unique" ] = false; cb.add( fn, fn ); cb.fire(); -}); +} ); QUnit.test( "jQuery.Callbacks.fireWith - arguments are copied", function( assert ) { assert.expect( 1 ); - var cb = jQuery.Callbacks("memory"), - args = ["hello"]; + var cb = jQuery.Callbacks( "memory" ), + args = [ "hello" ]; cb.fireWith( null, args ); args[ 0 ] = "world"; - cb.add(function( hello ) { + cb.add( function( hello ) { assert.strictEqual( hello, "hello", "arguments are copied internally" ); - }); -}); + } ); +} ); QUnit.test( "jQuery.Callbacks.remove - should remove all instances", function( assert ) { @@ -295,8 +295,8 @@ QUnit.test( "jQuery.Callbacks.remove - should remove all instances", function( a cb.add( fn, fn, function() { assert.ok( true, "end of test" ); - }).remove( fn ).fire(); -}); + } ).remove( fn ).fire(); +} ); QUnit.test( "jQuery.Callbacks.has", function( assert ) { @@ -312,36 +312,36 @@ QUnit.test( "jQuery.Callbacks.has", function( assert ) { function getC() { return "C"; } - cb.add(getA, getB, getC); + cb.add( getA, getB, getC ); assert.strictEqual( cb.has(), true, "No arguments to .has() returns whether callback function(s) are attached or not" ); - assert.strictEqual( cb.has(getA), true, "Check if a specific callback function is in the Callbacks list" ); + assert.strictEqual( cb.has( getA ), true, "Check if a specific callback function is in the Callbacks list" ); - cb.remove(getB); - assert.strictEqual( cb.has(getB), false, "Remove a specific callback function and make sure its no longer there" ); - assert.strictEqual( cb.has(getA), true, "Remove a specific callback function and make sure other callback function is still there" ); + cb.remove( getB ); + assert.strictEqual( cb.has( getB ), false, "Remove a specific callback function and make sure its no longer there" ); + assert.strictEqual( cb.has( getA ), true, "Remove a specific callback function and make sure other callback function is still there" ); cb.empty(); assert.strictEqual( cb.has(), false, "Empty list and make sure there are no callback function(s)" ); - assert.strictEqual( cb.has(getA), false, "Check for a specific function in an empty() list" ); + assert.strictEqual( cb.has( getA ), false, "Check for a specific function in an empty() list" ); - cb.add(getA, getB, function(){ + cb.add( getA, getB, function() { assert.strictEqual( cb.has(), true, "Check if list has callback function(s) from within a callback function" ); - assert.strictEqual( cb.has(getA), true, "Check if list has a specific callback from within a callback function" ); - }).fire(); + assert.strictEqual( cb.has( getA ), true, "Check if list has a specific callback from within a callback function" ); + } ).fire(); assert.strictEqual( cb.has(), true, "Callbacks list has callback function(s) after firing" ); cb.disable(); assert.strictEqual( cb.has(), false, "disabled() list has no callback functions (returns false)" ); - assert.strictEqual( cb.has(getA), false, "Check for a specific function in a disabled() list" ); + assert.strictEqual( cb.has( getA ), false, "Check for a specific function in a disabled() list" ); - cb = jQuery.Callbacks("unique"); - cb.add(getA); - cb.add(getA); + cb = jQuery.Callbacks( "unique" ); + cb.add( getA ); + cb.add( getA ); assert.strictEqual( cb.has(), true, "Check if unique list has callback function(s) attached" ); cb.lock(); assert.strictEqual( cb.has(), false, "locked() list is empty and returns false" ); -}); +} ); QUnit.test( "jQuery.Callbacks() - adding a string doesn't cause a stack overflow", function( assert ) { @@ -350,7 +350,7 @@ QUnit.test( "jQuery.Callbacks() - adding a string doesn't cause a stack overflow jQuery.Callbacks().add( "hello world" ); assert.ok( true, "no stack overflow" ); -}); +} ); QUnit.test( "jQuery.Callbacks() - disabled callback doesn't fire (gh-1790)", function( assert ) { @@ -365,4 +365,4 @@ QUnit.test( "jQuery.Callbacks() - disabled callback doesn't fire (gh-1790)", fun cb.add( shot ); cb.fire(); assert.ok( !fired, "Disabled callback function didn't fire" ); -}); +} ); diff --git a/test/unit/core.js b/test/unit/core.js index 1a6cf5e3c..d9ec725c9 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -1,7 +1,7 @@ -QUnit.module("core", { teardown: moduleTeardown }); +QUnit.module( "core", { teardown: moduleTeardown } ); -QUnit.test("Basic requirements", function( assert ) { - assert.expect(7); +QUnit.test( "Basic requirements", function( assert ) { + assert.expect( 7 ); assert.ok( Array.prototype.push, "Array.push()" ); assert.ok( Function.prototype.apply, "Function.apply()" ); assert.ok( document.getElementById, "getElementById" ); @@ -9,15 +9,15 @@ QUnit.test("Basic requirements", function( assert ) { assert.ok( RegExp, "RegExp" ); assert.ok( jQuery, "jQuery" ); assert.ok( $, "$" ); -}); +} ); -QUnit.test("jQuery()", function( assert ) { +QUnit.test( "jQuery()", function( assert ) { var elem, i, - obj = jQuery("div"), - code = jQuery("<code/>"), - img = jQuery("<img/>"), - div = jQuery("<div/><hr/><code/><b/>"), + obj = jQuery( "div" ), + code = jQuery( "<code/>" ), + img = jQuery( "<img/>" ), + div = jQuery( "<div/><hr/><code/><b/>" ), exec = false, expected = 23, attrObj = { @@ -30,19 +30,19 @@ QUnit.test("jQuery()", function( assert ) { // few here but beware of modular builds where these methods may be excluded. if ( jQuery.fn.click ) { expected++; - attrObj["click"] = function() { ok( exec, "Click executed." ); }; + attrObj[ "click" ] = function() { ok( exec, "Click executed." ); }; } if ( jQuery.fn.width ) { expected++; - attrObj["width"] = 10; + attrObj[ "width" ] = 10; } if ( jQuery.fn.offset ) { expected++; - attrObj["offset"] = { "top": 1, "left": 1 }; + attrObj[ "offset" ] = { "top": 1, "left": 1 }; } if ( jQuery.fn.css ) { expected += 2; - attrObj["css"] = { "paddingLeft": 1, "paddingRight": 1 }; + attrObj[ "css" ] = { "paddingLeft": 1, "paddingRight": 1 }; } if ( jQuery.fn.attr ) { expected++; @@ -53,10 +53,10 @@ QUnit.test("jQuery()", function( assert ) { // Basic constructor's behavior assert.equal( jQuery().length, 0, "jQuery() === jQuery([])" ); - assert.equal( jQuery(undefined).length, 0, "jQuery(undefined) === jQuery([])" ); - assert.equal( jQuery(null).length, 0, "jQuery(null) === jQuery([])" ); - assert.equal( jQuery("").length, 0, "jQuery('') === jQuery([])" ); - assert.deepEqual( jQuery(obj).get(), obj.get(), "jQuery(jQueryObj) == jQueryObj" ); + assert.equal( jQuery( undefined ).length, 0, "jQuery(undefined) === jQuery([])" ); + assert.equal( jQuery( null ).length, 0, "jQuery(null) === jQuery([])" ); + assert.equal( jQuery( "" ).length, 0, "jQuery('') === jQuery([])" ); + assert.deepEqual( jQuery( obj ).get(), obj.get(), "jQuery(jQueryObj) == jQueryObj" ); // Invalid #id goes to Sizzle which will throw an error (gh-1682) try { @@ -66,7 +66,7 @@ QUnit.test("jQuery()", function( assert ) { } // can actually yield more than one, when iframes are included, the window is an array as well - assert.equal( jQuery(window).length, 1, "Correct number of elements generated for jQuery(window)" ); + assert.equal( jQuery( window ).length, 1, "Correct number of elements generated for jQuery(window)" ); /* // disabled since this test was doing nothing. i tried to fix it but i'm not sure @@ -95,84 +95,84 @@ QUnit.test("jQuery()", function( assert ) { assert.equal( div.length, 4, "Correct number of elements generated for div hr code b" ); assert.equal( div.parent().length, 0, "Make sure that the generated HTML has no parent." ); - assert.equal( jQuery([1,2,3]).get(1), 2, "Test passing an array to the factory" ); + assert.equal( jQuery( [ 1,2,3 ] ).get( 1 ), 2, "Test passing an array to the factory" ); - assert.equal( jQuery(document.body).get(0), jQuery("body").get(0), "Test passing an html node to the factory" ); + assert.equal( jQuery( document.body ).get( 0 ), jQuery( "body" ).get( 0 ), "Test passing an html node to the factory" ); - elem = jQuery(" <em>hello</em>")[0]; + elem = jQuery( " <em>hello</em>" )[ 0 ]; assert.equal( elem.nodeName.toLowerCase(), "em", "leading space" ); - elem = jQuery("\n\n<em>world</em>")[0]; + elem = jQuery( "\n\n<em>world</em>" )[ 0 ]; assert.equal( elem.nodeName.toLowerCase(), "em", "leading newlines" ); - elem = jQuery("<div/>", attrObj ); + elem = jQuery( "<div/>", attrObj ); if ( jQuery.fn.width ) { - assert.equal( elem[0].style.width, "10px", "jQuery() quick setter width"); + assert.equal( elem[ 0 ].style.width, "10px", "jQuery() quick setter width" ); } if ( jQuery.fn.offset ) { - assert.equal( elem[0].style.top, "1px", "jQuery() quick setter offset"); + assert.equal( elem[ 0 ].style.top, "1px", "jQuery() quick setter offset" ); } if ( jQuery.fn.css ) { - assert.equal( elem[0].style.paddingLeft, "1px", "jQuery quick setter css"); - assert.equal( elem[0].style.paddingRight, "1px", "jQuery quick setter css"); + assert.equal( elem[ 0 ].style.paddingLeft, "1px", "jQuery quick setter css" ); + assert.equal( elem[ 0 ].style.paddingRight, "1px", "jQuery quick setter css" ); } if ( jQuery.fn.attr ) { - assert.equal( elem[0].getAttribute("desired"), "very", "jQuery quick setter attr"); + assert.equal( elem[ 0 ].getAttribute( "desired" ), "very", "jQuery quick setter attr" ); } - assert.equal( elem[0].childNodes.length, 1, "jQuery quick setter text"); - assert.equal( elem[0].firstChild.nodeValue, "test", "jQuery quick setter text"); - assert.equal( elem[0].className, "test2", "jQuery() quick setter class"); - assert.equal( elem[0].id, "test3", "jQuery() quick setter id"); + assert.equal( elem[ 0 ].childNodes.length, 1, "jQuery quick setter text" ); + assert.equal( elem[ 0 ].firstChild.nodeValue, "test", "jQuery quick setter text" ); + assert.equal( elem[ 0 ].className, "test2", "jQuery() quick setter class" ); + assert.equal( elem[ 0 ].id, "test3", "jQuery() quick setter id" ); exec = true; - elem.trigger("click"); + elem.trigger( "click" ); // manually clean up detached elements elem.remove(); for ( i = 0; i < 3; ++i ) { - elem = jQuery("<input type='text' value='TEST' />"); + elem = jQuery( "<input type='text' value='TEST' />" ); } - assert.equal( elem[0].defaultValue, "TEST", "Ensure cached nodes are cloned properly (Bug #6655)" ); + assert.equal( elem[ 0 ].defaultValue, "TEST", "Ensure cached nodes are cloned properly (Bug #6655)" ); elem = jQuery( "<input type='hidden'>", {} ); assert.strictEqual( elem[ 0 ].ownerDocument, document, "Empty attributes object is not interpreted as a document (trac-8950)" ); -}); +} ); -QUnit.test("jQuery(selector, context)", function( assert ) { - assert.expect(3); - assert.deepEqual( jQuery("div p", "#qunit-fixture").get(), q("sndp", "en", "sap"), "Basic selector with string as context" ); - assert.deepEqual( jQuery("div p", q("qunit-fixture")[0]).get(), q("sndp", "en", "sap"), "Basic selector with element as context" ); - assert.deepEqual( jQuery("div p", jQuery("#qunit-fixture")).get(), q("sndp", "en", "sap"), "Basic selector with jQuery object as context" ); -}); +QUnit.test( "jQuery(selector, context)", function( assert ) { + assert.expect( 3 ); + assert.deepEqual( jQuery( "div p", "#qunit-fixture" ).get(), q( "sndp", "en", "sap" ), "Basic selector with string as context" ); + assert.deepEqual( jQuery( "div p", q( "qunit-fixture" )[ 0 ] ).get(), q( "sndp", "en", "sap" ), "Basic selector with element as context" ); + assert.deepEqual( jQuery( "div p", jQuery( "#qunit-fixture" ) ).get(), q( "sndp", "en", "sap" ), "Basic selector with jQuery object as context" ); +} ); QUnit.test( "globalEval", function( assert ) { assert.expect( 3 ); - Globals.register("globalEvalTest"); + Globals.register( "globalEvalTest" ); - jQuery.globalEval("globalEvalTest = 1;"); + jQuery.globalEval( "globalEvalTest = 1;" ); assert.equal( window.globalEvalTest, 1, "Test variable assignments are global" ); - jQuery.globalEval("var globalEvalTest = 2;"); + jQuery.globalEval( "var globalEvalTest = 2;" ); assert.equal( window.globalEvalTest, 2, "Test variable declarations are global" ); - jQuery.globalEval("this.globalEvalTest = 3;"); + jQuery.globalEval( "this.globalEvalTest = 3;" ); assert.equal( window.globalEvalTest, 3, "Test context (this) is the window object" ); -}); +} ); QUnit.test( "globalEval with 'use strict'", function( assert ) { assert.expect( 1 ); - Globals.register("strictEvalTest"); + Globals.register( "strictEvalTest" ); - jQuery.globalEval("'use strict'; var strictEvalTest = 1;"); + jQuery.globalEval( "'use strict'; var strictEvalTest = 1;" ); assert.equal( window.strictEvalTest, 1, "Test variable declarations are global (strict mode)" ); -}); +} ); QUnit.test( "globalEval execution after script injection (#7862)", function( assert ) { assert.expect( 1 ); @@ -185,41 +185,41 @@ QUnit.test( "globalEval execution after script injection (#7862)", function( ass now = jQuery.now(); document.body.appendChild( script ); - jQuery.globalEval( "var strictEvalTest = " + jQuery.now() + ";"); + jQuery.globalEval( "var strictEvalTest = " + jQuery.now() + ";" ); assert.ok( window.strictEvalTest - now < 500, "Code executed synchronously" ); -}); +} ); // This is not run in AMD mode if ( jQuery.noConflict ) { - QUnit.test("noConflict", function( assert ) { - assert.expect(7); + QUnit.test( "noConflict", function( assert ) { + assert.expect( 7 ); var $$ = jQuery; assert.strictEqual( jQuery, jQuery.noConflict(), "noConflict returned the jQuery object" ); - assert.strictEqual( window["jQuery"], $$, "Make sure jQuery wasn't touched." ); - assert.strictEqual( window["$"], original$, "Make sure $ was reverted." ); + assert.strictEqual( window[ "jQuery" ], $$, "Make sure jQuery wasn't touched." ); + assert.strictEqual( window[ "$" ], original$, "Make sure $ was reverted." ); jQuery = $ = $$; - assert.strictEqual( jQuery.noConflict(true), $$, "noConflict returned the jQuery object" ); - assert.strictEqual( window["jQuery"], originaljQuery, "Make sure jQuery was reverted." ); - assert.strictEqual( window["$"], original$, "Make sure $ was reverted." ); - assert.ok( $$().pushStack([]), "Make sure that jQuery still works." ); + assert.strictEqual( jQuery.noConflict( true ), $$, "noConflict returned the jQuery object" ); + assert.strictEqual( window[ "jQuery" ], originaljQuery, "Make sure jQuery was reverted." ); + assert.strictEqual( window[ "$" ], original$, "Make sure $ was reverted." ); + assert.ok( $$().pushStack( [] ), "Make sure that jQuery still works." ); - window["jQuery"] = jQuery = $$; - }); + window[ "jQuery" ] = jQuery = $$; + } ); } -QUnit.test("trim", function( assert ) { - assert.expect(13); +QUnit.test( "trim", function( assert ) { + assert.expect( 13 ); - var nbsp = String.fromCharCode(160); + var nbsp = String.fromCharCode( 160 ); - assert.equal( jQuery.trim("hello "), "hello", "trailing space" ); - assert.equal( jQuery.trim(" hello"), "hello", "leading space" ); - assert.equal( jQuery.trim(" hello "), "hello", "space on both sides" ); - assert.equal( jQuery.trim(" " + nbsp + "hello " + nbsp + " "), "hello", " " ); + assert.equal( jQuery.trim( "hello " ), "hello", "trailing space" ); + assert.equal( jQuery.trim( " hello" ), "hello", "leading space" ); + assert.equal( jQuery.trim( " hello " ), "hello", "space on both sides" ); + assert.equal( jQuery.trim( " " + nbsp + "hello " + nbsp + " " ), "hello", " " ); assert.equal( jQuery.trim(), "", "Nothing in." ); assert.equal( jQuery.trim( undefined ), "", "Undefined" ); @@ -227,88 +227,88 @@ QUnit.test("trim", function( assert ) { assert.equal( jQuery.trim( 5 ), "5", "Number" ); assert.equal( jQuery.trim( false ), "false", "Boolean" ); - assert.equal( jQuery.trim(" "), "", "space should be trimmed" ); - assert.equal( jQuery.trim("ipad\xA0"), "ipad", "nbsp should be trimmed" ); - assert.equal( jQuery.trim("\uFEFF"), "", "zwsp should be trimmed" ); - assert.equal( jQuery.trim("\uFEFF \xA0! | \uFEFF"), "! |", "leading/trailing should be trimmed" ); -}); + assert.equal( jQuery.trim( " " ), "", "space should be trimmed" ); + assert.equal( jQuery.trim( "ipad\xA0" ), "ipad", "nbsp should be trimmed" ); + assert.equal( jQuery.trim( "\uFEFF" ), "", "zwsp should be trimmed" ); + assert.equal( jQuery.trim( "\uFEFF \xA0! | \uFEFF" ), "! |", "leading/trailing should be trimmed" ); +} ); -QUnit.test("type", function( assert ) { +QUnit.test( "type", function( assert ) { assert.expect( 28 ); - assert.equal( jQuery.type(null), "null", "null" ); - assert.equal( jQuery.type(undefined), "undefined", "undefined" ); - assert.equal( jQuery.type(true), "boolean", "Boolean" ); - assert.equal( jQuery.type(false), "boolean", "Boolean" ); - assert.equal( jQuery.type(Boolean(true)), "boolean", "Boolean" ); - assert.equal( jQuery.type(0), "number", "Number" ); - assert.equal( jQuery.type(1), "number", "Number" ); - assert.equal( jQuery.type(Number(1)), "number", "Number" ); - assert.equal( jQuery.type(""), "string", "String" ); - assert.equal( jQuery.type("a"), "string", "String" ); - assert.equal( jQuery.type(String("a")), "string", "String" ); - assert.equal( jQuery.type({}), "object", "Object" ); - assert.equal( jQuery.type(/foo/), "regexp", "RegExp" ); - assert.equal( jQuery.type(new RegExp("asdf")), "regexp", "RegExp" ); - assert.equal( jQuery.type([1]), "array", "Array" ); - assert.equal( jQuery.type(new Date()), "date", "Date" ); - assert.equal( jQuery.type(new Function("return;")), "function", "Function" ); - assert.equal( jQuery.type(function(){}), "function", "Function" ); - assert.equal( jQuery.type(new Error()), "error", "Error" ); - assert.equal( jQuery.type(window), "object", "Window" ); - assert.equal( jQuery.type(document), "object", "Document" ); - assert.equal( jQuery.type(document.body), "object", "Element" ); - assert.equal( jQuery.type(document.createTextNode("foo")), "object", "TextNode" ); - assert.equal( jQuery.type(document.getElementsByTagName("*")), "object", "NodeList" ); + assert.equal( jQuery.type( null ), "null", "null" ); + assert.equal( jQuery.type( undefined ), "undefined", "undefined" ); + assert.equal( jQuery.type( true ), "boolean", "Boolean" ); + assert.equal( jQuery.type( false ), "boolean", "Boolean" ); + assert.equal( jQuery.type( Boolean( true ) ), "boolean", "Boolean" ); + assert.equal( jQuery.type( 0 ), "number", "Number" ); + assert.equal( jQuery.type( 1 ), "number", "Number" ); + assert.equal( jQuery.type( Number( 1 ) ), "number", "Number" ); + assert.equal( jQuery.type( "" ), "string", "String" ); + assert.equal( jQuery.type( "a" ), "string", "String" ); + assert.equal( jQuery.type( String( "a" ) ), "string", "String" ); + assert.equal( jQuery.type( {} ), "object", "Object" ); + assert.equal( jQuery.type( /foo/ ), "regexp", "RegExp" ); + assert.equal( jQuery.type( new RegExp( "asdf" ) ), "regexp", "RegExp" ); + assert.equal( jQuery.type( [ 1 ] ), "array", "Array" ); + assert.equal( jQuery.type( new Date() ), "date", "Date" ); + assert.equal( jQuery.type( new Function( "return;" ) ), "function", "Function" ); + assert.equal( jQuery.type( function() {} ), "function", "Function" ); + assert.equal( jQuery.type( new Error() ), "error", "Error" ); + assert.equal( jQuery.type( window ), "object", "Window" ); + assert.equal( jQuery.type( document ), "object", "Document" ); + assert.equal( jQuery.type( document.body ), "object", "Element" ); + assert.equal( jQuery.type( document.createTextNode( "foo" ) ), "object", "TextNode" ); + assert.equal( jQuery.type( document.getElementsByTagName( "*" ) ), "object", "NodeList" ); // Avoid Lint complaints var MyString = String, MyNumber = Number, MyBoolean = Boolean, MyObject = Object; - assert.equal( jQuery.type(new MyBoolean(true)), "boolean", "Boolean" ); - assert.equal( jQuery.type(new MyNumber(1)), "number", "Number" ); - assert.equal( jQuery.type(new MyString("a")), "string", "String" ); - assert.equal( jQuery.type(new MyObject()), "object", "Object" ); -}); + assert.equal( jQuery.type( new MyBoolean( true ) ), "boolean", "Boolean" ); + assert.equal( jQuery.type( new MyNumber( 1 ) ), "number", "Number" ); + assert.equal( jQuery.type( new MyString( "a" ) ), "string", "String" ); + assert.equal( jQuery.type( new MyObject() ), "object", "Object" ); +} ); -QUnit.asyncTest("isPlainObject", function( assert ) { - assert.expect(15); +QUnit.asyncTest( "isPlainObject", function( assert ) { + assert.expect( 15 ); var pass, iframe, doc, fn = function() {}; // The use case that we want to match - assert.ok( jQuery.isPlainObject({}), "{}" ); + assert.ok( jQuery.isPlainObject( {} ), "{}" ); // Not objects shouldn't be matched - assert.ok( !jQuery.isPlainObject(""), "string" ); - assert.ok( !jQuery.isPlainObject(0) && !jQuery.isPlainObject(1), "number" ); - assert.ok( !jQuery.isPlainObject(true) && !jQuery.isPlainObject(false), "boolean" ); - assert.ok( !jQuery.isPlainObject(null), "null" ); - assert.ok( !jQuery.isPlainObject(undefined), "undefined" ); + assert.ok( !jQuery.isPlainObject( "" ), "string" ); + assert.ok( !jQuery.isPlainObject( 0 ) && !jQuery.isPlainObject( 1 ), "number" ); + assert.ok( !jQuery.isPlainObject( true ) && !jQuery.isPlainObject( false ), "boolean" ); + assert.ok( !jQuery.isPlainObject( null ), "null" ); + assert.ok( !jQuery.isPlainObject( undefined ), "undefined" ); // Arrays shouldn't be matched - assert.ok( !jQuery.isPlainObject([]), "array" ); + assert.ok( !jQuery.isPlainObject( [] ), "array" ); // Instantiated objects shouldn't be matched - assert.ok( !jQuery.isPlainObject(new Date()), "new Date" ); + assert.ok( !jQuery.isPlainObject( new Date() ), "new Date" ); // Functions shouldn't be matched - assert.ok( !jQuery.isPlainObject(fn), "fn" ); + assert.ok( !jQuery.isPlainObject( fn ), "fn" ); // Again, instantiated objects shouldn't be matched - assert.ok( !jQuery.isPlainObject(new fn()), "new fn (no methods)" ); + assert.ok( !jQuery.isPlainObject( new fn() ), "new fn (no methods)" ); // Makes the function a little more realistic // (and harder to detect, incidentally) - fn.prototype["someMethod"] = function(){}; + fn.prototype[ "someMethod" ] = function() {}; // Again, instantiated objects shouldn't be matched - assert.ok( !jQuery.isPlainObject(new fn()), "new fn" ); + assert.ok( !jQuery.isPlainObject( new fn() ), "new fn" ); // DOM Element - assert.ok( !jQuery.isPlainObject( document.createElement("div") ), "DOM Element" ); + assert.ok( !jQuery.isPlainObject( document.createElement( "div" ) ), "DOM Element" ); // Window assert.ok( !jQuery.isPlainObject( window ), "window" ); @@ -321,27 +321,27 @@ QUnit.asyncTest("isPlainObject", function( assert ) { assert.ok( pass, "Does not throw exceptions on host objects" ); // Objects from other windows should be matched - Globals.register("iframeDone"); + Globals.register( "iframeDone" ); window.iframeDone = function( otherObject, detail ) { window.iframeDone = undefined; iframe.parentNode.removeChild( iframe ); - assert.ok( jQuery.isPlainObject(new otherObject()), "new otherObject" + ( detail ? " - " + detail : "" ) ); + assert.ok( jQuery.isPlainObject( new otherObject() ), "new otherObject" + ( detail ? " - " + detail : "" ) ); QUnit.start(); }; try { - iframe = jQuery("#qunit-fixture")[0].appendChild( document.createElement("iframe") ); + iframe = jQuery( "#qunit-fixture" )[ 0 ].appendChild( document.createElement( "iframe" ) ); doc = iframe.contentDocument || iframe.contentWindow.document; doc.open(); - doc.write("<body onload='window.parent.iframeDone(Object);'>"); + doc.write( "<body onload='window.parent.iframeDone(Object);'>" ); doc.close(); - } catch(e) { + } catch ( e ) { window.iframeDone( Object, "iframes not supported" ); } -}); +} ); -QUnit.test("isFunction", function( assert ) { - assert.expect(19); +QUnit.test( "isFunction", function( assert ) { + assert.expect( 19 ); var mystr, myarr, myfunction, fn, obj, nodes, first, input, a; @@ -353,31 +353,31 @@ QUnit.test("isFunction", function( assert ) { assert.ok( !jQuery.isFunction( 0 ), "0 Value" ); // Check built-ins - assert.ok( jQuery.isFunction(String), "String Function("+String+")" ); - assert.ok( jQuery.isFunction(Array), "Array Function("+Array+")" ); - assert.ok( jQuery.isFunction(Object), "Object Function("+Object+")" ); - assert.ok( jQuery.isFunction(Function), "Function Function("+Function+")" ); + assert.ok( jQuery.isFunction( String ), "String Function(" + String + ")" ); + assert.ok( jQuery.isFunction( Array ), "Array Function(" + Array + ")" ); + assert.ok( jQuery.isFunction( Object ), "Object Function(" + Object + ")" ); + assert.ok( jQuery.isFunction( Function ), "Function Function(" + Function + ")" ); // When stringified, this could be misinterpreted mystr = "function"; - assert.ok( !jQuery.isFunction(mystr), "Function String" ); + assert.ok( !jQuery.isFunction( mystr ), "Function String" ); // When stringified, this could be misinterpreted myarr = [ "function" ]; - assert.ok( !jQuery.isFunction(myarr), "Function Array" ); + assert.ok( !jQuery.isFunction( myarr ), "Function Array" ); // When stringified, this could be misinterpreted myfunction = { "function": "test" }; - assert.ok( !jQuery.isFunction(myfunction), "Function Object" ); + assert.ok( !jQuery.isFunction( myfunction ), "Function Object" ); // Make sure normal functions still work - fn = function(){}; - assert.ok( jQuery.isFunction(fn), "Normal Function" ); + fn = function() {}; + assert.ok( jQuery.isFunction( fn ), "Normal Function" ); - obj = document.createElement("object"); + obj = document.createElement( "object" ); // Firefox says this is a function - assert.ok( !jQuery.isFunction(obj), "Object Element" ); + assert.ok( !jQuery.isFunction( obj ), "Object Element" ); // Since 1.3, this isn't supported (#2968) //ok( jQuery.isFunction(obj.getAttribute), "getAttribute Function" ); @@ -385,14 +385,14 @@ QUnit.test("isFunction", function( assert ) { nodes = document.body.childNodes; // Safari says this is a function - assert.ok( !jQuery.isFunction(nodes), "childNodes Property" ); + assert.ok( !jQuery.isFunction( nodes ), "childNodes Property" ); first = document.body.firstChild; // Normal elements are reported ok everywhere - assert.ok( !jQuery.isFunction(first), "A normal DOM Element" ); + assert.ok( !jQuery.isFunction( first ), "A normal DOM Element" ); - input = document.createElement("input"); + input = document.createElement( "input" ); input.type = "text"; document.body.appendChild( input ); @@ -401,30 +401,30 @@ QUnit.test("isFunction", function( assert ) { document.body.removeChild( input ); - a = document.createElement("a"); + a = document.createElement( "a" ); a.href = "some-function"; document.body.appendChild( a ); // This serializes with the word 'function' in it - assert.ok( !jQuery.isFunction(a), "Anchor Element" ); + assert.ok( !jQuery.isFunction( a ), "Anchor Element" ); document.body.removeChild( a ); // Recursive function calls have lengths and array-like properties - function callme(callback){ - function fn(response){ - callback(response); + function callme( callback ) { + function fn( response ) { + callback( response ); } - assert.ok( jQuery.isFunction(fn), "Recursive Function Call" ); + assert.ok( jQuery.isFunction( fn ), "Recursive Function Call" ); - fn({ some: "data" }); + fn( { some: "data" } ); } - callme(function(){ - callme(function(){}); - }); -}); + callme( function() { + callme( function() {} ); + } ); +} ); QUnit.test( "isNumeric", function( assert ) { assert.expect( 38 ); @@ -473,345 +473,349 @@ QUnit.test( "isNumeric", function( assert ) { assert.equal( t( {} ), false, "Empty object" ); assert.equal( t( [] ), false, "Empty array" ); assert.equal( t( [ 42 ] ), false, "Array with one number" ); - assert.equal( t( function(){} ), false, "Instance of a function" ); + assert.equal( t( function() {} ), false, "Instance of a function" ); assert.equal( t( new Date() ), false, "Instance of a Date" ); -}); +} ); -QUnit.test("isXMLDoc - HTML", function( assert ) { - assert.expect(4); +QUnit.test( "isXMLDoc - HTML", function( assert ) { + assert.expect( 4 ); assert.ok( !jQuery.isXMLDoc( document ), "HTML document" ); assert.ok( !jQuery.isXMLDoc( document.documentElement ), "HTML documentElement" ); assert.ok( !jQuery.isXMLDoc( document.body ), "HTML Body Element" ); var body, - iframe = document.createElement("iframe"); + iframe = document.createElement( "iframe" ); document.body.appendChild( iframe ); try { - body = jQuery(iframe).contents()[0]; + body = jQuery( iframe ).contents()[ 0 ]; try { assert.ok( !jQuery.isXMLDoc( body ), "Iframe body element" ); - } catch(e) { + } catch ( e ) { assert.ok( false, "Iframe body element exception" ); } - } catch(e) { + } catch ( e ) { assert.ok( true, "Iframe body element - iframe not working correctly" ); } document.body.removeChild( iframe ); -}); +} ); -QUnit.test("XSS via location.hash", function( assert ) { - assert.expect(1); +QUnit.test( "XSS via location.hash", function( assert ) { + assert.expect( 1 ); QUnit.stop(); - jQuery["_check9521"] = function(x){ + jQuery[ "_check9521" ] = function( x ) { assert.ok( x, "script called from #id-like selector with inline handler" ); - jQuery("#check9521").remove(); - delete jQuery["_check9521"]; + jQuery( "#check9521" ).remove(); + delete jQuery[ "_check9521" ]; 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) { - jQuery["_check9521"](true); + jQuery( "#<img id='check9521' src='no-such-.gif' onerror='jQuery._check9521(false)'>" ).appendTo( "#qunit-fixture" ); + } catch ( err ) { + jQuery[ "_check9521" ]( true ); } -}); +} ); -QUnit.test("isXMLDoc - XML", function( assert ) { - assert.expect(3); +QUnit.test( "isXMLDoc - XML", function( assert ) { + assert.expect( 3 ); var xml = createDashboardXML(); assert.ok( jQuery.isXMLDoc( xml ), "XML document" ); assert.ok( jQuery.isXMLDoc( xml.documentElement ), "XML documentElement" ); - assert.ok( jQuery.isXMLDoc( jQuery("tab", xml)[0] ), "XML Tab Element" ); -}); + assert.ok( jQuery.isXMLDoc( jQuery( "tab", xml )[ 0 ] ), "XML Tab Element" ); +} ); -QUnit.test("isWindow", function( assert ) { +QUnit.test( "isWindow", function( assert ) { assert.expect( 14 ); - assert.ok( jQuery.isWindow(window), "window" ); - assert.ok( jQuery.isWindow(document.getElementsByTagName("iframe")[0].contentWindow), "iframe.contentWindow" ); + assert.ok( jQuery.isWindow( window ), "window" ); + assert.ok( jQuery.isWindow( document.getElementsByTagName( "iframe" )[ 0 ].contentWindow ), "iframe.contentWindow" ); assert.ok( !jQuery.isWindow(), "empty" ); - assert.ok( !jQuery.isWindow(null), "null" ); - assert.ok( !jQuery.isWindow(undefined), "undefined" ); - assert.ok( !jQuery.isWindow(document), "document" ); - assert.ok( !jQuery.isWindow(document.documentElement), "documentElement" ); - assert.ok( !jQuery.isWindow(""), "string" ); - assert.ok( !jQuery.isWindow(1), "number" ); - assert.ok( !jQuery.isWindow(true), "boolean" ); - assert.ok( !jQuery.isWindow({}), "object" ); - assert.ok( !jQuery.isWindow({ setInterval: function(){} }), "fake window" ); - assert.ok( !jQuery.isWindow(/window/), "regexp" ); - assert.ok( !jQuery.isWindow(function(){}), "function" ); -}); - -QUnit.test("jQuery('html')", function( assert ) { + assert.ok( !jQuery.isWindow( null ), "null" ); + assert.ok( !jQuery.isWindow( undefined ), "undefined" ); + assert.ok( !jQuery.isWindow( document ), "document" ); + assert.ok( !jQuery.isWindow( document.documentElement ), "documentElement" ); + assert.ok( !jQuery.isWindow( "" ), "string" ); + assert.ok( !jQuery.isWindow( 1 ), "number" ); + assert.ok( !jQuery.isWindow( true ), "boolean" ); + assert.ok( !jQuery.isWindow( {} ), "object" ); + assert.ok( !jQuery.isWindow( { setInterval: function() {} } ), "fake window" ); + assert.ok( !jQuery.isWindow( /window/ ), "regexp" ); + assert.ok( !jQuery.isWindow( function() {} ), "function" ); +} ); + +QUnit.test( "jQuery('html')", function( assert ) { assert.expect( 18 ); var s, div, j; - jQuery["foo"] = false; - s = jQuery("<script>jQuery.foo='test';</script>")[0]; + jQuery[ "foo" ] = false; + s = jQuery( "<script>jQuery.foo='test';</script>" )[ 0 ]; assert.ok( s, "Creating a script" ); - assert.ok( !jQuery["foo"], "Make sure the script wasn't executed prematurely" ); - jQuery("body").append("<script>jQuery.foo='test';</script>"); - assert.ok( jQuery["foo"], "Executing a scripts contents in the right context" ); + assert.ok( !jQuery[ "foo" ], "Make sure the script wasn't executed prematurely" ); + jQuery( "body" ).append( "<script>jQuery.foo='test';</script>" ); + assert.ok( jQuery[ "foo" ], "Executing a scripts contents in the right context" ); // Test multi-line HTML - div = jQuery("<div>\r\nsome text\n<p>some p</p>\nmore text\r\n</div>")[0]; + div = jQuery( "<div>\r\nsome text\n<p>some p</p>\nmore text\r\n</div>" )[ 0 ]; assert.equal( div.nodeName.toUpperCase(), "DIV", "Make sure we're getting a div." ); assert.equal( div.firstChild.nodeType, 3, "Text node." ); assert.equal( div.lastChild.nodeType, 3, "Text node." ); - assert.equal( div.childNodes[1].nodeType, 1, "Paragraph." ); - assert.equal( div.childNodes[1].firstChild.nodeType, 3, "Paragraph text." ); + assert.equal( div.childNodes[ 1 ].nodeType, 1, "Paragraph." ); + assert.equal( div.childNodes[ 1 ].firstChild.nodeType, 3, "Paragraph text." ); - assert.ok( jQuery("<link rel='stylesheet'/>")[0], "Creating a link" ); + assert.ok( jQuery( "<link rel='stylesheet'/>" )[ 0 ], "Creating a link" ); - assert.ok( !jQuery("<script/>")[0].parentNode, "Create a script" ); + assert.ok( !jQuery( "<script/>" )[ 0 ].parentNode, "Create a script" ); - assert.ok( jQuery("<input/>").attr("type", "hidden"), "Create an input and set the type." ); + assert.ok( jQuery( "<input/>" ).attr( "type", "hidden" ), "Create an input and set the type." ); - j = jQuery("<span>hi</span> there <!-- mon ami -->"); + j = jQuery( "<span>hi</span> there <!-- mon ami -->" ); assert.ok( j.length >= 2, "Check node,textnode,comment creation (some browsers delete comments)" ); - assert.ok( !jQuery("<option>test</option>")[0].selected, "Make sure that options are auto-selected #2050" ); + assert.ok( !jQuery( "<option>test</option>" )[ 0 ].selected, "Make sure that options are auto-selected #2050" ); - assert.ok( jQuery("<div></div>")[0], "Create a div with closing tag." ); - assert.ok( jQuery("<table></table>")[0], "Create a table with closing tag." ); + assert.ok( jQuery( "<div></div>" )[ 0 ], "Create a div with closing tag." ); + assert.ok( jQuery( "<table></table>" )[ 0 ], "Create a table with closing tag." ); 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, "When html is within parens, do not recognize as html." ); assert.equal( jQuery( "\\<div\\>" ).length, 0, "Ignore escaped html characters" ); -}); +} ); -QUnit.test("jQuery(tag-hyphenated elements) gh-1987", function( assert ) { +QUnit.test( "jQuery(tag-hyphenated elements) gh-1987", function( assert ) { assert.expect( 17 ); - jQuery.each( "thead tbody tfoot colgroup caption tr th td".split(" "), function( i, name ) { - var j = jQuery("<" + name + "-d></" + name + "-d>"); - assert.ok( j[0], "Create a tag-hyphenated elements" ); - assert.ok( jQuery.nodeName(j[0], name.toUpperCase() + "-D"), "Tag-hyphenated element has expected node name" ); - }); + jQuery.each( "thead tbody tfoot colgroup caption tr th td".split( " " ), function( i, name ) { + var j = jQuery( "<" + name + "-d></" + name + "-d>" ); + assert.ok( j[ 0 ], "Create a tag-hyphenated elements" ); + assert.ok( jQuery.nodeName( j[ 0 ], name.toUpperCase() + "-D" ), "Tag-hyphenated element has expected node name" ); + } ); - var j = jQuery("<tr-multiple-hyphens></tr-multiple-hyphens>"); - assert.ok( jQuery.nodeName(j[0], "TR-MULTIPLE-HYPHENS"), "Element with multiple hyphens in its tag has expected node name" ); -}); + var j = jQuery( "<tr-multiple-hyphens></tr-multiple-hyphens>" ); + assert.ok( jQuery.nodeName( j[ 0 ], "TR-MULTIPLE-HYPHENS" ), "Element with multiple hyphens in its tag has expected node name" ); +} ); -QUnit.test("jQuery('massive html #7990')", function( assert ) { +QUnit.test( "jQuery('massive html #7990')", function( assert ) { assert.expect( 3 ); var i, li = "<li>very very very very large html string</li>", - html = ["<ul>"]; + html = [ "<ul>" ]; for ( i = 0; i < 30000; i += 1 ) { - html[html.length] = li; + html[ html.length ] = li; } - html[html.length] = "</ul>"; - html = jQuery(html.join(""))[0]; - assert.equal( html.nodeName.toLowerCase(), "ul"); - assert.equal( html.firstChild.nodeName.toLowerCase(), "li"); + html[ html.length ] = "</ul>"; + html = jQuery( html.join( "" ) )[ 0 ]; + assert.equal( html.nodeName.toLowerCase(), "ul" ); + assert.equal( html.firstChild.nodeName.toLowerCase(), "li" ); assert.equal( html.childNodes.length, 30000 ); -}); +} ); -QUnit.test("jQuery('html', context)", function( assert ) { - assert.expect(1); +QUnit.test( "jQuery('html', context)", function( assert ) { + assert.expect( 1 ); - var $div = jQuery("<div/>")[0], - $span = jQuery("<span/>", $div); - assert.equal($span.length, 1, "verify a span created with a div context works, #1763"); -}); + var $div = jQuery( "<div/>" )[ 0 ], + $span = jQuery( "<span/>", $div ); + assert.equal( $span.length, 1, "verify a span created with a div context works, #1763" ); +} ); -QUnit.test("jQuery(selector, xml).text(str) - loaded via xml document", function( assert ) { - assert.expect(2); +QUnit.test( "jQuery(selector, xml).text(str) - loaded via xml document", function( assert ) { + assert.expect( 2 ); var xml = createDashboardXML(), + // tests for #1419 where ie was a problem - tab = jQuery("tab", xml).eq(0); + tab = jQuery( "tab", xml ).eq( 0 ); assert.equal( tab.text(), "blabla", "verify initial text correct" ); - tab.text("newtext"); + tab.text( "newtext" ); assert.equal( tab.text(), "newtext", "verify new text correct" ); -}); +} ); -QUnit.test("end()", function( assert ) { - assert.expect(3); - assert.equal( "Yahoo", jQuery("#yahoo").parent().end().text(), "check for end" ); - assert.ok( jQuery("#yahoo").end(), "check for end with nothing to end" ); +QUnit.test( "end()", function( assert ) { + assert.expect( 3 ); + assert.equal( "Yahoo", jQuery( "#yahoo" ).parent().end().text(), "check for end" ); + assert.ok( jQuery( "#yahoo" ).end(), "check for end with nothing to end" ); - var x = jQuery("#yahoo"); + var x = jQuery( "#yahoo" ); x.parent(); - assert.equal( "Yahoo", jQuery("#yahoo").text(), "check for non-destructive behaviour" ); -}); - -QUnit.test("length", function( assert ) { - assert.expect(1); - assert.equal( jQuery("#qunit-fixture p").length, 6, "Get Number of Elements Found" ); -}); - -QUnit.test("get()", function( assert ) { - assert.expect(1); - assert.deepEqual( jQuery("#qunit-fixture p").get(), q("firstp","ap","sndp","en","sap","first"), "Get All Elements" ); -}); - -QUnit.test("toArray()", function( assert ) { - assert.expect(1); - assert.deepEqual( jQuery("#qunit-fixture p").toArray(), - q("firstp","ap","sndp","en","sap","first"), + assert.equal( "Yahoo", jQuery( "#yahoo" ).text(), "check for non-destructive behaviour" ); +} ); + +QUnit.test( "length", function( assert ) { + assert.expect( 1 ); + assert.equal( jQuery( "#qunit-fixture p" ).length, 6, "Get Number of Elements Found" ); +} ); + +QUnit.test( "get()", function( assert ) { + assert.expect( 1 ); + assert.deepEqual( jQuery( "#qunit-fixture p" ).get(), q( "firstp", "ap", "sndp", "en", "sap", "first" ), "Get All Elements" ); +} ); + +QUnit.test( "toArray()", function( assert ) { + assert.expect( 1 ); + assert.deepEqual( jQuery( "#qunit-fixture p" ).toArray(), + q( "firstp", "ap", "sndp", "en", "sap", "first" ), "Convert jQuery object to an Array" ); -}); +} ); -QUnit.test("inArray()", function( assert ) { - assert.expect(19); +QUnit.test( "inArray()", function( assert ) { + assert.expect( 19 ); var selections = { - p: q("firstp", "sap", "ap", "first"), - em: q("siblingnext", "siblingfirst"), - div: q("qunit-testrunner-toolbar", "nothiddendiv", "nothiddendivchild", "foo"), - a: q("mark", "groups", "google", "simon1"), + p: q( "firstp", "sap", "ap", "first" ), + em: q( "siblingnext", "siblingfirst" ), + div: q( "qunit-testrunner-toolbar", "nothiddendiv", "nothiddendivchild", "foo" ), + a: q( "mark", "groups", "google", "simon1" ), empty: [] }, tests = { - p: { elem: jQuery("#ap")[0], index: 2 }, - em: { elem: jQuery("#siblingfirst")[0], index: 1 }, - div: { elem: jQuery("#nothiddendiv")[0], index: 1 }, - a: { elem: jQuery("#simon1")[0], index: 3 } + p: { elem: jQuery( "#ap" )[ 0 ], index: 2 }, + em: { elem: jQuery( "#siblingfirst" )[ 0 ], index: 1 }, + div: { elem: jQuery( "#nothiddendiv" )[ 0 ], index: 1 }, + a: { elem: jQuery( "#simon1" )[ 0 ], index: 3 } }, falseTests = { - p: jQuery("#liveSpan1")[0], - em: jQuery("#nothiddendiv")[0], + p: jQuery( "#liveSpan1" )[ 0 ], + em: jQuery( "#nothiddendiv" )[ 0 ], empty: "" }; jQuery.each( tests, function( key, obj ) { 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" ); assert.equal( !!~jQuery.inArray( obj.elem, selections[ key ], -3 ), true, "elem is in the array of selections given a negative index" ); - }); + } ); jQuery.each( falseTests, function( key, elem ) { assert.equal( !!~jQuery.inArray( elem, selections[ key ] ), false, "elem is NOT in the array of selections" ); - }); + } ); -}); +} ); -QUnit.test("get(Number)", function( assert ) { - assert.expect(2); - assert.equal( jQuery("#qunit-fixture p").get(0), document.getElementById("firstp"), "Get A Single Element" ); - assert.strictEqual( jQuery("#firstp").get(1), undefined, "Try get with index larger elements count" ); -}); +QUnit.test( "get(Number)", function( assert ) { + assert.expect( 2 ); + assert.equal( jQuery( "#qunit-fixture p" ).get( 0 ), document.getElementById( "firstp" ), "Get A Single Element" ); + assert.strictEqual( jQuery( "#firstp" ).get( 1 ), undefined, "Try get with index larger elements count" ); +} ); -QUnit.test("get(-Number)",function( assert ) { - assert.expect(2); - assert.equal( jQuery("p").get(-1), document.getElementById("first"), "Get a single element with negative index" ); - assert.strictEqual( jQuery("#firstp").get(-2), undefined, "Try get with index negative index larger then elements count" ); -}); +QUnit.test( "get(-Number)", function( assert ) { + assert.expect( 2 ); + assert.equal( jQuery( "p" ).get( -1 ), document.getElementById( "first" ), "Get a single element with negative index" ); + assert.strictEqual( jQuery( "#firstp" ).get( -2 ), undefined, "Try get with index negative index larger then elements count" ); +} ); -QUnit.test("each(Function)", function( assert ) { - assert.expect(1); +QUnit.test( "each(Function)", function( assert ) { + assert.expect( 1 ); var div, pass, i; - div = jQuery("div"); - div.each(function(){this.foo = "zoo";}); + div = jQuery( "div" ); + div.each( function() {this.foo = "zoo";} ); pass = true; for ( i = 0; i < div.length; i++ ) { - if ( div.get(i).foo !== "zoo" ) { + if ( div.get( i ).foo !== "zoo" ) { pass = false; } } assert.ok( pass, "Execute a function, Relative" ); -}); +} ); -QUnit.test("slice()", function( assert ) { - assert.expect(7); +QUnit.test( "slice()", function( assert ) { + assert.expect( 7 ); - var $links = jQuery("#ap a"); + var $links = jQuery( "#ap a" ); - assert.deepEqual( $links.slice(1,2).get(), q("groups"), "slice(1,2)" ); - assert.deepEqual( $links.slice(1).get(), q("groups", "anchor1", "mark"), "slice(1)" ); - assert.deepEqual( $links.slice(0,3).get(), q("google", "groups", "anchor1"), "slice(0,3)" ); - assert.deepEqual( $links.slice(-1).get(), q("mark"), "slice(-1)" ); + assert.deepEqual( $links.slice( 1, 2 ).get(), q( "groups" ), "slice(1,2)" ); + assert.deepEqual( $links.slice( 1 ).get(), q( "groups", "anchor1", "mark" ), "slice(1)" ); + assert.deepEqual( $links.slice( 0, 3 ).get(), q( "google", "groups", "anchor1" ), "slice(0,3)" ); + assert.deepEqual( $links.slice( -1 ).get(), q( "mark" ), "slice(-1)" ); - assert.deepEqual( $links.eq(1).get(), q("groups"), "eq(1)" ); - assert.deepEqual( $links.eq("2").get(), q("anchor1"), "eq('2')" ); - assert.deepEqual( $links.eq(-1).get(), q("mark"), "eq(-1)" ); -}); + assert.deepEqual( $links.eq( 1 ).get(), q( "groups" ), "eq(1)" ); + assert.deepEqual( $links.eq( "2" ).get(), q( "anchor1" ), "eq('2')" ); + assert.deepEqual( $links.eq( -1 ).get(), q( "mark" ), "eq(-1)" ); +} ); -QUnit.test("first()/last()", function( assert ) { - assert.expect(4); +QUnit.test( "first()/last()", function( assert ) { + assert.expect( 4 ); - var $links = jQuery("#ap a"), $none = jQuery("asdf"); + var $links = jQuery( "#ap a" ), $none = jQuery( "asdf" ); - assert.deepEqual( $links.first().get(), q("google"), "first()" ); - assert.deepEqual( $links.last().get(), q("mark"), "last()" ); + assert.deepEqual( $links.first().get(), q( "google" ), "first()" ); + assert.deepEqual( $links.last().get(), q( "mark" ), "last()" ); assert.deepEqual( $none.first().get(), [], "first() none" ); assert.deepEqual( $none.last().get(), [], "last() none" ); -}); +} ); -QUnit.test("map()", function( assert ) { +QUnit.test( "map()", function( assert ) { assert.expect( 2 ); assert.deepEqual( - jQuery("#ap").map(function() { - return jQuery( this ).find("a").get(); - }).get(), + jQuery( "#ap" ).map( function() { + return jQuery( this ).find( "a" ).get(); + } ).get(), q( "google", "groups", "anchor1", "mark" ), "Array Map" ); assert.deepEqual( - jQuery("#ap > a").map(function() { + jQuery( "#ap > a" ).map( function() { return this.parentNode; - }).get(), - q( "ap","ap","ap" ), + } ).get(), + q( "ap", "ap", "ap" ), "Single Map" ); -}); +} ); -QUnit.test("jQuery.map", function( assert ) { +QUnit.test( "jQuery.map", function( assert ) { assert.expect( 25 ); var i, label, result, callback; result = jQuery.map( [ 3, 4, 5 ], function( v, k ) { return k; - }); - assert.equal( result.join(""), "012", "Map the keys from an array" ); + } ); + assert.equal( result.join( "" ), "012", "Map the keys from an array" ); result = jQuery.map( [ 3, 4, 5 ], function( v ) { return v; - }); - assert.equal( result.join(""), "345", "Map the values from an array" ); + } ); + assert.equal( result.join( "" ), "345", "Map the values from an array" ); result = jQuery.map( { a: 1, b: 2 }, function( v, k ) { return k; - }); - assert.equal( result.join(""), "ab", "Map the keys from an object" ); + } ); + assert.equal( result.join( "" ), "ab", "Map the keys from an object" ); result = jQuery.map( { a: 1, b: 2 }, function( v ) { return v; - }); - assert.equal( result.join(""), "12", "Map the values from an object" ); + } ); + assert.equal( result.join( "" ), "12", "Map the values from an object" ); result = jQuery.map( [ "a", undefined, null, "b" ], function( v ) { return v; - }); - assert.equal( result.join(""), "ab", "Array iteration does not include undefined/null results" ); + } ); + assert.equal( result.join( "" ), "ab", "Array iteration does not include undefined/null results" ); result = jQuery.map( { a: "a", b: undefined, c: null, d: "b" }, function( v ) { return v; - }); - assert.equal( result.join(""), "ab", "Object iteration does not include undefined/null results" ); + } ); + assert.equal( result.join( "" ), "ab", "Object iteration does not include undefined/null results" ); result = { Zero: function() {}, @@ -850,7 +854,7 @@ QUnit.test("jQuery.map", function( assert ) { "sparse Array": Array( 4 ), "length: 1 plain object": { length: 1, "0": true }, "length: 2 plain object": { length: 2, "0": true, "1": true }, - NodeList: document.getElementsByTagName("html") + NodeList: document.getElementsByTagName( "html" ) }; callback = function( v, k ) { if ( result[ label ] ) { @@ -866,22 +870,22 @@ QUnit.test("jQuery.map", function( assert ) { result = false; jQuery.map( { length: 0 }, function() { result = true; - }); + } ); assert.ok( !result, "length: 0 plain object treated like array" ); result = false; - jQuery.map( document.getElementsByTagName("asdf"), function() { + jQuery.map( document.getElementsByTagName( "asdf" ), function() { result = true; - }); + } ); assert.ok( !result, "empty NodeList treated like array" ); - result = jQuery.map( Array(4), function( v, k ){ - return k % 2 ? k : [k,k,k]; - }); - assert.equal( result.join(""), "00012223", "Array results flattened (#2616)" ); -}); + result = jQuery.map( Array( 4 ), function( v, k ) { + return k % 2 ? k : [ k,k,k ]; + } ); + assert.equal( result.join( "" ), "00012223", "Array results flattened (#2616)" ); +} ); -QUnit.test("jQuery.merge()", function( assert ) { +QUnit.test( "jQuery.merge()", function( assert ) { assert.expect( 10 ); assert.deepEqual( @@ -915,7 +919,7 @@ QUnit.test("jQuery.merge()", function( assert ) { // Fixed at [5998], #3641 assert.deepEqual( jQuery.merge( [ -2, -1 ], [ 0, 1, 2 ] ), - [ -2, -1 , 0, 1, 2 ], + [ -2, -1, 0, 1, 2 ], "Second array including a zero (falsy)" ); @@ -937,34 +941,34 @@ QUnit.test("jQuery.merge()", function( assert ) { ); assert.deepEqual( - jQuery.merge( [], document.getElementById("lengthtest").getElementsByTagName("input") ), - [ document.getElementById("length"), document.getElementById("idTest") ], + jQuery.merge( [], document.getElementById( "lengthtest" ).getElementsByTagName( "input" ) ), + [ document.getElementById( "length" ), document.getElementById( "idTest" ) ], "Second NodeList" ); -}); +} ); -QUnit.test("jQuery.grep()", function( assert ) { - assert.expect(8); +QUnit.test( "jQuery.grep()", function( assert ) { + assert.expect( 8 ); var searchCriterion = function( value ) { return value % 2 === 0; }; assert.deepEqual( jQuery.grep( [], searchCriterion ), [], "Empty array" ); - assert.deepEqual( jQuery.grep( new Array(4), searchCriterion ), [], "Sparse array" ); + assert.deepEqual( jQuery.grep( new Array( 4 ), searchCriterion ), [], "Sparse array" ); assert.deepEqual( jQuery.grep( [ 1, 2, 3, 4, 5, 6 ], searchCriterion ), [ 2, 4, 6 ], "Satisfying elements present" ); - assert.deepEqual( jQuery.grep( [ 1, 3, 5, 7], searchCriterion ), [], "Satisfying elements absent" ); + assert.deepEqual( jQuery.grep( [ 1, 3, 5, 7 ], searchCriterion ), [], "Satisfying elements absent" ); assert.deepEqual( jQuery.grep( [ 1, 2, 3, 4, 5, 6 ], searchCriterion, true ), [ 1, 3, 5 ], "Satisfying elements present and grep inverted" ); - assert.deepEqual( jQuery.grep( [ 1, 3, 5, 7], searchCriterion, true ), [1, 3, 5, 7], "Satisfying elements absent and grep inverted" ); + assert.deepEqual( jQuery.grep( [ 1, 3, 5, 7 ], searchCriterion, true ), [ 1, 3, 5, 7 ], "Satisfying elements absent and grep inverted" ); assert.deepEqual( jQuery.grep( [ 1, 2, 3, 4, 5, 6 ], searchCriterion, false ), [ 2, 4, 6 ], "Satisfying elements present but grep explicitly uninverted" ); assert.deepEqual( jQuery.grep( [ 1, 3, 5, 7 ], searchCriterion, false ), [], "Satisfying elements absent and grep explicitly uninverted" ); -}); +} ); -QUnit.test("jQuery.extend(Object, Object)", function( assert ) { - assert.expect(28); +QUnit.test( "jQuery.extend(Object, Object)", function( assert ) { + assert.expect( 28 ); var empty, optionsWithLength, optionsWithDate, myKlass, customObject, optionsWithCustomObject, MyNumber, ret, @@ -978,87 +982,87 @@ QUnit.test("jQuery.extend(Object, Object)", function( assert ) { deep2 = { "foo": { "baz": true }, "foo2": document }, deep2copy = { "foo": { "baz": true }, "foo2": document }, deepmerged = { "foo": { "bar": true, "baz": true }, "foo2": document }, - arr = [1, 2, 3], + arr = [ 1, 2, 3 ], nestedarray = { "arr": arr }; - jQuery.extend(settings, options); + jQuery.extend( settings, options ); assert.deepEqual( settings, merged, "Check if extended: settings must be extended" ); assert.deepEqual( options, optionsCopy, "Check if not modified: options must not be modified" ); - jQuery.extend(settings, null, options); + jQuery.extend( settings, null, options ); assert.deepEqual( settings, merged, "Check if extended: settings must be extended" ); assert.deepEqual( options, optionsCopy, "Check if not modified: options must not be modified" ); - jQuery.extend(true, deep1, deep2); - assert.deepEqual( deep1["foo"], deepmerged["foo"], "Check if foo: settings must be extended" ); - assert.deepEqual( deep2["foo"], deep2copy["foo"], "Check if not deep2: options must not be modified" ); - assert.equal( deep1["foo2"], document, "Make sure that a deep clone was not attempted on the document" ); + jQuery.extend( true, deep1, deep2 ); + assert.deepEqual( deep1[ "foo" ], deepmerged[ "foo" ], "Check if foo: settings must be extended" ); + assert.deepEqual( deep2[ "foo" ], deep2copy[ "foo" ], "Check if not deep2: options must not be modified" ); + assert.equal( deep1[ "foo2" ], document, "Make sure that a deep clone was not attempted on the document" ); - assert.ok( jQuery.extend(true, {}, nestedarray)["arr"] !== arr, "Deep extend of object must clone child array" ); + assert.ok( jQuery.extend( true, {}, nestedarray )[ "arr" ] !== arr, "Deep extend of object must clone child array" ); // #5991 - assert.ok( jQuery.isArray( jQuery.extend(true, { "arr": {} }, nestedarray)["arr"] ), "Cloned array have to be an Array" ); - assert.ok( jQuery.isPlainObject( jQuery.extend(true, { "arr": arr }, { "arr": {} })["arr"] ), "Cloned object have to be an plain object" ); + assert.ok( jQuery.isArray( jQuery.extend( true, { "arr": {} }, nestedarray )[ "arr" ] ), "Cloned array have to be an Array" ); + assert.ok( jQuery.isPlainObject( jQuery.extend( true, { "arr": arr }, { "arr": {} } )[ "arr" ] ), "Cloned object have to be an plain object" ); empty = {}; optionsWithLength = { "foo": { "length": -1 } }; - jQuery.extend(true, empty, optionsWithLength); - assert.deepEqual( empty["foo"], optionsWithLength["foo"], "The length property must copy correctly" ); + jQuery.extend( true, empty, optionsWithLength ); + assert.deepEqual( empty[ "foo" ], optionsWithLength[ "foo" ], "The length property must copy correctly" ); empty = {}; optionsWithDate = { "foo": { "date": new Date() } }; - jQuery.extend(true, empty, optionsWithDate); - assert.deepEqual( empty["foo"], optionsWithDate["foo"], "Dates copy correctly" ); + jQuery.extend( true, empty, optionsWithDate ); + assert.deepEqual( empty[ "foo" ], optionsWithDate[ "foo" ], "Dates copy correctly" ); /** @constructor */ myKlass = function() {}; customObject = new myKlass(); optionsWithCustomObject = { "foo": { "date": customObject } }; empty = {}; - jQuery.extend(true, empty, optionsWithCustomObject); - assert.ok( empty["foo"] && empty["foo"]["date"] === customObject, "Custom objects copy correctly (no methods)" ); + jQuery.extend( true, empty, optionsWithCustomObject ); + assert.ok( empty[ "foo" ] && empty[ "foo" ][ "date" ] === customObject, "Custom objects copy correctly (no methods)" ); // Makes the class a little more realistic - myKlass.prototype = { "someMethod": function(){} }; + myKlass.prototype = { "someMethod": function() {} }; empty = {}; - jQuery.extend(true, empty, optionsWithCustomObject); - assert.ok( empty["foo"] && empty["foo"]["date"] === customObject, "Custom objects copy correctly" ); + jQuery.extend( true, empty, optionsWithCustomObject ); + assert.ok( empty[ "foo" ] && empty[ "foo" ][ "date" ] === customObject, "Custom objects copy correctly" ); MyNumber = Number; - ret = jQuery.extend(true, { "foo": 4 }, { "foo": new MyNumber(5) } ); - assert.ok( parseInt(ret.foo, 10) === 5, "Wrapped numbers copy correctly" ); + ret = jQuery.extend( true, { "foo": 4 }, { "foo": new MyNumber( 5 ) } ); + assert.ok( parseInt( ret.foo, 10 ) === 5, "Wrapped numbers copy correctly" ); nullUndef; - nullUndef = jQuery.extend({}, options, { "xnumber2": null }); - assert.ok( nullUndef["xnumber2"] === null, "Check to make sure null values are copied"); + nullUndef = jQuery.extend( {}, options, { "xnumber2": null } ); + assert.ok( nullUndef[ "xnumber2" ] === null, "Check to make sure null values are copied" ); - nullUndef = jQuery.extend({}, options, { "xnumber2": undefined }); - assert.ok( nullUndef["xnumber2"] === options["xnumber2"], "Check to make sure undefined values are not copied"); + nullUndef = jQuery.extend( {}, options, { "xnumber2": undefined } ); + assert.ok( nullUndef[ "xnumber2" ] === options[ "xnumber2" ], "Check to make sure undefined values are not copied" ); - nullUndef = jQuery.extend({}, options, { "xnumber0": null }); - assert.ok( nullUndef["xnumber0"] === null, "Check to make sure null values are inserted"); + nullUndef = jQuery.extend( {}, options, { "xnumber0": null } ); + assert.ok( nullUndef[ "xnumber0" ] === null, "Check to make sure null values are inserted" ); target = {}; recursive = { foo:target, bar:5 }; - jQuery.extend(true, target, recursive); + jQuery.extend( true, target, recursive ); assert.deepEqual( target, { bar:5 }, "Check to make sure a recursive obj doesn't go never-ending loop by not copying it over" ); - ret = jQuery.extend(true, { foo: [] }, { foo: [0] } ); // 1907 + ret = jQuery.extend( true, { foo: [] }, { foo: [ 0 ] } ); // 1907 assert.equal( ret.foo.length, 1, "Check to make sure a value with coercion 'false' copies over when necessary to fix #1907" ); - ret = jQuery.extend(true, { foo: "1,2,3" }, { foo: [1, 2, 3] } ); + ret = jQuery.extend( true, { foo: "1,2,3" }, { foo: [ 1, 2, 3 ] } ); assert.ok( typeof ret.foo !== "string", "Check to make sure values equal with coercion (but not actually equal) overwrite correctly" ); - ret = jQuery.extend(true, { foo:"bar" }, { foo:null } ); + ret = jQuery.extend( true, { foo:"bar" }, { foo:null } ); assert.ok( typeof ret.foo !== "undefined", "Make sure a null value doesn't crash with deep extend, for #1908" ); obj = { foo:null }; - jQuery.extend(true, obj, { foo:"notnull" } ); + jQuery.extend( true, obj, { foo:"notnull" } ); assert.equal( obj.foo, "notnull", "Make sure a null value can be overwritten" ); function func() {} - jQuery.extend(func, { key: "value" } ); + jQuery.extend( func, { key: "value" } ); assert.equal( func.key, "value", "Verify a function can be extended" ); defaults = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" }; @@ -1069,19 +1073,21 @@ QUnit.test("jQuery.extend(Object, Object)", function( assert ) { options2Copy = { xstring2: "xx", xxx: "newstringx" }; merged2 = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "xx", xxx: "newstringx" }; - settings = jQuery.extend({}, defaults, options1, options2); + settings = jQuery.extend( {}, defaults, options1, options2 ); assert.deepEqual( settings, merged2, "Check if extended: settings must be extended" ); assert.deepEqual( defaults, defaultsCopy, "Check if not modified: options1 must not be modified" ); assert.deepEqual( options1, options1Copy, "Check if not modified: options1 must not be modified" ); assert.deepEqual( options2, options2Copy, "Check if not modified: options2 must not be modified" ); -}); +} ); -QUnit.test("jQuery.extend(true,{},{a:[], o:{}}); deep copy with array, followed by object", function( assert ) { - assert.expect(2); +QUnit.test( "jQuery.extend(true,{},{a:[], o:{}}); deep copy with array, followed by object", function( assert ) { + 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 @@ -1095,9 +1101,9 @@ QUnit.test("jQuery.extend(true,{},{a:[], o:{}}); deep copy with array, followed assert.deepEqual( result, initial, "The [result] and [initial] have equal shape and values" ); assert.ok( !jQuery.isArray( result.object ), "result.object wasn't paved with an empty array" ); -}); +} ); -QUnit.test("jQuery.each(Object,Function)", function( assert ) { +QUnit.test( "jQuery.each(Object,Function)", function( assert ) { assert.expect( 23 ); var i, label, seen, callback; @@ -1105,13 +1111,13 @@ QUnit.test("jQuery.each(Object,Function)", function( assert ) { seen = {}; jQuery.each( [ 3, 4, 5 ], function( k, v ) { seen[ k ] = v; - }); + } ); assert.deepEqual( seen, { "0": 3, "1": 4, "2": 5 }, "Array iteration" ); seen = {}; jQuery.each( { name: "name", lang: "lang" }, function( k, v ) { seen[ k ] = v; - }); + } ); assert.deepEqual( seen, { name: "name", lang: "lang" }, "Object iteration" ); seen = []; @@ -1120,14 +1126,14 @@ QUnit.test("jQuery.each(Object,Function)", function( assert ) { if ( k === 1 ) { return false; } - }); - assert.deepEqual( seen, [ 1, 2 ] , "Broken array iteration" ); + } ); + assert.deepEqual( seen, [ 1, 2 ], "Broken array iteration" ); seen = []; - jQuery.each( {"a": 1, "b": 2,"c": 3 }, function( k, v ) { + jQuery.each( { "a": 1, "b": 2,"c": 3 }, function( k, v ) { seen.push( v ); return false; - }); + } ); assert.deepEqual( seen, [ 1 ], "Broken object iteration" ); seen = { @@ -1167,7 +1173,7 @@ QUnit.test("jQuery.each(Object,Function)", function( assert ) { "sparse Array": Array( 4 ), "length: 1 plain object": { length: 1, "0": true }, "length: 2 plain object": { length: 2, "0": true, "1": true }, - NodeList: document.getElementsByTagName("html") + NodeList: document.getElementsByTagName( "html" ) }; callback = function( k ) { if ( seen[ label ] ) { @@ -1184,23 +1190,23 @@ QUnit.test("jQuery.each(Object,Function)", function( assert ) { seen = false; jQuery.each( { length: 0 }, function() { seen = true; - }); + } ); assert.ok( !seen, "length: 0 plain object treated like array" ); seen = false; - jQuery.each( document.getElementsByTagName("asdf"), function() { + jQuery.each( document.getElementsByTagName( "asdf" ), function() { seen = true; - }); + } ); assert.ok( !seen, "empty NodeList treated like array" ); i = 0; jQuery.each( document.styleSheets, function() { i++; - }); + } ); assert.equal( i, document.styleSheets.length, "Iteration over document.styleSheets" ); -}); +} ); -QUnit.test("jQuery.each/map(undefined/null,Function)", function( assert ) { +QUnit.test( "jQuery.each/map(undefined/null,Function)", function( assert ) { assert.expect( 1 ); try { @@ -1212,7 +1218,7 @@ QUnit.test("jQuery.each/map(undefined/null,Function)", function( assert ) { } catch ( e ) { assert.ok( false, "each/map must accept null and undefined values" ); } -}); +} ); QUnit.test( "JIT compilation does not interfere with length retrieval (gh-2145)", function( assert ) { assert.expect( 4 ); @@ -1230,74 +1236,74 @@ QUnit.test( "JIT compilation does not interfere with length retrieval (gh-2145)" jQuery.each( { 1: "1", 2: "2", 3: "3" }, function( index ) { assert.equal( ++i, index, "Iteration over object with solely " + "numeric indices (gh-2145 JIT iOS 8 bug)" ); - }); + } ); assert.equal( i, 3, "Iteration over object with solely " + "numeric indices (gh-2145 JIT iOS 8 bug)" ); -}); +} ); -QUnit.test("jQuery.makeArray", function( assert ){ - assert.expect(15); +QUnit.test( "jQuery.makeArray", function( assert ) { + assert.expect( 15 ); - assert.equal( jQuery.makeArray(jQuery("html>*"))[0].nodeName.toUpperCase(), "HEAD", "Pass makeArray a jQuery object" ); + assert.equal( jQuery.makeArray( jQuery( "html>*" ) )[ 0 ].nodeName.toUpperCase(), "HEAD", "Pass makeArray a jQuery object" ); - assert.equal( jQuery.makeArray(document.getElementsByName("PWD")).slice(0,1)[0].name, "PWD", "Pass makeArray a nodelist" ); + assert.equal( jQuery.makeArray( document.getElementsByName( "PWD" ) ).slice( 0, 1 )[ 0 ].name, "PWD", "Pass makeArray a nodelist" ); - assert.equal( (function() { return jQuery.makeArray(arguments); })(1,2).join(""), "12", "Pass makeArray an arguments array" ); + assert.equal( ( function() { return jQuery.makeArray( arguments ); } )( 1, 2 ).join( "" ), "12", "Pass makeArray an arguments array" ); - assert.equal( jQuery.makeArray([1,2,3]).join(""), "123", "Pass makeArray a real array" ); + assert.equal( jQuery.makeArray( [ 1,2,3 ] ).join( "" ), "123", "Pass makeArray a real array" ); assert.equal( jQuery.makeArray().length, 0, "Pass nothing to makeArray and expect an empty array" ); - assert.equal( jQuery.makeArray( 0 )[0], 0 , "Pass makeArray a number" ); + assert.equal( jQuery.makeArray( 0 )[ 0 ], 0, "Pass makeArray a number" ); - assert.equal( jQuery.makeArray( "foo" )[0], "foo", "Pass makeArray a string" ); + assert.equal( jQuery.makeArray( "foo" )[ 0 ], "foo", "Pass makeArray a string" ); - assert.equal( jQuery.makeArray( true )[0].constructor, Boolean, "Pass makeArray a boolean" ); + assert.equal( jQuery.makeArray( true )[ 0 ].constructor, Boolean, "Pass makeArray a boolean" ); - assert.equal( jQuery.makeArray( document.createElement("div") )[0].nodeName.toUpperCase(), "DIV", "Pass makeArray a single node" ); + assert.equal( jQuery.makeArray( document.createElement( "div" ) )[ 0 ].nodeName.toUpperCase(), "DIV", "Pass makeArray a single node" ); - assert.equal( jQuery.makeArray( {length:2, 0:"a", 1:"b"} ).join(""), "ab", "Pass makeArray an array like map (with length)" ); + assert.equal( jQuery.makeArray( { length:2, 0:"a", 1:"b" } ).join( "" ), "ab", "Pass makeArray an array like map (with length)" ); - assert.ok( !!jQuery.makeArray( document.documentElement.childNodes ).slice(0,1)[0].nodeName, "Pass makeArray a childNodes array" ); + assert.ok( !!jQuery.makeArray( document.documentElement.childNodes ).slice( 0, 1 )[ 0 ].nodeName, "Pass makeArray a childNodes array" ); // function, is tricky as it has length - assert.equal( jQuery.makeArray( function(){ return 1;} )[0](), 1, "Pass makeArray a function" ); + assert.equal( jQuery.makeArray( function() { return 1;} )[ 0 ](), 1, "Pass makeArray a function" ); //window, also has length - assert.equal( jQuery.makeArray(window)[0], window, "Pass makeArray the window" ); + assert.equal( jQuery.makeArray( window )[ 0 ], window, "Pass makeArray the window" ); - assert.equal( jQuery.makeArray(/a/)[0].constructor, RegExp, "Pass makeArray a regex" ); + assert.equal( jQuery.makeArray( /a/ )[ 0 ].constructor, RegExp, "Pass makeArray a regex" ); // Some nodes inherit traits of nodelists - assert.ok( jQuery.makeArray(document.getElementById("form")).length >= 13, + assert.ok( jQuery.makeArray( document.getElementById( "form" ) ).length >= 13, "Pass makeArray a form (treat as elements)" ); -}); +} ); -QUnit.test("jQuery.inArray", function( assert ){ - assert.expect(3); +QUnit.test( "jQuery.inArray", function( assert ) { + assert.expect( 3 ); - assert.equal( jQuery.inArray( 0, false ), -1 , "Search in 'false' as array returns -1 and doesn't throw exception" ); + assert.equal( jQuery.inArray( 0, false ), -1, "Search in 'false' as array returns -1 and doesn't throw exception" ); - assert.equal( jQuery.inArray( 0, null ), -1 , "Search in 'null' as array returns -1 and doesn't throw exception" ); + assert.equal( jQuery.inArray( 0, null ), -1, "Search in 'null' as array returns -1 and doesn't throw exception" ); - assert.equal( jQuery.inArray( 0, undefined ), -1 , "Search in 'undefined' as array returns -1 and doesn't throw exception" ); -}); + assert.equal( jQuery.inArray( 0, undefined ), -1, "Search in 'undefined' as array returns -1 and doesn't throw exception" ); +} ); -QUnit.test("jQuery.isEmptyObject", function( assert ){ - assert.expect(2); +QUnit.test( "jQuery.isEmptyObject", function( assert ) { + assert.expect( 2 ); - assert.equal(true, jQuery.isEmptyObject({}), "isEmptyObject on empty object literal" ); - assert.equal(false, jQuery.isEmptyObject({a:1}), "isEmptyObject on non-empty object literal" ); + assert.equal( true, jQuery.isEmptyObject( {} ), "isEmptyObject on empty object literal" ); + assert.equal( false, jQuery.isEmptyObject( { a:1 } ), "isEmptyObject on non-empty object literal" ); // What about this ? // equal(true, jQuery.isEmptyObject(null), "isEmptyObject on null" ); -}); +} ); -QUnit.test("jQuery.proxy", function( assert ){ +QUnit.test( "jQuery.proxy", function( assert ) { assert.expect( 9 ); var test2, test3, test4, fn, cb, - test = function(){ equal( this, thisObject, "Make sure that scope is set properly." ); }, + test = function() { equal( this, thisObject, "Make sure that scope is set properly." ); }, thisObject = { foo: "bar", method: test }; // Make sure normal works @@ -1313,15 +1319,15 @@ QUnit.test("jQuery.proxy", function( assert ){ assert.equal( jQuery.proxy( null, thisObject ), undefined, "Make sure no function was returned." ); // Partial application - test2 = function( a ){ equal( a, "pre-applied", "Ensure arguments can be pre-applied." ); }; + test2 = function( a ) { equal( a, "pre-applied", "Ensure arguments can be pre-applied." ); }; jQuery.proxy( test2, null, "pre-applied" )(); // Partial application w/ normal arguments - test3 = function( a, b ){ equal( b, "normal", "Ensure arguments can be pre-applied and passed as usual." ); }; + test3 = function( a, b ) { equal( b, "normal", "Ensure arguments can be pre-applied and passed as usual." ); }; jQuery.proxy( test3, null, "pre-applied" )( "normal" ); // Test old syntax - test4 = { "meth": function( a ){ equal( a, "boom", "Ensure old syntax works." ); } }; + test4 = { "meth": function( a ) { equal( a, "boom", "Ensure old syntax works." ); } }; jQuery.proxy( test4, "meth" )( "boom" ); // jQuery 1.9 improved currying with `this` object @@ -1331,9 +1337,9 @@ QUnit.test("jQuery.proxy", function( assert ){ }; cb = jQuery.proxy( fn, null, "arg1", "arg2" ); cb.call( thisObject, "arg3" ); -}); +} ); -QUnit.test("jQuery.parseHTML", function( assert ) { +QUnit.test( "jQuery.parseHTML", function( assert ) { assert.expect( 23 ); var html, nodes; @@ -1346,91 +1352,91 @@ QUnit.test("jQuery.parseHTML", function( assert ) { assert.deepEqual( jQuery.parseHTML( true ), [], "Boolean true" ); assert.deepEqual( jQuery.parseHTML( 42 ), [], "Positive number" ); assert.deepEqual( jQuery.parseHTML( "" ), [], "Empty string" ); - assert.throws(function() { - jQuery.parseHTML( "<div></div>", document.getElementById("form") ); - }, "Passing an element as the context raises an exception (context should be a document)"); + assert.throws( function() { + jQuery.parseHTML( "<div></div>", document.getElementById( "form" ) ); + }, "Passing an element as the context raises an exception (context should be a document)" ); - nodes = jQuery.parseHTML( jQuery("body")[0].innerHTML ); + nodes = jQuery.parseHTML( jQuery( "body" )[ 0 ].innerHTML ); assert.ok( nodes.length > 4, "Parse a large html string" ); assert.equal( jQuery.type( nodes ), "array", "parseHTML returns an array rather than a nodelist" ); html = "<script>undefined()</script>"; assert.equal( jQuery.parseHTML( html ).length, 0, "Ignore scripts by default" ); - assert.equal( jQuery.parseHTML( html, true )[0].nodeName.toLowerCase(), "script", "Preserve scripts when requested" ); + assert.equal( jQuery.parseHTML( html, true )[ 0 ].nodeName.toLowerCase(), "script", "Preserve scripts when requested" ); html += "<div></div>"; - assert.equal( jQuery.parseHTML( html )[0].nodeName.toLowerCase(), "div", "Preserve non-script nodes" ); - assert.equal( jQuery.parseHTML( html, true )[0].nodeName.toLowerCase(), "script", "Preserve script position"); + assert.equal( jQuery.parseHTML( html )[ 0 ].nodeName.toLowerCase(), "div", "Preserve non-script nodes" ); + assert.equal( jQuery.parseHTML( html, true )[ 0 ].nodeName.toLowerCase(), "script", "Preserve script position" ); - assert.equal( jQuery.parseHTML("text")[0].nodeType, 3, "Parsing text returns a text node" ); - assert.equal( jQuery.parseHTML( "\t<div></div>" )[0].nodeValue, "\t", "Preserve leading whitespace" ); + assert.equal( jQuery.parseHTML( "text" )[ 0 ].nodeType, 3, "Parsing text returns a text node" ); + assert.equal( jQuery.parseHTML( "\t<div></div>" )[ 0 ].nodeValue, "\t", "Preserve leading whitespace" ); - assert.equal( jQuery.parseHTML(" <div/> ")[0].nodeType, 3, "Leading spaces are treated as text nodes (#11290)" ); + assert.equal( jQuery.parseHTML( " <div/> " )[ 0 ].nodeType, 3, "Leading spaces are treated as text nodes (#11290)" ); html = jQuery.parseHTML( "<div>test div</div>" ); assert.equal( html[ 0 ].parentNode.nodeType, 11, "parentNode should be documentFragment" ); assert.equal( html[ 0 ].innerHTML, "test div", "Content should be preserved" ); - assert.equal( jQuery.parseHTML("<span><span>").length, 1, "Incorrect html-strings should not break anything" ); - assert.equal( jQuery.parseHTML("<td><td>")[ 1 ].parentNode.nodeType, 11, + assert.equal( jQuery.parseHTML( "<span><span>" ).length, 1, "Incorrect html-strings should not break anything" ); + assert.equal( jQuery.parseHTML( "<td><td>" )[ 1 ].parentNode.nodeType, 11, "parentNode should be documentFragment for wrapMap (variable in manipulation module) elements too" ); - assert.ok( jQuery.parseHTML("<#if><tr><p>This is a test.</p></tr><#/if>") || true, "Garbage input should not cause error" ); -}); + assert.ok( jQuery.parseHTML( "<#if><tr><p>This is a test.</p></tr><#/if>" ) || true, "Garbage input should not cause error" ); +} ); if ( jQuery.support.createHTMLDocument ) { - QUnit.asyncTest("jQuery.parseHTML", function( assert ) { + QUnit.asyncTest( "jQuery.parseHTML", function( assert ) { expect ( 1 ); - Globals.register("parseHTMLError"); + Globals.register( "parseHTMLError" ); - jQuery.globalEval("parseHTMLError = false;"); + jQuery.globalEval( "parseHTMLError = false;" ); jQuery.parseHTML( "<img src=x onerror='parseHTMLError = true'>" ); - window.setTimeout(function() { + window.setTimeout( function() { QUnit.start(); assert.equal( window.parseHTMLError, false, "onerror eventhandler has not been called." ); - }, 2000); - }); + }, 2000 ); + } ); } -QUnit.test("jQuery.parseJSON", function( assert ) { +QUnit.test( "jQuery.parseJSON", function( assert ) { assert.expect( 20 ); assert.strictEqual( jQuery.parseJSON( null ), null, "primitive null" ); - assert.strictEqual( jQuery.parseJSON("0.88"), 0.88, "Number" ); + assert.strictEqual( jQuery.parseJSON( "0.88" ), 0.88, "Number" ); assert.strictEqual( - jQuery.parseJSON("\" \\\" \\\\ \\/ \\b \\f \\n \\r \\t \\u007E \\u263a \""), + jQuery.parseJSON( "\" \\\" \\\\ \\/ \\b \\f \\n \\r \\t \\u007E \\u263a \"" ), " \" \\ / \b \f \n \r \t ~ \u263A ", "String escapes" ); - assert.deepEqual( jQuery.parseJSON("{}"), {}, "Empty object" ); - assert.deepEqual( jQuery.parseJSON("{\"test\":1}"), { "test": 1 }, "Plain object" ); - assert.deepEqual( jQuery.parseJSON("[0]"), [ 0 ], "Simple array" ); + assert.deepEqual( jQuery.parseJSON( "{}" ), {}, "Empty object" ); + assert.deepEqual( jQuery.parseJSON( "{\"test\":1}" ), { "test": 1 }, "Plain object" ); + assert.deepEqual( jQuery.parseJSON( "[0]" ), [ 0 ], "Simple array" ); assert.deepEqual( - jQuery.parseJSON("[ \"string\", -4.2, 2.7180e0, 3.14E-1, {}, [], true, false, null ]"), + jQuery.parseJSON( "[ \"string\", -4.2, 2.7180e0, 3.14E-1, {}, [], true, false, null ]" ), [ "string", -4.2, 2.718, 0.314, {}, [], true, false, null ], "Array of all data types" ); assert.deepEqual( jQuery.parseJSON( "{ \"string\": \"\", \"number\": 4.2e+1, \"object\": {}," + - "\"array\": [[]], \"boolean\": [ true, false ], \"null\": null }"), - { string: "", number: 42, object: {}, array: [[]], "boolean": [ true, false ], "null": null }, + "\"array\": [[]], \"boolean\": [ true, false ], \"null\": null }" ), + { string: "", number: 42, object: {}, array: [ [] ], "boolean": [ true, false ], "null": null }, "Dictionary of all data types" ); - assert.deepEqual( jQuery.parseJSON("\n{\"test\":1}\t"), { "test": 1 }, + assert.deepEqual( jQuery.parseJSON( "\n{\"test\":1}\t" ), { "test": 1 }, "Leading and trailing whitespace are ignored" ); - assert.throws(function() { + assert.throws( function() { jQuery.parseJSON(); }, null, "Undefined raises an error" ); - assert.throws(function() { + assert.throws( function() { jQuery.parseJSON( "" ); }, null, "Empty string raises an error" ); - assert.throws(function() { - jQuery.parseJSON("''"); + assert.throws( function() { + jQuery.parseJSON( "''" ); }, null, "Single-quoted string raises an error" ); /* @@ -1450,38 +1456,38 @@ QUnit.test("jQuery.parseJSON", function( assert ) { }, null, "Number with no integer component raises an error" ); */ - assert.throws(function() { - var result = jQuery.parseJSON("0101"); + assert.throws( function() { + var result = jQuery.parseJSON( "0101" ); // Support: IE9+ // Ensure base-10 interpretation on browsers that erroneously accept leading-zero numbers if ( result === 101 ) { - throw new Error("close enough"); + throw new Error( "close enough" ); } }, null, "Leading-zero number raises an error or is parsed as decimal" ); - assert.throws(function() { - jQuery.parseJSON("{a:1}"); + assert.throws( function() { + jQuery.parseJSON( "{a:1}" ); }, null, "Unquoted property raises an error" ); - assert.throws(function() { - jQuery.parseJSON("{'a':1}"); + assert.throws( function() { + jQuery.parseJSON( "{'a':1}" ); }, null, "Single-quoted property raises an error" ); - assert.throws(function() { - jQuery.parseJSON("[,]"); + assert.throws( function() { + jQuery.parseJSON( "[,]" ); }, null, "Array element elision raises an error" ); - assert.throws(function() { - jQuery.parseJSON("{},[]"); + assert.throws( function() { + jQuery.parseJSON( "{},[]" ); }, null, "Comma expression raises an error" ); - assert.throws(function() { - jQuery.parseJSON("[]\n,{}"); + assert.throws( function() { + jQuery.parseJSON( "[]\n,{}" ); }, null, "Newline-containing comma expression raises an error" ); - assert.throws(function() { - jQuery.parseJSON("\"\"\n\"\""); + assert.throws( function() { + jQuery.parseJSON( "\"\"\n\"\"" ); }, null, "Automatic semicolon insertion raises an error" ); - assert.strictEqual( jQuery.parseJSON([ 0 ]), 0, "Input cast to string" ); -}); + assert.strictEqual( jQuery.parseJSON( [ 0 ] ), 0, "Input cast to string" ); +} ); -QUnit.test("jQuery.parseXML", function( assert ){ +QUnit.test( "jQuery.parseXML", function( assert ) { assert.expect( 8 ); var xml, tmp; @@ -1492,13 +1498,13 @@ QUnit.test("jQuery.parseXML", function( assert ){ tmp = tmp.getElementsByTagName( "b" )[ 0 ]; assert.ok( !!tmp, "<b> present in document" ); assert.strictEqual( tmp.childNodes[ 0 ].nodeValue, "well-formed", "<b> text is as expected" ); - } catch (e) { + } catch ( e ) { assert.strictEqual( e, undefined, "unexpected error" ); } try { xml = jQuery.parseXML( "<p>Not a <<b>well-formed</b> xml string</p>" ); assert.ok( false, "invalid xml not detected" ); - } catch( e ) { + } catch ( e ) { assert.strictEqual( e.message, "Invalid XML: <p>Not a <<b>well-formed</b> xml string</p>", "invalid xml detected" ); } try { @@ -1510,12 +1516,12 @@ QUnit.test("jQuery.parseXML", function( assert ){ assert.strictEqual( xml, null, "null string => null document" ); xml = jQuery.parseXML( true ); assert.strictEqual( xml, null, "non-string => null document" ); - } catch( e ) { + } catch ( e ) { assert.ok( false, "empty input throws exception" ); } -}); +} ); -QUnit.test("jQuery.camelCase()", function( assert ) { +QUnit.test( "jQuery.camelCase()", function( assert ) { var tests = { "foo-bar": "fooBar", @@ -1527,12 +1533,12 @@ QUnit.test("jQuery.camelCase()", function( assert ) { "-ms-take": "msTake" }; - assert.expect(7); + assert.expect( 7 ); jQuery.each( tests, function( key, val ) { assert.equal( jQuery.camelCase( key ), val, "Converts: " + key + " => " + val ); - }); -}); + } ); +} ); testIframeWithCallback( "Conditional compilation compatibility (#13274)", diff --git a/test/unit/css.js b/test/unit/css.js index c28afd6fa..f91c50940 100644 --- a/test/unit/css.js +++ b/test/unit/css.js @@ -1,85 +1,85 @@ if ( jQuery.css ) { -QUnit.module("css", { teardown: moduleTeardown }); +QUnit.module( "css", { teardown: moduleTeardown } ); -QUnit.test("css(String|Hash)", function( assert ) { +QUnit.test( "css(String|Hash)", function( assert ) { assert.expect( 42 ); - assert.equal( jQuery("#qunit-fixture").css("display"), "block", "Check for css property \"display\"" ); + assert.equal( jQuery( "#qunit-fixture" ).css( "display" ), "block", "Check for css property \"display\"" ); var $child, div, div2, width, height, child, prctval, checkval, old; - $child = jQuery("#nothiddendivchild").css({ "width": "20%", "height": "20%" }); - assert.notEqual( $child.css("width"), "20px", "Retrieving a width percentage on the child of a hidden div returns percentage" ); - assert.notEqual( $child.css("height"), "20px", "Retrieving a height percentage on the child of a hidden div returns percentage" ); + $child = jQuery( "#nothiddendivchild" ).css( { "width": "20%", "height": "20%" } ); + assert.notEqual( $child.css( "width" ), "20px", "Retrieving a width percentage on the child of a hidden div returns percentage" ); + assert.notEqual( $child.css( "height" ), "20px", "Retrieving a height percentage on the child of a hidden div returns percentage" ); div = jQuery( "<div/>" ); // These should be "auto" (or some better value) // temporarily provide "0px" for backwards compat - assert.equal( div.css("width"), "0px", "Width on disconnected node." ); - assert.equal( div.css("height"), "0px", "Height on disconnected node." ); + assert.equal( div.css( "width" ), "0px", "Width on disconnected node." ); + assert.equal( div.css( "height" ), "0px", "Height on disconnected node." ); - div.css({ "width": 4, "height": 4 }); + div.css( { "width": 4, "height": 4 } ); - assert.equal( div.css("width"), "4px", "Width on disconnected node." ); - assert.equal( div.css("height"), "4px", "Height on disconnected node." ); + assert.equal( div.css( "width" ), "4px", "Width on disconnected node." ); + assert.equal( div.css( "height" ), "4px", "Height on disconnected node." ); - div2 = jQuery( "<div style='display:none;'><input type='text' style='height:20px;'/><textarea style='height:20px;'/><div style='height:20px;'></div></div>").appendTo("body"); + div2 = jQuery( "<div style='display:none;'><input type='text' style='height:20px;'/><textarea style='height:20px;'/><div style='height:20px;'></div></div>" ).appendTo( "body" ); - assert.equal( div2.find("input").css("height"), "20px", "Height on hidden input." ); - assert.equal( div2.find("textarea").css("height"), "20px", "Height on hidden textarea." ); - assert.equal( div2.find("div").css("height"), "20px", "Height on hidden div." ); + assert.equal( div2.find( "input" ).css( "height" ), "20px", "Height on hidden input." ); + assert.equal( div2.find( "textarea" ).css( "height" ), "20px", "Height on hidden textarea." ); + assert.equal( div2.find( "div" ).css( "height" ), "20px", "Height on hidden div." ); div2.remove(); // handle negative numbers by setting to zero #11604 - jQuery("#nothiddendiv").css( {"width": 1, "height": 1} ); - - width = parseFloat(jQuery("#nothiddendiv").css("width")); - height = parseFloat(jQuery("#nothiddendiv").css("height")); - jQuery("#nothiddendiv").css({ "overflow":"hidden", "width": -1, "height": -1 }); - assert.equal( parseFloat(jQuery("#nothiddendiv").css("width")), 0, "Test negative width set to 0"); - assert.equal( parseFloat(jQuery("#nothiddendiv").css("height")), 0, "Test negative height set to 0"); - - assert.equal( jQuery("<div style='display: none;'/>").css("display"), "none", "Styles on disconnected nodes"); - - jQuery("#floatTest").css({"float": "right"}); - assert.equal( jQuery("#floatTest").css("float"), "right", "Modified CSS float using \"float\": Assert float is right"); - jQuery("#floatTest").css({"font-size": "30px"}); - assert.equal( jQuery("#floatTest").css("font-size"), "30px", "Modified CSS font-size: Assert font-size is 30px"); - jQuery.each("0,0.25,0.5,0.75,1".split(","), function(i, n) { - jQuery("#foo").css({"opacity": n}); - - assert.equal( jQuery("#foo").css("opacity"), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a String" ); - jQuery("#foo").css({"opacity": parseFloat(n)}); - assert.equal( jQuery("#foo").css("opacity"), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a Number" ); - }); - jQuery("#foo").css({"opacity": ""}); - assert.equal( jQuery("#foo").css("opacity"), "1", "Assert opacity is 1 when set to an empty String" ); + jQuery( "#nothiddendiv" ).css( { "width": 1, "height": 1 } ); + + width = parseFloat( jQuery( "#nothiddendiv" ).css( "width" ) ); + height = parseFloat( jQuery( "#nothiddendiv" ).css( "height" ) ); + jQuery( "#nothiddendiv" ).css( { "overflow":"hidden", "width": -1, "height": -1 } ); + assert.equal( parseFloat( jQuery( "#nothiddendiv" ).css( "width" ) ), 0, "Test negative width set to 0" ); + assert.equal( parseFloat( jQuery( "#nothiddendiv" ).css( "height" ) ), 0, "Test negative height set to 0" ); + + assert.equal( jQuery( "<div style='display: none;'/>" ).css( "display" ), "none", "Styles on disconnected nodes" ); + + jQuery( "#floatTest" ).css( { "float": "right" } ); + assert.equal( jQuery( "#floatTest" ).css( "float" ), "right", "Modified CSS float using \"float\": Assert float is right" ); + jQuery( "#floatTest" ).css( { "font-size": "30px" } ); + assert.equal( jQuery( "#floatTest" ).css( "font-size" ), "30px", "Modified CSS font-size: Assert font-size is 30px" ); + jQuery.each( "0,0.25,0.5,0.75,1".split( "," ), function( i, n ) { + jQuery( "#foo" ).css( { "opacity": n } ); + + assert.equal( jQuery( "#foo" ).css( "opacity" ), parseFloat( n ), "Assert opacity is " + parseFloat( n ) + " as a String" ); + jQuery( "#foo" ).css( { "opacity": parseFloat( n ) } ); + assert.equal( jQuery( "#foo" ).css( "opacity" ), parseFloat( n ), "Assert opacity is " + parseFloat( n ) + " as a Number" ); + } ); + jQuery( "#foo" ).css( { "opacity": "" } ); + assert.equal( jQuery( "#foo" ).css( "opacity" ), "1", "Assert opacity is 1 when set to an empty String" ); - assert.equal( jQuery("#empty").css("opacity"), "0", "Assert opacity is accessible via filter property set in stylesheet in IE" ); - jQuery("#empty").css({ "opacity": "1" }); - assert.equal( jQuery("#empty").css("opacity"), "1", "Assert opacity is taken from style attribute when set vs stylesheet in IE with filters" ); + assert.equal( jQuery( "#empty" ).css( "opacity" ), "0", "Assert opacity is accessible via filter property set in stylesheet in IE" ); + jQuery( "#empty" ).css( { "opacity": "1" } ); + assert.equal( jQuery( "#empty" ).css( "opacity" ), "1", "Assert opacity is taken from style attribute when set vs stylesheet in IE with filters" ); - div = jQuery("#nothiddendiv"); - child = jQuery("#nothiddendivchild"); + div = jQuery( "#nothiddendiv" ); + child = jQuery( "#nothiddendivchild" ); - assert.equal( parseInt(div.css("fontSize"), 10), 16, "Verify fontSize px set." ); - assert.equal( parseInt(div.css("font-size"), 10), 16, "Verify fontSize px set." ); - assert.equal( parseInt(child.css("fontSize"), 10), 16, "Verify fontSize px set." ); - assert.equal( parseInt(child.css("font-size"), 10), 16, "Verify fontSize px set." ); + assert.equal( parseInt( div.css( "fontSize" ), 10 ), 16, "Verify fontSize px set." ); + assert.equal( parseInt( div.css( "font-size" ), 10 ), 16, "Verify fontSize px set." ); + assert.equal( parseInt( child.css( "fontSize" ), 10 ), 16, "Verify fontSize px set." ); + assert.equal( parseInt( child.css( "font-size" ), 10 ), 16, "Verify fontSize px set." ); - child.css("height", "100%"); - assert.equal( child[0].style.height, "100%", "Make sure the height is being set correctly." ); + child.css( "height", "100%" ); + assert.equal( child[ 0 ].style.height, "100%", "Make sure the height is being set correctly." ); - child.attr("class", "em"); - assert.equal( parseInt(child.css("fontSize"), 10), 32, "Verify fontSize em set." ); + child.attr( "class", "em" ); + assert.equal( parseInt( child.css( "fontSize" ), 10 ), 32, "Verify fontSize em set." ); // Have to verify this as the result depends upon the browser's CSS // support for font-size percentages - child.attr("class", "prct"); - prctval = parseInt(child.css("fontSize"), 10); + child.attr( "class", "prct" ); + prctval = parseInt( child.css( "fontSize" ), 10 ); checkval = 0; if ( prctval === 16 || prctval === 24 ) { checkval = prctval; @@ -87,123 +87,123 @@ QUnit.test("css(String|Hash)", function( assert ) { assert.equal( prctval, checkval, "Verify fontSize % set." ); - assert.equal( typeof child.css("width"), "string", "Make sure that a string width is returned from css('width')." ); + assert.equal( typeof child.css( "width" ), "string", "Make sure that a string width is returned from css('width')." ); - old = child[0].style.height; + old = child[ 0 ].style.height; // Test NaN - child.css("height", parseFloat("zoo")); - assert.equal( child[0].style.height, old, "Make sure height isn't changed on NaN." ); + child.css( "height", parseFloat( "zoo" ) ); + assert.equal( child[ 0 ].style.height, old, "Make sure height isn't changed on NaN." ); // Test null - child.css("height", null); - assert.equal( child[0].style.height, old, "Make sure height isn't changed on null." ); + child.css( "height", null ); + assert.equal( child[ 0 ].style.height, old, "Make sure height isn't changed on null." ); - old = child[0].style.fontSize; + old = child[ 0 ].style.fontSize; // Test NaN - child.css("font-size", parseFloat("zoo")); - assert.equal( child[0].style.fontSize, old, "Make sure font-size isn't changed on NaN." ); + child.css( "font-size", parseFloat( "zoo" ) ); + assert.equal( child[ 0 ].style.fontSize, old, "Make sure font-size isn't changed on NaN." ); // Test null - child.css("font-size", null); - assert.equal( child[0].style.fontSize, old, "Make sure font-size isn't changed on null." ); + child.css( "font-size", null ); + assert.equal( child[ 0 ].style.fontSize, old, "Make sure font-size isn't changed on null." ); assert.strictEqual( child.css( "x-fake" ), undefined, "Make sure undefined is returned from css(nonexistent)." ); - div = jQuery( "<div/>" ).css({ position: "absolute", "z-index": 1000 }).appendTo( "#qunit-fixture" ); + div = jQuery( "<div/>" ).css( { position: "absolute", "z-index": 1000 } ).appendTo( "#qunit-fixture" ); assert.strictEqual( div.css( "z-index" ), "1000", "Make sure that a string z-index is returned from css('z-index') (#14432)." ); -}); +} ); QUnit.test( "css() explicit and relative values", function( assert ) { assert.expect( 29 ); - var $elem = jQuery("#nothiddendiv"); + var $elem = jQuery( "#nothiddendiv" ); - $elem.css({ "width": 1, "height": 1, "paddingLeft": "1px", "opacity": 1 }); - assert.equal( $elem.css("width"), "1px", "Initial css set or width/height works (hash)" ); - assert.equal( $elem.css("paddingLeft"), "1px", "Initial css set of paddingLeft works (hash)" ); - assert.equal( $elem.css("opacity"), "1", "Initial css set of opacity works (hash)" ); + $elem.css( { "width": 1, "height": 1, "paddingLeft": "1px", "opacity": 1 } ); + assert.equal( $elem.css( "width" ), "1px", "Initial css set or width/height works (hash)" ); + assert.equal( $elem.css( "paddingLeft" ), "1px", "Initial css set of paddingLeft works (hash)" ); + assert.equal( $elem.css( "opacity" ), "1", "Initial css set of opacity works (hash)" ); - $elem.css({ width: "+=9" }); - assert.equal( $elem.css("width"), "10px", "'+=9' on width (hash)" ); + $elem.css( { width: "+=9" } ); + assert.equal( $elem.css( "width" ), "10px", "'+=9' on width (hash)" ); - $elem.css({ "width": "-=9" }); - assert.equal( $elem.css("width"), "1px", "'-=9' on width (hash)" ); + $elem.css( { "width": "-=9" } ); + assert.equal( $elem.css( "width" ), "1px", "'-=9' on width (hash)" ); - $elem.css({ "width": "+=9px" }); - assert.equal( $elem.css("width"), "10px", "'+=9px' on width (hash)" ); + $elem.css( { "width": "+=9px" } ); + assert.equal( $elem.css( "width" ), "10px", "'+=9px' on width (hash)" ); - $elem.css({ "width": "-=9px" }); - assert.equal( $elem.css("width"), "1px", "'-=9px' on width (hash)" ); + $elem.css( { "width": "-=9px" } ); + assert.equal( $elem.css( "width" ), "1px", "'-=9px' on width (hash)" ); $elem.css( "width", "+=9" ); - assert.equal( $elem.css("width"), "10px", "'+=9' on width (params)" ); + assert.equal( $elem.css( "width" ), "10px", "'+=9' on width (params)" ); $elem.css( "width", "-=9" ) ; - assert.equal( $elem.css("width"), "1px", "'-=9' on width (params)" ); + assert.equal( $elem.css( "width" ), "1px", "'-=9' on width (params)" ); $elem.css( "width", "+=9px" ); - assert.equal( $elem.css("width"), "10px", "'+=9px' on width (params)" ); + assert.equal( $elem.css( "width" ), "10px", "'+=9px' on width (params)" ); $elem.css( "width", "-=9px" ); - assert.equal( $elem.css("width"), "1px", "'-=9px' on width (params)" ); + assert.equal( $elem.css( "width" ), "1px", "'-=9px' on width (params)" ); $elem.css( "width", "-=-9px" ); - assert.equal( $elem.css("width"), "10px", "'-=-9px' on width (params)" ); + assert.equal( $elem.css( "width" ), "10px", "'-=-9px' on width (params)" ); $elem.css( "width", "+=-9px" ); - assert.equal( $elem.css("width"), "1px", "'+=-9px' on width (params)" ); + assert.equal( $elem.css( "width" ), "1px", "'+=-9px' on width (params)" ); - $elem.css({ "paddingLeft": "+=4" }); - assert.equal( $elem.css("paddingLeft"), "5px", "'+=4' on paddingLeft (hash)" ); + $elem.css( { "paddingLeft": "+=4" } ); + assert.equal( $elem.css( "paddingLeft" ), "5px", "'+=4' on paddingLeft (hash)" ); - $elem.css({ "paddingLeft": "-=4" }); - assert.equal( $elem.css("paddingLeft"), "1px", "'-=4' on paddingLeft (hash)" ); + $elem.css( { "paddingLeft": "-=4" } ); + assert.equal( $elem.css( "paddingLeft" ), "1px", "'-=4' on paddingLeft (hash)" ); - $elem.css({ "paddingLeft": "+=4px" }); - assert.equal( $elem.css("paddingLeft"), "5px", "'+=4px' on paddingLeft (hash)" ); + $elem.css( { "paddingLeft": "+=4px" } ); + assert.equal( $elem.css( "paddingLeft" ), "5px", "'+=4px' on paddingLeft (hash)" ); - $elem.css({ "paddingLeft": "-=4px" }); - assert.equal( $elem.css("paddingLeft"), "1px", "'-=4px' on paddingLeft (hash)" ); + $elem.css( { "paddingLeft": "-=4px" } ); + assert.equal( $elem.css( "paddingLeft" ), "1px", "'-=4px' on paddingLeft (hash)" ); - $elem.css({ "padding-left": "+=4" }); - assert.equal( $elem.css("paddingLeft"), "5px", "'+=4' on padding-left (hash)" ); + $elem.css( { "padding-left": "+=4" } ); + assert.equal( $elem.css( "paddingLeft" ), "5px", "'+=4' on padding-left (hash)" ); - $elem.css({ "padding-left": "-=4" }); - assert.equal( $elem.css("paddingLeft"), "1px", "'-=4' on padding-left (hash)" ); + $elem.css( { "padding-left": "-=4" } ); + assert.equal( $elem.css( "paddingLeft" ), "1px", "'-=4' on padding-left (hash)" ); - $elem.css({ "padding-left": "+=4px" }); - assert.equal( $elem.css("paddingLeft"), "5px", "'+=4px' on padding-left (hash)" ); + $elem.css( { "padding-left": "+=4px" } ); + assert.equal( $elem.css( "paddingLeft" ), "5px", "'+=4px' on padding-left (hash)" ); - $elem.css({ "padding-left": "-=4px" }); - assert.equal( $elem.css("paddingLeft"), "1px", "'-=4px' on padding-left (hash)" ); + $elem.css( { "padding-left": "-=4px" } ); + assert.equal( $elem.css( "paddingLeft" ), "1px", "'-=4px' on padding-left (hash)" ); $elem.css( "paddingLeft", "+=4" ); - assert.equal( $elem.css("paddingLeft"), "5px", "'+=4' on paddingLeft (params)" ); + assert.equal( $elem.css( "paddingLeft" ), "5px", "'+=4' on paddingLeft (params)" ); $elem.css( "paddingLeft", "-=4" ); - assert.equal( $elem.css("paddingLeft"), "1px", "'-=4' on paddingLeft (params)" ); + assert.equal( $elem.css( "paddingLeft" ), "1px", "'-=4' on paddingLeft (params)" ); $elem.css( "padding-left", "+=4px" ); - assert.equal( $elem.css("paddingLeft"), "5px", "'+=4px' on padding-left (params)" ); + assert.equal( $elem.css( "paddingLeft" ), "5px", "'+=4px' on padding-left (params)" ); $elem.css( "padding-left", "-=4px" ); - assert.equal( $elem.css("paddingLeft"), "1px", "'-=4px' on padding-left (params)" ); + assert.equal( $elem.css( "paddingLeft" ), "1px", "'-=4px' on padding-left (params)" ); - $elem.css({ "opacity": "-=0.5" }); - assert.equal( $elem.css("opacity"), "0.5", "'-=0.5' on opacity (hash)" ); + $elem.css( { "opacity": "-=0.5" } ); + assert.equal( $elem.css( "opacity" ), "0.5", "'-=0.5' on opacity (hash)" ); - $elem.css({ "opacity": "+=0.5" }); - assert.equal( $elem.css("opacity"), "1", "'+=0.5' on opacity (hash)" ); + $elem.css( { "opacity": "+=0.5" } ); + assert.equal( $elem.css( "opacity" ), "1", "'+=0.5' on opacity (hash)" ); $elem.css( "opacity", "-=0.5" ); - assert.equal( $elem.css("opacity"), "0.5", "'-=0.5' on opacity (params)" ); + assert.equal( $elem.css( "opacity" ), "0.5", "'-=0.5' on opacity (params)" ); $elem.css( "opacity", "+=0.5" ); - assert.equal( $elem.css("opacity"), "1", "'+=0.5' on opacity (params)" ); -}); + assert.equal( $elem.css( "opacity" ), "1", "'+=0.5' on opacity (params)" ); +} ); QUnit.test( "css() non-px relative values (gh-1711)", function( assert ) { assert.expect( 17 ); @@ -240,12 +240,12 @@ QUnit.test( "css() non-px relative values (gh-1711)", function( assert ) { "pc": parseFloat( $child.css( prop, "100pc" ).css( prop ) ) / 100, "cm": parseFloat( $child.css( prop, "100cm" ).css( prop ) ) / 100, "mm": parseFloat( $child.css( prop, "100mm" ).css( prop ) ) / 100, - "%" : parseFloat( $child.css( prop, "100%" ).css( prop ) ) / 100 + "%": parseFloat( $child.css( prop, "100%" ).css( prop ) ) / 100 }; }; - jQuery( "#nothiddendiv" ).css({ height: 1, padding: 0, width: 400 }); - $child.css({ height: 1, padding: 0 }); + jQuery( "#nothiddendiv" ).css( { height: 1, padding: 0, width: 400 } ); + $child.css( { height: 1, padding: 0 } ); getUnits( "width" ); cssCurrent = parseFloat( $child.css( "width", "50%" ).css( "width" ) ); @@ -269,44 +269,44 @@ QUnit.test( "css() non-px relative values (gh-1711)", function( assert ) { add( "lineHeight", 1, "cm" ); add( "lineHeight", -20, "mm" ); add( "lineHeight", 50, "%" ); -}); +} ); -QUnit.test("css(String, Object)", function( assert ) { +QUnit.test( "css(String, Object)", function( assert ) { assert.expect( 19 ); var j, div, display, ret, success; - jQuery("#floatTest").css("float", "left"); - assert.equal( jQuery("#floatTest").css("float"), "left", "Modified CSS float using \"float\": Assert float is left"); - jQuery("#floatTest").css("font-size", "20px"); - assert.equal( jQuery("#floatTest").css("font-size"), "20px", "Modified CSS font-size: Assert font-size is 20px"); + jQuery( "#floatTest" ).css( "float", "left" ); + assert.equal( jQuery( "#floatTest" ).css( "float" ), "left", "Modified CSS float using \"float\": Assert float is left" ); + jQuery( "#floatTest" ).css( "font-size", "20px" ); + assert.equal( jQuery( "#floatTest" ).css( "font-size" ), "20px", "Modified CSS font-size: Assert font-size is 20px" ); - jQuery.each("0,0.25,0.5,0.75,1".split(","), function(i, n) { - jQuery("#foo").css("opacity", n); - assert.equal( jQuery("#foo").css("opacity"), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a String" ); - jQuery("#foo").css("opacity", parseFloat(n)); - assert.equal( jQuery("#foo").css("opacity"), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a Number" ); - }); - jQuery("#foo").css("opacity", ""); - assert.equal( jQuery("#foo").css("opacity"), "1", "Assert opacity is 1 when set to an empty String" ); + jQuery.each( "0,0.25,0.5,0.75,1".split( "," ), function( i, n ) { + jQuery( "#foo" ).css( "opacity", n ); + assert.equal( jQuery( "#foo" ).css( "opacity" ), parseFloat( n ), "Assert opacity is " + parseFloat( n ) + " as a String" ); + jQuery( "#foo" ).css( "opacity", parseFloat( n ) ); + assert.equal( jQuery( "#foo" ).css( "opacity" ), parseFloat( n ), "Assert opacity is " + parseFloat( n ) + " as a Number" ); + } ); + jQuery( "#foo" ).css( "opacity", "" ); + assert.equal( jQuery( "#foo" ).css( "opacity" ), "1", "Assert opacity is 1 when set to an empty String" ); // using contents will get comments regular, text, and comment nodes - j = jQuery("#nonnodes").contents(); - j.css("overflow", "visible"); - assert.equal( j.css("overflow"), "visible", "Check node,textnode,comment css works" ); - assert.equal( jQuery("#t2037 .hidden").css("display"), "none", "Make sure browser thinks it is hidden" ); + j = jQuery( "#nonnodes" ).contents(); + j.css( "overflow", "visible" ); + assert.equal( j.css( "overflow" ), "visible", "Check node,textnode,comment css works" ); + assert.equal( jQuery( "#t2037 .hidden" ).css( "display" ), "none", "Make sure browser thinks it is hidden" ); - div = jQuery("#nothiddendiv"); - display = div.css("display"); - ret = div.css("display", undefined); + div = jQuery( "#nothiddendiv" ); + display = div.css( "display" ); + ret = div.css( "display", undefined ); assert.equal( ret, div, "Make sure setting undefined returns the original set." ); - assert.equal( div.css("display"), display, "Make sure that the display wasn't changed." ); + assert.equal( div.css( "display" ), display, "Make sure that the display wasn't changed." ); success = true; try { jQuery( "#foo" ).css( "backgroundColor", "rgba(0, 0, 0, 0.1)" ); } - catch (e) { + catch ( e ) { success = false; } assert.ok( success, "Setting RGBA values does not throw Error (#5509)" ); @@ -314,7 +314,7 @@ QUnit.test("css(String, Object)", function( assert ) { jQuery( "#foo" ).css( "font", "7px/21px sans-serif" ); assert.strictEqual( jQuery( "#foo" ).css( "line-height" ), "21px", "Set font shorthand property (#14759)" ); -}); +} ); QUnit.test( "css(String, Object) with negative values", function( assert ) { assert.expect( 4 ); @@ -329,7 +329,7 @@ QUnit.test( "css(String, Object) with negative values", function( assert ) { jQuery( "#nothiddendiv" ).css( "left", "-20px" ); assert.equal( jQuery( "#nothiddendiv" ).css( "top" ), "-20px", "Ensure negative top values work." ); assert.equal( jQuery( "#nothiddendiv" ).css( "left" ), "-20px", "Ensure negative left values work." ); -}); +} ); QUnit.test( "css(Array)", function( assert ) { assert.expect( 2 ); @@ -341,179 +341,179 @@ QUnit.test( "css(Array)", function( assert ) { expectedSingle = { "width": "16px" }, - elem = jQuery("<div></div>").appendTo("#qunit-fixture"); + elem = jQuery( "<div></div>" ).appendTo( "#qunit-fixture" ); - assert.deepEqual( elem.css( expectedMany ).css([ "overflow", "width" ]), expectedMany, "Getting multiple element array" ); - assert.deepEqual( elem.css( expectedSingle ).css([ "width" ]), expectedSingle, "Getting single element array" ); -}); + assert.deepEqual( elem.css( expectedMany ).css( [ "overflow", "width" ] ), expectedMany, "Getting multiple element array" ); + assert.deepEqual( elem.css( expectedSingle ).css( [ "width" ] ), expectedSingle, "Getting single element array" ); +} ); -QUnit.test("css(String, Function)", function( assert ) { - assert.expect(3); +QUnit.test( "css(String, Function)", function( assert ) { + assert.expect( 3 ); var index, - sizes = ["10px", "20px", "30px"]; + sizes = [ "10px", "20px", "30px" ]; - jQuery("<div id='cssFunctionTest'><div class='cssFunction'></div>" + + jQuery( "<div id='cssFunctionTest'><div class='cssFunction'></div>" + "<div class='cssFunction'></div>" + - "<div class='cssFunction'></div></div>") - .appendTo("body"); + "<div class='cssFunction'></div></div>" ) + .appendTo( "body" ); index = 0; - jQuery("#cssFunctionTest div").css("font-size", function() { - var size = sizes[index]; + jQuery( "#cssFunctionTest div" ).css( "font-size", function() { + var size = sizes[ index ]; index++; return size; - }); + } ); index = 0; - jQuery("#cssFunctionTest div").each(function() { - var computedSize = jQuery(this).css("font-size"), - expectedSize = sizes[index]; + jQuery( "#cssFunctionTest div" ).each( function() { + var computedSize = jQuery( this ).css( "font-size" ), + expectedSize = sizes[ index ]; assert.equal( computedSize, expectedSize, "Div #" + index + " should be " + expectedSize ); index++; - }); + } ); - jQuery("#cssFunctionTest").remove(); -}); + jQuery( "#cssFunctionTest" ).remove(); +} ); -QUnit.test("css(String, Function) with incoming value", function( assert ) { - assert.expect(3); +QUnit.test( "css(String, Function) with incoming value", function( assert ) { + assert.expect( 3 ); var index, - sizes = ["10px", "20px", "30px"]; + sizes = [ "10px", "20px", "30px" ]; - jQuery("<div id='cssFunctionTest'><div class='cssFunction'></div>" + + jQuery( "<div id='cssFunctionTest'><div class='cssFunction'></div>" + "<div class='cssFunction'></div>" + - "<div class='cssFunction'></div></div>") - .appendTo("body"); + "<div class='cssFunction'></div></div>" ) + .appendTo( "body" ); index = 0; - jQuery("#cssFunctionTest div").css("font-size", function() { - var size = sizes[index]; + jQuery( "#cssFunctionTest div" ).css( "font-size", function() { + var size = sizes[ index ]; index++; return size; - }); + } ); index = 0; - jQuery("#cssFunctionTest div").css("font-size", function(i, computedSize) { - var expectedSize = sizes[index]; + jQuery( "#cssFunctionTest div" ).css( "font-size", function( i, computedSize ) { + var expectedSize = sizes[ index ]; assert.equal( computedSize, expectedSize, "Div #" + index + " should be " + expectedSize ); index++; return computedSize; - }); + } ); - jQuery("#cssFunctionTest").remove(); -}); + jQuery( "#cssFunctionTest" ).remove(); +} ); -QUnit.test("css(Object) where values are Functions", function( assert ) { - assert.expect(3); +QUnit.test( "css(Object) where values are Functions", function( assert ) { + assert.expect( 3 ); var index, - sizes = ["10px", "20px", "30px"]; + sizes = [ "10px", "20px", "30px" ]; - jQuery("<div id='cssFunctionTest'><div class='cssFunction'></div>" + + jQuery( "<div id='cssFunctionTest'><div class='cssFunction'></div>" + "<div class='cssFunction'></div>" + - "<div class='cssFunction'></div></div>") - .appendTo("body"); + "<div class='cssFunction'></div></div>" ) + .appendTo( "body" ); index = 0; - jQuery("#cssFunctionTest div").css({"fontSize": function() { - var size = sizes[index]; + jQuery( "#cssFunctionTest div" ).css( { "fontSize": function() { + var size = sizes[ index ]; index++; return size; - }}); + } } ); index = 0; - jQuery("#cssFunctionTest div").each(function() { - var computedSize = jQuery(this).css("font-size"), - expectedSize = sizes[index]; + jQuery( "#cssFunctionTest div" ).each( function() { + var computedSize = jQuery( this ).css( "font-size" ), + expectedSize = sizes[ index ]; assert.equal( computedSize, expectedSize, "Div #" + index + " should be " + expectedSize ); index++; - }); + } ); - jQuery("#cssFunctionTest").remove(); -}); + jQuery( "#cssFunctionTest" ).remove(); +} ); -QUnit.test("css(Object) where values are Functions with incoming values", function( assert ) { - assert.expect(3); +QUnit.test( "css(Object) where values are Functions with incoming values", function( assert ) { + assert.expect( 3 ); var index, - sizes = ["10px", "20px", "30px"]; + sizes = [ "10px", "20px", "30px" ]; - jQuery("<div id='cssFunctionTest'><div class='cssFunction'></div>" + + jQuery( "<div id='cssFunctionTest'><div class='cssFunction'></div>" + "<div class='cssFunction'></div>" + - "<div class='cssFunction'></div></div>") - .appendTo("body"); + "<div class='cssFunction'></div></div>" ) + .appendTo( "body" ); index = 0; - jQuery("#cssFunctionTest div").css({"fontSize": function() { - var size = sizes[index]; + jQuery( "#cssFunctionTest div" ).css( { "fontSize": function() { + var size = sizes[ index ]; index++; return size; - }}); + } } ); index = 0; - jQuery("#cssFunctionTest div").css({"font-size": function(i, computedSize) { - var expectedSize = sizes[index]; + jQuery( "#cssFunctionTest div" ).css( { "font-size": function( i, computedSize ) { + var expectedSize = sizes[ index ]; assert.equal( computedSize, expectedSize, "Div #" + index + " should be " + expectedSize ); index++; return computedSize; - }}); + } } ); - jQuery("#cssFunctionTest").remove(); -}); + jQuery( "#cssFunctionTest" ).remove(); +} ); -QUnit.test("show(); hide()", function( assert ) { +QUnit.test( "show(); hide()", function( assert ) { assert.expect( 4 ); var hiddendiv, div; - hiddendiv = jQuery("div.hidden"); + hiddendiv = jQuery( "div.hidden" ); hiddendiv.hide(); - assert.equal( hiddendiv.css("display"), "none", "Cascade-hidden div after hide()" ); + assert.equal( hiddendiv.css( "display" ), "none", "Cascade-hidden div after hide()" ); hiddendiv.show(); - assert.equal( hiddendiv.css("display"), "none", "Show does not trump CSS cascade" ); + assert.equal( hiddendiv.css( "display" ), "none", "Show does not trump CSS cascade" ); - div = jQuery("<div>").hide(); - assert.equal( div.css("display"), "none", "Detached div hidden" ); - div.appendTo("#qunit-fixture").show(); - assert.equal( div.css("display"), "block", "Initially-detached div after show()" ); + div = jQuery( "<div>" ).hide(); + assert.equal( div.css( "display" ), "none", "Detached div hidden" ); + div.appendTo( "#qunit-fixture" ).show(); + assert.equal( div.css( "display" ), "block", "Initially-detached div after show()" ); -}); +} ); -QUnit.test("show();", function( assert ) { +QUnit.test( "show();", function( assert ) { assert.expect( 18 ); var hiddendiv, div, pass, old, test; - hiddendiv = jQuery("div.hidden"); + hiddendiv = jQuery( "div.hidden" ); - assert.equal(jQuery.css( hiddendiv[0], "display"), "none", "hiddendiv is display: none"); + assert.equal( jQuery.css( hiddendiv[ 0 ], "display" ), "none", "hiddendiv is display: none" ); - hiddendiv.css("display", "block"); - assert.equal(jQuery.css( hiddendiv[0], "display"), "block", "hiddendiv is display: block"); + hiddendiv.css( "display", "block" ); + assert.equal( jQuery.css( hiddendiv[ 0 ], "display" ), "block", "hiddendiv is display: block" ); hiddendiv.show(); - assert.equal(jQuery.css( hiddendiv[0], "display"), "block", "hiddendiv is display: block"); + assert.equal( jQuery.css( hiddendiv[ 0 ], "display" ), "block", "hiddendiv is display: block" ); - hiddendiv.css("display",""); + hiddendiv.css( "display", "" ); pass = true; - div = jQuery("#qunit-fixture div"); - div.show().each(function(){ + div = jQuery( "#qunit-fixture div" ); + div.show().each( function() { if ( this.style.display === "none" ) { pass = false; } - }); + } ); assert.ok( pass, "Show" ); jQuery( @@ -524,138 +524,138 @@ QUnit.test("show();", function( assert ) { "<table id='test-table'></table>" ).appendTo( "#qunit-fixture" ).find( "*" ).css( "display", "none" ); - old = jQuery("#test-table").show().css("display") !== "table"; - jQuery("#test-table").remove(); + old = jQuery( "#test-table" ).show().css( "display" ) !== "table"; + jQuery( "#test-table" ).remove(); test = { - "div" : "block", - "p" : "block", - "a" : "inline", - "code" : "inline", - "pre" : "block", - "span" : "inline", - "table" : old ? "block" : "table", - "thead" : old ? "block" : "table-header-group", - "tbody" : old ? "block" : "table-row-group", - "tr" : old ? "block" : "table-row", - "th" : old ? "block" : "table-cell", - "td" : old ? "block" : "table-cell", - "ul" : "block", - "li" : old ? "block" : "list-item" + "div": "block", + "p": "block", + "a": "inline", + "code": "inline", + "pre": "block", + "span": "inline", + "table": old ? "block" : "table", + "thead": old ? "block" : "table-header-group", + "tbody": old ? "block" : "table-row-group", + "tr": old ? "block" : "table-row", + "th": old ? "block" : "table-cell", + "td": old ? "block" : "table-cell", + "ul": "block", + "li": old ? "block" : "list-item" }; - jQuery.each(test, function(selector, expected) { - var elem = jQuery(selector, "#show-tests").show(); - assert.equal( elem.css("display"), expected, "Show using correct display type for " + selector ); - }); + jQuery.each( test, function( selector, expected ) { + var elem = jQuery( selector, "#show-tests" ).show(); + assert.equal( elem.css( "display" ), expected, "Show using correct display type for " + selector ); + } ); // Make sure that showing or hiding a text node doesn't cause an error - jQuery("<div>test</div> text <span>test</span>").show().remove(); - jQuery("<div>test</div> text <span>test</span>").hide().remove(); -}); + jQuery( "<div>test</div> text <span>test</span>" ).show().remove(); + jQuery( "<div>test</div> text <span>test</span>" ).hide().remove(); +} ); -QUnit.test( "show() resolves correct default display for detached nodes", function( assert ){ +QUnit.test( "show() resolves correct default display for detached nodes", function( assert ) { assert.expect( 16 ); var div, span, tr; - div = jQuery("<div class='hidden'>"); - div.show().appendTo("#qunit-fixture"); - assert.equal( div.css("display"), "none", + div = jQuery( "<div class='hidden'>" ); + div.show().appendTo( "#qunit-fixture" ); + assert.equal( div.css( "display" ), "none", "A shown-while-detached div can be hidden by the CSS cascade" ); - div = jQuery("<div><div class='hidden'></div></div>").children("div"); - div.show().appendTo("#qunit-fixture"); - assert.equal( div.css("display"), "none", + div = jQuery( "<div><div class='hidden'></div></div>" ).children( "div" ); + div.show().appendTo( "#qunit-fixture" ); + assert.equal( div.css( "display" ), "none", "A shown-while-detached div inside a visible div can be hidden by the CSS cascade" ); - span = jQuery("<span class='hidden'/>"); - span.show().appendTo("#qunit-fixture"); - assert.equal( span.css("display"), "none", + span = jQuery( "<span class='hidden'/>" ); + span.show().appendTo( "#qunit-fixture" ); + assert.equal( span.css( "display" ), "none", "A shown-while-detached span can be hidden by the CSS cascade" ); - div = jQuery("div.hidden"); + div = jQuery( "div.hidden" ); div.detach().show(); assert.ok( !div[ 0 ].style.display, "show() does not update inline style of a cascade-hidden-before-detach div" ); - div.appendTo("#qunit-fixture"); - assert.equal( div.css("display"), "none", + div.appendTo( "#qunit-fixture" ); + assert.equal( div.css( "display" ), "none", "A shown-while-detached cascade-hidden div is hidden after attachment" ); div.remove(); - span = jQuery("<span class='hidden'/>"); - span.appendTo("#qunit-fixture").detach().show().appendTo("#qunit-fixture"); - assert.equal( span.css("display"), "none", + span = jQuery( "<span class='hidden'/>" ); + span.appendTo( "#qunit-fixture" ).detach().show().appendTo( "#qunit-fixture" ); + assert.equal( span.css( "display" ), "none", "A shown-while-detached cascade-hidden span is hidden after attachment" ); span.remove(); - div = jQuery( document.createElement("div") ); - div.show().appendTo("#qunit-fixture"); + div = jQuery( document.createElement( "div" ) ); + div.show().appendTo( "#qunit-fixture" ); assert.ok( !div[ 0 ].style.display, "A shown-while-detached div has no inline style" ); - assert.equal( div.css("display"), "block", + assert.equal( div.css( "display" ), "block", "A shown-while-detached div has default display after attachment" ); div.remove(); - div = jQuery("<div style='display: none'>"); + div = jQuery( "<div style='display: none'>" ); div.show(); assert.equal( div[ 0 ].style.display, "", "show() updates inline style of a detached inline-hidden div" ); - div.appendTo("#qunit-fixture"); - assert.equal( div.css("display"), "block", + div.appendTo( "#qunit-fixture" ); + assert.equal( div.css( "display" ), "block", "A shown-while-detached inline-hidden div has default display after attachment" ); - div = jQuery("<div><div style='display: none'></div></div>").children("div"); - div.show().appendTo("#qunit-fixture"); - assert.equal( div.css("display"), "block", + div = jQuery( "<div><div style='display: none'></div></div>" ).children( "div" ); + div.show().appendTo( "#qunit-fixture" ); + assert.equal( div.css( "display" ), "block", "A shown-while-detached inline-hidden div inside a visible div has default display " + "after attachment" ); - span = jQuery("<span style='display: none'/>"); + span = jQuery( "<span style='display: none'/>" ); span.show(); assert.equal( span[ 0 ].style.display, "", "show() updates inline style of a detached inline-hidden span" ); - span.appendTo("#qunit-fixture"); - assert.equal( span.css("display"), "inline", + span.appendTo( "#qunit-fixture" ); + assert.equal( span.css( "display" ), "inline", "A shown-while-detached inline-hidden span has default display after attachment" ); - div = jQuery("<div style='display: inline'/>"); - div.show().appendTo("#qunit-fixture"); - assert.equal( div.css("display"), "inline", + div = jQuery( "<div style='display: inline'/>" ); + div.show().appendTo( "#qunit-fixture" ); + assert.equal( div.css( "display" ), "inline", "show() does not update inline style of a detached inline-visible div" ); div.remove(); - tr = jQuery("<tr/>"); - jQuery("#table").append( tr ); + tr = jQuery( "<tr/>" ); + jQuery( "#table" ).append( tr ); tr.detach().hide().show(); assert.ok( !tr[ 0 ].style.display, "Not-hidden detached tr elements have no inline style" ); tr.remove(); - span = jQuery("<span/>").hide().show(); + span = jQuery( "<span/>" ).hide().show(); assert.ok( !span[ 0 ].style.display, "Not-hidden detached span elements have no inline style" ); span.remove(); -}); +} ); -QUnit.test("toggle()", function( assert ) { - assert.expect(9); +QUnit.test( "toggle()", function( assert ) { + assert.expect( 9 ); var div, oldHide, - x = jQuery("#foo"); + x = jQuery( "#foo" ); - assert.ok( x.is(":visible"), "is visible" ); + assert.ok( x.is( ":visible" ), "is visible" ); x.toggle(); - assert.ok( x.is(":hidden"), "is hidden" ); + assert.ok( x.is( ":hidden" ), "is hidden" ); x.toggle(); - assert.ok( x.is(":visible"), "is visible again" ); + assert.ok( x.is( ":visible" ), "is visible again" ); - x.toggle(true); - assert.ok( x.is(":visible"), "is visible" ); - x.toggle(false); - assert.ok( x.is(":hidden"), "is hidden" ); - x.toggle(true); - assert.ok( x.is(":visible"), "is visible again" ); + x.toggle( true ); + assert.ok( x.is( ":visible" ), "is visible" ); + x.toggle( false ); + assert.ok( x.is( ":hidden" ), "is hidden" ); + x.toggle( true ); + assert.ok( x.is( ":visible" ), "is visible again" ); - div = jQuery("<div style='display:none'><div></div></div>").appendTo("#qunit-fixture"); - x = div.find("div"); + div = jQuery( "<div style='display:none'><div></div></div>" ).appendTo( "#qunit-fixture" ); + x = div.find( "div" ); assert.strictEqual( x.toggle().css( "display" ), "none", "is hidden" ); assert.strictEqual( x.toggle().css( "display" ), "block", "is visible" ); @@ -667,103 +667,104 @@ QUnit.test("toggle()", function( assert ) { }; x.toggle( name === "show" ); jQuery.fn.hide = oldHide; -}); +} ); -QUnit.test("hide hidden elements (bug #7141)", function( assert ) { - assert.expect(3); +QUnit.test( "hide hidden elements (bug #7141)", function( assert ) { + assert.expect( 3 ); - var div = jQuery("<div style='display:none'></div>").appendTo("#qunit-fixture"); - assert.equal( div.css("display"), "none", "Element is hidden by default" ); + var div = jQuery( "<div style='display:none'></div>" ).appendTo( "#qunit-fixture" ); + assert.equal( div.css( "display" ), "none", "Element is hidden by default" ); div.hide(); - assert.ok( !jQuery._data(div, "olddisplay"), "olddisplay is undefined after hiding an already-hidden element" ); + assert.ok( !jQuery._data( div, "olddisplay" ), "olddisplay is undefined after hiding an already-hidden element" ); div.show(); - assert.equal( div.css("display"), "block", "Show a double-hidden element" ); + assert.equal( div.css( "display" ), "block", "Show a double-hidden element" ); div.remove(); -}); +} ); -QUnit.test("jQuery.css(elem, 'height') doesn't clear radio buttons (bug #1095)", function( assert ) { - assert.expect(4); +QUnit.test( "jQuery.css(elem, 'height') doesn't clear radio buttons (bug #1095)", function( assert ) { + assert.expect( 4 ); - var $checkedtest = jQuery("#checkedtest"); - jQuery.css($checkedtest[0], "height"); + var $checkedtest = jQuery( "#checkedtest" ); + jQuery.css( $checkedtest[ 0 ], "height" ); - assert.ok( jQuery("input[type='radio']", $checkedtest).first().attr("checked"), "Check first radio still checked." ); - assert.ok( !jQuery("input[type='radio']", $checkedtest).last().attr("checked"), "Check last radio still NOT checked." ); - assert.ok( jQuery("input[type='checkbox']", $checkedtest).first().attr("checked"), "Check first checkbox still checked." ); - assert.ok( !jQuery("input[type='checkbox']", $checkedtest).last().attr("checked"), "Check last checkbox still NOT checked." ); -}); + assert.ok( jQuery( "input[type='radio']", $checkedtest ).first().attr( "checked" ), "Check first radio still checked." ); + assert.ok( !jQuery( "input[type='radio']", $checkedtest ).last().attr( "checked" ), "Check last radio still NOT checked." ); + assert.ok( jQuery( "input[type='checkbox']", $checkedtest ).first().attr( "checked" ), "Check first checkbox still checked." ); + assert.ok( !jQuery( "input[type='checkbox']", $checkedtest ).last().attr( "checked" ), "Check last checkbox still NOT checked." ); +} ); -QUnit.test("internal ref to elem.runtimeStyle (bug #7608)", function( assert ) { - assert.expect(1); +QUnit.test( "internal ref to elem.runtimeStyle (bug #7608)", function( assert ) { + assert.expect( 1 ); var result = true; try { - jQuery("#foo").css( { "width": "0%" } ).css("width"); - } catch (e) { + jQuery( "#foo" ).css( { "width": "0%" } ).css( "width" ); + } catch ( e ) { result = false; } assert.ok( result, "elem.runtimeStyle does not throw exception" ); -}); +} ); -QUnit.test("marginRight computed style (bug #3333)", function( assert ) { - assert.expect(1); +QUnit.test( "marginRight computed style (bug #3333)", function( assert ) { + assert.expect( 1 ); - var $div = jQuery("#foo"); - $div.css({ + var $div = jQuery( "#foo" ); + $div.css( { "width": "1px", "marginRight": 0 - }); + } ); - assert.equal($div.css("marginRight"), "0px", "marginRight correctly calculated with a width and display block"); -}); + assert.equal( $div.css( "marginRight" ), "0px", "marginRight correctly calculated with a width and display block" ); +} ); -QUnit.test("box model properties incorrectly returning % instead of px, see #10639 and #12088", function( assert ) { +QUnit.test( "box model properties incorrectly returning % instead of px, see #10639 and #12088", function( assert ) { assert.expect( 2 ); - var container = jQuery("<div/>").width( 400 ).appendTo("#qunit-fixture"), - el = jQuery("<div/>").css({ "width": "50%", "marginRight": "50%" }).appendTo( container ), - el2 = jQuery("<div/>").css({ "width": "50%", "minWidth": "300px", "marginLeft": "25%" }).appendTo( container ); + var container = jQuery( "<div/>" ).width( 400 ).appendTo( "#qunit-fixture" ), + el = jQuery( "<div/>" ).css( { "width": "50%", "marginRight": "50%" } ).appendTo( container ), + el2 = jQuery( "<div/>" ).css( { "width": "50%", "minWidth": "300px", "marginLeft": "25%" } ).appendTo( container ); - assert.equal( el.css("marginRight"), "200px", "css('marginRight') returning % instead of px, see #10639" ); - assert.equal( el2.css("marginLeft"), "100px", "css('marginLeft') returning incorrect pixel value, see #12088" ); -}); + assert.equal( el.css( "marginRight" ), "200px", "css('marginRight') returning % instead of px, see #10639" ); + assert.equal( el2.css( "marginLeft" ), "100px", "css('marginLeft') returning incorrect pixel value, see #12088" ); +} ); -QUnit.test("jQuery.cssProps behavior, (bug #8402)", function( assert ) { +QUnit.test( "jQuery.cssProps behavior, (bug #8402)", function( assert ) { assert.expect( 2 ); - var div = jQuery( "<div>" ).appendTo(document.body).css({ + var div = jQuery( "<div>" ).appendTo( document.body ).css( { "position": "absolute", "top": 0, "left": 10 - }); + } ); jQuery.cssProps.top = "left"; - 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"); + 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; -}); +} ); -QUnit.test("widows & orphans #8936", function( assert ) { +QUnit.test( "widows & orphans #8936", function( assert ) { - var $p = jQuery("<p>").appendTo("#qunit-fixture"); + var $p = jQuery( "<p>" ).appendTo( "#qunit-fixture" ); assert.expect( 2 ); - $p.css({ + $p.css( { "widows": 3, "orphans": 3 - }); + } ); - assert.equal( $p.css( "widows" ) || jQuery.style( $p[0], "widows" ), 3, "widows correctly set to 3" ); - assert.equal( $p.css( "orphans" ) || jQuery.style( $p[0], "orphans" ), 3, "orphans correctly set to 3" ); + assert.equal( $p.css( "widows" ) || jQuery.style( $p[ 0 ], "widows" ), 3, "widows correctly set to 3" ); + assert.equal( $p.css( "orphans" ) || jQuery.style( $p[ 0 ], "orphans" ), 3, "orphans correctly set to 3" ); $p.remove(); -}); +} ); -QUnit.test("can't get css for disconnected in IE<9, see #10254 and #8388", function( assert ) { +QUnit.test( "can't get css for disconnected in IE<9, see #10254 and #8388", function( assert ) { assert.expect( 2 ); var span, div; @@ -772,9 +773,9 @@ QUnit.test("can't get css for disconnected in IE<9, see #10254 and #8388", funct div = jQuery( "<div/>" ).css( "top", 10 ); assert.equal( div.css( "top" ), "10px", "can't get top in IE<9, see #8388" ); -}); +} ); -QUnit.test("can't get background-position in IE<9, see #10796", function( assert ) { +QUnit.test( "can't get background-position in IE<9, see #10796", function( assert ) { var div = jQuery( "<div/>" ).appendTo( "#qunit-fixture" ), units = [ "0 0", @@ -791,29 +792,30 @@ QUnit.test("can't get background-position in IE<9, see #10796", function( assert assert.expect( l ); - for( ; i < l; i++ ) { + for ( ; i < l; i++ ) { div.css( "background-position", units [ i ] ); assert.ok( div.css( "background-position" ), "can't get background-position in IE<9, see #10796" ); } -}); +} ); if ( jQuery.fn.offset ) { - QUnit.test("percentage properties for left and top should be transformed to pixels, see #9505", function( assert ) { + QUnit.test( "percentage properties for left and top should be transformed to pixels, see #9505", function( assert ) { assert.expect( 2 ); - var parent = jQuery("<div style='position:relative;width:200px;height:200px;margin:0;padding:0;border-width:0'></div>").appendTo( "#qunit-fixture" ), - div = jQuery("<div style='position: absolute; width: 20px; height: 20px; top:50%; left:50%'></div>").appendTo( parent ); + var parent = jQuery( "<div style='position:relative;width:200px;height:200px;margin:0;padding:0;border-width:0'></div>" ).appendTo( "#qunit-fixture" ), + div = jQuery( "<div style='position: absolute; width: 20px; height: 20px; top:50%; left:50%'></div>" ).appendTo( parent ); - assert.equal( div.css("top"), "100px", "position properties not transformed to pixels, see #9505" ); - assert.equal( div.css("left"), "100px", "position properties not transformed to pixels, see #9505" ); - }); + assert.equal( div.css( "top" ), "100px", "position properties not transformed to pixels, see #9505" ); + assert.equal( div.css( "left" ), "100px", "position properties not transformed to pixels, see #9505" ); + } ); } -QUnit.test("Do not append px (#9548, #12990)", function( assert ) { +QUnit.test( "Do not append px (#9548, #12990)", function( assert ) { assert.expect( 2 ); - var $div = jQuery("<div>").appendTo("#qunit-fixture"); + 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'" ); @@ -822,25 +824,25 @@ QUnit.test("Do not append px (#9548, #12990)", function( assert ) { } $div.css( "column-count", 1 ); - if ( $div.css("column-count") ) { - assert.equal( $div.css("column-count"), 1, "Do not append px to 'column-count'" ); + if ( $div.css( "column-count" ) ) { + assert.equal( $div.css( "column-count" ), 1, "Do not append px to 'column-count'" ); } else { assert.ok( true, "No support for column-count CSS property" ); } -}); +} ); -QUnit.test("css('width') and css('height') should respect box-sizing, see #11004", function( assert ) { +QUnit.test( "css('width') and css('height') should respect box-sizing, see #11004", function( assert ) { assert.expect( 4 ); // Support: Android 2.3 (-webkit-box-sizing). - var el_dis = jQuery("<div style='width:300px;height:300px;margin:2px;padding:2px;-webkit-box-sizing:border-box;box-sizing:border-box;'>test</div>"), - el = el_dis.clone().appendTo("#qunit-fixture"); + var el_dis = jQuery( "<div style='width:300px;height:300px;margin:2px;padding:2px;-webkit-box-sizing:border-box;box-sizing:border-box;'>test</div>" ), + el = el_dis.clone().appendTo( "#qunit-fixture" ); - assert.equal( el.css("width"), el.css("width", el.css("width")).css("width"), "css('width') is not respecting box-sizing, see #11004"); - assert.equal( el_dis.css("width"), el_dis.css("width", el_dis.css("width")).css("width"), "css('width') is not respecting box-sizing for disconnected element, see #11004"); - assert.equal( el.css("height"), el.css("height", el.css("height")).css("height"), "css('height') is not respecting box-sizing, see #11004"); - assert.equal( el_dis.css("height"), el_dis.css("height", el_dis.css("height")).css("height"), "css('height') is not respecting box-sizing for disconnected element, see #11004"); -}); + assert.equal( el.css( "width" ), el.css( "width", el.css( "width" ) ).css( "width" ), "css('width') is not respecting box-sizing, see #11004" ); + assert.equal( el_dis.css( "width" ), el_dis.css( "width", el_dis.css( "width" ) ).css( "width" ), "css('width') is not respecting box-sizing for disconnected element, see #11004" ); + assert.equal( el.css( "height" ), el.css( "height", el.css( "height" ) ).css( "height" ), "css('height') is not respecting box-sizing, see #11004" ); + assert.equal( el_dis.css( "height" ), el_dis.css( "height", el_dis.css( "height" ) ).css( "height" ), "css('height') is not respecting box-sizing for disconnected element, see #11004" ); +} ); testIframeWithCallback( "css('width') should work correctly before document ready (#14084)", @@ -857,7 +859,7 @@ testIframeWithCallback( div = document.createElement( "div" ); div.style.width = "3.3px"; qunitFixture.appendChild( div ); - supportsFractionalGBCR = div.getBoundingClientRect().width.toFixed(1) === "3.3"; + supportsFractionalGBCR = div.getBoundingClientRect().width.toFixed( 1 ) === "3.3"; qunitFixture.removeChild( div ); QUnit.test( "css('width') and css('height') should return fractional values for nodes in the document", function( assert ) { @@ -896,23 +898,23 @@ testIframeWithCallback( } ); } )(); -QUnit.test("certain css values of 'normal' should be convertable to a number, see #8627", function( assert ) { +QUnit.test( "certain css values of 'normal' should be convertable to a number, see #8627", function( assert ) { expect ( 3 ); - var el = jQuery("<div style='letter-spacing:normal;font-weight:normal;'>test</div>").appendTo("#qunit-fixture"); + var el = jQuery( "<div style='letter-spacing:normal;font-weight:normal;'>test</div>" ).appendTo( "#qunit-fixture" ); - assert.ok( jQuery.isNumeric( parseFloat( el.css("letterSpacing") ) ), "css('letterSpacing') not convertable to number, see #8627" ); - assert.ok( jQuery.isNumeric( parseFloat( el.css("fontWeight") ) ), "css('fontWeight') not convertable to number, see #8627" ); + assert.ok( jQuery.isNumeric( parseFloat( el.css( "letterSpacing" ) ) ), "css('letterSpacing') not convertable to number, see #8627" ); + assert.ok( jQuery.isNumeric( parseFloat( el.css( "fontWeight" ) ) ), "css('fontWeight') not convertable to number, see #8627" ); assert.equal( typeof el.css( "fontWeight" ), "string", ".css() returns a string" ); -}); +} ); // only run this test in IE9 if ( document.documentMode === 9 ) { QUnit.test( ".css('filter') returns a string in IE9, see #12537", function( assert ) { assert.expect( 1 ); - assert.equal( jQuery("<div style='-ms-filter:\"progid:DXImageTransform.Microsoft.gradient(startColorstr=#FFFFFF, endColorstr=#ECECEC)\";'></div>").css("filter"), "progid:DXImageTransform.Microsoft.gradient(startColorstr=#FFFFFF, endColorstr=#ECECEC)", "IE9 returns the correct value from css('filter')." ); - }); + assert.equal( jQuery( "<div style='-ms-filter:\"progid:DXImageTransform.Microsoft.gradient(startColorstr=#FFFFFF, endColorstr=#ECECEC)\";'></div>" ).css( "filter" ), "progid:DXImageTransform.Microsoft.gradient(startColorstr=#FFFFFF, endColorstr=#ECECEC)", "IE9 returns the correct value from css('filter')." ); + } ); } QUnit.test( "cssHooks - expand", function( assert ) { @@ -920,7 +922,7 @@ QUnit.test( "cssHooks - expand", function( assert ) { var result, properties = { margin: [ "marginTop", "marginRight", "marginBottom", "marginLeft" ], - borderWidth: [ "borderTopWidth", "borderRightWidth", "borderBottomWidth", "borderLeftWidth"], + borderWidth: [ "borderTopWidth", "borderRightWidth", "borderBottomWidth", "borderLeftWidth" ], padding: [ "paddingTop", "paddingRight", "paddingBottom", "paddingLeft" ] }; @@ -929,70 +931,70 @@ QUnit.test( "cssHooks - expand", function( assert ) { expected = {}; jQuery.each( keys, function( _, key ) { expected[ key ] = 10; - }); + } ); result = hook.expand( 10 ); assert.deepEqual( result, expected, property + " expands properly with a number" ); jQuery.each( keys, function( _, key ) { expected[ key ] = "10px"; - }); + } ); result = hook.expand( "10px" ); assert.deepEqual( result, expected, property + " expands properly with '10px'" ); - expected[ keys[1] ] = expected[ keys[3] ] = "20px"; + expected[ keys[ 1 ] ] = expected[ keys[ 3 ] ] = "20px"; result = hook.expand( "10px 20px" ); assert.deepEqual( result, expected, property + " expands properly with '10px 20px'" ); - expected[ keys[2] ] = "30px"; + expected[ keys[ 2 ] ] = "30px"; result = hook.expand( "10px 20px 30px" ); assert.deepEqual( result, expected, property + " expands properly with '10px 20px 30px'" ); - expected[ keys[3] ] = "40px"; + expected[ keys[ 3 ] ] = "40px"; result = hook.expand( "10px 20px 30px 40px" ); assert.deepEqual( result, expected, property + " expands properly with '10px 20px 30px 40px'" ); - }); + } ); -}); +} ); QUnit.test( "css opacity consistency across browsers (#12685)", function( assert ) { assert.expect( 4 ); var el, - fixture = jQuery("#qunit-fixture"); + fixture = jQuery( "#qunit-fixture" ); // Append style element - jQuery("<style>.opacityWithSpaces_t12685 { opacity: 0.1; filter: alpha(opacity = 10); } .opacityNoSpaces_t12685 { opacity: 0.2; filter: alpha(opacity=20); }</style>").appendTo( fixture ); + jQuery( "<style>.opacityWithSpaces_t12685 { opacity: 0.1; filter: alpha(opacity = 10); } .opacityNoSpaces_t12685 { opacity: 0.2; filter: alpha(opacity=20); }</style>" ).appendTo( fixture ); - el = jQuery("<div class='opacityWithSpaces_t12685'></div>").appendTo(fixture); + el = jQuery( "<div class='opacityWithSpaces_t12685'></div>" ).appendTo( fixture ); - assert.equal( Math.round( el.css("opacity") * 100 ), 10, "opacity from style sheet (filter:alpha with spaces)" ); - el.removeClass("opacityWithSpaces_t12685").addClass("opacityNoSpaces_t12685"); - assert.equal( Math.round( el.css("opacity") * 100 ), 20, "opacity from style sheet (filter:alpha without spaces)" ); + assert.equal( Math.round( el.css( "opacity" ) * 100 ), 10, "opacity from style sheet (filter:alpha with spaces)" ); + el.removeClass( "opacityWithSpaces_t12685" ).addClass( "opacityNoSpaces_t12685" ); + assert.equal( Math.round( el.css( "opacity" ) * 100 ), 20, "opacity from style sheet (filter:alpha without spaces)" ); el.css( "opacity", 0.3 ); - assert.equal( Math.round( el.css("opacity") * 100 ), 30, "override opacity" ); + assert.equal( Math.round( el.css( "opacity" ) * 100 ), 30, "override opacity" ); el.css( "opacity", "" ); - assert.equal( Math.round( el.css("opacity") * 100 ), 20, "remove opacity override" ); -}); + assert.equal( Math.round( el.css( "opacity" ) * 100 ), 20, "remove opacity override" ); +} ); QUnit.test( ":visible/:hidden selectors", function( assert ) { assert.expect( 17 ); var $div, $table, $a; - assert.ok( jQuery("#nothiddendiv").is(":visible"), "Modifying CSS display: Assert element is visible" ); - jQuery("#nothiddendiv").css({ display: "none" }); - assert.ok( !jQuery("#nothiddendiv").is(":visible"), "Modified CSS display: Assert element is hidden" ); - jQuery("#nothiddendiv").css({ "display": "block" }); - assert.ok( jQuery("#nothiddendiv").is(":visible"), "Modified CSS display: Assert element is visible"); - assert.ok( !jQuery(window).is(":visible"), "Calling is(':visible') on window does not throw an exception (#10267)."); - assert.ok( !jQuery(document).is(":visible"), "Calling is(':visible') on document does not throw an exception (#10267)."); + assert.ok( jQuery( "#nothiddendiv" ).is( ":visible" ), "Modifying CSS display: Assert element is visible" ); + jQuery( "#nothiddendiv" ).css( { display: "none" } ); + assert.ok( !jQuery( "#nothiddendiv" ).is( ":visible" ), "Modified CSS display: Assert element is hidden" ); + jQuery( "#nothiddendiv" ).css( { "display": "block" } ); + assert.ok( jQuery( "#nothiddendiv" ).is( ":visible" ), "Modified CSS display: Assert element is visible" ); + assert.ok( !jQuery( window ).is( ":visible" ), "Calling is(':visible') on window does not throw an exception (#10267)." ); + assert.ok( !jQuery( document ).is( ":visible" ), "Calling is(':visible') on document does not throw an exception (#10267)." ); - assert.ok( jQuery("#nothiddendiv").is(":visible"), "Modifying CSS display: Assert element is visible"); - jQuery("#nothiddendiv").css("display", "none"); - assert.ok( !jQuery("#nothiddendiv").is(":visible"), "Modified CSS display: Assert element is hidden"); - jQuery("#nothiddendiv").css("display", "block"); - assert.ok( jQuery("#nothiddendiv").is(":visible"), "Modified CSS display: Assert element is visible"); + assert.ok( jQuery( "#nothiddendiv" ).is( ":visible" ), "Modifying CSS display: Assert element is visible" ); + jQuery( "#nothiddendiv" ).css( "display", "none" ); + assert.ok( !jQuery( "#nothiddendiv" ).is( ":visible" ), "Modified CSS display: Assert element is hidden" ); + jQuery( "#nothiddendiv" ).css( "display", "block" ); + assert.ok( jQuery( "#nothiddendiv" ).is( ":visible" ), "Modified CSS display: Assert element is visible" ); assert.ok( jQuery( "#siblingspan" ).is( ":visible" ), "Span with no content is visible" ); $div = jQuery( "<div><span></span></div>" ).appendTo( "#qunit-fixture" ); @@ -1005,19 +1007,19 @@ QUnit.test( ":visible/:hidden selectors", function( assert ) { // $br = jQuery( "<br/>" ).appendTo( "#qunit-fixture" ); // ok( $br.is( ":visible" ), "br element is visible" ); - $table = jQuery("#table"); - $table.html("<tr><td style='display:none'>cell</td><td>cell</td></tr>"); - assert.equal(jQuery("#table td:visible").length, 1, "hidden cell is not perceived as visible (#4512). Works on table elements"); - $table.css("display", "none").html("<tr><td>cell</td><td>cell</td></tr>"); - assert.equal(jQuery("#table td:visible").length, 0, "hidden cell children not perceived as visible (#4512)"); + $table = jQuery( "#table" ); + $table.html( "<tr><td style='display:none'>cell</td><td>cell</td></tr>" ); + assert.equal( jQuery( "#table td:visible" ).length, 1, "hidden cell is not perceived as visible (#4512). Works on table elements" ); + $table.css( "display", "none" ).html( "<tr><td>cell</td><td>cell</td></tr>" ); + assert.equal( jQuery( "#table td:visible" ).length, 0, "hidden cell children not perceived as visible (#4512)" ); - t( "Is Visible", "#qunit-fixture div:visible:lt(2)", ["foo", "nothiddendiv"] ); + t( "Is Visible", "#qunit-fixture div:visible:lt(2)", [ "foo", "nothiddendiv" ] ); t( "Is Not Hidden", "#qunit-fixture:hidden", [] ); - t( "Is Hidden", "#form input:hidden", ["hidden1","hidden2"] ); + t( "Is Hidden", "#form input:hidden", [ "hidden1","hidden2" ] ); $a = jQuery( "<a href='#'><h1>Header</h1></a>" ).appendTo( "#qunit-fixture" ); assert.ok( $a.is( ":visible" ), "Anchor tag with flow content is visible (gh-2227)" ); -}); +} ); QUnit.test( "Keep the last style if the new one isn't recognized by the browser (#14836)", function( assert ) { assert.expect( 2 ); @@ -1027,56 +1029,59 @@ QUnit.test( "Keep the last style if the new one isn't recognized by the browser assert.equal( el.css( "position" ), "absolute", "The old style is kept when setting an unrecognized value" ); el = jQuery( "<div></div>" ).css( "position", "absolute" ).css( "position", " " ); assert.equal( el.css( "position" ), "absolute", "The old style is kept when setting to a space" ); -}); +} ); 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", "The style can be reset by setting to an empty string" ); -}); +} ); QUnit.asyncTest( "Clearing a Cloned Element's Style Shouldn't Clear the Original Element's Style (#8908)", 24, function( assert ) { var baseUrl = document.location.href.replace( /([^\/]*)$/, "" ), - styles = [{ + styles = [ { name: "backgroundAttachment", - value: ["fixed"], + value: [ "fixed" ], expected: [ "scroll" ] },{ name: "backgroundColor", value: [ "rgb(255, 0, 0)", "rgb(255,0,0)", "#ff0000" ], - expected: ["transparent"] + expected: [ "transparent" ] }, { + // Firefox returns auto's value name: "backgroundImage", value: [ "url('test.png')", "url(" + baseUrl + "test.png)", "url(\"" + baseUrl + "test.png\")" ], expected: [ "none", "url(\"http://static.jquery.com/files/rocker/images/logo_jquery_215x53.gif\")" ] }, { name: "backgroundPosition", - value: ["5% 5%"], + value: [ "5% 5%" ], expected: [ "0% 0%", "-1000px 0px", "-1000px 0%" ] }, { + // Firefox returns no-repeat name: "backgroundRepeat", - value: ["repeat-y"], + value: [ "repeat-y" ], expected: [ "repeat", "no-repeat" ] }, { name: "backgroundClip", - value: ["padding-box"], - expected: ["border-box"] + value: [ "padding-box" ], + expected: [ "border-box" ] }, { name: "backgroundOrigin", - value: ["content-box"], - expected: ["padding-box"] + value: [ "content-box" ], + expected: [ "padding-box" ] }, { name: "backgroundSize", - value: ["80px 60px"], + value: [ "80px 60px" ], expected: [ "auto auto" ] - }]; + } ]; - jQuery.each(styles, function( index, style ) { + jQuery.each( styles, function( index, style ) { var $clone, $clonedChildren, $source = jQuery( "#firstp" ), source = $source[ 0 ], @@ -1100,7 +1105,7 @@ QUnit.asyncTest( "Clearing a Cloned Element's Style Shouldn't Clear the Original $clone.css( style.name, "" ); $clonedChildren.css( style.name, "" ); - window.setTimeout(function() { + window.setTimeout( function() { assert.notEqual( $clone.css( style.name ), style.value[ 0 ], "Cloned css was changed" ); assert.ok( jQuery.inArray( $source.css( style.name ) !== -1, style.value ), @@ -1113,10 +1118,10 @@ QUnit.asyncTest( "Clearing a Cloned Element's Style Shouldn't Clear the Original "; result: " + $children.css( style.name ) + "; expected: " + style.value.join( "," ) ); }, 100 ); - }); + } ); window.setTimeout( start, 1000 ); -}); +} ); QUnit.test( "show() after hide() should always set display to initial value (#14750)", function( assert ) { assert.expect( 1 ); @@ -1128,13 +1133,13 @@ QUnit.test( "show() after hide() should always set display to initial value (#14 div.css( "display", "inline" ).hide().show().css( "display", "list-item" ).hide().show(); assert.equal( div.css( "display" ), "list-item", "should get last set display value" ); -}); +} ); // Support: IE < 11 // We have to jump through the hoops here in order to test work with "order" CSS property, // that some browsers do not support. This test is not, strictly speaking, correct, // but it's the best that we can do. -(function() { +( function() { var style = document.createElement( "div" ).style, exist = "order" in style || "WebkitOrder" in style; @@ -1146,9 +1151,9 @@ QUnit.test( "show() after hide() should always set display to initial value (#14 $elem.css( "order", 2 ); assert.equal( $elem.css( "order" ), "2", "2 on order" ); - }); + } ); } -})(); +} )(); QUnit.test( "Do not throw on frame elements from css method (#15098)", function( assert ) { assert.expect( 1 ); @@ -1173,7 +1178,7 @@ QUnit.test( "Do not throw on frame elements from css method (#15098)", function( } catch ( _ ) { assert.ok( false, "It did throw" ); } -}); +} ); ( function() { var vendorPrefixes = [ "Webkit", "Moz", "ms" ]; @@ -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. diff --git a/test/unit/data.js b/test/unit/data.js index 21f760473..3a90c0054 100644 --- a/test/unit/data.js +++ b/test/unit/data.js @@ -1,13 +1,13 @@ -QUnit.module("data", { teardown: moduleTeardown }); +QUnit.module( "data", { teardown: moduleTeardown } ); -QUnit.test("expando", function( assert ){ - assert.expect(1); +QUnit.test( "expando", function( assert ) { + assert.expect( 1 ); - assert.equal(jQuery.expando !== undefined, true, "jQuery is exposing the expando"); -}); + assert.equal( jQuery.expando !== undefined, true, "jQuery is exposing the expando" ); +} ); QUnit.test( "jQuery.data & removeData, expected returns", function( assert ) { - assert.expect(4); + assert.expect( 4 ); var elem = document.body; assert.equal( @@ -19,7 +19,7 @@ QUnit.test( "jQuery.data & removeData, expected returns", function( assert ) { "jQuery.data( elem, key ) returns value" ); assert.deepEqual( - jQuery.data( elem, { goodnight: "moon" }), { goodnight: "moon" }, + jQuery.data( elem, { goodnight: "moon" } ), { goodnight: "moon" }, "jQuery.data( elem, obj ) returns obj" ); assert.equal( @@ -27,10 +27,10 @@ QUnit.test( "jQuery.data & removeData, expected returns", function( assert ) { "jQuery.removeData( elem, key, value ) returns undefined" ); -}); +} ); QUnit.test( "jQuery._data & _removeData, expected returns", function( assert ) { - assert.expect(4); + assert.expect( 4 ); var elem = document.body; assert.equal( @@ -42,17 +42,17 @@ QUnit.test( "jQuery._data & _removeData, expected returns", function( assert ) { "jQuery._data( elem, key ) returns value" ); assert.deepEqual( - jQuery._data( elem, { goodnight: "moon" }), { goodnight: "moon" }, + jQuery._data( elem, { goodnight: "moon" } ), { goodnight: "moon" }, "jQuery._data( elem, obj ) returns obj" ); assert.equal( jQuery._removeData( elem, "hello" ), undefined, "jQuery._removeData( elem, key, value ) returns undefined" ); -}); +} ); QUnit.test( "jQuery.hasData no side effects", function( assert ) { - assert.expect(1); + assert.expect( 1 ); var obj = {}; jQuery.hasData( obj ); @@ -60,44 +60,44 @@ QUnit.test( "jQuery.hasData no side effects", function( assert ) { assert.equal( Object.getOwnPropertyNames( obj ).length, 0, "No data expandos where added when calling jQuery.hasData(o)" ); -}); +} ); function dataTests( elem, assert ) { var dataObj, internalDataObj; - assert.equal( jQuery.data(elem, "foo"), undefined, "No data exists initially" ); - assert.strictEqual( jQuery.hasData(elem), false, "jQuery.hasData agrees no data exists initially" ); + assert.equal( jQuery.data( elem, "foo" ), undefined, "No data exists initially" ); + assert.strictEqual( jQuery.hasData( elem ), false, "jQuery.hasData agrees no data exists initially" ); - dataObj = jQuery.data(elem); + dataObj = jQuery.data( elem ); assert.equal( typeof dataObj, "object", "Calling data with no args gives us a data object reference" ); - assert.strictEqual( jQuery.data(elem), dataObj, "Calling jQuery.data returns the same data object when called multiple times" ); + assert.strictEqual( jQuery.data( elem ), dataObj, "Calling jQuery.data returns the same data object when called multiple times" ); - assert.strictEqual( jQuery.hasData(elem), false, "jQuery.hasData agrees no data exists even when an empty data obj exists" ); + assert.strictEqual( jQuery.hasData( elem ), false, "jQuery.hasData agrees no data exists even when an empty data obj exists" ); - dataObj["foo"] = "bar"; - assert.equal( jQuery.data(elem, "foo"), "bar", "Data is readable by jQuery.data when set directly on a returned data object" ); + dataObj[ "foo" ] = "bar"; + assert.equal( jQuery.data( elem, "foo" ), "bar", "Data is readable by jQuery.data when set directly on a returned data object" ); - assert.strictEqual( jQuery.hasData(elem), true, "jQuery.hasData agrees data exists when data exists" ); + assert.strictEqual( jQuery.hasData( elem ), true, "jQuery.hasData agrees data exists when data exists" ); - jQuery.data(elem, "foo", "baz"); - assert.equal( jQuery.data(elem, "foo"), "baz", "Data can be changed by jQuery.data" ); - assert.equal( dataObj["foo"], "baz", "Changes made through jQuery.data propagate to referenced data object" ); + jQuery.data( elem, "foo", "baz" ); + assert.equal( jQuery.data( elem, "foo" ), "baz", "Data can be changed by jQuery.data" ); + assert.equal( dataObj[ "foo" ], "baz", "Changes made through jQuery.data propagate to referenced data object" ); - jQuery.data(elem, "foo", undefined); - assert.equal( jQuery.data(elem, "foo"), "baz", "Data is not unset by passing undefined to jQuery.data" ); + jQuery.data( elem, "foo", undefined ); + assert.equal( jQuery.data( elem, "foo" ), "baz", "Data is not unset by passing undefined to jQuery.data" ); - jQuery.data(elem, "foo", null); - assert.strictEqual( jQuery.data(elem, "foo"), null, "Setting null using jQuery.data works OK" ); + jQuery.data( elem, "foo", null ); + assert.strictEqual( jQuery.data( elem, "foo" ), null, "Setting null using jQuery.data works OK" ); - jQuery.data(elem, "foo", "foo1"); + jQuery.data( elem, "foo", "foo1" ); - jQuery.data(elem, { "bar" : "baz", "boom" : "bloz" }); - assert.strictEqual( jQuery.data(elem, "foo"), "foo1", "Passing an object extends the data object instead of replacing it" ); - assert.equal( jQuery.data(elem, "boom"), "bloz", "Extending the data object works" ); + jQuery.data( elem, { "bar": "baz", "boom": "bloz" } ); + assert.strictEqual( jQuery.data( elem, "foo" ), "foo1", "Passing an object extends the data object instead of replacing it" ); + assert.equal( jQuery.data( elem, "boom" ), "bloz", "Extending the data object works" ); - jQuery._data(elem, "foo", "foo2", true); - assert.equal( jQuery._data(elem, "foo"), "foo2", "Setting internal data works" ); - assert.equal( jQuery.data(elem, "foo"), "foo1", "Setting internal data does not override user data" ); + jQuery._data( elem, "foo", "foo2", true ); + assert.equal( jQuery._data( elem, "foo" ), "foo2", "Setting internal data works" ); + assert.equal( jQuery.data( elem, "foo" ), "foo1", "Setting internal data does not override user data" ); internalDataObj = jQuery._data( elem ); assert.ok( internalDataObj, "Internal data object exists" ); @@ -105,31 +105,31 @@ function dataTests( elem, assert ) { assert.strictEqual( elem.boom, undefined, "Data is never stored directly on the object" ); - jQuery.removeData(elem, "foo"); - assert.strictEqual( jQuery.data(elem, "foo"), undefined, "jQuery.removeData removes single properties" ); + jQuery.removeData( elem, "foo" ); + assert.strictEqual( jQuery.data( elem, "foo" ), undefined, "jQuery.removeData removes single properties" ); - jQuery.removeData(elem); - assert.strictEqual( jQuery._data(elem), internalDataObj, "jQuery.removeData does not remove internal data if it exists" ); + jQuery.removeData( elem ); + assert.strictEqual( jQuery._data( elem ), internalDataObj, "jQuery.removeData does not remove internal data if it exists" ); - jQuery.data(elem, "foo", "foo1"); - jQuery._data(elem, "foo", "foo2"); + jQuery.data( elem, "foo", "foo1" ); + jQuery._data( elem, "foo", "foo2" ); - assert.equal( jQuery.data(elem, "foo"), "foo1", "(sanity check) Ensure data is set in user data object" ); - assert.equal( jQuery._data(elem, "foo"), "foo2", "(sanity check) Ensure data is set in internal data object" ); + assert.equal( jQuery.data( elem, "foo" ), "foo1", "(sanity check) Ensure data is set in user data object" ); + assert.equal( jQuery._data( elem, "foo" ), "foo2", "(sanity check) Ensure data is set in internal data object" ); - assert.strictEqual( jQuery._data(elem, jQuery.expando), undefined, "Removing the last item in internal data destroys the internal data object" ); + assert.strictEqual( jQuery._data( elem, jQuery.expando ), undefined, "Removing the last item in internal data destroys the internal data object" ); - jQuery._data(elem, "foo", "foo2"); - assert.equal( jQuery._data(elem, "foo"), "foo2", "(sanity check) Ensure data is set in internal data object" ); + jQuery._data( elem, "foo", "foo2" ); + assert.equal( jQuery._data( elem, "foo" ), "foo2", "(sanity check) Ensure data is set in internal data object" ); - jQuery.removeData(elem, "foo"); - assert.equal( jQuery._data(elem, "foo"), "foo2", "(sanity check) jQuery.removeData for user data does not remove internal data" ); + jQuery.removeData( elem, "foo" ); + assert.equal( jQuery._data( elem, "foo" ), "foo2", "(sanity check) jQuery.removeData for user data does not remove internal data" ); } -QUnit.test("jQuery.data(div)", function( assert ) { +QUnit.test( "jQuery.data(div)", function( assert ) { assert.expect( 25 ); - var div = document.createElement("div"); + var div = document.createElement( "div" ); dataTests( div, assert ); @@ -137,15 +137,15 @@ QUnit.test("jQuery.data(div)", function( assert ) { // assert that nothing else was put in there, and that that // one stayed there. QUnit.expectJqData( this, div, "foo" ); -}); +} ); -QUnit.test("jQuery.data({})", function( assert ) { +QUnit.test( "jQuery.data({})", function( assert ) { assert.expect( 25 ); dataTests( {}, assert ); -}); +} ); -QUnit.test("jQuery.data(window)", function( assert ) { +QUnit.test( "jQuery.data(window)", function( assert ) { assert.expect( 25 ); // remove bound handlers from window object to stop potential false positives caused by fix for #5280 in @@ -153,66 +153,66 @@ QUnit.test("jQuery.data(window)", function( assert ) { jQuery( window ).off( "unload" ); dataTests( window, assert ); -}); +} ); -QUnit.test("jQuery.data(document)", function( assert ) { +QUnit.test( "jQuery.data(document)", function( assert ) { assert.expect( 25 ); dataTests( document, assert ); QUnit.expectJqData( this, document, "foo" ); -}); +} ); -QUnit.test("jQuery.data(<embed>)", function( assert ) { +QUnit.test( "jQuery.data(<embed>)", function( assert ) { assert.expect( 25 ); - dataTests( document.createElement("embed"), assert ); -}); + dataTests( document.createElement( "embed" ), assert ); +} ); -QUnit.test("jQuery.data(object/flash)", function( assert ) { +QUnit.test( "jQuery.data(object/flash)", function( assert ) { assert.expect( 25 ); - var flash = document.createElement("object"); + var flash = document.createElement( "object" ); flash.setAttribute( "classid", "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ); dataTests( flash, assert ); -}); +} ); // attempting to access the data of an undefined jQuery element should be undefined -QUnit.test("jQuery().data() === undefined (#14101)", function( assert ) { +QUnit.test( "jQuery().data() === undefined (#14101)", function( assert ) { assert.expect( 2 ); - assert.strictEqual(jQuery().data(), undefined); - assert.strictEqual(jQuery().data("key"), undefined); -}); + assert.strictEqual( jQuery().data(), undefined ); + assert.strictEqual( jQuery().data( "key" ), undefined ); +} ); -QUnit.test(".data()", function( assert ) { - assert.expect(5); +QUnit.test( ".data()", function( assert ) { + assert.expect( 5 ); var div, dataObj, nodiv, obj; - div = jQuery("#foo"); - assert.strictEqual( div.data("foo"), undefined, "Make sure that missing result is undefined" ); - div.data("test", "success"); + div = jQuery( "#foo" ); + assert.strictEqual( div.data( "foo" ), undefined, "Make sure that missing result is undefined" ); + div.data( "test", "success" ); dataObj = div.data(); - assert.deepEqual( dataObj, {test: "success"}, "data() returns entire data object with expected properties" ); - assert.strictEqual( div.data("foo"), undefined, "Make sure that missing result is still undefined" ); + assert.deepEqual( dataObj, { test: "success" }, "data() returns entire data object with expected properties" ); + assert.strictEqual( div.data( "foo" ), undefined, "Make sure that missing result is still undefined" ); - nodiv = jQuery("#unfound"); + nodiv = jQuery( "#unfound" ); assert.equal( nodiv.data(), null, "data() on empty set returns null" ); obj = { foo: "bar" }; - jQuery(obj).data("foo", "baz"); + jQuery( obj ).data( "foo", "baz" ); - dataObj = jQuery.extend(true, {}, jQuery(obj).data()); + dataObj = jQuery.extend( true, {}, jQuery( obj ).data() ); assert.deepEqual( dataObj, { "foo": "baz" }, "Retrieve data object from a wrapped JS object (#7524)" ); -}); +} ); function testDataTypes( $obj, assert ) { - jQuery.each({ + jQuery.each( { "null": null, "true": true, "false": false, @@ -220,90 +220,90 @@ function testDataTypes( $obj, assert ) { "one": 1, "empty string": "", "empty array": [], - "array": [1], + "array": [ 1 ], "empty object": {}, "object": { foo: "bar" }, "date": new Date(), "regex": /test/, "function": function() {} }, function( type, value ) { - assert.strictEqual( $obj.data( "test", value ).data("test"), value, "Data set to " + type ); - }); + assert.strictEqual( $obj.data( "test", value ).data( "test" ), value, "Data set to " + type ); + } ); } -QUnit.test("jQuery(Element).data(String, Object).data(String)", function( assert ) { +QUnit.test( "jQuery(Element).data(String, Object).data(String)", function( assert ) { assert.expect( 18 ); - var parent = jQuery("<div><div></div></div>"), + var parent = jQuery( "<div><div></div></div>" ), div = parent.children(); - assert.strictEqual( div.data("test"), undefined, "No data exists initially" ); - assert.strictEqual( div.data("test", "success").data("test"), "success", "Data added" ); - assert.strictEqual( div.data("test", "overwritten").data("test"), "overwritten", "Data overwritten" ); - assert.strictEqual( div.data("test", undefined).data("test"), "overwritten", ".data(key,undefined) does nothing but is chainable (#5571)"); - assert.strictEqual( div.data("notexist"), undefined, "No data exists for unset key" ); + assert.strictEqual( div.data( "test" ), undefined, "No data exists initially" ); + assert.strictEqual( div.data( "test", "success" ).data( "test" ), "success", "Data added" ); + assert.strictEqual( div.data( "test", "overwritten" ).data( "test" ), "overwritten", "Data overwritten" ); + assert.strictEqual( div.data( "test", undefined ).data( "test" ), "overwritten", ".data(key,undefined) does nothing but is chainable (#5571)" ); + assert.strictEqual( div.data( "notexist" ), undefined, "No data exists for unset key" ); testDataTypes( div, assert ); parent.remove(); -}); +} ); -QUnit.test("jQuery(plain Object).data(String, Object).data(String)", function( assert ) { +QUnit.test( "jQuery(plain Object).data(String, Object).data(String)", function( assert ) { assert.expect( 16 ); // #3748 - var $obj = jQuery({ exists: true }); - assert.strictEqual( $obj.data("nothing"), undefined, "Non-existent data returns undefined"); - assert.strictEqual( $obj.data("exists"), undefined, "Object properties are not returned as data" ); + var $obj = jQuery( { exists: true } ); + assert.strictEqual( $obj.data( "nothing" ), undefined, "Non-existent data returns undefined" ); + assert.strictEqual( $obj.data( "exists" ), undefined, "Object properties are not returned as data" ); testDataTypes( $obj, assert ); // Clean up $obj.removeData(); - assert.deepEqual( $obj[0], { exists: true }, "removeData does not clear the object" ); -}); + assert.deepEqual( $obj[ 0 ], { exists: true }, "removeData does not clear the object" ); +} ); -QUnit.test(".data(object) does not retain references. #13815", function( assert ) { +QUnit.test( ".data(object) does not retain references. #13815", function( assert ) { assert.expect( 2 ); - var $divs = jQuery("<div></div><div></div>").appendTo("#qunit-fixture"); + var $divs = jQuery( "<div></div><div></div>" ).appendTo( "#qunit-fixture" ); - $divs.data({ "type": "foo" }); + $divs.data( { "type": "foo" } ); $divs.eq( 0 ).data( "type", "bar" ); - assert.equal( $divs.eq( 0 ).data("type"), "bar", "Correct updated value" ); - assert.equal( $divs.eq( 1 ).data("type"), "foo", "Original value retained" ); -}); + assert.equal( $divs.eq( 0 ).data( "type" ), "bar", "Correct updated value" ); + assert.equal( $divs.eq( 1 ).data( "type" ), "foo", "Original value retained" ); +} ); -QUnit.test("data-* attributes", function( assert ) { +QUnit.test( "data-* attributes", function( assert ) { assert.expect( 46 ); var prop, i, l, metadata, elem, obj, obj2, check, num, num2, parseJSON = jQuery.parseJSON, - div = jQuery("<div>"), - child = jQuery("<div data-myobj='old data' data-ignored=\"DOM\" data-other='test' data-foo-42='boosh'></div>"), - dummy = jQuery("<div data-myobj='old data' data-ignored=\"DOM\" data-other='test' data-foo-42='boosh'></div>"); + div = jQuery( "<div>" ), + child = jQuery( "<div data-myobj='old data' data-ignored=\"DOM\" data-other='test' data-foo-42='boosh'></div>" ), + dummy = jQuery( "<div data-myobj='old data' data-ignored=\"DOM\" data-other='test' data-foo-42='boosh'></div>" ); - assert.equal( div.data("attr"), undefined, "Check for non-existing data-attr attribute" ); + assert.equal( div.data( "attr" ), undefined, "Check for non-existing data-attr attribute" ); - div.attr("data-attr", "exists"); - assert.equal( div.data("attr"), "exists", "Check for existing data-attr attribute" ); + div.attr( "data-attr", "exists" ); + assert.equal( div.data( "attr" ), "exists", "Check for existing data-attr attribute" ); - div.attr("data-attr", "exists2"); - assert.equal( div.data("attr"), "exists", "Check that updates to data- don't update .data()" ); + div.attr( "data-attr", "exists2" ); + assert.equal( div.data( "attr" ), "exists", "Check that updates to data- don't update .data()" ); - div.data("attr", "internal").attr("data-attr", "external"); - assert.equal( div.data("attr"), "internal", "Check for .data('attr') precedence (internal > external data-* attribute)" ); + div.data( "attr", "internal" ).attr( "data-attr", "external" ); + assert.equal( div.data( "attr" ), "internal", "Check for .data('attr') precedence (internal > external data-* attribute)" ); div.remove(); - child.appendTo("#qunit-fixture"); - assert.equal( child.data("myobj"), "old data", "Value accessed from data-* attribute"); - assert.equal( child.data("foo-42"), "boosh", "camelCasing does not affect numbers (#1751)" ); + child.appendTo( "#qunit-fixture" ); + assert.equal( child.data( "myobj" ), "old data", "Value accessed from data-* attribute" ); + assert.equal( child.data( "foo-42" ), "boosh", "camelCasing does not affect numbers (#1751)" ); - child.data("myobj", "replaced"); - assert.equal( child.data("myobj"), "replaced", "Original data overwritten"); + child.data( "myobj", "replaced" ); + assert.equal( child.data( "myobj" ), "replaced", "Original data overwritten" ); - child.data("ignored", "cache"); - assert.equal( child.data("ignored"), "cache", "Cached data used before DOM data-* fallback"); + child.data( "ignored", "cache" ); + assert.equal( child.data( "ignored" ), "cache", "Cached data used before DOM data-* fallback" ); obj = child.data(); obj2 = dummy.data(); @@ -314,8 +314,8 @@ QUnit.test("data-* attributes", function( assert ) { dummy.remove(); for ( i = 0, l = check.length; i < l; i++ ) { - assert.ok( obj[ check[i] ], "Make sure data- property exists when calling data-." ); - assert.ok( obj2[ check[i] ], "Make sure data- property exists when calling data-." ); + assert.ok( obj[ check[ i ] ], "Make sure data- property exists when calling data-." ); + assert.ok( obj2[ check[ i ] ], "Make sure data- property exists when calling data-." ); } for ( prop in obj ) { @@ -330,9 +330,9 @@ QUnit.test("data-* attributes", function( assert ) { assert.equal( num2, check.length, "Make sure that the right number of properties came through." ); - child.attr("data-other", "newvalue"); + child.attr( "data-other", "newvalue" ); - assert.equal( child.data("other"), "test", "Make sure value was pulled in properly from a .data()." ); + assert.equal( child.data( "other" ), "test", "Make sure value was pulled in properly from a .data()." ); // attribute parsing i = 0; @@ -342,221 +342,221 @@ QUnit.test("data-* attributes", function( assert ) { }; child - .attr("data-true", "true") - .attr("data-false", "false") - .attr("data-five", "5") - .attr("data-point", "5.5") - .attr("data-pointe", "5.5E3") - .attr("data-grande", "5.574E9") - .attr("data-hexadecimal", "0x42") - .attr("data-pointbad", "5..5") - .attr("data-pointbad2", "-.") - .attr("data-bigassnum", "123456789123456789123456789") - .attr("data-badjson", "{123}") - .attr("data-badjson2", "[abc]") - .attr("data-notjson", " {}") - .attr("data-notjson2", "[] ") - .attr("data-empty", "") - .attr("data-space", " ") - .attr("data-null", "null") - .attr("data-string", "test"); - - assert.strictEqual( child.data("true"), true, "Primitive true read from attribute"); - assert.strictEqual( child.data("false"), false, "Primitive false read from attribute"); - assert.strictEqual( child.data("five"), 5, "Integer read from attribute"); - assert.strictEqual( child.data("point"), 5.5, "Floating-point number read from attribute"); - assert.strictEqual( child.data("pointe"), "5.5E3", - "Exponential-notation number read from attribute as string"); - assert.strictEqual( child.data("grande"), "5.574E9", - "Big exponential-notation number read from attribute as string"); - assert.strictEqual( child.data("hexadecimal"), "0x42", - "Hexadecimal number read from attribute as string"); - assert.strictEqual( child.data("pointbad"), "5..5", - "Extra-point non-number read from attribute as string"); - assert.strictEqual( child.data("pointbad2"), "-.", - "No-digit non-number read from attribute as string"); - assert.strictEqual( child.data("bigassnum"), "123456789123456789123456789", - "Bad bigass number read from attribute as string"); - assert.strictEqual( child.data("badjson"), "{123}", "Bad JSON object read from attribute as string"); - assert.strictEqual( child.data("badjson2"), "[abc]", "Bad JSON array read from attribute as string"); - assert.strictEqual( child.data("notjson"), " {}", - "JSON object with leading non-JSON read from attribute as string"); - assert.strictEqual( child.data("notjson2"), "[] ", - "JSON array with trailing non-JSON read from attribute as string"); - assert.strictEqual( child.data("empty"), "", "Empty string read from attribute"); - assert.strictEqual( child.data("space"), " ", "Whitespace string read from attribute"); - assert.strictEqual( child.data("null"), null, "Primitive null read from attribute"); - assert.strictEqual( child.data("string"), "test", "Typical string read from attribute"); + .attr( "data-true", "true" ) + .attr( "data-false", "false" ) + .attr( "data-five", "5" ) + .attr( "data-point", "5.5" ) + .attr( "data-pointe", "5.5E3" ) + .attr( "data-grande", "5.574E9" ) + .attr( "data-hexadecimal", "0x42" ) + .attr( "data-pointbad", "5..5" ) + .attr( "data-pointbad2", "-." ) + .attr( "data-bigassnum", "123456789123456789123456789" ) + .attr( "data-badjson", "{123}" ) + .attr( "data-badjson2", "[abc]" ) + .attr( "data-notjson", " {}" ) + .attr( "data-notjson2", "[] " ) + .attr( "data-empty", "" ) + .attr( "data-space", " " ) + .attr( "data-null", "null" ) + .attr( "data-string", "test" ); + + assert.strictEqual( child.data( "true" ), true, "Primitive true read from attribute" ); + assert.strictEqual( child.data( "false" ), false, "Primitive false read from attribute" ); + assert.strictEqual( child.data( "five" ), 5, "Integer read from attribute" ); + assert.strictEqual( child.data( "point" ), 5.5, "Floating-point number read from attribute" ); + assert.strictEqual( child.data( "pointe" ), "5.5E3", + "Exponential-notation number read from attribute as string" ); + assert.strictEqual( child.data( "grande" ), "5.574E9", + "Big exponential-notation number read from attribute as string" ); + assert.strictEqual( child.data( "hexadecimal" ), "0x42", + "Hexadecimal number read from attribute as string" ); + assert.strictEqual( child.data( "pointbad" ), "5..5", + "Extra-point non-number read from attribute as string" ); + assert.strictEqual( child.data( "pointbad2" ), "-.", + "No-digit non-number read from attribute as string" ); + assert.strictEqual( child.data( "bigassnum" ), "123456789123456789123456789", + "Bad bigass number read from attribute as string" ); + assert.strictEqual( child.data( "badjson" ), "{123}", "Bad JSON object read from attribute as string" ); + assert.strictEqual( child.data( "badjson2" ), "[abc]", "Bad JSON array read from attribute as string" ); + assert.strictEqual( child.data( "notjson" ), " {}", + "JSON object with leading non-JSON read from attribute as string" ); + assert.strictEqual( child.data( "notjson2" ), "[] ", + "JSON array with trailing non-JSON read from attribute as string" ); + assert.strictEqual( child.data( "empty" ), "", "Empty string read from attribute" ); + assert.strictEqual( child.data( "space" ), " ", "Whitespace string read from attribute" ); + assert.strictEqual( child.data( "null" ), null, "Primitive null read from attribute" ); + assert.strictEqual( child.data( "string" ), "test", "Typical string read from attribute" ); assert.equal( i, 2, "Correct number of JSON parse attempts when reading from attributes" ); jQuery.parseJSON = parseJSON; child.remove(); // tests from metadata plugin - function testData(index, elem) { - switch (index) { + function testData( index, elem ) { + switch ( index ) { case 0: - assert.equal(jQuery(elem).data("foo"), "bar", "Check foo property"); - assert.equal(jQuery(elem).data("bar"), "baz", "Check baz property"); + assert.equal( jQuery( elem ).data( "foo" ), "bar", "Check foo property" ); + assert.equal( jQuery( elem ).data( "bar" ), "baz", "Check baz property" ); break; case 1: - assert.equal(jQuery(elem).data("test"), "bar", "Check test property"); - assert.equal(jQuery(elem).data("bar"), "baz", "Check bar property"); + assert.equal( jQuery( elem ).data( "test" ), "bar", "Check test property" ); + assert.equal( jQuery( elem ).data( "bar" ), "baz", "Check bar property" ); break; case 2: - assert.equal(jQuery(elem).data("zoooo"), "bar", "Check zoooo property"); - assert.deepEqual(jQuery(elem).data("bar"), {"test":"baz"}, "Check bar property"); + assert.equal( jQuery( elem ).data( "zoooo" ), "bar", "Check zoooo property" ); + assert.deepEqual( jQuery( elem ).data( "bar" ), { "test":"baz" }, "Check bar property" ); break; case 3: - assert.equal(jQuery(elem).data("number"), true, "Check number property"); - assert.deepEqual(jQuery(elem).data("stuff"), [2,8], "Check stuff property"); + assert.equal( jQuery( elem ).data( "number" ), true, "Check number property" ); + assert.deepEqual( jQuery( elem ).data( "stuff" ), [ 2,8 ], "Check stuff property" ); break; default: - assert.ok(false, ["Assertion failed on index ", index, ", with data"].join("")); + assert.ok( false, [ "Assertion failed on index ", index, ", with data" ].join( "" ) ); } } metadata = "<ol><li class='test test2' data-foo='bar' data-bar='baz' data-arr='[1,2]'>Some stuff</li><li class='test test2' data-test='bar' data-bar='baz'>Some stuff</li><li class='test test2' data-zoooo='bar' data-bar='{\"test\":\"baz\"}'>Some stuff</li><li class='test test2' data-number=true data-stuff='[2,8]'>Some stuff</li></ol>"; - elem = jQuery(metadata).appendTo("#qunit-fixture"); + elem = jQuery( metadata ).appendTo( "#qunit-fixture" ); - elem.find("li").each(testData); + elem.find( "li" ).each( testData ); elem.remove(); -}); +} ); -QUnit.test(".data(Object)", function( assert ) { - assert.expect(4); +QUnit.test( ".data(Object)", function( assert ) { + assert.expect( 4 ); var obj, jqobj, - div = jQuery("<div/>"); + div = jQuery( "<div/>" ); - div.data({ "test": "in", "test2": "in2" }); - assert.equal( div.data("test"), "in", "Verify setting an object in data" ); - assert.equal( div.data("test2"), "in2", "Verify setting an object in data" ); + div.data( { "test": "in", "test2": "in2" } ); + assert.equal( div.data( "test" ), "in", "Verify setting an object in data" ); + assert.equal( div.data( "test2" ), "in2", "Verify setting an object in data" ); - obj = {test:"unset"}; - jqobj = jQuery(obj); + obj = { test:"unset" }; + jqobj = jQuery( obj ); - jqobj.data("test", "unset"); - jqobj.data({ "test": "in", "test2": "in2" }); - assert.equal( jQuery.data(obj)["test"], "in", "Verify setting an object on an object extends the data object" ); - assert.equal( obj["test2"], undefined, "Verify setting an object on an object does not extend the object" ); + jqobj.data( "test", "unset" ); + jqobj.data( { "test": "in", "test2": "in2" } ); + assert.equal( jQuery.data( obj )[ "test" ], "in", "Verify setting an object on an object extends the data object" ); + assert.equal( obj[ "test2" ], undefined, "Verify setting an object on an object does not extend the object" ); // manually clean up detached elements div.remove(); -}); +} ); -QUnit.test("jQuery.removeData", function( assert ) { - assert.expect(10); +QUnit.test( "jQuery.removeData", function( assert ) { + assert.expect( 10 ); var obj, - div = jQuery("#foo")[0]; - jQuery.data(div, "test", "testing"); - jQuery.removeData(div, "test"); - assert.equal( jQuery.data(div, "test"), undefined, "Check removal of data" ); + div = jQuery( "#foo" )[ 0 ]; + jQuery.data( div, "test", "testing" ); + jQuery.removeData( div, "test" ); + assert.equal( jQuery.data( div, "test" ), undefined, "Check removal of data" ); - jQuery.data(div, "test2", "testing"); + jQuery.data( div, "test2", "testing" ); jQuery.removeData( div ); - assert.ok( !jQuery.data(div, "test2"), "Make sure that the data property no longer exists." ); + assert.ok( !jQuery.data( div, "test2" ), "Make sure that the data property no longer exists." ); assert.ok( !div[ jQuery.expando ], "Make sure the expando no longer exists, as well." ); - jQuery.data(div, { + jQuery.data( div, { test3: "testing", test4: "testing" - }); + } ); jQuery.removeData( div, "test3 test4" ); - assert.ok( !jQuery.data(div, "test3") || jQuery.data(div, "test4"), "Multiple delete with spaces." ); + assert.ok( !jQuery.data( div, "test3" ) || jQuery.data( div, "test4" ), "Multiple delete with spaces." ); - jQuery.data(div, { + jQuery.data( div, { test3: "testing", test4: "testing" - }); + } ); jQuery.removeData( div, [ "test3", "test4" ] ); - assert.ok( !jQuery.data(div, "test3") || jQuery.data(div, "test4"), "Multiple delete by array." ); + assert.ok( !jQuery.data( div, "test3" ) || jQuery.data( div, "test4" ), "Multiple delete by array." ); - jQuery.data(div, { + jQuery.data( div, { "test3 test4": "testing", "test3": "testing" - }); + } ); jQuery.removeData( div, "test3 test4" ); - assert.ok( !jQuery.data(div, "test3 test4"), "Multiple delete with spaces deleted key with exact name" ); - assert.ok( jQuery.data(div, "test3"), "Left the partial matched key alone" ); + assert.ok( !jQuery.data( div, "test3 test4" ), "Multiple delete with spaces deleted key with exact name" ); + assert.ok( jQuery.data( div, "test3" ), "Left the partial matched key alone" ); obj = {}; - jQuery.data(obj, "test", "testing"); - assert.equal( jQuery(obj).data("test"), "testing", "verify data on plain object"); - jQuery.removeData(obj, "test"); - assert.equal( jQuery.data(obj, "test"), undefined, "Check removal of data on plain object" ); + jQuery.data( obj, "test", "testing" ); + assert.equal( jQuery( obj ).data( "test" ), "testing", "verify data on plain object" ); + jQuery.removeData( obj, "test" ); + assert.equal( jQuery.data( obj, "test" ), undefined, "Check removal of data on plain object" ); jQuery.data( window, "BAD", true ); jQuery.removeData( window, "BAD" ); assert.ok( !jQuery.data( window, "BAD" ), "Make sure that the value was not still set." ); -}); - -QUnit.test(".removeData()", function( assert ) { - assert.expect(6); - var div = jQuery("#foo"); - div.data("test", "testing"); - div.removeData("test"); - assert.equal( div.data("test"), undefined, "Check removal of data" ); - - div.data("test", "testing"); - div.data("test.foo", "testing2"); - div.removeData("test.bar"); - assert.equal( div.data("test.foo"), "testing2", "Make sure data is intact" ); - assert.equal( div.data("test"), "testing", "Make sure data is intact" ); - - div.removeData("test"); - assert.equal( div.data("test.foo"), "testing2", "Make sure data is intact" ); - assert.equal( div.data("test"), undefined, "Make sure data is intact" ); - - div.removeData("test.foo"); - assert.equal( div.data("test.foo"), undefined, "Make sure data is intact" ); -}); - -if (window.JSON && window.JSON.stringify) { - QUnit.test("JSON serialization (#8108)", function( assert ) { - assert.expect(1); +} ); + +QUnit.test( ".removeData()", function( assert ) { + assert.expect( 6 ); + var div = jQuery( "#foo" ); + div.data( "test", "testing" ); + div.removeData( "test" ); + assert.equal( div.data( "test" ), undefined, "Check removal of data" ); + + div.data( "test", "testing" ); + div.data( "test.foo", "testing2" ); + div.removeData( "test.bar" ); + assert.equal( div.data( "test.foo" ), "testing2", "Make sure data is intact" ); + assert.equal( div.data( "test" ), "testing", "Make sure data is intact" ); + + div.removeData( "test" ); + assert.equal( div.data( "test.foo" ), "testing2", "Make sure data is intact" ); + assert.equal( div.data( "test" ), undefined, "Make sure data is intact" ); + + div.removeData( "test.foo" ); + assert.equal( div.data( "test.foo" ), undefined, "Make sure data is intact" ); +} ); + +if ( window.JSON && window.JSON.stringify ) { + QUnit.test( "JSON serialization (#8108)", function( assert ) { + assert.expect( 1 ); var obj = { "foo": "bar" }; - jQuery.data(obj, "hidden", true); + jQuery.data( obj, "hidden", true ); - assert.equal( JSON.stringify(obj), "{\"foo\":\"bar\"}", "Expando is hidden from JSON.stringify" ); - }); + assert.equal( JSON.stringify( obj ), "{\"foo\":\"bar\"}", "Expando is hidden from JSON.stringify" ); + } ); } -QUnit.test(".data should follow html5 specification regarding camel casing", function( assert ) { - assert.expect(12); +QUnit.test( ".data should follow html5 specification regarding camel casing", function( assert ) { + assert.expect( 12 ); - var div = jQuery("<div id='myObject' data-w-t-f='ftw' data-big-a-little-a='bouncing-b' data-foo='a' data-foo-bar='b' data-foo-bar-baz='c'></div>") - .prependTo("body"); + var div = jQuery( "<div id='myObject' data-w-t-f='ftw' data-big-a-little-a='bouncing-b' data-foo='a' data-foo-bar='b' data-foo-bar-baz='c'></div>" ) + .prependTo( "body" ); - assert.equal( div.data()["wTF"], "ftw", "Verify single letter data-* key" ); - assert.equal( div.data()["bigALittleA"], "bouncing-b", "Verify single letter mixed data-* key" ); + assert.equal( div.data()[ "wTF" ], "ftw", "Verify single letter data-* key" ); + assert.equal( div.data()[ "bigALittleA" ], "bouncing-b", "Verify single letter mixed data-* key" ); - assert.equal( div.data()["foo"], "a", "Verify single word data-* key" ); - assert.equal( div.data()["fooBar"], "b", "Verify multiple word data-* key" ); - assert.equal( div.data()["fooBarBaz"], "c", "Verify multiple word data-* key" ); + assert.equal( div.data()[ "foo" ], "a", "Verify single word data-* key" ); + assert.equal( div.data()[ "fooBar" ], "b", "Verify multiple word data-* key" ); + assert.equal( div.data()[ "fooBarBaz" ], "c", "Verify multiple word data-* key" ); - assert.equal( div.data("foo"), "a", "Verify single word data-* key" ); - assert.equal( div.data("fooBar"), "b", "Verify multiple word data-* key" ); - assert.equal( div.data("fooBarBaz"), "c", "Verify multiple word data-* key" ); + assert.equal( div.data( "foo" ), "a", "Verify single word data-* key" ); + assert.equal( div.data( "fooBar" ), "b", "Verify multiple word data-* key" ); + assert.equal( div.data( "fooBarBaz" ), "c", "Verify multiple word data-* key" ); - div.data("foo-bar", "d"); + div.data( "foo-bar", "d" ); - assert.equal( div.data("fooBar"), "d", "Verify updated data-* key" ); - assert.equal( div.data("foo-bar"), "d", "Verify updated data-* key" ); + assert.equal( div.data( "fooBar" ), "d", "Verify updated data-* key" ); + assert.equal( div.data( "foo-bar" ), "d", "Verify updated data-* key" ); - assert.equal( div.data("fooBar"), "d", "Verify updated data-* key (fooBar)" ); - assert.equal( div.data("foo-bar"), "d", "Verify updated data-* key (foo-bar)" ); + assert.equal( div.data( "fooBar" ), "d", "Verify updated data-* key (fooBar)" ); + assert.equal( div.data( "foo-bar" ), "d", "Verify updated data-* key (foo-bar)" ); div.remove(); -}); +} ); -QUnit.test(".data should not miss preset data-* w/ hyphenated property names", function( assert ) { +QUnit.test( ".data should not miss preset data-* w/ hyphenated property names", function( assert ) { - assert.expect(2); + assert.expect( 2 ); - var div = jQuery("<div/>", { id: "hyphened" }).appendTo("#qunit-fixture"), + var div = jQuery( "<div/>", { id: "hyphened" } ).appendTo( "#qunit-fixture" ), test = { "camelBar": "camelBar", "hyphen-foo": "hyphen-foo" @@ -564,47 +564,47 @@ QUnit.test(".data should not miss preset data-* w/ hyphenated property names", f div.data( test ); - jQuery.each( test , function(i, k) { - assert.equal( div.data(k), k, "data with property '"+k+"' was correctly found"); - }); -}); + jQuery.each( test, function( i, k ) { + assert.equal( div.data( k ), k, "data with property '" + k + "' was correctly found" ); + } ); +} ); -QUnit.test("jQuery.data should not miss data-* w/ hyphenated property names #14047", function( assert ) { +QUnit.test( "jQuery.data should not miss data-* w/ hyphenated property names #14047", function( assert ) { - assert.expect(1); + assert.expect( 1 ); - var div = jQuery("<div/>"); + var div = jQuery( "<div/>" ); div.data( "foo-bar", "baz" ); - assert.equal( jQuery.data(div[0], "foo-bar"), "baz", "data with property 'foo-bar' was correctly found"); -}); + assert.equal( jQuery.data( div[ 0 ], "foo-bar" ), "baz", "data with property 'foo-bar' was correctly found" ); +} ); -QUnit.test(".data should not miss attr() set data-* with hyphenated property names", function( assert ) { - assert.expect(2); +QUnit.test( ".data should not miss attr() set data-* with hyphenated property names", function( assert ) { + assert.expect( 2 ); var a, b; - a = jQuery("<div/>").appendTo("#qunit-fixture"); + a = jQuery( "<div/>" ).appendTo( "#qunit-fixture" ); a.attr( "data-long-param", "test" ); - a.data( "long-param", { a: 2 }); + a.data( "long-param", { a: 2 } ); - assert.deepEqual( a.data("long-param"), { a: 2 }, "data with property long-param was found, 1" ); + assert.deepEqual( a.data( "long-param" ), { a: 2 }, "data with property long-param was found, 1" ); - b = jQuery("<div/>").appendTo("#qunit-fixture"); + b = jQuery( "<div/>" ).appendTo( "#qunit-fixture" ); b.attr( "data-long-param", "test" ); b.data( "long-param" ); - b.data( "long-param", { a: 2 }); + b.data( "long-param", { a: 2 } ); - assert.deepEqual( b.data("long-param"), { a: 2 }, "data with property long-param was found, 2" ); -}); + assert.deepEqual( b.data( "long-param" ), { a: 2 }, "data with property long-param was found, 2" ); +} ); -QUnit.test(".data always sets data with the camelCased key (gh-2257)", function( assert ) { +QUnit.test( ".data always sets data with the camelCased key (gh-2257)", function( assert ) { assert.expect( 18 ); - var div = jQuery("<div>").appendTo("#qunit-fixture"), + var div = jQuery( "<div>" ).appendTo( "#qunit-fixture" ), datas = { "non-empty": "a string", "empty-string": "", @@ -626,8 +626,8 @@ QUnit.test(".data always sets data with the camelCased key (gh-2257)", function( var allData = div.data(); assert.equal( allData[ key ], undefined, ".data does not store with hyphenated keys" ); assert.equal( allData[ jQuery.camelCase( key ) ], val, ".data stores the camelCased key" ); - }); -}); + } ); +} ); QUnit.test( ".data should not strip more than one hyphen when camelCasing (gh-2070)", function( assert ) { assert.expect( 3 ); @@ -637,11 +637,11 @@ QUnit.test( ".data should not strip more than one hyphen when camelCasing (gh-20 assert.equal( allData.nestedSingle, "single", "Key is correctly camelCased" ); assert.equal( allData[ "nested-Double" ], "double", "Key with double hyphens is correctly camelCased" ); assert.equal( allData[ "nested--Triple" ], "triple", "Key with triple hyphens is correctly camelCased" ); -}); +} ); -QUnit.test(".data supports interoperable hyphenated/camelCase get/set of properties with arbitrary non-null|NaN|undefined values", function( assert ) { +QUnit.test( ".data supports interoperable hyphenated/camelCase get/set of properties with arbitrary non-null|NaN|undefined values", function( assert ) { - var div = jQuery("<div/>", { id: "hyphened" }).appendTo("#qunit-fixture"), + var div = jQuery( "<div/>", { id: "hyphened" } ).appendTo( "#qunit-fixture" ), datas = { "non-empty": "a string", "empty-string": "", @@ -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 @@ -667,11 +668,11 @@ QUnit.test(".data supports interoperable hyphenated/camelCase get/set of propert assert.deepEqual( div.data( key ), val, "get: " + key ); assert.deepEqual( div.data( jQuery.camelCase( key ) ), val, "get: " + jQuery.camelCase( key ) ); - }); -}); + } ); +} ); -QUnit.test(".data supports interoperable removal of hyphenated/camelCase properties", function( assert ) { - var div = jQuery("<div/>", { id: "hyphened" }).appendTo("#qunit-fixture"), +QUnit.test( ".data supports interoperable removal of hyphenated/camelCase properties", function( assert ) { + var div = jQuery( "<div/>", { id: "hyphened" } ).appendTo( "#qunit-fixture" ), datas = { "non-empty": "a string", "empty-string": "", @@ -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 @@ -699,11 +701,11 @@ QUnit.test(".data supports interoperable removal of hyphenated/camelCase propert assert.equal( div.data( key ), undefined, "get: " + key ); - }); -}); + } ); +} ); -QUnit.test(".data supports interoperable removal of properties SET TWICE #13850", function( assert ) { - var div = jQuery("<div>").appendTo("#qunit-fixture"), +QUnit.test( ".data supports interoperable removal of properties SET TWICE #13850", function( assert ) { + var div = jQuery( "<div>" ).appendTo( "#qunit-fixture" ), datas = { "non-empty": "a string", "empty-string": "", @@ -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 @@ -728,51 +731,54 @@ QUnit.test(".data supports interoperable removal of properties SET TWICE #13850" div.removeData( key ); assert.equal( div.data( key ), undefined, "removal: " + key ); - }); -}); + } ); +} ); QUnit.test( ".removeData supports removal of hyphenated properties via array (#12786, gh-2257)", function( assert ) { assert.expect( 4 ); var div, plain, compare; - div = jQuery("<div>").appendTo("#qunit-fixture"); - plain = jQuery({}); + div = jQuery( "<div>" ).appendTo( "#qunit-fixture" ); + plain = jQuery( {} ); // Properties should always be camelCased compare = { + // From batch assignment .data({ "a-a": 1 }) "aA": 1, + // From property, value assignment .data( "b-b", 1 ) "bB": 1 }; // Mixed assignment - div.data({ "a-a": 1 }).data( "b-b", 1 ); - plain.data({ "a-a": 1 }).data( "b-b", 1 ); + div.data( { "a-a": 1 } ).data( "b-b", 1 ); + plain.data( { "a-a": 1 } ).data( "b-b", 1 ); assert.deepEqual( div.data(), compare, "Data appears as expected. (div)" ); assert.deepEqual( plain.data(), compare, "Data appears as expected. (plain)" ); - div.removeData([ "a-a", "b-b" ]); - plain.removeData([ "a-a", "b-b" ]); + div.removeData( [ "a-a", "b-b" ] ); + plain.removeData( [ "a-a", "b-b" ] ); assert.deepEqual( div.data(), {}, "Data is empty. (div)" ); assert.deepEqual( plain.data(), {}, "Data is empty. (plain)" ); -}); +} ); // Test originally by Moschel -QUnit.test(".removeData should not throw exceptions. (#10080)", function( assert ) { - assert.expect(1); +QUnit.test( ".removeData should not throw exceptions. (#10080)", function( assert ) { + assert.expect( 1 ); QUnit.stop(); - var frame = jQuery("#loadediframe"); - jQuery(frame[0].contentWindow).on("unload", function() { - assert.ok(true, "called unload"); + var frame = jQuery( "#loadediframe" ); + jQuery( frame[ 0 ].contentWindow ).on( "unload", function() { + assert.ok( true, "called unload" ); QUnit.start(); - }); + } ); + // change the url to trigger unload - frame.attr("src", "data/iframe.html?param=true"); -}); + frame.attr( "src", "data/iframe.html?param=true" ); +} ); QUnit.test( ".data only checks element attributes once. #8909", function( assert ) { assert.expect( 2 ); @@ -792,18 +798,18 @@ QUnit.test( ".data only checks element attributes once. #8909", function( assert // clean up data cache element.remove(); -}); +} ); QUnit.test( "data-* with JSON value can have newlines", function( assert ) { - assert.expect(1); + assert.expect( 1 ); - var x = jQuery("<div data-some='{\n\"foo\":\n\t\"bar\"\n}'></div>"); - assert.equal( x.data("some").foo, "bar", "got a JSON data- attribute with spaces" ); + var x = jQuery( "<div data-some='{\n\"foo\":\n\t\"bar\"\n}'></div>" ); + assert.equal( x.data( "some" ).foo, "bar", "got a JSON data- attribute with spaces" ); x.remove(); -}); +} ); -QUnit.test(".data doesn't throw when calling selection is empty. #13551", function( assert ) { - assert.expect(1); +QUnit.test( ".data doesn't throw when calling selection is empty. #13551", function( assert ) { + assert.expect( 1 ); try { jQuery( null ).data( "prop" ); @@ -811,9 +817,9 @@ QUnit.test(".data doesn't throw when calling selection is empty. #13551", functi } catch ( e ) { assert.ok( false, e.message ); } -}); +} ); -QUnit.test("jQuery.acceptData", function( assert ) { +QUnit.test( "jQuery.acceptData", function( assert ) { assert.expect( 10 ); var flash, pdf; @@ -838,19 +844,19 @@ QUnit.test("jQuery.acceptData", function( assert ) { assert.ok( jQuery.acceptData( jQuery( "#form" ).append( "<input id='nodeType'/><input id='nodeName'/>" )[ 0 ] ), "form with aliased DOM properties" ); -}); +} ); -QUnit.test("Check proper data removal of non-element descendants nodes (#8335)", function( assert ) { +QUnit.test( "Check proper data removal of non-element descendants nodes (#8335)", function( assert ) { assert.expect( 1 ); - var div = jQuery("<div>text</div>"), + var div = jQuery( "<div>text</div>" ), text = div.contents(); text.data( "test", "test" ); // This should be a noop. div.remove(); - assert.ok( !text.data("test"), "Be sure data is not stored in non-element" ); -}); + assert.ok( !text.data( "test" ), "Be sure data is not stored in non-element" ); +} ); testIframeWithCallback( "enumerate data attrs on body (#14894)", @@ -876,4 +882,4 @@ QUnit.test( "Check that the expando is removed when there's no more data", funct assert.ok( false, "Expando was not removed when there was no more data" ); } } -}); +} ); diff --git a/test/unit/deferred.js b/test/unit/deferred.js index 83b7897af..33b5b4f16 100644 --- a/test/unit/deferred.js +++ b/test/unit/deferred.js @@ -1,6 +1,6 @@ QUnit.module( "deferred", { teardown: moduleTeardown -}); +} ); jQuery.each( [ "", " - new operator" ], function( _, withNew ) { @@ -16,32 +16,32 @@ jQuery.each( [ "", " - new operator" ], function( _, withNew ) { assert.ok( jQuery.isFunction( defer.pipe ), "defer.pipe is a function" ); - createDeferred().resolve().done(function() { + createDeferred().resolve().done( function() { assert.ok( true, "Success on resolve" ); assert.strictEqual( this.state(), "resolved", "Deferred is resolved (state)" ); - }).fail(function() { + } ).fail( function() { assert.ok( false, "Error on resolve" ); - }).always(function() { + } ).always( function() { assert.ok( true, "Always callback on resolve" ); - }); + } ); - createDeferred().reject().done(function() { + createDeferred().reject().done( function() { assert.ok( false, "Success on reject" ); - }).fail(function() { + } ).fail( function() { assert.ok( true, "Error on reject" ); assert.strictEqual( this.state(), "rejected", "Deferred is rejected (state)" ); - }).always(function() { + } ).always( function() { assert.ok( true, "Always callback on reject" ); - }); + } ); - createDeferred(function( defer ) { + createDeferred( function( defer ) { assert.ok( this === defer, "Defer passed as this & first argument" ); - this.resolve("done"); - }).done(function( value ) { + this.resolve( "done" ); + } ).done( function( value ) { assert.strictEqual( value, "done", "Passed function executed" ); - }); + } ); - createDeferred(function( defer ) { + createDeferred( function( defer ) { var promise = defer.promise(), func = function() {}, funcPromise = defer.promise( func ); @@ -54,17 +54,17 @@ jQuery.each( [ "", " - new operator" ], function( _, withNew ) { if ( promise[ key ] !== func[ key ] ) { assert.strictEqual( func[ key ], promise[ key ], key + " is the same" ); } - }); - }); + } ); + } ); jQuery.expandedEach = jQuery.each; - jQuery.expandedEach( "resolve reject".split(" "), function( _, change ) { - createDeferred(function( defer ) { + jQuery.expandedEach( "resolve reject".split( " " ), function( _, change ) { + createDeferred( function( defer ) { assert.strictEqual( defer.state(), "pending", "pending after creation" ); var checked = 0; - defer.progress(function( value ) { + defer.progress( function( value ) { assert.strictEqual( value, checked, "Progress: right value (" + value + ") received" ); - }); + } ); for ( checked = 0; checked < 3; checked++ ) { defer.notify( checked ); } @@ -72,11 +72,10 @@ jQuery.each( [ "", " - new operator" ], function( _, withNew ) { defer[ change ](); assert.notStrictEqual( defer.state(), "pending", "not pending after " + change ); defer.notify(); - }); - }); - }); -}); - + } ); + } ); + } ); +} ); QUnit.test( "jQuery.Deferred - chainability", function( assert ) { @@ -85,13 +84,13 @@ QUnit.test( "jQuery.Deferred - chainability", function( assert ) { assert.expect( 10 ); jQuery.expandedEach = jQuery.each; - jQuery.expandedEach( "resolve reject notify resolveWith rejectWith notifyWith done fail progress always".split(" "), function( _, method ) { + jQuery.expandedEach( "resolve reject notify resolveWith rejectWith notifyWith done fail progress always".split( " " ), function( _, method ) { var object = { m: defer[ method ] }; assert.strictEqual( object.m(), object, method + " is chainable" ); - }); -}); + } ); +} ); QUnit.test( "jQuery.Deferred.then - filtering (done)", function( assert ) { @@ -99,36 +98,36 @@ QUnit.test( "jQuery.Deferred.then - filtering (done)", function( assert ) { var value1, value2, value3, defer = jQuery.Deferred(), - piped = defer.then(function( a, b ) { + piped = defer.then( function( a, b ) { return a * b; - }), + } ), done = jQuery.map( new Array( 3 ), function() { return assert.async(); } ); - piped.done(function( result ) { + piped.done( function( result ) { value3 = result; - }); + } ); - defer.done(function( a, b ) { + defer.done( function( a, b ) { value1 = a; value2 = b; - }); + } ); - defer.resolve( 2, 3 ).then(function() { + defer.resolve( 2, 3 ).then( function() { assert.strictEqual( value1, 2, "first resolve value ok" ); assert.strictEqual( value2, 3, "second resolve value ok" ); assert.strictEqual( value3, 6, "result of filter ok" ); done.pop().call(); - }); + } ); - jQuery.Deferred().reject().then(function() { + jQuery.Deferred().reject().then( function() { assert.ok( false, "then should not be called on reject" ); - }).then( null, done.pop() ); + } ).then( null, done.pop() ); - jQuery.Deferred().resolve().then( jQuery.noop ).done(function( value ) { + jQuery.Deferred().resolve().then( jQuery.noop ).done( function( value ) { assert.strictEqual( value, undefined, "then done callback can return undefined/null" ); done.pop().call(); - }); -}); + } ); +} ); QUnit.test( "jQuery.Deferred.then - filtering (fail)", function( assert ) { @@ -138,70 +137,70 @@ QUnit.test( "jQuery.Deferred.then - filtering (fail)", function( assert ) { defer = jQuery.Deferred(), piped = defer.then( null, function( a, b ) { return a * b; - }), + } ), done = jQuery.map( new Array( 3 ), function() { return assert.async(); } ); - piped.done(function( result ) { + piped.done( function( result ) { value3 = result; - }); + } ); - defer.fail(function( a, b ) { + defer.fail( function( a, b ) { value1 = a; value2 = b; - }); + } ); defer.reject( 2, 3 ).then( null, function() { assert.strictEqual( value1, 2, "first reject value ok" ); assert.strictEqual( value2, 3, "second reject value ok" ); assert.strictEqual( value3, 6, "result of filter ok" ); done.pop().call(); - }); + } ); jQuery.Deferred().resolve().then( null, function() { assert.ok( false, "then should not be called on resolve" ); - }).then( done.pop() ); + } ).then( done.pop() ); - jQuery.Deferred().reject().then( null, jQuery.noop ).done(function( value ) { + jQuery.Deferred().reject().then( null, jQuery.noop ).done( function( value ) { assert.strictEqual( value, undefined, "then fail callback can return undefined/null" ); done.pop().call(); - }); -}); + } ); +} ); QUnit.test( "jQuery.Deferred.catch", function( assert ) { assert.expect( 4 ); var value1, value2, value3, defer = jQuery.Deferred(), - piped = defer[ "catch" ](function( a, b ) { + piped = defer[ "catch" ]( function( a, b ) { return a * b; - }), + } ), done = jQuery.map( new Array( 3 ), function() { return assert.async(); } ); - piped.done(function( result ) { + piped.done( function( result ) { value3 = result; - }); + } ); - defer.fail(function( a, b ) { + defer.fail( function( a, b ) { value1 = a; value2 = b; - }); + } ); - defer.reject( 2, 3 )[ "catch" ](function() { + defer.reject( 2, 3 )[ "catch" ]( function() { assert.strictEqual( value1, 2, "first reject value ok" ); assert.strictEqual( value2, 3, "second reject value ok" ); assert.strictEqual( value3, 6, "result of filter ok" ); done.pop().call(); - }); + } ); - jQuery.Deferred().resolve()[ "catch" ](function() { + jQuery.Deferred().resolve()[ "catch" ]( function() { assert.ok( false, "then should not be called on resolve" ); - }).then( done.pop() ); + } ).then( done.pop() ); - jQuery.Deferred().reject()[ "catch" ]( jQuery.noop ).done(function( value ) { + jQuery.Deferred().reject()[ "catch" ]( jQuery.noop ).done( function( value ) { assert.strictEqual( value, undefined, "then fail callback can return undefined/null" ); done.pop().call(); - }); -}); + } ); +} ); QUnit.test( "[PIPE ONLY] jQuery.Deferred.pipe - filtering (fail)", function( assert ) { @@ -211,34 +210,34 @@ QUnit.test( "[PIPE ONLY] jQuery.Deferred.pipe - filtering (fail)", function( ass defer = jQuery.Deferred(), piped = defer.pipe( null, function( a, b ) { return a * b; - }), + } ), done = jQuery.map( new Array( 3 ), function() { return assert.async(); } ); - piped.fail(function( result ) { + piped.fail( function( result ) { value3 = result; - }); + } ); - defer.fail(function( a, b ) { + defer.fail( function( a, b ) { value1 = a; value2 = b; - }); + } ); defer.reject( 2, 3 ).pipe( null, function() { assert.strictEqual( value1, 2, "first reject value ok" ); assert.strictEqual( value2, 3, "second reject value ok" ); assert.strictEqual( value3, 6, "result of filter ok" ); done.pop().call(); - }); + } ); jQuery.Deferred().resolve().pipe( null, function() { assert.ok( false, "then should not be called on resolve" ); - }).then( done.pop() ); + } ).then( done.pop() ); - jQuery.Deferred().reject().pipe( null, jQuery.noop ).fail(function( value ) { + jQuery.Deferred().reject().pipe( null, jQuery.noop ).fail( function( value ) { assert.strictEqual( value, undefined, "then fail callback can return undefined/null" ); done.pop().call(); - }); -}); + } ); +} ); QUnit.test( "jQuery.Deferred.then - filtering (progress)", function( assert ) { @@ -248,25 +247,25 @@ QUnit.test( "jQuery.Deferred.then - filtering (progress)", function( assert ) { defer = jQuery.Deferred(), piped = defer.then( null, null, function( a, b ) { return a * b; - }), + } ), done = assert.async(); - piped.progress(function( result ) { + piped.progress( function( result ) { value3 = result; - }); + } ); - defer.progress(function( a, b ) { + defer.progress( function( a, b ) { value1 = a; value2 = b; - }); + } ); defer.notify( 2, 3 ).then( null, null, function() { assert.strictEqual( value1, 2, "first progress value ok" ); assert.strictEqual( value2, 3, "second progress value ok" ); assert.strictEqual( value3, 6, "result of filter ok" ); done(); - }); -}); + } ); +} ); QUnit.test( "jQuery.Deferred.then - deferred (done)", function( assert ) { @@ -274,31 +273,31 @@ QUnit.test( "jQuery.Deferred.then - deferred (done)", function( assert ) { var value1, value2, value3, defer = jQuery.Deferred(), - piped = defer.then(function( a, b ) { - return jQuery.Deferred(function( defer ) { + piped = defer.then( function( a, b ) { + return jQuery.Deferred( function( defer ) { defer.reject( a * b ); - }); - }), + } ); + } ), done = assert.async(); - piped.fail(function( result ) { + piped.fail( function( result ) { value3 = result; - }); + } ); - defer.done(function( a, b ) { + defer.done( function( a, b ) { value1 = a; value2 = b; - }); + } ); defer.resolve( 2, 3 ); - piped.fail(function() { + piped.fail( function() { assert.strictEqual( value1, 2, "first resolve value ok" ); assert.strictEqual( value2, 3, "second resolve value ok" ); assert.strictEqual( value3, 6, "result of filter ok" ); done(); - }); -}); + } ); +} ); QUnit.test( "jQuery.Deferred.then - deferred (fail)", function( assert ) { @@ -307,30 +306,30 @@ QUnit.test( "jQuery.Deferred.then - deferred (fail)", function( assert ) { var value1, value2, value3, defer = jQuery.Deferred(), piped = defer.then( null, function( a, b ) { - return jQuery.Deferred(function( defer ) { + return jQuery.Deferred( function( defer ) { defer.resolve( a * b ); - }); - }), + } ); + } ), done = assert.async(); - piped.done(function( result ) { + piped.done( function( result ) { value3 = result; - }); + } ); - defer.fail(function( a, b ) { + defer.fail( function( a, b ) { value1 = a; value2 = b; - }); + } ); defer.reject( 2, 3 ); - piped.done(function() { + piped.done( function() { assert.strictEqual( value1, 2, "first reject value ok" ); assert.strictEqual( value2, 3, "second reject value ok" ); assert.strictEqual( value3, 6, "result of filter ok" ); done(); - }); -}); + } ); +} ); QUnit.test( "jQuery.Deferred.then - deferred (progress)", function( assert ) { @@ -339,38 +338,38 @@ QUnit.test( "jQuery.Deferred.then - deferred (progress)", function( assert ) { var value1, value2, value3, defer = jQuery.Deferred(), piped = defer.then( null, null, function( a, b ) { - return jQuery.Deferred(function( defer ) { + return jQuery.Deferred( function( defer ) { defer.resolve( a * b ); - }); - }), + } ); + } ), done = assert.async(); - piped.progress(function( result ) { - return jQuery.Deferred().resolve().then(function() { + piped.progress( function( result ) { + return jQuery.Deferred().resolve().then( function() { return result; - }).then(function( result ) { + } ).then( function( result ) { value3 = result; - }); - }); + } ); + } ); - defer.progress(function( a, b ) { + defer.progress( function( a, b ) { value1 = a; value2 = b; - }); + } ); defer.notify( 2, 3 ); piped.then( null, null, function( result ) { - return jQuery.Deferred().resolve().then(function() { + return jQuery.Deferred().resolve().then( function() { return result; - }).then(function() { + } ).then( function() { assert.strictEqual( value1, 2, "first progress value ok" ); assert.strictEqual( value2, 3, "second progress value ok" ); assert.strictEqual( value3, 6, "result of filter ok" ); done(); - }); - }); -}); + } ); + } ); +} ); QUnit.test( "[PIPE ONLY] jQuery.Deferred.pipe - deferred (progress)", function( assert ) { @@ -379,30 +378,30 @@ QUnit.test( "[PIPE ONLY] jQuery.Deferred.pipe - deferred (progress)", function( var value1, value2, value3, defer = jQuery.Deferred(), piped = defer.pipe( null, null, function( a, b ) { - return jQuery.Deferred(function( defer ) { + return jQuery.Deferred( function( defer ) { defer.resolve( a * b ); - }); - }), + } ); + } ), done = assert.async(); - piped.done(function( result ) { + piped.done( function( result ) { value3 = result; - }); + } ); - defer.progress(function( a, b ) { + defer.progress( function( a, b ) { value1 = a; value2 = b; - }); + } ); defer.notify( 2, 3 ); - piped.done(function() { + piped.done( function() { assert.strictEqual( value1, 2, "first progress value ok" ); assert.strictEqual( value2, 3, "second progress value ok" ); assert.strictEqual( value3, 6, "result of filter ok" ); done(); - }); -}); + } ); +} ); QUnit.test( "jQuery.Deferred.then - context", function( assert ) { @@ -412,48 +411,48 @@ QUnit.test( "jQuery.Deferred.then - context", function( assert ) { context = {}, done = jQuery.map( new Array( 4 ), function() { return assert.async(); } ); - jQuery.Deferred().resolveWith( context, [ 2 ] ).then(function( value ) { + jQuery.Deferred().resolveWith( context, [ 2 ] ).then( function( value ) { return value * 3; - }).done(function( value ) { + } ).done( function( value ) { assert.notStrictEqual( this, context, "custom context not propagated through .then" ); assert.strictEqual( value, 6, "proper value received" ); done.pop().call(); - }); + } ); - jQuery.Deferred().resolve().then(function() { + jQuery.Deferred().resolve().then( function() { return jQuery.Deferred().resolveWith( context ); - }).done(function() { + } ).done( function() { assert.strictEqual( this, context, "custom context of returned deferred correctly propagated" ); done.pop().call(); - }); + } ); defer = jQuery.Deferred(); - piped = defer.then(function( value ) { + piped = defer.then( function( value ) { return value * 3; - }); + } ); defer.resolve( 2 ); - piped.done(function( value ) { + piped.done( function( value ) { assert.strictEqual( this, piped, "default context gets updated to latest promise in the chain" ); assert.strictEqual( value, 6, "proper value received" ); done.pop().call(); - }); + } ); defer2 = jQuery.Deferred(); piped2 = defer2.then(); defer2.resolve( 2 ); - piped2.done(function( value ) { + piped2.done( function( value ) { assert.strictEqual( this, piped2, "default context updated to latest promise in the chain (without passing function)" ); assert.strictEqual( value, 2, "proper value received (without passing function)" ); done.pop().call(); - }); -}); + } ); +} ); QUnit.test( "[PIPE ONLY] jQuery.Deferred.pipe - context", function( assert ) { @@ -463,66 +462,66 @@ QUnit.test( "[PIPE ONLY] jQuery.Deferred.pipe - context", function( assert ) { context = {}, done = jQuery.map( new Array( 4 ), function() { return assert.async(); } ); - jQuery.Deferred().resolveWith( context, [ 2 ] ).pipe(function( value ) { + jQuery.Deferred().resolveWith( context, [ 2 ] ).pipe( function( value ) { return value * 3; - }).done(function( value ) { + } ).done( function( value ) { assert.strictEqual( this, context, "[PIPE ONLY] custom context correctly propagated" ); assert.strictEqual( value, 6, "proper value received" ); done.pop().call(); - }); + } ); - jQuery.Deferred().resolve().pipe(function() { - return jQuery.Deferred().resolveWith(context); - }).done(function() { + jQuery.Deferred().resolve().pipe( function() { + return jQuery.Deferred().resolveWith( context ); + } ).done( function() { assert.strictEqual( this, context, "custom context of returned deferred correctly propagated" ); done.pop().call(); - }); + } ); defer = jQuery.Deferred(); - piped = defer.pipe(function( value ) { + piped = defer.pipe( function( value ) { return value * 3; - }); + } ); defer.resolve( 2 ); - piped.done(function( value ) { + piped.done( function( value ) { assert.strictEqual( this, piped, "default context gets updated to latest promise in the chain" ); assert.strictEqual( value, 6, "proper value received" ); done.pop().call(); - }); + } ); defer2 = jQuery.Deferred(); piped2 = defer2.pipe(); defer2.resolve( 2 ); - piped2.done(function( value ) { + piped2.done( function( value ) { assert.strictEqual( this, piped2, "default context updated to latest promise in the chain (without passing function)" ); assert.strictEqual( value, 2, "proper value received (without passing function)" ); done.pop().call(); - }); -}); + } ); +} ); QUnit.asyncTest( "jQuery.Deferred.then - spec compatibility", function( assert ) { assert.expect( 1 ); - var defer = jQuery.Deferred().done(function() { + var defer = jQuery.Deferred().done( function() { setTimeout( start ); throw new Error(); - }); + } ); - defer.then(function() { + defer.then( function() { assert.ok( true, "errors in .done callbacks don't stop .then handlers" ); - }); + } ); try { defer.resolve(); } catch ( _ ) {} -}); +} ); QUnit.test( "jQuery.Deferred - 1.x/2.x compatibility", function( assert ) { @@ -534,46 +533,46 @@ QUnit.test( "jQuery.Deferred - 1.x/2.x compatibility", function( assert ) { thenable.unwrapped = false; - jQuery.Deferred().resolve( 1, 2 ).then(function() { + jQuery.Deferred().resolve( 1, 2 ).then( function() { assert.deepEqual( [].slice.call( arguments ), [ 1, 2 ], ".then fulfillment callbacks receive all resolution values" ); done.pop().call(); - }); + } ); jQuery.Deferred().reject( 1, 2 ).then( null, function() { assert.deepEqual( [].slice.call( arguments ), [ 1, 2 ], ".then rejection callbacks receive all rejection values" ); done.pop().call(); - }); + } ); jQuery.Deferred().notify( 1, 2 ).then( null, null, function() { assert.deepEqual( [].slice.call( arguments ), [ 1, 2 ], ".then progress callbacks receive all progress values" ); done.pop().call(); - }); + } ); - jQuery.Deferred().resolveWith( context ).then(function() { + jQuery.Deferred().resolveWith( context ).then( function() { assert.deepEqual( this, context, ".then fulfillment callbacks receive context" ); done.pop().call(); - }); + } ); jQuery.Deferred().rejectWith( context ).then( null, function() { assert.deepEqual( this, context, ".then rejection callbacks receive context" ); done.pop().call(); - }); + } ); jQuery.Deferred().notifyWith( context ).then( null, null, function() { assert.deepEqual( this, context, ".then progress callbacks receive context" ); done.pop().call(); - }); + } ); - jQuery.Deferred().resolve( thenable ).done(function( value ) { + jQuery.Deferred().resolve( thenable ).done( function( value ) { assert.strictEqual( value, thenable, ".done doesn't unwrap thenables" ); done.pop().call(); - }); + } ); jQuery.Deferred().notify( thenable ).then().then( null, null, function( value ) { assert.strictEqual( value, "thenable fulfillment", ".then implicit progress callbacks unwrap thenables" ); done.pop().call(); - }); -}); + } ); +} ); QUnit.test( "jQuery.Deferred.then - progress and thenables", function( assert ) { @@ -590,16 +589,16 @@ QUnit.test( "jQuery.Deferred.then - progress and thenables", function( assert ) trigger.then( null, null, function() { var notifier = jQuery.Deferred().notify( "foo" ); - setTimeout(function() { + setTimeout( function() { notifier.notify( "bar" ).resolve( "baz" ); - }); + } ); return notifier; - }).then( failer( "fulfill" ), failer( "reject" ), function( v ) { + } ).then( failer( "fulfill" ), failer( "reject" ), function( v ) { assert.strictEqual( v, expectedProgress.shift(), "expected progress value" ); done.pop().call(); - }); + } ); trigger.notify(); -}); +} ); QUnit.test( "jQuery.Deferred - notify and resolve", function( assert ) { @@ -643,18 +642,19 @@ 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(); } ); -}); +} ); QUnit.test( "jQuery.when", function( assert ) { assert.expect( 37 ); // Some other objects - jQuery.each({ + jQuery.each( { "an empty string": "", "a non-empty string": "some string", "zero": 0, @@ -669,21 +669,21 @@ QUnit.test( "jQuery.when", function( assert ) { }, function( message, value ) { assert.ok( jQuery.isFunction( - jQuery.when( value ).done(function( resolveValue ) { + jQuery.when( value ).done( function( resolveValue ) { assert.strictEqual( this, window, "Context is the global object with " + message ); assert.strictEqual( resolveValue, value, "Test the promise was resolved with " + message ); - }).promise + } ).promise ), "Test " + message + " triggers the creation of a new Promise" ); - }); + } ); assert.ok( jQuery.isFunction( - jQuery.when().done(function( resolveValue ) { + jQuery.when().done( function( resolveValue ) { assert.strictEqual( this, window, "Test the promise was resolved with window as its context" ); assert.strictEqual( resolveValue, undefined, "Test the promise was resolved with no parameter" ); - }).promise + } ).promise ), "Test calling when with no parameter triggers the creation of a new Promise" ); @@ -691,23 +691,23 @@ QUnit.test( "jQuery.when", function( assert ) { var cache, context = {}; - jQuery.when( jQuery.Deferred().resolveWith( context ) ).done(function() { + jQuery.when( jQuery.Deferred().resolveWith( context ) ).done( function() { assert.strictEqual( this, context, "when( promise ) propagates context" ); - }); + } ); - jQuery.each([ 1, 2, 3 ], function( k, i ) { + jQuery.each( [ 1, 2, 3 ], function( k, i ) { - jQuery.when( cache || jQuery.Deferred(function() { + jQuery.when( cache || jQuery.Deferred( function() { this.resolve( i ); - }) - ).done(function( value ) { + } ) + ).done( function( value ) { assert.strictEqual( value, 1, "Function executed" + ( i > 1 ? " only once" : "" ) ); cache = value; - }); + } ); - }); -}); + } ); +} ); QUnit.test( "jQuery.when - joined", function( assert ) { @@ -762,7 +762,7 @@ QUnit.test( "jQuery.when - joined", function( assert ) { context2 = defer2 && jQuery.isFunction( defer2.promise ) ? defer2.promise() : ( defer2.then ? window : undefined ); - jQuery.when( defer1, defer2 ).done(function( a, b ) { + jQuery.when( defer1, defer2 ).done( function( a, b ) { if ( shouldResolve ) { assert.deepEqual( [ a, b ], expected, code + " => resolve" ); assert.strictEqual( this[ 0 ], context1, code + " => first context OK" ); @@ -770,22 +770,22 @@ QUnit.test( "jQuery.when - joined", function( assert ) { } else { assert.ok( false, code + " => resolve" ); } - }).fail(function( a, b ) { + } ).fail( function( a, b ) { if ( shouldError ) { assert.deepEqual( [ a, b ], expected, code + " => reject" ); } else { assert.ok( false, code + " => reject" ); } - }).progress(function( a, b ) { + } ).progress( function( a, b ) { assert.deepEqual( [ a, b ], expectedNotify, code + " => progress" ); assert.strictEqual( this[ 0 ], expectedNotify[ 0 ] ? context1 : undefined, code + " => first context OK" ); assert.strictEqual( this[ 1 ], expectedNotify[ 1 ] ? context2 : undefined, code + " => second context OK" ); - }).always( restart ); - }); - }); + } ).always( restart ); + } ); + } ); deferreds.eventuallyFulfilled.resolve( 1 ); deferreds.eventuallyRejected.reject( 0 ); -}); +} ); QUnit.test( "jQuery.when - resolved", function( assert ) { @@ -795,18 +795,18 @@ QUnit.test( "jQuery.when - resolved", function( assert ) { b = jQuery.Deferred().notify( 2 ).resolve( 5 ), c = jQuery.Deferred().notify( 3 ).resolve( 6 ); - jQuery.when( a, b, c ).progress(function( a, b, c ) { + jQuery.when( a, b, c ).progress( function( a, b, c ) { assert.strictEqual( a, 1, "first notify value ok" ); assert.strictEqual( b, 2, "second notify value ok" ); assert.strictEqual( c, 3, "third notify value ok" ); - }).done(function( a, b, c ) { + } ).done( function( a, b, c ) { assert.strictEqual( a, 4, "first resolve value ok" ); assert.strictEqual( b, 5, "second resolve value ok" ); assert.strictEqual( c, 6, "third resolve value ok" ); - }).fail(function() { + } ).fail( function() { assert.ok( false, "Error on resolve" ); - }); -}); + } ); +} ); QUnit.test( "jQuery.when - filtering", function( assert ) { @@ -821,12 +821,12 @@ QUnit.test( "jQuery.when - filtering", function( assert ) { jQuery.when( jQuery.Deferred().resolve( 3 ).then( increment ), jQuery.Deferred().reject( 5 ).then( null, increment ) - ).done(function( four, six ) { + ).done( function( four, six ) { assert.strictEqual( four, 4, "resolved value incremented" ); assert.strictEqual( six, 6, "rejected value incremented" ); QUnit.start(); - }); -}); + } ); +} ); QUnit.test( "jQuery.when - exceptions", function( assert ) { @@ -838,14 +838,14 @@ QUnit.test( "jQuery.when - exceptions", function( assert ) { QUnit.stop(); - jQuery.Deferred().resolve().then( woops ).fail(function( doneException ) { + jQuery.Deferred().resolve().then( woops ).fail( function( doneException ) { assert.strictEqual( doneException, "exception thrown", "throwing in done handler" ); - jQuery.Deferred().reject().then( null, woops ).fail(function( failException ) { + jQuery.Deferred().reject().then( null, woops ).fail( function( failException ) { assert.strictEqual( failException, "exception thrown", "throwing in fail handler" ); QUnit.start(); - }); - }); -}); + } ); + } ); +} ); QUnit.test( "jQuery.when - chaining", function( assert ) { @@ -868,13 +868,13 @@ QUnit.test( "jQuery.when - chaining", function( assert ) { jQuery.Deferred().reject( 5 ).then( null, chain ), jQuery.Deferred().resolve( 3 ).then( chainStandard ), jQuery.Deferred().reject( 5 ).then( null, chainStandard ) - ).done(function( v1, v2, s1, s2 ) { + ).done( function( v1, v2, s1, s2 ) { assert.strictEqual( v1, "other deferred", "chaining in done handler" ); assert.strictEqual( v2, "other deferred", "chaining in fail handler" ); assert.strictEqual( s1, "std deferred", "chaining thenable in done handler" ); assert.strictEqual( s2, "std deferred", "chaining thenable in fail handler" ); QUnit.start(); - }); + } ); defer.resolve( "other deferred" ); -}); +} ); diff --git a/test/unit/deprecated.js b/test/unit/deprecated.js index 2a2357a52..52c137dc3 100644 --- a/test/unit/deprecated.js +++ b/test/unit/deprecated.js @@ -1,2 +1,2 @@ -QUnit.module("deprecated", { teardown: moduleTeardown }); +QUnit.module( "deprecated", { teardown: moduleTeardown } ); diff --git a/test/unit/dimensions.js b/test/unit/dimensions.js index 5b471094f..c2f08a0bd 100644 --- a/test/unit/dimensions.js +++ b/test/unit/dimensions.js @@ -1,10 +1,10 @@ -(function() { +( function() { if ( !jQuery.fn.width ) { return; } -QUnit.module("dimensions", { teardown: moduleTeardown }); +QUnit.module( "dimensions", { teardown: moduleTeardown } ); function pass( val ) { return val; @@ -29,111 +29,111 @@ function fn( val ) { */ function testWidth( val, assert ) { - assert.expect(9); + assert.expect( 9 ); var $div, blah; - $div = jQuery("#nothiddendiv"); - $div.width( val(30) ); - assert.equal($div.width(), 30, "Test set to 30 correctly"); + $div = jQuery( "#nothiddendiv" ); + $div.width( val( 30 ) ); + assert.equal( $div.width(), 30, "Test set to 30 correctly" ); $div.hide(); - assert.equal($div.width(), 30, "Test hidden div"); + assert.equal( $div.width(), 30, "Test hidden div" ); $div.show(); - $div.width( val(-1) ); // handle negative numbers by setting to 0 #11604 - assert.equal($div.width(), 0, "Test negative width normalized to 0"); - $div.css("padding", "20px"); - assert.equal($div.width(), 0, "Test padding specified with pixels"); - $div.css("border", "2px solid #fff"); - assert.equal($div.width(), 0, "Test border specified with pixels"); + $div.width( val( -1 ) ); // handle negative numbers by setting to 0 #11604 + assert.equal( $div.width(), 0, "Test negative width normalized to 0" ); + $div.css( "padding", "20px" ); + assert.equal( $div.width(), 0, "Test padding specified with pixels" ); + $div.css( "border", "2px solid #fff" ); + assert.equal( $div.width(), 0, "Test border specified with pixels" ); - $div.css({ "display": "", "border": "", "padding": "" }); + $div.css( { "display": "", "border": "", "padding": "" } ); - jQuery("#nothiddendivchild").css({ "width": 20, "padding": "3px", "border": "2px solid #fff" }); - assert.equal(jQuery("#nothiddendivchild").width(), 20, "Test child width with border and padding"); - jQuery("#nothiddendiv, #nothiddendivchild").css({ "border": "", "padding": "", "width": "" }); + jQuery( "#nothiddendivchild" ).css( { "width": 20, "padding": "3px", "border": "2px solid #fff" } ); + assert.equal( jQuery( "#nothiddendivchild" ).width(), 20, "Test child width with border and padding" ); + jQuery( "#nothiddendiv, #nothiddendivchild" ).css( { "border": "", "padding": "", "width": "" } ); - blah = jQuery("blah"); - assert.equal( blah.width( val(10) ), blah, "Make sure that setting a width on an empty set returns the set." ); - assert.equal( blah.width(), null, "Make sure 'null' is returned on an empty set"); + blah = jQuery( "blah" ); + assert.equal( blah.width( val( 10 ) ), blah, "Make sure that setting a width on an empty set returns the set." ); + assert.equal( blah.width(), null, "Make sure 'null' is returned on an empty set" ); - assert.equal( jQuery(window).width(), document.documentElement.clientWidth, "Window width is equal to width reported by window/document." ); + assert.equal( jQuery( window ).width(), document.documentElement.clientWidth, "Window width is equal to width reported by window/document." ); - QUnit.expectJqData( this, $div[0], "olddisplay" ); + QUnit.expectJqData( this, $div[ 0 ], "olddisplay" ); } -QUnit.test("width()", function( assert ) { +QUnit.test( "width()", function( assert ) { testWidth( pass, assert ); -}); +} ); -QUnit.test("width(Function)", function( assert ) { +QUnit.test( "width(Function)", function( assert ) { testWidth( fn, assert ); -}); +} ); -QUnit.test("width(Function(args))", function( assert ) { +QUnit.test( "width(Function(args))", function( assert ) { assert.expect( 2 ); - var $div = jQuery("#nothiddendiv"); - $div.width( 30 ).width(function(i, width) { + var $div = jQuery( "#nothiddendiv" ); + $div.width( 30 ).width( function( i, width ) { assert.equal( width, 30, "Make sure previous value is correct." ); return width + 1; - }); + } ); assert.equal( $div.width(), 31, "Make sure value was modified correctly." ); -}); +} ); function testHeight( val, assert ) { - assert.expect(9); + assert.expect( 9 ); var $div, blah; - $div = jQuery("#nothiddendiv"); - $div.height( val(30) ); - assert.equal($div.height(), 30, "Test set to 30 correctly"); + $div = jQuery( "#nothiddendiv" ); + $div.height( val( 30 ) ); + assert.equal( $div.height(), 30, "Test set to 30 correctly" ); $div.hide(); - assert.equal($div.height(), 30, "Test hidden div"); + assert.equal( $div.height(), 30, "Test hidden div" ); $div.show(); - $div.height( val(-1) ); // handle negative numbers by setting to 0 #11604 - assert.equal($div.height(), 0, "Test negative height normalized to 0"); - $div.css("padding", "20px"); - assert.equal($div.height(), 0, "Test padding specified with pixels"); - $div.css("border", "2px solid #fff"); - assert.equal($div.height(), 0, "Test border specified with pixels"); + $div.height( val( -1 ) ); // handle negative numbers by setting to 0 #11604 + assert.equal( $div.height(), 0, "Test negative height normalized to 0" ); + $div.css( "padding", "20px" ); + assert.equal( $div.height(), 0, "Test padding specified with pixels" ); + $div.css( "border", "2px solid #fff" ); + assert.equal( $div.height(), 0, "Test border specified with pixels" ); - $div.css({ "display": "", "border": "", "padding": "", "height": "1px" }); + $div.css( { "display": "", "border": "", "padding": "", "height": "1px" } ); - jQuery("#nothiddendivchild").css({ "height": 20, "padding": "3px", "border": "2px solid #fff" }); - assert.equal(jQuery("#nothiddendivchild").height(), 20, "Test child height with border and padding"); - jQuery("#nothiddendiv, #nothiddendivchild").css({ "border": "", "padding": "", "height": "" }); + jQuery( "#nothiddendivchild" ).css( { "height": 20, "padding": "3px", "border": "2px solid #fff" } ); + assert.equal( jQuery( "#nothiddendivchild" ).height(), 20, "Test child height with border and padding" ); + jQuery( "#nothiddendiv, #nothiddendivchild" ).css( { "border": "", "padding": "", "height": "" } ); - blah = jQuery("blah"); - assert.equal( blah.height( val(10) ), blah, "Make sure that setting a height on an empty set returns the set." ); - assert.equal( blah.height(), null, "Make sure 'null' is returned on an empty set"); + blah = jQuery( "blah" ); + assert.equal( blah.height( val( 10 ) ), blah, "Make sure that setting a height on an empty set returns the set." ); + assert.equal( blah.height(), null, "Make sure 'null' is returned on an empty set" ); - assert.equal( jQuery(window).height(), document.documentElement.clientHeight, "Window width is equal to width reported by window/document." ); + assert.equal( jQuery( window ).height(), document.documentElement.clientHeight, "Window width is equal to width reported by window/document." ); - QUnit.expectJqData( this, $div[0], "olddisplay" ); + QUnit.expectJqData( this, $div[ 0 ], "olddisplay" ); } -QUnit.test("height()", function( assert ) { +QUnit.test( "height()", function( assert ) { testHeight( pass, assert ); -}); +} ); -QUnit.test("height(Function)", function( assert ) { +QUnit.test( "height(Function)", function( assert ) { testHeight( fn, assert ); -}); +} ); -QUnit.test("height(Function(args))", function( assert ) { +QUnit.test( "height(Function(args))", function( assert ) { assert.expect( 2 ); - var $div = jQuery("#nothiddendiv"); - $div.height( 30 ).height(function(i, height) { + var $div = jQuery( "#nothiddendiv" ); + $div.height( 30 ).height( function( i, height ) { assert.equal( height, 30, "Make sure previous value is correct." ); return height + 1; - }); + } ); assert.equal( $div.height(), 31, "Make sure value was modified correctly." ); -}); +} ); -QUnit.test("innerWidth()", function( assert ) { +QUnit.test( "innerWidth()", function( assert ) { assert.expect( 6 ); var $div, div, @@ -144,11 +144,11 @@ QUnit.test("innerWidth()", function( assert ) { assert.equal( jQuery( document ).innerWidth(), $doc.width(), "Test on document" ); $div = jQuery( "#nothiddendiv" ); - $div.css({ + $div.css( { "margin": 10, "border": "2px solid #fff", "width": 30 - }); + } ); assert.equal( $div.innerWidth(), 30, "Test with margin and border" ); $div.css( "padding", "20px" ); @@ -157,7 +157,7 @@ QUnit.test("innerWidth()", function( assert ) { assert.equal( $div.innerWidth(), 70, "Test hidden div" ); // reset styles - $div.css({ "display": "", "border": "", "padding": "", "width": "", "height": "" }); + $div.css( { "display": "", "border": "", "padding": "", "width": "", "height": "" } ); div = jQuery( "<div>" ); @@ -166,9 +166,9 @@ QUnit.test("innerWidth()", function( assert ) { div.remove(); QUnit.expectJqData( this, $div[ 0 ], "olddisplay" ); -}); +} ); -QUnit.test("innerHeight()", function( assert ) { +QUnit.test( "innerHeight()", function( assert ) { assert.expect( 6 ); var $div, div, @@ -179,11 +179,11 @@ QUnit.test("innerHeight()", function( assert ) { assert.equal( jQuery( document ).innerHeight(), $doc.height(), "Test on document" ); $div = jQuery( "#nothiddendiv" ); - $div.css({ + $div.css( { "margin": 10, "border": "2px solid #fff", "height": 30 - }); + } ); assert.equal( $div.innerHeight(), 30, "Test with margin and border" ); $div.css( "padding", "20px" ); @@ -192,7 +192,7 @@ QUnit.test("innerHeight()", function( assert ) { assert.equal( $div.innerHeight(), 70, "Test hidden div" ); // reset styles - $div.css({ "display": "", "border": "", "padding": "", "width": "", "height": "" }); + $div.css( { "display": "", "border": "", "padding": "", "width": "", "height": "" } ); div = jQuery( "<div>" ); @@ -201,9 +201,9 @@ QUnit.test("innerHeight()", function( assert ) { div.remove(); QUnit.expectJqData( this, $div[ 0 ], "olddisplay" ); -}); +} ); -QUnit.test("outerWidth()", function( assert ) { +QUnit.test( "outerWidth()", function( assert ) { assert.expect( 11 ); var $div, div, @@ -231,7 +231,7 @@ QUnit.test("outerWidth()", function( assert ) { assert.equal( $div.outerWidth( true ), 94, "Test hidden div with padding, border and margin with margin option" ); // reset styles - $div.css({ "position": "", "display": "", "border": "", "padding": "", "width": "", "height": "" }); + $div.css( { "position": "", "display": "", "border": "", "padding": "", "width": "", "height": "" } ); div = jQuery( "<div>" ); @@ -240,23 +240,23 @@ QUnit.test("outerWidth()", function( assert ) { div.remove(); QUnit.expectJqData( this, $div[ 0 ], "olddisplay" ); -}); +} ); -QUnit.test("child of a hidden elem (or unconnected node) has accurate inner/outer/Width()/Height() see #9441 #9300", function( assert ) { - assert.expect(16); +QUnit.test( "child of a hidden elem (or unconnected node) has accurate inner/outer/Width()/Height() see #9441 #9300", function( assert ) { + assert.expect( 16 ); // setup html - var $divNormal = jQuery("<div>").css({ "width": "100px", "height": "100px", "border": "10px solid white", "padding": "2px", "margin": "3px" }), + var $divNormal = jQuery( "<div>" ).css( { "width": "100px", "height": "100px", "border": "10px solid white", "padding": "2px", "margin": "3px" } ), $divChild = $divNormal.clone(), $divUnconnected = $divNormal.clone(), - $divHiddenParent = jQuery("<div>").css( "display", "none" ).append( $divChild ).appendTo("body"); - $divNormal.appendTo("body"); + $divHiddenParent = jQuery( "<div>" ).css( "display", "none" ).append( $divChild ).appendTo( "body" ); + $divNormal.appendTo( "body" ); // tests that child div of a hidden div works the same as a normal div assert.equal( $divChild.width(), $divNormal.width(), "child of a hidden element width() is wrong see #9441" ); assert.equal( $divChild.innerWidth(), $divNormal.innerWidth(), "child of a hidden element innerWidth() is wrong see #9441" ); assert.equal( $divChild.outerWidth(), $divNormal.outerWidth(), "child of a hidden element outerWidth() is wrong see #9441" ); - assert.equal( $divChild.outerWidth(true), $divNormal.outerWidth( true ), "child of a hidden element outerWidth( true ) is wrong see #9300" ); + assert.equal( $divChild.outerWidth( true ), $divNormal.outerWidth( true ), "child of a hidden element outerWidth( true ) is wrong see #9300" ); // Support: IE 10-11, Edge // Child height is not always decimal @@ -269,7 +269,7 @@ QUnit.test("child of a hidden elem (or unconnected node) has accurate inner/oute assert.equal( $divUnconnected.width(), $divNormal.width(), "unconnected element width() is wrong see #9441" ); assert.equal( $divUnconnected.innerWidth(), $divNormal.innerWidth(), "unconnected element innerWidth() is wrong see #9441" ); assert.equal( $divUnconnected.outerWidth(), $divNormal.outerWidth(), "unconnected element outerWidth() is wrong see #9441" ); - assert.equal( $divUnconnected.outerWidth(true), $divNormal.outerWidth( true ), "unconnected element outerWidth( true ) is wrong see #9300" ); + assert.equal( $divUnconnected.outerWidth( true ), $divNormal.outerWidth( true ), "unconnected element outerWidth( true ) is wrong see #9300" ); // Support: IE 10-11, Edge // Child height is not always decimal @@ -281,9 +281,9 @@ QUnit.test("child of a hidden elem (or unconnected node) has accurate inner/oute // teardown html $divHiddenParent.remove(); $divNormal.remove(); -}); +} ); -QUnit.test("getting dimensions shouldn't modify runtimeStyle see #9233", function( assert ) { +QUnit.test( "getting dimensions shouldn't modify runtimeStyle see #9233", function( assert ) { assert.expect( 1 ); var $div = jQuery( "<div>" ).appendTo( "#qunit-fixture" ), @@ -304,36 +304,36 @@ QUnit.test("getting dimensions shouldn't modify runtimeStyle see #9233", functio } $div.remove(); -}); +} ); QUnit.test( "table dimensions", function( assert ) { assert.expect( 2 ); - var table = jQuery("<table><colgroup><col/><col/></colgroup><tbody><tr><td></td><td>a</td></tr><tr><td></td><td>a</td></tr></tbody></table>").appendTo("#qunit-fixture"), - tdElem = table.find("td").first(), - colElem = table.find("col").first().width( 300 ); + var table = jQuery( "<table><colgroup><col/><col/></colgroup><tbody><tr><td></td><td>a</td></tr><tr><td></td><td>a</td></tr></tbody></table>" ).appendTo( "#qunit-fixture" ), + tdElem = table.find( "td" ).first(), + colElem = table.find( "col" ).first().width( 300 ); - table.find("td").css({ "margin": 0, "padding": 0 }); + table.find( "td" ).css( { "margin": 0, "padding": 0 } ); assert.equal( tdElem.width(), tdElem.width(), "width() doesn't alter dimension values of empty cells, see #11293" ); assert.equal( colElem.width(), 300, "col elements have width(), see #12243" ); -}); +} ); -QUnit.test("box-sizing:border-box child of a hidden elem (or unconnected node) has accurate inner/outer/Width()/Height() see #10413", function( assert ) { - assert.expect(16); +QUnit.test( "box-sizing:border-box child of a hidden elem (or unconnected node) has accurate inner/outer/Width()/Height() see #10413", function( assert ) { + assert.expect( 16 ); // setup html - var $divNormal = jQuery("<div>").css({ "boxSizing": "border-box", "width": "100px", "height": "100px", "border": "10px solid white", "padding": "2px", "margin": "3px" }), + var $divNormal = jQuery( "<div>" ).css( { "boxSizing": "border-box", "width": "100px", "height": "100px", "border": "10px solid white", "padding": "2px", "margin": "3px" } ), $divChild = $divNormal.clone(), $divUnconnected = $divNormal.clone(), - $divHiddenParent = jQuery("<div>").css( "display", "none" ).append( $divChild ).appendTo("body"); - $divNormal.appendTo("body"); + $divHiddenParent = jQuery( "<div>" ).css( "display", "none" ).append( $divChild ).appendTo( "body" ); + $divNormal.appendTo( "body" ); // tests that child div of a hidden div works the same as a normal div assert.equal( $divChild.width(), $divNormal.width(), "child of a hidden element width() is wrong see #10413" ); assert.equal( $divChild.innerWidth(), $divNormal.innerWidth(), "child of a hidden element innerWidth() is wrong see #10413" ); assert.equal( $divChild.outerWidth(), $divNormal.outerWidth(), "child of a hidden element outerWidth() is wrong see #10413" ); - assert.equal( $divChild.outerWidth(true), $divNormal.outerWidth( true ), "child of a hidden element outerWidth( true ) is wrong see #10413" ); + assert.equal( $divChild.outerWidth( true ), $divNormal.outerWidth( true ), "child of a hidden element outerWidth( true ) is wrong see #10413" ); // Support: IE 10-11, Edge // Child height is not always decimal @@ -346,7 +346,7 @@ QUnit.test("box-sizing:border-box child of a hidden elem (or unconnected node) h assert.equal( $divUnconnected.width(), $divNormal.width(), "unconnected element width() is wrong see #10413" ); assert.equal( $divUnconnected.innerWidth(), $divNormal.innerWidth(), "unconnected element innerWidth() is wrong see #10413" ); assert.equal( $divUnconnected.outerWidth(), $divNormal.outerWidth(), "unconnected element outerWidth() is wrong see #10413" ); - assert.equal( $divUnconnected.outerWidth(true), $divNormal.outerWidth( true ), "unconnected element outerWidth( true ) is wrong see #10413" ); + assert.equal( $divUnconnected.outerWidth( true ), $divNormal.outerWidth( true ), "unconnected element outerWidth( true ) is wrong see #10413" ); // Support: IE 10-11, Edge // Child height is not always decimal @@ -358,9 +358,9 @@ QUnit.test("box-sizing:border-box child of a hidden elem (or unconnected node) h // teardown html $divHiddenParent.remove(); $divNormal.remove(); -}); +} ); -QUnit.test("outerHeight()", function( assert ) { +QUnit.test( "outerHeight()", function( assert ) { assert.expect( 11 ); var $div, div, @@ -387,7 +387,7 @@ QUnit.test("outerHeight()", function( assert ) { assert.equal( $div.outerHeight( true ), 94, "Test hidden div with padding, border and margin with margin option" ); // reset styles - $div.css({ "display": "", "border": "", "padding": "", "width": "", "height": "" }); + $div.css( { "display": "", "border": "", "padding": "", "width": "", "height": "" } ); div = jQuery( "<div>" ); @@ -396,20 +396,20 @@ QUnit.test("outerHeight()", function( assert ) { div.remove(); QUnit.expectJqData( this, $div[ 0 ], "olddisplay" ); -}); +} ); -QUnit.test("passing undefined is a setter #5571", function( assert ) { - assert.expect(4); - assert.equal(jQuery("#nothiddendiv").height(30).height(undefined).height(), 30, ".height(undefined) is chainable (#5571)"); - assert.equal(jQuery("#nothiddendiv").height(30).innerHeight(undefined).height(), 30, ".innerHeight(undefined) is chainable (#5571)"); - assert.equal(jQuery("#nothiddendiv").height(30).outerHeight(undefined).height(), 30, ".outerHeight(undefined) is chainable (#5571)"); - assert.equal(jQuery("#nothiddendiv").width(30).width(undefined).width(), 30, ".width(undefined) is chainable (#5571)"); -}); +QUnit.test( "passing undefined is a setter #5571", function( assert ) { + assert.expect( 4 ); + assert.equal( jQuery( "#nothiddendiv" ).height( 30 ).height( undefined ).height(), 30, ".height(undefined) is chainable (#5571)" ); + assert.equal( jQuery( "#nothiddendiv" ).height( 30 ).innerHeight( undefined ).height(), 30, ".innerHeight(undefined) is chainable (#5571)" ); + assert.equal( jQuery( "#nothiddendiv" ).height( 30 ).outerHeight( undefined ).height(), 30, ".outerHeight(undefined) is chainable (#5571)" ); + assert.equal( jQuery( "#nothiddendiv" ).width( 30 ).width( undefined ).width(), 30, ".width(undefined) is chainable (#5571)" ); +} ); QUnit.test( "getters on non elements should return null", function( assert ) { assert.expect( 8 ); - var nonElem = jQuery("notAnElement"); + var nonElem = jQuery( "notAnElement" ); assert.strictEqual( nonElem.width(), null, ".width() is not null (#12283)" ); assert.strictEqual( nonElem.innerWidth(), null, ".innerWidth() is not null (#12283)" ); @@ -420,14 +420,14 @@ QUnit.test( "getters on non elements should return null", function( assert ) { assert.strictEqual( nonElem.innerHeight(), null, ".innerHeight() is not null (#12283)" ); assert.strictEqual( nonElem.outerHeight(), null, ".outerHeight() is not null (#12283)" ); assert.strictEqual( nonElem.outerHeight( true ), null, ".outerHeight(true) is not null (#12283)" ); -}); +} ); -QUnit.test("setters with and without box-sizing:border-box", function( assert ){ - assert.expect(20); +QUnit.test( "setters with and without box-sizing:border-box", function( assert ) { + assert.expect( 20 ); // Support: Android 2.3 (-webkit-box-sizing). - var el_bb = jQuery("<div style='width:114px;height:114px;margin:5px;padding:3px;border:4px solid white;-webkit-box-sizing:border-box;box-sizing:border-box;'>test</div>").appendTo("#qunit-fixture"), - el = jQuery("<div style='width:100px;height:100px;margin:5px;padding:3px;border:4px solid white;'>test</div>").appendTo("#qunit-fixture"), + var el_bb = jQuery( "<div style='width:114px;height:114px;margin:5px;padding:3px;border:4px solid white;-webkit-box-sizing:border-box;box-sizing:border-box;'>test</div>" ).appendTo( "#qunit-fixture" ), + el = jQuery( "<div style='width:100px;height:100px;margin:5px;padding:3px;border:4px solid white;'>test</div>" ).appendTo( "#qunit-fixture" ), expected = 100; assert.equal( el_bb.width( 101 ).width(), expected + 1, "test border-box width(int) by roundtripping" ); @@ -453,13 +453,13 @@ QUnit.test("setters with and without box-sizing:border-box", function( assert ){ assert.equal( el.outerHeight( 117 ).height(), expected + 3, "test border-box outerHeight(int) by roundtripping" ); assert.equal( el.outerHeight( 118, false ).height(), expected + 4, "test border-box outerHeight(int, false) by roundtripping" ); assert.equal( el.outerHeight( 129, true ).height(), expected + 5, "test border-box innerHeight(int, true) by roundtripping" ); -}); +} ); testIframe( "dimensions/documentLarge", "window vs. large document", function( jQuery, window, document, assert ) { - assert.expect(2); + assert.expect( 2 ); assert.ok( jQuery( document ).height() > jQuery( window ).height(), "document height is larger than window height" ); assert.ok( jQuery( document ).width() > jQuery( window ).width(), "document width is larger than window width" ); @@ -472,15 +472,15 @@ QUnit.test( "allow modification of coordinates argument (gh-1848)", function( as var offsetTop, element = jQuery( "<div/>" ).appendTo( "#qunit-fixture" ); - element.offset(function( index, coords ) { + element.offset( function( index, coords ) { coords.top = 100; return coords; - }); + } ); offsetTop = element.offset().top; - assert.ok( Math.abs(offsetTop - 100) < 0.02, - "coordinates are modified (got offset.top: " + offsetTop + ")"); -}); + assert.ok( Math.abs( offsetTop - 100 ) < 0.02, + "coordinates are modified (got offset.top: " + offsetTop + ")" ); +} ); -})(); +} )(); diff --git a/test/unit/effects.js b/test/unit/effects.js index 934b3e193..755b074f8 100644 --- a/test/unit/effects.js +++ b/test/unit/effects.js @@ -1,4 +1,4 @@ -(function() { +( function() { // Can't test what ain't there if ( !jQuery.fx ) { @@ -7,7 +7,7 @@ if ( !jQuery.fx ) { var oldRaf = window.requestAnimationFrame; -QUnit.module("effects", { +QUnit.module( "effects", { setup: function() { window.requestAnimationFrame = null; this.sandbox = sinon.sandbox.create(); @@ -25,44 +25,44 @@ QUnit.module("effects", { window.requestAnimationFrame = oldRaf; return moduleTeardown.apply( this, arguments ); } -}); +} ); -QUnit.test("sanity check", function( assert ) { - assert.expect(1); - assert.equal( jQuery("#dl:visible, #qunit-fixture:visible, #foo:visible").length, 3, "QUnit state is correct for testing effects" ); -}); +QUnit.test( "sanity check", function( assert ) { + assert.expect( 1 ); + assert.equal( jQuery( "#dl:visible, #qunit-fixture:visible, #foo:visible" ).length, 3, "QUnit state is correct for testing effects" ); +} ); -QUnit.test("show() basic", function( assert ) { +QUnit.test( "show() basic", function( assert ) { assert.expect( 1 ); - var div = jQuery("<div>").hide().appendTo("#qunit-fixture").show(); + var div = jQuery( "<div>" ).hide().appendTo( "#qunit-fixture" ).show(); - assert.equal( div.css("display"), "block", "Make sure pre-hidden divs show" ); + assert.equal( div.css( "display" ), "block", "Make sure pre-hidden divs show" ); // Clean up the detached node div.remove(); -}); +} ); -QUnit.test("show()", function( assert ) { +QUnit.test( "show()", function( assert ) { assert.expect( 27 ); var div, speeds, old, test, - hiddendiv = jQuery("div.hidden"); + hiddendiv = jQuery( "div.hidden" ); - assert.equal(jQuery.css( hiddendiv[0], "display"), "none", "hiddendiv is display: none"); + assert.equal( jQuery.css( hiddendiv[ 0 ], "display" ), "none", "hiddendiv is display: none" ); - hiddendiv.css("display", "block"); - assert.equal(jQuery.css( hiddendiv[0], "display"), "block", "hiddendiv is display: block"); + hiddendiv.css( "display", "block" ); + assert.equal( jQuery.css( hiddendiv[ 0 ], "display" ), "block", "hiddendiv is display: block" ); hiddendiv.show(); - assert.equal(jQuery.css( hiddendiv[0], "display"), "block", "hiddendiv is display: block"); + assert.equal( jQuery.css( hiddendiv[ 0 ], "display" ), "block", "hiddendiv is display: block" ); - hiddendiv.css("display",""); + hiddendiv.css( "display", "" ); - div = jQuery("#fx-queue div").slice(0, 4); - div.show().each(function() { - assert.notEqual(this.style.display, "none", "don't change any <div> with display block"); - }); + div = jQuery( "#fx-queue div" ).slice( 0, 4 ); + div.show().each( function() { + assert.notEqual( this.style.display, "none", "don't change any <div> with display block" ); + } ); speeds = { "null speed": null, @@ -70,23 +70,23 @@ QUnit.test("show()", function( assert ) { "false speed": false }; - jQuery.each(speeds, function(name, speed) { + jQuery.each( speeds, function( name, speed ) { var pass = true; - div.hide().show(speed).each(function() { + div.hide().show( speed ).each( function() { if ( this.style.display === "none" ) { pass = false; } - }); - assert.ok( pass, "Show with " + name); - }); + } ); + assert.ok( pass, "Show with " + name ); + } ); - jQuery.each(speeds, function(name, speed) { + jQuery.each( speeds, function( name, speed ) { var pass = true; - div.hide().show(speed, function() { + div.hide().show( speed, function() { pass = false; - }); + } ); assert.ok( pass, "Show with " + name + " does not call animate callback" ); - }); + } ); // Tolerate data from show()/hide() QUnit.expectJqData( this, div, "olddisplay" ); @@ -99,40 +99,40 @@ QUnit.test("show()", function( assert ) { "<table id='test-table'></table>" ).appendTo( "#qunit-fixture" ).find( "*" ).css( "display", "none" ); - old = jQuery("#test-table").show().css("display") !== "table"; - jQuery("#test-table").remove(); + old = jQuery( "#test-table" ).show().css( "display" ) !== "table"; + jQuery( "#test-table" ).remove(); test = { - "div" : "block", - "p" : "block", - "a" : "inline", - "code" : "inline", - "pre" : "block", - "span" : "inline", - "table" : old ? "block" : "table", - "thead" : old ? "block" : "table-header-group", - "tbody" : old ? "block" : "table-row-group", - "tr" : old ? "block" : "table-row", - "th" : old ? "block" : "table-cell", - "td" : old ? "block" : "table-cell", - "ul" : "block", - "li" : old ? "block" : "list-item" + "div": "block", + "p": "block", + "a": "inline", + "code": "inline", + "pre": "block", + "span": "inline", + "table": old ? "block" : "table", + "thead": old ? "block" : "table-header-group", + "tbody": old ? "block" : "table-row-group", + "tr": old ? "block" : "table-row", + "th": old ? "block" : "table-cell", + "td": old ? "block" : "table-cell", + "ul": "block", + "li": old ? "block" : "list-item" }; - jQuery.each(test, function(selector, expected) { - var elem = jQuery(selector, "#show-tests").show(); - assert.equal( elem.css("display"), expected, "Show using correct display type for " + selector ); - }); + jQuery.each( test, function( selector, expected ) { + var elem = jQuery( selector, "#show-tests" ).show(); + assert.equal( elem.css( "display" ), expected, "Show using correct display type for " + selector ); + } ); - jQuery("#show-tests").remove(); + jQuery( "#show-tests" ).remove(); // Make sure that showing or hiding a text node doesn't cause an error - jQuery("<div>test</div> text <span>test</span>").show().remove(); - jQuery("<div>test</div> text <span>test</span>").hide().remove(); -}); + jQuery( "<div>test</div> text <span>test</span>" ).show().remove(); + jQuery( "<div>test</div> text <span>test</span>" ).hide().remove(); +} ); -QUnit.test("show(Number) - other displays", function( assert ) { - assert.expect(30); +QUnit.test( "show(Number) - other displays", function( assert ) { + assert.expect( 30 ); jQuery( "<div id='show-tests'>" + @@ -143,105 +143,105 @@ QUnit.test("show(Number) - other displays", function( assert ) { ).appendTo( "#qunit-fixture" ).find( "*" ).css( "display", "none" ); var test, - old = jQuery("#test-table").show().css("display") !== "table"; + old = jQuery( "#test-table" ).show().css( "display" ) !== "table"; - jQuery("#test-table").remove(); + jQuery( "#test-table" ).remove(); // Note: inline elements are expected to be inline-block // because we're showing width/height // Can't animate width/height inline // See #14344 test = { - "div" : "block", - "p" : "block", - "a" : "inline", - "code" : "inline", - "pre" : "block", - "span" : "inline", - "table" : old ? "block" : "table", - "thead" : old ? "block" : "table-header-group", - "tbody" : old ? "block" : "table-row-group", - "tr" : old ? "block" : "table-row", - "th" : old ? "block" : "table-cell", - "td" : old ? "block" : "table-cell", - "ul" : "block", - "li" : old ? "block" : "list-item" + "div": "block", + "p": "block", + "a": "inline", + "code": "inline", + "pre": "block", + "span": "inline", + "table": old ? "block" : "table", + "thead": old ? "block" : "table-header-group", + "tbody": old ? "block" : "table-row-group", + "tr": old ? "block" : "table-row", + "th": old ? "block" : "table-cell", + "td": old ? "block" : "table-cell", + "ul": "block", + "li": old ? "block" : "list-item" }; jQuery.each( test, function( selector ) { jQuery( selector, "#show-tests" ).show( 100 ); - }); + } ); this.clock.tick( 50 ); jQuery.each( test, function( selector, expected ) { - jQuery( selector, "#show-tests" ).each(function() { + jQuery( selector, "#show-tests" ).each( function() { assert.equal( jQuery( this ).css( "display" ), expected === "inline" ? "inline-block" : expected, "Correct display type during animation for " + selector ); - }); - }); + } ); + } ); this.clock.tick( 50 ); jQuery.each( test, function( selector, expected ) { - jQuery( selector, "#show-tests" ).each(function() { + jQuery( selector, "#show-tests" ).each( function() { assert.equal( jQuery( this ).css( "display" ), expected, "Correct display type after animation for " + selector ); - }); - }); + } ); + } ); - jQuery("#show-tests").remove(); -}); + jQuery( "#show-tests" ).remove(); +} ); // Supports #7397 -QUnit.test("Persist correct display value", function( assert ) { - assert.expect(3); +QUnit.test( "Persist correct display value", function( assert ) { + assert.expect( 3 ); jQuery( "<div id='show-tests'><span style='position:absolute;'>foo</span></div>" ) .appendTo( "#qunit-fixture" ).find( "*" ).css( "display", "none" ); - var $span = jQuery("#show-tests span"), - displayNone = $span.css("display"), + var $span = jQuery( "#show-tests span" ), + displayNone = $span.css( "display" ), display = "", clock = this.clock; $span.show(); - display = $span.css("display"); + display = $span.css( "display" ); $span.hide(); - $span.fadeIn(100, function() { - assert.equal($span.css("display"), display, "Expecting display: " + display); - $span.fadeOut(100, function () { - assert.equal($span.css("display"), displayNone, "Expecting display: " + displayNone); - $span.fadeIn(100, function() { - assert.equal($span.css("display"), display, "Expecting display: " + display); - }); - }); - }); + $span.fadeIn( 100, function() { + assert.equal( $span.css( "display" ), display, "Expecting display: " + display ); + $span.fadeOut( 100, function() { + assert.equal( $span.css( "display" ), displayNone, "Expecting display: " + displayNone ); + $span.fadeIn( 100, function() { + assert.equal( $span.css( "display" ), display, "Expecting display: " + display ); + } ); + } ); + } ); clock.tick( 300 ); QUnit.expectJqData( this, $span, "olddisplay" ); -}); +} ); -QUnit.test("animate(Hash, Object, Function)", function( assert ) { - assert.expect(1); - var hash = {opacity: "show"}, - hashCopy = jQuery.extend({}, hash); - jQuery("#foo").animate(hash, 0, function() { +QUnit.test( "animate(Hash, Object, Function)", function( assert ) { + assert.expect( 1 ); + var hash = { opacity: "show" }, + hashCopy = jQuery.extend( {}, hash ); + jQuery( "#foo" ).animate( hash, 0, function() { assert.equal( hash.opacity, hashCopy.opacity, "Check if animate changed the hash parameter" ); - }); -}); + } ); +} ); -QUnit.test("animate relative values", function( assert ) { +QUnit.test( "animate relative values", function( assert ) { var value = 40, clock = this.clock, bases = [ "%", "px", "em" ], adjustments = [ "px", "em" ], - container = jQuery("<div></div>") - .css({ position: "absolute", height: "50em", width: "50em" }), + container = jQuery( "<div></div>" ) + .css( { position: "absolute", height: "50em", width: "50em" } ), animations = bases.length * adjustments.length; assert.expect( 2 * animations ); @@ -250,13 +250,13 @@ QUnit.test("animate relative values", function( assert ) { jQuery.each( adjustments, function( _, adjustUnit ) { var base = value + baseUnit, adjust = { height: "+=2" + adjustUnit, width: "-=2" + adjustUnit }, - elem = jQuery("<div></div>") - .appendTo( container.clone().appendTo("#qunit-fixture") ) - .css({ + elem = jQuery( "<div></div>" ) + .appendTo( container.clone().appendTo( "#qunit-fixture" ) ) + .css( { position: "absolute", height: base, width: value + adjustUnit - }), + } ), baseScale = elem[ 0 ].offsetHeight / value, adjustScale = elem[ 0 ].offsetWidth / value; @@ -266,80 +266,79 @@ QUnit.test("animate relative values", function( assert ) { assert.equal( this.offsetWidth, value * baseScale - 2 * adjustScale, baseUnit + "-=" + adjustUnit ); - }); + } ); clock.tick( 100 ); - }); - }); -}); + } ); + } ); +} ); -QUnit.test("animate negative height", function( assert ) { - assert.expect(1); - jQuery("#foo").animate({ height: -100 }, 100, function() { +QUnit.test( "animate negative height", function( assert ) { + assert.expect( 1 ); + jQuery( "#foo" ).animate( { height: -100 }, 100, function() { assert.equal( this.offsetHeight, 0, "Verify height." ); - }); + } ); this.clock.tick( 100 ); -}); +} ); -QUnit.test("animate negative margin", function( assert ) { - assert.expect(1); - jQuery("#foo").animate({ "marginTop": -100 }, 100, function() { - assert.equal( jQuery(this).css("marginTop"), "-100px", "Verify margin." ); - }); +QUnit.test( "animate negative margin", function( assert ) { + assert.expect( 1 ); + jQuery( "#foo" ).animate( { "marginTop": -100 }, 100, function() { + assert.equal( jQuery( this ).css( "marginTop" ), "-100px", "Verify margin." ); + } ); this.clock.tick( 100 ); -}); +} ); -QUnit.test("animate negative margin with px", function( assert ) { - assert.expect(1); - jQuery("#foo").animate({ marginTop: "-100px" }, 100, function() { - assert.equal( jQuery(this).css("marginTop"), "-100px", "Verify margin." ); - }); +QUnit.test( "animate negative margin with px", function( assert ) { + assert.expect( 1 ); + jQuery( "#foo" ).animate( { marginTop: "-100px" }, 100, function() { + assert.equal( jQuery( this ).css( "marginTop" ), "-100px", "Verify margin." ); + } ); this.clock.tick( 100 ); -}); +} ); -QUnit.test("animate negative padding", function( assert ) { - assert.expect(1); - jQuery("#foo").animate({ "paddingBottom": -100 }, 100, function() { - assert.equal( jQuery(this).css("paddingBottom"), "0px", "Verify paddingBottom." ); - }); +QUnit.test( "animate negative padding", function( assert ) { + assert.expect( 1 ); + jQuery( "#foo" ).animate( { "paddingBottom": -100 }, 100, function() { + assert.equal( jQuery( this ).css( "paddingBottom" ), "0px", "Verify paddingBottom." ); + } ); this.clock.tick( 100 ); -}); - -QUnit.test("animate block as inline width/height", function( assert ) { - assert.expect(3); +} ); +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" ); + 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" ); assert.equal( this.offsetHeight, 42, "height was animated" ); - }); + } ); this.clock.tick( 100 ); -}); +} ); -QUnit.test("animate native inline width/height", function( assert ) { - assert.expect(3); +QUnit.test( "animate native inline width/height", function( assert ) { + assert.expect( 3 ); - jQuery("#foo").css({ display: "", width: "", height: "" }) - .append("<span>text</span>") - .children("span") - .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" ); + jQuery( "#foo" ).css( { display: "", width: "", height: "" } ) + .append( "<span>text</span>" ) + .children( "span" ) + .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" ); assert.equal( this.offsetHeight, 42, "height was animated" ); - }); + } ); this.clock.tick( 100 ); -}); +} ); QUnit.test( "animate block width/height", function( assert ) { assert.expect( 3 ); - jQuery("<div>").appendTo("#qunit-fixture").css({ + jQuery( "<div>" ).appendTo( "#qunit-fixture" ).css( { display: "block", width: 20, height: 20, paddingLeft: 60 - }).animate({ + } ).animate( { width: 42, height: 42 }, { @@ -350,80 +349,80 @@ QUnit.test( "animate block width/height", function( assert ) { } }, complete: function() { - assert.equal( jQuery( this ).css("display"), "block", "inline-block was not set on block element when animating width/height" ); + assert.equal( jQuery( this ).css( "display" ), "block", "inline-block was not set on block element when animating width/height" ); assert.equal( jQuery( this ).width(), 42, "width was animated" ); assert.equal( jQuery( this ).height(), 42, "height was animated" ); } - }); + } ); this.clock.tick( 100 ); -}); +} ); -QUnit.test("animate table width/height", function( assert ) { - assert.expect(1); +QUnit.test( "animate table width/height", function( assert ) { + assert.expect( 1 ); - var displayMode = jQuery("#table").css("display") !== "table" ? "block" : "table"; + var displayMode = jQuery( "#table" ).css( "display" ) !== "table" ? "block" : "table"; - jQuery("#table").animate({ width: 42, height: 42 }, 100, function() { - assert.equal( jQuery(this).css("display"), displayMode, "display mode is correct" ); - }); + jQuery( "#table" ).animate( { width: 42, height: 42 }, 100, function() { + assert.equal( jQuery( this ).css( "display" ), displayMode, "display mode is correct" ); + } ); this.clock.tick( 100 ); -}); +} ); -QUnit.test("animate table-row width/height", function( assert ) { - assert.expect(3); +QUnit.test( "animate table-row width/height", function( assert ) { + assert.expect( 3 ); var tr = jQuery( "#table" ) - .attr({ "cellspacing": 0, "cellpadding": 0, "border": 0 }) + .attr( { "cellspacing": 0, "cellpadding": 0, "border": 0 } ) .html( "<tr style='height:42px;'><td style='padding:0;'><div style='width:20px;height:20px;'></div></td></tr>" ) .find( "tr" ); - tr.animate({ width: 10, height: 10 }, 100, function() { + tr.animate( { width: 10, height: 10 }, 100, function() { assert.equal( jQuery( this ).css( "display" ), "table-row", "display mode is correct" ); assert.equal( this.offsetWidth, 20, "width animated to shrink wrap point" ); assert.equal( this.offsetHeight, 20, "height animated to shrink wrap point" ); - }); + } ); this.clock.tick( 100 ); -}); +} ); -QUnit.test("animate table-cell width/height", function( assert ) { - assert.expect(3); +QUnit.test( "animate table-cell width/height", function( assert ) { + assert.expect( 3 ); var td = jQuery( "#table" ) - .attr({ "cellspacing": 0, "cellpadding": 0, "border": 0 }) + .attr( { "cellspacing": 0, "cellpadding": 0, "border": 0 } ) .html( "<tr><td style='width:42px;height:42px;padding:0;'><div style='width:20px;height:20px;'></div></td></tr>" ) .find( "td" ); - td.animate({ width: 10, height: 10 }, 100, function() { + td.animate( { width: 10, height: 10 }, 100, function() { assert.equal( jQuery( this ).css( "display" ), "table-cell", "display mode is correct" ); assert.equal( this.offsetWidth, 20, "width animated to shrink wrap point" ); assert.equal( this.offsetHeight, 20, "height animated to shrink wrap point" ); - }); + } ); this.clock.tick( 100 ); -}); +} ); -QUnit.test("animate percentage(%) on width/height", function( assert ) { +QUnit.test( "animate percentage(%) on width/height", function( assert ) { assert.expect( 2 ); - var $div = jQuery("<div style='position:absolute;top:-999px;left:-999px;width:60px;height:60px;'><div style='width:50%;height:50%;'></div></div>") - .appendTo("#qunit-fixture").children("div"); + var $div = jQuery( "<div style='position:absolute;top:-999px;left:-999px;width:60px;height:60px;'><div style='width:50%;height:50%;'></div></div>" ) + .appendTo( "#qunit-fixture" ).children( "div" ); - $div.animate({ width: "25%", height: "25%" }, 13, function() { - var $this = jQuery(this); - assert.equal( $this.css("width"), "15px", "Width was animated to 15px rather than 25px"); - assert.equal( $this.css("height"), "15px", "Height was animated to 15px rather than 25px"); - }); + $div.animate( { width: "25%", height: "25%" }, 13, function() { + var $this = jQuery( this ); + assert.equal( $this.css( "width" ), "15px", "Width was animated to 15px rather than 25px" ); + assert.equal( $this.css( "height" ), "15px", "Height was animated to 15px rather than 25px" ); + } ); this.clock.tick( 20 ); -}); +} ); -QUnit.test("animate resets overflow-x and overflow-y when finished", function( assert ) { - assert.expect(2); - jQuery("#foo") - .css({ display: "block", width: 20, height: 20, overflowX: "visible", overflowY: "auto" }) - .animate({ width: 42, height: 42 }, 100, function() { +QUnit.test( "animate resets overflow-x and overflow-y when finished", function( assert ) { + assert.expect( 2 ); + jQuery( "#foo" ) + .css( { display: "block", width: 20, height: 20, overflowX: "visible", overflowY: "auto" } ) + .animate( { width: 42, height: 42 }, 100, function() { assert.equal( this.style.overflowX, "visible", "overflow-x is visible" ); assert.equal( this.style.overflowY, "auto", "overflow-y is auto" ); - }); + } ); this.clock.tick( 100 ); -}); +} ); /* // This test ends up being flaky depending upon the CPU load QUnit.test("animate option (queue === false)", function( assert ) { @@ -450,7 +449,7 @@ QUnit.test( "animate option { queue: false }", function( assert ) { assert.expect( 2 ); var foo = jQuery( "#foo" ); - foo.animate({ + foo.animate( { fontSize: "2em" }, { queue: false, @@ -458,17 +457,17 @@ QUnit.test( "animate option { queue: false }", function( assert ) { complete: function() { assert.ok( true, "Animation Completed" ); } - }); + } ); this.clock.tick( 10 ); assert.equal( foo.queue().length, 0, "Queue is empty" ); -}); +} ); QUnit.test( "animate option { queue: true }", function( assert ) { assert.expect( 2 ); var foo = jQuery( "#foo" ); - foo.animate({ + foo.animate( { fontSize: "2em" }, { queue: true, @@ -476,18 +475,18 @@ QUnit.test( "animate option { queue: true }", function( assert ) { complete: function() { assert.ok( true, "Animation Completed" ); } - }); + } ); assert.notEqual( foo.queue().length, 0, "Default queue is not empty" ); //clear out existing timers before next test this.clock.tick( 10 ); -}); +} ); QUnit.test( "animate option { queue: 'name' }", function( assert ) { assert.expect( 5 ); var foo = jQuery( "#foo" ), - origWidth = parseFloat( foo.css("width") ), + origWidth = parseFloat( foo.css( "width" ) ), order = []; foo.animate( { width: origWidth + 100 }, { @@ -497,128 +496,127 @@ QUnit.test( "animate option { queue: 'name' }", function( assert ) { // second callback function order.push( 2 ); - assert.equal( parseFloat( foo.css("width") ), origWidth + 100, "Animation ended" ); - assert.equal( foo.queue("name").length, 1, "Queue length of 'name' queue" ); + assert.equal( parseFloat( foo.css( "width" ) ), origWidth + 100, "Animation ended" ); + assert.equal( foo.queue( "name" ).length, 1, "Queue length of 'name' queue" ); } - }).queue( "name", function() { + } ).queue( "name", function() { // last callback function 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." ); - assert.equal( foo.queue("name").length, 2, "Queue length of 'name' queue" ); + assert.equal( parseFloat( foo.css( "width" ) ), origWidth, "Animation does not start on its own." ); + assert.equal( foo.queue( "name" ).length, 2, "Queue length of 'name' queue" ); foo.dequeue( "name" ); this.clock.tick( 10 ); -}); +} ); -QUnit.test("animate with no properties", function( assert ) { - assert.expect(2); +QUnit.test( "animate with no properties", function( assert ) { + assert.expect( 2 ); var foo, - divs = jQuery("div"), + divs = jQuery( "div" ), count = 0; - divs.animate({}, function(){ + divs.animate( {}, function() { count++; - }); + } ); assert.equal( divs.length, count, "Make sure that callback is called for each element in the set." ); + foo = jQuery( "#foo" ); - foo = jQuery("#foo"); - - foo.animate({}); - foo.animate({top: 10}, 100, function(){ + foo.animate( {} ); + foo.animate( { top: 10 }, 100, function() { assert.ok( true, "Animation was properly dequeued." ); - }); + } ); this.clock.tick( 100 ); -}); - -QUnit.test("animate duration 0", function( assert ) { - assert.expect(11); +} ); +QUnit.test( "animate duration 0", function( assert ) { + assert.expect( 11 ); var $elem, - $elems = jQuery([{ a:0 },{ a:0 }]), + $elems = jQuery( [ { a:0 },{ a:0 } ] ), counter = 0; assert.equal( jQuery.timers.length, 0, "Make sure no animation was running from another test" ); - $elems.eq(0).animate( {a:1}, 0, function(){ + $elems.eq( 0 ).animate( { a:1 }, 0, function() { assert.ok( true, "Animate a simple property." ); counter++; - }); + } ); // Failed until [6115] assert.equal( jQuery.timers.length, 0, "Make sure synchronic animations are not left on jQuery.timers" ); assert.equal( counter, 1, "One synchronic animations" ); - $elems.animate( { a:2 }, 0, function(){ + $elems.animate( { a:2 }, 0, function() { assert.ok( true, "Animate a second simple property." ); counter++; - }); + } ); assert.equal( counter, 3, "Multiple synchronic animations" ); - $elems.eq(0).animate( {a:3}, 0, function(){ + $elems.eq( 0 ).animate( { a:3 }, 0, function() { assert.ok( true, "Animate a third simple property." ); counter++; - }); - $elems.eq(1).animate( {a:3}, 200, function(){ + } ); + $elems.eq( 1 ).animate( { a:3 }, 200, function() { counter++; + // Failed until [6115] assert.equal( counter, 5, "One synchronic and one asynchronic" ); - }); + } ); this.clock.tick( 200 ); - $elem = jQuery("<div />"); - $elem.show(0, function(){ - assert.ok(true, "Show callback with no duration"); - }); - $elem.hide(0, function(){ - assert.ok(true, "Hide callback with no duration"); - }); + $elem = jQuery( "<div />" ); + $elem.show( 0, function() { + assert.ok( true, "Show callback with no duration" ); + } ); + $elem.hide( 0, function() { + assert.ok( true, "Hide callback with no duration" ); + } ); // manually clean up detached elements $elem.remove(); -}); +} ); -QUnit.test("animate hyphenated properties", function( assert ) { - assert.expect(1); +QUnit.test( "animate hyphenated properties", function( assert ) { + assert.expect( 1 ); - jQuery("#foo") - .css("font-size", 10) - .animate({"font-size": 20}, 200, function() { + jQuery( "#foo" ) + .css( "font-size", 10 ) + .animate( { "font-size": 20 }, 200, function() { 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 ); -}); +} ); -QUnit.test("animate non-element", function( assert ) { - assert.expect(1); +QUnit.test( "animate non-element", function( assert ) { + assert.expect( 1 ); var obj = { test: 0 }; - jQuery(obj).animate({test: 200}, 200, function(){ + jQuery( obj ).animate( { test: 200 }, 200, function() { assert.equal( obj.test, 200, "The custom property should be modified." ); - }); + } ); this.clock.tick( 200 ); -}); +} ); -QUnit.test("stop()", function( assert ) { +QUnit.test( "stop()", function( assert ) { assert.expect( 4 ); var $one, $two, - $foo = jQuery("#foo"), + $foo = jQuery( "#foo" ), w = 0, nw; @@ -626,34 +624,35 @@ QUnit.test("stop()", function( assert ) { .animate( { "width": "show" }, 1500 ); this.clock.tick( 100 ); - nw = $foo.css("width"); + nw = $foo.css( "width" ); assert.notEqual( parseFloat( nw ), w, "An animation occurred " + nw + " " + w + "px" ); $foo.stop(); - nw = $foo.css("width"); + nw = $foo.css( "width" ); assert.notEqual( parseFloat( nw ), w, "Stop didn't reset the animation " + nw + " " + w + "px" ); this.clock.tick( 100 ); $foo.removeData(); - $foo.removeData(undefined, true); - assert.equal( nw, $foo.css("width"), "The animation didn't continue" ); + $foo.removeData( undefined, true ); + assert.equal( nw, $foo.css( "width" ), "The animation didn't continue" ); - $one = jQuery("#fadein"); - $two = jQuery("#show"); - $one.fadeTo(100, 0, function() { + $one = jQuery( "#fadein" ); + $two = jQuery( "#show" ); + $one.fadeTo( 100, 0, function() { $one.stop(); - }); + } ); this.clock.tick( 100 ); - $two.fadeTo(100, 0, function() { - assert.equal( $two.css("opacity"), "0", "Stop does not interfere with animations on other elements (#6641)" ); + $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", ""); - }); + $one.add( $two ).css( "opacity", "" ); + } ); this.clock.tick( 100 ); -}); +} ); -QUnit.test("stop() - several in queue", function( assert ) { +QUnit.test( "stop() - several in queue", function( assert ) { assert.expect( 5 ); var nw, $foo = jQuery( "#foo" ); @@ -661,9 +660,9 @@ QUnit.test("stop() - several in queue", function( assert ) { // default duration is 400ms, so 800px ensures we aren't 0 or 1 after 1ms $foo.hide().css( "width", 800 ); - $foo.animate({ "width": "show" }, 400, "linear"); - $foo.animate({ "width": "hide" }); - $foo.animate({ "width": "show" }); + $foo.animate( { "width": "show" }, 400, "linear" ); + $foo.animate( { "width": "hide" } ); + $foo.animate( { "width": "show" } ); this.clock.tick( 1 ); @@ -681,119 +680,121 @@ QUnit.test("stop() - several in queue", function( assert ) { $foo.stop( true ); assert.equal( $foo.queue().length, 0, "0 in the queue" ); -}); +} ); -QUnit.test("stop(clearQueue)", function( assert ) { - assert.expect(4); +QUnit.test( "stop(clearQueue)", function( assert ) { + assert.expect( 4 ); - var $foo = jQuery("#foo"), + var $foo = jQuery( "#foo" ), w = 0, nw; - $foo.hide().css( "width", 200 ).css("width"); + $foo.hide().css( "width", 200 ).css( "width" ); - $foo.animate({ "width": "show" }, 1000); - $foo.animate({ "width": "hide" }, 1000); - $foo.animate({ "width": "show" }, 1000); + $foo.animate( { "width": "show" }, 1000 ); + $foo.animate( { "width": "hide" }, 1000 ); + $foo.animate( { "width": "show" }, 1000 ); this.clock.tick( 100 ); - nw = $foo.css("width"); - assert.ok( parseFloat( nw ) !== w, "An animation occurred " + nw + " " + w + "px"); - $foo.stop(true); + nw = $foo.css( "width" ); + assert.ok( parseFloat( nw ) !== w, "An animation occurred " + nw + " " + w + "px" ); + $foo.stop( true ); - nw = $foo.css("width"); - assert.ok( parseFloat( nw ) !== w, "Stop didn't reset the animation " + nw + " " + w + "px"); + nw = $foo.css( "width" ); + assert.ok( parseFloat( nw ) !== w, "Stop didn't reset the animation " + nw + " " + w + "px" ); assert.equal( $foo.queue().length, 0, "The animation queue was cleared" ); this.clock.tick( 100 ); - assert.equal( nw, $foo.css("width"), "The animation didn't continue" ); -}); + assert.equal( nw, $foo.css( "width" ), "The animation didn't continue" ); +} ); -QUnit.test("stop(clearQueue, gotoEnd)", function( assert ) { - assert.expect(1); +QUnit.test( "stop(clearQueue, gotoEnd)", function( assert ) { + assert.expect( 1 ); - var $foo = jQuery("#foo"), + var $foo = jQuery( "#foo" ), w = 0, nw; - $foo.hide().css( "width", 200 ).css("width"); + $foo.hide().css( "width", 200 ).css( "width" ); - $foo.animate({ width: "show" }, 1000); - $foo.animate({ width: "hide" }, 1000); - $foo.animate({ width: "show" }, 1000); - $foo.animate({ width: "hide" }, 1000); + $foo.animate( { width: "show" }, 1000 ); + $foo.animate( { width: "hide" }, 1000 ); + $foo.animate( { width: "show" }, 1000 ); + $foo.animate( { width: "hide" }, 1000 ); this.clock.tick( 100 ); - nw = $foo.css("width"); - assert.ok( parseFloat( nw ) !== w, "An animation occurred " + nw + " " + w + "px"); - $foo.stop(false, true); + nw = $foo.css( "width" ); + assert.ok( parseFloat( nw ) !== w, "An animation occurred " + nw + " " + w + "px" ); + $foo.stop( false, true ); + + nw = $foo.css( "width" ); - nw = $foo.css("width"); // Disabled, being flaky //equal( nw, 1, "Stop() reset the animation" ); this.clock.tick( 100 ); + // Disabled, being flaky //equal( $foo.queue().length, 2, "The next animation continued" ); - $foo.stop(true); -}); + $foo.stop( true ); +} ); QUnit.test( "stop( queue, ..., ... ) - Stop single queues", function( assert ) { assert.expect( 3 ); var saved, - foo = jQuery("#foo").css({ width: 200, height: 200 }); + foo = jQuery( "#foo" ).css( { width: 200, height: 200 } ); - foo.animate({ + foo.animate( { width: 400 - },{ + }, { duration: 500, complete: function() { - assert.equal( parseFloat( foo.css("width") ), 400, "Animation completed for standard queue" ); - assert.equal( parseFloat( foo.css("height") ), saved, "Height was not changed after the second stop"); + assert.equal( parseFloat( foo.css( "width" ) ), 400, "Animation completed for standard queue" ); + assert.equal( parseFloat( foo.css( "height" ) ), saved, "Height was not changed after the second stop" ); } - }); + } ); - foo.animate({ + foo.animate( { height: 400 - },{ + }, { duration: 1000, queue: "height" - }).dequeue("height").stop( "height", false, true ); + } ).dequeue( "height" ).stop( "height", false, true ); - assert.equal( parseFloat( foo.css("height") ), 400, "Height was stopped with gotoEnd" ); + assert.equal( parseFloat( foo.css( "height" ) ), 400, "Height was stopped with gotoEnd" ); - foo.animate({ + foo.animate( { height: 200 - },{ + }, { duration: 1000, queue: "height" - }).dequeue( "height" ).stop( "height", false, false ); - saved = parseFloat( foo.css("height") ); + } ).dequeue( "height" ).stop( "height", false, false ); + saved = parseFloat( foo.css( "height" ) ); this.clock.tick( 500 ); -}); +} ); -QUnit.test("toggle()", function( assert ) { - assert.expect(6); - var x = jQuery("#foo"); - assert.ok( x.is(":visible"), "is visible" ); +QUnit.test( "toggle()", function( assert ) { + assert.expect( 6 ); + var x = jQuery( "#foo" ); + assert.ok( x.is( ":visible" ), "is visible" ); x.toggle(); - assert.ok( x.is(":hidden"), "is hidden" ); + assert.ok( x.is( ":hidden" ), "is hidden" ); x.toggle(); - assert.ok( x.is(":visible"), "is visible again" ); - - x.toggle(true); - assert.ok( x.is(":visible"), "is visible" ); - x.toggle(false); - assert.ok( x.is(":hidden"), "is hidden" ); - x.toggle(true); - assert.ok( x.is(":visible"), "is visible again" ); -}); + assert.ok( x.is( ":visible" ), "is visible again" ); + + x.toggle( true ); + assert.ok( x.is( ":visible" ), "is visible" ); + x.toggle( false ); + assert.ok( x.is( ":hidden" ), "is hidden" ); + x.toggle( true ); + assert.ok( x.is( ":visible" ), "is visible again" ); +} ); QUnit.test( "jQuery.fx.prototype.cur() - <1.8 Back Compat", function( assert ) { assert.expect( 7 ); - var div = jQuery( "<div></div>" ).appendTo( "#qunit-fixture" ).css({ + var div = jQuery( "<div></div>" ).appendTo( "#qunit-fixture" ).css( { color: "#ABC", border: "5px solid black", left: "auto", marginBottom: "-11000px" - })[0]; + } )[ 0 ]; assert.equal( ( new jQuery.fx( div, {}, "color" ) ).cur(), @@ -839,31 +840,31 @@ QUnit.test( "jQuery.fx.prototype.cur() - <1.8 Back Compat", function( assert ) { ); jQuery( div ).remove(); -}); +} ); -QUnit.test("Overflow and Display", function( assert ) { - assert.expect(4); +QUnit.test( "Overflow and Display", function( assert ) { + assert.expect( 4 ); var - testClass = jQuery.makeTest("Overflow and Display") - .addClass("overflow inline"), - testStyle = jQuery.makeTest("Overflow and Display (inline style)") - .css({ overflow: "visible", display: "inline" }), + testClass = jQuery.makeTest( "Overflow and Display" ) + .addClass( "overflow inline" ), + testStyle = jQuery.makeTest( "Overflow and Display (inline style)" ) + .css( { overflow: "visible", display: "inline" } ), done = function() { assert.equal( jQuery.css( this, "overflow" ), "visible", "Overflow should be 'visible'" ); assert.equal( jQuery.css( this, "display" ), "inline", "Display should be 'inline'" ); }; testClass.add( testStyle ) - .addClass("widewidth") - .text("Some sample text.") - .before("text before") - .after("text after") - .animate({ opacity: 0.5 }, "slow", done ); + .addClass( "widewidth" ) + .text( "Some sample text." ) + .before( "text before" ) + .after( "text after" ) + .animate( { opacity: 0.5 }, "slow", done ); this.clock.tick( 600 ); -}); +} ); -jQuery.each({ +jQuery.each( { "CSS Auto": function( elem, prop ) { jQuery( elem ).addClass( "auto" + prop ) .text( "This is a long string of text." ); @@ -899,7 +900,7 @@ jQuery.each({ return 0; } }, function( fn, f ) { - jQuery.each({ + jQuery.each( { "show": function( elem, prop ) { jQuery( elem ).hide().addClass( "wide" + prop ); return "show"; @@ -920,7 +921,7 @@ jQuery.each({ return 0; } }, function( tn, t ) { - QUnit.test(fn + " to " + tn, function( assert ) { + QUnit.test( fn + " to " + tn, function( assert ) { var num, anim, elem = jQuery.makeTest( fn + " to " + tn ), t_w = t( elem, "width" ), @@ -935,6 +936,7 @@ jQuery.each({ } num = 0; + // TODO: uncrowd this if ( t_h === "show" ) { num++; } if ( t_w === "show" ) { num++; } @@ -950,9 +952,9 @@ jQuery.each({ anim = { width: t_w, height: t_h, opacity: t_o }; - elem.animate(anim, 50); + elem.animate( anim, 50 ); - jQuery.when( elem ).done(function( $elem ) { + jQuery.when( elem ).done( function( $elem ) { var cur_o, cur_w, cur_h, old_h, elem = $elem[ 0 ]; @@ -969,9 +971,9 @@ jQuery.each({ assert.ok( f_h === "" ? elem.style.height === f_h : elem.style.height.indexOf( f_h ) === 0, "Height must be reset to " + f_h + ": " + elem.style.height ); } - cur_o = jQuery.style(elem, "opacity"); + cur_o = jQuery.style( elem, "opacity" ); - if ( f_o !== jQuery.css(elem, "opacity") ) { + if ( f_o !== jQuery.css( elem, "opacity" ) ) { f_o = f( elem, "opacity" ); } @@ -986,13 +988,13 @@ jQuery.each({ if ( t_o.constructor === Number ) { assert.equal( cur_o, t_o, "Final opacity should be " + t_o + ": " + cur_o ); - assert.ok( jQuery.css(elem, "opacity") !== "" || cur_o === t_o, "Opacity should be explicitly set to " + t_o + ", is instead: " + cur_o ); + assert.ok( jQuery.css( elem, "opacity" ) !== "" || cur_o === t_o, "Opacity should be explicitly set to " + t_o + ", is instead: " + cur_o ); } if ( t_w.constructor === Number ) { assert.equal( elem.style.width, t_w + "px", "Final width should be " + t_w + ": " + elem.style.width ); - cur_w = jQuery.css( elem,"width" ); + cur_w = jQuery.css( elem, "width" ); assert.ok( elem.style.width !== "" || cur_w === t_w, "Width should be explicitly set to " + t_w + ", is instead: " + cur_w ); } @@ -1000,14 +1002,14 @@ jQuery.each({ if ( t_h.constructor === Number ) { assert.equal( elem.style.height, t_h + "px", "Final height should be " + t_h + ": " + elem.style.height ); - cur_h = jQuery.css( elem,"height" ); + cur_h = jQuery.css( elem, "height" ); assert.ok( elem.style.height !== "" || cur_h === t_h, "Height should be explicitly set to " + t_h + ", is instead: " + cur_h ); } if ( t_h === "show" ) { old_h = jQuery.css( elem, "height" ); - jQuery( elem ).append("<br/>Some more text<br/>and some more..."); + jQuery( elem ).append( "<br/>Some more text<br/>and some more..." ); if ( /Auto/.test( fn ) ) { assert.notEqual( jQuery.css( elem, "height" ), old_h, "Make sure height is auto." ); @@ -1019,18 +1021,18 @@ jQuery.each({ // manually remove generated element jQuery( elem ).remove(); - }); + } ); this.clock.tick( 50 ); - }); - }); -}); + } ); + } ); +} ); -QUnit.test("Effects chaining", function( assert ) { +QUnit.test( "Effects chaining", function( assert ) { var remaining = 16, props = [ "opacity", "height", "width", "display", "overflow" ], setup = function( name, selector ) { var $el = jQuery( selector ); - return $el.data( getProps( $el[0] ) ).data( "name", name ); + return $el.data( getProps( $el[ 0 ] ) ).data( "name", name ); }, check = function() { var data = jQuery.data( this ), @@ -1045,40 +1047,40 @@ QUnit.test("Effects chaining", function( assert ) { var obj = {}; jQuery.each( props, function( i, prop ) { obj[ prop ] = prop === "overflow" && el.style[ prop ] || jQuery.css( el, prop ); - }); + } ); return obj; }; assert.expect( remaining ); - setup( ".fadeOut().fadeIn()", "#fadein div" ).fadeOut("fast").fadeIn( "fast", check ); - setup( ".fadeIn().fadeOut()", "#fadeout div" ).fadeIn("fast").fadeOut( "fast", check ); - setup( ".hide().show()", "#show div" ).hide("fast").show( "fast", check ); - setup( ".show().hide()", "#hide div" ).show("fast").hide( "fast", check ); - setup( ".show().hide(easing)", "#easehide div" ).show("fast").hide( "fast", "linear", check ); - setup( ".toggle().toggle() - in", "#togglein div" ).toggle("fast").toggle( "fast", check ); - setup( ".toggle().toggle() - out", "#toggleout div" ).toggle("fast").toggle( "fast", check ); - setup( ".toggle().toggle(easing) - out", "#easetoggleout div" ).toggle("fast").toggle( "fast", "linear", check ); - setup( ".slideDown().slideUp()", "#slidedown div" ).slideDown("fast").slideUp( "fast", check ); - setup( ".slideUp().slideDown()", "#slideup div" ).slideUp("fast").slideDown( "fast", check ); - setup( ".slideUp().slideDown(easing)", "#easeslideup div" ).slideUp("fast").slideDown( "fast", "linear", check ); - setup( ".slideToggle().slideToggle() - in", "#slidetogglein div" ).slideToggle("fast").slideToggle( "fast", check ); - setup( ".slideToggle().slideToggle() - out", "#slidetoggleout div" ).slideToggle("fast").slideToggle( "fast", check ); - setup( ".fadeToggle().fadeToggle() - in", "#fadetogglein div" ).fadeToggle("fast").fadeToggle( "fast", check ); - setup( ".fadeToggle().fadeToggle() - out", "#fadetoggleout div" ).fadeToggle("fast").fadeToggle( "fast", check ); + setup( ".fadeOut().fadeIn()", "#fadein div" ).fadeOut( "fast" ).fadeIn( "fast", check ); + setup( ".fadeIn().fadeOut()", "#fadeout div" ).fadeIn( "fast" ).fadeOut( "fast", check ); + setup( ".hide().show()", "#show div" ).hide( "fast" ).show( "fast", check ); + setup( ".show().hide()", "#hide div" ).show( "fast" ).hide( "fast", check ); + setup( ".show().hide(easing)", "#easehide div" ).show( "fast" ).hide( "fast", "linear", check ); + setup( ".toggle().toggle() - in", "#togglein div" ).toggle( "fast" ).toggle( "fast", check ); + setup( ".toggle().toggle() - out", "#toggleout div" ).toggle( "fast" ).toggle( "fast", check ); + setup( ".toggle().toggle(easing) - out", "#easetoggleout div" ).toggle( "fast" ).toggle( "fast", "linear", check ); + setup( ".slideDown().slideUp()", "#slidedown div" ).slideDown( "fast" ).slideUp( "fast", check ); + setup( ".slideUp().slideDown()", "#slideup div" ).slideUp( "fast" ).slideDown( "fast", check ); + setup( ".slideUp().slideDown(easing)", "#easeslideup div" ).slideUp( "fast" ).slideDown( "fast", "linear", check ); + setup( ".slideToggle().slideToggle() - in", "#slidetogglein div" ).slideToggle( "fast" ).slideToggle( "fast", check ); + setup( ".slideToggle().slideToggle() - out", "#slidetoggleout div" ).slideToggle( "fast" ).slideToggle( "fast", check ); + setup( ".fadeToggle().fadeToggle() - in", "#fadetogglein div" ).fadeToggle( "fast" ).fadeToggle( "fast", check ); + setup( ".fadeToggle().fadeToggle() - out", "#fadetoggleout div" ).fadeToggle( "fast" ).fadeToggle( "fast", check ); setup( ".fadeTo(0.5).fadeTo(1.0, easing)", "#fadeto div" ).fadeTo( "fast", 0.5 ).fadeTo( "fast", 1.0, "linear", check ); this.clock.tick( 400 ); -}); +} ); -jQuery.makeTest = function( text ){ - var elem = jQuery("<div></div>") +jQuery.makeTest = function( text ) { + var elem = jQuery( "<div></div>" ) .attr( "id", "test" + jQuery.makeTest.id++ ) - .addClass("box"); + .addClass( "box" ); - jQuery("<h4></h4>") + jQuery( "<h4></h4>" ) .text( text ) - .appendTo("#fx-tests") + .appendTo( "#fx-tests" ) .after( elem ); return elem; @@ -1086,18 +1088,18 @@ jQuery.makeTest = function( text ){ jQuery.makeTest.id = 1; -QUnit.test("jQuery.show('fast') doesn't clear radio buttons (bug #1095)", function( assert ) { - assert.expect(4); +QUnit.test( "jQuery.show('fast') doesn't clear radio buttons (bug #1095)", function( assert ) { + assert.expect( 4 ); - var $checkedtest = jQuery("#checkedtest"); - $checkedtest.hide().show("fast", function() { - assert.ok( jQuery("input[type='radio']", $checkedtest).first().attr("checked"), "Check first radio still checked." ); - assert.ok( !jQuery("input[type='radio']", $checkedtest).last().attr("checked"), "Check last radio still NOT checked." ); - assert.ok( jQuery("input[type='checkbox']", $checkedtest).first().attr("checked"), "Check first checkbox still checked." ); - assert.ok( !jQuery("input[type='checkbox']", $checkedtest).last().attr("checked"), "Check last checkbox still NOT checked." ); - }); + var $checkedtest = jQuery( "#checkedtest" ); + $checkedtest.hide().show( "fast", function() { + assert.ok( jQuery( "input[type='radio']", $checkedtest ).first().attr( "checked" ), "Check first radio still checked." ); + assert.ok( !jQuery( "input[type='radio']", $checkedtest ).last().attr( "checked" ), "Check last radio still NOT checked." ); + assert.ok( jQuery( "input[type='checkbox']", $checkedtest ).first().attr( "checked" ), "Check first checkbox still checked." ); + assert.ok( !jQuery( "input[type='checkbox']", $checkedtest ).last().attr( "checked" ), "Check last checkbox still NOT checked." ); + } ); this.clock.tick( 200 ); -}); +} ); QUnit.test( "interrupt toggle", function( assert ) { assert.expect( 24 ); @@ -1106,13 +1108,14 @@ QUnit.test( "interrupt toggle", function( assert ) { longDuration = 2000, shortDuration = 500, remaining = 0, - $elems = jQuery(".chain-test"), + $elems = jQuery( ".chain-test" ), clock = this.clock, finish = function() { }; jQuery.each( { slideToggle: "height", fadeToggle: "opacity", toggle: "width" }, function( method, prop ) { - var $methodElems = $elems.filter( "[id^='" + method.toLowerCase() + "']" ).each(function() { + var $methodElems = $elems.filter( "[id^='" + method.toLowerCase() + "']" ).each( function() { + // Don't end test until we're done with this element remaining++; @@ -1121,28 +1124,28 @@ QUnit.test( "interrupt toggle", function( assert ) { // Expect olddisplay data from our .hide() call below QUnit.expectJqData( env, this, "olddisplay" ); - }); + } ); // Interrupt a hiding toggle $methodElems[ method ]( longDuration ); - setTimeout(function() { - $methodElems.stop().each(function() { + setTimeout( function() { + $methodElems.stop().each( function() { assert.notEqual( jQuery( this ).css( prop ), jQuery.data( this, "startVal" ), ".stop() before completion of hiding ." + method + "() - #" + this.id ); - }); + } ); // Restore $methodElems[ method ]( shortDuration, function() { var id = this.id, $elem = jQuery( this ), - startVal = $elem.data("startVal"); + startVal = $elem.data( "startVal" ); - $elem.removeData("startVal"); + $elem.removeData( "startVal" ); assert.equal( $elem.css( prop ), startVal, "original value restored by ." + method + "() - #" + id ); // Interrupt a showing toggle $elem.hide()[ method ]( longDuration ); - setTimeout(function() { + setTimeout( function() { $elem.stop(); assert.notEqual( $elem.css( prop ), startVal, ".stop() before completion of showing ." + method + "() - #" + id ); @@ -1150,15 +1153,15 @@ QUnit.test( "interrupt toggle", function( assert ) { $elem[ method ]( shortDuration, function() { assert.equal( $elem.css( prop ), startVal, "original value restored by ." + method + "() - #" + id ); finish(); - }); + } ); }, shortDuration ); - }); + } ); }, shortDuration ); - }); + } ); clock.tick( longDuration ); // FIXME untangle the set timeouts -}); +} ); QUnit.test( "animate with per-property easing", function( assert ) { @@ -1195,34 +1198,34 @@ QUnit.test( "animate with per-property easing", function( assert ) { assert.ok( defaultTestCalled, "Easing function (_default) called" ); assert.equal( props.a[ 1 ], "_test1", "animate does not change original props (per-property easing would be lost)" ); assert.equal( props.b[ 1 ], "_test2", "animate does not change original props (per-property easing would be lost)" ); - }); + } ); this.clock.tick( 400 ); -}); +} ); -QUnit.test("animate with CSS shorthand properties", function( assert ){ - assert.expect(11); +QUnit.test( "animate with CSS shorthand properties", function( assert ) { + assert.expect( 11 ); var easeAnimation_count = 0, easeProperty_count = 0, propsBasic = { "padding": "10 20 30" }, propsSpecial = { "padding": [ "1 2 3", "propertyScope" ] }; - jQuery.easing.animationScope = function(p) { + jQuery.easing.animationScope = function( p ) { if ( p >= 1 ) { easeAnimation_count++; } return p; }; - jQuery.easing.propertyScope = function(p) { + jQuery.easing.propertyScope = function( p ) { if ( p >= 1 ) { easeProperty_count++; } return p; }; - jQuery("#foo") + jQuery( "#foo" ) .animate( propsBasic, 200, "animationScope", function() { assert.equal( this.style.paddingTop, "10px", "padding-top was animated" ); assert.equal( this.style.paddingLeft, "20px", "padding-left was animated" ); @@ -1230,7 +1233,7 @@ QUnit.test("animate with CSS shorthand properties", function( assert ){ assert.equal( this.style.paddingBottom, "30px", "padding-bottom was animated" ); assert.equal( easeAnimation_count, 4, "per-animation default easing called for each property" ); easeAnimation_count = 0; - }) + } ) .animate( propsSpecial, 200, "animationScope", function() { assert.equal( this.style.paddingTop, "1px", "padding-top was animated again" ); assert.equal( this.style.paddingLeft, "2px", "padding-left was animated again" ); @@ -1239,37 +1242,37 @@ QUnit.test("animate with CSS shorthand properties", function( assert ){ assert.equal( easeAnimation_count, 0, "per-animation default easing not called" ); assert.equal( easeProperty_count, 4, "special easing called for each property" ); - jQuery(this).css("padding", "0"); + jQuery( this ).css( "padding", "0" ); delete jQuery.easing.animationScope; delete jQuery.easing.propertyScope; - }); + } ); this.clock.tick( 400 ); -}); +} ); -QUnit.test("hide hidden elements, with animation (bug #7141)", function( assert ) { - assert.expect(3); +QUnit.test( "hide hidden elements, with animation (bug #7141)", function( assert ) { + assert.expect( 3 ); - var div = jQuery("<div style='display:none'></div>").appendTo("#qunit-fixture"); - assert.equal( div.css("display"), "none", "Element is hidden by default" ); - div.hide(1, function () { - assert.ok( !jQuery._data(div, "olddisplay"), "olddisplay is undefined after hiding an already-hidden element" ); - div.show(1, function () { - assert.equal( div.css("display"), "block", "Show a double-hidden element" ); - }); - }); + var div = jQuery( "<div style='display:none'></div>" ).appendTo( "#qunit-fixture" ); + assert.equal( div.css( "display" ), "none", "Element is hidden by default" ); + div.hide( 1, function() { + assert.ok( !jQuery._data( div, "olddisplay" ), "olddisplay is undefined after hiding an already-hidden element" ); + div.show( 1, function() { + assert.equal( div.css( "display" ), "block", "Show a double-hidden element" ); + } ); + } ); this.clock.tick( 10 ); -}); +} ); -QUnit.test("animate unit-less properties (#4966)", function( assert ) { +QUnit.test( "animate unit-less properties (#4966)", function( assert ) { assert.expect( 2 ); var div = jQuery( "<div style='z-index: 0; position: absolute;'></div>" ).appendTo( "#qunit-fixture" ); assert.equal( div.css( "z-index" ), "0", "z-index is 0" ); - div.animate({ zIndex: 2 }, function() { + div.animate( { zIndex: 2 }, function() { assert.equal( div.css( "z-index" ), "2", "z-index is 2" ); - }); + } ); this.clock.tick( 400 ); -}); +} ); QUnit.test( "animate properties missing px w/ opacity as last (#9074)", function( assert ) { assert.expect( 6 ); @@ -1282,11 +1285,11 @@ QUnit.test( "animate properties missing px w/ opacity as last (#9074)", function } assert.equal( cssInt( "marginLeft" ), 0, "Margin left is 0" ); assert.equal( cssInt( "left" ), 0, "Left is 0" ); - div.animate({ + div.animate( { left: 200, marginLeft: 200, opacity: 0 - }, 2000); + }, 2000 ); this.clock.tick( 500 ); @@ -1297,25 +1300,26 @@ QUnit.test( "animate properties missing px w/ opacity as last (#9074)", function assert.notEqual( l, 0, "Left is not 0 after partial animate" ); assert.notEqual( l, 200, "Left is not 200 after partial animate" ); div.stop().remove(); -}); +} ); -QUnit.test("callbacks should fire in correct order (#9100)", function( assert ) { +QUnit.test( "callbacks should fire in correct order (#9100)", function( assert ) { assert.expect( 1 ); var a = 1, cb = 0; - jQuery("<p data-operation='*2'></p><p data-operation='^2'></p>").appendTo("#qunit-fixture") + 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; + .animate( { fontSize: 12 }, 13, function() { + a *= jQuery( this ).data( "operation" ) === "*2" ? 2 : a; cb++; if ( cb === 2 ) { - assert.equal( a, 4, "test value has been *2 and _then_ ^2"); + assert.equal( a, 4, "test value has been *2 and _then_ ^2" ); } - }); + } ); this.clock.tick( 20 ); -}); +} ); QUnit.test( "callbacks that throw exceptions will be removed (#5684)", function( assert ) { assert.expect( 2 ); @@ -1325,9 +1329,9 @@ QUnit.test( "callbacks that throw exceptions will be removed (#5684)", function( function TestException() { } - foo.animate({ height: 1 }, 1, function() { + foo.animate( { height: 1 }, 1, function() { throw new TestException(); - }); + } ); // this test thoroughly abuses undocumented methods - please feel free to update // with any changes internally to these functions. @@ -1343,39 +1347,40 @@ QUnit.test( "callbacks that throw exceptions will be removed (#5684)", function( assert.ok( true, "Test completed without throwing a second exception" ); -}); +} ); -QUnit.test("animate will scale margin properties individually", function( assert ) { +QUnit.test( "animate will scale margin properties individually", function( assert ) { assert.expect( 2 ); - var foo = jQuery( "#foo" ).css({ + var foo = jQuery( "#foo" ).css( { "margin": 0, "marginLeft": 100 - }); + } ); assert.ok( foo.css( "marginLeft" ) !== foo.css( "marginRight" ), "Sanity Check" ); - foo.animate({ + foo.animate( { "margin": 200 - }).stop(); + } ).stop(); - assert.ok( foo.css( "marginLeft") !== foo.css( "marginRight" ), "The margin properties are different"); + assert.ok( foo.css( "marginLeft" ) !== foo.css( "marginRight" ), "The margin properties are different" ); // clean up for next test - foo.css({ + foo.css( { "marginLeft": "", "marginRight": "", "marginTop": "", "marginBottom": "" - }); -}); + } ); +} ); -QUnit.test("Do not append px to 'fill-opacity' #9548", function( assert ) { +QUnit.test( "Do not append px to 'fill-opacity' #9548", function( assert ) { assert.expect( 1 ); - var $div = jQuery("<div>").appendTo("#qunit-fixture"); + var $div = jQuery( "<div>" ).appendTo( "#qunit-fixture" ); + + $div.css( "fill-opacity", 0 ).animate( { "fill-opacity": 1.0 }, 0, function() { - $div.css("fill-opacity", 0).animate({ "fill-opacity": 1.0 }, 0, function () { // Support: Android 2.3 (no support for fill-opacity) if ( jQuery( this ).css( "fill-opacity" ) ) { assert.equal( jQuery( this ).css( "fill-opacity" ), 1, "Do not append px to 'fill-opacity'" ); @@ -1383,10 +1388,10 @@ QUnit.test("Do not append px to 'fill-opacity' #9548", function( assert ) { assert.ok( true, "No support for fill-opacity CSS property" ); } $div.remove(); - }); -}); + } ); +} ); -QUnit.test("line-height animates correctly (#13855)", function( assert ) { +QUnit.test( "line-height animates correctly (#13855)", function( assert ) { assert.expect( 12 ); var t0, @@ -1398,22 +1403,22 @@ QUnit.test("line-height animates correctly (#13855)", function( assert ) { "<p style='line-height: 5000px;'>px</p>" + "<p style='line-height: 5000%;'>percent</p>" + "<p style='line-height: 100em;'>em</p>" - ).appendTo("#qunit-fixture"), + ).appendTo( "#qunit-fixture" ), initialHeight = jQuery.map( animated, function( el ) { return jQuery( el ).height(); - }), + } ), tolerance = 1.5; // Delay start to improve test stability - setTimeout(function() { + setTimeout( function() { - t0 = +(new Date()); + t0 = +( new Date() ); animated.animate( { "line-height": "hide" }, longDuration, "linear" ); - setTimeout(function() { - var progress = ( (new Date()) - t0 ) / longDuration; + setTimeout( function() { + var progress = ( ( new Date() ) - t0 ) / longDuration; - animated.each(function( i ) { + animated.each( function( i ) { var label = jQuery.text( this ), initial = initialHeight[ i ], height = jQuery( this ).height(), @@ -1422,32 +1427,32 @@ QUnit.test("line-height animates correctly (#13855)", function( assert ) { height + " < " + initial + " @ " + ( progress * 100 ) + "%" ); assert.ok( height > lower, "hide " + label + ": lower bound; " + height + " > " + lower + " @ " + ( progress * 100 ) + "%" ); - }); + } ); - t0 = +(new Date()); + t0 = +( new Date() ); animated.stop( true, true ).hide() .animate( { "line-height": "show" }, longDuration, "linear" ); - setTimeout(function() { - var progress = ( (new Date()) - t0 ) / longDuration; + setTimeout( function() { + var progress = ( ( new Date() ) - t0 ) / longDuration; - animated.each(function( i ) { + animated.each( function( i ) { var label = jQuery.text( this ), initial = initialHeight[ i ], height = jQuery( this ).height(), upper = initial * progress * tolerance; assert.ok( height < upper, "show " + label + ": upper bound; " + height + " < " + upper + " @ " + ( progress * 100 ) + "%" ); - }); + } ); animated.stop( true, true ); }, shortDuration ); -clock.tick(shortDuration); +clock.tick( shortDuration ); }, shortDuration ); -clock.tick(shortDuration); +clock.tick( shortDuration ); }, 50 ); clock.tick( 50 ); -}); +} ); // Start 1.8 Animation tests QUnit.test( "jQuery.Animation( object, props, opts )", function( assert ) { @@ -1465,23 +1470,23 @@ QUnit.test( "jQuery.Animation( object, props, opts )", function( assert ) { "width": 200 }; - animation = jQuery.Animation( testObject, testDest, { "duration": 1 }); - animation.done(function() { + animation = jQuery.Animation( testObject, testDest, { "duration": 1 } ); + animation.done( function() { for ( var prop in testDest ) { assert.equal( testObject[ prop ], testDest[ prop ], "Animated: " + prop ); } - animation.done(function() { + animation.done( function() { assert.deepEqual( testObject, testDest, "No unexpected properties" ); - }); - }); + } ); + } ); this.clock.tick( 10 ); -}); +} ); QUnit.test( "Animate Option: step: function( percent, tween )", function( assert ) { assert.expect( 1 ); var counter = {}; - jQuery( "#foo" ).animate({ + jQuery( "#foo" ).animate( { prop1: 1, prop2: 2, prop3: 3 @@ -1489,37 +1494,38 @@ 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; } - }).queue( function( next ) { + } ).queue( function( next ) { assert.deepEqual( counter, { - prop1: [0, 1], - prop2: [0, 2], - prop3: [0, 3] - }, "Step function was called once at 0% and once at 100% for each property"); + prop1: [ 0, 1 ], + prop2: [ 0, 2 ], + prop3: [ 0, 3 ] + }, "Step function was called once at 0% and once at 100% for each property" ); next(); - }); + } ); this.clock.tick( 10 ); -}); +} ); QUnit.test( "Animate callbacks have correct context", function( assert ) { assert.expect( 2 ); var foo = jQuery( "#foo" ); - foo.animate({ + foo.animate( { height: 10 }, 10, function() { assert.equal( foo[ 0 ], this, "Complete callback after stop(true) `this` is element" ); - }).stop( true, true ); - foo.animate({ + } ).stop( true, true ); + foo.animate( { height: 100 }, 10, function() { assert.equal( foo[ 0 ], this, "Complete callback `this` is element" ); - }); + } ); this.clock.tick( 10 ); -}); +} ); QUnit.test( "User supplied callback called after show when fx off (#8892)", function( assert ) { assert.expect( 2 ); @@ -1532,10 +1538,10 @@ QUnit.test( "User supplied callback called after show when fx off (#8892)", func foo.fadeOut( 500, function() { assert.ok( jQuery( this ).is( ":hidden" ), "Element is hidden in callback" ); jQuery.fx.off = false; - }); - }); + } ); + } ); this.clock.tick( 1000 ); -}); +} ); QUnit.test( "animate should set display for disconnected nodes", function( assert ) { assert.expect( 20 ); @@ -1548,18 +1554,18 @@ QUnit.test( "animate should set display for disconnected nodes", function( asser fadeTo: [ "fast", 0.5 ], slideDown: [ "fast" ], show: [ 1 ], - animate: [{ width: "show" }] + animate: [ { width: "show" } ] }, - $divEmpty = jQuery("<div/>"), - $divTest = jQuery("<div>test</div>"), - $divNone = jQuery("<div style='display: none;'/>"), - $divInline = jQuery("<div style='display: inline;'/>"), - nullParentDisplay = $divEmpty.css("display"), - underFragmentDisplay = $divTest.css("display"), + $divEmpty = jQuery( "<div/>" ), + $divTest = jQuery( "<div>test</div>" ), + $divNone = jQuery( "<div style='display: none;'/>" ), + $divInline = jQuery( "<div style='display: inline;'/>" ), + nullParentDisplay = $divEmpty.css( "display" ), + underFragmentDisplay = $divTest.css( "display" ), clock = this.clock; assert.strictEqual( $divEmpty[ 0 ].parentNode, null, "Setup: element with null parentNode" ); - assert.strictEqual( ($divTest[ 0 ].parentNode || {}).nodeType, 11, "Setup: element under fragment" ); + assert.strictEqual( ( $divTest[ 0 ].parentNode || {} ).nodeType, 11, "Setup: element under fragment" ); assert.strictEqual( $divEmpty.show()[ 0 ].style.display, "", "set display with show() for element with null parentNode" ); @@ -1573,54 +1579,54 @@ QUnit.test( "animate should set display for disconnected nodes", function( asser QUnit.expectJqData( env, $divNone[ 0 ], "olddisplay" ); jQuery.each( methods, function( name, opt ) { - jQuery.fn[ name ].apply( jQuery("<div/>"), opt.concat( [ function() { + jQuery.fn[ name ].apply( jQuery( "<div/>" ), opt.concat( [ function() { assert.strictEqual( jQuery( this ).css( "display" ), nullParentDisplay, "." + name + " block with null parentNode" ); } ] ) ); - jQuery.fn[ name ].apply( jQuery("<div>test</div>"), opt.concat( [ function() { + jQuery.fn[ name ].apply( jQuery( "<div>test</div>" ), opt.concat( [ function() { assert.strictEqual( jQuery( this ).css( "display" ), underFragmentDisplay, "." + name + " block under fragment" ); } ] ) ); - }); + } ); clock.tick( 400 ); -}); +} ); -QUnit.test("Animation callback should not show animated element as :animated (#7157)", function( assert ) { +QUnit.test( "Animation callback should not show animated element as :animated (#7157)", function( assert ) { assert.expect( 1 ); var foo = jQuery( "#foo" ); - foo.animate({ + foo.animate( { opacity: 0 }, 100, function() { - assert.ok( !foo.is(":animated"), "The element is not animated" ); - }); + assert.ok( !foo.is( ":animated" ), "The element is not animated" ); + } ); this.clock.tick( 100 ); -}); +} ); -QUnit.test("Initial step callback should show element as :animated (#14623)", function( assert ) { +QUnit.test( "Initial step callback should show element as :animated (#14623)", function( assert ) { assert.expect( 1 ); var foo = jQuery( "#foo" ); - foo.animate({ + foo.animate( { opacity: 0 }, { duration: 100, step: function() { - assert.ok( foo.is(":animated"), "The element matches :animated inside step function" ); + assert.ok( foo.is( ":animated" ), "The element matches :animated inside step function" ); } - }); + } ); this.clock.tick( 1 ); foo.stop(); -}); +} ); QUnit.test( "hide called on element within hidden parent should set display to none (#10045)", function( assert ) { assert.expect( 3 ); - var hidden = jQuery(".hidden"), - elems = jQuery("<div>hide</div><div>hide0</div><div>hide1</div>"); + var hidden = jQuery( ".hidden" ), + elems = jQuery( "<div>hide</div><div>hide0</div><div>hide1</div>" ); hidden.append( elems ); @@ -1628,25 +1634,25 @@ QUnit.test( "hide called on element within hidden parent should set display to n elems.eq( 0 ).hide(), elems.eq( 1 ).hide( 0 ), elems.eq( 2 ).hide( 1 ) - ).done(function() { + ).done( function() { assert.strictEqual( elems.get( 0 ).style.display, "none", "hide() called on element within hidden parent should set display to none" ); assert.strictEqual( elems.get( 1 ).style.display, "none", "hide( 0 ) called on element within hidden parent should set display to none" ); assert.strictEqual( elems.get( 2 ).style.display, "none", "hide( 1 ) called on element within hidden parent should set display to none" ); elems.remove(); - }); + } ); this.clock.tick( 10 ); -}); +} ); QUnit.test( "hide, fadeOut and slideUp called on element width height and width = 0 should set display to none", function( assert ) { assert.expect( 5 ); - var foo = jQuery("#foo"), + var foo = jQuery( "#foo" ), i = 0, elems = jQuery(); for ( ; i < 5; i++ ) { - elems = elems.add("<div style='width:0;height:0;'></div>"); + elems = elems.add( "<div style='width:0;height:0;'></div>" ); } foo.append( elems ); @@ -1657,7 +1663,7 @@ QUnit.test( "hide, fadeOut and slideUp called on element width height and width elems.eq( 2 ).hide( 1 ), elems.eq( 3 ).fadeOut(), elems.eq( 4 ).slideUp() - ).done(function() { + ).done( function() { assert.strictEqual( elems.get( 0 ).style.display, "none", "hide() called on element width height and width = 0 should set display to none" ); assert.strictEqual( elems.get( 1 ).style.display, "none", "hide( jQuery.noop ) called on element width height and width = 0 should set display to none" ); @@ -1665,24 +1671,24 @@ QUnit.test( "hide, fadeOut and slideUp called on element width height and width assert.strictEqual( elems.get( 3 ).style.display, "none", "fadeOut() called on element width height and width = 0 should set display to none" ); assert.strictEqual( elems.get( 4 ).style.display, "none", "slideUp() called on element width height and width = 0 should set display to none" ); - }); + } ); this.clock.tick( 400 ); -}); +} ); QUnit.test( "hide should not leave hidden inline elements visible (#14848)", function( assert ) { assert.expect( 2 ); - var el = jQuery("#simon1"); + var el = jQuery( "#simon1" ); el.hide( 1, function() { assert.equal( el.css( "display" ), "none", "hidden" ); el.hide( 1, function() { assert.equal( el.css( "display" ), "none", "still hidden" ); - }); - }); + } ); + } ); this.clock.tick( 100 ); -}); +} ); QUnit.test( "Handle queue:false promises", function( assert ) { assert.expect( 10 ); @@ -1690,7 +1696,7 @@ QUnit.test( "Handle queue:false promises", function( assert ) { var foo = jQuery( "#foo" ).clone().addBack(), step = 1; - foo.animate({ + foo.animate( { top: 1 }, { duration: 10, @@ -1698,7 +1704,7 @@ QUnit.test( "Handle queue:false promises", function( assert ) { complete: function() { assert.ok( step++ <= 2, "Step one or two" ); } - }).animate({ + } ).animate( { bottom: 1 }, { duration: 10, @@ -1706,13 +1712,13 @@ QUnit.test( "Handle queue:false promises", function( assert ) { assert.ok( step > 2 && step < 5, "Step three or four" ); step++; } - }); + } ); this.clock.tick( 10 ); foo.promise().done( function() { assert.equal( step++, 5, "steps 1-5: queue:false then queue:fx done" ); - foo.animate({ + foo.animate( { top: 10 }, { duration: 10, @@ -1720,7 +1726,7 @@ QUnit.test( "Handle queue:false promises", function( assert ) { assert.ok( step > 5 && step < 8, "Step six or seven" ); step++; } - }).animate({ + } ).animate( { bottom: 10 }, { duration: 10, @@ -1729,20 +1735,20 @@ QUnit.test( "Handle queue:false promises", function( assert ) { assert.ok( step > 7 && step < 10, "Step eight or nine" ); step++; } - }).promise().done( function() { + } ).promise().done( function() { assert.equal( step++, 10, "steps 6-10: queue:fx then queue:false" ); - }); + } ); - }); + } ); this.clock.tick( 10 ); -}); +} ); QUnit.test( "multiple unqueued and promise", function( assert ) { assert.expect( 4 ); var foo = jQuery( "#foo" ), step = 1; - foo.animate({ + foo.animate( { marginLeft: 300 }, { duration: 500, @@ -1750,7 +1756,7 @@ QUnit.test( "multiple unqueued and promise", function( assert ) { complete: function() { assert.strictEqual( step++, 2, "Step 2" ); } - }).animate({ + } ).animate( { top: 100 }, { duration: 1000, @@ -1758,54 +1764,55 @@ QUnit.test( "multiple unqueued and promise", function( assert ) { complete: function() { assert.strictEqual( step++, 3, "Step 3" ); } - }).animate({}, { + } ).animate( {}, { duration: 2000, queue: false, complete: function() { + // no properties is a non-op and finishes immediately assert.strictEqual( step++, 1, "Step 1" ); } - }).promise().done( function() { + } ).promise().done( function() { assert.strictEqual( step++, 4, "Step 4" ); - }); + } ); this.clock.tick( 1000 ); -}); +} ); QUnit.test( "animate does not change start value for non-px animation (#7109)", function( assert ) { assert.expect( 1 ); - var parent = jQuery( "<div><div></div></div>" ).css({ width: 284, height: 1 }).appendTo( "#qunit-fixture" ), - child = parent.children().css({ fontSize: "98.6in", width: "0.01em", height: 1 }), + var parent = jQuery( "<div><div></div></div>" ).css( { width: 284, height: 1 } ).appendTo( "#qunit-fixture" ), + child = parent.children().css( { fontSize: "98.6in", width: "0.01em", height: 1 } ), actual = parseFloat( child.css( "width" ) ), computed = []; - child.animate({ width: "0%" }, { + child.animate( { width: "0%" }, { duration: 1, step: function() { computed.push( parseFloat( child.css( "width" ) ) ); } - }).queue( function( next ) { + } ).queue( function( next ) { var ratio = computed[ 0 ] / actual; - assert.ok( ratio > 0.9 && ratio < 1.1 , "Starting width was close enough" ); + assert.ok( ratio > 0.9 && ratio < 1.1, "Starting width was close enough" ); next(); parent.remove(); - }); + } ); this.clock.tick( 10 ); -}); +} ); QUnit.test( "non-px animation handles non-numeric start (#11971)", function( assert ) { assert.expect( 2 ); - var foo = jQuery("#foo"), - initial = foo.css("backgroundPositionX"); + var foo = jQuery( "#foo" ), + initial = foo.css( "backgroundPositionX" ); if ( !initial ) { - assert.expect(1); + assert.expect( 1 ); assert.ok( true, "Style property not understood" ); return; } - foo.animate({ backgroundPositionX: "42%" }, { + foo.animate( { backgroundPositionX: "42%" }, { duration: 1, progress: function( anim, percent ) { if ( percent ) { @@ -1821,14 +1828,14 @@ QUnit.test( "non-px animation handles non-numeric start (#11971)", function( ass done: function() { assert.equal( jQuery.style( this, "backgroundPositionX" ), "42%", "End reached" ); } - }); + } ); this.clock.tick( 10 ); -}); +} ); -QUnit.test("Animation callbacks (#11797)", function( assert ) { +QUnit.test( "Animation callbacks (#11797)", function( assert ) { assert.expect( 15 ); - var targets = jQuery("#foo").children(), + var targets = jQuery( "#foo" ).children(), done = false, expectedProgress = 0; @@ -1850,12 +1857,12 @@ QUnit.test("Animation callbacks (#11797)", function( assert ) { assert.ok( true, "empty: always" ); done = true; } - }); + } ); assert.ok( done, "empty: done immediately" ); done = false; - targets.eq( 1 ).animate({ + targets.eq( 1 ).animate( { opacity: 0 }, { duration: 1, @@ -1875,11 +1882,11 @@ QUnit.test("Animation callbacks (#11797)", function( assert ) { assert.ok( true, "stopped: always" ); done = true; } - }).stop(); + } ).stop(); assert.ok( done, "stopped: stopped immediately" ); - targets.eq( 2 ).animate({ + targets.eq( 2 ).animate( { opacity: 0 }, { duration: 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++; }, @@ -1904,16 +1913,16 @@ QUnit.test("Animation callbacks (#11797)", function( assert ) { always: function() { assert.ok( true, "async: always" ); } - }); + } ); this.clock.tick( 10 ); -}); +} ); QUnit.test( "Animate properly sets overflow hidden when animating width/height (#12117)", function( assert ) { assert.expect( 8 ); jQuery.each( [ "height", "width" ], function( _, prop ) { jQuery.each( [ 100, 0 ], function( _, value ) { - var div = jQuery("<div>").css( "overflow", "auto" ), + var div = jQuery( "<div>" ).css( "overflow", "auto" ), props = {}; props[ prop ] = value; div.animate( props, 1 ); @@ -1922,24 +1931,24 @@ QUnit.test( "Animate properly sets overflow hidden when animating width/height ( div.stop(); assert.equal( div.css( "overflow" ), "auto", "overflow: auto restored after animating " + prop + " to " + value ); - }); - }); -}); + } ); + } ); +} ); QUnit.test( "Each tick of the timer loop uses a fresh time (#12837)", function( assert ) { var lastVal, - tmp = jQuery({ + tmp = jQuery( { test: 0 - }); + } ); assert.expect( 3 ); - tmp.animate({ + tmp.animate( { test: 100 }, { step: function( p, fx ) { assert.ok( fx.now !== lastVal, "Current value is not the last value: " + lastVal + " - " + fx.now ); lastVal = fx.now; } - }); + } ); this.clock.tick( 1 ); // now that we have a new time, run another tick @@ -1949,7 +1958,7 @@ QUnit.test( "Each tick of the timer loop uses a fresh time (#12837)", function( jQuery.fx.tick(); tmp.stop(); -}); +} ); QUnit.test( "Animations with 0 duration don't ease (#12273)", function( assert ) { assert.expect( 1 ); @@ -1958,7 +1967,7 @@ QUnit.test( "Animations with 0 duration don't ease (#12273)", function( assert ) assert.ok( false, "Called easing" ); }; - jQuery( "#foo" ).animate({ + jQuery( "#foo" ).animate( { height: 100 }, { duration: 0, @@ -1966,12 +1975,13 @@ QUnit.test( "Animations with 0 duration don't ease (#12273)", function( assert ) complete: function() { assert.equal( jQuery( this ).height(), 100, "Height is 100" ); } - }); + } ); delete jQuery.easing.test; -}); +} ); + +jQuery.map( [ "toggle", "slideToggle", "fadeToggle" ], function( method ) { -jQuery.map([ "toggle", "slideToggle", "fadeToggle" ], function ( method ) { // this test would look a lot better if we were using something to override // the default timers var duration = 1500; @@ -1979,7 +1989,7 @@ jQuery.map([ "toggle", "slideToggle", "fadeToggle" ], function ( method ) { function secondToggle() { var stopped = parseFloat( element.css( check ) ); tested = false; - element[ method ]({ + element[ method ]( { duration: duration, step: function( p, fx ) { if ( fx.pos > 0.1 && fx.prop === check && !tested ) { @@ -1989,17 +1999,17 @@ jQuery.map([ "toggle", "slideToggle", "fadeToggle" ], function ( method ) { element.stop(); } } - }); + } ); } var tested, original, check = method === "slideToggle" ? "height" : "opacity", - element = jQuery("#foo").height( 200 ); + element = jQuery( "#foo" ).height( 200 ); assert.expect( 4 ); - element[ method ]({ + element[ method ]( { duration: duration, easing: "linear", step: function( p, fx ) { @@ -2012,16 +2022,17 @@ jQuery.map([ "toggle", "slideToggle", "fadeToggle" ], function ( method ) { } }, always: secondToggle - }); + } ); + //FIXME figure out why 470 this.clock.tick( 470 ); - }); -}); + } ); +} ); QUnit.test( "jQuery.fx.start & jQuery.fx.stop hook points", function( assert ) { var oldStart = jQuery.fx.start, oldStop = jQuery.fx.stop, - foo = jQuery({ foo: 0 }); + foo = jQuery( { foo: 0 } ); assert.expect( 3 ); @@ -2033,17 +2044,19 @@ QUnit.test( "jQuery.fx.start & jQuery.fx.stop hook points", function( assert ) { }; // calls start - foo.animate({ foo: 1 }, { queue: false }); + foo.animate( { foo: 1 }, { queue: false } ); + // calls start - foo.animate({ foo: 2 }, { queue: false }); + foo.animate( { foo: 2 }, { queue: false } ); foo.stop(); + // calls stop jQuery.fx.tick(); // cleanup jQuery.fx.start = oldStart; jQuery.fx.stop = oldStop; -}); +} ); QUnit.test( ".finish() completes all queued animations", function( assert ) { var animations = { @@ -2052,31 +2065,33 @@ QUnit.test( ".finish() completes all queued animations", function( assert ) { height: 100, width: 100 }, - div = jQuery("<div>"); + div = jQuery( "<div>" ); assert.expect( 11 ); jQuery.each( animations, function( prop, value ) { var anim = {}; anim[ prop ] = value; + // the delay shouldn't matter at all! div.css( prop, 1 ).animate( anim, function() { assert.ok( true, "Called animation callback for " + prop ); - }).delay( 100 ); - }); + } ).delay( 100 ); + } ); assert.equal( div.queue().length, 8, "8 animations in the queue" ); div.finish(); jQuery.each( animations, function( prop, value ) { assert.equal( parseFloat( div.css( prop ) ), value, prop + " finished at correct value" ); - }); + } ); assert.equal( div.queue().length, 0, "empty queue when done" ); - assert.equal( div.is(":animated"), false, ":animated doesn't match" ); + assert.equal( div.is( ":animated" ), false, ":animated doesn't match" ); // cleanup div.remove(); + // leaves a "shadow timer" which does nothing around, need to force a tick jQuery.fx.tick(); -}); +} ); QUnit.test( ".finish( false ) - unqueued animations", function( assert ) { var animations = { @@ -2085,7 +2100,7 @@ QUnit.test( ".finish( false ) - unqueued animations", function( assert ) { height: 100, width: 100 }, - div = jQuery("<div>"); + div = jQuery( "<div>" ); assert.expect( 10 ); @@ -2097,20 +2112,21 @@ QUnit.test( ".finish( false ) - unqueued animations", function( assert ) { complete: function() { assert.ok( true, "Called animation callback for " + prop ); } - }); - }); + } ); + } ); assert.equal( div.queue().length, 0, "0 animations in the queue" ); div.finish( false ); jQuery.each( animations, function( prop, value ) { assert.equal( parseFloat( div.css( prop ) ), value, prop + " finished at correct value" ); - }); - assert.equal( div.is(":animated"), false, ":animated doesn't match" ); + } ); + assert.equal( div.is( ":animated" ), false, ":animated doesn't match" ); // cleanup div.remove(); + // leaves a "shadow timer" which does nothing around, need to force a tick jQuery.fx.tick(); -}); +} ); QUnit.test( ".finish( \"custom\" ) - custom queue animations", function( assert ) { var animations = { @@ -2119,7 +2135,7 @@ QUnit.test( ".finish( \"custom\" ) - custom queue animations", function( assert height: 100, width: 100 }, - div = jQuery("<div>"); + div = jQuery( "<div>" ); assert.expect( 11 ); @@ -2131,30 +2147,32 @@ QUnit.test( ".finish( \"custom\" ) - custom queue animations", function( assert complete: function() { assert.ok( true, "Called animation callback for " + prop ); } - }); - }); + } ); + } ); 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" ); + assert.equal( div.is( ":animated" ), true, ":animated matches" ); div.finish( "custom" ); jQuery.each( animations, function( prop, value ) { assert.equal( parseFloat( div.css( prop ) ), value, prop + " finished at correct value" ); - }); - assert.equal( div.is(":animated"), false, ":animated doesn't match" ); + } ); + assert.equal( div.is( ":animated" ), false, ":animated doesn't match" ); // cleanup div.remove(); + // leaves a "shadow timer" which does nothing around, need to force a tick jQuery.fx.tick(); -}); +} ); QUnit.test( ".finish() calls finish of custom queue functions", function( assert ) { function queueTester( next, hooks ) { hooks.stop = function( gotoEnd ) { inside++; - assert.equal( this, div[0] ); - assert.ok( gotoEnd, "hooks.stop(true) called"); + assert.equal( this, div[ 0 ] ); + assert.ok( gotoEnd, "hooks.stop(true) called" ); }; } var div = jQuery( "<div>" ), @@ -2173,15 +2191,15 @@ QUnit.test( ".finish() calls finish of custom queue functions", function( assert assert.equal( outside, 2, "2 finish callbacks" ); div.remove(); -}); +} ); QUnit.test( ".finish() is applied correctly when multiple elements were animated (#13937)", function( assert ) { assert.expect( 3 ); - var elems = jQuery("<a>0</a><a>1</a><a>2</a>"); + var elems = jQuery( "<a>0</a><a>1</a><a>2</a>" ); elems.animate( { opacity: 0 }, 1500 ).animate( { opacity: 1 }, 1500 ); - setTimeout(function() { + setTimeout( function() { elems.eq( 1 ).finish(); assert.ok( !elems.eq( 1 ).queue().length, "empty queue for .finish()ed element" ); assert.ok( elems.eq( 0 ).queue().length, "non-empty queue for preceding element" ); @@ -2190,13 +2208,13 @@ QUnit.test( ".finish() is applied correctly when multiple elements were animated }, 100 ); this.clock.tick( 1500 ); -}); +} ); QUnit.test( "slideDown() after stop() (#13483)", function( assert ) { assert.expect( 2 ); var ul = jQuery( "<ul style='height: 100px; display: block;'></ul>" ) - .appendTo("#qunit-fixture"), + .appendTo( "#qunit-fixture" ), origHeight = ul.height(), clock = this.clock; @@ -2220,10 +2238,10 @@ QUnit.test( "slideDown() after stop() (#13483)", function( assert ) { ul.remove(); clock.tick( 10 ); - }); + } ); clock.tick( 10 ); -}); +} ); QUnit.test( "Respect display value on inline elements (#14824)", function( assert ) { assert.expect( 2 ); @@ -2234,22 +2252,22 @@ QUnit.test( "Respect display value on inline elements (#14824)", function( asser jQuery( "#qunit-fixture" ).append( fromStyleSheet, fromStyleAttr ); - fromStyleSheet.slideUp(function() { + fromStyleSheet.slideUp( function() { jQuery( this ).slideDown( function() { assert.equal( jQuery( this ).css( "display" ), "block", "Respect previous display value (from stylesheet) on span element" ); - }); - }); + } ); + } ); fromStyleAttr.slideUp( function() { jQuery( this ).slideDown( function() { assert.equal( jQuery( this ).css( "display" ), "block", "Respect previous display value (from style attribute) on span element" ); - }); - }); + } ); + } ); clock.tick( 800 ); -}); +} ); QUnit.test( "jQuery.easing._default (gh-2218)", function( assert ) { assert.expect( 2 ); @@ -2261,7 +2279,7 @@ QUnit.test( "jQuery.easing._default (gh-2218)", function( assert ) { assert.equal( anim.opts.easing, jQuery.easing._default, "anim.opts.easing should be equal to jQuery.easing._default when the easing argument is not given" ); } - }) + } ) .animate( { height: "5px" }, { duration: 5, easing: "linear", @@ -2269,11 +2287,11 @@ QUnit.test( "jQuery.easing._default (gh-2218)", function( assert ) { assert.equal( anim.opts.easing, "linear", "anim.opts.easing should be equal to the easing argument" ); } - }) + } ) .stop(); this.clock.tick( 25 ); -}); +} ); QUnit.test( "jQuery.easing._default in Animation (gh-2218", function( assert ) { assert.expect( 3 ); @@ -2298,10 +2316,10 @@ QUnit.test( "jQuery.easing._default in Animation (gh-2218", function( assert ) { "Animation used custom jQuery.easing._default" ); jQuery.easing._default = defaultEasing; delete jQuery.easing.custom; - }); + } ); this.clock.tick( 10 ); -}); +} ); QUnit.test( "jQuery.easing._default in Tween (gh-2218)", function( assert ) { assert.expect( 3 ); @@ -2325,33 +2343,33 @@ QUnit.test( "jQuery.easing._default in Tween (gh-2218)", function( assert ) { "Animation used custom jQuery.easing._default" ); jQuery.easing._default = defaultEasing; delete jQuery.easing.custom; -}); +} ); QUnit.test( "Display value is correct for disconnected nodes (trac-13310)", function( assert ) { assert.expect( 3 ); - var div = jQuery("<div/>"); + var div = jQuery( "<div/>" ); - assert.equal( div.css( "display", "inline" ).hide().show().appendTo("body").css( "display" ), "inline", "Initialized display value has returned" ); + assert.equal( div.css( "display", "inline" ).hide().show().appendTo( "body" ).css( "display" ), "inline", "Initialized display value has returned" ); div.remove(); div.css( "display", "none" ).hide(); assert.equal( jQuery._data( div[ 0 ], "olddisplay" ), undefined, "olddisplay is undefined after hiding a detached and hidden element" ); div.remove(); - div.css( "display", "inline-block" ).hide().appendTo("body").fadeIn(function() { + div.css( "display", "inline-block" ).hide().appendTo( "body" ).fadeIn( function() { assert.equal( div.css( "display" ), "inline-block", "Initialized display value has returned" ); div.remove(); - }); + } ); this.clock.tick( 1000 ); -}); +} ); QUnit.test( "Show/hide/toggle and display: inline", function( assert ) { assert.expect( 40 ); var clock = this.clock; - jQuery( "<span/><div style='display:inline' title='inline div'/>" ).each(function() { + jQuery( "<span/><div style='display:inline' title='inline div'/>" ).each( function() { var completed, interrupted, N = 100, fixture = jQuery( "#qunit-fixture" ), @@ -2360,59 +2378,59 @@ QUnit.test( "Show/hide/toggle and display: inline", function( assert ) { // Animations allowed to complete completed = jQuery.map( [ - $el.clone().data({ call: "hide", done: "none" }).appendTo( fixture ).hide( N ), - $el.clone().data({ call: "toggle", done: "none" }).appendTo( fixture ).toggle( N ), - $el.clone().data({ call: "hide+show", done: "inline" }).appendTo( fixture ) + $el.clone().data( { call: "hide", done: "none" } ).appendTo( fixture ).hide( N ), + $el.clone().data( { call: "toggle", done: "none" } ).appendTo( fixture ).toggle( N ), + $el.clone().data( { call: "hide+show", done: "inline" } ).appendTo( fixture ) .hide().show( N ), - $el.clone().data({ call: "hide+toggle", done: "inline" }).appendTo( fixture ) + $el.clone().data( { call: "hide+toggle", done: "inline" } ).appendTo( fixture ) .hide().toggle( N ) ], function( $clone ) { return $clone[ 0 ]; } ); // Animations not allowed to complete interrupted = jQuery.map( [ - $el.clone().data({ call: "hide+stop" }).appendTo( fixture ).hide( N ), - $el.clone().data({ call: "toggle+stop" }).appendTo( fixture ).toggle( N ), - $el.clone().data({ call: "hide+show+stop" }).appendTo( fixture ).hide().show( N ), - $el.clone().data({ call: "hide+toggle+stop" }).appendTo( fixture ).hide().toggle( N ) + $el.clone().data( { call: "hide+stop" } ).appendTo( fixture ).hide( N ), + $el.clone().data( { call: "toggle+stop" } ).appendTo( fixture ).toggle( N ), + $el.clone().data( { call: "hide+show+stop" } ).appendTo( fixture ).hide().show( N ), + $el.clone().data( { call: "hide+toggle+stop" } ).appendTo( fixture ).hide().toggle( N ) ], function( $clone ) { return $clone[ 0 ]; } ); // All elements should be inline-block during the animation clock.tick( N / 2 ); - jQuery( completed ).each(function() { + jQuery( completed ).each( function() { var $el = jQuery( this ), call = $el.data( "call" ); assert.strictEqual( $el.css( "display" ), "inline-block", kind + " display during " + call ); - }); + } ); // Interrupted elements should remain inline-block jQuery( interrupted ).stop(); clock.tick( N / 2 ); - jQuery( interrupted ).each(function() { + jQuery( interrupted ).each( function() { var $el = jQuery( this ), call = $el.data( "call" ); assert.strictEqual( $el.css( "display" ), "inline-block", kind + " display after " + call ); - }); + } ); // Completed elements should not remain inline-block clock.tick( N / 2 ); - jQuery( completed ).each(function() { + jQuery( completed ).each( function() { var $el = jQuery( this ), call = $el.data( "call" ), display = $el.data( "done" ); assert.strictEqual( $el.css( "display" ), display, kind + " display after " + call ); - }); + } ); // A post-animation toggle should not make any element inline-block completed = jQuery( completed.concat( interrupted ) ); completed.toggle( N / 2 ); clock.tick( N ); - completed.each(function() { + completed.each( function() { var $el = jQuery( this ), call = $el.data( "call" ); assert.ok( $el.css( "display" ) !== "inline-block", kind + " display is not inline-block after " + call + "+toggle" ); - }); - }); -}); + } ); + } ); +} ); -})(); +} )(); diff --git a/test/unit/event.js b/test/unit/event.js index 8b0976721..6f4e6824e 100644 --- a/test/unit/event.js +++ b/test/unit/event.js @@ -3,28 +3,28 @@ QUnit.module( "event", { document.body.focus(); }, teardown: moduleTeardown -}); +} ); -QUnit.test("on() with non-null,defined data", function( assert ) { +QUnit.test( "on() with non-null,defined data", function( assert ) { - assert.expect(2); + assert.expect( 2 ); var handler = function( event, data ) { assert.equal( data, 0, "non-null, defined data (zero) is correctly passed" ); }; - jQuery("#foo").on("foo.on", handler); - jQuery("div").on("foo.delegate", "#foo", handler); + jQuery( "#foo" ).on( "foo.on", handler ); + jQuery( "div" ).on( "foo.delegate", "#foo", handler ); - jQuery("#foo").trigger("foo", 0); + jQuery( "#foo" ).trigger( "foo", 0 ); - jQuery("#foo").off("foo.on", handler); - jQuery("div").off("foo.delegate", "#foo"); + jQuery( "#foo" ).off( "foo.on", handler ); + jQuery( "div" ).off( "foo.delegate", "#foo" ); -}); +} ); -QUnit.test("Handler changes and .trigger() order", function( assert ) { - assert.expect(1); +QUnit.test( "Handler changes and .trigger() order", function( assert ) { + assert.expect( 1 ); var markup = jQuery( "<div><div><p><span><b class=\"a\">b</b></span></p></div></div>" @@ -34,154 +34,154 @@ QUnit.test("Handler changes and .trigger() order", function( assert ) { markup .find( "*" ).addBack().on( "click", function() { path += this.nodeName.toLowerCase() + " "; - }) + } ) .filter( "b" ).on( "click", function( e ) { + // Removing span should not stop propagation to original parents if ( e.target === this ) { - jQuery(this).parent().remove(); + jQuery( this ).parent().remove(); } - }); + } ); markup.find( "b" ).trigger( "click" ); assert.equal( path, "b p div div ", "Delivered all events" ); markup.remove(); -}); +} ); -QUnit.test("on(), with data", function( assert ) { - assert.expect(4); +QUnit.test( "on(), with data", function( assert ) { + assert.expect( 4 ); var test, handler, handler2; - handler = function(event) { + handler = function( event ) { assert.ok( event.data, "on() with data, check passed data exists" ); - assert.equal( event.data["foo"], "bar", "on() with data, Check value of passed data" ); + assert.equal( event.data[ "foo" ], "bar", "on() with data, Check value of passed data" ); }; - jQuery("#firstp").on("click", {"foo": "bar"}, handler).trigger("click").off("click", handler); + jQuery( "#firstp" ).on( "click", { "foo": "bar" }, handler ).trigger( "click" ).off( "click", handler ); - assert.ok( !jQuery._data(jQuery("#firstp")[0], "events"), "Event handler unbound when using data." ); + assert.ok( !jQuery._data( jQuery( "#firstp" )[ 0 ], "events" ), "Event handler unbound when using data." ); - test = function(){}; - handler2 = function(event) { + test = function() {}; + handler2 = function( event ) { assert.equal( event.data, test, "on() with function data, Check value of passed data" ); }; - jQuery("#firstp").on("click", test, handler2).trigger("click").off("click", handler2); -}); + jQuery( "#firstp" ).on( "click", test, handler2 ).trigger( "click" ).off( "click", handler2 ); +} ); -QUnit.test("click(), with data", function( assert ) { - assert.expect(3); - var handler = function(event) { +QUnit.test( "click(), with data", function( assert ) { + assert.expect( 3 ); + var handler = function( event ) { assert.ok( event.data, "on() with data, check passed data exists" ); - assert.equal( event.data["foo"], "bar", "on() with data, Check value of passed data" ); + assert.equal( event.data[ "foo" ], "bar", "on() with data, Check value of passed data" ); }; - jQuery("#firstp").on( "click", {"foo": "bar"}, handler).trigger("click").off("click", handler); + jQuery( "#firstp" ).on( "click", { "foo": "bar" }, handler ).trigger( "click" ).off( "click", handler ); - assert.ok( !jQuery._data(jQuery("#firstp")[0], "events"), "Event handler unbound when using data." ); -}); + assert.ok( !jQuery._data( jQuery( "#firstp" )[ 0 ], "events" ), "Event handler unbound when using data." ); +} ); -QUnit.test("on(), with data, trigger with data", function( assert ) { - assert.expect(4); - var handler = function(event, data) { +QUnit.test( "on(), with data, trigger with data", function( assert ) { + assert.expect( 4 ); + var handler = function( event, data ) { assert.ok( event.data, "check passed data exists" ); assert.equal( event.data.foo, "bar", "Check value of passed data" ); assert.ok( data, "Check trigger data" ); assert.equal( data.bar, "foo", "Check value of trigger data" ); }; - jQuery("#firstp").on("click", {foo: "bar"}, handler).trigger("click", [{bar: "foo"}]).off("click", handler); -}); + jQuery( "#firstp" ).on( "click", { foo: "bar" }, handler ).trigger( "click", [ { bar: "foo" } ] ).off( "click", handler ); +} ); -QUnit.test("on(), multiple events at once", function( assert ) { - assert.expect(2); +QUnit.test( "on(), multiple events at once", function( assert ) { + assert.expect( 2 ); var handler, clickCounter = 0, mouseoverCounter = 0; - handler = function(event) { - if (event.type === "click") { + handler = function( event ) { + if ( event.type === "click" ) { clickCounter += 1; - } - else if (event.type === "mouseover") { + } else if ( event.type === "mouseover" ) { mouseoverCounter += 1; } }; - jQuery("#firstp").on("click mouseover", handler).trigger("click").trigger("mouseover"); + jQuery( "#firstp" ).on( "click mouseover", handler ).trigger( "click" ).trigger( "mouseover" ); assert.equal( clickCounter, 1, "on() with multiple events at once" ); assert.equal( mouseoverCounter, 1, "on() with multiple events at once" ); -}); +} ); -QUnit.test("on(), five events at once", function( assert ) { - assert.expect(1); +QUnit.test( "on(), five events at once", function( assert ) { + assert.expect( 1 ); var count = 0, handler = function() { count++; }; - jQuery("#firstp").on("click mouseover foo bar baz", handler) - .trigger("click").trigger("mouseover") - .trigger("foo").trigger("bar") - .trigger("baz"); + jQuery( "#firstp" ).on( "click mouseover foo bar baz", handler ) + .trigger( "click" ).trigger( "mouseover" ) + .trigger( "foo" ).trigger( "bar" ) + .trigger( "baz" ); assert.equal( count, 5, "on() five events at once" ); -}); +} ); -QUnit.test("on(), multiple events at once and namespaces", function( assert ) { - assert.expect(7); +QUnit.test( "on(), multiple events at once and namespaces", function( assert ) { + assert.expect( 7 ); var cur, div, obj = {}; - div = jQuery("<div/>").on("focusin.a", function(e) { + div = jQuery( "<div/>" ).on( "focusin.a", function( e ) { assert.equal( e.type, cur, "Verify right single event was fired." ); - }); + } ); cur = "focusin"; - div.trigger("focusin.a"); + div.trigger( "focusin.a" ); // manually clean up detached elements div.remove(); - div = jQuery("<div/>").on("click mouseover", obj, function(e) { + div = jQuery( "<div/>" ).on( "click mouseover", obj, function( e ) { assert.equal( e.type, cur, "Verify right multi event was fired." ); assert.equal( e.data, obj, "Make sure the data came in correctly." ); - }); + } ); cur = "click"; - div.trigger("click"); + div.trigger( "click" ); cur = "mouseover"; - div.trigger("mouseover"); + div.trigger( "mouseover" ); // manually clean up detached elements div.remove(); - div = jQuery("<div/>").on("focusin.a focusout.b", function(e) { + div = jQuery( "<div/>" ).on( "focusin.a focusout.b", function( e ) { assert.equal( e.type, cur, "Verify right multi event was fired." ); - }); + } ); cur = "focusin"; - div.trigger("focusin.a"); + div.trigger( "focusin.a" ); cur = "focusout"; - div.trigger("focusout.b"); + div.trigger( "focusout.b" ); // manually clean up detached elements div.remove(); -}); +} ); -QUnit.test("on(), namespace with special add", function( assert ) { - assert.expect(27); +QUnit.test( "on(), namespace with special add", function( assert ) { + assert.expect( 27 ); var i = 0, - div = jQuery("<div/>").appendTo("#qunit-fixture").on( "test", function() { + div = jQuery( "<div/>" ).appendTo( "#qunit-fixture" ).on( "test", function() { assert.ok( true, "Test event fired." ); - }); + } ); - jQuery.event.special["test"] = { + jQuery.event.special[ "test" ] = { _default: function( e, data ) { assert.equal( e.type, "test", "Make sure we're dealing with a test event." ); assert.ok( data, "And that trigger data was passed." ); - assert.strictEqual( e.target, div[0], "And that the target is correct." ); + assert.strictEqual( e.target, div[ 0 ], "And that the target is correct." ); assert.equal( this, window, "And that the context is correct." ); }, setup: function() {}, @@ -202,13 +202,13 @@ QUnit.test("on(), namespace with special add", function( assert ) { div.on( "test.a", { x: 1 }, function( e ) { assert.ok( !!e.xyz, "Make sure that the data is getting passed through." ); - assert.equal( e.data["x"], 1, "Make sure data is attached properly." ); - }); + assert.equal( e.data[ "x" ], 1, "Make sure data is attached properly." ); + } ); div.on( "test.b", { x: 2 }, function( e ) { assert.ok( !!e.xyz, "Make sure that the data is getting passed through." ); - assert.equal( e.data["x"], 2, "Make sure data is attached properly." ); - }); + assert.equal( e.data[ "x" ], 2, "Make sure data is attached properly." ); + } ); // Should trigger 5 div.trigger( "test", 33.33 ); @@ -220,61 +220,63 @@ QUnit.test("on(), namespace with special add", function( assert ) { div.trigger( "test.b", { year: 1982 } ); // Should trigger 4 - div.off("test"); + div.off( "test" ); - div = jQuery("<div/>").on( "test", function() { + div = jQuery( "<div/>" ).on( "test", function() { assert.ok( true, "Test event fired." ); - }); + } ); // Should trigger 2 - div.appendTo("#qunit-fixture").remove(); + div.appendTo( "#qunit-fixture" ).remove(); - delete jQuery.event.special["test"]; -}); + delete jQuery.event.special[ "test" ]; +} ); -QUnit.test("on(), no data", function( assert ) { - assert.expect(1); - var handler = function(event) { +QUnit.test( "on(), no data", function( assert ) { + assert.expect( 1 ); + var handler = function( event ) { ok ( !event.data, "Check that no data is added to the event object" ); }; - jQuery("#firstp").on("click", handler).trigger("click"); -}); + jQuery( "#firstp" ).on( "click", handler ).trigger( "click" ); +} ); -QUnit.test("on/one/off(Object)", function( assert ){ - assert.expect(6); +QUnit.test( "on/one/off(Object)", function( assert ) { + assert.expect( 6 ); var $elem, clickCounter = 0, mouseoverCounter = 0; - function handler(event) { - if (event.type === "click") { + function handler( event ) { + if ( event.type === "click" ) { clickCounter++; - } else if (event.type === "mouseover") { + } else if ( event.type === "mouseover" ) { mouseoverCounter++; } } - function handlerWithData(event) { - if (event.type === "click") { + function handlerWithData( event ) { + if ( event.type === "click" ) { clickCounter += event.data; - } else if (event.type === "mouseover") { + } else if ( event.type === "mouseover" ) { mouseoverCounter += event.data; } } - function trigger(){ - $elem.trigger("click").trigger("mouseover"); + function trigger() { + $elem.trigger( "click" ).trigger( "mouseover" ); } - $elem = jQuery("#firstp") + $elem = jQuery( "#firstp" ) + // Regular bind - .on({ + .on( { "click":handler, "mouseover":handler - }) + } ) + // Bind with data - .one({ + .one( { "click":handlerWithData, "mouseover":handlerWithData }, 2 ); @@ -288,24 +290,24 @@ QUnit.test("on/one/off(Object)", function( assert ){ assert.equal( clickCounter, 4, "on(Object)" ); assert.equal( mouseoverCounter, 4, "on(Object)" ); - jQuery("#firstp").off({ + jQuery( "#firstp" ).off( { "click":handler, "mouseover":handler - }); + } ); trigger(); assert.equal( clickCounter, 4, "on(Object)" ); assert.equal( mouseoverCounter, 4, "on(Object)" ); -}); +} ); -QUnit.test("on/off(Object), on/off(Object, String)", function( assert ) { - assert.expect(6); +QUnit.test( "on/off(Object), on/off(Object, String)", function( assert ) { + assert.expect( 6 ); var events, clickCounter = 0, mouseoverCounter = 0, - $p = jQuery("#firstp"), - $a = $p.find("a").eq(0); + $p = jQuery( "#firstp" ), + $a = $p.find( "a" ).eq( 0 ); events = { "click": function( event ) { @@ -317,7 +319,7 @@ QUnit.test("on/off(Object), on/off(Object, String)", function( assert ) { }; function trigger() { - $a.trigger("click").trigger("mouseover"); + $a.trigger( "click" ).trigger( "mouseover" ); } jQuery( document ).on( events, "#firstp a" ); @@ -338,41 +340,41 @@ QUnit.test("on/off(Object), on/off(Object, String)", function( assert ) { trigger(); assert.equal( clickCounter, 4, "off" ); assert.equal( mouseoverCounter, 4, "off" ); -}); +} ); -QUnit.test("on immediate propagation", function( assert ) { - assert.expect(2); +QUnit.test( "on immediate propagation", function( assert ) { + assert.expect( 2 ); var lastClick, - $p = jQuery("#firstp"), - $a = $p.find("a").eq(0); + $p = jQuery( "#firstp" ), + $a = $p.find( "a" ).eq( 0 ); lastClick = ""; - jQuery( document ).on( "click", "#firstp a", function(e) { + jQuery( document ).on( "click", "#firstp a", function( e ) { lastClick = "click1"; e.stopImmediatePropagation(); - }); + } ); jQuery( document ).on( "click", "#firstp a", function() { lastClick = "click2"; - }); + } ); $a.trigger( "click" ); assert.equal( lastClick, "click1", "on stopImmediatePropagation" ); jQuery( document ).off( "click", "#firstp a" ); lastClick = ""; - $p.on( "click", "a", function(e) { + $p.on( "click", "a", function( e ) { lastClick = "click1"; e.stopImmediatePropagation(); - }); + } ); $p.on( "click", "a", function() { lastClick = "click2"; - }); + } ); $a.trigger( "click" ); assert.equal( lastClick, "click1", "on stopImmediatePropagation" ); $p.off( "click", "**" ); -}); +} ); -QUnit.test("on bubbling, isDefaultPrevented, stopImmediatePropagation", function( assert ) { +QUnit.test( "on bubbling, isDefaultPrevented, stopImmediatePropagation", function( assert ) { assert.expect( 3 ); var $anchor2 = jQuery( "#anchor2" ), @@ -380,27 +382,29 @@ QUnit.test("on bubbling, isDefaultPrevented, stopImmediatePropagation", function neverCallMe = function() { assert.ok( false, "immediate propagation should have been stopped" ); }, - fakeClick = function($jq) { + fakeClick = function( $jq ) { + // Use a native click so we don't get jQuery simulated bubbling var e = document.createEvent( "MouseEvents" ); e.initEvent( "click", true, true ); $jq[ 0 ].dispatchEvent( e ); }; - $anchor2.on( "click", function(e) { + $anchor2.on( "click", function( e ) { e.preventDefault(); - }); + } ); $main.on( "click", "#foo", function( e ) { assert.equal( e.isDefaultPrevented(), true, "isDefaultPrevented true passed to bubbled event" ); - }); + } ); fakeClick( $anchor2 ); $anchor2.off( "click" ); $main.off( "click", "**" ); $anchor2.on( "click", function() { + // Let the default action occur - }); - $main.on("click", "#foo", function(e) { + } ); + $main.on( "click", "#foo", function( e ) { assert.equal( e.isDefaultPrevented(), false, "isDefaultPrevented false passed to bubbled event" ); - }); + } ); fakeClick( $anchor2 ); $anchor2.off( "click" ); $main.off( "click", "**" ); @@ -414,91 +418,91 @@ QUnit.test("on bubbling, isDefaultPrevented, stopImmediatePropagation", function $anchor2.on( "click", function( e ) { e.stopImmediatePropagation(); assert.ok( true, "anchor was clicked and prop stopped" ); - }); - $anchor2[0].addEventListener( "click", neverCallMe, false ); + } ); + $anchor2[ 0 ].addEventListener( "click", neverCallMe, false ); fakeClick( $anchor2 ); - $anchor2[0].removeEventListener( "click", neverCallMe ); + $anchor2[ 0 ].removeEventListener( "click", neverCallMe ); } -}); +} ); -QUnit.test("on(), iframes", function( assert ) { +QUnit.test( "on(), iframes", function( assert ) { assert.expect( 1 ); // events don't work with iframes, see #939 - this test fails in IE because of contentDocument - var doc = jQuery("#loadediframe").contents(); + var doc = jQuery( "#loadediframe" ).contents(); - jQuery("div", doc).on("click", function() { + jQuery( "div", doc ).on( "click", function() { assert.ok( true, "Binding to element inside iframe" ); - }).trigger("click").off("click"); -}); + } ).trigger( "click" ).off( "click" ); +} ); -QUnit.test("on(), trigger change on select", function( assert ) { - assert.expect(5); +QUnit.test( "on(), trigger change on select", function( assert ) { + assert.expect( 5 ); var counter = 0; - function selectOnChange(event) { + function selectOnChange( event ) { assert.equal( event.data, counter++, "Event.data is not a global event object" ); } - jQuery("#form select").each(function(i){ - jQuery(this).on("change", i, selectOnChange); - }).trigger("change"); -}); + jQuery( "#form select" ).each( function( i ) { + jQuery( this ).on( "change", i, selectOnChange ); + } ).trigger( "change" ); +} ); -QUnit.test("on(), namespaced events, cloned events", function( assert ) { +QUnit.test( "on(), namespaced events, cloned events", function( assert ) { assert.expect( 18 ); var firstp = jQuery( "#firstp" ); - firstp.on("custom.test",function(){ - assert.ok(false, "Custom event triggered"); - }); + firstp.on( "custom.test", function() { + assert.ok( false, "Custom event triggered" ); + } ); - firstp.on("click",function(e){ - assert.ok(true, "Normal click triggered"); + firstp.on( "click", function( e ) { + assert.ok( true, "Normal click triggered" ); assert.equal( e.type + e.namespace, "click", "Check that only click events trigger this fn" ); - }); + } ); - firstp.on("click.test",function(e){ + firstp.on( "click.test", function( e ) { var check = "click"; assert.ok( true, "Namespaced click triggered" ); if ( e.namespace ) { check += "test"; } assert.equal( e.type + e.namespace, check, "Check that only click/click.test events trigger this fn" ); - }); + } ); //clone(true) element to verify events are cloned correctly firstp = firstp.add( firstp.clone( true ).attr( "id", "firstp2" ).insertBefore( firstp ) ); // Trigger both bound fn (8) - firstp.trigger("click"); + firstp.trigger( "click" ); // Trigger one bound fn (4) - firstp.trigger("click.test"); + firstp.trigger( "click.test" ); // Remove only the one fn - firstp.off("click.test"); + firstp.off( "click.test" ); // Trigger the remaining fn (4) - firstp.trigger("click"); + firstp.trigger( "click" ); // Remove the remaining namespaced fn - firstp.off(".test"); + firstp.off( ".test" ); // Try triggering the custom event (0) - firstp.trigger("custom"); + firstp.trigger( "custom" ); // using contents will get comments regular, text, and comment nodes - jQuery("#nonnodes").contents().on("tester", function () { - assert.equal(this.nodeType, 1, "Check node,textnode,comment on just does real nodes" ); - }).trigger("tester"); + jQuery( "#nonnodes" ).contents().on( "tester", function() { + assert.equal( this.nodeType, 1, "Check node,textnode,comment on just does real nodes" ); + } ).trigger( "tester" ); // Make sure events stick with appendTo'd elements (which are cloned) #2027 - jQuery("<a href='#fail' class='test'>test</a>").on( "click", function(){ return false; }).appendTo("#qunit-fixture"); - assert.ok( jQuery("a.test").eq(0).triggerHandler("click") === false, "Handler is bound to appendTo'd elements" ); -}); + jQuery( "<a href='#fail' class='test'>test</a>" ).on( "click", function() { return false; } ).appendTo( "#qunit-fixture" ); + assert.ok( jQuery( "a.test" ).eq( 0 ).triggerHandler( "click" ) === false, "Handler is bound to appendTo'd elements" ); +} ); -QUnit.test("on(), multi-namespaced events", function( assert ) { - assert.expect(6); +QUnit.test( "on(), multi-namespaced events", function( assert ) { + assert.expect( 6 ); var order = [ "click.test.abc", @@ -509,120 +513,120 @@ QUnit.test("on(), multi-namespaced events", function( assert ) { "custom.test2" ]; - function check(name, msg){ + function check( name, msg ) { assert.deepEqual( name, order.shift(), msg ); } - jQuery("#firstp").on("custom.test",function() { - check("custom.test", "Custom event triggered"); - }); + jQuery( "#firstp" ).on( "custom.test", function() { + check( "custom.test", "Custom event triggered" ); + } ); - jQuery("#firstp").on("custom.test2",function() { - check("custom.test2", "Custom event triggered"); - }); + jQuery( "#firstp" ).on( "custom.test2", function() { + check( "custom.test2", "Custom event triggered" ); + } ); - jQuery("#firstp").on("click.test",function() { - check("click.test", "Normal click triggered"); - }); + jQuery( "#firstp" ).on( "click.test", function() { + check( "click.test", "Normal click triggered" ); + } ); - jQuery("#firstp").on("click.test.abc",function() { - check("click.test.abc", "Namespaced click triggered"); - }); + jQuery( "#firstp" ).on( "click.test.abc", function() { + check( "click.test.abc", "Namespaced click triggered" ); + } ); // Those would not trigger/off (#5303) - jQuery("#firstp").trigger("click.a.test"); - jQuery("#firstp").off("click.a.test"); + jQuery( "#firstp" ).trigger( "click.a.test" ); + jQuery( "#firstp" ).off( "click.a.test" ); // Trigger both bound fn (1) - jQuery("#firstp").trigger("click.test.abc"); + jQuery( "#firstp" ).trigger( "click.test.abc" ); // Trigger one bound fn (1) - jQuery("#firstp").trigger("click.abc"); + jQuery( "#firstp" ).trigger( "click.abc" ); // Trigger two bound fn (2) - jQuery("#firstp").trigger("click.test"); + jQuery( "#firstp" ).trigger( "click.test" ); // Remove only the one fn - jQuery("#firstp").off("click.abc"); + jQuery( "#firstp" ).off( "click.abc" ); // Trigger the remaining fn (1) - jQuery("#firstp").trigger("click"); + jQuery( "#firstp" ).trigger( "click" ); // Remove the remaining fn - jQuery("#firstp").off(".test"); + jQuery( "#firstp" ).off( ".test" ); // Trigger the remaining fn (1) - jQuery("#firstp").trigger("custom"); -}); + jQuery( "#firstp" ).trigger( "custom" ); +} ); -QUnit.test("namespace-only event binding is a no-op", function( assert ){ - assert.expect(2); +QUnit.test( "namespace-only event binding is a no-op", function( assert ) { + assert.expect( 2 ); - jQuery("#firstp") + jQuery( "#firstp" ) .on( ".whoops", function() { assert.ok( false, "called a namespace-only event" ); - }) + } ) .on( "whoops", function() { assert.ok( true, "called whoops" ); - }) - .trigger("whoops") // 1 - .off(".whoops") - .trigger("whoops") // 2 - .off("whoops"); -}); - -QUnit.test("Empty namespace is ignored", function( assert ){ + } ) + .trigger( "whoops" ) // 1 + .off( ".whoops" ) + .trigger( "whoops" ) // 2 + .off( "whoops" ); +} ); + +QUnit.test( "Empty namespace is ignored", function( assert ) { assert.expect( 1 ); - jQuery("#firstp") + jQuery( "#firstp" ) .on( "meow.", function( e ) { assert.equal( e.namespace, "", "triggered a namespace-less meow event" ); - }) - .trigger("meow.") - .off("meow."); -}); + } ) + .trigger( "meow." ) + .off( "meow." ); +} ); -QUnit.test("on(), with same function", function( assert ) { - assert.expect(2); +QUnit.test( "on(), with same function", function( assert ) { + assert.expect( 2 ); - var count = 0, func = function(){ + var count = 0, func = function() { count++; }; - jQuery("#liveHandlerOrder").on("foo.bar", func).on("foo.zar", func); - jQuery("#liveHandlerOrder").trigger("foo.bar"); + jQuery( "#liveHandlerOrder" ).on( "foo.bar", func ).on( "foo.zar", func ); + jQuery( "#liveHandlerOrder" ).trigger( "foo.bar" ); - assert.equal(count, 1, "Verify binding function with multiple namespaces." ); + assert.equal( count, 1, "Verify binding function with multiple namespaces." ); - jQuery("#liveHandlerOrder").off("foo.bar", func).off("foo.zar", func); - jQuery("#liveHandlerOrder").trigger("foo.bar"); + jQuery( "#liveHandlerOrder" ).off( "foo.bar", func ).off( "foo.zar", func ); + jQuery( "#liveHandlerOrder" ).trigger( "foo.bar" ); - assert.equal(count, 1, "Verify that removing events still work." ); -}); + assert.equal( count, 1, "Verify that removing events still work." ); +} ); -QUnit.test("on(), make sure order is maintained", function( assert ) { - assert.expect(1); +QUnit.test( "on(), make sure order is maintained", function( assert ) { + assert.expect( 1 ); - var elem = jQuery("#firstp"), log = [], check = []; + var elem = jQuery( "#firstp" ), log = [], check = []; - jQuery.each( new Array(100), function( i ) { - elem.on( "click", function(){ + jQuery.each( new Array( 100 ), function( i ) { + elem.on( "click", function() { log.push( i ); - }); + } ); check.push( i ); - }); + } ); - elem.trigger("click"); + elem.trigger( "click" ); - assert.equal( log.join(","), check.join(","), "Make sure order was maintained." ); + assert.equal( log.join( "," ), check.join( "," ), "Make sure order was maintained." ); - elem.off("click"); -}); + elem.off( "click" ); +} ); -QUnit.test("on(), with different this object", function( assert ) { - assert.expect(4); +QUnit.test( "on(), with different this object", function( assert ) { + assert.expect( 4 ); var thisObject = { myThis: true }, data = { myData: true }, handler1 = function() { @@ -633,367 +637,369 @@ QUnit.test("on(), with different this object", function( assert ) { assert.equal( event.data, data, "on() with different this object and data" ); }; - jQuery("#firstp") - .on("click", jQuery.proxy(handler1, thisObject)).trigger("click").off("click", handler1) - .on("click", data, jQuery.proxy(handler2, thisObject)).trigger("click").off("click", handler2); + jQuery( "#firstp" ) + .on( "click", jQuery.proxy( handler1, thisObject ) ).trigger( "click" ).off( "click", handler1 ) + .on( "click", data, jQuery.proxy( handler2, thisObject ) ).trigger( "click" ).off( "click", handler2 ); - assert.ok( !jQuery._data(jQuery("#firstp")[0], "events"), "Event handler unbound when using different this object and data." ); -}); + assert.ok( !jQuery._data( jQuery( "#firstp" )[ 0 ], "events" ), "Event handler unbound when using different this object and data." ); +} ); -QUnit.test("on(name, false), off(name, false)", function( assert ) { - assert.expect(3); +QUnit.test( "on(name, false), off(name, false)", function( assert ) { + assert.expect( 3 ); var main = 0; - jQuery("#qunit-fixture").on("click", function(){ main++; }); - jQuery("#ap").trigger("click"); + jQuery( "#qunit-fixture" ).on( "click", function() { main++; } ); + jQuery( "#ap" ).trigger( "click" ); assert.equal( main, 1, "Verify that the trigger happened correctly." ); main = 0; - jQuery("#ap").on("click", false); - jQuery("#ap").trigger("click"); + jQuery( "#ap" ).on( "click", false ); + jQuery( "#ap" ).trigger( "click" ); assert.equal( main, 0, "Verify that no bubble happened." ); main = 0; - jQuery("#ap").off("click", false); - jQuery("#ap").trigger("click"); + jQuery( "#ap" ).off( "click", false ); + jQuery( "#ap" ).trigger( "click" ); assert.equal( main, 1, "Verify that the trigger happened correctly." ); // manually clean up events from elements outside the fixture - jQuery("#qunit-fixture").off("click"); -}); + jQuery( "#qunit-fixture" ).off( "click" ); +} ); -QUnit.test("on(name, selector, false), off(name, selector, false)", function( assert ) { - assert.expect(3); +QUnit.test( "on(name, selector, false), off(name, selector, false)", function( assert ) { + assert.expect( 3 ); var main = 0; - jQuery("#qunit-fixture").on("click", "#ap", function(){ main++; }); - jQuery("#ap").trigger("click"); + jQuery( "#qunit-fixture" ).on( "click", "#ap", function() { main++; } ); + jQuery( "#ap" ).trigger( "click" ); assert.equal( main, 1, "Verify that the trigger happened correctly." ); main = 0; - jQuery("#ap").on("click", "#groups", false); - jQuery("#groups").trigger("click"); + jQuery( "#ap" ).on( "click", "#groups", false ); + jQuery( "#groups" ).trigger( "click" ); assert.equal( main, 0, "Verify that no bubble happened." ); main = 0; - jQuery("#ap").off("click", "#groups", false); - jQuery("#groups").trigger("click"); + jQuery( "#ap" ).off( "click", "#groups", false ); + jQuery( "#groups" ).trigger( "click" ); assert.equal( main, 1, "Verify that the trigger happened correctly." ); - jQuery("#qunit-fixture").off("click", "#ap"); -}); + jQuery( "#qunit-fixture" ).off( "click", "#ap" ); +} ); -QUnit.test("on()/trigger()/off() on plain object", function( assert ) { +QUnit.test( "on()/trigger()/off() on plain object", function( assert ) { assert.expect( 7 ); var events, obj = {}; // Make sure it doesn't complain when no events are found - jQuery(obj).trigger("test"); + jQuery( obj ).trigger( "test" ); // Make sure it doesn't complain when no events are found - jQuery(obj).off("test"); + jQuery( obj ).off( "test" ); - jQuery(obj).on({ + jQuery( obj ).on( { "test": function() { assert.ok( true, "Custom event run." ); }, "submit": function() { assert.ok( true, "Custom submit event run." ); } - }); + } ); - events = jQuery._data(obj, "events"); + events = jQuery._data( obj, "events" ); assert.ok( events, "Object has events bound." ); - assert.equal( obj["events"], undefined, "Events object on plain objects is not events" ); - assert.equal( obj["test"], undefined, "Make sure that test event is not on the plain object." ); - assert.equal( obj["handle"], undefined, "Make sure that the event handler is not on the plain object." ); + assert.equal( obj[ "events" ], undefined, "Events object on plain objects is not events" ); + assert.equal( obj[ "test" ], undefined, "Make sure that test event is not on the plain object." ); + assert.equal( obj[ "handle" ], undefined, "Make sure that the event handler is not on the plain object." ); // Should trigger 1 - jQuery(obj).trigger("test"); - jQuery(obj).trigger("submit"); + jQuery( obj ).trigger( "test" ); + jQuery( obj ).trigger( "submit" ); - jQuery(obj).off("test"); - jQuery(obj).off("submit"); + jQuery( obj ).off( "test" ); + jQuery( obj ).off( "submit" ); // Should trigger 0 - jQuery(obj).trigger("test"); + jQuery( obj ).trigger( "test" ); // Make sure it doesn't complain when no events are found - jQuery(obj).off("test"); + jQuery( obj ).off( "test" ); assert.equal( obj && obj[ jQuery.expando ] && obj[ jQuery.expando ][ jQuery.expando ] && - obj[ jQuery.expando ][ jQuery.expando ]["events"], undefined, "Make sure events object is removed" ); -}); + obj[ jQuery.expando ][ jQuery.expando ][ "events" ], undefined, "Make sure events object is removed" ); +} ); -QUnit.test("off(type)", function( assert ) { +QUnit.test( "off(type)", function( assert ) { assert.expect( 1 ); var message, func, - $elem = jQuery("#firstp"); + $elem = jQuery( "#firstp" ); - function error(){ + function error() { assert.ok( false, message ); } message = "unbind passing function"; - $elem.on("error1", error).off("error1", error).triggerHandler("error1"); + $elem.on( "error1", error ).off( "error1", error ).triggerHandler( "error1" ); message = "unbind all from event"; - $elem.on("error1", error).off("error1").triggerHandler("error1"); + $elem.on( "error1", error ).off( "error1" ).triggerHandler( "error1" ); message = "unbind all"; - $elem.on("error1", error).off().triggerHandler("error1"); + $elem.on( "error1", error ).off().triggerHandler( "error1" ); message = "unbind many with function"; - $elem.on("error1 error2",error) - .off("error1 error2", error ) - .trigger("error1").triggerHandler("error2"); + $elem.on( "error1 error2", error ) + .off( "error1 error2", error ) + .trigger( "error1" ).triggerHandler( "error2" ); message = "unbind many"; // #3538 - $elem.on("error1 error2", error) - .off("error1 error2") - .trigger("error1").triggerHandler("error2"); + $elem.on( "error1 error2", error ) + .off( "error1 error2" ) + .trigger( "error1" ).triggerHandler( "error2" ); message = "unbind without a type or handler"; - $elem.on("error1 error2.test",error) + $elem.on( "error1 error2.test", error ) .off() - .trigger("error1").triggerHandler("error2"); + .trigger( "error1" ).triggerHandler( "error2" ); // Should only unbind the specified function - jQuery( document ).on( "click", function(){ - assert.ok( true, "called handler after selective removal"); - }); + jQuery( document ).on( "click", function() { + assert.ok( true, "called handler after selective removal" ); + } ); func = function() {}; jQuery( document ) .on( "click", func ) .off( "click", func ) - .trigger("click") + .trigger( "click" ) .off( "click" ); -}); +} ); -QUnit.test("off(eventObject)", function( assert ) { - assert.expect(4); +QUnit.test( "off(eventObject)", function( assert ) { + assert.expect( 4 ); - var $elem = jQuery("#firstp"), + var $elem = jQuery( "#firstp" ), num; - function check( expected ){ + function check( expected ) { num = 0; - $elem.trigger("foo").triggerHandler("bar"); + $elem.trigger( "foo" ).triggerHandler( "bar" ); assert.equal( num, expected, "Check the right handlers are triggered" ); } $elem + // This handler shouldn't be unbound - .on("foo", function(){ + .on( "foo", function() { num += 1; - }) - .on("foo", function(e){ + } ) + .on( "foo", function( e ) { $elem.off( e ); num += 2; - }) + } ) + // Neither this one - .on("bar", function(){ + .on( "bar", function() { num += 4; - }); + } ); check( 7 ); check( 5 ); - $elem.off("bar"); + $elem.off( "bar" ); check( 1 ); $elem.off(); check( 0 ); -}); +} ); if ( jQuery.fn.hover ) { - QUnit.test("hover() mouseenter mouseleave", function( assert ) { - assert.expect(1); + QUnit.test( "hover() mouseenter mouseleave", function( assert ) { + assert.expect( 1 ); var times = 0, handler1 = function() { ++times; }, handler2 = function() { ++times; }; - jQuery("#firstp") - .hover(handler1, handler2) + jQuery( "#firstp" ) + .hover( handler1, handler2 ) .mouseenter().mouseleave() - .off("mouseenter", handler1) - .off("mouseleave", handler2) - .hover(handler1) + .off( "mouseenter", handler1 ) + .off( "mouseleave", handler2 ) + .hover( handler1 ) .mouseenter().mouseleave() - .off("mouseenter mouseleave", handler1) + .off( "mouseenter mouseleave", handler1 ) .mouseenter().mouseleave(); assert.equal( times, 4, "hover handlers fired" ); - }); + } ); } -QUnit.test("mouseover triggers mouseenter", function( assert ) { - assert.expect(1); +QUnit.test( "mouseover triggers mouseenter", function( assert ) { + assert.expect( 1 ); var count = 0, - elem = jQuery("<a />"); - elem.on( "mouseenter", function () { + elem = jQuery( "<a />" ); + elem.on( "mouseenter", function() { count++; - }); - elem.trigger("mouseover"); - assert.equal(count, 1, "make sure mouseover triggers a mouseenter" ); + } ); + elem.trigger( "mouseover" ); + assert.equal( count, 1, "make sure mouseover triggers a mouseenter" ); elem.remove(); -}); +} ); -QUnit.test("pointerover triggers pointerenter", function( assert ) { - assert.expect(1); +QUnit.test( "pointerover triggers pointerenter", function( assert ) { + assert.expect( 1 ); var count = 0, - elem = jQuery("<a />"); - elem.on( "pointerenter", function () { + elem = jQuery( "<a />" ); + elem.on( "pointerenter", function() { count++; - }); - elem.trigger("pointerover"); - assert.equal(count, 1, "make sure pointerover triggers a pointerenter" ); + } ); + elem.trigger( "pointerover" ); + assert.equal( count, 1, "make sure pointerover triggers a pointerenter" ); elem.remove(); -}); +} ); -QUnit.test("withinElement implemented with jQuery.contains()", function( assert ) { +QUnit.test( "withinElement implemented with jQuery.contains()", function( assert ) { - assert.expect(1); + assert.expect( 1 ); - jQuery("#qunit-fixture").append("<div id='jc-outer'><div id='jc-inner'></div></div>"); + jQuery( "#qunit-fixture" ).append( "<div id='jc-outer'><div id='jc-inner'></div></div>" ); - jQuery("#jc-outer").on("mouseenter mouseleave", function( event ) { + jQuery( "#jc-outer" ).on( "mouseenter mouseleave", function( event ) { assert.equal( this.id, "jc-outer", this.id + " " + event.type ); - }).trigger("mouseenter"); + } ).trigger( "mouseenter" ); - jQuery("#jc-inner").trigger("mousenter"); + jQuery( "#jc-inner" ).trigger( "mousenter" ); - jQuery("#jc-outer").off("mouseenter mouseleave").remove(); - jQuery("#jc-inner").remove(); + jQuery( "#jc-outer" ).off( "mouseenter mouseleave" ).remove(); + jQuery( "#jc-inner" ).remove(); -}); +} ); -QUnit.test("mouseenter, mouseleave don't catch exceptions", function( assert ) { - assert.expect(2); +QUnit.test( "mouseenter, mouseleave don't catch exceptions", function( assert ) { + assert.expect( 2 ); - var elem = jQuery("#firstp").on( "mouseenter mouseleave", function() { + var elem = jQuery( "#firstp" ).on( "mouseenter mouseleave", function() { throw "an Exception"; - }); + } ); try { - elem.trigger("mouseenter"); - } catch (e) { + elem.trigger( "mouseenter" ); + } catch ( e ) { assert.equal( e, "an Exception", "mouseenter doesn't catch exceptions" ); } try { - elem.trigger("mouseleave"); - } catch (e) { + elem.trigger( "mouseleave" ); + } catch ( e ) { assert.equal( e, "an Exception", "mouseleave doesn't catch exceptions" ); } -}); +} ); if ( jQuery.fn.click ) { - QUnit.test("trigger() shortcuts", function( assert ) { - assert.expect(5); + QUnit.test( "trigger() shortcuts", function( assert ) { + assert.expect( 5 ); var counter, clickCounter, - elem = jQuery("<li><a href='#'>Change location</a></li>").prependTo("#firstUL"); - elem.find("a").on("click", function() { - var close = jQuery("spanx", this); // same with jQuery(this).find("span"); + elem = jQuery( "<li><a href='#'>Change location</a></li>" ).prependTo( "#firstUL" ); + elem.find( "a" ).on( "click", function() { + var close = jQuery( "spanx", this ); // same with jQuery(this).find("span"); assert.equal( close.length, 0, "Context element does not exist, length must be zero" ); - assert.ok( !close[0], "Context element does not exist, direct access to element must return undefined" ); + assert.ok( !close[ 0 ], "Context element does not exist, direct access to element must return undefined" ); return false; - }).click(); + } ).click(); // manually clean up detached elements elem.remove(); - jQuery("#check1").click(function() { + jQuery( "#check1" ).click( function() { assert.ok( true, "click event handler for checkbox gets fired twice, see #815" ); - }).click(); + } ).click(); counter = 0; - jQuery("#firstp")[0].onclick = function() { + jQuery( "#firstp" )[ 0 ].onclick = function() { counter++; }; - jQuery("#firstp").click(); + jQuery( "#firstp" ).click(); assert.equal( counter, 1, "Check that click, triggers onclick event handler also" ); clickCounter = 0; - jQuery("#simon1")[0].onclick = function() { + jQuery( "#simon1" )[ 0 ].onclick = function() { clickCounter++; }; - jQuery("#simon1").click(); + jQuery( "#simon1" ).click(); assert.equal( clickCounter, 1, "Check that click, triggers onclick event handler on an a tag also" ); // test that special handlers do not blow up with VML elements (#7071) - jQuery("<xml:namespace ns='urn:schemas-microsoft-com:vml' prefix='v' />").appendTo("head"); - jQuery("<v:oval id='oval' style='width:100pt;height:75pt;' fillcolor='red'> </v:oval>").appendTo("#form"); - jQuery("#oval").click().keydown(); - }); + jQuery( "<xml:namespace ns='urn:schemas-microsoft-com:vml' prefix='v' />" ).appendTo( "head" ); + jQuery( "<v:oval id='oval' style='width:100pt;height:75pt;' fillcolor='red'> </v:oval>" ).appendTo( "#form" ); + jQuery( "#oval" ).click().keydown(); + } ); } -QUnit.test("trigger() bubbling", function( assert ) { - assert.expect(18); +QUnit.test( "trigger() bubbling", function( assert ) { + assert.expect( 18 ); var win = 0, doc = 0, html = 0, body = 0, main = 0, ap = 0; - jQuery(window).on("click", function(){ win++; }); - jQuery(document).on("click", function( e ){ if ( e.target !== document) { doc++; } }); - jQuery("html").on("click", function(){ html++; }); - jQuery("body").on("click", function(){ body++; }); - jQuery("#qunit-fixture").on("click", function(){ main++; }); - jQuery("#ap").on("click", function(){ ap++; return false; }); + jQuery( window ).on( "click", function() { win++; } ); + jQuery( document ).on( "click", function( e ) { if ( e.target !== document ) { doc++; } } ); + jQuery( "html" ).on( "click", function() { html++; } ); + jQuery( "body" ).on( "click", function() { body++; } ); + jQuery( "#qunit-fixture" ).on( "click", function() { main++; } ); + jQuery( "#ap" ).on( "click", function() { ap++; return false; } ); - jQuery("html").trigger("click"); + jQuery( "html" ).trigger( "click" ); assert.equal( win, 1, "HTML bubble" ); assert.equal( doc, 1, "HTML bubble" ); assert.equal( html, 1, "HTML bubble" ); - jQuery("body").trigger("click"); + jQuery( "body" ).trigger( "click" ); assert.equal( win, 2, "Body bubble" ); assert.equal( doc, 2, "Body bubble" ); assert.equal( html, 2, "Body bubble" ); assert.equal( body, 1, "Body bubble" ); - jQuery("#qunit-fixture").trigger("click"); + jQuery( "#qunit-fixture" ).trigger( "click" ); assert.equal( win, 3, "Main bubble" ); assert.equal( doc, 3, "Main bubble" ); assert.equal( html, 3, "Main bubble" ); assert.equal( body, 2, "Main bubble" ); assert.equal( main, 1, "Main bubble" ); - jQuery("#ap").trigger("click"); + jQuery( "#ap" ).trigger( "click" ); assert.equal( doc, 3, "ap bubble" ); assert.equal( html, 3, "ap bubble" ); assert.equal( body, 2, "ap bubble" ); assert.equal( main, 1, "ap bubble" ); assert.equal( ap, 1, "ap bubble" ); - jQuery( document ).trigger("click"); + jQuery( document ).trigger( "click" ); assert.equal( win, 4, "doc bubble" ); // manually clean up events from elements outside the fixture - jQuery(window).off("click"); - jQuery(document).off("click"); - jQuery("html, body, #qunit-fixture").off("click"); -}); + jQuery( window ).off( "click" ); + jQuery( document ).off( "click" ); + jQuery( "html, body, #qunit-fixture" ).off( "click" ); +} ); -QUnit.test("trigger(type, [data], [fn])", function( assert ) { - assert.expect(16); +QUnit.test( "trigger(type, [data], [fn])", function( assert ) { + assert.expect( 16 ); var $elem, pass, form, elem2, - handler = function(event, a, b, c) { + handler = function( event, a, b, c ) { assert.equal( event.type, "click", "check passed data" ); assert.equal( a, 1, "check passed data" ); assert.equal( b, "2", "check passed data" ); @@ -1001,92 +1007,91 @@ QUnit.test("trigger(type, [data], [fn])", function( assert ) { return "test"; }; - $elem = jQuery("#firstp"); + $elem = jQuery( "#firstp" ); // Simulate a "native" click - $elem[0].click = function(){ + $elem[ 0 ].click = function() { assert.ok( true, "Native call was triggered" ); }; - - jQuery( document ).on("mouseenter", "#firstp", function(){ + jQuery( document ).on( "mouseenter", "#firstp", function() { assert.ok( true, "Trigger mouseenter bound by on" ); - }); + } ); - jQuery( document ).on("mouseleave", "#firstp", function(){ + jQuery( document ).on( "mouseleave", "#firstp", function() { assert.ok( true, "Trigger mouseleave bound by on" ); - }); + } ); - $elem.trigger("mouseenter"); + $elem.trigger( "mouseenter" ); - $elem.trigger("mouseleave"); + $elem.trigger( "mouseleave" ); - jQuery( document ).off( "mouseenter mouseleave", "#firstp"); + jQuery( document ).off( "mouseenter mouseleave", "#firstp" ); // Triggers handlers and native // Trigger 5 - $elem.on("click", handler).trigger("click", [1, "2", "abc"]); + $elem.on( "click", handler ).trigger( "click", [ 1, "2", "abc" ] ); // Simulate a "native" click - $elem[0].click = function(){ + $elem[ 0 ].click = function() { assert.ok( false, "Native call was triggered" ); }; // Trigger only the handlers (no native) // Triggers 5 - assert.equal( $elem.triggerHandler("click", [1, "2", "abc"]), "test", "Verify handler response" ); + assert.equal( $elem.triggerHandler( "click", [ 1, "2", "abc" ] ), "test", "Verify handler response" ); pass = true; try { - elem2 = jQuery("#form input").eq(0); - elem2.get(0).style.display = "none"; - elem2.trigger("focus"); - } catch( e ) { + elem2 = jQuery( "#form input" ).eq( 0 ); + elem2.get( 0 ).style.display = "none"; + elem2.trigger( "focus" ); + } catch ( e ) { pass = false; } assert.ok( pass, "Trigger focus on hidden element" ); pass = true; try { - jQuery("#qunit-fixture table").eq(0).on("test:test", function(){}).trigger("test:test"); + jQuery( "#qunit-fixture table" ).eq( 0 ).on( "test:test", function() {} ).trigger( "test:test" ); } catch ( e ) { pass = false; } assert.ok( pass, "Trigger on a table with a colon in the even type, see #3533" ); - form = jQuery("<form action=''></form>").appendTo("body"); + form = jQuery( "<form action=''></form>" ).appendTo( "body" ); // Make sure it can be prevented locally - form.on( "submit", function(){ + form.on( "submit", function() { assert.ok( true, "Local `on` still works." ); return false; - }); + } ); // Trigger 1 - form.trigger("submit"); + form.trigger( "submit" ); - form.off("submit"); + form.off( "submit" ); - jQuery(document).on( "submit", function(){ + jQuery( document ).on( "submit", function() { assert.ok( true, "Make sure bubble works up to document." ); return false; - }); + } ); // Trigger 1 - form.trigger("submit"); + form.trigger( "submit" ); - jQuery(document).off("submit"); + jQuery( document ).off( "submit" ); form.remove(); -}); +} ); QUnit.test( "submit event bubbles on copied forms (#11649)", function( assert ) { assert.expect( 3 ); var $formByClone, $formByHTML, - $testForm = jQuery("#testForm"), - $fixture = jQuery("#qunit-fixture"), - $wrapperDiv = jQuery("<div/>").appendTo( $fixture ); + $testForm = jQuery( "#testForm" ), + $fixture = jQuery( "#qunit-fixture" ), + $wrapperDiv = jQuery( "<div/>" ).appendTo( $fixture ); function noSubmit( e ) { e.preventDefault(); @@ -1100,29 +1105,29 @@ QUnit.test( "submit event bubbles on copied forms (#11649)", function( assert ) $fixture.on( "submit", "form", delegatedSubmit ); // Trigger form submission to introduce the _submit_attached property - $testForm.on( "submit", noSubmit ).find("input[name=sub1]").trigger("click"); + $testForm.on( "submit", noSubmit ).find( "input[name=sub1]" ).trigger( "click" ); // Copy the form via .clone() and .html() - $formByClone = $testForm.clone( true, true ).removeAttr("id"); - $formByHTML = jQuery( jQuery.parseHTML($fixture.html()) ).filter("#testForm").removeAttr("id"); + $formByClone = $testForm.clone( true, true ).removeAttr( "id" ); + $formByHTML = jQuery( jQuery.parseHTML( $fixture.html() ) ).filter( "#testForm" ).removeAttr( "id" ); $wrapperDiv.append( $formByClone, $formByHTML ); // Check submit bubbling on the copied forms - $wrapperDiv.find("form").on( "submit", noSubmit ).find("input[name=sub1]").trigger("click"); + $wrapperDiv.find( "form" ).on( "submit", noSubmit ).find( "input[name=sub1]" ).trigger( "click" ); // Clean up $wrapperDiv.remove(); $fixture.off( "submit", "form", delegatedSubmit ); $testForm.off( "submit", noSubmit ); -}); +} ); -QUnit.test( "change event bubbles on copied forms (#11796)", function( assert ){ +QUnit.test( "change event bubbles on copied forms (#11796)", function( assert ) { assert.expect( 3 ); var $formByClone, $formByHTML, - $form = jQuery("#form"), - $fixture = jQuery("#qunit-fixture"), - $wrapperDiv = jQuery("<div/>").appendTo( $fixture ); + $form = jQuery( "#form" ), + $fixture = jQuery( "#qunit-fixture" ), + $wrapperDiv = jQuery( "<div/>" ).appendTo( $fixture ); function delegatedChange() { assert.ok( true, "Make sure change event bubbles up." ); @@ -1133,31 +1138,31 @@ QUnit.test( "change event bubbles on copied forms (#11796)", function( assert ){ $fixture.on( "change", "form", delegatedChange ); // Trigger change event to introduce the _change_attached property - $form.find("select[name=select1]").val("1").trigger("change"); + $form.find( "select[name=select1]" ).val( "1" ).trigger( "change" ); // Copy the form via .clone() and .html() - $formByClone = $form.clone( true, true ).removeAttr("id"); - $formByHTML = jQuery( jQuery.parseHTML($fixture.html()) ).filter("#form").removeAttr("id"); + $formByClone = $form.clone( true, true ).removeAttr( "id" ); + $formByHTML = jQuery( jQuery.parseHTML( $fixture.html() ) ).filter( "#form" ).removeAttr( "id" ); $wrapperDiv.append( $formByClone, $formByHTML ); // Check change bubbling on the copied forms - $wrapperDiv.find("form select[name=select1]").val("2").trigger("change"); + $wrapperDiv.find( "form select[name=select1]" ).val( "2" ).trigger( "change" ); // Clean up $wrapperDiv.remove(); $fixture.off( "change", "form", delegatedChange ); -}); +} ); -QUnit.test("trigger(eventObject, [data], [fn])", function( assert ) { - assert.expect(28); +QUnit.test( "trigger(eventObject, [data], [fn])", function( assert ) { + assert.expect( 28 ); var event, - $parent = jQuery("<div id='par' />").appendTo("body"), - $child = jQuery("<p id='child'>foo</p>").appendTo( $parent ); + $parent = jQuery( "<div id='par' />" ).appendTo( "body" ), + $child = jQuery( "<p id='child'>foo</p>" ).appendTo( $parent ); $parent.get( 0 ).style.display = "none"; - event = jQuery.Event("noNew"); + event = jQuery.Event( "noNew" ); assert.ok( event !== window, "Instantiate jQuery.Event without the 'new' keyword" ); assert.equal( event.type, "noNew", "Verify its type" ); @@ -1170,40 +1175,41 @@ QUnit.test("trigger(eventObject, [data], [fn])", function( assert ) { event.stopPropagation(); assert.equal( event.isPropagationStopped(), true, "Verify isPropagationStopped" ); - event.isPropagationStopped = function(){ return false; }; + event.isPropagationStopped = function() { return false; }; event.stopImmediatePropagation(); assert.equal( event.isPropagationStopped(), true, "Verify isPropagationStopped" ); assert.equal( event.isImmediatePropagationStopped(), true, "Verify isPropagationStopped" ); - $parent.on("foo",function( e ) { + $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" ); assert.equal( e.currentTarget.id, "par", "Verify event.currentTarget when passed passing an event object" ); assert.equal( e.secret, "boo!", "Verify event object's custom attribute when passed passing an event object" ); - }); + } ); // test with an event object - event = new jQuery.Event("foo"); + event = new jQuery.Event( "foo" ); event.secret = "boo!"; - $child.trigger(event); + $child.trigger( event ); // test with a literal object - $child.trigger({"type": "foo", "secret": "boo!"}); + $child.trigger( { "type": "foo", "secret": "boo!" } ); $parent.off(); - function error(){ - assert.ok( false, "This assertion shouldn't be reached"); + function error() { + assert.ok( false, "This assertion shouldn't be reached" ); } - $parent.on("foo", error ); + $parent.on( "foo", error ); - $child.on("foo",function(e, a, b, c ){ - assert.equal( arguments.length, 4, "Check arguments length"); - assert.equal( a, 1, "Check first custom argument"); - assert.equal( b, 2, "Check second custom argument"); - assert.equal( c, 3, "Check third custom argument"); + $child.on( "foo", function( e, a, b, c ) { + assert.equal( arguments.length, 4, "Check arguments length" ); + assert.equal( a, 1, "Check first custom argument" ); + assert.equal( b, 2, "Check second custom argument" ); + assert.equal( c, 3, "Check third custom argument" ); assert.equal( e.isDefaultPrevented(), false, "Verify isDefaultPrevented" ); assert.equal( e.isPropagationStopped(), false, "Verify isPropagationStopped" ); @@ -1213,18 +1219,18 @@ QUnit.test("trigger(eventObject, [data], [fn])", function( assert ) { e.stopImmediatePropagation(); return "result"; - }); + } ); // We should add this back in when we want to test the order // in which event handlers are iterated. //$child.on("foo", error ); - event = new jQuery.Event("foo"); - $child.trigger( event, [1,2,3] ).off(); - assert.equal( event.result, "result", "Check event.result attribute"); + event = new jQuery.Event( "foo" ); + $child.trigger( event, [ 1,2,3 ] ).off(); + assert.equal( event.result, "result", "Check event.result attribute" ); // Will error if it bubbles - $child.triggerHandler("foo"); + $child.triggerHandler( "foo" ); $child.off(); $parent.off().remove(); @@ -1235,53 +1241,53 @@ QUnit.test("trigger(eventObject, [data], [fn])", function( assert ) { assert.equal( event.type, "zowie", "Verify its type" ); assert.equal( event.isPropagationStopped(), false, "propagation not stopped" ); assert.equal( event.isDefaultPrevented(), false, "default not prevented" ); -}); +} ); -QUnit.test(".trigger() bubbling on disconnected elements (#10489)", function( assert ) { - assert.expect(2); +QUnit.test( ".trigger() bubbling on disconnected elements (#10489)", function( assert ) { + assert.expect( 2 ); - jQuery( window ).on( "click", function(){ + jQuery( window ).on( "click", function() { assert.ok( false, "click fired on window" ); - }); + } ); jQuery( "<div><p>hi</p></div>" ) .on( "click", function() { assert.ok( true, "click fired on div" ); - }) + } ) .find( "p" ) .on( "click", function() { assert.ok( true, "click fired on p" ); - }) - .trigger("click") + } ) + .trigger( "click" ) .off( "click" ) .end() .off( "click" ) .remove(); jQuery( window ).off( "click" ); -}); +} ); -QUnit.test(".trigger() doesn't bubble load event (#10717)", function( assert ) { - assert.expect(1); +QUnit.test( ".trigger() doesn't bubble load event (#10717)", function( assert ) { + assert.expect( 1 ); - jQuery( window ).on( "load", function(){ + jQuery( window ).on( "load", function() { assert.ok( false, "load fired on window" ); - }); + } ); // It's not an image, but as long as it fires load... - jQuery("<img src='index.html' />") + jQuery( "<img src='index.html' />" ) .appendTo( "body" ) .on( "load", function() { assert.ok( true, "load fired on img" ); - }) + } ) .trigger( "load" ) .remove(); jQuery( window ).off( "load" ); -}); +} ); -QUnit.test("Delegated events in SVG (#10791; #13180)", function( assert ) { - assert.expect(2); +QUnit.test( "Delegated events in SVG (#10791; #13180)", function( assert ) { + assert.expect( 2 ); var useElem, e, svg = jQuery( @@ -1293,32 +1299,32 @@ QUnit.test("Delegated events in SVG (#10791; #13180)", function( assert ) { "</svg>" ); - jQuery("#qunit-fixture") + jQuery( "#qunit-fixture" ) .append( svg ) .on( "click", "#svg-by-id", function() { assert.ok( true, "delegated id selector" ); - }) + } ) .on( "click", "[class~='svg-by-class']", function() { assert.ok( true, "delegated class selector" ); - }) + } ) .find( "#svg-by-id, [class~='svg-by-class']" ) - .trigger("click") + .trigger( "click" ) .end(); // Fire a native click on an SVGElementInstance (the instance tree of an SVG <use>) // to confirm that it doesn't break our event delegation handling (#13180) - useElem = svg.find("#use")[0]; + useElem = svg.find( "#use" )[ 0 ]; if ( document.createEvent && useElem && useElem.instanceRoot ) { - e = document.createEvent("MouseEvents"); + e = document.createEvent( "MouseEvents" ); e.initEvent( "click", true, true ); useElem.instanceRoot.dispatchEvent( e ); } - jQuery("#qunit-fixture").off("click"); -}); + jQuery( "#qunit-fixture" ).off( "click" ); +} ); -QUnit.test("Delegated events in forms (#10844; #11145; #8165; #11382, #11764)", function( assert ) { - assert.expect(5); +QUnit.test( "Delegated events in forms (#10844; #11145; #8165; #11382, #11764)", function( assert ) { + assert.expect( 5 ); // Alias names like "id" cause havoc var form = jQuery( @@ -1328,36 +1334,36 @@ QUnit.test("Delegated events in forms (#10844; #11145; #8165; #11382, #11764)", ) .on( "submit", function( event ) { event.preventDefault(); - }) - .appendTo("body"); + } ) + .appendTo( "body" ); - jQuery("body") + jQuery( "body" ) .on( "submit", "#myform", function() { assert.ok( true, "delegated id selector with aliased id" ); - }) - .find("#myform") - .trigger("submit") + } ) + .find( "#myform" ) + .trigger( "submit" ) .end() - .off("submit"); + .off( "submit" ); - form.append("<input type='text' name='disabled' value='differently abled' />"); - jQuery("body") + form.append( "<input type='text' name='disabled' value='differently abled' />" ); + jQuery( "body" ) .on( "submit", "#myform", function() { assert.ok( true, "delegated id selector with aliased disabled" ); - }) - .find("#myform") - .trigger("submit") + } ) + .find( "#myform" ) + .trigger( "submit" ) .end() - .off("submit"); + .off( "submit" ); form .append( "<button id='nestyDisabledBtn'><span>Zing</span></button>" ) .on( "click", "#nestyDisabledBtn", function() { assert.ok( true, "click on enabled/disabled button with nesty elements" ); - }) + } ) .on( "mouseover", "#nestyDisabledBtn", function() { assert.ok( true, "mouse on enabled/disabled button with nesty elements" ); - }) + } ) .find( "span" ) .trigger( "click" ) // yep .trigger( "mouseover" ) // yep @@ -1370,10 +1376,10 @@ QUnit.test("Delegated events in forms (#10844; #11145; #8165; #11382, #11764)", .off( "click" ); form.remove(); -}); +} ); -QUnit.test("Submit event can be stopped (#11049)", function( assert ) { - assert.expect(1); +QUnit.test( "Submit event can be stopped (#11049)", function( assert ) { + assert.expect( 1 ); // Since we manually bubble in IE, make sure inner handlers get a chance to cancel var form = jQuery( @@ -1382,33 +1388,33 @@ QUnit.test("Submit event can be stopped (#11049)", function( assert ) { "<input type='submit' />" + "</form>" ) - .appendTo("body"); + .appendTo( "body" ); jQuery( "body" ) .on( "submit", function() { assert.ok( true, "submit bubbled on first handler" ); return false; - }) + } ) .find( "#myform input[type=submit]" ) - .each( function(){ this.click(); } ) + .each( function() { this.click(); } ) .end() .on( "submit", function() { assert.ok( false, "submit bubbled on second handler" ); return false; - }) + } ) .find( "#myform input[type=submit]" ) - .each( function(){ + .each( function() { jQuery( this.form ).on( "submit", function( e ) { e.preventDefault(); e.stopPropagation(); - }); + } ); this.click(); - }) + } ) .end() .off( "submit" ); form.remove(); -}); +} ); // Test beforeunload event only if it supported. // Support: iOS 7+, Android<4.0 @@ -1416,8 +1422,8 @@ QUnit.test("Submit event can be stopped (#11049)", function( assert ) { // handler making it impossible to feature-detect the support. if ( window.onbeforeunload === null && !/(ipad|iphone|ipod|android 2\.3)/i.test( navigator.userAgent ) ) { - QUnit.test("on(beforeunload)", 1, function( assert ) { - var iframe = jQuery(jQuery.parseHTML("<iframe src='data/event/onbeforeunload.html'><iframe>")); + QUnit.test( "on(beforeunload)", 1, function( assert ) { + var iframe = jQuery( jQuery.parseHTML( "<iframe src='data/event/onbeforeunload.html'><iframe>" ) ); var done = assert.async(); window.onmessage = function( event ) { @@ -1430,15 +1436,15 @@ if ( window.onbeforeunload === null && done(); }; - iframe.appendTo("#qunit-fixture"); - }); + iframe.appendTo( "#qunit-fixture" ); + } ); } -QUnit.test("jQuery.Event( type, props )", function( assert ) { +QUnit.test( "jQuery.Event( type, props )", function( assert ) { - assert.expect(6); + assert.expect( 6 ); - var event = jQuery.Event( "keydown", { keyCode: 64 }), + var event = jQuery.Event( "keydown", { keyCode: 64 } ), handler = function( event ) { assert.ok( "keyCode" in event, "Special property 'keyCode' exists" ); assert.equal( event.keyCode, 64, "event.keyCode has explicit value '64'" ); @@ -1448,24 +1454,24 @@ QUnit.test("jQuery.Event( type, props )", function( assert ) { assert.equal( event.type, "keydown", "Verify type" ); // ensure "type" in props won't clobber the one set by constructor - assert.equal( jQuery.inArray("type", jQuery.event.props), -1, "'type' property not in props (#10375)" ); + assert.equal( jQuery.inArray( "type", jQuery.event.props ), -1, "'type' property not in props (#10375)" ); assert.ok( "keyCode" in event, "Special 'keyCode' property exists" ); assert.strictEqual( jQuery.isPlainObject( event ), false, "Instances of $.Event should not be identified as a plain object." ); - jQuery("body").on( "keydown", handler ).trigger( event ); + jQuery( "body" ).on( "keydown", handler ).trigger( event ); - jQuery("body").off( "keydown" ); + jQuery( "body" ).off( "keydown" ); -}); +} ); -QUnit.test("jQuery.Event properties", function( assert ){ - assert.expect(12); +QUnit.test( "jQuery.Event properties", function( assert ) { + assert.expect( 12 ); var handler, - $structure = jQuery("<div id='ancestor'><p id='delegate'><span id='target'>shiny</span></p></div>"), - $target = $structure.find("#target"); + $structure = jQuery( "<div id='ancestor'><p id='delegate'><span id='target'>shiny</span></p></div>" ), + $target = $structure.find( "#target" ); handler = function( e ) { assert.strictEqual( e.currentTarget, this, "currentTarget at " + this.id ); @@ -1474,43 +1480,43 @@ QUnit.test("jQuery.Event properties", function( assert ){ $structure.one( "click", handler ); $structure.one( "click", "p", handler ); $target.one( "click", handler ); - $target[0].onclick = function( e ) { + $target[ 0 ].onclick = function( e ) { assert.strictEqual( e.currentTarget, this, "currentTarget at target (native handler)" ); assert.equal( e.isTrigger, 3, "trigger at target (native handler)" ); }; - $target.trigger("click"); + $target.trigger( "click" ); $target.one( "click", function( e ) { assert.equal( e.isTrigger, 2, "triggerHandler at target" ); - }); - $target[0].onclick = function( e ) { + } ); + $target[ 0 ].onclick = function( e ) { assert.equal( e.isTrigger, 2, "triggerHandler at target (native handler)" ); }; - $target.triggerHandler("click"); + $target.triggerHandler( "click" ); handler = function( e ) { assert.strictEqual( e.isTrigger, undefined, "native event at " + this.id ); }; $target.one( "click", handler ); - $target[0].onclick = function( e ) { + $target[ 0 ].onclick = function( e ) { assert.strictEqual( e.isTrigger, undefined, "native event at target (native handler)" ); }; - fireNative( $target[0], "click" ); -}); + fireNative( $target[ 0 ], "click" ); +} ); -QUnit.test(".on()/.off()", function( assert ) { - assert.expect(65); +QUnit.test( ".on()/.off()", function( assert ) { + assert.expect( 65 ); var event, clicked, hash, called, livec, lived, livee, submit = 0, div = 0, livea = 0, liveb = 0; - jQuery("#body").on("submit", "#qunit-fixture div", function(){ submit++; return false; }); - jQuery("#body").on("click", "#qunit-fixture div", function(){ div++; }); - jQuery("#body").on("click", "div#nothiddendiv", function(){ livea++; }); - jQuery("#body").on("click", "div#nothiddendivchild", function(){ liveb++; }); + jQuery( "#body" ).on( "submit", "#qunit-fixture div", function() { submit++; return false; } ); + jQuery( "#body" ).on( "click", "#qunit-fixture div", function() { div++; } ); + jQuery( "#body" ).on( "click", "div#nothiddendiv", function() { livea++; } ); + jQuery( "#body" ).on( "click", "div#nothiddendivchild", function() { liveb++; } ); // Nothing should trigger on the body - jQuery("body").trigger("click"); + jQuery( "body" ).trigger( "click" ); assert.equal( submit, 0, "Click on body" ); assert.equal( div, 0, "Click on body" ); assert.equal( livea, 0, "Click on body" ); @@ -1518,7 +1524,7 @@ QUnit.test(".on()/.off()", function( assert ) { // This should trigger two events submit = 0; div = 0; livea = 0; liveb = 0; - jQuery("div#nothiddendiv").trigger("click"); + jQuery( "div#nothiddendiv" ).trigger( "click" ); assert.equal( submit, 0, "Click on div" ); assert.equal( div, 1, "Click on div" ); assert.equal( livea, 1, "Click on div" ); @@ -1526,7 +1532,7 @@ QUnit.test(".on()/.off()", function( assert ) { // This should trigger three events (w/ bubbling) submit = 0; div = 0; livea = 0; liveb = 0; - jQuery("div#nothiddendivchild").trigger("click"); + jQuery( "div#nothiddendivchild" ).trigger( "click" ); assert.equal( submit, 0, "Click on inner div" ); assert.equal( div, 2, "Click on inner div" ); assert.equal( livea, 1, "Click on inner div" ); @@ -1534,7 +1540,7 @@ QUnit.test(".on()/.off()", function( assert ) { // This should trigger one submit submit = 0; div = 0; livea = 0; liveb = 0; - jQuery("div#nothiddendivchild").trigger("submit"); + jQuery( "div#nothiddendivchild" ).trigger( "submit" ); assert.equal( submit, 1, "Submit on div" ); assert.equal( div, 0, "Submit on div" ); assert.equal( livea, 0, "Submit on div" ); @@ -1542,7 +1548,7 @@ QUnit.test(".on()/.off()", function( assert ) { // Make sure no other events were removed in the process submit = 0; div = 0; livea = 0; liveb = 0; - jQuery("div#nothiddendivchild").trigger("click"); + jQuery( "div#nothiddendivchild" ).trigger( "click" ); assert.equal( submit, 0, "off Click on inner div" ); assert.equal( div, 2, "off Click on inner div" ); assert.equal( livea, 1, "off Click on inner div" ); @@ -1550,8 +1556,8 @@ QUnit.test(".on()/.off()", function( assert ) { // Now make sure that the removal works submit = 0; div = 0; livea = 0; liveb = 0; - jQuery("#body").off("click", "div#nothiddendivchild"); - jQuery("div#nothiddendivchild").trigger("click"); + jQuery( "#body" ).off( "click", "div#nothiddendivchild" ); + jQuery( "div#nothiddendivchild" ).trigger( "click" ); assert.equal( submit, 0, "off Click on inner div" ); assert.equal( div, 2, "off Click on inner div" ); assert.equal( livea, 1, "off Click on inner div" ); @@ -1559,7 +1565,7 @@ QUnit.test(".on()/.off()", function( assert ) { // Make sure that the click wasn't removed too early submit = 0; div = 0; livea = 0; liveb = 0; - jQuery("div#nothiddendiv").trigger("click"); + jQuery( "div#nothiddendiv" ).trigger( "click" ); assert.equal( submit, 0, "off Click on inner div" ); assert.equal( div, 1, "off Click on inner div" ); assert.equal( livea, 1, "off Click on inner div" ); @@ -1567,8 +1573,8 @@ QUnit.test(".on()/.off()", function( assert ) { // Make sure that stopPropagation doesn't stop live events submit = 0; div = 0; livea = 0; liveb = 0; - jQuery("#body").on("click", "div#nothiddendivchild", function( e ){ liveb++; e.stopPropagation(); }); - jQuery("div#nothiddendivchild").trigger("click"); + jQuery( "#body" ).on( "click", "div#nothiddendivchild", function( e ) { liveb++; e.stopPropagation(); } ); + jQuery( "div#nothiddendivchild" ).trigger( "click" ); assert.equal( submit, 0, "stopPropagation Click on inner div" ); assert.equal( div, 1, "stopPropagation Click on inner div" ); assert.equal( livea, 0, "stopPropagation Click on inner div" ); @@ -1576,126 +1582,126 @@ QUnit.test(".on()/.off()", function( assert ) { // Make sure click events only fire with primary click submit = 0; div = 0; livea = 0; liveb = 0; - event = jQuery.Event("click"); + event = jQuery.Event( "click" ); event.button = 1; - jQuery("div#nothiddendiv").trigger(event); + jQuery( "div#nothiddendiv" ).trigger( event ); assert.equal( livea, 0, "on secondary click" ); - jQuery("#body").off("click", "div#nothiddendivchild"); - jQuery("#body").off("click", "div#nothiddendiv"); - jQuery("#body").off("click", "#qunit-fixture div"); - jQuery("#body").off("submit", "#qunit-fixture div"); + jQuery( "#body" ).off( "click", "div#nothiddendivchild" ); + jQuery( "#body" ).off( "click", "div#nothiddendiv" ); + jQuery( "#body" ).off( "click", "#qunit-fixture div" ); + jQuery( "#body" ).off( "submit", "#qunit-fixture div" ); // Test binding with a different context clicked = 0; - jQuery("#qunit-fixture").on("click", "#foo", function(){ clicked++; }); - jQuery("#qunit-fixture div").trigger("click"); - jQuery("#foo").trigger("click"); - jQuery("#qunit-fixture").trigger("click"); - jQuery("body").trigger("click"); + jQuery( "#qunit-fixture" ).on( "click", "#foo", function() { clicked++; } ); + jQuery( "#qunit-fixture div" ).trigger( "click" ); + jQuery( "#foo" ).trigger( "click" ); + jQuery( "#qunit-fixture" ).trigger( "click" ); + jQuery( "body" ).trigger( "click" ); assert.equal( clicked, 2, "on with a context" ); // Test unbinding with a different context - jQuery("#qunit-fixture").off("click", "#foo"); - jQuery("#foo").trigger("click"); - assert.equal( clicked, 2, "off with a context"); + jQuery( "#qunit-fixture" ).off( "click", "#foo" ); + jQuery( "#foo" ).trigger( "click" ); + assert.equal( clicked, 2, "off with a context" ); // Test binding with event data - jQuery("#body").on("click", "#foo", true, function( e ){ equal( e.data, true, "on with event data" ); }); - jQuery("#foo").trigger("click"); - jQuery("#body").off("click", "#foo"); + jQuery( "#body" ).on( "click", "#foo", true, function( e ) { equal( e.data, true, "on with event data" ); } ); + jQuery( "#foo" ).trigger( "click" ); + jQuery( "#body" ).off( "click", "#foo" ); // Test binding with trigger data - jQuery("#body").on("click", "#foo", function(e, data){ equal( data, true, "on with trigger data" ); }); - jQuery("#foo").trigger("click", true); - jQuery("#body").off("click", "#foo"); + jQuery( "#body" ).on( "click", "#foo", function( e, data ) { equal( data, true, "on with trigger data" ); } ); + jQuery( "#foo" ).trigger( "click", true ); + jQuery( "#body" ).off( "click", "#foo" ); // Test binding with different this object - jQuery("#body").on("click", "#foo", jQuery.proxy(function(){ equal( this["foo"], "bar", "on with event scope" ); }, { "foo": "bar" })); - jQuery("#foo").trigger("click"); - jQuery("#body").off("click", "#foo"); + jQuery( "#body" ).on( "click", "#foo", jQuery.proxy( function() { equal( this[ "foo" ], "bar", "on with event scope" ); }, { "foo": "bar" } ) ); + jQuery( "#foo" ).trigger( "click" ); + jQuery( "#body" ).off( "click", "#foo" ); // Test binding with different this object, event data, and trigger data - jQuery("#body").on("click", "#foo", true, jQuery.proxy(function(e, data){ + jQuery( "#body" ).on( "click", "#foo", true, jQuery.proxy( function( e, data ) { assert.equal( e.data, true, "on with with different this object, event data, and trigger data" ); assert.equal( this.foo, "bar", "on with with different this object, event data, and trigger data" ); - assert.equal( data, true, "on with with different this object, event data, and trigger data"); - }, { "foo": "bar" })); - jQuery("#foo").trigger("click", true); - jQuery("#body").off("click", "#foo"); + assert.equal( data, true, "on with with different this object, event data, and trigger data" ); + }, { "foo": "bar" } ) ); + jQuery( "#foo" ).trigger( "click", true ); + jQuery( "#body" ).off( "click", "#foo" ); // Verify that return false prevents default action - jQuery("#body").on("click", "#anchor2", function(){ return false; }); + jQuery( "#body" ).on( "click", "#anchor2", function() { return false; } ); hash = window.location.hash; - jQuery("#anchor2").trigger("click"); + jQuery( "#anchor2" ).trigger( "click" ); assert.equal( window.location.hash, hash, "return false worked" ); - jQuery("#body").off("click", "#anchor2"); + jQuery( "#body" ).off( "click", "#anchor2" ); // Verify that .preventDefault() prevents default action - jQuery("#body").on("click", "#anchor2", function(e){ e.preventDefault(); }); + jQuery( "#body" ).on( "click", "#anchor2", function( e ) { e.preventDefault(); } ); hash = window.location.hash; - jQuery("#anchor2").trigger("click"); + jQuery( "#anchor2" ).trigger( "click" ); assert.equal( window.location.hash, hash, "e.preventDefault() worked" ); - jQuery("#body").off("click", "#anchor2"); + jQuery( "#body" ).off( "click", "#anchor2" ); // Test binding the same handler to multiple points called = 0; - function callback(){ called++; return false; } + function callback() { called++; return false; } - jQuery("#body").on("click", "#nothiddendiv", callback); - jQuery("#body").on("click", "#anchor2", callback); + jQuery( "#body" ).on( "click", "#nothiddendiv", callback ); + jQuery( "#body" ).on( "click", "#anchor2", callback ); - jQuery("#nothiddendiv").trigger("click"); + jQuery( "#nothiddendiv" ).trigger( "click" ); assert.equal( called, 1, "Verify that only one click occurred." ); called = 0; - jQuery("#anchor2").trigger("click"); + jQuery( "#anchor2" ).trigger( "click" ); assert.equal( called, 1, "Verify that only one click occurred." ); // Make sure that only one callback is removed - jQuery("#body").off("click", "#anchor2", callback); + jQuery( "#body" ).off( "click", "#anchor2", callback ); called = 0; - jQuery("#nothiddendiv").trigger("click"); + jQuery( "#nothiddendiv" ).trigger( "click" ); assert.equal( called, 1, "Verify that only one click occurred." ); called = 0; - jQuery("#anchor2").trigger("click"); + jQuery( "#anchor2" ).trigger( "click" ); assert.equal( called, 0, "Verify that no click occurred." ); // Make sure that it still works if the selector is the same, // but the event type is different - jQuery("#body").on("foo", "#nothiddendiv", callback); + jQuery( "#body" ).on( "foo", "#nothiddendiv", callback ); // Cleanup - jQuery("#body").off("click", "#nothiddendiv", callback); + jQuery( "#body" ).off( "click", "#nothiddendiv", callback ); called = 0; - jQuery("#nothiddendiv").trigger("click"); + jQuery( "#nothiddendiv" ).trigger( "click" ); assert.equal( called, 0, "Verify that no click occurred." ); called = 0; - jQuery("#nothiddendiv").trigger("foo"); + jQuery( "#nothiddendiv" ).trigger( "foo" ); assert.equal( called, 1, "Verify that one foo occurred." ); // Cleanup - jQuery("#body").off("foo", "#nothiddendiv", callback); + jQuery( "#body" ).off( "foo", "#nothiddendiv", callback ); // Make sure we don't loose the target by DOM modifications // after the bubble already reached the liveHandler livec = 0; - jQuery("#nothiddendivchild").html("<span></span>"); + jQuery( "#nothiddendivchild" ).html( "<span></span>" ); - jQuery("#body").on("click", "#nothiddendivchild", function(){ jQuery("#nothiddendivchild").html(""); }); - jQuery("#body").on("click", "#nothiddendivchild", function(e){ if(e.target) {livec++;} }); + jQuery( "#body" ).on( "click", "#nothiddendivchild", function() { jQuery( "#nothiddendivchild" ).html( "" ); } ); + jQuery( "#body" ).on( "click", "#nothiddendivchild", function( e ) { if ( e.target ) {livec++;} } ); - jQuery("#nothiddendiv span").trigger("click"); - assert.equal( jQuery("#nothiddendiv span").length, 0, "Verify that first handler occurred and modified the DOM." ); + jQuery( "#nothiddendiv span" ).trigger( "click" ); + assert.equal( jQuery( "#nothiddendiv span" ).length, 0, "Verify that first handler occurred and modified the DOM." ); assert.equal( livec, 1, "Verify that second handler occurred even with nuked target." ); // Cleanup - jQuery("#body").off("click", "#nothiddendivchild"); + jQuery( "#body" ).off( "click", "#nothiddendivchild" ); // Verify that .live() occurs and cancel bubble in the same order as // we would expect .on() and .click() without delegation @@ -1703,204 +1709,204 @@ QUnit.test(".on()/.off()", function( assert ) { livee = 0; // bind one pair in one order - jQuery("#body").on("click", "span#liveSpan1 a", function(){ lived++; return false; }); - jQuery("#body").on("click", "span#liveSpan1", function(){ livee++; }); + jQuery( "#body" ).on( "click", "span#liveSpan1 a", function() { lived++; return false; } ); + jQuery( "#body" ).on( "click", "span#liveSpan1", function() { livee++; } ); - jQuery("span#liveSpan1 a").trigger("click"); + jQuery( "span#liveSpan1 a" ).trigger( "click" ); assert.equal( lived, 1, "Verify that only one first handler occurred." ); assert.equal( livee, 0, "Verify that second handler doesn't." ); // and one pair in inverse - jQuery("#body").on("click", "span#liveSpan2", function(){ livee++; }); - jQuery("#body").on("click", "span#liveSpan2 a", function(){ lived++; return false; }); + jQuery( "#body" ).on( "click", "span#liveSpan2", function() { livee++; } ); + jQuery( "#body" ).on( "click", "span#liveSpan2 a", function() { lived++; return false; } ); lived = 0; livee = 0; - jQuery("span#liveSpan2 a").trigger("click"); + jQuery( "span#liveSpan2 a" ).trigger( "click" ); assert.equal( lived, 1, "Verify that only one first handler occurred." ); assert.equal( livee, 0, "Verify that second handler doesn't." ); // Cleanup - jQuery("#body").off("click", "**"); + jQuery( "#body" ).off( "click", "**" ); // Test this, target and currentTarget are correct - jQuery("#body").on("click", "span#liveSpan1", function( e ) { + jQuery( "#body" ).on( "click", "span#liveSpan1", function( e ) { assert.equal( this.id, "liveSpan1", "Check the this within a on handler" ); assert.equal( e.currentTarget.id, "liveSpan1", "Check the event.currentTarget within a on handler" ); assert.equal( e.delegateTarget, document.body, "Check the event.delegateTarget within a on handler" ); assert.equal( e.target.nodeName.toUpperCase(), "A", "Check the event.target within a on handler" ); - }); + } ); - jQuery("span#liveSpan1 a").trigger("click"); + jQuery( "span#liveSpan1 a" ).trigger( "click" ); - jQuery("#body").off("click", "span#liveSpan1"); + jQuery( "#body" ).off( "click", "span#liveSpan1" ); // Work with deep selectors livee = 0; function clickB() { livee++; } - jQuery("#body").on("click", "#nothiddendiv div", function(){ livee++; }); - jQuery("#body").on("click", "#nothiddendiv div", clickB); - jQuery("#body").on("mouseover", "#nothiddendiv div", function(){ livee++; }); + jQuery( "#body" ).on( "click", "#nothiddendiv div", function() { livee++; } ); + jQuery( "#body" ).on( "click", "#nothiddendiv div", clickB ); + jQuery( "#body" ).on( "mouseover", "#nothiddendiv div", function() { livee++; } ); assert.equal( livee, 0, "No clicks, deep selector." ); livee = 0; - jQuery("#nothiddendivchild").trigger("click"); + jQuery( "#nothiddendivchild" ).trigger( "click" ); assert.equal( livee, 2, "Click, deep selector." ); livee = 0; - jQuery("#nothiddendivchild").trigger("mouseover"); + jQuery( "#nothiddendivchild" ).trigger( "mouseover" ); assert.equal( livee, 1, "Mouseover, deep selector." ); - jQuery("#body").off("mouseover", "#nothiddendiv div"); + jQuery( "#body" ).off( "mouseover", "#nothiddendiv div" ); livee = 0; - jQuery("#nothiddendivchild").trigger("click"); + jQuery( "#nothiddendivchild" ).trigger( "click" ); assert.equal( livee, 2, "Click, deep selector." ); livee = 0; - jQuery("#nothiddendivchild").trigger("mouseover"); + jQuery( "#nothiddendivchild" ).trigger( "mouseover" ); assert.equal( livee, 0, "Mouseover, deep selector." ); - jQuery("#body").off("click", "#nothiddendiv div", clickB); + jQuery( "#body" ).off( "click", "#nothiddendiv div", clickB ); livee = 0; - jQuery("#nothiddendivchild").trigger("click"); + jQuery( "#nothiddendivchild" ).trigger( "click" ); assert.equal( livee, 1, "Click, deep selector." ); - jQuery("#body").off("click", "#nothiddendiv div"); -}); + jQuery( "#body" ).off( "click", "#nothiddendiv div" ); +} ); -QUnit.test("jQuery.off using dispatched jQuery.Event", function( assert ) { - assert.expect(1); +QUnit.test( "jQuery.off using dispatched jQuery.Event", function( assert ) { + assert.expect( 1 ); - var markup = jQuery("<p><a href='#'>target</a></p>"), + var markup = jQuery( "<p><a href='#'>target</a></p>" ), count = 0; markup .on( "click.name", "a", function( event ) { assert.equal( ++count, 1, "event called once before removal" ); jQuery().off( event ); - }) - .find("a").trigger("click").trigger("click").end() + } ) + .find( "a" ).trigger( "click" ).trigger( "click" ).end() .remove(); -}); +} ); QUnit.test( "delegated event with delegateTarget-relative selector", function( assert ) { - assert.expect(3); - var markup = jQuery("<div><ul><li><a id=\"a0\"></a><ul id=\"ul0\"><li class=test><a id=\"a0_0\"></a></li><li><a id=\"a0_1\"></a></li></ul></li></ul></div>").appendTo("#qunit-fixture"); + assert.expect( 3 ); + var markup = jQuery( "<div><ul><li><a id=\"a0\"></a><ul id=\"ul0\"><li class=test><a id=\"a0_0\"></a></li><li><a id=\"a0_1\"></a></li></ul></li></ul></div>" ).appendTo( "#qunit-fixture" ); // Non-positional selector (#12383) - markup.find("#ul0") + markup.find( "#ul0" ) .on( "click", "div li a", function() { assert.ok( false, "div is ABOVE the delegation point!" ); - }) + } ) .on( "click", "ul a", function() { assert.ok( false, "ul IS the delegation point!" ); - }) + } ) .on( "click", "li.test a", function() { assert.ok( true, "li.test is below the delegation point." ); - }) - .find("#a0_0").trigger("click").end() - .off("click"); + } ) + .find( "#a0_0" ).trigger( "click" ).end() + .off( "click" ); // Positional selector (#11315) - markup.find("ul").eq(0) + markup.find( "ul" ).eq( 0 ) .on( "click", ">li>a", function() { assert.ok( this.id === "a0", "child li was clicked" ); - }) - .find("#ul0") + } ) + .find( "#ul0" ) .on( "click", "li:first>a", function() { - assert.ok( this.id === "a0_0" , "first li under #u10 was clicked" ); - }) + assert.ok( this.id === "a0_0", "first li under #u10 was clicked" ); + } ) .end() - .find("a").trigger("click").end() - .find("#ul0").off(); + .find( "a" ).trigger( "click" ).end() + .find( "#ul0" ).off(); markup.remove(); -}); +} ); QUnit.test( "delegated event with selector matching Object.prototype property (#13203)", function( assert ) { - assert.expect(1); + assert.expect( 1 ); var matched = 0; - jQuery("#foo").on( "click", "toString", function() { + jQuery( "#foo" ).on( "click", "toString", function() { matched++; - }); + } ); - jQuery("#anchor2").trigger("click"); + jQuery( "#anchor2" ).trigger( "click" ); assert.equal( matched, 0, "Nothing matched 'toString'" ); -}); +} ); QUnit.test( "delegated event with intermediate DOM manipulation (#13208)", function( assert ) { - assert.expect(1); + assert.expect( 1 ); - jQuery("#foo").on( "click", "[id=sap]", function() {}); - jQuery("#sap").on( "click", "[id=anchor2]", function() { + jQuery( "#foo" ).on( "click", "[id=sap]", function() {} ); + jQuery( "#sap" ).on( "click", "[id=anchor2]", function() { document.createDocumentFragment().appendChild( this.parentNode ); assert.ok( true, "Element removed" ); - }); - jQuery("#anchor2").trigger("click"); -}); + } ); + jQuery( "#anchor2" ).trigger( "click" ); +} ); -QUnit.test("stopPropagation() stops directly-bound events on delegated target", function( assert ) { - assert.expect(1); +QUnit.test( "stopPropagation() stops directly-bound events on delegated target", function( assert ) { + assert.expect( 1 ); - var markup = jQuery("<div><p><a href=\"#\">target</a></p></div>"); + var markup = jQuery( "<div><p><a href=\"#\">target</a></p></div>" ); markup .on( "click", function() { assert.ok( false, "directly-bound event on delegate target was called" ); - }) + } ) .on( "click", "a", function( e ) { e.stopPropagation(); assert.ok( true, "delegated handler was called" ); - }) - .find("a").trigger("click").end() + } ) + .find( "a" ).trigger( "click" ).end() .remove(); -}); +} ); -QUnit.test("off all bound delegated events", function( assert ){ - assert.expect(2); +QUnit.test( "off all bound delegated events", function( assert ) { + assert.expect( 2 ); var count = 0, clicks = 0, - div = jQuery("#body"); + div = jQuery( "#body" ); - div.on( "click submit", "div#nothiddendivchild", function(){ count++; } ); - div.on( "click", function(){ clicks++; } ); + div.on( "click submit", "div#nothiddendivchild", function() { count++; } ); + div.on( "click", function() { clicks++; } ); div.off( undefined, "**" ); - jQuery("div#nothiddendivchild").trigger("click"); - jQuery("div#nothiddendivchild").trigger("submit"); + jQuery( "div#nothiddendivchild" ).trigger( "click" ); + jQuery( "div#nothiddendivchild" ).trigger( "submit" ); assert.equal( count, 0, "Make sure no events were triggered." ); - div.trigger("click"); + div.trigger( "click" ); assert.equal( clicks, 2, "Make sure delegated and directly bound event occurred." ); - div.off("click"); -}); + div.off( "click" ); +} ); -QUnit.test("on with multiple delegated events", function( assert ){ - assert.expect(1); +QUnit.test( "on with multiple delegated events", function( assert ) { + assert.expect( 1 ); var count = 0, - div = jQuery("#body"); + div = jQuery( "#body" ); - div.on("click submit", "div#nothiddendivchild", function(){ count++; }); + div.on( "click submit", "div#nothiddendivchild", function() { count++; } ); - jQuery("div#nothiddendivchild").trigger("click"); - jQuery("div#nothiddendivchild").trigger("submit"); + jQuery( "div#nothiddendivchild" ).trigger( "click" ); + jQuery( "div#nothiddendivchild" ).trigger( "submit" ); assert.equal( count, 2, "Make sure both the click and submit were triggered." ); - jQuery("#body").off( undefined, "**" ); -}); + jQuery( "#body" ).off( undefined, "**" ); +} ); -QUnit.test("delegated on with change", function( assert ){ - assert.expect(8); +QUnit.test( "delegated on with change", function( assert ) { + assert.expect( 8 ); var select, checkbox, checkboxFunction, text, textChange, oldTextVal, @@ -1908,182 +1914,182 @@ QUnit.test("delegated on with change", function( assert ){ selectChange = 0, checkboxChange = 0; - select = jQuery("select[name='S1']"); - jQuery("#body").on("change", "select[name='S1']", function() { + select = jQuery( "select[name='S1']" ); + jQuery( "#body" ).on( "change", "select[name='S1']", function() { selectChange++; - }); + } ); - checkbox = jQuery("#check2"); - checkboxFunction = function(){ + checkbox = jQuery( "#check2" ); + checkboxFunction = function() { checkboxChange++; }; - jQuery("#body").on("change", "#check2", checkboxFunction); + jQuery( "#body" ).on( "change", "#check2", checkboxFunction ); // test click on select // second click that changed it selectChange = 0; - select[0].selectedIndex = select[0].selectedIndex ? 0 : 1; - select.trigger("change"); + select[ 0 ].selectedIndex = select[ 0 ].selectedIndex ? 0 : 1; + select.trigger( "change" ); assert.equal( selectChange, 1, "Change on click." ); // test keys on select selectChange = 0; - select[0].selectedIndex = select[0].selectedIndex ? 0 : 1; - select.trigger("change"); + select[ 0 ].selectedIndex = select[ 0 ].selectedIndex ? 0 : 1; + select.trigger( "change" ); assert.equal( selectChange, 1, "Change on keyup." ); // test click on checkbox - checkbox.trigger("change"); + checkbox.trigger( "change" ); assert.equal( checkboxChange, 1, "Change on checkbox." ); // test blur/focus on text - text = jQuery("#name"); + text = jQuery( "#name" ); textChange = 0; oldTextVal = text.val(); - jQuery("#body").on("change", "#name", function() { + jQuery( "#body" ).on( "change", "#name", function() { textChange++; - }); + } ); - text.val(oldTextVal+"foo"); - text.trigger("change"); + text.val( oldTextVal + "foo" ); + text.trigger( "change" ); assert.equal( textChange, 1, "Change on text input." ); - text.val(oldTextVal); - jQuery("#body").off("change", "#name"); + text.val( oldTextVal ); + jQuery( "#body" ).off( "change", "#name" ); // test blur/focus on password - password = jQuery("#name"); + password = jQuery( "#name" ); passwordChange = 0; oldPasswordVal = password.val(); - jQuery("#body").on("change", "#name", function() { + jQuery( "#body" ).on( "change", "#name", function() { passwordChange++; - }); + } ); - password.val(oldPasswordVal + "foo"); - password.trigger("change"); + password.val( oldPasswordVal + "foo" ); + password.trigger( "change" ); assert.equal( passwordChange, 1, "Change on password input." ); - password.val(oldPasswordVal); - jQuery("#body").off("change", "#name"); + password.val( oldPasswordVal ); + jQuery( "#body" ).off( "change", "#name" ); // make sure die works // die all changes selectChange = 0; - jQuery("#body").off("change", "select[name='S1']"); - select[0].selectedIndex = select[0].selectedIndex ? 0 : 1; - select.trigger("change"); + jQuery( "#body" ).off( "change", "select[name='S1']" ); + select[ 0 ].selectedIndex = select[ 0 ].selectedIndex ? 0 : 1; + select.trigger( "change" ); assert.equal( selectChange, 0, "Die on click works." ); selectChange = 0; - select[0].selectedIndex = select[0].selectedIndex ? 0 : 1; - select.trigger("change"); + select[ 0 ].selectedIndex = select[ 0 ].selectedIndex ? 0 : 1; + select.trigger( "change" ); assert.equal( selectChange, 0, "Die on keyup works." ); // die specific checkbox - jQuery("#body").off("change", "#check2", checkboxFunction); - checkbox.trigger("change"); + jQuery( "#body" ).off( "change", "#check2", checkboxFunction ); + checkbox.trigger( "change" ); assert.equal( checkboxChange, 1, "Die on checkbox." ); -}); +} ); -QUnit.test("delegated on with submit", function( assert ) { +QUnit.test( "delegated on with submit", function( assert ) { assert.expect( 2 ); var count1 = 0, count2 = 0; - jQuery("#body").on("submit", "#testForm", function(ev) { + jQuery( "#body" ).on( "submit", "#testForm", function( ev ) { count1++; ev.preventDefault(); - }); + } ); - jQuery(document).on("submit", "body", function(ev) { + jQuery( document ).on( "submit", "body", function( ev ) { count2++; ev.preventDefault(); - }); + } ); - jQuery("#testForm input[name=sub1]").trigger("submit"); + jQuery( "#testForm input[name=sub1]" ).trigger( "submit" ); assert.equal( count1, 1, "Verify form submit." ); assert.equal( count2, 1, "Verify body submit." ); - jQuery("#body").off( undefined, "**" ); - jQuery(document).off( undefined, "**" ); -}); + jQuery( "#body" ).off( undefined, "**" ); + jQuery( document ).off( undefined, "**" ); +} ); -QUnit.test("delegated off() with only namespaces", function( assert ) { - assert.expect(2); +QUnit.test( "delegated off() with only namespaces", function( assert ) { + assert.expect( 2 ); - var $delegate = jQuery("#liveHandlerOrder"), + var $delegate = jQuery( "#liveHandlerOrder" ), count = 0; - $delegate.on("click.ns", "a", function() { + $delegate.on( "click.ns", "a", function() { count++; - }); + } ); - jQuery("a", $delegate).eq(0).trigger("click.ns"); + jQuery( "a", $delegate ).eq( 0 ).trigger( "click.ns" ); - assert.equal( count, 1, "delegated click.ns"); + assert.equal( count, 1, "delegated click.ns" ); $delegate.off( ".ns", "**" ); - jQuery("a", $delegate).eq(1).trigger("click.ns"); + jQuery( "a", $delegate ).eq( 1 ).trigger( "click.ns" ); - assert.equal( count, 1, "no more .ns after off"); -}); + assert.equal( count, 1, "no more .ns after off" ); +} ); -QUnit.test("Non DOM element events", function( assert ) { - assert.expect(1); +QUnit.test( "Non DOM element events", function( assert ) { + assert.expect( 1 ); var o = {}; - jQuery(o).on("nonelementobj", function() { + jQuery( o ).on( "nonelementobj", function() { assert.ok( true, "Event on non-DOM object triggered" ); - }); + } ); - jQuery(o).trigger("nonelementobj").off("nonelementobj"); -}); + jQuery( o ).trigger( "nonelementobj" ).off( "nonelementobj" ); +} ); -QUnit.test("inline handler returning false stops default", function( assert ) { - assert.expect(1); +QUnit.test( "inline handler returning false stops default", function( assert ) { + assert.expect( 1 ); - var markup = jQuery("<div><a href=\"#\" onclick=\"return false\">x</a></div>"); - markup.on( "click", function(e) { - assert.ok( e.isDefaultPrevented(), "inline handler prevented default"); + var markup = jQuery( "<div><a href=\"#\" onclick=\"return false\">x</a></div>" ); + markup.on( "click", function( e ) { + assert.ok( e.isDefaultPrevented(), "inline handler prevented default" ); return false; - }); - markup.find("a").trigger("click"); - markup.off("click"); -}); + } ); + markup.find( "a" ).trigger( "click" ); + markup.off( "click" ); +} ); -QUnit.test("window resize", function( assert ) { - assert.expect(2); +QUnit.test( "window resize", function( assert ) { + assert.expect( 2 ); - jQuery(window).off(); + jQuery( window ).off(); - jQuery(window).on( "resize", function(){ + jQuery( window ).on( "resize", function() { assert.ok( true, "Resize event fired." ); - }).trigger("resize").off("resize"); + } ).trigger( "resize" ).off( "resize" ); - assert.ok( !jQuery._data(window, "events"), "Make sure all the events are gone." ); -}); + assert.ok( !jQuery._data( window, "events" ), "Make sure all the events are gone." ); +} ); -QUnit.test("focusin bubbles", function( assert ) { - assert.expect(2); +QUnit.test( "focusin bubbles", function( assert ) { + assert.expect( 2 ); var input = jQuery( "<input type='text' />" ).prependTo( "body" ), order = 0; // focus the element so DOM focus won't fire - input[0].focus(); + input[ 0 ].focus(); - jQuery( "body" ).on( "focusin.focusinBubblesTest", function(){ + jQuery( "body" ).on( "focusin.focusinBubblesTest", function() { assert.equal( 1, order++, "focusin on the body second" ); - }); + } ); - input.on( "focusin.focusinBubblesTest", function(){ + input.on( "focusin.focusinBubblesTest", function() { assert.equal( 0, order++, "focusin on the element first" ); - }); + } ); // Removed since DOM focus is unreliable on test swarm // DOM focus method @@ -2100,32 +2106,32 @@ QUnit.test("focusin bubbles", function( assert ) { input.remove(); jQuery( "body" ).off( "focusin.focusinBubblesTest" ); -}); +} ); -QUnit.test("custom events with colons (#3533, #8272)", function( assert ) { - assert.expect(1); +QUnit.test( "custom events with colons (#3533, #8272)", function( assert ) { + assert.expect( 1 ); - var tab = jQuery("<table><tr><td>trigger</td></tr></table>").appendTo("body"); + var tab = jQuery( "<table><tr><td>trigger</td></tr></table>" ).appendTo( "body" ); try { - tab.trigger("back:forth"); + tab.trigger( "back:forth" ); assert.ok( true, "colon events don't throw" ); } catch ( e ) { assert.ok( false, "colon events die" ); } tab.remove(); -}); +} ); -QUnit.test(".on and .off", function( assert ) { - assert.expect(9); +QUnit.test( ".on and .off", function( assert ) { + assert.expect( 9 ); var counter, mixfn, data, - $onandoff = jQuery("<div id=\"onandoff\"><p>on<b>and</b>off</p><div>worked<em>or</em>borked?</div></div>").appendTo("body"); + $onandoff = jQuery( "<div id=\"onandoff\"><p>on<b>and</b>off</p><div>worked<em>or</em>borked?</div></div>" ).appendTo( "body" ); // Simple case jQuery( "#onandoff" ) .on( "whip", function() { assert.ok( true, "whipped it good" ); - }) + } ) .trigger( "whip" ) .off(); @@ -2133,12 +2139,12 @@ QUnit.test(".on and .off", function( assert ) { counter = 0; jQuery( "#onandoff b" ) .on( "click", 5, function( e, trig ) { - counter += e.data + (trig || 9); // twice, 5+9+5+17=36 - }) + counter += e.data + ( trig || 9 ); // twice, 5+9+5+17=36 + } ) .one( "click", 7, function( e, trig ) { - counter += e.data + (trig || 11); // once, 7+11=18 - }) - .trigger("click") + counter += e.data + ( trig || 11 ); // once, 7+11=18 + } ) + .trigger( "click" ) .trigger( "click", 17 ) .off( "click" ); assert.equal( counter, 54, "direct event bindings with data" ); @@ -2147,23 +2153,22 @@ QUnit.test(".on and .off", function( assert ) { counter = 0; jQuery( "#onandoff" ) .on( "click", "em", 5, function( e, trig ) { - counter += e.data + (trig || 9); // twice, 5+9+5+17=36 - }) + counter += e.data + ( trig || 9 ); // twice, 5+9+5+17=36 + } ) .one( "click", "em", 7, function( e, trig ) { - counter += e.data + (trig || 11); // once, 7+11=18 - }) - .find("em") - .trigger("click") + counter += e.data + ( trig || 11 ); // once, 7+11=18 + } ) + .find( "em" ) + .trigger( "click" ) .trigger( "click", 17 ) .end() .off( "click", "em" ); assert.equal( counter, 54, "delegated event bindings with data" ); - // Mixed event bindings and types counter = 0; - mixfn = function(e, trig) { - counter += (e.data || 0) + (trig || 1); + mixfn = function( e, trig ) { + counter += ( e.data || 0 ) + ( trig || 1 ); }; jQuery( "#onandoff" ) .on( " click clack cluck ", "em", 2, mixfn ) @@ -2172,7 +2177,7 @@ QUnit.test(".on and .off", function( assert ) { .trigger( "what!" ) .each( function() { assert.equal( counter, 0, "nothing triggered yet" ); - }) + } ) .find( "em" ) .one( "cluck", 3, mixfn ) .trigger( "cluck", 8 ) // 3+8 2+8 + 0+8 = 29 @@ -2181,12 +2186,12 @@ QUnit.test(".on and .off", function( assert ) { .end() .each( function() { assert.equal( counter, 49, "after triggering em element" ); - }) - .off( "cluck", function(){} ) // shouldn't remove anything + } ) + .off( "cluck", function() {} ) // shouldn't remove anything .trigger( "cluck", 2 ) // 0+2 = 2 .each( function() { assert.equal( counter, 51, "after triggering #onandoff cluck" ); - }) + } ) .find( "b" ) .on( "click", 95, mixfn ) .on( "clack", "p", 97, mixfn ) @@ -2196,7 +2201,7 @@ QUnit.test(".on and .off", function( assert ) { .end() .each( function() { assert.equal( counter, 51, "after triggering b" ); - }) + } ) .trigger( "cluck", 3 ) // 0+3 = 3 .off( "clack", "em", mixfn ) .find( "em" ) @@ -2204,20 +2209,20 @@ QUnit.test(".on and .off", function( assert ) { .end() .each( function() { assert.equal( counter, 54, "final triggers" ); - }) + } ) .off( "click cluck" ); // We should have removed all the event handlers ... kinda hacky way to check this - data = jQuery.data[ jQuery( "#onandoff" )[0].expando ] || {}; - assert.equal( data["events"], undefined, "no events left" ); + data = jQuery.data[ jQuery( "#onandoff" )[ 0 ].expando ] || {}; + assert.equal( data[ "events" ], undefined, "no events left" ); $onandoff.remove(); -}); +} ); -QUnit.test("special on name mapping", function( assert ) { +QUnit.test( "special on name mapping", function( assert ) { assert.expect( 7 ); - jQuery.event.special["slap"] = { + jQuery.event.special[ "slap" ] = { bindType: "click", delegateType: "swing", handle: function( event ) { @@ -2229,7 +2234,7 @@ QUnit.test("special on name mapping", function( assert ) { assert.ok( true, "event " + event.type + " triggered" ); }; - jQuery("<div><button id=\"mammy\">Are We Not Men?</button></div>") + jQuery( "<div><button id=\"mammy\">Are We Not Men?</button></div>" ) .on( "slap", "button", jQuery.noop ) .on( "swing", "button", comeback ) .find( "button" ) @@ -2248,15 +2253,16 @@ QUnit.test("special on name mapping", function( assert ) { .trigger( "swing" ) .end() .remove(); - delete jQuery.event.special["slap"]; + delete jQuery.event.special[ "slap" ]; - jQuery.event.special["gutfeeling"] = { + jQuery.event.special[ "gutfeeling" ] = { bindType: "click", 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 ); + return event.handleObj.handler.call( this, event ); } }; @@ -2282,11 +2288,11 @@ QUnit.test("special on name mapping", function( assert ) { .trigger( "gutfeeling" ) // This one should not .remove(); - delete jQuery.event.special["gutfeeling"]; -}); + delete jQuery.event.special[ "gutfeeling" ]; +} ); -QUnit.test(".on and .off, selective mixed removal (#10705)", function( assert ) { - assert.expect(7); +QUnit.test( ".on and .off, selective mixed removal (#10705)", function( assert ) { + assert.expect( 7 ); var timingx = function( e ) { assert.ok( true, "triggered " + e.type ); @@ -2305,13 +2311,13 @@ QUnit.test(".on and .off, selective mixed removal (#10705)", function( assert ) .trigger( "click" ) // 2 .off( "future click" ) .trigger( "click" ); // 0 -}); +} ); -QUnit.test(".on( event-map, null-selector, data ) #11130", function( assert ) { +QUnit.test( ".on( event-map, null-selector, data ) #11130", function( assert ) { assert.expect( 1 ); - var $p = jQuery("<p>Strange Pursuit</p>"), + var $p = jQuery( "<p>Strange Pursuit</p>" ), data = "bar", map = { "foo": function( event ) { @@ -2320,15 +2326,15 @@ QUnit.test(".on( event-map, null-selector, data ) #11130", function( assert ) { } }; - $p.on( map, null, data ).trigger("foo"); -}); + $p.on( map, null, data ).trigger( "foo" ); +} ); -QUnit.test("clone() delegated events (#11076)", function( assert ) { - assert.expect(3); +QUnit.test( "clone() delegated events (#11076)", function( assert ) { + assert.expect( 3 ); var counter = { "center": 0, "fold": 0, "centerfold": 0 }, clicked = function() { - counter[ jQuery(this).text().replace(/\s+/, "") ]++; + counter[ jQuery( this ).text().replace( /\s+/, "" ) ]++; }, table = jQuery( "<table><tr><td>center</td><td>fold</td></tr></table>" ) @@ -2337,27 +2343,27 @@ QUnit.test("clone() delegated events (#11076)", function( assert ) { .on( "click", "td:last-child", clicked ), clone = table.clone( true ); - clone.find("td").trigger("click"); - assert.equal( counter["center"], 1, "first child" ); - assert.equal( counter["fold"], 1, "last child" ); - assert.equal( counter["centerfold"], 2, "all children" ); + clone.find( "td" ).trigger( "click" ); + assert.equal( counter[ "center" ], 1, "first child" ); + assert.equal( counter[ "fold" ], 1, "last child" ); + assert.equal( counter[ "centerfold" ], 2, "all children" ); table.remove(); clone.remove(); -}); +} ); -QUnit.test("checkbox state (#3827)", function( assert ) { +QUnit.test( "checkbox state (#3827)", function( assert ) { assert.expect( 9 ); - var markup = jQuery("<div><input type=checkbox><div>").appendTo("#qunit-fixture"), - cb = markup.find("input")[0]; + var markup = jQuery( "<div><input type=checkbox><div>" ).appendTo( "#qunit-fixture" ), + cb = markup.find( "input" )[ 0 ]; - jQuery(cb).on( "click", function(){ + jQuery( cb ).on( "click", function() { assert.equal( this.checked, false, "just-clicked checkbox is not checked" ); - }); - markup.on( "click", function(){ + } ); + markup.on( "click", function() { assert.equal( cb.checked, false, "checkbox is not checked in bubbled event" ); - }); + } ); // Native click cb.checked = true; @@ -2368,23 +2374,23 @@ QUnit.test("checkbox state (#3827)", function( assert ) { // jQuery click cb.checked = true; assert.equal( cb.checked, true, "jQuery - checkbox is initially checked" ); - jQuery( cb ).trigger("click"); + jQuery( cb ).trigger( "click" ); assert.equal( cb.checked, false, "jQuery - checkbox is no longer checked" ); // Handlers only; checkbox state remains false jQuery( cb ).triggerHandler( "click" ); -}); +} ); -QUnit.test("hover event no longer special since 1.9", function( assert ) { +QUnit.test( "hover event no longer special since 1.9", function( assert ) { assert.expect( 1 ); - jQuery("<div>craft</div>") + jQuery( "<div>craft</div>" ) .on( "hover", function( e ) { assert.equal( e.type, "hover", "I am hovering!" ); - }) - .trigger("hover") - .off("hover"); -}); + } ) + .trigger( "hover" ) + .off( "hover" ); +} ); QUnit.test( "event object properties on natively-triggered event", function( assert ) { assert.expect( 3 ); @@ -2395,17 +2401,18 @@ 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" ); assert.equal( "bubbles" in e, true, "has .bubbles" ); - }); + } ); evt.initEvent( "click", true, true ); link.dispatchEvent( evt ); $link.off( "click" ).remove(); -}); +} ); -QUnit.test("fixHooks extensions", function( assert ) { +QUnit.test( "fixHooks extensions", function( assert ) { assert.expect( 2 ); // IE requires focusable elements to be visible, so append to body @@ -2414,9 +2421,9 @@ QUnit.test("fixHooks extensions", function( assert ) { // Ensure the property doesn't exist $fixture.on( "click", function( event ) { - assert.ok( !("blurrinessLevel" in event), "event.blurrinessLevel does not exist" ); - }); - fireNative( $fixture[0], "click" ); + assert.ok( !( "blurrinessLevel" in event ), "event.blurrinessLevel does not exist" ); + } ); + fireNative( $fixture[ 0 ], "click" ); $fixture.off( "click" ); jQuery.event.fixHooks.click = { @@ -2429,13 +2436,13 @@ QUnit.test("fixHooks extensions", function( assert ) { // Trigger a native click and ensure the property is set $fixture.on( "click", function( event ) { assert.equal( event.blurrinessLevel, 42, "event.blurrinessLevel was set" ); - }); - fireNative( $fixture[0], "click" ); + } ); + fireNative( $fixture[ 0 ], "click" ); delete jQuery.event.fixHooks.click; $fixture.off( "click" ).remove(); jQuery.event.fixHooks.click = saved; -}); +} ); QUnit.test( "drag/drop events copy mouse-related event properties (gh-1925, gh-2009)", function( assert ) { assert.expect( 4 ); @@ -2445,48 +2452,48 @@ QUnit.test( "drag/drop events copy mouse-related event properties (gh-1925, gh-2 $fixture.on( "dragmove", function( evt ) { assert.ok( "pageX" in evt, "checking for pageX property on dragmove" ); assert.ok( "pageY" in evt, "checking for pageY property on dragmove" ); - }); + } ); fireNative( $fixture[ 0 ], "dragmove" ); $fixture.on( "drop", function( evt ) { assert.ok( "pageX" in evt, "checking for pageX property on drop" ); assert.ok( "pageY" in evt, "checking for pageY property on drop" ); - }); + } ); fireNative( $fixture[ 0 ], "drop" ); $fixture.unbind( "dragmove drop" ).remove(); -}); +} ); QUnit.test( "focusin using non-element targets", function( assert ) { assert.expect( 2 ); jQuery( document ).on( "focusin", function( e ) { assert.ok( e.type === "focusin", "got a focusin event on a document" ); - }).trigger( "focusin" ).off( "focusin" ); + } ).trigger( "focusin" ).off( "focusin" ); jQuery( window ).on( "focusin", function( e ) { assert.ok( e.type === "focusin", "got a focusin event on a window" ); - }).trigger( "focusin" ).off( "focusin" ); + } ).trigger( "focusin" ).off( "focusin" ); -}); +} ); testIframeWithCallback( "focusin from an iframe", "event/focusinCrossFrame.html", function( frameDoc, assert ) { - assert.expect(1); + assert.expect( 1 ); var input = jQuery( frameDoc ).find( "#frame-input" ); // Create a focusin handler on the parent; shouldn't affect the iframe's fate jQuery ( "body" ).on( "focusin.iframeTest", function() { assert.ok( false, "fired a focusin event in the parent document" ); - }); + } ); input.on( "focusin", function() { assert.ok( true, "fired a focusin event in the iframe" ); - }); + } ); // Avoid a native event; Chrome can't force focus to another frame input.trigger( "focusin" ); @@ -2506,7 +2513,7 @@ testIframeWithCallback( "jQuery.ready promise", "event/promiseReady.html", function( isOk, assert ) { - assert.expect(1); + assert.expect( 1 ); assert.ok( isOk, "$.when( $.ready ) works" ); } ); @@ -2515,7 +2522,7 @@ testIframeWithCallback( "Focusing iframe element", "event/focusElem.html", function( isOk, assert ) { - assert.expect(1); + assert.expect( 1 ); assert.ok( isOk, "Focused an element in an iframe" ); } ); @@ -2535,46 +2542,47 @@ if ( hasPHP ) { "jQuery.ready synchronous load with long loading subresources", "event/syncReady.html", function( isOk, assert ) { - assert.expect(1); + assert.expect( 1 ); assert.ok( isOk, "jQuery loaded synchronously fires ready when the DOM can truly be interacted with" ); } ); } -QUnit.test("change handler should be detached from element", function( assert ) { +QUnit.test( "change handler should be detached from element", function( assert ) { assert.expect( 2 ); var $fixture = jQuery( "<input type='text' id='change-ie-leak' />" ).appendTo( "body" ), originRemoveEvent = jQuery.removeEvent, - wrapperRemoveEvent = function(elem, type, handle){ - assert.equal("change", type, "Event handler for 'change' event should be removed"); - assert.equal("change-ie-leak", jQuery(elem).attr("id"), "Event handler for 'change' event should be removed from appropriate element"); - originRemoveEvent(elem, type, handle); + wrapperRemoveEvent = function( elem, type, handle ) { + assert.equal( "change", type, "Event handler for 'change' event should be removed" ); + assert.equal( "change-ie-leak", jQuery( elem ).attr( "id" ), "Event handler for 'change' event should be removed from appropriate element" ); + originRemoveEvent( elem, type, handle ); }; jQuery.removeEvent = wrapperRemoveEvent ; - $fixture.on( "change", function() {}); + $fixture.on( "change", function() {} ); $fixture.off( "change" ); $fixture.remove(); jQuery.removeEvent = originRemoveEvent; -}); +} ); -QUnit.test("trigger click on checkbox, fires change event", function( assert ) { - assert.expect(1); +QUnit.test( "trigger click on checkbox, fires change event", function( assert ) { + assert.expect( 1 ); - var check = jQuery("#check2"); + var check = jQuery( "#check2" ); var done = assert.async(); check.on( "change", function() { + // get it? - check.off("change"); + check.off( "change" ); assert.ok( true, "Change event fired as a result of triggered click" ); done(); - }).trigger("click"); -}); + } ).trigger( "click" ); +} ); QUnit.test( "Namespace preserved when passed an Event (#12739)", function( assert ) { assert.expect( 4 ); @@ -2585,84 +2593,84 @@ QUnit.test( "Namespace preserved when passed an Event (#12739)", function( asser triggered = 0, fooEvent; - markup.find("div") + markup.find( "div" ) .addBack() .on( "foo.bar", function( e ) { if ( !e.handled ) { triggered++; e.handled = true; assert.equal( e.namespace, "bar", "namespace is bar" ); - jQuery( e.target ).find("div").each(function() { + jQuery( e.target ).find( "div" ).each( function() { jQuery( this ).triggerHandler( e ); - }); + } ); } - }) + } ) .on( "foo.bar2", function() { assert.ok( false, "foo.bar2 called on trigger " + triggered + " id " + this.id ); - }); + } ); - markup.trigger("foo.bar"); - markup.trigger( jQuery.Event("foo.bar") ); - fooEvent = jQuery.Event("foo"); + markup.trigger( "foo.bar" ); + markup.trigger( jQuery.Event( "foo.bar" ) ); + fooEvent = jQuery.Event( "foo" ); fooEvent.namespace = "bar"; markup.trigger( fooEvent ); markup.remove(); assert.equal( triggered, 3, "foo.bar triggered" ); -}); +} ); QUnit.test( "make sure events cloned correctly", function( assert ) { assert.expect( 18 ); var clone, - fixture = jQuery("#qunit-fixture"), - checkbox = jQuery("#check1"), - p = jQuery("#firstp"); + fixture = jQuery( "#qunit-fixture" ), + checkbox = jQuery( "#check1" ), + p = jQuery( "#firstp" ); fixture.on( "click change", function( event, result ) { assert.ok( result, event.type + " on original element is fired" ); - }).on( "click", "#firstp", function( event, result ) { + } ).on( "click", "#firstp", function( event, result ) { assert.ok( result, "Click on original child element though delegation is fired" ); - }).on( "change", "#check1", function( event, result ) { + } ).on( "change", "#check1", function( event, result ) { assert.ok( result, "Change on original child element though delegation is fired" ); - }); + } ); - p.on("click", function() { + p.on( "click", function() { assert.ok( true, "Click on original child element is fired" ); - }); + } ); - checkbox.on("change", function() { + checkbox.on( "change", function() { assert.ok( true, "Change on original child element is fired" ); - }); + } ); - fixture.clone().trigger("click").trigger("change"); // 0 events should be fired + fixture.clone().trigger( "click" ).trigger( "change" ); // 0 events should be fired clone = fixture.clone( true ); - clone.find("p").eq(0).trigger( "click", true ); // 3 events should fire - clone.find("#check1").trigger( "change", true ); // 3 events should fire + clone.find( "p" ).eq( 0 ).trigger( "click", true ); // 3 events should fire + clone.find( "#check1" ).trigger( "change", true ); // 3 events should fire clone.remove(); clone = fixture.clone( true, true ); - clone.find("p").eq(0).trigger( "click", true ); // 3 events should fire - clone.find("#check1").trigger( "change", true ); // 3 events should fire + clone.find( "p" ).eq( 0 ).trigger( "click", true ); // 3 events should fire + clone.find( "#check1" ).trigger( "change", true ); // 3 events should fire fixture.off(); p.off(); checkbox.off(); - p.trigger("click"); // 0 should be fired - checkbox.trigger("change"); // 0 should be fired + p.trigger( "click" ); // 0 should be fired + checkbox.trigger( "change" ); // 0 should be fired - clone.find("p").eq(0).trigger( "click", true ); // 3 events should fire - clone.find("#check1").trigger( "change", true ); // 3 events should fire + clone.find( "p" ).eq( 0 ).trigger( "click", true ); // 3 events should fire + clone.find( "#check1" ).trigger( "change", true ); // 3 events should fire clone.remove(); - clone.find("p").eq(0).trigger("click"); // 0 should be fired - clone.find("#check1").trigger("change"); // 0 events should fire -}); + clone.find( "p" ).eq( 0 ).trigger( "click" ); // 0 should be fired + clone.find( "#check1" ).trigger( "change" ); // 0 events should fire +} ); QUnit.test( "String.prototype.namespace does not cause trigger() to throw (#13360)", function( assert ) { assert.expect( 1 ); @@ -2671,21 +2679,21 @@ QUnit.test( "String.prototype.namespace does not cause trigger() to throw (#1336 String.prototype.namespace = function() {}; try { - jQuery("<p>").trigger("foo.bar"); - } catch( e ) { + jQuery( "<p>" ).trigger( "foo.bar" ); + } catch ( e ) { errored = true; } assert.equal( errored, false, "trigger() did not throw exception" ); delete String.prototype.namespace; -}); +} ); QUnit.test( "Inline event result is returned (#13993)", function( assert ) { assert.expect( 1 ); - var result = jQuery("<p onclick='return 42'>hello</p>").triggerHandler("click"); + var result = jQuery( "<p onclick='return 42'>hello</p>" ).triggerHandler( "click" ); assert.equal( result, 42, "inline handler returned value" ); -}); +} ); QUnit.test( ".off() removes the expando when there's no more data", function( assert ) { assert.expect( 1 ); @@ -2706,7 +2714,7 @@ QUnit.test( ".off() removes the expando when there's no more data", function( as assert.ok( false, "Expando was not removed when there was no more data" ); } } -}); +} ); QUnit.test( "preventDefault() on focusin does not throw exception", function( assert ) { assert.expect( 1 ); @@ -2765,7 +2773,7 @@ QUnit.test( "Donor event interference", function( assert ) { QUnit.test( "originalEvent property for Chrome, Safari and FF of simulated event", function( assert ) { var userAgent = window.navigator.userAgent; - if ( !(/chrome/i.test( userAgent ) || + if ( !( /chrome/i.test( userAgent ) || /firefox/i.test( userAgent ) || /safari/i.test( userAgent ) ) ) { assert.expect( 1 ); @@ -2796,7 +2804,7 @@ QUnit.test( "originalEvent property for Chrome, Safari and FF of simulated event } ); // This tests are unreliable in Firefox -if ( !(/firefox/i.test( window.navigator.userAgent )) ) { +if ( !( /firefox/i.test( window.navigator.userAgent ) ) ) { QUnit.test( "Check order of focusin/focusout events", function( assert ) { assert.expect( 2 ); @@ -2806,15 +2814,15 @@ if ( !(/firefox/i.test( window.navigator.userAgent )) ) { input.on( "focus", function() { focus = true; - }).on( "focusin", function() { + } ).on( "focusin", function() { assert.ok( !focus, "Focusin event should fire before focus does" ); - }).on( "blur", function() { + } ).on( "blur", function() { blur = true; - }).on( "focusout", function() { + } ).on( "focusout", function() { assert.ok( !blur, "Focusout event should fire before blur does" ); - }); + } ); // gain focus input.trigger( "focus" ); @@ -2824,43 +2832,43 @@ if ( !(/firefox/i.test( window.navigator.userAgent )) ) { // cleanup input.off(); - }); + } ); - QUnit.test("focus-blur order (#12868)", function( assert ) { + QUnit.test( "focus-blur order (#12868)", function( assert ) { assert.expect( 5 ); var order, - $text = jQuery("#text1"), - $radio = jQuery("#radio1").trigger("focus"); + $text = jQuery( "#text1" ), + $radio = jQuery( "#radio1" ).trigger( "focus" ); // IE8-10 fire focus/blur events asynchronously; this is the resulting mess. // IE's browser window must be topmost for this to work properly!! QUnit.stop(); - $radio[0].focus(); + $radio[ 0 ].focus(); setTimeout( function() { $text - .on( "focus", function(){ + .on( "focus", function() { assert.equal( order++, 1, "text focus" ); - }) - .on( "blur", function(){ + } ) + .on( "blur", function() { assert.equal( order++, 0, "text blur" ); - }); + } ); $radio - .on( "focus", function(){ + .on( "focus", function() { assert.equal( order++, 1, "radio focus" ); - }) - .on( "blur", function(){ + } ) + .on( "blur", function() { assert.equal( order++, 0, "radio blur" ); - }); + } ); // Enabled input getting focus order = 0; - assert.equal( document.activeElement, $radio[0], "radio has focus" ); - $text.trigger("focus"); + assert.equal( document.activeElement, $radio[ 0 ], "radio has focus" ); + $text.trigger( "focus" ); setTimeout( function() { - assert.equal( document.activeElement, $text[0], "text has focus" ); + assert.equal( document.activeElement, $text[ 0 ], "text has focus" ); // Run handlers without native method on an input order = 1; @@ -2869,5 +2877,5 @@ if ( !(/firefox/i.test( window.navigator.userAgent )) ) { QUnit.start(); }, 50 ); }, 50 ); - }); + } ); } diff --git a/test/unit/exports.js b/test/unit/exports.js index 39e4b1b47..bca8954cf 100644 --- a/test/unit/exports.js +++ b/test/unit/exports.js @@ -1,7 +1,7 @@ -QUnit.module("exports", { teardown: moduleTeardown }); +QUnit.module( "exports", { teardown: moduleTeardown } ); -QUnit.test("amdModule", function( assert ) { - assert.expect(1); +QUnit.test( "amdModule", function( assert ) { + assert.expect( 1 ); assert.equal( jQuery, amdDefined, "Make sure defined module matches jQuery" ); -}); +} ); diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js index 5cd91a30d..2daa78fc4 100644 --- a/test/unit/manipulation.js +++ b/test/unit/manipulation.js @@ -1,6 +1,6 @@ QUnit.module( "manipulation", { teardown: moduleTeardown -}); +} ); // Ensure that an extended Array prototype doesn't break jQuery Array.prototype.arrayProtoFn = function() { @@ -35,31 +35,31 @@ QUnit.test( "text()", function( assert ) { var expected, frag, $newLineTest; expected = "This link has class=\"blog\": Simon Willison's Weblog"; - assert.equal( jQuery("#sap").text(), expected, "Check for merged text of more then one element." ); + assert.equal( jQuery( "#sap" ).text(), expected, "Check for merged text of more then one element." ); // Check serialization of text values - assert.equal( jQuery(document.createTextNode("foo")).text(), "foo", "Text node was retrieved from .text()." ); - assert.notEqual( jQuery(document).text(), "", "Retrieving text for the document retrieves all text (#10724)." ); + assert.equal( jQuery( document.createTextNode( "foo" ) ).text(), "foo", "Text node was retrieved from .text()." ); + assert.notEqual( jQuery( document ).text(), "", "Retrieving text for the document retrieves all text (#10724)." ); // Retrieve from document fragments #10864 frag = document.createDocumentFragment(); - frag.appendChild( document.createTextNode("foo") ); + frag.appendChild( document.createTextNode( "foo" ) ); - assert.equal( jQuery(frag).text(), "foo", "Document Fragment Text node was retrieved from .text()." ); + assert.equal( jQuery( frag ).text(), "foo", "Document Fragment Text node was retrieved from .text()." ); - $newLineTest = jQuery("<div>test<br/>testy</div>").appendTo("#moretests"); - $newLineTest.find("br").replaceWith("\n"); + $newLineTest = jQuery( "<div>test<br/>testy</div>" ).appendTo( "#moretests" ); + $newLineTest.find( "br" ).replaceWith( "\n" ); assert.equal( $newLineTest.text(), "test\ntesty", "text() does not remove new lines (#11153)" ); $newLineTest.remove(); -}); +} ); QUnit.test( "text(undefined)", function( assert ) { assert.expect( 1 ); - assert.equal( jQuery("#foo").text("<div").text(undefined)[ 0 ].innerHTML, "<div", ".text(undefined) is chainable (#5571)" ); -}); + assert.equal( jQuery( "#foo" ).text( "<div" ).text( undefined )[ 0 ].innerHTML, "<div", ".text(undefined) is chainable (#5571)" ); +} ); function testText( valueObj, assert ) { @@ -67,12 +67,12 @@ function testText( valueObj, assert ) { var val, j, expected, $multipleElements, $parentDiv, $childDiv; - val = valueObj("<div><b>Hello</b> cruel world!</div>"); - assert.equal( jQuery("#foo").text(val)[ 0 ].innerHTML.replace(/>/g, ">"), "<div><b>Hello</b> cruel world!</div>", "Check escaped text" ); + val = valueObj( "<div><b>Hello</b> cruel world!</div>" ); + assert.equal( jQuery( "#foo" ).text( val )[ 0 ].innerHTML.replace( />/g, ">" ), "<div><b>Hello</b> cruel world!</div>", "Check escaped text" ); // using contents will get comments regular, text, and comment nodes - j = jQuery("#nonnodes").contents(); - j.text( valueObj("hi!") ); + j = jQuery( "#nonnodes" ).contents(); + j.text( valueObj( "hi!" ) ); assert.equal( jQuery( j[ 0 ] ).text(), "hi!", "Check node,textnode,comment with text()" ); assert.equal( j[ 1 ].nodeValue, " there ", "Check node,textnode,comment with text()" ); @@ -84,24 +84,24 @@ function testText( valueObj, assert ) { $multipleElements = jQuery( "<div>Hello</div>" ).add( "<div>World</div>" ); $multipleElements.text( expected ); - assert.equal( $multipleElements.eq(0).text(), expected, "text() updates multiple elements (#11809)" ); - assert.equal( $multipleElements.eq(1).text(), expected, "text() updates multiple elements (#11809)" ); + assert.equal( $multipleElements.eq( 0 ).text(), expected, "text() updates multiple elements (#11809)" ); + assert.equal( $multipleElements.eq( 1 ).text(), expected, "text() updates multiple elements (#11809)" ); // Prevent memory leaks #11809 $childDiv = jQuery( "<div/>" ); - $childDiv.data("leak", true); + $childDiv.data( "leak", true ); $parentDiv = jQuery( "<div/>" ); $parentDiv.append( $childDiv ); - $parentDiv.text("Dry off"); + $parentDiv.text( "Dry off" ); } QUnit.test( "text(String)", function( assert ) { testText( manipulationBareObj, assert ); -}); +} ); QUnit.test( "text(Function)", function( assert ) { testText( manipulationFunctionReturningObj, assert ); -}); +} ); QUnit.test( "text(Function) with incoming value", function( assert ) { @@ -109,43 +109,43 @@ QUnit.test( "text(Function) with incoming value", function( assert ) { var old = "This link has class=\"blog\": Simon Willison's Weblog"; - jQuery("#sap").text(function( i, val ) { + jQuery( "#sap" ).text( function( i, val ) { assert.equal( val, old, "Make sure the incoming value is correct." ); return "foobar"; - }); + } ); - assert.equal( jQuery("#sap").text(), "foobar", "Check for merged text of more then one element." ); -}); + assert.equal( jQuery( "#sap" ).text(), "foobar", "Check for merged text of more then one element." ); +} ); function testAppendForObject( valueObj, isFragment, assert ) { var $base, type = isFragment ? " (DocumentFragment)" : " (Element)", text = "This link has class=\"blog\": Simon Willison's Weblog", - el = document.getElementById("sap").cloneNode( true ), - first = document.getElementById("first"), - yahoo = document.getElementById("yahoo"); + el = document.getElementById( "sap" ).cloneNode( true ), + first = document.getElementById( "first" ), + yahoo = document.getElementById( "yahoo" ); if ( isFragment ) { $base = document.createDocumentFragment(); - jQuery( el ).contents().each(function() { + jQuery( el ).contents().each( function() { $base.appendChild( this ); - }); + } ); $base = jQuery( $base ); } else { $base = jQuery( el ); } - assert.equal( $base.clone().append( valueObj(first.cloneNode(true)) ).text(), + assert.equal( $base.clone().append( valueObj( first.cloneNode( true ) ) ).text(), text + "Try them out:", "Check for appending of element" + type ); - assert.equal( $base.clone().append( valueObj([ first.cloneNode(true), yahoo.cloneNode(true) ]) ).text(), + assert.equal( $base.clone().append( valueObj( [ first.cloneNode( true ), yahoo.cloneNode( true ) ] ) ).text(), text + "Try them out:Yahoo", "Check for appending of array of elements" + type ); - assert.equal( $base.clone().append( valueObj(jQuery("#yahoo, #first").clone()) ).text(), + assert.equal( $base.clone().append( valueObj( jQuery( "#yahoo, #first" ).clone() ) ).text(), text + "YahooTry them out:", "Check for appending of jQuery object" + type ); @@ -155,27 +155,27 @@ function testAppendForObject( valueObj, isFragment, assert ) { "Check for appending a number" + type ); - assert.equal( $base.clone().append( valueObj([ jQuery("#first").clone(), jQuery("#yahoo, #google").clone() ]) ).text(), + assert.equal( $base.clone().append( valueObj( [ jQuery( "#first" ).clone(), jQuery( "#yahoo, #google" ).clone() ] ) ).text(), text + "Try them out:GoogleYahoo", "Check for appending of array of jQuery objects" ); - assert.equal( $base.clone().append( valueObj(" text with spaces ") ).text(), + assert.equal( $base.clone().append( valueObj( " text with spaces " ) ).text(), text + " text with spaces ", "Check for appending text with spaces" + type ); - assert.equal( $base.clone().append( valueObj([]) ).text(), + assert.equal( $base.clone().append( valueObj( [] ) ).text(), text, "Check for appending an empty array" + type ); - assert.equal( $base.clone().append( valueObj("") ).text(), + assert.equal( $base.clone().append( valueObj( "" ) ).text(), text, "Check for appending an empty string" + type ); - assert.equal( $base.clone().append( valueObj(document.getElementsByTagName("foo")) ).text(), + assert.equal( $base.clone().append( valueObj( document.getElementsByTagName( "foo" ) ) ).text(), text, "Check for appending an empty nodelist" + type ); @@ -185,7 +185,7 @@ function testAppendForObject( valueObj, isFragment, assert ) { "Make sure that multiple arguments works." + type ); - assert.equal( $base.clone().append( valueObj(document.getElementById("form").cloneNode(true)) ).children("form").length, + assert.equal( $base.clone().append( valueObj( document.getElementById( "form" ).cloneNode( true ) ) ).children( "form" ).length, 1, "Check for appending a form (#910)" + type ); @@ -202,130 +202,130 @@ function testAppend( valueObj, assert ) { $input, $radioChecked, $radioUnchecked, $radioParent, $map, $table; defaultText = "Try them out:"; - result = jQuery("#first").append( valueObj("<b>buga</b>") ); + result = jQuery( "#first" ).append( valueObj( "<b>buga</b>" ) ); assert.equal( result.text(), defaultText + "buga", "Check if text appending works" ); - assert.equal( jQuery("#select3").append( valueObj("<option value='appendTest'>Append Test</option>") ).find("option:last-child").attr("value"), "appendTest", "Appending html options to select element" ); + assert.equal( jQuery( "#select3" ).append( valueObj( "<option value='appendTest'>Append Test</option>" ) ).find( "option:last-child" ).attr( "value" ), "appendTest", "Appending html options to select element" ); - jQuery("#qunit-fixture form").append( valueObj("<input name='radiotest' type='radio' checked='checked' />") ); - jQuery("#qunit-fixture form input[name=radiotest]").each(function() { - assert.ok( jQuery(this).is(":checked"), "Append checked radio" ); - }).remove(); + jQuery( "#qunit-fixture form" ).append( valueObj( "<input name='radiotest' type='radio' checked='checked' />" ) ); + jQuery( "#qunit-fixture form input[name=radiotest]" ).each( function() { + assert.ok( jQuery( this ).is( ":checked" ), "Append checked radio" ); + } ).remove(); - jQuery("#qunit-fixture form").append( valueObj("<input name='radiotest2' type='radio' checked = 'checked' />") ); - jQuery("#qunit-fixture form input[name=radiotest2]").each(function() { - assert.ok( jQuery(this).is(":checked"), "Append alternately formated checked radio" ); - }).remove(); + jQuery( "#qunit-fixture form" ).append( valueObj( "<input name='radiotest2' type='radio' checked = 'checked' />" ) ); + jQuery( "#qunit-fixture form input[name=radiotest2]" ).each( function() { + assert.ok( jQuery( this ).is( ":checked" ), "Append alternately formated checked radio" ); + } ).remove(); - jQuery("#qunit-fixture form").append( valueObj("<input name='radiotest3' type='radio' checked />") ); - jQuery("#qunit-fixture form input[name=radiotest3]").each(function() { - assert.ok( jQuery(this).is(":checked"), "Append HTML5-formated checked radio" ); - }).remove(); + jQuery( "#qunit-fixture form" ).append( valueObj( "<input name='radiotest3' type='radio' checked />" ) ); + jQuery( "#qunit-fixture form input[name=radiotest3]" ).each( function() { + assert.ok( jQuery( this ).is( ":checked" ), "Append HTML5-formated checked radio" ); + } ).remove(); - jQuery("#qunit-fixture form").append( valueObj("<input type='radio' checked='checked' name='radiotest4' />") ); - jQuery("#qunit-fixture form input[name=radiotest4]").each(function() { - assert.ok( jQuery(this).is(":checked"), "Append with name attribute after checked attribute" ); - }).remove(); + jQuery( "#qunit-fixture form" ).append( valueObj( "<input type='radio' checked='checked' name='radiotest4' />" ) ); + jQuery( "#qunit-fixture form input[name=radiotest4]" ).each( function() { + assert.ok( jQuery( this ).is( ":checked" ), "Append with name attribute after checked attribute" ); + } ).remove(); message = "Test for appending a DOM node to the contents of an iframe"; - iframe = jQuery("#iframe")[ 0 ]; + iframe = jQuery( "#iframe" )[ 0 ]; iframeDoc = iframe.contentDocument || iframe.contentWindow && iframe.contentWindow.document; try { if ( iframeDoc && iframeDoc.body ) { - assert.equal( jQuery(iframeDoc.body).append( valueObj("<div id='success'>test</div>") )[ 0 ].lastChild.id, "success", message ); + assert.equal( jQuery( iframeDoc.body ).append( valueObj( "<div id='success'>test</div>" ) )[ 0 ].lastChild.id, "success", message ); } else { assert.ok( true, message + " - can't test" ); } - } catch( e ) { + } catch ( e ) { assert.strictEqual( e.message || e, undefined, message ); } - jQuery("<fieldset/>").appendTo("#form").append( valueObj("<legend id='legend'>test</legend>") ); + jQuery( "<fieldset/>" ).appendTo( "#form" ).append( valueObj( "<legend id='legend'>test</legend>" ) ); t( "Append legend", "#legend", [ "legend" ] ); - $map = jQuery("<map/>").append( valueObj("<area id='map01' shape='rect' coords='50,50,150,150' href='http://www.jquery.com/' alt='jQuery'>") ); + $map = jQuery( "<map/>" ).append( valueObj( "<area id='map01' shape='rect' coords='50,50,150,150' href='http://www.jquery.com/' alt='jQuery'>" ) ); assert.equal( $map[ 0 ].childNodes.length, 1, "The area was inserted." ); assert.equal( $map[ 0 ].firstChild.nodeName.toLowerCase(), "area", "The area was inserted." ); - jQuery("#select1").append( valueObj("<OPTION>Test</OPTION>") ); - assert.equal( jQuery("#select1 option:last-child").text(), "Test", "Appending OPTION (all caps)" ); + jQuery( "#select1" ).append( valueObj( "<OPTION>Test</OPTION>" ) ); + assert.equal( jQuery( "#select1 option:last-child" ).text(), "Test", "Appending OPTION (all caps)" ); - jQuery("#select1").append( valueObj("<optgroup label='optgroup'><option>optgroup</option></optgroup>") ); - assert.equal( jQuery("#select1 optgroup").attr("label"), "optgroup", "Label attribute in newly inserted optgroup is correct" ); - assert.equal( jQuery("#select1 option").last().text(), "optgroup", "Appending optgroup" ); + jQuery( "#select1" ).append( valueObj( "<optgroup label='optgroup'><option>optgroup</option></optgroup>" ) ); + assert.equal( jQuery( "#select1 optgroup" ).attr( "label" ), "optgroup", "Label attribute in newly inserted optgroup is correct" ); + assert.equal( jQuery( "#select1 option" ).last().text(), "optgroup", "Appending optgroup" ); - $table = jQuery("#table"); + $table = jQuery( "#table" ); - jQuery.each( "thead tbody tfoot colgroup caption tr th td".split(" "), function( i, name ) { + jQuery.each( "thead tbody tfoot colgroup caption tr th td".split( " " ), function( i, name ) { $table.append( valueObj( "<" + name + "/>" ) ); assert.equal( $table.find( name ).length, 1, "Append " + name ); assert.ok( jQuery.parseHTML( "<" + name + "/>" ).length, name + " wrapped correctly" ); - }); + } ); - jQuery("#table colgroup").append( valueObj("<col/>") ); - assert.equal( jQuery("#table colgroup col").length, 1, "Append col" ); + jQuery( "#table colgroup" ).append( valueObj( "<col/>" ) ); + assert.equal( jQuery( "#table colgroup col" ).length, 1, "Append col" ); - jQuery("#form") - .append( valueObj("<select id='appendSelect1'></select>") ) - .append( valueObj("<select id='appendSelect2'><option>Test</option></select>") ); + jQuery( "#form" ) + .append( valueObj( "<select id='appendSelect1'></select>" ) ) + .append( valueObj( "<select id='appendSelect2'><option>Test</option></select>" ) ); t( "Append Select", "#appendSelect1, #appendSelect2", [ "appendSelect1", "appendSelect2" ] ); - assert.equal( "Two nodes", jQuery("<div />").append( "Two", " nodes" ).text(), "Appending two text nodes (#4011)" ); - assert.equal( jQuery("<div />").append( "1", "", 3 ).text(), "13", "If median is false-like value, subsequent arguments should not be ignored" ); + assert.equal( "Two nodes", jQuery( "<div />" ).append( "Two", " nodes" ).text(), "Appending two text nodes (#4011)" ); + assert.equal( jQuery( "<div />" ).append( "1", "", 3 ).text(), "13", "If median is false-like value, subsequent arguments should not be ignored" ); // using contents will get comments regular, text, and comment nodes - j = jQuery("#nonnodes").contents(); - d = jQuery("<div/>").appendTo("#nonnodes").append( j ); + j = jQuery( "#nonnodes" ).contents(); + d = jQuery( "<div/>" ).appendTo( "#nonnodes" ).append( j ); - assert.equal( jQuery("#nonnodes").length, 1, "Check node,textnode,comment append moved leaving just the div" ); + assert.equal( jQuery( "#nonnodes" ).length, 1, "Check node,textnode,comment append moved leaving just the div" ); assert.equal( d.contents().length, 3, "Check node,textnode,comment append works" ); - d.contents().appendTo("#nonnodes"); + d.contents().appendTo( "#nonnodes" ); d.remove(); - assert.equal( jQuery("#nonnodes").contents().length, 3, "Check node,textnode,comment append cleanup worked" ); + assert.equal( jQuery( "#nonnodes" ).contents().length, 3, "Check node,textnode,comment append cleanup worked" ); - $input = jQuery("<input type='checkbox'/>").prop( "checked", true ).appendTo("#testForm"); + $input = jQuery( "<input type='checkbox'/>" ).prop( "checked", true ).appendTo( "#testForm" ); assert.equal( $input[ 0 ].checked, true, "A checked checkbox that is appended stays checked" ); - $radioChecked = jQuery("input[type='radio'][name='R1']").eq( 1 ); + $radioChecked = jQuery( "input[type='radio'][name='R1']" ).eq( 1 ); $radioParent = $radioChecked.parent(); - $radioUnchecked = jQuery("<input type='radio' name='R1' checked='checked'/>").appendTo( $radioParent ); - $radioChecked.trigger("click"); + $radioUnchecked = jQuery( "<input type='radio' name='R1' checked='checked'/>" ).appendTo( $radioParent ); + $radioChecked.trigger( "click" ); $radioUnchecked[ 0 ].checked = false; - jQuery("<div/>").insertBefore($radioParent).append($radioParent); + jQuery( "<div/>" ).insertBefore( $radioParent ).append( $radioParent ); assert.equal( $radioChecked[ 0 ].checked, true, "Reappending radios uphold which radio is checked" ); assert.equal( $radioUnchecked[ 0 ].checked, false, "Reappending radios uphold not being checked" ); - assert.equal( jQuery("<div/>").append( valueObj("option<area/>") )[ 0 ].childNodes.length, 2, "HTML-string with leading text should be processed correctly" ); + assert.equal( jQuery( "<div/>" ).append( valueObj( "option<area/>" ) )[ 0 ].childNodes.length, 2, "HTML-string with leading text should be processed correctly" ); } QUnit.test( "append(String|Element|Array<Element>|jQuery)", function( assert ) { testAppend( manipulationBareObj, assert ); -}); +} ); QUnit.test( "append(Function)", function( assert ) { testAppend( manipulationFunctionReturningObj, assert ); -}); +} ); QUnit.test( "append(param) to object, see #11280", function( assert ) { assert.expect( 5 ); - var object = jQuery( document.createElement("object") ).appendTo( document.body ); + var object = jQuery( document.createElement( "object" ) ).appendTo( document.body ); assert.equal( object.children().length, 0, "object does not start with children" ); - object.append( jQuery("<param type='wmode' name='foo'>") ); + object.append( jQuery( "<param type='wmode' name='foo'>" ) ); assert.equal( object.children().length, 1, "appended param" ); - assert.equal( object.children().eq(0).attr("name"), "foo", "param has name=foo" ); + assert.equal( object.children().eq( 0 ).attr( "name" ), "foo", "param has name=foo" ); - object = jQuery("<object><param type='baz' name='bar'></object>"); + object = jQuery( "<object><param type='baz' name='bar'></object>" ); assert.equal( object.children().length, 1, "object created with child param" ); - assert.equal( object.children().eq(0).attr("name"), "bar", "param has name=bar" ); -}); + assert.equal( object.children().eq( 0 ).attr( "name" ), "bar", "param has name=bar" ); +} ); QUnit.test( "append(Function) returns String", function( assert ) { @@ -334,86 +334,86 @@ QUnit.test( "append(Function) returns String", function( assert ) { var defaultText, result, select, old; defaultText = "Try them out:"; - old = jQuery("#first").html(); + old = jQuery( "#first" ).html(); - result = jQuery("#first").append(function( i, val ) { + result = jQuery( "#first" ).append( function( i, val ) { assert.equal( val, old, "Make sure the incoming value is correct." ); return "<b>buga</b>"; - }); + } ); assert.equal( result.text(), defaultText + "buga", "Check if text appending works" ); - select = jQuery("#select3"); + select = jQuery( "#select3" ); old = select.html(); - assert.equal( select.append(function( i, val ) { + assert.equal( select.append( function( i, val ) { assert.equal( val, old, "Make sure the incoming value is correct." ); return "<option value='appendTest'>Append Test</option>"; - }).find("option:last-child").attr("value"), "appendTest", "Appending html options to select element" ); -}); + } ).find( "option:last-child" ).attr( "value" ), "appendTest", "Appending html options to select element" ); +} ); QUnit.test( "append(Function) returns Element", function( assert ) { assert.expect( 2 ); var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:", - old = jQuery("#sap").html(); + old = jQuery( "#sap" ).html(); - jQuery("#sap").append(function( i, val ) { + jQuery( "#sap" ).append( function( i, val ) { assert.equal( val, old, "Make sure the incoming value is correct." ); - return document.getElementById("first"); - }); - assert.equal( jQuery("#sap").text(), expected, "Check for appending of element" ); -}); + return document.getElementById( "first" ); + } ); + assert.equal( jQuery( "#sap" ).text(), expected, "Check for appending of element" ); +} ); QUnit.test( "append(Function) returns Array<Element>", function( assert ) { assert.expect( 2 ); var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo", - old = jQuery("#sap").html(); + old = jQuery( "#sap" ).html(); - jQuery("#sap").append(function( i, val ) { + jQuery( "#sap" ).append( function( i, val ) { assert.equal( val, old, "Make sure the incoming value is correct." ); - return [ document.getElementById("first"), document.getElementById("yahoo") ]; - }); - assert.equal( jQuery("#sap").text(), expected, "Check for appending of array of elements" ); -}); + return [ document.getElementById( "first" ), document.getElementById( "yahoo" ) ]; + } ); + assert.equal( jQuery( "#sap" ).text(), expected, "Check for appending of array of elements" ); +} ); QUnit.test( "append(Function) returns jQuery", function( assert ) { assert.expect( 2 ); var expected = "This link has class=\"blog\": Simon Willison's WeblogYahooTry them out:", - old = jQuery("#sap").html(); + old = jQuery( "#sap" ).html(); - jQuery("#sap").append(function( i, val ) { + jQuery( "#sap" ).append( function( i, val ) { assert.equal( val, old, "Make sure the incoming value is correct." ); - return jQuery("#yahoo, #first"); - }); - assert.equal( jQuery("#sap").text(), expected, "Check for appending of jQuery object" ); -}); + return jQuery( "#yahoo, #first" ); + } ); + assert.equal( jQuery( "#sap" ).text(), expected, "Check for appending of jQuery object" ); +} ); QUnit.test( "append(Function) returns Number", function( assert ) { assert.expect( 2 ); - var old = jQuery("#sap").html(); + var old = jQuery( "#sap" ).html(); - jQuery("#sap").append(function( i, val ) { + jQuery( "#sap" ).append( function( i, val ) { assert.equal( val, old, "Make sure the incoming value is correct." ); return 5; - }); - assert.ok( jQuery("#sap")[ 0 ].innerHTML.match( /5$/ ), "Check for appending a number" ); -}); + } ); + assert.ok( jQuery( "#sap" )[ 0 ].innerHTML.match( /5$/ ), "Check for appending a number" ); +} ); QUnit.test( "XML DOM manipulation (#9960)", function( assert ) { assert.expect( 5 ); var scxml1Adopted, - xmlDoc1 = jQuery.parseXML("<scxml xmlns='http://www.w3.org/2005/07/scxml' version='1.0'><state x='100' y='100' initial='actions' id='provisioning'></state><state x='100' y='100' id='error'></state><state x='100' y='100' id='finished' final='true'></state></scxml>"), - xmlDoc2 = jQuery.parseXML("<scxml xmlns='http://www.w3.org/2005/07/scxml' version='1.0'><state id='provisioning3'></state></scxml>"), + xmlDoc1 = jQuery.parseXML( "<scxml xmlns='http://www.w3.org/2005/07/scxml' version='1.0'><state x='100' y='100' initial='actions' id='provisioning'></state><state x='100' y='100' id='error'></state><state x='100' y='100' id='finished' final='true'></state></scxml>" ), + xmlDoc2 = jQuery.parseXML( "<scxml xmlns='http://www.w3.org/2005/07/scxml' version='1.0'><state id='provisioning3'></state></scxml>" ), xml1 = jQuery( xmlDoc1 ), xml2 = jQuery( xmlDoc2 ), scxml1 = jQuery( "scxml", xml1 ), scxml2 = jQuery( "scxml", xml2 ), - state = scxml2.find("state"); + state = scxml2.find( "state" ); // Android 2.3 doesn't automatically adopt nodes from foreign documents. // Although technically this is compliant behavior, no other browser @@ -425,16 +425,16 @@ QUnit.test( "XML DOM manipulation (#9960)", function( assert ) { } scxml1.append( state ); - assert.strictEqual( scxml1[0].lastChild, state[0], "append" ); + assert.strictEqual( scxml1[ 0 ].lastChild, state[ 0 ], "append" ); scxml1.prepend( state ); - assert.strictEqual( scxml1[0].firstChild, state[0], "prepend" ); + assert.strictEqual( scxml1[ 0 ].firstChild, state[ 0 ], "prepend" ); - scxml1.find("#finished").after( state ); - assert.strictEqual( scxml1[0].lastChild, state[0], "after" ); + scxml1.find( "#finished" ).after( state ); + assert.strictEqual( scxml1[ 0 ].lastChild, state[ 0 ], "after" ); - scxml1.find("#provisioning").before( state ); - assert.strictEqual( scxml1[0].firstChild, state[0], "before" ); + scxml1.find( "#provisioning" ).before( state ); + assert.strictEqual( scxml1[ 0 ].firstChild, state[ 0 ], "before" ); // Support: Android 2.3 if ( /android 2\.3/i.test( navigator.userAgent ) ) { @@ -443,8 +443,8 @@ QUnit.test( "XML DOM manipulation (#9960)", function( assert ) { } else { scxml2.replaceWith( scxml1 ); } - assert.deepEqual( jQuery( "state", xml2 ).get(), scxml1.find("state").get(), "replaceWith" ); -}); + assert.deepEqual( jQuery( "state", xml2 ).get(), scxml1.find( "state" ).get(), "replaceWith" ); +} ); QUnit.test( "append HTML5 sectioning elements (Bug #6485)", function( assert ) { @@ -452,75 +452,75 @@ QUnit.test( "append HTML5 sectioning elements (Bug #6485)", function( assert ) { var article, aside; - jQuery("#qunit-fixture").append("<article style='font-size:10px'><section><aside>HTML5 elements</aside></section></article>"); + jQuery( "#qunit-fixture" ).append( "<article style='font-size:10px'><section><aside>HTML5 elements</aside></section></article>" ); - article = jQuery("article"); - aside = jQuery("aside"); + article = jQuery( "article" ); + aside = jQuery( "aside" ); assert.equal( article.get( 0 ).style.fontSize, "10px", "HTML5 elements are styleable" ); assert.equal( aside.length, 1, "HTML5 elements do not collapse their children" ); -}); +} ); if ( jQuery.css ) { QUnit.test( "HTML5 Elements inherit styles from style rules (Bug #10501)", function( assert ) { assert.expect( 1 ); - jQuery("#qunit-fixture").append("<article id='article'></article>"); - jQuery("#article").append("<section>This section should have a pink background.</section>"); + jQuery( "#qunit-fixture" ).append( "<article id='article'></article>" ); + jQuery( "#article" ).append( "<section>This section should have a pink background.</section>" ); // In IE, the missing background color will claim its value is "transparent" - assert.notEqual( jQuery("section").css("background-color"), "transparent", "HTML5 elements inherit styles" ); - }); + assert.notEqual( jQuery( "section" ).css( "background-color" ), "transparent", "HTML5 elements inherit styles" ); + } ); } QUnit.test( "html(String) with HTML5 (Bug #6485)", function( assert ) { assert.expect( 2 ); - jQuery("#qunit-fixture").html("<article><section><aside>HTML5 elements</aside></section></article>"); - assert.equal( jQuery("#qunit-fixture").children().children().length, 1, "Make sure HTML5 article elements can hold children. innerHTML shortcut path" ); - assert.equal( jQuery("#qunit-fixture").children().children().children().length, 1, "Make sure nested HTML5 elements can hold children." ); -}); + jQuery( "#qunit-fixture" ).html( "<article><section><aside>HTML5 elements</aside></section></article>" ); + assert.equal( jQuery( "#qunit-fixture" ).children().children().length, 1, "Make sure HTML5 article elements can hold children. innerHTML shortcut path" ); + assert.equal( jQuery( "#qunit-fixture" ).children().children().children().length, 1, "Make sure nested HTML5 elements can hold children." ); +} ); QUnit.test( "html(String) tag-hyphenated elements (Bug #1987)", function( assert ) { assert.expect( 27 ); - jQuery.each( "thead tbody tfoot colgroup caption tr th td".split(" "), function( i, name ) { - var j = jQuery("<" + name + "-d></" + name + "-d><" + name + "-d></" + name + "-d>"); - assert.ok( j[0], "Create a tag-hyphenated element" ); - assert.ok( jQuery.nodeName(j[0], name.toUpperCase() + "-D"), "Hyphenated node name" ); - assert.ok( jQuery.nodeName(j[1], name.toUpperCase() + "-D"), "Hyphenated node name" ); - }); + jQuery.each( "thead tbody tfoot colgroup caption tr th td".split( " " ), function( i, name ) { + var j = jQuery( "<" + name + "-d></" + name + "-d><" + name + "-d></" + name + "-d>" ); + assert.ok( j[ 0 ], "Create a tag-hyphenated element" ); + assert.ok( jQuery.nodeName( j[ 0 ], name.toUpperCase() + "-D" ), "Hyphenated node name" ); + assert.ok( jQuery.nodeName( j[ 1 ], name.toUpperCase() + "-D" ), "Hyphenated node name" ); + } ); - var j = jQuery("<tr-multiple-hyphens><td-with-hyphen>text</td-with-hyphen></tr-multiple-hyphens>"); - assert.ok( jQuery.nodeName(j[0], "TR-MULTIPLE-HYPHENS"), "Tags with multiple hypens" ); - assert.ok( jQuery.nodeName(j.children()[0], "TD-WITH-HYPHEN"), "Tags with multiple hypens" ); + var j = jQuery( "<tr-multiple-hyphens><td-with-hyphen>text</td-with-hyphen></tr-multiple-hyphens>" ); + assert.ok( jQuery.nodeName( j[ 0 ], "TR-MULTIPLE-HYPHENS" ), "Tags with multiple hypens" ); + assert.ok( jQuery.nodeName( j.children()[ 0 ], "TD-WITH-HYPHEN" ), "Tags with multiple hypens" ); assert.equal( j.children().text(), "text", "Tags with multiple hypens behave normally" ); -}); +} ); QUnit.test( "IE8 serialization bug", function( assert ) { assert.expect( 2 ); - var wrapper = jQuery("<div></div>"); + var wrapper = jQuery( "<div></div>" ); - wrapper.html("<div></div><article></article>"); - assert.equal( wrapper.children("article").length, 1, "HTML5 elements are insertable with .html()" ); + wrapper.html( "<div></div><article></article>" ); + assert.equal( wrapper.children( "article" ).length, 1, "HTML5 elements are insertable with .html()" ); - wrapper.html("<div></div><link></link>"); - assert.equal( wrapper.children("link").length, 1, "Link elements are insertable with .html()" ); -}); + wrapper.html( "<div></div><link></link>" ); + assert.equal( wrapper.children( "link" ).length, 1, "Link elements are insertable with .html()" ); +} ); QUnit.test( "html() object element #10324", function( assert ) { assert.expect( 1 ); - var object = jQuery("<object id='object2'><param name='object2test' value='test'></param></object>?").appendTo("#qunit-fixture"), + var object = jQuery( "<object id='object2'><param name='object2test' value='test'></param></object>?" ).appendTo( "#qunit-fixture" ), clone = object.clone(); assert.equal( clone.html(), object.html(), "html() returns correct innerhtml of cloned object elements" ); -}); +} ); QUnit.test( "append(xml)", function( assert ) { @@ -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,23 +542,24 @@ 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 { elem = new ActiveXObject( aActiveX[ n ] ); return elem; - } catch(_) {} + } catch ( _ ) {} } } } xmlDoc = createXMLDoc(); - xml1 = xmlDoc.createElement("head"); - xml2 = xmlDoc.createElement("test"); + xml1 = xmlDoc.createElement( "head" ); + xml2 = xmlDoc.createElement( "test" ); - assert.ok( jQuery(xml1).append(xml2), "Append an xml element to another without raising an exception." ); + assert.ok( jQuery( xml1 ).append( xml2 ), "Append an xml element to another without raising an exception." ); -}); +} ); QUnit.test( "appendTo(String)", function( assert ) { @@ -566,76 +568,76 @@ QUnit.test( "appendTo(String)", function( assert ) { var l, defaultText; defaultText = "Try them out:"; - jQuery("<b>buga</b>").appendTo("#first"); - assert.equal( jQuery("#first").text(), defaultText + "buga", "Check if text appending works" ); - assert.equal( jQuery("<option value='appendTest'>Append Test</option>").appendTo("#select3").parent().find("option:last-child").attr("value"), "appendTest", "Appending html options to select element" ); - - l = jQuery("#first").children().length + 2; - jQuery("<strong>test</strong>"); - jQuery("<strong>test</strong>"); - jQuery([ jQuery("<strong>test</strong>")[ 0 ], jQuery("<strong>test</strong>")[ 0 ] ]) - .appendTo("#first"); - assert.equal( jQuery("#first").children().length, l, "Make sure the elements were inserted." ); - assert.equal( jQuery("#first").children().last()[ 0 ].nodeName.toLowerCase(), "strong", "Verify the last element." ); -}); + jQuery( "<b>buga</b>" ).appendTo( "#first" ); + assert.equal( jQuery( "#first" ).text(), defaultText + "buga", "Check if text appending works" ); + assert.equal( jQuery( "<option value='appendTest'>Append Test</option>" ).appendTo( "#select3" ).parent().find( "option:last-child" ).attr( "value" ), "appendTest", "Appending html options to select element" ); + + l = jQuery( "#first" ).children().length + 2; + jQuery( "<strong>test</strong>" ); + jQuery( "<strong>test</strong>" ); + jQuery( [ jQuery( "<strong>test</strong>" )[ 0 ], jQuery( "<strong>test</strong>" )[ 0 ] ] ) + .appendTo( "#first" ); + assert.equal( jQuery( "#first" ).children().length, l, "Make sure the elements were inserted." ); + assert.equal( jQuery( "#first" ).children().last()[ 0 ].nodeName.toLowerCase(), "strong", "Verify the last element." ); +} ); QUnit.test( "appendTo(Element|Array<Element>)", function( assert ) { assert.expect( 2 ); var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:"; - jQuery( document.getElementById("first") ).appendTo("#sap"); - assert.equal( jQuery("#sap").text(), expected, "Check for appending of element" ); + jQuery( document.getElementById( "first" ) ).appendTo( "#sap" ); + assert.equal( jQuery( "#sap" ).text(), expected, "Check for appending of element" ); expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo"; - jQuery([ document.getElementById("first"), document.getElementById("yahoo") ]).appendTo("#sap"); - assert.equal( jQuery("#sap").text(), expected, "Check for appending of array of elements" ); + jQuery( [ document.getElementById( "first" ), document.getElementById( "yahoo" ) ] ).appendTo( "#sap" ); + assert.equal( jQuery( "#sap" ).text(), expected, "Check for appending of array of elements" ); -}); +} ); QUnit.test( "appendTo(jQuery)", function( assert ) { assert.expect( 10 ); var expected, num, div; - assert.ok( jQuery(document.createElement("script")).appendTo("body").length, "Make sure a disconnected script can be appended." ); + assert.ok( jQuery( document.createElement( "script" ) ).appendTo( "body" ).length, "Make sure a disconnected script can be appended." ); expected = "This link has class=\"blog\": Simon Willison's WeblogYahooTry them out:"; - jQuery("#yahoo, #first").appendTo("#sap"); - assert.equal( jQuery("#sap").text(), expected, "Check for appending of jQuery object" ); + jQuery( "#yahoo, #first" ).appendTo( "#sap" ); + assert.equal( jQuery( "#sap" ).text(), expected, "Check for appending of jQuery object" ); - jQuery("#select1").appendTo("#foo"); + jQuery( "#select1" ).appendTo( "#foo" ); t( "Append select", "#foo select", [ "select1" ] ); - div = jQuery("<div/>").on( "click", function() { + div = jQuery( "<div/>" ).on( "click", function() { assert.ok( true, "Running a cloned click." ); - }); - div.appendTo("#qunit-fixture, #moretests"); + } ); + div.appendTo( "#qunit-fixture, #moretests" ); - jQuery("#qunit-fixture div").last().trigger("click"); - jQuery("#moretests div").last().trigger("click"); + jQuery( "#qunit-fixture div" ).last().trigger( "click" ); + jQuery( "#moretests div" ).last().trigger( "click" ); - div = jQuery("<div/>").appendTo("#qunit-fixture, #moretests"); + div = jQuery( "<div/>" ).appendTo( "#qunit-fixture, #moretests" ); assert.equal( div.length, 2, "appendTo returns the inserted elements" ); - div.addClass("test"); + div.addClass( "test" ); - assert.ok( jQuery("#qunit-fixture div").last().hasClass("test"), "appendTo element was modified after the insertion" ); - assert.ok( jQuery("#moretests div").last().hasClass("test"), "appendTo element was modified after the insertion" ); + assert.ok( jQuery( "#qunit-fixture div" ).last().hasClass( "test" ), "appendTo element was modified after the insertion" ); + assert.ok( jQuery( "#moretests div" ).last().hasClass( "test" ), "appendTo element was modified after the insertion" ); - div = jQuery("<div/>"); - jQuery("<span>a</span><b>b</b>").filter("span").appendTo( div ); + div = jQuery( "<div/>" ); + jQuery( "<span>a</span><b>b</b>" ).filter( "span" ).appendTo( div ); assert.equal( div.children().length, 1, "Make sure the right number of children were inserted." ); - div = jQuery("#moretests div"); + div = jQuery( "#moretests div" ); - num = jQuery("#qunit-fixture div").length; - div.remove().appendTo("#qunit-fixture"); + num = jQuery( "#qunit-fixture div" ).length; + div.remove().appendTo( "#qunit-fixture" ); - assert.equal( jQuery("#qunit-fixture div").length, num, "Make sure all the removed divs were inserted." ); -}); + assert.equal( jQuery( "#qunit-fixture div" ).length, num, "Make sure all the removed divs were inserted." ); +} ); QUnit.test( "prepend(String)", function( assert ) { @@ -643,10 +645,10 @@ QUnit.test( "prepend(String)", function( assert ) { var result, expected; expected = "Try them out:"; - result = jQuery("#first").prepend( "<b>buga</b>" ); + result = jQuery( "#first" ).prepend( "<b>buga</b>" ); assert.equal( result.text(), "buga" + expected, "Check if text prepending works" ); - assert.equal( jQuery("#select3").prepend( "<option value='prependTest'>Prepend Test</option>" ).find("option:first-child").attr("value"), "prependTest", "Prepending html options to select element" ); -}); + assert.equal( jQuery( "#select3" ).prepend( "<option value='prependTest'>Prepend Test</option>" ).find( "option:first-child" ).attr( "value" ), "prependTest", "Prepending html options to select element" ); +} ); QUnit.test( "prepend(Element)", function( assert ) { @@ -654,9 +656,9 @@ QUnit.test( "prepend(Element)", function( assert ) { var expected; expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog"; - jQuery("#sap").prepend( document.getElementById("first") ); - assert.equal( jQuery("#sap").text(), expected, "Check for prepending of element" ); -}); + jQuery( "#sap" ).prepend( document.getElementById( "first" ) ); + assert.equal( jQuery( "#sap" ).text(), expected, "Check for prepending of element" ); +} ); QUnit.test( "prepend(Array<Element>)", function( assert ) { @@ -664,9 +666,9 @@ QUnit.test( "prepend(Array<Element>)", function( assert ) { var expected; expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog"; - jQuery("#sap").prepend( [ document.getElementById("first"), document.getElementById("yahoo") ] ); - assert.equal( jQuery("#sap").text(), expected, "Check for prepending of array of elements" ); -}); + jQuery( "#sap" ).prepend( [ document.getElementById( "first" ), document.getElementById( "yahoo" ) ] ); + assert.equal( jQuery( "#sap" ).text(), expected, "Check for prepending of array of elements" ); +} ); QUnit.test( "prepend(jQuery)", function( assert ) { @@ -674,9 +676,9 @@ QUnit.test( "prepend(jQuery)", function( assert ) { var expected; expected = "YahooTry them out:This link has class=\"blog\": Simon Willison's Weblog"; - jQuery("#sap").prepend( jQuery("#yahoo, #first") ); - assert.equal( jQuery("#sap").text(), expected, "Check for prepending of jQuery object" ); -}); + jQuery( "#sap" ).prepend( jQuery( "#yahoo, #first" ) ); + assert.equal( jQuery( "#sap" ).text(), expected, "Check for prepending of jQuery object" ); +} ); QUnit.test( "prepend(Array<jQuery>)", function( assert ) { @@ -684,9 +686,9 @@ QUnit.test( "prepend(Array<jQuery>)", function( assert ) { var expected; expected = "Try them out:GoogleYahooThis link has class=\"blog\": Simon Willison's Weblog"; - jQuery("#sap").prepend( [ jQuery("#first"), jQuery("#yahoo, #google") ] ); - assert.equal( jQuery("#sap").text(), expected, "Check for prepending of array of jQuery objects" ); -}); + jQuery( "#sap" ).prepend( [ jQuery( "#first" ), jQuery( "#yahoo, #google" ) ] ); + assert.equal( jQuery( "#sap" ).text(), expected, "Check for prepending of array of jQuery objects" ); +} ); QUnit.test( "prepend(Function) with incoming value -- String", function( assert ) { @@ -695,21 +697,21 @@ QUnit.test( "prepend(Function) with incoming value -- String", function( assert var defaultText, old, result; defaultText = "Try them out:"; - old = jQuery("#first").html(); - result = jQuery("#first").prepend(function( i, val ) { + old = jQuery( "#first" ).html(); + result = jQuery( "#first" ).prepend( function( i, val ) { assert.equal( val, old, "Make sure the incoming value is correct." ); return "<b>buga</b>"; - }); + } ); assert.equal( result.text(), "buga" + defaultText, "Check if text prepending works" ); - old = jQuery("#select3").html(); + old = jQuery( "#select3" ).html(); - assert.equal( jQuery("#select3").prepend(function( i, val ) { + assert.equal( jQuery( "#select3" ).prepend( function( i, val ) { assert.equal( val, old, "Make sure the incoming value is correct." ); return "<option value='prependTest'>Prepend Test</option>"; - }).find("option:first-child").attr("value"), "prependTest", "Prepending html options to select element" ); -}); + } ).find( "option:first-child" ).attr( "value" ), "prependTest", "Prepending html options to select element" ); +} ); QUnit.test( "prepend(Function) with incoming value -- Element", function( assert ) { @@ -717,15 +719,15 @@ QUnit.test( "prepend(Function) with incoming value -- Element", function( assert var old, expected; expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog"; - old = jQuery("#sap").html(); + old = jQuery( "#sap" ).html(); - jQuery("#sap").prepend(function( i, val ) { + jQuery( "#sap" ).prepend( function( i, val ) { assert.equal( val, old, "Make sure the incoming value is correct." ); - return document.getElementById("first"); - }); + return document.getElementById( "first" ); + } ); - assert.equal( jQuery("#sap").text(), expected, "Check for prepending of element" ); -}); + assert.equal( jQuery( "#sap" ).text(), expected, "Check for prepending of element" ); +} ); QUnit.test( "prepend(Function) with incoming value -- Array<Element>", function( assert ) { @@ -733,15 +735,15 @@ QUnit.test( "prepend(Function) with incoming value -- Array<Element>", function( var old, expected; expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog"; - old = jQuery("#sap").html(); + old = jQuery( "#sap" ).html(); - jQuery("#sap").prepend(function( i, val ) { + jQuery( "#sap" ).prepend( function( i, val ) { assert.equal( val, old, "Make sure the incoming value is correct." ); - return [ document.getElementById("first"), document.getElementById("yahoo") ]; - }); + return [ document.getElementById( "first" ), document.getElementById( "yahoo" ) ]; + } ); - assert.equal( jQuery("#sap").text(), expected, "Check for prepending of array of elements" ); -}); + assert.equal( jQuery( "#sap" ).text(), expected, "Check for prepending of array of elements" ); +} ); QUnit.test( "prepend(Function) with incoming value -- jQuery", function( assert ) { @@ -749,15 +751,15 @@ QUnit.test( "prepend(Function) with incoming value -- jQuery", function( assert var old, expected; expected = "YahooTry them out:This link has class=\"blog\": Simon Willison's Weblog"; - old = jQuery("#sap").html(); + old = jQuery( "#sap" ).html(); - jQuery("#sap").prepend(function( i, val ) { + jQuery( "#sap" ).prepend( function( i, val ) { assert.equal( val, old, "Make sure the incoming value is correct." ); - return jQuery("#yahoo, #first"); - }); + return jQuery( "#yahoo, #first" ); + } ); - assert.equal( jQuery("#sap").text(), expected, "Check for prepending of jQuery object" ); -}); + assert.equal( jQuery( "#sap" ).text(), expected, "Check for prepending of jQuery object" ); +} ); QUnit.test( "prependTo(String)", function( assert ) { @@ -766,11 +768,11 @@ QUnit.test( "prependTo(String)", function( assert ) { var defaultText; defaultText = "Try them out:"; - jQuery("<b>buga</b>").prependTo("#first"); - assert.equal( jQuery("#first").text(), "buga" + defaultText, "Check if text prepending works" ); - assert.equal( jQuery("<option value='prependTest'>Prepend Test</option>").prependTo("#select3").parent().find("option:first-child").attr("value"), "prependTest", "Prepending html options to select element" ); + jQuery( "<b>buga</b>" ).prependTo( "#first" ); + assert.equal( jQuery( "#first" ).text(), "buga" + defaultText, "Check if text prepending works" ); + assert.equal( jQuery( "<option value='prependTest'>Prepend Test</option>" ).prependTo( "#select3" ).parent().find( "option:first-child" ).attr( "value" ), "prependTest", "Prepending html options to select element" ); -}); +} ); QUnit.test( "prependTo(Element)", function( assert ) { @@ -779,9 +781,9 @@ QUnit.test( "prependTo(Element)", function( assert ) { var expected; expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog"; - jQuery( document.getElementById("first") ).prependTo("#sap"); - assert.equal( jQuery("#sap").text(), expected, "Check for prepending of element" ); -}); + jQuery( document.getElementById( "first" ) ).prependTo( "#sap" ); + assert.equal( jQuery( "#sap" ).text(), expected, "Check for prepending of element" ); +} ); QUnit.test( "prependTo(Array<Element>)", function( assert ) { @@ -790,9 +792,9 @@ QUnit.test( "prependTo(Array<Element>)", function( assert ) { var expected; expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog"; - jQuery( [ document.getElementById("first"), document.getElementById("yahoo") ] ).prependTo("#sap"); - assert.equal( jQuery("#sap").text(), expected, "Check for prepending of array of elements" ); -}); + jQuery( [ document.getElementById( "first" ), document.getElementById( "yahoo" ) ] ).prependTo( "#sap" ); + assert.equal( jQuery( "#sap" ).text(), expected, "Check for prepending of array of elements" ); +} ); QUnit.test( "prependTo(jQuery)", function( assert ) { @@ -801,19 +803,19 @@ QUnit.test( "prependTo(jQuery)", function( assert ) { var expected; expected = "YahooTry them out:This link has class=\"blog\": Simon Willison's Weblog"; - jQuery("#yahoo, #first").prependTo("#sap"); - assert.equal( jQuery("#sap").text(), expected, "Check for prepending of jQuery object" ); -}); + jQuery( "#yahoo, #first" ).prependTo( "#sap" ); + assert.equal( jQuery( "#sap" ).text(), expected, "Check for prepending of jQuery object" ); +} ); QUnit.test( "prependTo(Array<jQuery>)", function( assert ) { assert.expect( 1 ); - jQuery("<select id='prependSelect1'></select>").prependTo("#form"); - jQuery("<select id='prependSelect2'><option>Test</option></select>").prependTo("#form"); + jQuery( "<select id='prependSelect1'></select>" ).prependTo( "#form" ); + jQuery( "<select id='prependSelect2'><option>Test</option></select>" ).prependTo( "#form" ); t( "Prepend Select", "#prependSelect2, #prependSelect1", [ "prependSelect2", "prependSelect1" ] ); -}); +} ); QUnit.test( "before(String)", function( assert ) { @@ -822,9 +824,9 @@ QUnit.test( "before(String)", function( assert ) { var expected; expected = "This is a normal link: bugaYahoo"; - jQuery("#yahoo").before( manipulationBareObj("<b>buga</b>") ); - assert.equal( jQuery("#en").text(), expected, "Insert String before" ); -}); + jQuery( "#yahoo" ).before( manipulationBareObj( "<b>buga</b>" ) ); + assert.equal( jQuery( "#en" ).text(), expected, "Insert String before" ); +} ); QUnit.test( "before(Element)", function( assert ) { @@ -833,9 +835,9 @@ QUnit.test( "before(Element)", function( assert ) { var expected; expected = "This is a normal link: Try them out:Yahoo"; - jQuery("#yahoo").before( manipulationBareObj(document.getElementById("first")) ); - assert.equal( jQuery("#en").text(), expected, "Insert element before" ); -}); + jQuery( "#yahoo" ).before( manipulationBareObj( document.getElementById( "first" ) ) ); + assert.equal( jQuery( "#en" ).text(), expected, "Insert element before" ); +} ); QUnit.test( "before(Array<Element>)", function( assert ) { @@ -843,9 +845,9 @@ QUnit.test( "before(Array<Element>)", function( assert ) { var expected; expected = "This is a normal link: Try them out:diveintomarkYahoo"; - jQuery("#yahoo").before( manipulationBareObj([ document.getElementById("first"), document.getElementById("mark") ]) ); - assert.equal( jQuery("#en").text(), expected, "Insert array of elements before" ); -}); + jQuery( "#yahoo" ).before( manipulationBareObj( [ document.getElementById( "first" ), document.getElementById( "mark" ) ] ) ); + assert.equal( jQuery( "#en" ).text(), expected, "Insert array of elements before" ); +} ); QUnit.test( "before(jQuery)", function( assert ) { @@ -853,9 +855,9 @@ QUnit.test( "before(jQuery)", function( assert ) { var expected; expected = "This is a normal link: diveintomarkTry them out:Yahoo"; - jQuery("#yahoo").before( manipulationBareObj(jQuery("#mark, #first")) ); - assert.equal( jQuery("#en").text(), expected, "Insert jQuery before" ); -}); + jQuery( "#yahoo" ).before( manipulationBareObj( jQuery( "#mark, #first" ) ) ); + assert.equal( jQuery( "#en" ).text(), expected, "Insert jQuery before" ); +} ); QUnit.test( "before(Array<jQuery>)", function( assert ) { @@ -863,9 +865,9 @@ QUnit.test( "before(Array<jQuery>)", function( assert ) { var expected; expected = "This is a normal link: Try them out:GooglediveintomarkYahoo"; - jQuery("#yahoo").before( manipulationBareObj([ jQuery("#first"), jQuery("#mark, #google") ]) ); - assert.equal( jQuery("#en").text(), expected, "Insert array of jQuery objects before" ); -}); + jQuery( "#yahoo" ).before( manipulationBareObj( [ jQuery( "#first" ), jQuery( "#mark, #google" ) ] ) ); + assert.equal( jQuery( "#en" ).text(), expected, "Insert array of jQuery objects before" ); +} ); QUnit.test( "before(Function) -- Returns String", function( assert ) { @@ -874,9 +876,9 @@ QUnit.test( "before(Function) -- Returns String", function( assert ) { var expected; expected = "This is a normal link: bugaYahoo"; - jQuery("#yahoo").before( manipulationFunctionReturningObj("<b>buga</b>") ); - assert.equal( jQuery("#en").text(), expected, "Insert String before" ); -}); + jQuery( "#yahoo" ).before( manipulationFunctionReturningObj( "<b>buga</b>" ) ); + assert.equal( jQuery( "#en" ).text(), expected, "Insert String before" ); +} ); QUnit.test( "before(Function) -- Returns Element", function( assert ) { @@ -885,9 +887,9 @@ QUnit.test( "before(Function) -- Returns Element", function( assert ) { var expected; expected = "This is a normal link: Try them out:Yahoo"; - jQuery("#yahoo").before( manipulationFunctionReturningObj(document.getElementById("first")) ); - assert.equal( jQuery("#en").text(), expected, "Insert element before" ); -}); + jQuery( "#yahoo" ).before( manipulationFunctionReturningObj( document.getElementById( "first" ) ) ); + assert.equal( jQuery( "#en" ).text(), expected, "Insert element before" ); +} ); QUnit.test( "before(Function) -- Returns Array<Element>", function( assert ) { @@ -895,9 +897,9 @@ QUnit.test( "before(Function) -- Returns Array<Element>", function( assert ) { var expected; expected = "This is a normal link: Try them out:diveintomarkYahoo"; - jQuery("#yahoo").before( manipulationFunctionReturningObj([ document.getElementById("first"), document.getElementById("mark") ]) ); - assert.equal( jQuery("#en").text(), expected, "Insert array of elements before" ); -}); + jQuery( "#yahoo" ).before( manipulationFunctionReturningObj( [ document.getElementById( "first" ), document.getElementById( "mark" ) ] ) ); + assert.equal( jQuery( "#en" ).text(), expected, "Insert array of elements before" ); +} ); QUnit.test( "before(Function) -- Returns jQuery", function( assert ) { @@ -905,9 +907,9 @@ QUnit.test( "before(Function) -- Returns jQuery", function( assert ) { var expected; expected = "This is a normal link: diveintomarkTry them out:Yahoo"; - jQuery("#yahoo").before( manipulationFunctionReturningObj(jQuery("#mark, #first")) ); - assert.equal( jQuery("#en").text(), expected, "Insert jQuery before" ); -}); + jQuery( "#yahoo" ).before( manipulationFunctionReturningObj( jQuery( "#mark, #first" ) ) ); + assert.equal( jQuery( "#en" ).text(), expected, "Insert jQuery before" ); +} ); QUnit.test( "before(Function) -- Returns Array<jQuery>", function( assert ) { @@ -915,19 +917,19 @@ QUnit.test( "before(Function) -- Returns Array<jQuery>", function( assert ) { var expected; expected = "This is a normal link: Try them out:GooglediveintomarkYahoo"; - jQuery("#yahoo").before( manipulationFunctionReturningObj([ jQuery("#first"), jQuery("#mark, #google") ]) ); - assert.equal( jQuery("#en").text(), expected, "Insert array of jQuery objects before" ); -}); + jQuery( "#yahoo" ).before( manipulationFunctionReturningObj( [ jQuery( "#first" ), jQuery( "#mark, #google" ) ] ) ); + assert.equal( jQuery( "#en" ).text(), expected, "Insert array of jQuery objects before" ); +} ); QUnit.test( "before(no-op)", function( assert ) { assert.expect( 2 ); var set; - set = jQuery("<div/>").before("<span>test</span>"); + set = jQuery( "<div/>" ).before( "<span>test</span>" ); assert.equal( set[ 0 ].nodeName.toLowerCase(), "div", "Insert before a disconnected node should be a no-op" ); assert.equal( set.length, 1, "Insert the element before the disconnected node. should be a no-op" ); -}); +} ); QUnit.test( "before and after w/ empty object (#10812)", function( assert ) { @@ -937,127 +939,127 @@ QUnit.test( "before and after w/ empty object (#10812)", function( assert ) { res = jQuery( "#notInTheDocument" ).before( "(" ).after( ")" ); assert.equal( res.length, 0, "didn't choke on empty object" ); -}); +} ); QUnit.test( ".before() and .after() disconnected node", function( assert ) { - assert.expect(2); + assert.expect( 2 ); - assert.equal( jQuery("<input type='checkbox'/>").before("<div/>").length, 1, "before() on disconnected node is no-op" ); - assert.equal( jQuery("<input type='checkbox'/>").after("<div/>").length, 1, "after() on disconnected node is no-op" ); -}); + assert.equal( jQuery( "<input type='checkbox'/>" ).before( "<div/>" ).length, 1, "before() on disconnected node is no-op" ); + assert.equal( jQuery( "<input type='checkbox'/>" ).after( "<div/>" ).length, 1, "after() on disconnected node is no-op" ); +} ); QUnit.test( "insert with .before() on disconnected node last", function( assert ) { - assert.expect(1); + assert.expect( 1 ); var expectedBefore = "This is a normal link: bugaYahoo"; - jQuery("#yahoo").add("<span/>").before("<b>buga</b>"); - assert.equal( jQuery("#en").text(), expectedBefore, "Insert String before with disconnected node last" ); -}); + jQuery( "#yahoo" ).add( "<span/>" ).before( "<b>buga</b>" ); + assert.equal( jQuery( "#en" ).text(), expectedBefore, "Insert String before with disconnected node last" ); +} ); QUnit.test( "insert with .before() on disconnected node first", function( assert ) { - assert.expect(1); + assert.expect( 1 ); var expectedBefore = "This is a normal link: bugaYahoo"; - jQuery("<span/>").add("#yahoo").before("<b>buga</b>"); - assert.equal( jQuery("#en").text(), expectedBefore, "Insert String before with disconnected node first" ); -}); + jQuery( "<span/>" ).add( "#yahoo" ).before( "<b>buga</b>" ); + assert.equal( jQuery( "#en" ).text(), expectedBefore, "Insert String before with disconnected node first" ); +} ); QUnit.test( "insert with .before() on disconnected node last", function( assert ) { - assert.expect(1); + assert.expect( 1 ); var expectedAfter = "This is a normal link: Yahoobuga"; - jQuery("#yahoo").add("<span/>").after("<b>buga</b>"); - assert.equal( jQuery("#en").text(), expectedAfter, "Insert String after with disconnected node last" ); -}); + jQuery( "#yahoo" ).add( "<span/>" ).after( "<b>buga</b>" ); + assert.equal( jQuery( "#en" ).text(), expectedAfter, "Insert String after with disconnected node last" ); +} ); QUnit.test( "insert with .before() on disconnected node last", function( assert ) { - assert.expect(1); + assert.expect( 1 ); var expectedAfter = "This is a normal link: Yahoobuga"; - jQuery("<span/>").add("#yahoo").after("<b>buga</b>"); - assert.equal( jQuery("#en").text(), expectedAfter, "Insert String after with disconnected node first" ); -}); + jQuery( "<span/>" ).add( "#yahoo" ).after( "<b>buga</b>" ); + assert.equal( jQuery( "#en" ).text(), expectedAfter, "Insert String after with disconnected node first" ); +} ); QUnit.test( "insertBefore(String)", function( assert ) { assert.expect( 1 ); var expected = "This is a normal link: bugaYahoo"; - jQuery("<b>buga</b>").insertBefore("#yahoo"); - assert.equal( jQuery("#en").text(), expected, "Insert String before" ); -}); + jQuery( "<b>buga</b>" ).insertBefore( "#yahoo" ); + assert.equal( jQuery( "#en" ).text(), expected, "Insert String before" ); +} ); QUnit.test( "insertBefore(Element)", function( assert ) { assert.expect( 1 ); var expected = "This is a normal link: Try them out:Yahoo"; - jQuery( document.getElementById("first") ).insertBefore("#yahoo"); - assert.equal( jQuery("#en").text(), expected, "Insert element before" ); -}); + jQuery( document.getElementById( "first" ) ).insertBefore( "#yahoo" ); + assert.equal( jQuery( "#en" ).text(), expected, "Insert element before" ); +} ); QUnit.test( "insertBefore(Array<Element>)", function( assert ) { assert.expect( 1 ); var expected = "This is a normal link: Try them out:diveintomarkYahoo"; - jQuery( [ document.getElementById("first"), document.getElementById("mark") ] ).insertBefore("#yahoo"); - assert.equal( jQuery("#en").text(), expected, "Insert array of elements before" ); -}); + jQuery( [ document.getElementById( "first" ), document.getElementById( "mark" ) ] ).insertBefore( "#yahoo" ); + assert.equal( jQuery( "#en" ).text(), expected, "Insert array of elements before" ); +} ); QUnit.test( "insertBefore(jQuery)", function( assert ) { assert.expect( 1 ); var expected = "This is a normal link: diveintomarkTry them out:Yahoo"; - jQuery("#mark, #first").insertBefore("#yahoo"); - assert.equal( jQuery("#en").text(), expected, "Insert jQuery before" ); -}); + jQuery( "#mark, #first" ).insertBefore( "#yahoo" ); + assert.equal( jQuery( "#en" ).text(), expected, "Insert jQuery before" ); +} ); QUnit.test( ".after(String)", function( assert ) { assert.expect( 1 ); var expected = "This is a normal link: Yahoobuga"; - jQuery("#yahoo").after( "<b>buga</b>" ); - assert.equal( jQuery("#en").text(), expected, "Insert String after" ); -}); + jQuery( "#yahoo" ).after( "<b>buga</b>" ); + assert.equal( jQuery( "#en" ).text(), expected, "Insert String after" ); +} ); QUnit.test( ".after(Element)", function( assert ) { assert.expect( 1 ); var expected = "This is a normal link: YahooTry them out:"; - jQuery("#yahoo").after( document.getElementById("first") ); - assert.equal( jQuery("#en").text(), expected, "Insert element after" ); -}); + jQuery( "#yahoo" ).after( document.getElementById( "first" ) ); + assert.equal( jQuery( "#en" ).text(), expected, "Insert element after" ); +} ); QUnit.test( ".after(Array<Element>)", function( assert ) { assert.expect( 1 ); var expected = "This is a normal link: YahooTry them out:diveintomark"; - jQuery("#yahoo").after( [ document.getElementById("first"), document.getElementById("mark") ] ); - assert.equal( jQuery("#en").text(), expected, "Insert array of elements after" ); -}); + jQuery( "#yahoo" ).after( [ document.getElementById( "first" ), document.getElementById( "mark" ) ] ); + assert.equal( jQuery( "#en" ).text(), expected, "Insert array of elements after" ); +} ); QUnit.test( ".after(jQuery)", function( assert ) { assert.expect( 1 ); var expected = "This is a normal link: YahooTry them out:Googlediveintomark"; - jQuery("#yahoo").after( [ jQuery("#first"), jQuery("#mark, #google") ] ); - assert.equal( jQuery("#en").text(), expected, "Insert array of jQuery objects after" ); -}); + jQuery( "#yahoo" ).after( [ jQuery( "#first" ), jQuery( "#mark, #google" ) ] ); + assert.equal( jQuery( "#en" ).text(), expected, "Insert array of jQuery objects after" ); +} ); QUnit.test( ".after(Function) returns String", function( assert ) { @@ -1065,9 +1067,9 @@ QUnit.test( ".after(Function) returns String", function( assert ) { var expected = "This is a normal link: Yahoobuga", val = manipulationFunctionReturningObj; - jQuery("#yahoo").after( val("<b>buga</b>") ); - assert.equal( jQuery("#en").text(), expected, "Insert String after" ); -}); + jQuery( "#yahoo" ).after( val( "<b>buga</b>" ) ); + assert.equal( jQuery( "#en" ).text(), expected, "Insert String after" ); +} ); QUnit.test( ".after(Function) returns Element", function( assert ) { @@ -1075,9 +1077,9 @@ QUnit.test( ".after(Function) returns Element", function( assert ) { var expected = "This is a normal link: YahooTry them out:", val = manipulationFunctionReturningObj; - jQuery("#yahoo").after( val(document.getElementById("first")) ); - assert.equal( jQuery("#en").text(), expected, "Insert element after" ); -}); + jQuery( "#yahoo" ).after( val( document.getElementById( "first" ) ) ); + assert.equal( jQuery( "#en" ).text(), expected, "Insert element after" ); +} ); QUnit.test( ".after(Function) returns Array<Element>", function( assert ) { @@ -1085,9 +1087,9 @@ QUnit.test( ".after(Function) returns Array<Element>", function( assert ) { var expected = "This is a normal link: YahooTry them out:diveintomark", val = manipulationFunctionReturningObj; - jQuery("#yahoo").after( val([ document.getElementById("first"), document.getElementById("mark") ]) ); - assert.equal( jQuery("#en").text(), expected, "Insert array of elements after" ); -}); + jQuery( "#yahoo" ).after( val( [ document.getElementById( "first" ), document.getElementById( "mark" ) ] ) ); + assert.equal( jQuery( "#en" ).text(), expected, "Insert array of elements after" ); +} ); QUnit.test( ".after(Function) returns jQuery", function( assert ) { @@ -1095,54 +1097,54 @@ QUnit.test( ".after(Function) returns jQuery", function( assert ) { var expected = "This is a normal link: YahooTry them out:Googlediveintomark", val = manipulationFunctionReturningObj; - jQuery("#yahoo").after( val([ jQuery("#first"), jQuery("#mark, #google") ]) ); - assert.equal( jQuery("#en").text(), expected, "Insert array of jQuery objects after" ); -}); + jQuery( "#yahoo" ).after( val( [ jQuery( "#first" ), jQuery( "#mark, #google" ) ] ) ); + assert.equal( jQuery( "#en" ).text(), expected, "Insert array of jQuery objects after" ); +} ); QUnit.test( ".after(disconnected node)", function( assert ) { assert.expect( 2 ); - var set = jQuery("<div/>").before("<span>test</span>"); + var set = jQuery( "<div/>" ).before( "<span>test</span>" ); assert.equal( set[ 0 ].nodeName.toLowerCase(), "div", "Insert after a disconnected node should be a no-op" ); assert.equal( set.length, 1, "Insert the element after the disconnected node should be a no-op" ); -}); +} ); QUnit.test( "insertAfter(String)", function( assert ) { assert.expect( 1 ) ; var expected = "This is a normal link: Yahoobuga"; - jQuery("<b>buga</b>").insertAfter("#yahoo"); - assert.equal( jQuery("#en").text(), expected, "Insert String after" ); -}); + jQuery( "<b>buga</b>" ).insertAfter( "#yahoo" ); + assert.equal( jQuery( "#en" ).text(), expected, "Insert String after" ); +} ); QUnit.test( "insertAfter(Element)", function( assert ) { - assert.expect(1); + assert.expect( 1 ); var expected = "This is a normal link: YahooTry them out:"; - jQuery( document.getElementById("first") ).insertAfter("#yahoo"); - assert.equal( jQuery("#en").text(), expected, "Insert element after" ); -}); + jQuery( document.getElementById( "first" ) ).insertAfter( "#yahoo" ); + assert.equal( jQuery( "#en" ).text(), expected, "Insert element after" ); +} ); QUnit.test( "insertAfter(Array<Element>)", function( assert ) { - assert.expect(1); + assert.expect( 1 ); var expected = "This is a normal link: YahooTry them out:diveintomark"; - jQuery( [ document.getElementById("first"), document.getElementById("mark") ] ).insertAfter("#yahoo"); - assert.equal( jQuery("#en").text(), expected, "Insert array of elements after" ); -}); + jQuery( [ document.getElementById( "first" ), document.getElementById( "mark" ) ] ).insertAfter( "#yahoo" ); + assert.equal( jQuery( "#en" ).text(), expected, "Insert array of elements after" ); +} ); QUnit.test( "insertAfter(jQuery)", function( assert ) { - assert.expect(1); + assert.expect( 1 ); var expected = "This is a normal link: YahoodiveintomarkTry them out:"; - jQuery("#mark, #first").insertAfter("#yahoo"); - assert.equal( jQuery("#en").text(), expected, "Insert jQuery after" ); -}); + jQuery( "#mark, #first" ).insertAfter( "#yahoo" ); + assert.equal( jQuery( "#en" ).text(), expected, "Insert jQuery after" ); +} ); function testReplaceWith( val, assert ) { @@ -1151,132 +1153,127 @@ function testReplaceWith( val, assert ) { assert.expect( expected ); - jQuery("#yahoo").replaceWith( val("<b id='replace'>buga</b>") ); - assert.ok( jQuery("#replace")[ 0 ], "Replace element with element from string" ); - assert.ok( !jQuery("#yahoo")[ 0 ], "Verify that original element is gone, after string" ); + jQuery( "#yahoo" ).replaceWith( val( "<b id='replace'>buga</b>" ) ); + assert.ok( jQuery( "#replace" )[ 0 ], "Replace element with element from string" ); + assert.ok( !jQuery( "#yahoo" )[ 0 ], "Verify that original element is gone, after string" ); - jQuery("#anchor2").replaceWith( val(document.getElementById("first")) ); - assert.ok( jQuery("#first")[ 0 ], "Replace element with element" ); - assert.ok( !jQuery("#anchor2")[ 0 ], "Verify that original element is gone, after element" ); + jQuery( "#anchor2" ).replaceWith( val( document.getElementById( "first" ) ) ); + assert.ok( jQuery( "#first" )[ 0 ], "Replace element with element" ); + assert.ok( !jQuery( "#anchor2" )[ 0 ], "Verify that original element is gone, after element" ); - jQuery("#qunit-fixture").append("<div id='bar'><div id='baz'></div></div>"); - jQuery("#baz").replaceWith( val("Baz") ); - assert.equal( jQuery("#bar").text(),"Baz", "Replace element with text" ); - assert.ok( !jQuery("#baz")[ 0 ], "Verify that original element is gone, after element" ); + jQuery( "#qunit-fixture" ).append( "<div id='bar'><div id='baz'></div></div>" ); + jQuery( "#baz" ).replaceWith( val( "Baz" ) ); + assert.equal( jQuery( "#bar" ).text(), "Baz", "Replace element with text" ); + assert.ok( !jQuery( "#baz" )[ 0 ], "Verify that original element is gone, after element" ); - jQuery("#bar").replaceWith( "<div id='yahoo'></div>", "...", "<div id='baz'></div>" ); - assert.deepEqual( jQuery("#yahoo, #baz").get(), q( "yahoo", "baz" ), "Replace element with multiple arguments (#13722)" ); - assert.strictEqual( jQuery("#yahoo")[0].nextSibling, jQuery("#baz")[0].previousSibling, "Argument order preserved" ); - assert.deepEqual( jQuery("#bar").get(), [], "Verify that original element is gone, after multiple arguments" ); + jQuery( "#bar" ).replaceWith( "<div id='yahoo'></div>", "...", "<div id='baz'></div>" ); + assert.deepEqual( jQuery( "#yahoo, #baz" ).get(), q( "yahoo", "baz" ), "Replace element with multiple arguments (#13722)" ); + assert.strictEqual( jQuery( "#yahoo" )[ 0 ].nextSibling, jQuery( "#baz" )[ 0 ].previousSibling, "Argument order preserved" ); + assert.deepEqual( jQuery( "#bar" ).get(), [], "Verify that original element is gone, after multiple arguments" ); - jQuery("#google").replaceWith( val([ document.getElementById("first"), document.getElementById("mark") ]) ); - assert.deepEqual( jQuery("#mark, #first").get(), q( "first", "mark" ), "Replace element with array of elements" ); - assert.ok( !jQuery("#google")[ 0 ], "Verify that original element is gone, after array of elements" ); + jQuery( "#google" ).replaceWith( val( [ document.getElementById( "first" ), document.getElementById( "mark" ) ] ) ); + assert.deepEqual( jQuery( "#mark, #first" ).get(), q( "first", "mark" ), "Replace element with array of elements" ); + assert.ok( !jQuery( "#google" )[ 0 ], "Verify that original element is gone, after array of elements" ); - jQuery("#groups").replaceWith( val(jQuery("#mark, #first")) ); - assert.deepEqual( jQuery("#mark, #first").get(), q( "first", "mark" ), "Replace element with jQuery collection" ); - assert.ok( !jQuery("#groups")[ 0 ], "Verify that original element is gone, after jQuery collection" ); + jQuery( "#groups" ).replaceWith( val( jQuery( "#mark, #first" ) ) ); + assert.deepEqual( jQuery( "#mark, #first" ).get(), q( "first", "mark" ), "Replace element with jQuery collection" ); + assert.ok( !jQuery( "#groups" )[ 0 ], "Verify that original element is gone, after jQuery collection" ); - jQuery("#mark, #first").replaceWith( val("<span class='replacement'></span><span class='replacement'></span>") ); - assert.equal( jQuery("#qunit-fixture .replacement").length, 4, "Replace multiple elements (#12449)" ); - assert.deepEqual( jQuery("#mark, #first").get(), [], "Verify that original elements are gone, after replace multiple" ); + jQuery( "#mark, #first" ).replaceWith( val( "<span class='replacement'></span><span class='replacement'></span>" ) ); + assert.equal( jQuery( "#qunit-fixture .replacement" ).length, 4, "Replace multiple elements (#12449)" ); + assert.deepEqual( jQuery( "#mark, #first" ).get(), [], "Verify that original elements are gone, after replace multiple" ); - tmp = jQuery("<b>content</b>")[0]; - jQuery("#anchor1").contents().replaceWith( val(tmp) ); - assert.deepEqual( jQuery("#anchor1").contents().get(), [ tmp ], "Replace text node with element" ); + tmp = jQuery( "<b>content</b>" )[ 0 ]; + 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() { + tmp = jQuery( "<div/>" ).appendTo( "#qunit-fixture" ).on( "click", function() { assert.ok( true, "Newly bound click run." ); - }); - y = jQuery("<div/>").appendTo("#qunit-fixture").on( "click", function() { + } ); + y = jQuery( "<div/>" ).appendTo( "#qunit-fixture" ).on( "click", function() { assert.ok( false, "Previously bound click run." ); - }); - child = y.append("<b>test</b>").find("b").on( "click", function() { + } ); + child = y.append( "<b>test</b>" ).find( "b" ).on( "click", function() { assert.ok( true, "Child bound click run." ); return false; - }); - - y.replaceWith( val(tmp) ); + } ); - tmp.trigger("click"); - y.trigger("click"); // Shouldn't be run - child.trigger("click"); // Shouldn't be run + y.replaceWith( val( tmp ) ); + tmp.trigger( "click" ); + y.trigger( "click" ); // Shouldn't be run + child.trigger( "click" ); // Shouldn't be run - y = jQuery("<div/>").appendTo("#qunit-fixture").on( "click", function() { + y = jQuery( "<div/>" ).appendTo( "#qunit-fixture" ).on( "click", function() { assert.ok( false, "Previously bound click run." ); - }); - child2 = y.append("<u>test</u>").find("u").on( "click", function() { + } ); + child2 = y.append( "<u>test</u>" ).find( "u" ).on( "click", function() { assert.ok( true, "Child 2 bound click run." ); return false; - }); - - y.replaceWith( val(child2) ); + } ); - child2.trigger("click"); + y.replaceWith( val( child2 ) ); + child2.trigger( "click" ); - set = jQuery("<div/>").replaceWith( val("<span>test</span>") ); - assert.equal( set[0].nodeName.toLowerCase(), "div", "No effect on a disconnected node." ); + 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." ); - + 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 ); + child = jQuery( "#qunit-fixture" ).children().first(); + $div = jQuery( "<div class='pathological'/>" ).insertBefore( child ); $div.replaceWith( $div ); assert.deepEqual( jQuery( ".pathological", "#qunit-fixture" ).get(), $div.get(), "Self-replacement" ); $div.replaceWith( child ); - assert.deepEqual( jQuery("#qunit-fixture").children().first().get(), child.get(), + assert.deepEqual( jQuery( "#qunit-fixture" ).children().first().get(), child.get(), "Replacement with following sibling (#13810)" ); 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>") ); + 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." ); - $div = jQuery("<div class='replacewith'></div>").appendTo("#qunit-fixture"); - $div.replaceWith( val("<div class='replacewith'></div><script>" + + $div = jQuery( "<div class='replacewith'></div>" ).appendTo( "#qunit-fixture" ); + $div.replaceWith( val( "<div class='replacewith'></div><script>" + "equal( jQuery('.replacewith').length, 1, 'Check number of elements in page.' );" + - "</script>") ); + "</script>" ) ); - jQuery("#qunit-fixture").append("<div id='replaceWith'></div>"); - assert.equal( jQuery("#qunit-fixture").find("div[id=replaceWith]").length, 1, "Make sure only one div exists." ); - jQuery("#replaceWith").replaceWith( val("<div id='replaceWith'></div>") ); - assert.equal( jQuery("#qunit-fixture").find("div[id=replaceWith]").length, 1, "Make sure only one div exists after replacement." ); - jQuery("#replaceWith").replaceWith( val("<div id='replaceWith'></div>") ); - assert.equal( jQuery("#qunit-fixture").find("div[id=replaceWith]").length, 1, "Make sure only one div exists after subsequent replacement." ); + jQuery( "#qunit-fixture" ).append( "<div id='replaceWith'></div>" ); + assert.equal( jQuery( "#qunit-fixture" ).find( "div[id=replaceWith]" ).length, 1, "Make sure only one div exists." ); + jQuery( "#replaceWith" ).replaceWith( val( "<div id='replaceWith'></div>" ) ); + assert.equal( jQuery( "#qunit-fixture" ).find( "div[id=replaceWith]" ).length, 1, "Make sure only one div exists after replacement." ); + jQuery( "#replaceWith" ).replaceWith( val( "<div id='replaceWith'></div>" ) ); + assert.equal( jQuery( "#qunit-fixture" ).find( "div[id=replaceWith]" ).length, 1, "Make sure only one div exists after subsequent replacement." ); return expected; } QUnit.test( "replaceWith(String|Element|Array<Element>|jQuery)", function( assert ) { testReplaceWith( manipulationBareObj, assert ); -}); +} ); QUnit.test( "replaceWith(Function)", function( assert ) { - assert.expect( testReplaceWith(manipulationFunctionReturningObj, assert ) + 1 ); + assert.expect( testReplaceWith( manipulationFunctionReturningObj, assert ) + 1 ); - var y = jQuery("#foo")[ 0 ]; + var y = jQuery( "#foo" )[ 0 ]; - jQuery( y ).replaceWith(function() { + jQuery( y ).replaceWith( function() { assert.equal( this, y, "Make sure the context is coming in correctly." ); - }); -}); + } ); +} ); QUnit.test( "replaceWith(string) for more than one element", function( assert ) { assert.expect( 3 ); - assert.equal( jQuery("#foo p").length, 3, "ensuring that test data has not changed" ); + assert.equal( jQuery( "#foo p" ).length, 3, "ensuring that test data has not changed" ); - jQuery("#foo p").replaceWith("<span>bar</span>"); - assert.equal(jQuery("#foo span").length, 3, "verify that all the three original element have been replaced"); - assert.equal(jQuery("#foo p").length, 0, "verify that all the three original element have been replaced"); -}); + jQuery( "#foo p" ).replaceWith( "<span>bar</span>" ); + assert.equal( jQuery( "#foo span" ).length, 3, "verify that all the three original element have been replaced" ); + assert.equal( jQuery( "#foo p" ).length, 0, "verify that all the three original element have been replaced" ); +} ); QUnit.test( "Empty replaceWith (trac-13401; trac-13596; gh-2204)", function( assert ) { @@ -1297,97 +1294,97 @@ QUnit.test( "Empty replaceWith (trac-13401; trac-13596; gh-2204)", function( ass jQuery.each( tests, function( label, input ) { $el.html( "<a/>" ).children().replaceWith( input ); assert.strictEqual( $el.html(), "", "replaceWith(" + label + ")" ); - $el.html( "<b/>" ).children().replaceWith(function() { return input; }); + $el.html( "<b/>" ).children().replaceWith( function() { return input; } ); assert.strictEqual( $el.html(), "", "replaceWith(function returning " + label + ")" ); - $el.html( "<i/>" ).children().replaceWith(function( i ) { i; return input; }); + $el.html( "<i/>" ).children().replaceWith( function( i ) { i; return input; } ); assert.strictEqual( $el.html(), "", "replaceWith(other function returning " + label + ")" ); - $el.html( "<p/>" ).children().replaceWith(function( i ) { + $el.html( "<p/>" ).children().replaceWith( function( i ) { return i ? input : jQuery( this ).html( i + "" ); - }); + } ); assert.strictEqual( $el.eq( 0 ).html(), expectedHTML, "replaceWith(function conditionally returning context)" ); assert.strictEqual( $el.eq( 1 ).html(), "", "replaceWith(function conditionally returning " + label + ")" ); - }); -}); + } ); +} ); QUnit.test( "replaceAll(String)", function( assert ) { assert.expect( 2 ); - jQuery("<b id='replace'>buga</b>").replaceAll("#yahoo"); - assert.ok( jQuery("#replace")[ 0 ], "Replace element with string" ); - assert.ok( !jQuery("#yahoo")[ 0 ], "Verify that original element is gone, after string" ); -}); + jQuery( "<b id='replace'>buga</b>" ).replaceAll( "#yahoo" ); + assert.ok( jQuery( "#replace" )[ 0 ], "Replace element with string" ); + assert.ok( !jQuery( "#yahoo" )[ 0 ], "Verify that original element is gone, after string" ); +} ); QUnit.test( "replaceAll(Element)", function( assert ) { assert.expect( 2 ); - jQuery( document.getElementById("first") ).replaceAll("#yahoo"); - assert.ok( jQuery("#first")[ 0 ], "Replace element with element" ); - assert.ok( !jQuery("#yahoo")[ 0 ], "Verify that original element is gone, after element" ); -}); + jQuery( document.getElementById( "first" ) ).replaceAll( "#yahoo" ); + assert.ok( jQuery( "#first" )[ 0 ], "Replace element with element" ); + assert.ok( !jQuery( "#yahoo" )[ 0 ], "Verify that original element is gone, after element" ); +} ); QUnit.test( "replaceAll(Array<Element>)", function( assert ) { assert.expect( 3 ); - jQuery( [ document.getElementById("first"), document.getElementById("mark") ] ).replaceAll("#yahoo"); - assert.ok( jQuery("#first")[ 0 ], "Replace element with array of elements" ); - assert.ok( jQuery("#mark")[ 0 ], "Replace element with array of elements" ); - assert.ok( !jQuery("#yahoo")[ 0 ], "Verify that original element is gone, after array of elements" ); -}); + jQuery( [ document.getElementById( "first" ), document.getElementById( "mark" ) ] ).replaceAll( "#yahoo" ); + assert.ok( jQuery( "#first" )[ 0 ], "Replace element with array of elements" ); + assert.ok( jQuery( "#mark" )[ 0 ], "Replace element with array of elements" ); + assert.ok( !jQuery( "#yahoo" )[ 0 ], "Verify that original element is gone, after array of elements" ); +} ); QUnit.test( "replaceAll(jQuery)", function( assert ) { assert.expect( 3 ); - jQuery("#mark, #first").replaceAll("#yahoo"); - assert.ok( jQuery("#first")[ 0 ], "Replace element with set of elements" ); - assert.ok( jQuery("#mark")[ 0 ], "Replace element with set of elements" ); - assert.ok( !jQuery("#yahoo")[ 0 ], "Verify that original element is gone, after set of elements" ); -}); + jQuery( "#mark, #first" ).replaceAll( "#yahoo" ); + assert.ok( jQuery( "#first" )[ 0 ], "Replace element with set of elements" ); + assert.ok( jQuery( "#mark" )[ 0 ], "Replace element with set of elements" ); + assert.ok( !jQuery( "#yahoo" )[ 0 ], "Verify that original element is gone, after set of elements" ); +} ); QUnit.test( "jQuery.clone() (#8017)", function( assert ) { assert.expect( 2 ); - assert.ok( jQuery.clone && jQuery.isFunction( jQuery.clone ) , "jQuery.clone() utility exists and is a function."); + assert.ok( jQuery.clone && jQuery.isFunction( jQuery.clone ), "jQuery.clone() utility exists and is a function." ); - var main = jQuery("#qunit-fixture")[ 0 ], + var main = jQuery( "#qunit-fixture" )[ 0 ], clone = jQuery.clone( main ); assert.equal( main.childNodes.length, clone.childNodes.length, "Simple child length to ensure a large dom tree copies correctly" ); -}); +} ); QUnit.test( "append to multiple elements (#8070)", function( assert ) { assert.expect( 2 ); - var selects = jQuery("<select class='test8070'></select><select class='test8070'></select>").appendTo("#qunit-fixture"); - selects.append("<OPTION>1</OPTION><OPTION>2</OPTION>"); + var selects = jQuery( "<select class='test8070'></select><select class='test8070'></select>" ).appendTo( "#qunit-fixture" ); + selects.append( "<OPTION>1</OPTION><OPTION>2</OPTION>" ); assert.equal( selects[ 0 ].childNodes.length, 2, "First select got two nodes" ); assert.equal( selects[ 1 ].childNodes.length, 2, "Second select got two nodes" ); -}); +} ); QUnit.test( "table manipulation", function( assert ) { assert.expect( 2 ); - var table = jQuery("<table style='font-size:16px'></table>").appendTo("#qunit-fixture").empty(), - height = table[0].offsetHeight; + var table = jQuery( "<table style='font-size:16px'></table>" ).appendTo( "#qunit-fixture" ).empty(), + height = table[ 0 ].offsetHeight; - table.append("<tr><td>DATA</td></tr>"); - assert.ok( table[0].offsetHeight - height >= 15, "appended rows are visible" ); + table.append( "<tr><td>DATA</td></tr>" ); + assert.ok( table[ 0 ].offsetHeight - height >= 15, "appended rows are visible" ); table.empty(); - height = table[0].offsetHeight; - table.prepend("<tr><td>DATA</td></tr>"); - assert.ok( table[0].offsetHeight - height >= 15, "prepended rows are visible" ); -}); + height = table[ 0 ].offsetHeight; + table.prepend( "<tr><td>DATA</td></tr>" ); + assert.ok( table[ 0 ].offsetHeight - height >= 15, "prepended rows are visible" ); +} ); QUnit.test( "clone()", function( assert ) { @@ -1395,61 +1392,61 @@ QUnit.test( "clone()", function( assert ) { var div, clone, form, body; - assert.equal( jQuery("#en").text(), "This is a normal link: Yahoo", "Assert text for #en" ); - assert.equal( jQuery("#first").append( jQuery("#yahoo").clone() ).text(), "Try them out:Yahoo", "Check for clone" ); - assert.equal( jQuery("#en").text(), "This is a normal link: Yahoo", "Reassert text for #en" ); + assert.equal( jQuery( "#en" ).text(), "This is a normal link: Yahoo", "Assert text for #en" ); + assert.equal( jQuery( "#first" ).append( jQuery( "#yahoo" ).clone() ).text(), "Try them out:Yahoo", "Check for clone" ); + assert.equal( jQuery( "#en" ).text(), "This is a normal link: Yahoo", "Reassert text for #en" ); - jQuery.each( "table thead tbody tfoot tr td div button ul ol li select option textarea iframe".split(" "), function( i, nodeName ) { + jQuery.each( "table thead tbody tfoot tr td div button ul ol li select option textarea iframe".split( " " ), function( i, nodeName ) { assert.equal( jQuery( "<" + nodeName + "/>" ).clone()[ 0 ].nodeName.toLowerCase(), nodeName, "Clone a " + nodeName ); - }); - assert.equal( jQuery("<input type='checkbox' />").clone()[ 0 ].nodeName.toLowerCase(), "input", "Clone a <input type='checkbox' />" ); + } ); + assert.equal( jQuery( "<input type='checkbox' />" ).clone()[ 0 ].nodeName.toLowerCase(), "input", "Clone a <input type='checkbox' />" ); // Check cloning non-elements - assert.equal( jQuery("#nonnodes").contents().clone().length, 3, "Check node,textnode,comment clone works (some browsers delete comments on clone)" ); + assert.equal( jQuery( "#nonnodes" ).contents().clone().length, 3, "Check node,textnode,comment clone works (some browsers delete comments on clone)" ); // Verify that clones of clones can keep event listeners - div = jQuery("<div><ul><li>test</li></ul></div>").on( "click", function() { + div = jQuery( "<div><ul><li>test</li></ul></div>" ).on( "click", function() { assert.ok( true, "Bound event still exists." ); - }); + } ); clone = div.clone( true ); div.remove(); div = clone.clone( true ); clone.remove(); assert.equal( div.length, 1, "One element cloned" ); assert.equal( div[ 0 ].nodeName.toUpperCase(), "DIV", "DIV element cloned" ); - div.trigger("click"); + div.trigger( "click" ); // Manually clean up detached elements div.remove(); // Verify that cloned children can keep event listeners - div = jQuery("<div/>").append([ document.createElement("table"), document.createElement("table") ]); - div.find("table").on( "click", function() { + div = jQuery( "<div/>" ).append( [ document.createElement( "table" ), document.createElement( "table" ) ] ); + div.find( "table" ).on( "click", function() { assert.ok( true, "Bound event still exists." ); - }); + } ); clone = div.clone( true ); assert.equal( clone.length, 1, "One element cloned" ); assert.equal( clone[ 0 ].nodeName.toUpperCase(), "DIV", "DIV element cloned" ); - clone.find("table").trigger("click"); + clone.find( "table" ).trigger( "click" ); // Manually clean up detached elements div.remove(); clone.remove(); // Make sure that doing .clone() doesn't clone event listeners - div = jQuery("<div><ul><li>test</li></ul></div>").on( "click", function() { + div = jQuery( "<div><ul><li>test</li></ul></div>" ).on( "click", function() { assert.ok( false, "Bound event still exists after .clone()." ); - }); + } ); clone = div.clone(); - clone.trigger("click"); + clone.trigger( "click" ); // Manually clean up detached elements clone.remove(); div.remove(); // Test both html() and clone() for <embed> and <object> types - div = jQuery("<div/>").html("<embed height='355' width='425' src='http://www.youtube.com/v/3KANI2dpXLw&hl=en'></embed>"); + div = jQuery( "<div/>" ).html( "<embed height='355' width='425' src='http://www.youtube.com/v/3KANI2dpXLw&hl=en'></embed>" ); clone = div.clone( true ); assert.equal( clone.length, 1, "One element cloned" ); @@ -1459,76 +1456,77 @@ QUnit.test( "clone()", function( assert ) { // this is technically an invalid object, but because of the special // classid instantiation it is the only kind that IE has trouble with, // so let's test with it too. - div = jQuery("<div/>").html("<object height='355' width='425' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'> <param name='movie' value='http://www.youtube.com/v/3KANI2dpXLw&hl=en'> <param name='wmode' value='transparent'> </object>"); + div = jQuery( "<div/>" ).html( "<object height='355' width='425' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'> <param name='movie' value='http://www.youtube.com/v/3KANI2dpXLw&hl=en'> <param name='wmode' value='transparent'> </object>" ); clone = div.clone( true ); assert.equal( clone.length, 1, "One element cloned" ); assert.equal( clone[ 0 ].nodeName.toUpperCase(), "DIV", "DIV element cloned" ); - div = div.find("object"); - clone = clone.find("object"); + 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 ); } ); - (function() { + ( function() { var params = {}; - clone.find("param").each(function( index, param ) { + clone.find( "param" ).each( function( index, param ) { params[ param.attributes.name.nodeValue.toLowerCase() ] = param.attributes.value.nodeValue.toLowerCase(); - }); + } ); - div.find("param").each(function( index, param ) { + div.find( "param" ).each( function( index, param ) { var key = param.attributes.name.nodeValue.toLowerCase(); assert.equal( params[ key ], param.attributes.value.nodeValue.toLowerCase(), "<param> cloned: " + key ); - }); - })(); + } ); + } )(); // and here's a valid one. - div = jQuery("<div/>").html("<object height='355' width='425' type='application/x-shockwave-flash' data='http://www.youtube.com/v/3KANI2dpXLw&hl=en'> <param name='movie' value='http://www.youtube.com/v/3KANI2dpXLw&hl=en'> <param name='wmode' value='transparent'> </object>"); + div = jQuery( "<div/>" ).html( "<object height='355' width='425' type='application/x-shockwave-flash' data='http://www.youtube.com/v/3KANI2dpXLw&hl=en'> <param name='movie' value='http://www.youtube.com/v/3KANI2dpXLw&hl=en'> <param name='wmode' value='transparent'> </object>" ); - clone = div.clone(true); + clone = div.clone( true ); assert.equal( clone.length, 1, "One element cloned" ); assert.equal( clone.html(), div.html(), "Element contents cloned" ); assert.equal( clone[ 0 ].nodeName.toUpperCase(), "DIV", "DIV element cloned" ); - div = jQuery("<div/>").data({ "a": true }); + div = jQuery( "<div/>" ).data( { "a": true } ); clone = div.clone( true ); - assert.equal( clone.data("a"), true, "Data cloned." ); + assert.equal( clone.data( "a" ), true, "Data cloned." ); clone.data( "a", false ); - assert.equal( clone.data("a"), false, "Ensure cloned element data object was correctly modified" ); - assert.equal( div.data("a"), true, "Ensure cloned element data object is copied, not referenced" ); + assert.equal( clone.data( "a" ), false, "Ensure cloned element data object was correctly modified" ); + assert.equal( div.data( "a" ), true, "Ensure cloned element data object is copied, not referenced" ); // manually clean up detached elements div.remove(); clone.remove(); - form = document.createElement("form"); + form = document.createElement( "form" ); form.action = "/test/"; - div = document.createElement("div"); - div.appendChild( document.createTextNode("test") ); + div = document.createElement( "div" ); + div.appendChild( document.createTextNode( "test" ) ); form.appendChild( div ); - assert.equal( jQuery(form).clone().children().length, 1, "Make sure we just get the form back." ); + assert.equal( jQuery( form ).clone().children().length, 1, "Make sure we just get the form back." ); - body = jQuery("body").clone(); + body = jQuery( "body" ).clone(); assert.equal( body.children()[ 0 ].id, "qunit", "Make sure cloning body works" ); body.remove(); -}); +} ); QUnit.test( "clone(script type=non-javascript) (#11359)", function( assert ) { assert.expect( 3 ); - var src = jQuery("<script type='text/filler'>Lorem ipsum dolor sit amet</script><q><script type='text/filler'>consectetur adipiscing elit</script></q>"), + var src = jQuery( "<script type='text/filler'>Lorem ipsum dolor sit amet</script><q><script type='text/filler'>consectetur adipiscing elit</script></q>" ), dest = src.clone(); assert.equal( dest[ 0 ].text, "Lorem ipsum dolor sit amet", "Cloning preserves script text" ); assert.equal( dest.last().html(), src.last().html(), "Cloning preserves nested script text" ); assert.ok( /^\s*<scr.pt\s+type=['"]?text\/filler['"]?\s*>consectetur adipiscing elit<\/scr.pt>\s*$/i.test( dest.last().html() ), "Cloning preserves nested script text" ); dest.remove(); -}); +} ); QUnit.test( "clone(form element) (Bug #3879, #6655)", function( assert ) { @@ -1536,49 +1534,49 @@ QUnit.test( "clone(form element) (Bug #3879, #6655)", function( assert ) { var clone, element; - element = jQuery("<select><option>Foo</option><option value='selected' selected>Bar</option></select>"); + element = jQuery( "<select><option>Foo</option><option value='selected' selected>Bar</option></select>" ); - assert.equal( element.clone().find("option").filter(function() { return this.selected; }).val(), "selected", "Selected option cloned correctly" ); + assert.equal( element.clone().find( "option" ).filter( function() { return this.selected; } ).val(), "selected", "Selected option cloned correctly" ); - element = jQuery("<input type='checkbox' value='foo'>").attr( "checked", "checked" ); + element = jQuery( "<input type='checkbox' value='foo'>" ).attr( "checked", "checked" ); clone = element.clone(); - assert.equal( clone.is(":checked"), element.is(":checked"), "Checked input cloned correctly" ); + assert.equal( clone.is( ":checked" ), element.is( ":checked" ), "Checked input cloned correctly" ); assert.equal( clone[ 0 ].defaultValue, "foo", "Checked input defaultValue cloned correctly" ); - element = jQuery("<input type='text' value='foo'>"); + element = jQuery( "<input type='text' value='foo'>" ); clone = element.clone(); assert.equal( clone[ 0 ].defaultValue, "foo", "Text input defaultValue cloned correctly" ); - element = jQuery("<textarea>foo</textarea>"); + element = jQuery( "<textarea>foo</textarea>" ); clone = element.clone(); assert.equal( clone[ 0 ].defaultValue, "foo", "Textarea defaultValue cloned correctly" ); -}); +} ); QUnit.test( "clone(multiple selected options) (Bug #8129)", function( assert ) { assert.expect( 1 ); - var element = jQuery("<select><option>Foo</option><option selected>Bar</option><option selected>Baz</option></select>"); + var element = jQuery( "<select><option>Foo</option><option selected>Bar</option><option selected>Baz</option></select>" ); - assert.equal( element.clone().find("option:selected").length, element.find("option:selected").length, "Multiple selected options cloned correctly" ); + assert.equal( element.clone().find( "option:selected" ).length, element.find( "option:selected" ).length, "Multiple selected options cloned correctly" ); -}); +} ); QUnit.test( "clone() on XML nodes", function( assert ) { assert.expect( 2 ); var xml = createDashboardXML(), - root = jQuery(xml.documentElement).clone(), - origTab = jQuery("tab", xml).eq( 0 ), - cloneTab = jQuery("tab", root).eq( 0 ); + root = jQuery( xml.documentElement ).clone(), + origTab = jQuery( "tab", xml ).eq( 0 ), + cloneTab = jQuery( "tab", root ).eq( 0 ); - origTab.text("origval"); - cloneTab.text("cloneval"); + origTab.text( "origval" ); + cloneTab.text( "cloneval" ); assert.equal( origTab.text(), "origval", "Check original XML node was correctly set" ); assert.equal( cloneTab.text(), "cloneval", "Check cloned XML node was correctly set" ); -}); +} ); QUnit.test( "clone() on local XML nodes with html5 nodename", function( assert ) { @@ -1589,54 +1587,54 @@ QUnit.test( "clone() on local XML nodes with html5 nodename", function( assert ) assert.equal( $meter[ 0 ].nodeName, "meter", "Check if nodeName was not changed due to cloning" ); assert.equal( $meter[ 0 ].nodeType, 1, "Check if nodeType is not changed due to cloning" ); -}); +} ); QUnit.test( "html(undefined)", function( assert ) { assert.expect( 1 ); - assert.equal( jQuery("#foo").html("<i>test</i>").html(undefined).html().toLowerCase(), "<i>test</i>", ".html(undefined) is chainable (#5571)" ); -}); + assert.equal( jQuery( "#foo" ).html( "<i>test</i>" ).html( undefined ).html().toLowerCase(), "<i>test</i>", ".html(undefined) is chainable (#5571)" ); +} ); QUnit.test( "html() on empty set", function( assert ) { assert.expect( 1 ); assert.strictEqual( jQuery().html(), undefined, ".html() returns undefined for empty sets (#11962)" ); -}); +} ); function childNodeNames( node ) { return jQuery.map( node.childNodes, function( child ) { return child.nodeName.toUpperCase(); - }).join(" "); + } ).join( " " ); } function testHtml( valueObj, assert ) { assert.expect( 40 ); var actual, expected, tmp, - div = jQuery("<div></div>"), - fixture = jQuery("#qunit-fixture"); + div = jQuery( "<div></div>" ), + fixture = jQuery( "#qunit-fixture" ); - div.html( valueObj("<div id='parent_1'><div id='child_1'/></div><div id='parent_2'/>") ); + div.html( valueObj( "<div id='parent_1'><div id='child_1'/></div><div id='parent_2'/>" ) ); assert.equal( div.children().length, 2, "Found children" ); assert.equal( div.children().children().length, 1, "Found grandchild" ); actual = []; expected = []; - tmp = jQuery("<map/>").html( valueObj("<area alt='area'/>") ).each(function() { - expected.push("AREA"); + tmp = jQuery( "<map/>" ).html( valueObj( "<area alt='area'/>" ) ).each( function() { + expected.push( "AREA" ); actual.push( childNodeNames( this ) ); - }); + } ); assert.equal( expected.length, 1, "Expecting one parent" ); assert.deepEqual( actual, expected, "Found the inserted area element" ); - assert.equal( div.html(valueObj(5)).html(), "5", "Setting a number as html" ); - assert.equal( div.html(valueObj(0)).html(), "0", "Setting a zero as html" ); - assert.equal( div.html(valueObj(Infinity)).html(), "Infinity", "Setting Infinity as html" ); - assert.equal( div.html(valueObj(NaN)).html(), "", "Setting NaN as html" ); - assert.equal( div.html(valueObj(1e2)).html(), "100", "Setting exponential number notation as html" ); + assert.equal( div.html( valueObj( 5 ) ).html(), "5", "Setting a number as html" ); + assert.equal( div.html( valueObj( 0 ) ).html(), "0", "Setting a zero as html" ); + assert.equal( div.html( valueObj( Infinity ) ).html(), "Infinity", "Setting Infinity as html" ); + assert.equal( div.html( valueObj( NaN ) ).html(), "", "Setting NaN as html" ); + assert.equal( div.html( valueObj( 1e2 ) ).html(), "100", "Setting exponential number notation as html" ); - div.html( valueObj(" &") ); + div.html( valueObj( " &" ) ); assert.equal( div[ 0 ].innerHTML.replace( /\xA0/, " " ), " &", @@ -1644,46 +1642,46 @@ function testHtml( valueObj, assert ) { ); tmp = "<div>hello1</div>"; - assert.equal( div.html(valueObj(tmp) ).html().replace( />/g, ">" ), tmp, "Escaped html" ); + assert.equal( div.html( valueObj( tmp ) ).html().replace( />/g, ">" ), tmp, "Escaped html" ); tmp = "x" + tmp; - assert.equal( div.html(valueObj( tmp )).html().replace( />/g, ">" ), tmp, "Escaped html, leading x" ); + assert.equal( div.html( valueObj( tmp ) ).html().replace( />/g, ">" ), tmp, "Escaped html, leading x" ); tmp = " " + tmp.slice( 1 ); - assert.equal( div.html(valueObj( tmp )).html().replace( />/g, ">" ), tmp, "Escaped html, leading space" ); + assert.equal( div.html( valueObj( tmp ) ).html().replace( />/g, ">" ), tmp, "Escaped html, leading space" ); actual = []; expected = []; tmp = {}; - jQuery("#nonnodes").contents().html( valueObj("<b>bold</b>") ).each(function() { + jQuery( "#nonnodes" ).contents().html( valueObj( "<b>bold</b>" ) ).each( function() { var html = jQuery( this ).html(); tmp[ this.nodeType ] = true; expected.push( this.nodeType === 1 ? "<b>bold</b>" : undefined ); actual.push( html ? html.toLowerCase() : html ); - }); + } ); assert.deepEqual( actual, expected, "Set containing element, text node, comment" ); assert.ok( tmp[ 1 ], "element" ); assert.ok( tmp[ 3 ], "text node" ); assert.ok( tmp[ 8 ], "comment" ); actual = []; expected = []; - fixture.children("div").html( valueObj("<b>test</b>") ).each(function() { - expected.push("B"); + fixture.children( "div" ).html( valueObj( "<b>test</b>" ) ).each( function() { + expected.push( "B" ); actual.push( childNodeNames( this ) ); - }); + } ); assert.equal( expected.length, 7, "Expecting many parents" ); assert.deepEqual( actual, expected, "Correct childNodes after setting HTML" ); actual = []; expected = []; - fixture.html( valueObj("<style>.foobar{color:green;}</style>") ).each(function() { - expected.push("STYLE"); + fixture.html( valueObj( "<style>.foobar{color:green;}</style>" ) ).each( function() { + expected.push( "STYLE" ); actual.push( childNodeNames( this ) ); - }); + } ); assert.equal( expected.length, 1, "Expecting one parent" ); assert.deepEqual( actual, expected, "Found the inserted style element" ); - fixture.html( valueObj("<select/>") ); - jQuery("#qunit-fixture select").html( valueObj("<option>O1</option><option selected='selected'>O2</option><option>O3</option>") ); - assert.equal( jQuery("#qunit-fixture select").val(), "O2", "Selected option correct" ); + fixture.html( valueObj( "<select/>" ) ); + jQuery( "#qunit-fixture select" ).html( valueObj( "<option>O1</option><option selected='selected'>O2</option><option>O3</option>" ) ); + assert.equal( jQuery( "#qunit-fixture select" ).val(), "O2", "Selected option correct" ); tmp = fixture.html( - valueObj([ + valueObj( [ "<script type='something/else'>ok( false, 'evaluated: non-script' );</script>", "<script type='text/javascript'>ok( true, 'evaluated: text/javascript' );</script>", "<script type='text/ecmascript'>ok( true, 'evaluated: text/ecmascript' );</script>", @@ -1694,38 +1692,38 @@ function testHtml( valueObj, assert ) { "<script type='text/ecmascript'>ok( true, 'evaluated: inner text/ecmascript' );</script>", "<script>ok( true, 'evaluated: inner no type' );</script>", "</div>" - ].join("")) - ).find("script"); + ].join( "" ) ) + ).find( "script" ); assert.equal( tmp.length, 8, "All script tags remain." ); assert.equal( tmp[ 0 ].type, "something/else", "Non-evaluated type." ); assert.equal( tmp[ 1 ].type, "text/javascript", "Evaluated type." ); - fixture.html( valueObj("<script type='text/javascript'>ok( true, 'Injection of identical script' );</script>") ); - fixture.html( valueObj("<script type='text/javascript'>ok( true, 'Injection of identical script' );</script>") ); - fixture.html( valueObj("<script type='text/javascript'>ok( true, 'Injection of identical script' );</script>") ); - fixture.html( valueObj("foo <form><script type='text/javascript'>ok( true, 'Injection of identical script (#975)' );</script></form>") ); + fixture.html( valueObj( "<script type='text/javascript'>ok( true, 'Injection of identical script' );</script>" ) ); + fixture.html( valueObj( "<script type='text/javascript'>ok( true, 'Injection of identical script' );</script>" ) ); + fixture.html( valueObj( "<script type='text/javascript'>ok( true, 'Injection of identical script' );</script>" ) ); + fixture.html( valueObj( "foo <form><script type='text/javascript'>ok( true, 'Injection of identical script (#975)' );</script></form>" ) ); jQuery.scriptorder = 0; - fixture.html( valueObj([ + fixture.html( valueObj( [ "<script>", "equal( jQuery('#scriptorder').length, 1,'Execute after html' );", "equal( jQuery.scriptorder++, 0, 'Script is executed in order' );", "</script>", "<span id='scriptorder'><script>equal( jQuery.scriptorder++, 1, 'Script (nested) is executed in order');</script></span>", "<script>equal( jQuery.scriptorder++, 2, 'Script (unnested) is executed in order' );</script>" - ].join("")) ); + ].join( "" ) ) ); fixture.html( valueObj( fixture.text() ) ); assert.ok( /^[^<]*[^<\s][^<]*$/.test( fixture.html() ), "Replace html with text" ); } QUnit.test( "html(String|Number)", function( assert ) { - testHtml(manipulationBareObj, assert ); -}); + testHtml( manipulationBareObj, assert ); +} ); QUnit.test( "html(Function)", function( assert ) { - testHtml(manipulationFunctionReturningObj, assert ); -}); + testHtml( manipulationFunctionReturningObj, assert ); +} ); QUnit.test( "html(Function) with incoming value -- direct selection", function( assert ) { @@ -1733,24 +1731,24 @@ QUnit.test( "html(Function) with incoming value -- direct selection", function( var els, actualhtml, pass; - els = jQuery("#foo > p"); - actualhtml = els.map(function() { + els = jQuery( "#foo > p" ); + actualhtml = els.map( function() { return jQuery( this ).html(); - }); + } ); - els.html(function( i, val ) { + els.html( function( i, val ) { assert.equal( val, actualhtml[ i ], "Make sure the incoming value is correct." ); return "<b>test</b>"; - }); + } ); pass = true; - els.each(function() { + els.each( function() { if ( this.childNodes.length !== 1 ) { pass = false; } - }); + } ); assert.ok( pass, "Set HTML" ); -}); +} ); QUnit.test( "html(Function) with incoming value -- jQuery.contents()", function( assert ) { @@ -1758,15 +1756,15 @@ QUnit.test( "html(Function) with incoming value -- jQuery.contents()", function( var actualhtml, j, $div, $div2, insert; - j = jQuery("#nonnodes").contents(); - actualhtml = j.map(function() { + j = jQuery( "#nonnodes" ).contents(); + actualhtml = j.map( function() { return jQuery( this ).html(); - }); + } ); - j.html(function( i, val ) { + j.html( function( i, val ) { assert.equal( val, actualhtml[ i ], "Make sure the incoming value is correct." ); return "<b>bold</b>"; - }); + } ); // Handle the case where no comment is in the document if ( j.length === 2 ) { @@ -1775,99 +1773,99 @@ QUnit.test( "html(Function) with incoming value -- jQuery.contents()", function( assert.equal( j.html().replace( / xmlns="[^"]+"/g, "" ).toLowerCase(), "<b>bold</b>", "Check node,textnode,comment with html()" ); - $div = jQuery("<div />"); + $div = jQuery( "<div />" ); - assert.equal( $div.html(function( i, val ) { + assert.equal( $div.html( function( i, val ) { assert.equal( val, "", "Make sure the incoming value is correct." ); return 5; - }).html(), "5", "Setting a number as html" ); + } ).html(), "5", "Setting a number as html" ); - assert.equal( $div.html(function( i, val ) { + assert.equal( $div.html( function( i, val ) { assert.equal( val, "5", "Make sure the incoming value is correct." ); return 0; - }).html(), "0", "Setting a zero as html" ); + } ).html(), "0", "Setting a zero as html" ); - $div2 = jQuery("<div/>"); + $div2 = jQuery( "<div/>" ); insert = "<div>hello1</div>"; - assert.equal( $div2.html(function( i, val ) { + assert.equal( $div2.html( function( i, val ) { assert.equal( val, "", "Make sure the incoming value is correct." ); return insert; - }).html().replace(/>/g, ">"), insert, "Verify escaped insertion." ); + } ).html().replace( />/g, ">" ), insert, "Verify escaped insertion." ); - assert.equal( $div2.html(function( i, val ) { - assert.equal( val.replace(/>/g, ">"), insert, "Make sure the incoming value is correct." ); + assert.equal( $div2.html( function( i, val ) { + assert.equal( val.replace( />/g, ">" ), insert, "Make sure the incoming value is correct." ); return "x" + insert; - }).html().replace( />/g, ">" ), "x" + insert, "Verify escaped insertion." ); + } ).html().replace( />/g, ">" ), "x" + insert, "Verify escaped insertion." ); - assert.equal( $div2.html(function( i, val ) { + assert.equal( $div2.html( function( i, val ) { assert.equal( val.replace( />/g, ">" ), "x" + insert, "Make sure the incoming value is correct." ); return " " + insert; - }).html().replace( />/g, ">" ), " " + insert, "Verify escaped insertion." ); -}); + } ).html().replace( />/g, ">" ), " " + insert, "Verify escaped insertion." ); +} ); QUnit.test( "clone()/html() don't expose jQuery/Sizzle expandos (#12858)", function( assert ) { assert.expect( 2 ); - var $content = jQuery("<div><b><i>text</i></b></div>").appendTo("#qunit-fixture"), + var $content = jQuery( "<div><b><i>text</i></b></div>" ).appendTo( "#qunit-fixture" ), expected = /^<b><i>text<\/i><\/b>$/i; // Attach jQuery and Sizzle data (the latter with a non-qSA nth-child) try { - $content.find(":nth-child(1):lt(4)").data( "test", true ); + $content.find( ":nth-child(1):lt(4)" ).data( "test", true ); // But don't break on a non-Sizzle build - } catch( e ) { - $content.find("*").data( "test", true ); + } catch ( e ) { + $content.find( "*" ).data( "test", true ); } assert.ok( expected.test( $content.clone( false )[ 0 ].innerHTML ), "clone()" ); assert.ok( expected.test( $content.html() ), "html()" ); -}); +} ); QUnit.test( "remove() no filters", function( assert ) { assert.expect( 2 ); - var first = jQuery("#ap").children().first(); + var first = jQuery( "#ap" ).children().first(); - first.data("foo", "bar"); + first.data( "foo", "bar" ); - jQuery("#ap").children().remove(); - assert.ok( jQuery("#ap").text().length > 10, "Check text is not removed" ); - assert.equal( jQuery("#ap").children().length, 0, "Check remove" ); -}); + jQuery( "#ap" ).children().remove(); + assert.ok( jQuery( "#ap" ).text().length > 10, "Check text is not removed" ); + assert.equal( jQuery( "#ap" ).children().length, 0, "Check remove" ); +} ); QUnit.test( "remove() with filters", function( assert ) { assert.expect( 8 ); var markup, div; - jQuery("#ap").children().remove("a"); - assert.ok( jQuery("#ap").text().length > 10, "Check text is not removed" ); - assert.equal( jQuery("#ap").children().length, 1, "Check filtered remove" ); + jQuery( "#ap" ).children().remove( "a" ); + assert.ok( jQuery( "#ap" ).text().length > 10, "Check text is not removed" ); + assert.equal( jQuery( "#ap" ).children().length, 1, "Check filtered remove" ); - jQuery("#ap").children().remove("a, code"); - assert.equal( jQuery("#ap").children().length, 0, "Check multi-filtered remove" ); + jQuery( "#ap" ).children().remove( "a, code" ); + assert.equal( jQuery( "#ap" ).children().length, 0, "Check multi-filtered remove" ); // Positional and relative selectors markup = "<div><span>1</span><span>2</span><span>3</span><span>4</span></div>"; div = jQuery( markup ); - div.children().remove("span:nth-child(2n)"); + div.children().remove( "span:nth-child(2n)" ); assert.equal( div.text(), "13", "relative selector in remove" ); div = jQuery( markup ); - div.children().remove("span:first"); + div.children().remove( "span:first" ); assert.equal( div.text(), "234", "positional selector in remove" ); div = jQuery( markup ); - div.children().remove("span:last"); + div.children().remove( "span:last" ); assert.equal( div.text(), "123", "positional selector in remove" ); // using contents will get comments regular, text, and comment nodes // Handle the case where no comment is in the document - assert.ok( jQuery("#nonnodes").contents().length >= 2, "Check node,textnode,comment remove works" ); - jQuery("#nonnodes").contents().remove(); - assert.equal( jQuery("#nonnodes").contents().length, 0, "Check node,textnode,comment remove works" ); -}); + assert.ok( jQuery( "#nonnodes" ).contents().length >= 2, "Check node,textnode,comment remove works" ); + jQuery( "#nonnodes" ).contents().remove(); + assert.equal( jQuery( "#nonnodes" ).contents().length, 0, "Check node,textnode,comment remove works" ); +} ); QUnit.test( "remove() event cleaning ", function( assert ) { assert.expect( 1 ); @@ -1875,16 +1873,16 @@ QUnit.test( "remove() event cleaning ", function( assert ) { var count, first, cleanUp; count = 0; - first = jQuery("#ap").children().first(); + first = jQuery( "#ap" ).children().first(); cleanUp = first.on( "click", function() { count++; - }).remove().appendTo("#qunit-fixture").trigger("click"); + } ).remove().appendTo( "#qunit-fixture" ).trigger( "click" ); assert.strictEqual( 0, count, "Event handler has been removed" ); // Clean up detached data cleanUp.remove(); -}); +} ); QUnit.test( "remove() in document order #13779", function( assert ) { assert.expect( 1 ); @@ -1893,11 +1891,11 @@ QUnit.test( "remove() in document order #13779", function( assert ) { cleanData = jQuery.cleanData; jQuery.cleanData = function( nodes ) { - last = jQuery.text( nodes[0] ); + last = jQuery.text( nodes[ 0 ] ); cleanData.call( this, nodes ); }; - jQuery("#qunit-fixture").append( + jQuery( "#qunit-fixture" ).append( jQuery.parseHTML( "<div class='removal-fixture'>1</div>" + "<div class='removal-fixture'>2</div>" + @@ -1905,60 +1903,60 @@ QUnit.test( "remove() in document order #13779", function( assert ) { ) ); - jQuery(".removal-fixture").remove(); + jQuery( ".removal-fixture" ).remove(); assert.equal( last, 3, "The removal fixtures were removed in document order" ); jQuery.cleanData = cleanData; -}); +} ); -QUnit.test("detach() no filters", function( assert ) { +QUnit.test( "detach() no filters", function( assert ) { - assert.expect(3); + assert.expect( 3 ); - var first = jQuery("#ap").children().first(); + var first = jQuery( "#ap" ).children().first(); - first.data("foo", "bar"); + first.data( "foo", "bar" ); - jQuery("#ap").children().detach(); - assert.ok(jQuery("#ap").text().length > 10, "Check text is not removed"); - assert.equal(jQuery("#ap").children().length, 0, "Check remove"); + jQuery( "#ap" ).children().detach(); + assert.ok( jQuery( "#ap" ).text().length > 10, "Check text is not removed" ); + assert.equal( jQuery( "#ap" ).children().length, 0, "Check remove" ); - assert.equal(first.data("foo"), "bar"); + assert.equal( first.data( "foo" ), "bar" ); first.remove(); -}); +} ); -QUnit.test("detach() with filters", function( assert ) { +QUnit.test( "detach() with filters", function( assert ) { - assert.expect(8); + assert.expect( 8 ); var markup, div; - jQuery("#ap").children().detach("a"); - assert.ok(jQuery("#ap").text().length > 10, "Check text is not removed"); - assert.equal(jQuery("#ap").children().length, 1, "Check filtered remove"); + jQuery( "#ap" ).children().detach( "a" ); + assert.ok( jQuery( "#ap" ).text().length > 10, "Check text is not removed" ); + assert.equal( jQuery( "#ap" ).children().length, 1, "Check filtered remove" ); - jQuery("#ap").children().detach("a, code"); - assert.equal(jQuery("#ap").children().length, 0, "Check multi-filtered remove"); + jQuery( "#ap" ).children().detach( "a, code" ); + assert.equal( jQuery( "#ap" ).children().length, 0, "Check multi-filtered remove" ); // Positional and relative selectors markup = "<div><span>1</span><span>2</span><span>3</span><span>4</span></div>"; - div = jQuery(markup); - div.children().detach("span:nth-child(2n)"); - assert.equal(div.text(), "13", "relative selector in detach"); - div = jQuery(markup); - div.children().detach("span:first"); - assert.equal(div.text(), "234", "positional selector in detach"); - div = jQuery(markup); - div.children().detach("span:last"); - assert.equal(div.text(), "123", "positional selector in detach"); + div = jQuery( markup ); + div.children().detach( "span:nth-child(2n)" ); + assert.equal( div.text(), "13", "relative selector in detach" ); + div = jQuery( markup ); + div.children().detach( "span:first" ); + assert.equal( div.text(), "234", "positional selector in detach" ); + div = jQuery( markup ); + div.children().detach( "span:last" ); + assert.equal( div.text(), "123", "positional selector in detach" ); // using contents will get comments regular, text, and comment nodes // Handle the case where no comment is in the document - assert.ok(jQuery("#nonnodes").contents().length >= 2, "Check node,textnode,comment remove works"); - jQuery("#nonnodes").contents().detach(); - assert.equal(jQuery("#nonnodes").contents().length, 0, "Check node,textnode,comment remove works"); -}); + assert.ok( jQuery( "#nonnodes" ).contents().length >= 2, "Check node,textnode,comment remove works" ); + jQuery( "#nonnodes" ).contents().detach(); + assert.equal( jQuery( "#nonnodes" ).contents().length, 0, "Check node,textnode,comment remove works" ); +} ); QUnit.test( "detach() event cleaning ", function( assert ) { assert.expect( 1 ); @@ -1966,29 +1964,29 @@ QUnit.test( "detach() event cleaning ", function( assert ) { var count, first, cleanUp; count = 0; - first = jQuery("#ap").children().first(); + first = jQuery( "#ap" ).children().first(); cleanUp = first.on( "click", function() { count++; - }).detach().appendTo("#qunit-fixture").trigger("click"); + } ).detach().appendTo( "#qunit-fixture" ).trigger( "click" ); assert.strictEqual( 1, count, "Event handler has not been removed" ); // Clean up detached data cleanUp.remove(); -}); +} ); -QUnit.test("empty()", function( assert ) { +QUnit.test( "empty()", function( assert ) { assert.expect( 3 ); - assert.equal( jQuery("#ap").children().empty().text().length, 0, "Check text is removed" ); - assert.equal( jQuery("#ap").children().length, 4, "Check elements are not removed" ); + assert.equal( jQuery( "#ap" ).children().empty().text().length, 0, "Check text is removed" ); + assert.equal( jQuery( "#ap" ).children().length, 4, "Check elements are not removed" ); // using contents will get comments regular, text, and comment nodes - var j = jQuery("#nonnodes").contents(); + var j = jQuery( "#nonnodes" ).contents(); j.empty(); assert.equal( j.html(), "", "Check node,textnode,comment empty works" ); -}); +} ); QUnit.test( "jQuery.cleanData", function( assert ) { @@ -2003,10 +2001,10 @@ QUnit.test( "jQuery.cleanData", function( assert ) { // Should both do nothing pos = "Outer"; - div.trigger("click"); + div.trigger( "click" ); pos = "Inner"; - div.children().trigger("click"); + div.children().trigger( "click" ); type = "empty"; div = getDiv(); @@ -2017,11 +2015,11 @@ QUnit.test( "jQuery.cleanData", function( assert ) { // Should trigger 1 pos = "Outer"; - div.trigger("click"); + div.trigger( "click" ); // Should do nothing pos = "Inner"; - child.trigger("click"); + child.trigger( "click" ); // Should trigger 2 div.remove(); @@ -2032,29 +2030,29 @@ QUnit.test( "jQuery.cleanData", function( assert ) { child = div.children(); // Should trigger 2 remove event - div.html("<div></div>"); + div.html( "<div></div>" ); // Should trigger 1 pos = "Outer"; - div.trigger("click"); + div.trigger( "click" ); // Should do nothing pos = "Inner"; - child.trigger("click"); + child.trigger( "click" ); // Should trigger 2 div.remove(); function getDiv() { - var div = jQuery("<div class='outer'><div class='inner'></div></div>").on( "click", function() { + var div = jQuery( "<div class='outer'><div class='inner'></div></div>" ).on( "click", function() { assert.ok( true, type + " " + pos + " Click event fired." ); - }).on( "focus", function() { + } ).on( "focus", function() { assert.ok( true, type + " " + pos + " Focus event fired." ); - }).find("div").on( "click", function() { + } ).find( "div" ).on( "click", function() { assert.ok( false, type + " " + pos + " Click event fired." ); - }).on( "focus", function() { + } ).on( "focus", function() { assert.ok( false, type + " " + pos + " Focus event fired." ); - }).end().appendTo("body"); + } ).end().appendTo( "body" ); div[ 0 ].detachEvent = div[ 0 ].removeEventListener = function( t ) { assert.ok( true, type + " Outer " + t + " event unbound" ); @@ -2066,7 +2064,7 @@ QUnit.test( "jQuery.cleanData", function( assert ) { return div; } -}); +} ); QUnit.test( "jQuery.cleanData eliminates all private data (gh-2127)", function( assert ) { assert.expect( 3 ); @@ -2085,7 +2083,7 @@ QUnit.test( "jQuery.cleanData eliminates all private data (gh-2127)", function( "Private data is empty after node is removed" ); div.remove(); -}); +} ); QUnit.test( "jQuery.cleanData eliminates all public data", function( assert ) { assert.expect( 2 ); @@ -2105,7 +2103,7 @@ QUnit.test( "jQuery.cleanData eliminates all public data", function( assert ) { assert.ok( false, "Expando was not removed when there was no more data" ); } } -}); +} ); QUnit.test( "domManip plain-text caching (trac-6779)", function( assert ) { @@ -2120,11 +2118,11 @@ QUnit.test( "domManip plain-text caching (trac-6779)", function( assert ) { try { $f.append( bad[ i ] ); } - catch( e ) {} + catch ( e ) {} } - assert.equal( $f.text(), bad.join(""), "Cached strings that match Object properties" ); + assert.equal( $f.text(), bad.join( "" ), "Cached strings that match Object properties" ); $f.remove(); -}); +} ); QUnit.test( "domManip executes scripts containing html comments or CDATA (trac-9221)", function( assert ) { @@ -2153,7 +2151,7 @@ QUnit.test( "domManip executes scripts containing html comments or CDATA (trac-9 "//--><!]]>", "</script>" ].join( "\n" ) ).appendTo( "#qunit-fixture" ); -}); +} ); testIframeWithCallback( "domManip tolerates window-valued document[0] in IE9/10 (trac-12266)", @@ -2169,12 +2167,12 @@ QUnit.test( "jQuery.clone - no exceptions for object elements #9587", function( assert.expect( 1 ); try { - jQuery("#no-clone-exception").clone(); + jQuery( "#no-clone-exception" ).clone(); assert.ok( true, "cloned with no exceptions" ); - } catch( e ) { + } catch ( e ) { assert.ok( false, e.message ); } -}); +} ); QUnit.test( "Cloned, detached HTML5 elems (#10667,10670)", function( assert ) { @@ -2193,38 +2191,38 @@ QUnit.test( "Cloned, detached HTML5 elems (#10667,10670)", function( assert ) { // Bind an event $section.on( "click", function() { assert.ok( true, "clone fired event" ); - }); + } ); // Second clone (will have an event bound) $clone = $section.clone( true ); // Trigger an event from the first clone - $clone.trigger("click"); - $clone.off("click"); + $clone.trigger( "click" ); + $clone.off( "click" ); // Add a child node with text to the original - $section.append("<p>Hello</p>"); + $section.append( "<p>Hello</p>" ); // Third clone (will have child node and text) $clone = $section.clone( true ); - assert.equal( $clone.find("p").text(), "Hello", "Assert text in child of clone" ); + assert.equal( $clone.find( "p" ).text(), "Hello", "Assert text in child of clone" ); // Trigger an event from the third clone - $clone.trigger("click"); - $clone.off("click"); + $clone.trigger( "click" ); + $clone.off( "click" ); // Add attributes to copy - $section.attr({ + $section.attr( { "class": "foo bar baz", "title": "This is a title" - }); + } ); // Fourth clone (will have newly added attributes) $clone = $section.clone( true ); - assert.equal( $clone.attr("class"), $section.attr("class"), "clone and element have same class attribute" ); - assert.equal( $clone.attr("title"), $section.attr("title"), "clone and element have same title attribute" ); + assert.equal( $clone.attr( "class" ), $section.attr( "class" ), "clone and element have same class attribute" ); + assert.equal( $clone.attr( "title" ), $section.attr( "title" ), "clone and element have same title attribute" ); // Remove the original $section.remove(); @@ -2236,12 +2234,12 @@ QUnit.test( "Cloned, detached HTML5 elems (#10667,10670)", function( assert ) { $clone.remove(); // Trigger an event from the clone of the clone - $section.trigger("click"); + $section.trigger( "click" ); // Unbind any remaining events - $section.off("click"); - $clone.off("click"); -}); + $section.off( "click" ); + $clone.off( "click" ); +} ); QUnit.test( "Guard against exceptions when clearing safeChildNodes", function( assert ) { @@ -2250,24 +2248,25 @@ QUnit.test( "Guard against exceptions when clearing safeChildNodes", function( a var div; try { - div = jQuery("<div/><hr/><code/><b/>"); - } catch(e) {} + div = jQuery( "<div/><hr/><code/><b/>" ); + } catch ( e ) {} assert.ok( div && div.jquery, "Created nodes safely, guarded against exceptions on safeChildNodes[ -1 ]" ); -}); +} ); QUnit.test( "Ensure oldIE creates a new set on appendTo (#8894)", function( assert ) { assert.expect( 5 ); - assert.strictEqual( jQuery("<div/>").clone().addClass("test").appendTo("<div/>").end().end().hasClass("test"), false, "Check jQuery.fn.appendTo after jQuery.clone" ); - assert.strictEqual( jQuery("<div/>").find("p").end().addClass("test").appendTo("<div/>").end().end().hasClass("test"), false, "Check jQuery.fn.appendTo after jQuery.fn.find" ); - assert.strictEqual( jQuery("<div/>").text("test").addClass("test").appendTo("<div/>").end().end().hasClass("test"), false, "Check jQuery.fn.appendTo after jQuery.fn.text" ); - assert.strictEqual( jQuery("<bdi/>").clone().addClass("test").appendTo("<div/>").end().end().hasClass("test"), false, "Check jQuery.fn.appendTo after clone html5 element" ); - assert.strictEqual( jQuery("<p/>").appendTo("<div/>").end().length, jQuery("<p>test</p>").appendTo("<div/>").end().length, "Elements created with createElement and with createDocumentFragment should be treated alike" ); -}); + assert.strictEqual( jQuery( "<div/>" ).clone().addClass( "test" ).appendTo( "<div/>" ).end().end().hasClass( "test" ), false, "Check jQuery.fn.appendTo after jQuery.clone" ); + assert.strictEqual( jQuery( "<div/>" ).find( "p" ).end().addClass( "test" ).appendTo( "<div/>" ).end().end().hasClass( "test" ), false, "Check jQuery.fn.appendTo after jQuery.fn.find" ); + assert.strictEqual( jQuery( "<div/>" ).text( "test" ).addClass( "test" ).appendTo( "<div/>" ).end().end().hasClass( "test" ), false, "Check jQuery.fn.appendTo after jQuery.fn.text" ); + assert.strictEqual( jQuery( "<bdi/>" ).clone().addClass( "test" ).appendTo( "<div/>" ).end().end().hasClass( "test" ), false, "Check jQuery.fn.appendTo after clone html5 element" ); + assert.strictEqual( jQuery( "<p/>" ).appendTo( "<div/>" ).end().length, jQuery( "<p>test</p>" ).appendTo( "<div/>" ).end().length, "Elements created with createElement and with createDocumentFragment should be treated alike" ); +} ); 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 ) ) { @@ -2281,7 +2280,7 @@ QUnit.asyncTest( "html() - script exceptions bubble (#11743)", 2, function( asse var onerror = window.onerror; - setTimeout(function() { + setTimeout( function() { window.onerror = onerror; QUnit.start(); @@ -2304,46 +2303,46 @@ QUnit.asyncTest( "html() - script exceptions bubble (#11743)", 2, function( asse }; jQuery( "#qunit-fixture" ).html( "<script>undefined();</script>" ); -}); +} ); QUnit.test( "checked state is cloned with clone()", function( assert ) { assert.expect( 2 ); - var elem = jQuery.parseHTML("<input type='checkbox' checked='checked'/>")[ 0 ]; + var elem = jQuery.parseHTML( "<input type='checkbox' checked='checked'/>" )[ 0 ]; elem.checked = false; - assert.equal( jQuery(elem).clone().attr("id","clone")[ 0 ].checked, false, "Checked false state correctly cloned" ); + assert.equal( jQuery( elem ).clone().attr( "id", "clone" )[ 0 ].checked, false, "Checked false state correctly cloned" ); - elem = jQuery.parseHTML("<input type='checkbox'/>")[ 0 ]; + elem = jQuery.parseHTML( "<input type='checkbox'/>" )[ 0 ]; elem.checked = true; - assert.equal( jQuery(elem).clone().attr("id","clone")[ 0 ].checked, true, "Checked true state correctly cloned" ); -}); + assert.equal( jQuery( elem ).clone().attr( "id", "clone" )[ 0 ].checked, true, "Checked true state correctly cloned" ); +} ); QUnit.test( "manipulate mixed jQuery and text (#12384, #12346)", function( assert ) { assert.expect( 2 ); - var div = jQuery("<div>a</div>").append( " ", jQuery("<span>b</span>"), " ", jQuery("<span>c</span>") ), + var div = jQuery( "<div>a</div>" ).append( " ", jQuery( "<span>b</span>" ), " ", jQuery( "<span>c</span>" ) ), nbsp = String.fromCharCode( 160 ); - assert.equal( div.text(), "a" + nbsp + "b" + nbsp+ "c", "Appending mixed jQuery with text nodes" ); + assert.equal( div.text(), "a" + nbsp + "b" + nbsp + "c", "Appending mixed jQuery with text nodes" ); - div = jQuery("<div><div></div></div>") - .find("div") + div = jQuery( "<div><div></div></div>" ) + .find( "div" ) .after( "<p>a</p>", "<p>b</p>" ) .parent(); - assert.equal( div.find("*").length, 3, "added 2 paragraphs after inner div" ); -}); + assert.equal( div.find( "*" ).length, 3, "added 2 paragraphs after inner div" ); +} ); QUnit.test( "script evaluation (#11795)", function( assert ) { assert.expect( 13 ); var scriptsIn, scriptsOut, - fixture = jQuery("#qunit-fixture").empty(), - objGlobal = (function() { + fixture = jQuery( "#qunit-fixture" ).empty(), + objGlobal = ( function() { return this; - })(), + } )(), isOk = objGlobal.ok, notOk = function() { var args = arguments; @@ -2352,7 +2351,7 @@ QUnit.test( "script evaluation (#11795)", function( assert ) { }; objGlobal.ok = notOk; - scriptsIn = jQuery([ + scriptsIn = jQuery( [ "<script type='something/else'>ok( false, 'evaluated: non-script' );</script>", "<script type='text/javascript'>ok( true, 'evaluated: text/javascript' );</script>", "<script type='text/ecmascript'>ok( true, 'evaluated: text/ecmascript' );</script>", @@ -2363,31 +2362,31 @@ QUnit.test( "script evaluation (#11795)", function( assert ) { "<script type='text/ecmascript'>ok( true, 'evaluated: inner text/ecmascript' );</script>", "<script>ok( true, 'evaluated: inner no type' );</script>", "</div>" - ].join("")); - scriptsIn.appendTo( jQuery("<div class='detached'/>") ); + ].join( "" ) ); + scriptsIn.appendTo( jQuery( "<div class='detached'/>" ) ); objGlobal.ok = isOk; - scriptsOut = fixture.append( scriptsIn ).find("script"); + scriptsOut = fixture.append( scriptsIn ).find( "script" ); assert.equal( scriptsOut[ 0 ].type, "something/else", "Non-evaluated type." ); assert.equal( scriptsOut[ 1 ].type, "text/javascript", "Evaluated type." ); - assert.deepEqual( scriptsOut.get(), fixture.find("script").get(), "All script tags remain." ); + assert.deepEqual( scriptsOut.get(), fixture.find( "script" ).get(), "All script tags remain." ); objGlobal.ok = notOk; - scriptsOut = scriptsOut.add( scriptsOut.clone() ).appendTo( fixture.find("div") ); - assert.deepEqual( fixture.find("div script").get(), scriptsOut.get(), "Scripts cloned without reevaluation" ); + scriptsOut = scriptsOut.add( scriptsOut.clone() ).appendTo( fixture.find( "div" ) ); + assert.deepEqual( fixture.find( "div script" ).get(), scriptsOut.get(), "Scripts cloned without reevaluation" ); fixture.append( scriptsOut.detach() ); - assert.deepEqual( fixture.children("script").get(), scriptsOut.get(), "Scripts detached without reevaluation" ); + assert.deepEqual( fixture.children( "script" ).get(), scriptsOut.get(), "Scripts detached without reevaluation" ); objGlobal.ok = isOk; if ( jQuery.ajax ) { - Globals.register("testBar"); - jQuery("#qunit-fixture").append( "<script src='" + url("data/testbar.php") + "'/>" ); - assert.strictEqual( window["testBar"], "bar", "Global script evaluation" ); + Globals.register( "testBar" ); + jQuery( "#qunit-fixture" ).append( "<script src='" + url( "data/testbar.php" ) + "'/>" ); + assert.strictEqual( window[ "testBar" ], "bar", "Global script evaluation" ); } else { assert.ok( true, "No jQuery.ajax" ); assert.ok( true, "No jQuery.ajax" ); } -}); +} ); QUnit.test( "jQuery._evalUrl (#12838)", function( assert ) { @@ -2403,7 +2402,7 @@ QUnit.test( "jQuery._evalUrl (#12838)", function( assert ) { assert.equal( ( input.url || input ).slice( -1 ), expectedArgument, message ); expectedArgument++; }; - jQuery("#qunit-fixture").append("<script src='1'/><script src='2'/>"); + jQuery( "#qunit-fixture" ).append( "<script src='1'/><script src='2'/>" ); assert.equal( expectedArgument, 3, "synchronous execution" ); message = "custom implementation"; @@ -2412,11 +2411,11 @@ QUnit.test( "jQuery._evalUrl (#12838)", function( assert ) { jQuery.ajax = function( options ) { assert.strictEqual( options, {}, "Unexpected call to jQuery.ajax" ); }; - jQuery("#qunit-fixture").append("<script src='3'/><script src='4'/>"); + jQuery( "#qunit-fixture" ).append( "<script src='3'/><script src='4'/>" ); jQuery.ajax = ajax; jQuery._evalUrl = evalUrl; -}); +} ); QUnit.test( "jQuery.htmlPrefilter (gh-1747)", function( assert ) { @@ -2456,7 +2455,7 @@ QUnit.test( "jQuery.htmlPrefilter (gh-1747)", function( assert ) { jQuery.htmlPrefilter = htmlPrefilter; done(); }, 100 ); -}); +} ); QUnit.test( "insertAfter, insertBefore, etc do not work when destination is original element. Element is removed (#4087)", function( assert ) { @@ -2464,7 +2463,7 @@ QUnit.test( "insertAfter, insertBefore, etc do not work when destination is orig var elems; - jQuery.each([ + jQuery.each( [ "appendTo", "prependTo", "insertBefore", @@ -2475,44 +2474,44 @@ QUnit.test( "insertAfter, insertBefore, etc do not work when destination is orig "<ul id='test4087-complex'><li class='test4087'><div>c1</div>h1</li><li><div>c2</div>h2</li></ul>", "<div id='test4087-simple'><div class='test4087-1'>1<div class='test4087-2'>2</div><div class='test4087-3'>3</div></div></div>", "<div id='test4087-multiple'><div class='test4087-multiple'>1</div><div class='test4087-multiple'>2</div></div>" - ].join("") ).appendTo( "#qunit-fixture" ); + ].join( "" ) ).appendTo( "#qunit-fixture" ); // complex case based on http://jsfiddle.net/pbramos/gZ7vB/ - jQuery("#test4087-complex div")[ name ]("#test4087-complex li:last-child div:last-child"); - assert.equal( jQuery("#test4087-complex li:last-child div").length, name === "replaceAll" ? 1 : 2, name +" a node to itself, complex case." ); + jQuery( "#test4087-complex div" )[ name ]( "#test4087-complex li:last-child div:last-child" ); + assert.equal( jQuery( "#test4087-complex li:last-child div" ).length, name === "replaceAll" ? 1 : 2, name + " a node to itself, complex case." ); // simple case - jQuery( ".test4087-1" )[ name ](".test4087-1"); - assert.equal( jQuery(".test4087-1").length, 1, name +" a node to itself, simple case." ); + jQuery( ".test4087-1" )[ name ]( ".test4087-1" ); + assert.equal( jQuery( ".test4087-1" ).length, 1, name + " a node to itself, simple case." ); // clean for next test - jQuery("#test4087-complex").remove(); - jQuery("#test4087-simple").remove(); - jQuery("#test4087-multiple").remove(); - }); -}); + jQuery( "#test4087-complex" ).remove(); + jQuery( "#test4087-simple" ).remove(); + jQuery( "#test4087-multiple" ).remove(); + } ); +} ); QUnit.test( "Index for function argument should be received (#13094)", function( assert ) { assert.expect( 2 ); var i = 0; - jQuery("<div/><div/>").before(function( index ) { + jQuery( "<div/><div/>" ).before( function( index ) { assert.equal( index, i++, "Index should be correct" ); - }); + } ); -}); +} ); QUnit.test( "Make sure jQuery.fn.remove can work on elements in documentFragment", function( assert ) { assert.expect( 1 ); var fragment = document.createDocumentFragment(), - div = fragment.appendChild( document.createElement("div") ); + div = fragment.appendChild( document.createElement( "div" ) ); jQuery( div ).remove(); assert.equal( fragment.childNodes.length, 0, "div element was removed from documentFragment" ); -}); +} ); QUnit.test( "Make sure specific elements with content created correctly (#13232)", function( assert ) { assert.expect( 20 ); @@ -2538,12 +2537,12 @@ QUnit.test( "Make sure specific elements with content created correctly (#13232) results.push( name ); args.push( html ); - }); + } ); - jQuery.fn.append.apply( jQuery("<div/>"), args ).children().each(function( i ) { + jQuery.fn.append.apply( jQuery( "<div/>" ), args ).children().each( function( i ) { assert.ok( jQuery.nodeName( this, results[ i ] ) ); - }); -}); + } ); +} ); QUnit.test( "Validate creation of multiple quantities of certain elements (#13818)", function( assert ) { assert.expect( 44 ); @@ -2551,15 +2550,15 @@ QUnit.test( "Validate creation of multiple quantities of certain elements (#1381 var tags = [ "thead", "tbody", "tfoot", "colgroup", "col", "caption", "tr", "th", "td", "optgroup", "option" ]; jQuery.each( tags, function( index, tag ) { - jQuery( "<" + tag + "/><" + tag + "/>" ).each(function() { + jQuery( "<" + tag + "/><" + tag + "/>" ).each( function() { assert.ok( jQuery.nodeName( this, tag ), tag + " empty elements created correctly" ); - }); + } ); - jQuery( "<" + this + "></" + tag + "><" + tag + "></" + tag + ">" ).each(function() { + jQuery( "<" + this + "></" + tag + "><" + tag + "></" + tag + ">" ).each( function() { assert.ok( jQuery.nodeName( this, tag ), tag + " elements with closing tag created correctly" ); - }); - }); -}); + } ); + } ); +} ); QUnit.test( "Make sure tr element will be appended to tbody element of table when present", function( assert ) { assert.expect( 1 ); @@ -2576,7 +2575,7 @@ QUnit.test( "Make sure tr element will be appended to tbody element of table whe html = table.innerHTML.toLowerCase().replace( /\s/g, "" ); assert.strictEqual( html, "<tbody><tr><td>test</td></tr></tbody>" ); -}); +} ); QUnit.test( "Make sure tr elements will be appended to tbody element of table when present", function( assert ) { assert.expect( 1 ); @@ -2593,7 +2592,7 @@ QUnit.test( "Make sure tr elements will be appended to tbody element of table wh html = table.innerHTML.toLowerCase().replace( /\s/g, "" ); assert.strictEqual( html, "<tbody><tr><td>1</td></tr><tr><td>2</td></tr></tbody>" ); -}); +} ); QUnit.test( "Make sure tfoot element will not be appended to tbody element of table when present", function( assert ) { assert.expect( 1 ); @@ -2610,7 +2609,7 @@ QUnit.test( "Make sure tfoot element will not be appended to tbody element of ta html = table.innerHTML.toLowerCase().replace( /\s/g, "" ); assert.strictEqual( html, "<tbody></tbody><tfoot></tfoot>" ); -}); +} ); QUnit.test( "Make sure document fragment will be appended to tbody element of table when present", function( assert ) { assert.expect( 1 ); @@ -2634,7 +2633,7 @@ QUnit.test( "Make sure document fragment will be appended to tbody element of ta html = table.innerHTML.toLowerCase().replace( /\s/g, "" ); assert.strictEqual( html, "<tbody><tr><td>test</td></tr></tbody>" ); -}); +} ); QUnit.test( "Make sure col element is appended correctly", function( assert ) { assert.expect( 1 ); @@ -2646,7 +2645,7 @@ QUnit.test( "Make sure col element is appended correctly", function( assert ) { jQuery( "<col width='150'/>" ).prependTo( table ); assert.strictEqual( table.find( "td" ).width(), 150 ); -}); +} ); QUnit.test( "Insert script with data-URI (gh-1887)", 1, function( assert ) { Globals.register( "testFoo" ); @@ -2662,7 +2661,7 @@ QUnit.test( "Insert script with data-URI (gh-1887)", 1, function( assert ) { jQuery( fixture ).append( "<script src=\"data:text/javascript,testFoo = 'foo';\"></script>" ); - setTimeout(function() { + setTimeout( function() { if ( window[ "testSrcFoo" ] === "foo" ) { assert.strictEqual( window[ "testFoo" ], window[ "testSrcFoo" ], "data-URI script executed" ); @@ -2672,4 +2671,4 @@ QUnit.test( "Insert script with data-URI (gh-1887)", 1, function( assert ) { done(); }, 100 ); -}); +} ); diff --git a/test/unit/offset.js b/test/unit/offset.js index 039b8c781..457034662 100644 --- a/test/unit/offset.js +++ b/test/unit/offset.js @@ -1,38 +1,39 @@ -(function() { +( function() { if ( !jQuery.fn.offset ) { return; } var supportsScroll, supportsFixedPosition, - forceScroll = jQuery("<div/>").css({ width: 2000, height: 2000 }), + forceScroll = jQuery( "<div/>" ).css( { width: 2000, height: 2000 } ), checkSupport = function() { + // Only run once checkSupport = false; - var checkFixed = jQuery("<div/>").css({ position: "fixed", top: "20px" }).appendTo("#qunit-fixture"); + var checkFixed = jQuery( "<div/>" ).css( { position: "fixed", top: "20px" } ).appendTo( "#qunit-fixture" ); // Must append to body because #qunit-fixture is hidden and elements inside it don't have a scrollTop - forceScroll.appendTo("body"); + forceScroll.appendTo( "body" ); window.scrollTo( 200, 200 ); supportsScroll = document.documentElement.scrollTop || document.body.scrollTop; forceScroll.detach(); - supportsFixedPosition = checkFixed[0].offsetTop === 20; + supportsFixedPosition = checkFixed[ 0 ].offsetTop === 20; checkFixed.remove(); }; -QUnit.module("offset", { setup: function(){ +QUnit.module( "offset", { setup: function() { if ( typeof checkSupport === "function" ) { checkSupport(); } // Force a scroll value on the main window to ensure incorrect results // if offset is using the scroll offset of the parent window - forceScroll.appendTo("body"); + forceScroll.appendTo( "body" ); window.scrollTo( 1, 1 ); forceScroll.detach(); -}, teardown: moduleTeardown }); +}, teardown: moduleTeardown } ); /* Closure-compiler will roll static methods off of the jQuery object and so they will @@ -41,13 +42,13 @@ QUnit.module("offset", { setup: function(){ the iframe window and the "jQuery" symbol is used to access any static methods. */ -QUnit.test("empty set", function( assert ) { +QUnit.test( "empty set", function( assert ) { assert.expect( 2 ); assert.strictEqual( jQuery().offset(), undefined, "offset() returns undefined for empty set (#11962)" ); assert.strictEqual( jQuery().position(), undefined, "position() returns undefined for empty set (#11962)" ); -}); +} ); -QUnit.test("disconnected element", function( assert ) { +QUnit.test( "disconnected element", function( assert ) { assert.expect( 2 ); var result = jQuery( document.createElement( "div" ) ).offset(); @@ -57,12 +58,12 @@ QUnit.test("disconnected element", function( assert ) { // valid input, but will return zeros for back-compat assert.equal( result.top, 0, "Retrieving offset on disconnected elements returns zeros (gh-2310)" ); assert.equal( result.left, 0, "Retrieving offset on disconnected elements returns zeros (gh-2310)" ); -}); +} ); -QUnit.test("hidden (display: none) element", function( assert ) { +QUnit.test( "hidden (display: none) element", function( assert ) { assert.expect( 2 ); - var node = jQuery("<div style='display: none' />").appendTo("#qunit-fixture"), + var node = jQuery( "<div style='display: none' />" ).appendTo( "#qunit-fixture" ), result = node.offset(); node.remove(); @@ -72,10 +73,10 @@ QUnit.test("hidden (display: none) element", function( assert ) { // valid input, but will return zeros for back-compat assert.equal( result.top, 0, "Retrieving offset on hidden elements returns zeros (gh-2310)" ); assert.equal( result.left, 0, "Retrieving offset on hidden elements returns zeros (gh-2310)" ); -}); +} ); -testIframe("offset/absolute", "absolute", function( $, iframe, document, assert ) { - assert.expect(4); +testIframe( "offset/absolute", "absolute", function( $, iframe, document, assert ) { + assert.expect( 4 ); var doc = iframe.document, tests; @@ -85,23 +86,22 @@ testIframe("offset/absolute", "absolute", function( $, iframe, document, assert { "id": "#absolute-1", "top": 1, "left": 1 } ]; jQuery.each( tests, function() { - assert.equal( jQuery( this["id"], doc ).offset().top, this["top"], "jQuery('" + this["id"] + "').offset().top" ); - assert.equal( jQuery( this["id"], doc ).offset().left, this["left"], "jQuery('" + this["id"] + "').offset().left" ); - }); - + assert.equal( jQuery( this[ "id" ], doc ).offset().top, this[ "top" ], "jQuery('" + this[ "id" ] + "').offset().top" ); + 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 } ]; jQuery.each( tests, function() { - assert.equal( jQuery( this["id"], doc ).position().top, this["top"], "jQuery('" + this["id"] + "').position().top" ); - assert.equal( jQuery( this["id"], doc ).position().left, this["left"], "jQuery('" + this["id"] + "').position().left" ); - }); -}); + assert.equal( jQuery( this[ "id" ], doc ).position().top, this[ "top" ], "jQuery('" + this[ "id" ] + "').position().top" ); + assert.equal( jQuery( this[ "id" ], doc ).position().left, this[ "left" ], "jQuery('" + this[ "id" ] + "').position().left" ); + } ); +} ); -testIframe("offset/absolute", "absolute", function( $, window, document, assert ) { - assert.expect(178); +testIframe( "offset/absolute", "absolute", function( $, window, document, assert ) { + assert.expect( 178 ); var tests, offset; @@ -113,10 +113,9 @@ testIframe("offset/absolute", "absolute", function( $, window, document, assert { "id": "#absolute-2", "top": 20, "left": 20 } ]; jQuery.each( tests, function() { - assert.equal( $( this["id"] ).offset().top, this["top"], "jQuery('" + this["id"] + "').offset().top" ); - assert.equal( $( this["id"] ).offset().left, this["left"], "jQuery('" + this["id"] + "').offset().left" ); - }); - + assert.equal( $( this[ "id" ] ).offset().top, this[ "top" ], "jQuery('" + this[ "id" ] + "').offset().top" ); + assert.equal( $( this[ "id" ] ).offset().left, this[ "left" ], "jQuery('" + this[ "id" ] + "').offset().left" ); + } ); // get position tests = [ @@ -126,16 +125,15 @@ testIframe("offset/absolute", "absolute", function( $, window, document, assert { "id": "#absolute-2", "top": 19, "left": 19 } ]; jQuery.each( tests, function() { - assert.equal( $( this["id"] ).position().top, this["top"], "jQuery('" + this["id"] + "').position().top" ); - assert.equal( $( this["id"] ).position().left, this["left"], "jQuery('" + this["id"] + "').position().left" ); - }); + assert.equal( $( this[ "id" ] ).position().top, this[ "top" ], "jQuery('" + this[ "id" ] + "').position().top" ); + assert.equal( $( this[ "id" ] ).position().left, this[ "left" ], "jQuery('" + this[ "id" ] + "').position().left" ); + } ); // test #5781 - offset = $( "#positionTest" ).offset({ "top": 10, "left": 10 }).offset(); + offset = $( "#positionTest" ).offset( { "top": 10, "left": 10 } ).offset(); 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 }, @@ -156,39 +154,39 @@ testIframe("offset/absolute", "absolute", function( $, window, document, assert { "id": "#absolute-1", "top": 1, "left": 1 } ]; jQuery.each( tests, function() { - $( this["id"] ).offset({ "top": this["top"], "left": this["left"] }); - assert.equal( $( this["id"] ).offset().top, this["top"], "jQuery('" + this["id"] + "').offset({ top: " + this["top"] + " })" ); - assert.equal( $( this["id"] ).offset().left, this["left"], "jQuery('" + this["id"] + "').offset({ left: " + this["left"] + " })" ); + $( this[ "id" ] ).offset( { "top": this[ "top" ], "left": this[ "left" ] } ); + assert.equal( $( this[ "id" ] ).offset().top, this[ "top" ], "jQuery('" + this[ "id" ] + "').offset({ top: " + this[ "top" ] + " })" ); + assert.equal( $( this[ "id" ] ).offset().left, this[ "left" ], "jQuery('" + this[ "id" ] + "').offset({ left: " + this[ "left" ] + " })" ); - var top = this["top"], left = this["left"]; + var top = this[ "top" ], left = this[ "left" ]; - $( this["id"] ).offset(function(i, val){ + $( this[ "id" ] ).offset( function( i, val ) { assert.equal( val.top, top, "Verify incoming top position." ); assert.equal( val.left, left, "Verify incoming top position." ); return { "top": top + 1, "left": left + 1 }; - }); - assert.equal( $( this["id"] ).offset().top, this["top"] + 1, "jQuery('" + this["id"] + "').offset({ top: " + (this["top"] + 1) + " })" ); - assert.equal( $( this["id"] ).offset().left, this["left"] + 1, "jQuery('" + this["id"] + "').offset({ left: " + (this["left"] + 1) + " })" ); - - $( this["id"] ) - .offset({ "left": this["left"] + 2 }) - .offset({ "top": this["top"] + 2 }); - assert.equal( $( this["id"] ).offset().top, this["top"] + 2, "Setting one property at a time." ); - assert.equal( $( this["id"] ).offset().left, this["left"] + 2, "Setting one property at a time." ); - - $( this["id"] ).offset({ "top": this["top"], "left": this["left"], "using": function( props ) { - $( this ).css({ + } ); + assert.equal( $( this[ "id" ] ).offset().top, this[ "top" ] + 1, "jQuery('" + this[ "id" ] + "').offset({ top: " + ( this[ "top" ] + 1 ) + " })" ); + assert.equal( $( this[ "id" ] ).offset().left, this[ "left" ] + 1, "jQuery('" + this[ "id" ] + "').offset({ left: " + ( this[ "left" ] + 1 ) + " })" ); + + $( this[ "id" ] ) + .offset( { "left": this[ "left" ] + 2 } ) + .offset( { "top": this[ "top" ] + 2 } ); + assert.equal( $( this[ "id" ] ).offset().top, this[ "top" ] + 2, "Setting one property at a time." ); + assert.equal( $( this[ "id" ] ).offset().left, this[ "left" ] + 2, "Setting one property at a time." ); + + $( this[ "id" ] ).offset( { "top": this[ "top" ], "left": this[ "left" ], "using": function( props ) { + $( this ).css( { "top": props.top + 1, "left": props.left + 1 - }); - }}); - 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 })" ); - }); -}); + } ); + } } ); + 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 })" ); + } ); +} ); -testIframe("offset/relative", "relative", function( $, window, document, assert ) { - assert.expect(60); +testIframe( "offset/relative", "relative", function( $, window, document, assert ) { + assert.expect( 60 ); // get offset var tests = [ @@ -197,10 +195,9 @@ testIframe("offset/relative", "relative", function( $, window, document, assert { "id": "#relative-2", "top": 142, "left": 27 } ]; jQuery.each( tests, function() { - assert.equal( $( this["id"] ).offset().top, this["top"], "jQuery('" + this["id"] + "').offset().top" ); - assert.equal( $( this["id"] ).offset().left, this["left"], "jQuery('" + this["id"] + "').offset().left" ); - }); - + assert.equal( $( this[ "id" ] ).offset().top, this[ "top" ], "jQuery('" + this[ "id" ] + "').offset().top" ); + assert.equal( $( this[ "id" ] ).offset().left, this[ "left" ], "jQuery('" + this[ "id" ] + "').offset().left" ); + } ); // get position tests = [ @@ -209,10 +206,9 @@ testIframe("offset/relative", "relative", function( $, window, document, assert { "id": "#relative-2", "top": 141, "left": 26 } ]; jQuery.each( tests, function() { - assert.equal( $( this["id"] ).position().top, this["top"], "jQuery('" + this["id"] + "').position().top" ); - assert.equal( $( this["id"] ).position().left, this["left"], "jQuery('" + this["id"] + "').position().left" ); - }); - + assert.equal( $( this[ "id" ] ).position().top, this[ "top" ], "jQuery('" + this[ "id" ] + "').position().top" ); + assert.equal( $( this[ "id" ] ).position().left, this[ "left" ], "jQuery('" + this[ "id" ] + "').position().left" ); + } ); // set offset tests = [ @@ -230,22 +226,22 @@ testIframe("offset/relative", "relative", function( $, window, document, assert { "id": "#relative-1", "top": 7, "left": 7 } ]; jQuery.each( tests, function() { - $( this["id"] ).offset({ "top": this["top"], "left": this["left"] }); - assert.equal( $( this["id"] ).offset().top, this["top"], "jQuery('" + this["id"] + "').offset({ top: " + this["top"] + " })" ); - assert.equal( $( this["id"] ).offset().left, this["left"], "jQuery('" + this["id"] + "').offset({ left: " + this["left"] + " })" ); + $( this[ "id" ] ).offset( { "top": this[ "top" ], "left": this[ "left" ] } ); + assert.equal( $( this[ "id" ] ).offset().top, this[ "top" ], "jQuery('" + this[ "id" ] + "').offset({ top: " + this[ "top" ] + " })" ); + assert.equal( $( this[ "id" ] ).offset().left, this[ "left" ], "jQuery('" + this[ "id" ] + "').offset({ left: " + this[ "left" ] + " })" ); - $( this["id"] ).offset({ "top": this["top"], "left": this["left"], "using": function( props ) { - $( this ).css({ + $( this[ "id" ] ).offset( { "top": this[ "top" ], "left": this[ "left" ], "using": function( props ) { + $( this ).css( { "top": props.top + 1, "left": props.left + 1 - }); - }}); - 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 })" ); - }); -}); - -testIframe("offset/static", "static", 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 })" ); + } ); +} ); + +testIframe( "offset/static", "static", function( $, window, document, assert ) { assert.expect( 80 ); // get offset @@ -256,10 +252,9 @@ testIframe("offset/static", "static", function( $, window, document, assert ) { { "id": "#static-2", "top": 122, left: 7 } ]; jQuery.each( tests, function() { - assert.equal( $( this["id"] ).offset().top, this["top"], "jQuery('" + this["id"] + "').offset().top" ); - assert.equal( $( this["id"] ).offset().left, this["left"], "jQuery('" + this["id"] + "').offset().left" ); - }); - + assert.equal( $( this[ "id" ] ).offset().top, this[ "top" ], "jQuery('" + this[ "id" ] + "').offset().top" ); + assert.equal( $( this[ "id" ] ).offset().left, this[ "left" ], "jQuery('" + this[ "id" ] + "').offset().left" ); + } ); // get position tests = [ @@ -269,10 +264,9 @@ testIframe("offset/static", "static", function( $, window, document, assert ) { { "id": "#static-2", "top": 121, "left": 6 } ]; jQuery.each( tests, function() { - assert.equal( $( this["id"] ).position().top, this["top"], "jQuery('" + this["top"] + "').position().top" ); - assert.equal( $( this["id"] ).position().left, this["left"], "jQuery('" + this["left"] +"').position().left" ); - }); - + assert.equal( $( this[ "id" ] ).position().top, this[ "top" ], "jQuery('" + this[ "top" ] + "').position().top" ); + assert.equal( $( this[ "id" ] ).position().left, this[ "left" ], "jQuery('" + this[ "left" ] + "').position().left" ); + } ); // set offset tests = [ @@ -294,23 +288,23 @@ testIframe("offset/static", "static", function( $, window, document, assert ) { { "id": "#static-1", "top": 7, "left": 7 } ]; jQuery.each( tests, function() { - $( this["id"] ).offset({ "top": this["top"], "left": this["left"] }); - assert.equal( $( this["id"] ).offset().top, this["top"], "jQuery('" + this["id"] + "').offset({ top: " + this["top"] + " })" ); - assert.equal( $( this["id"] ).offset().left, this["left"], "jQuery('" + this["id"] + "').offset({ left: " + this["left"] + " })" ); + $( this[ "id" ] ).offset( { "top": this[ "top" ], "left": this[ "left" ] } ); + assert.equal( $( this[ "id" ] ).offset().top, this[ "top" ], "jQuery('" + this[ "id" ] + "').offset({ top: " + this[ "top" ] + " })" ); + assert.equal( $( this[ "id" ] ).offset().left, this[ "left" ], "jQuery('" + this[ "id" ] + "').offset({ left: " + this[ "left" ] + " })" ); - $( this["id"] ).offset({ "top": this["top"], "left": this["left"], "using": function( props ) { - $( this ).css({ + $( this[ "id" ] ).offset( { "top": this[ "top" ], "left": this[ "left" ], "using": function( props ) { + $( this ).css( { "top": props.top + 1, "left": props.left + 1 - }); - }}); - 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 })" ); - }); -}); + } ); + } } ); + 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 })" ); + } ); +} ); -testIframe("offset/fixed", "fixed", function( $, window, document, assert ) { - assert.expect(34); +testIframe( "offset/fixed", "fixed", function( $, window, document, assert ) { + assert.expect( 34 ); var tests, $noTopLeft; @@ -339,18 +333,19 @@ testIframe("offset/fixed", "fixed", function( $, window, document, assert ) { assert.ok( true, "Browser doesn't support scroll position." ); } else if ( window.supportsFixedPosition ) { - assert.equal( $( this["id"] ).offset().top, this["offsetTop"], "jQuery('" + this["id"] + "').offset().top" ); - assert.equal( $( this["id"] ).position().top, this["positionTop"], "jQuery('" + this["id"] + "').position().top" ); - 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" ); + assert.equal( $( this[ "id" ] ).offset().top, this[ "offsetTop" ], "jQuery('" + this[ "id" ] + "').offset().top" ); + assert.equal( $( this[ "id" ] ).position().top, this[ "positionTop" ], "jQuery('" + this[ "id" ] + "').position().top" ); + 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" ); assert.ok( true, "Fixed position is not supported" ); assert.ok( true, "Fixed position is not supported" ); } - }); + } ); tests = [ { "id": "#fixed-1", "top": 100, "left": 100 }, @@ -363,74 +358,76 @@ testIframe("offset/fixed", "fixed", function( $, window, document, assert ) { jQuery.each( tests, function() { if ( window.supportsFixedPosition ) { - $( this["id"] ).offset({ "top": this["top"], "left": this["left"] }); - assert.equal( $( this["id"] ).offset().top, this["top"], "jQuery('" + this["id"] + "').offset({ top: " + this["top"] + " })" ); - assert.equal( $( this["id"] ).offset().left, this["left"], "jQuery('" + this["id"] + "').offset({ left: " + this["left"] + " })" ); + $( this[ "id" ] ).offset( { "top": this[ "top" ], "left": this[ "left" ] } ); + assert.equal( $( this[ "id" ] ).offset().top, this[ "top" ], "jQuery('" + this[ "id" ] + "').offset({ top: " + this[ "top" ] + " })" ); + assert.equal( $( this[ "id" ] ).offset().left, this[ "left" ], "jQuery('" + this[ "id" ] + "').offset({ left: " + this[ "left" ] + " })" ); - $( this["id"] ).offset({ "top": this["top"], "left": this["left"], "using": function( props ) { - $( this ).css({ + $( this[ "id" ] ).offset( { "top": this[ "top" ], "left": this[ "left" ], "using": function( props ) { + $( this ).css( { "top": props.top + 1, "left": props.left + 1 - }); - }}); - 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 })" ); + } ); + } } ); + 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" ); assert.ok( true, "Fixed position is not supported" ); assert.ok( true, "Fixed position is not supported" ); } - }); + } ); // Bug 8316 - $noTopLeft = $("#fixed-no-top-left"); + $noTopLeft = $( "#fixed-no-top-left" ); if ( window.supportsFixedPosition ) { 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" ); } -}); +} ); -testIframe("offset/table", "table", function( $, window, document, assert ) { - assert.expect(4); +testIframe( "offset/table", "table", function( $, window, document, assert ) { + assert.expect( 4 ); - assert.equal( $("#table-1").offset().top, 6, "jQuery('#table-1').offset().top" ); - assert.equal( $("#table-1").offset().left, 6, "jQuery('#table-1').offset().left" ); + assert.equal( $( "#table-1" ).offset().top, 6, "jQuery('#table-1').offset().top" ); + assert.equal( $( "#table-1" ).offset().left, 6, "jQuery('#table-1').offset().left" ); - assert.equal( $("#th-1").offset().top, 10, "jQuery('#th-1').offset().top" ); - assert.equal( $("#th-1").offset().left, 10, "jQuery('#th-1').offset().left" ); -}); + assert.equal( $( "#th-1" ).offset().top, 10, "jQuery('#th-1').offset().top" ); + assert.equal( $( "#th-1" ).offset().left, 10, "jQuery('#th-1').offset().left" ); +} ); -testIframe("offset/scroll", "scroll", function( $, win, doc, assert ) { +testIframe( "offset/scroll", "scroll", function( $, win, doc, assert ) { assert.expect( 30 ); - assert.equal( $("#scroll-1").offset().top, 7, "jQuery('#scroll-1').offset().top" ); - assert.equal( $("#scroll-1").offset().left, 7, "jQuery('#scroll-1').offset().left" ); + assert.equal( $( "#scroll-1" ).offset().top, 7, "jQuery('#scroll-1').offset().top" ); + assert.equal( $( "#scroll-1" ).offset().left, 7, "jQuery('#scroll-1').offset().left" ); - assert.equal( $("#scroll-1-1").offset().top, 11, "jQuery('#scroll-1-1').offset().top" ); - assert.equal( $("#scroll-1-1").offset().left, 11, "jQuery('#scroll-1-1').offset().left" ); + assert.equal( $( "#scroll-1-1" ).offset().top, 11, "jQuery('#scroll-1-1').offset().top" ); + assert.equal( $( "#scroll-1-1" ).offset().left, 11, "jQuery('#scroll-1-1').offset().left" ); // These tests are solely for master/compat consistency // Retrieving offset on disconnected/hidden elements is not officially // valid input, but will return zeros for back-compat - assert.equal( $("#hidden").offset().top, 0, "Hidden elements do not subtract scroll" ); - assert.equal( $("#hidden").offset().left, 0, "Hidden elements do not subtract scroll" ); + assert.equal( $( "#hidden" ).offset().top, 0, "Hidden elements do not subtract scroll" ); + assert.equal( $( "#hidden" ).offset().left, 0, "Hidden elements do not subtract scroll" ); // scroll offset tests .scrollTop/Left - assert.equal( $("#scroll-1").scrollTop(), 5, "jQuery('#scroll-1').scrollTop()" ); - assert.equal( $("#scroll-1").scrollLeft(), 5, "jQuery('#scroll-1').scrollLeft()" ); + assert.equal( $( "#scroll-1" ).scrollTop(), 5, "jQuery('#scroll-1').scrollTop()" ); + assert.equal( $( "#scroll-1" ).scrollLeft(), 5, "jQuery('#scroll-1').scrollLeft()" ); - assert.equal( $("#scroll-1-1").scrollTop(), 0, "jQuery('#scroll-1-1').scrollTop()" ); - assert.equal( $("#scroll-1-1").scrollLeft(), 0, "jQuery('#scroll-1-1').scrollLeft()" ); + assert.equal( $( "#scroll-1-1" ).scrollTop(), 0, "jQuery('#scroll-1-1').scrollTop()" ); + assert.equal( $( "#scroll-1-1" ).scrollLeft(), 0, "jQuery('#scroll-1-1').scrollLeft()" ); // scroll method chaining - assert.equal( $("#scroll-1").scrollTop(undefined).scrollTop(), 5, ".scrollTop(undefined) is chainable (#5571)" ); - assert.equal( $("#scroll-1").scrollLeft(undefined).scrollLeft(), 5, ".scrollLeft(undefined) is chainable (#5571)" ); + assert.equal( $( "#scroll-1" ).scrollTop( undefined ).scrollTop(), 5, ".scrollTop(undefined) is chainable (#5571)" ); + assert.equal( $( "#scroll-1" ).scrollLeft( undefined ).scrollLeft(), 5, ".scrollLeft(undefined) is chainable (#5571)" ); win.name = "test"; @@ -441,113 +438,113 @@ testIframe("offset/scroll", "scroll", function( $, win, doc, assert ) { assert.ok( true, "Browser doesn't support scroll position." ); assert.ok( true, "Browser doesn't support scroll position." ); } else { - assert.equal( $(win).scrollTop(), 1000, "jQuery(window).scrollTop()" ); - assert.equal( $(win).scrollLeft(), 1000, "jQuery(window).scrollLeft()" ); + assert.equal( $( win ).scrollTop(), 1000, "jQuery(window).scrollTop()" ); + assert.equal( $( win ).scrollLeft(), 1000, "jQuery(window).scrollLeft()" ); - assert.equal( $(win.document).scrollTop(), 1000, "jQuery(document).scrollTop()" ); - assert.equal( $(win.document).scrollLeft(), 1000, "jQuery(document).scrollLeft()" ); + assert.equal( $( win.document ).scrollTop(), 1000, "jQuery(document).scrollTop()" ); + assert.equal( $( win.document ).scrollLeft(), 1000, "jQuery(document).scrollLeft()" ); } // test jQuery using parent window/document // jQuery reference here is in the iframe - window.scrollTo(0,0); - assert.equal( $(window).scrollTop(), 0, "jQuery(window).scrollTop() other window" ); - assert.equal( $(window).scrollLeft(), 0, "jQuery(window).scrollLeft() other window" ); - assert.equal( $(document).scrollTop(), 0, "jQuery(window).scrollTop() other document" ); - assert.equal( $(document).scrollLeft(), 0, "jQuery(window).scrollLeft() other document" ); + window.scrollTo( 0, 0 ); + assert.equal( $( window ).scrollTop(), 0, "jQuery(window).scrollTop() other window" ); + assert.equal( $( window ).scrollLeft(), 0, "jQuery(window).scrollLeft() other window" ); + assert.equal( $( document ).scrollTop(), 0, "jQuery(window).scrollTop() other document" ); + assert.equal( $( document ).scrollLeft(), 0, "jQuery(window).scrollLeft() other document" ); // Tests scrollTop/Left with empty jquery objects - assert.notEqual( $().scrollTop(100), null, "jQuery().scrollTop(100) testing setter on empty jquery object" ); - assert.notEqual( $().scrollLeft(100), null, "jQuery().scrollLeft(100) testing setter on empty jquery object" ); - assert.notEqual( $().scrollTop(null), null, "jQuery().scrollTop(null) testing setter on empty jquery object" ); - assert.notEqual( $().scrollLeft(null), null, "jQuery().scrollLeft(null) testing setter on empty jquery object" ); + assert.notEqual( $().scrollTop( 100 ), null, "jQuery().scrollTop(100) testing setter on empty jquery object" ); + assert.notEqual( $().scrollLeft( 100 ), null, "jQuery().scrollLeft(100) testing setter on empty jquery object" ); + assert.notEqual( $().scrollTop( null ), null, "jQuery().scrollTop(null) testing setter on empty jquery object" ); + assert.notEqual( $().scrollLeft( null ), null, "jQuery().scrollLeft(null) testing setter on empty jquery object" ); assert.strictEqual( $().scrollTop(), null, "jQuery().scrollTop(100) testing setter on empty jquery object" ); assert.strictEqual( $().scrollLeft(), null, "jQuery().scrollLeft(100) testing setter on empty jquery object" ); // Tests position after parent scrolling (#15239) - $("#scroll-1").scrollTop(0); - $("#scroll-1").scrollLeft(0); - assert.equal( $("#scroll-1-1").position().top, 6, "jQuery('#scroll-1-1').position().top unaffected by parent scrolling" ); - assert.equal( $("#scroll-1-1").position().left, 6, "jQuery('#scroll-1-1').position().left unaffected by parent scrolling" ); - - $("#scroll-1").scrollTop(5); - $("#scroll-1").scrollLeft(5); - assert.equal( $("#scroll-1-1").position().top, 6, "jQuery('#scroll-1-1').position().top unaffected by parent scrolling" ); - assert.equal( $("#scroll-1-1").position().left, 6, "jQuery('#scroll-1-1').position().left unaffected by parent scrolling" ); -}); - -testIframe("offset/body", "body", function( $, window, document, assert ) { - assert.expect(4); - - assert.equal( $("body").offset().top, 1, "jQuery('#body').offset().top" ); - assert.equal( $("body").offset().left, 1, "jQuery('#body').offset().left" ); - assert.equal( $("#firstElement").position().left, 5, "$('#firstElement').position().left" ); - assert.equal( $("#firstElement").position().top, 5, "$('#firstElement').position().top" ); -}); - -QUnit.test("chaining", function( assert ) { - assert.expect(3); + $( "#scroll-1" ).scrollTop( 0 ); + $( "#scroll-1" ).scrollLeft( 0 ); + assert.equal( $( "#scroll-1-1" ).position().top, 6, "jQuery('#scroll-1-1').position().top unaffected by parent scrolling" ); + assert.equal( $( "#scroll-1-1" ).position().left, 6, "jQuery('#scroll-1-1').position().left unaffected by parent scrolling" ); + + $( "#scroll-1" ).scrollTop( 5 ); + $( "#scroll-1" ).scrollLeft( 5 ); + assert.equal( $( "#scroll-1-1" ).position().top, 6, "jQuery('#scroll-1-1').position().top unaffected by parent scrolling" ); + assert.equal( $( "#scroll-1-1" ).position().left, 6, "jQuery('#scroll-1-1').position().left unaffected by parent scrolling" ); +} ); + +testIframe( "offset/body", "body", function( $, window, document, assert ) { + assert.expect( 4 ); + + assert.equal( $( "body" ).offset().top, 1, "jQuery('#body').offset().top" ); + assert.equal( $( "body" ).offset().left, 1, "jQuery('#body').offset().left" ); + assert.equal( $( "#firstElement" ).position().left, 5, "$('#firstElement').position().left" ); + assert.equal( $( "#firstElement" ).position().top, 5, "$('#firstElement').position().top" ); +} ); + +QUnit.test( "chaining", function( assert ) { + assert.expect( 3 ); var coords = { "top": 1, "left": 1 }; - assert.equal( jQuery("#absolute-1").offset(coords).jquery, jQuery.fn.jquery, "offset(coords) returns jQuery object" ); - assert.equal( jQuery("#non-existent").offset(coords).jquery, jQuery.fn.jquery, "offset(coords) with empty jQuery set returns jQuery object" ); - assert.equal( jQuery("#absolute-1").offset(undefined).jquery, jQuery.fn.jquery, "offset(undefined) returns jQuery object (#5571)" ); -}); + assert.equal( jQuery( "#absolute-1" ).offset( coords ).jquery, jQuery.fn.jquery, "offset(coords) returns jQuery object" ); + assert.equal( jQuery( "#non-existent" ).offset( coords ).jquery, jQuery.fn.jquery, "offset(coords) with empty jQuery set returns jQuery object" ); + assert.equal( jQuery( "#absolute-1" ).offset( undefined ).jquery, jQuery.fn.jquery, "offset(undefined) returns jQuery object (#5571)" ); +} ); -QUnit.test("offsetParent", function( assert ){ - assert.expect(13); +QUnit.test( "offsetParent", function( assert ) { + assert.expect( 13 ); var body, header, div, area; - body = jQuery("body").offsetParent(); + body = jQuery( "body" ).offsetParent(); assert.equal( body.length, 1, "Only one offsetParent found." ); - assert.equal( body[0], document.documentElement, "The html element is the offsetParent of the body." ); + assert.equal( body[ 0 ], document.documentElement, "The html element is the offsetParent of the body." ); - header = jQuery("#qunit").offsetParent(); + header = jQuery( "#qunit" ).offsetParent(); assert.equal( header.length, 1, "Only one offsetParent found." ); - assert.equal( header[0], document.documentElement, "The html element is the offsetParent of #qunit." ); + assert.equal( header[ 0 ], document.documentElement, "The html element is the offsetParent of #qunit." ); - div = jQuery("#nothiddendivchild").offsetParent(); + div = jQuery( "#nothiddendivchild" ).offsetParent(); assert.equal( div.length, 1, "Only one offsetParent found." ); - assert.equal( div[0], document.getElementById("qunit-fixture"), "The #qunit-fixture is the offsetParent of #nothiddendivchild." ); + assert.equal( div[ 0 ], document.getElementById( "qunit-fixture" ), "The #qunit-fixture is the offsetParent of #nothiddendivchild." ); - jQuery("#nothiddendiv").css("position", "relative"); + jQuery( "#nothiddendiv" ).css( "position", "relative" ); - div = jQuery("#nothiddendivchild").offsetParent(); + div = jQuery( "#nothiddendivchild" ).offsetParent(); assert.equal( div.length, 1, "Only one offsetParent found." ); - assert.equal( div[0], jQuery("#nothiddendiv")[0], "The div is the offsetParent." ); + assert.equal( div[ 0 ], jQuery( "#nothiddendiv" )[ 0 ], "The div is the offsetParent." ); - div = jQuery("body, #nothiddendivchild").offsetParent(); + div = jQuery( "body, #nothiddendivchild" ).offsetParent(); assert.equal( div.length, 2, "Two offsetParent found." ); - assert.equal( div[0], document.documentElement, "The html element is the offsetParent of the body." ); - assert.equal( div[1], jQuery("#nothiddendiv")[0], "The div is the offsetParent." ); + assert.equal( div[ 0 ], document.documentElement, "The html element is the offsetParent of the body." ); + assert.equal( div[ 1 ], jQuery( "#nothiddendiv" )[ 0 ], "The div is the offsetParent." ); - area = jQuery("#imgmap area").offsetParent(); - assert.equal( area[0], document.documentElement, "The html element is the offsetParent of the body." ); + area = jQuery( "#imgmap area" ).offsetParent(); + assert.equal( area[ 0 ], document.documentElement, "The html element is the offsetParent of the body." ); - div = jQuery("<div>").css({ "position": "absolute" }).appendTo("body"); - assert.equal( div.offsetParent()[0], document.documentElement, "Absolutely positioned div returns html as offset parent, see #12139" ); + div = jQuery( "<div>" ).css( { "position": "absolute" } ).appendTo( "body" ); + assert.equal( div.offsetParent()[ 0 ], document.documentElement, "Absolutely positioned div returns html as offset parent, see #12139" ); div.remove(); -}); +} ); -QUnit.test("fractions (see #7730 and #7885)", function( assert ) { - assert.expect(2); +QUnit.test( "fractions (see #7730 and #7885)", function( assert ) { + assert.expect( 2 ); - jQuery("body").append("<div id='fractions'/>"); + jQuery( "body" ).append( "<div id='fractions'/>" ); var result, expected = { "top": 1000, "left": 1000 }, - div = jQuery("#fractions"); + div = jQuery( "#fractions" ); - div.css({ + div.css( { "position": "absolute", "left": "1000.7432222px", "top": "1000.532325px", "width": 100, "height": 100 - }); + } ); - div.offset(expected); + div.offset( expected ); result = div.offset(); @@ -555,9 +552,9 @@ QUnit.test("fractions (see #7730 and #7885)", function( assert ) { assert.equal( result.left, expected.left, "Check left" ); div.remove(); -}); +} ); -QUnit.test("iframe scrollTop/Left (see gh-1945)", function( assert ) { +QUnit.test( "iframe scrollTop/Left (see gh-1945)", function( assert ) { assert.expect( 2 ); var ifDoc = jQuery( "#iframe" )[ 0 ].contentDocument; @@ -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>" ); @@ -582,6 +580,6 @@ QUnit.test("iframe scrollTop/Left (see gh-1945)", function( assert ) { assert.equal( jQuery( ifDoc ).scrollTop(), 200, "$($('#iframe')[0].contentDocument).scrollTop()" ); assert.equal( jQuery( ifDoc ).scrollLeft(), 500, "$($('#iframe')[0].contentDocument).scrollLeft()" ); } -}); +} ); -})(); +} )(); diff --git a/test/unit/queue.js b/test/unit/queue.js index 42192f3d3..780e20058 100644 --- a/test/unit/queue.js +++ b/test/unit/queue.js @@ -1,240 +1,241 @@ -QUnit.module( "queue", { teardown: moduleTeardown }); +QUnit.module( "queue", { teardown: moduleTeardown } ); QUnit.test( "queue() with other types", function( assert ) { assert.expect( 14 ); QUnit.stop(); - var $div = jQuery({}), + var $div = jQuery( {} ), counter = 0; - $div.promise( "foo" ).done(function() { + $div.promise( "foo" ).done( function() { assert.equal( counter, 0, "Deferred for collection with no queue is automatically resolved" ); - }); + } ); $div - .queue("foo",function(){ + .queue( "foo", function() { assert.equal( ++counter, 1, "Dequeuing" ); - jQuery.dequeue(this,"foo"); - }) - .queue("foo",function(){ + jQuery.dequeue( this, "foo" ); + } ) + .queue( "foo", function() { assert.equal( ++counter, 2, "Dequeuing" ); - jQuery(this).dequeue("foo"); - }) - .queue("foo",function(){ + jQuery( this ).dequeue( "foo" ); + } ) + .queue( "foo", function() { assert.equal( ++counter, 3, "Dequeuing" ); - }) - .queue("foo",function(){ + } ) + .queue( "foo", function() { assert.equal( ++counter, 4, "Dequeuing" ); - }); + } ); - $div.promise("foo").done(function() { + $div.promise( "foo" ).done( function() { assert.equal( counter, 4, "Testing previous call to dequeue in deferred" ); QUnit.start(); - }); + } ); - assert.equal( $div.queue("foo").length, 4, "Testing queue length" ); + assert.equal( $div.queue( "foo" ).length, 4, "Testing queue length" ); - assert.equal( $div.queue("foo", undefined).queue("foo").length, 4, ".queue('name',undefined) does nothing but is chainable (#5571)"); + assert.equal( $div.queue( "foo", undefined ).queue( "foo" ).length, 4, ".queue('name',undefined) does nothing but is chainable (#5571)" ); - $div.dequeue("foo"); + $div.dequeue( "foo" ); assert.equal( counter, 3, "Testing previous call to dequeue" ); - assert.equal( $div.queue("foo").length, 1, "Testing queue length" ); + assert.equal( $div.queue( "foo" ).length, 1, "Testing queue length" ); - $div.dequeue("foo"); + $div.dequeue( "foo" ); assert.equal( counter, 4, "Testing previous call to dequeue" ); - assert.equal( $div.queue("foo").length, 0, "Testing queue length" ); + assert.equal( $div.queue( "foo" ).length, 0, "Testing queue length" ); - $div.dequeue("foo"); + $div.dequeue( "foo" ); assert.equal( counter, 4, "Testing previous call to dequeue" ); - assert.equal( $div.queue("foo").length, 0, "Testing queue length" ); + assert.equal( $div.queue( "foo" ).length, 0, "Testing queue length" ); -}); +} ); -QUnit.test("queue(name) passes in the next item in the queue as a parameter", function( assert ) { - assert.expect(2); +QUnit.test( "queue(name) passes in the next item in the queue as a parameter", function( assert ) { + assert.expect( 2 ); - var div = jQuery({}), + var div = jQuery( {} ), counter = 0; - div.queue("foo", function(next) { - assert.equal(++counter, 1, "Dequeueing"); + div.queue( "foo", function( next ) { + assert.equal( ++counter, 1, "Dequeueing" ); next(); - }).queue("foo", function(next) { - assert.equal(++counter, 2, "Next was called"); + } ).queue( "foo", function( next ) { + assert.equal( ++counter, 2, "Next was called" ); next(); - }).queue("bar", function() { - assert.equal(++counter, 3, "Other queues are not triggered by next()"); - }); + } ).queue( "bar", function() { + assert.equal( ++counter, 3, "Other queues are not triggered by next()" ); + } ); - div.dequeue("foo"); -}); + div.dequeue( "foo" ); +} ); -QUnit.test("queue() passes in the next item in the queue as a parameter to fx queues", function( assert ) { - assert.expect(3); +QUnit.test( "queue() passes in the next item in the queue as a parameter to fx queues", function( assert ) { + assert.expect( 3 ); QUnit.stop(); - var div = jQuery({}), + var div = jQuery( {} ), counter = 0; - div.queue(function(next) { - assert.equal(++counter, 1, "Dequeueing"); - setTimeout(function() { next(); }, 500); - }).queue(function(next) { - assert.equal(++counter, 2, "Next was called"); + div.queue( function( next ) { + assert.equal( ++counter, 1, "Dequeueing" ); + setTimeout( function() { next(); }, 500 ); + } ).queue( function( next ) { + assert.equal( ++counter, 2, "Next was called" ); next(); - }).queue("bar", function() { - assert.equal(++counter, 3, "Other queues are not triggered by next()"); - }); + } ).queue( "bar", function() { + assert.equal( ++counter, 3, "Other queues are not triggered by next()" ); + } ); - jQuery.when( div.promise("fx"), div ).done(function() { - assert.equal(counter, 2, "Deferreds resolved"); + jQuery.when( div.promise( "fx" ), div ).done( function() { + assert.equal( counter, 2, "Deferreds resolved" ); QUnit.start(); - }); -}); + } ); +} ); -QUnit.test("callbacks keep their place in the queue", function( assert ) { - assert.expect(5); +QUnit.test( "callbacks keep their place in the queue", function( assert ) { + assert.expect( 5 ); QUnit.stop(); - var div = jQuery("<div>"), + var div = jQuery( "<div>" ), counter = 0; - div.queue(function( next ) { + div.queue( function( next ) { assert.equal( ++counter, 1, "Queue/callback order: first called" ); setTimeout( next, 200 ); - }).delay( 100 ).queue(function( next ) { + } ).delay( 100 ).queue( function( next ) { assert.equal( ++counter, 2, "Queue/callback order: second called" ); - jQuery( this ).delay( 100 ).queue(function( next ) { + jQuery( this ).delay( 100 ).queue( function( next ) { assert.equal( ++counter, 4, "Queue/callback order: fourth called" ); next(); - }); + } ); next(); - }).queue(function( next ) { + } ).queue( function( next ) { assert.equal( ++counter, 3, "Queue/callback order: third called" ); next(); - }); + } ); - div.promise("fx").done(function() { - assert.equal(counter, 4, "Deferreds resolved"); + div.promise( "fx" ).done( function() { + assert.equal( counter, 4, "Deferreds resolved" ); QUnit.start(); - }); -}); + } ); +} ); QUnit.test( "jQuery.queue should return array while manipulating the queue", function( assert ) { assert.expect( 1 ); - var div = document.createElement("div"); + var div = document.createElement( "div" ); assert.ok( jQuery.isArray( jQuery.queue( div, "fx", jQuery.noop ) ), "jQuery.queue should return an array while manipulating the queue" ); -}); +} ); -QUnit.test("delay()", function( assert ) { - assert.expect(2); +QUnit.test( "delay()", function( assert ) { + assert.expect( 2 ); QUnit.stop(); - var foo = jQuery({}), run = 0; + var foo = jQuery( {} ), run = 0; - foo.delay(100).queue(function(){ + foo.delay( 100 ).queue( function() { run = 1; assert.ok( true, "The function was dequeued." ); QUnit.start(); - }); + } ); assert.equal( run, 0, "The delay delayed the next function from running." ); -}); +} ); -QUnit.test("clearQueue(name) clears the queue", function( assert ) { - assert.expect(2); +QUnit.test( "clearQueue(name) clears the queue", function( assert ) { + assert.expect( 2 ); QUnit.stop(); - var div = jQuery({}), + var div = jQuery( {} ), counter = 0; - div.queue("foo", function( next ) { + div.queue( "foo", function( next ) { counter++; - jQuery(this).clearQueue("foo"); + jQuery( this ).clearQueue( "foo" ); next(); - }).queue("foo", function() { + } ).queue( "foo", function() { counter++; - }); + } ); - div.promise("foo").done(function() { + div.promise( "foo" ).done( function() { assert.ok( true, "dequeue resolves the deferred" ); QUnit.start(); - }); + } ); - div.dequeue("foo"); + div.dequeue( "foo" ); - assert.equal(counter, 1, "the queue was cleared"); -}); + assert.equal( counter, 1, "the queue was cleared" ); +} ); -QUnit.test("clearQueue() clears the fx queue", function( assert ) { - assert.expect(1); +QUnit.test( "clearQueue() clears the fx queue", function( assert ) { + assert.expect( 1 ); - var div = jQuery({}), + var div = jQuery( {} ), counter = 0; - div.queue(function( next ) { + div.queue( function( next ) { counter++; var self = this; - setTimeout(function() { jQuery(self).clearQueue(); next(); }, 50); - }).queue(function() { + setTimeout( function() { jQuery( self ).clearQueue(); next(); }, 50 ); + } ).queue( function() { counter++; - }); + } ); - assert.equal(counter, 1, "the queue was cleared"); + assert.equal( counter, 1, "the queue was cleared" ); div.removeData(); -}); +} ); QUnit.asyncTest( "fn.promise() - called when fx queue is empty", 3, function( assert ) { var foo = jQuery( "#foo" ).clone().addBack(), promised = false; foo.queue( function( next ) { + // called twice! assert.ok( !promised, "Promised hasn't been called" ); setTimeout( next, 10 ); - }); + } ); foo.promise().done( function() { assert.ok( promised = true, "Promised" ); QUnit.start(); - }); -}); + } ); +} ); QUnit.asyncTest( "fn.promise( \"queue\" ) - called whenever last queue function is dequeued", 5, function( assert ) { var foo = jQuery( "#foo" ), test; foo.promise( "queue" ).done( function() { assert.strictEqual( test, undefined, "called immediately when queue was already empty" ); - }); + } ); test = 1; foo.queue( "queue", function( next ) { assert.strictEqual( test++, 1, "step one" ); setTimeout( next, 0 ); - }).queue( "queue", function( next ) { + } ).queue( "queue", function( next ) { assert.strictEqual( test++, 2, "step two" ); setTimeout( function() { next(); assert.strictEqual( test++, 4, "step four" ); QUnit.start(); }, 10 ); - }).promise( "queue" ).done( function() { + } ).promise( "queue" ).done( function() { assert.strictEqual( test++, 3, "step three" ); - }); + } ); foo.dequeue( "queue" ); -}); +} ); QUnit.asyncTest( "fn.promise( \"queue\" ) - waits for animation to complete before resolving", 2, function( assert ) { var foo = jQuery( "#foo" ), test = 1; - foo.animate({ + foo.animate( { top: 100 }, { duration: 1, @@ -242,43 +243,42 @@ QUnit.asyncTest( "fn.promise( \"queue\" ) - waits for animation to complete befo complete: function() { assert.strictEqual( test++, 1, "step one" ); } - }).dequeue( "queue" ); + } ).dequeue( "queue" ); foo.promise( "queue" ).done( function() { assert.strictEqual( test++, 2, "step two" ); QUnit.start(); - }); + } ); -}); +} ); QUnit.test( ".promise(obj)", function( assert ) { - assert.expect(2); + assert.expect( 2 ); var obj = {}, promise = jQuery( "#foo" ).promise( "promise", obj ); assert.ok( jQuery.isFunction( promise.promise ), ".promise(type, obj) returns a promise" ); assert.strictEqual( promise, obj, ".promise(type, obj) returns obj" ); -}); - +} ); if ( jQuery.fn.stop ) { - QUnit.test("delay() can be stopped", function( assert ) { + QUnit.test( "delay() can be stopped", function( assert ) { assert.expect( 3 ); QUnit.stop(); var done = {}; - jQuery({}) + jQuery( {} ) .queue( "alternate", function( next ) { done.alt1 = true; assert.ok( true, "This first function was dequeued" ); next(); - }) + } ) .delay( 1000, "alternate" ) .queue( "alternate", function() { done.alt2 = true; assert.ok( true, "The function was dequeued immediately, the delay was stopped" ); - }) + } ) .dequeue( "alternate" ) // stop( "alternate", false ) will NOT clear the queue, so it should automatically dequeue the next @@ -286,20 +286,20 @@ if ( jQuery.fn.stop ) { // this test .delay( 1 ) - .queue(function() { + .queue( function() { done.default1 = true; assert.ok( false, "This queue should never run" ); - }) + } ) // stop( clearQueue ) should clear the queue .stop( true, false ); assert.deepEqual( done, { alt1: true, alt2: true }, "Queue ran the proper functions" ); - setTimeout(function() { + setTimeout( function() { QUnit.start(); }, 1500 ); - }); + } ); QUnit.asyncTest( "queue stop hooks", 2, function( assert ) { var foo = jQuery( "#foo" ); @@ -308,7 +308,7 @@ if ( jQuery.fn.stop ) { hooks.stop = function( gotoEnd ) { assert.equal( !!gotoEnd, false, "Stopped without gotoEnd" ); }; - }); + } ); foo.stop(); foo.queue( function( next, hooks ) { @@ -316,9 +316,9 @@ if ( jQuery.fn.stop ) { assert.equal( gotoEnd, true, "Stopped with gotoEnd" ); QUnit.start(); }; - }); + } ); foo.stop( false, true ); - }); + } ); } // if ( jQuery.fn.stop ) diff --git a/test/unit/ready.js b/test/unit/ready.js index d058466b2..6272dbdd4 100644 --- a/test/unit/ready.js +++ b/test/unit/ready.js @@ -1,6 +1,6 @@ QUnit.module( "ready" ); -(function() { +( function() { var notYetReady, noEarlyExecution, order = [], args = {}; @@ -12,7 +12,7 @@ QUnit.module( "ready" ); assert.equal( notYetReady, true, "jQuery.isReady should not be true before DOM ready" ); assert.equal( jQuery.isReady, true, "jQuery.isReady should be true once DOM is ready" ); - }); + } ); // Create an event handler. function makeHandler( testId ) { @@ -22,7 +22,7 @@ QUnit.module( "ready" ); // the correct arg is being passed into the event handler. return function( arg ) { order.push( testId ); - args[testId] = arg; + args[ testId ] = arg; }; } @@ -65,6 +65,6 @@ QUnit.module( "ready" ); assert.equal( order.pop(), "h", "Event handler should execute immediately" ); assert.equal( args.h, jQuery, "Argument passed to fn in jQuery(document).ready( fn ) should be jQuery" ); - }); + } ); -})(); +} )(); diff --git a/test/unit/selector.js b/test/unit/selector.js index e7f3d85ae..8d18506fe 100644 --- a/test/unit/selector.js +++ b/test/unit/selector.js @@ -1,93 +1,93 @@ -QUnit.module("selector", { teardown: moduleTeardown }); +QUnit.module( "selector", { teardown: moduleTeardown } ); /** * This test page is for selector tests that require jQuery in order to do the selection */ -QUnit.test("element - jQuery only", function( assert ) { +QUnit.test( "element - jQuery only", function( assert ) { assert.expect( 7 ); - var fixture = document.getElementById("qunit-fixture"); + var fixture = document.getElementById( "qunit-fixture" ); - assert.deepEqual( jQuery("p", fixture).get(), q("firstp","ap","sndp","en","sap","first"), "Finding elements with a Node context." ); - assert.deepEqual( jQuery("p", "#qunit-fixture").get(), q("firstp","ap","sndp","en","sap","first"), "Finding elements with a selector context." ); - assert.deepEqual( jQuery("p", jQuery("#qunit-fixture")).get(), q("firstp","ap","sndp","en","sap","first"), "Finding elements with a jQuery object context." ); - assert.deepEqual( jQuery("#qunit-fixture").find("p").get(), q("firstp","ap","sndp","en","sap","first"), "Finding elements with a context via .find()." ); + assert.deepEqual( jQuery( "p", fixture ).get(), q( "firstp", "ap", "sndp", "en", "sap", "first" ), "Finding elements with a Node context." ); + assert.deepEqual( jQuery( "p", "#qunit-fixture" ).get(), q( "firstp", "ap", "sndp", "en", "sap", "first" ), "Finding elements with a selector context." ); + assert.deepEqual( jQuery( "p", jQuery( "#qunit-fixture" ) ).get(), q( "firstp", "ap", "sndp", "en", "sap", "first" ), "Finding elements with a jQuery object context." ); + assert.deepEqual( jQuery( "#qunit-fixture" ).find( "p" ).get(), q( "firstp", "ap", "sndp", "en", "sap", "first" ), "Finding elements with a context via .find()." ); - assert.ok( jQuery("#length").length, "<input name=\"length\"> cannot be found under IE, see #945" ); - assert.ok( jQuery("#lengthtest input").length, "<input name=\"length\"> cannot be found under IE, see #945" ); + assert.ok( jQuery( "#length" ).length, "<input name=\"length\"> cannot be found under IE, see #945" ); + assert.ok( jQuery( "#lengthtest input" ).length, "<input name=\"length\"> cannot be found under IE, see #945" ); // #7533 - assert.equal( jQuery("<div id=\"A'B~C.D[E]\"><p>foo</p></div>").find("p").length, 1, "Find where context root is a node and has an ID with CSS3 meta characters" ); -}); + assert.equal( jQuery( "<div id=\"A'B~C.D[E]\"><p>foo</p></div>" ).find( "p" ).length, 1, "Find where context root is a node and has an ID with CSS3 meta characters" ); +} ); -QUnit.test("id", function( assert ) { +QUnit.test( "id", function( assert ) { assert.expect( 26 ); var a; - t( "ID Selector", "#body", ["body"] ); - t( "ID Selector w/ Element", "body#body", ["body"] ); + t( "ID Selector", "#body", [ "body" ] ); + t( "ID Selector w/ Element", "body#body", [ "body" ] ); t( "ID Selector w/ Element", "ul#first", [] ); - t( "ID selector with existing ID descendant", "#firstp #simon1", ["simon1"] ); + t( "ID selector with existing ID descendant", "#firstp #simon1", [ "simon1" ] ); t( "ID selector with non-existent descendant", "#firstp #foobar", [] ); - t( "ID selector using UTF8", "#台北Táiběi", ["台北Táiběi"] ); - t( "Multiple ID selectors using UTF8", "#台北Táiběi, #台北", ["台北Táiběi","台北"] ); - t( "Descendant ID selector using UTF8", "div #台北", ["台北"] ); - t( "Child ID selector using UTF8", "form > #台北", ["台北"] ); - - t( "Escaped ID", "#foo\\:bar", ["foo:bar"] ); - t( "Escaped ID", "#test\\.foo\\[5\\]bar", ["test.foo[5]bar"] ); - t( "Descendant escaped ID", "div #foo\\:bar", ["foo:bar"] ); - t( "Descendant escaped ID", "div #test\\.foo\\[5\\]bar", ["test.foo[5]bar"] ); - t( "Child escaped ID", "form > #foo\\:bar", ["foo:bar"] ); - t( "Child escaped ID", "form > #test\\.foo\\[5\\]bar", ["test.foo[5]bar"] ); - - t( "ID Selector, child ID present", "#form > #radio1", ["radio1"] ); // bug #267 + t( "ID selector using UTF8", "#台北Táiběi", [ "台北Táiběi" ] ); + t( "Multiple ID selectors using UTF8", "#台北Táiběi, #台北", [ "台北Táiběi","台北" ] ); + t( "Descendant ID selector using UTF8", "div #台北", [ "台北" ] ); + t( "Child ID selector using UTF8", "form > #台北", [ "台北" ] ); + + t( "Escaped ID", "#foo\\:bar", [ "foo:bar" ] ); + t( "Escaped ID", "#test\\.foo\\[5\\]bar", [ "test.foo[5]bar" ] ); + t( "Descendant escaped ID", "div #foo\\:bar", [ "foo:bar" ] ); + t( "Descendant escaped ID", "div #test\\.foo\\[5\\]bar", [ "test.foo[5]bar" ] ); + t( "Child escaped ID", "form > #foo\\:bar", [ "foo:bar" ] ); + t( "Child escaped ID", "form > #test\\.foo\\[5\\]bar", [ "test.foo[5]bar" ] ); + + t( "ID Selector, child ID present", "#form > #radio1", [ "radio1" ] ); // bug #267 t( "ID Selector, not an ancestor ID", "#form #first", [] ); t( "ID Selector, not a child ID", "#form > #option1a", [] ); - t( "All Children of ID", "#foo > *", ["sndp", "en", "sap"] ); + t( "All Children of ID", "#foo > *", [ "sndp", "en", "sap" ] ); t( "All Children of ID with no children", "#firstUL > *", [] ); - a = jQuery("<a id='backslash\\foo'></a>").appendTo("#qunit-fixture"); - t( "ID Selector contains backslash", "#backslash\\\\foo", ["backslash\\foo"] ); + a = jQuery( "<a id='backslash\\foo'></a>" ).appendTo( "#qunit-fixture" ); + t( "ID Selector contains backslash", "#backslash\\\\foo", [ "backslash\\foo" ] ); - t( "ID Selector on Form with an input that has a name of 'id'", "#lengthtest", ["lengthtest"] ); + t( "ID Selector on Form with an input that has a name of 'id'", "#lengthtest", [ "lengthtest" ] ); t( "ID selector with non-existent ancestor", "#asdfasdf #foobar", [] ); // bug #986 - t( "Underscore ID", "#types_all", ["types_all"] ); - t( "Dash ID", "#qunit-fixture", ["qunit-fixture"] ); + t( "Underscore ID", "#types_all", [ "types_all" ] ); + t( "Dash ID", "#qunit-fixture", [ "qunit-fixture" ] ); - t( "ID with weird characters in it", "#name\\+value", ["name+value"] ); -}); + t( "ID with weird characters in it", "#name\\+value", [ "name+value" ] ); +} ); -QUnit.test("class - jQuery only", function( assert ) { +QUnit.test( "class - jQuery only", function( assert ) { assert.expect( 4 ); - assert.deepEqual( jQuery(".blog", document.getElementsByTagName("p")).get(), q("mark", "simon"), "Finding elements with a context." ); - assert.deepEqual( jQuery(".blog", "p").get(), q("mark", "simon"), "Finding elements with a context." ); - assert.deepEqual( jQuery(".blog", jQuery("p")).get(), q("mark", "simon"), "Finding elements with a context." ); - assert.deepEqual( jQuery("p").find(".blog").get(), q("mark", "simon"), "Finding elements with a context." ); -}); + assert.deepEqual( jQuery( ".blog", document.getElementsByTagName( "p" ) ).get(), q( "mark", "simon" ), "Finding elements with a context." ); + assert.deepEqual( jQuery( ".blog", "p" ).get(), q( "mark", "simon" ), "Finding elements with a context." ); + assert.deepEqual( jQuery( ".blog", jQuery( "p" ) ).get(), q( "mark", "simon" ), "Finding elements with a context." ); + assert.deepEqual( jQuery( "p" ).find( ".blog" ).get(), q( "mark", "simon" ), "Finding elements with a context." ); +} ); -QUnit.test("name", function( assert ) { +QUnit.test( "name", function( assert ) { assert.expect( 5 ); var form; - t( "Name selector", "input[name=action]", ["text1"] ); - t( "Name selector with single quotes", "input[name='action']", ["text1"] ); - t( "Name selector with double quotes", "input[name=\"action\"]", ["text1"] ); + t( "Name selector", "input[name=action]", [ "text1" ] ); + t( "Name selector with single quotes", "input[name='action']", [ "text1" ] ); + t( "Name selector with double quotes", "input[name=\"action\"]", [ "text1" ] ); - t( "Name selector for grouped input", "input[name='types[]']", ["types_all", "types_anime", "types_movie"] ); + t( "Name selector for grouped input", "input[name='types[]']", [ "types_all", "types_anime", "types_movie" ] ); - form = jQuery("<form><input name='id'/></form>").appendTo("body"); - assert.equal( jQuery("input", form[0]).length, 1, "Make sure that rooted queries on forms (with possible expandos) work." ); + form = jQuery( "<form><input name='id'/></form>" ).appendTo( "body" ); + assert.equal( jQuery( "input", form[ 0 ] ).length, 1, "Make sure that rooted queries on forms (with possible expandos) work." ); form.remove(); -}); +} ); QUnit.test( "selectors with comma", function( assert ) { assert.expect( 4 ); @@ -98,108 +98,108 @@ QUnit.test( "selectors with comma", function( assert ) { assert.equal( fixture.find( "h2, div p" ).filter( "h2" ).length, 1, "has to find one <h2>" ); assert.equal( fixture.find( "h2 , div p" ).filter( "p" ).length, 2, "has to find two <p>" ); assert.equal( fixture.find( "h2 , div p" ).filter( "h2" ).length, 1, "has to find one <h2>" ); -}); +} ); QUnit.test( "child and adjacent", function( assert ) { assert.expect( 27 ); var nothiddendiv; - t( "Child", "p > a", ["simon1","google","groups","mark","yahoo","simon"] ); - t( "Child", "p> a", ["simon1","google","groups","mark","yahoo","simon"] ); - t( "Child", "p >a", ["simon1","google","groups","mark","yahoo","simon"] ); - t( "Child", "p>a", ["simon1","google","groups","mark","yahoo","simon"] ); - t( "Child w/ Class", "p > a.blog", ["mark","simon"] ); - t( "All Children", "code > *", ["anchor1","anchor2"] ); - t( "All Grandchildren", "p > * > *", ["anchor1","anchor2"] ); - t( "Adjacent", "p + p", ["ap","en","sap"] ); - t( "Adjacent", "p#firstp + p", ["ap"] ); - t( "Adjacent", "p[lang=en] + p", ["sap"] ); - t( "Adjacent", "a.GROUPS + code + a", ["mark"] ); - t( "Element Preceded By", "#groups ~ a", ["mark"] ); - t( "Element Preceded By", "#length ~ input", ["idTest"] ); - t( "Element Preceded By", "#siblingfirst ~ em", ["siblingnext", "siblingthird"] ); - t( "Element Preceded By (multiple)", "#siblingTest em ~ em ~ em ~ span", ["siblingspan"] ); - t( "Element Preceded By, Containing", "#liveHandlerOrder ~ div em:contains('1')", ["siblingfirst"] ); - - t( "Multiple combinators selects all levels", "#siblingTest em *", ["siblingchild", "siblinggrandchild", "siblinggreatgrandchild"] ); - t( "Multiple combinators selects all levels", "#siblingTest > em *", ["siblingchild", "siblinggrandchild", "siblinggreatgrandchild"] ); - t( "Multiple sibling combinators doesn't miss general siblings", "#siblingTest > em:first-child + em ~ span", ["siblingspan"] ); + t( "Child", "p > a", [ "simon1","google","groups","mark","yahoo","simon" ] ); + t( "Child", "p> a", [ "simon1","google","groups","mark","yahoo","simon" ] ); + t( "Child", "p >a", [ "simon1","google","groups","mark","yahoo","simon" ] ); + t( "Child", "p>a", [ "simon1","google","groups","mark","yahoo","simon" ] ); + t( "Child w/ Class", "p > a.blog", [ "mark","simon" ] ); + t( "All Children", "code > *", [ "anchor1","anchor2" ] ); + t( "All Grandchildren", "p > * > *", [ "anchor1","anchor2" ] ); + t( "Adjacent", "p + p", [ "ap","en","sap" ] ); + t( "Adjacent", "p#firstp + p", [ "ap" ] ); + t( "Adjacent", "p[lang=en] + p", [ "sap" ] ); + t( "Adjacent", "a.GROUPS + code + a", [ "mark" ] ); + t( "Element Preceded By", "#groups ~ a", [ "mark" ] ); + t( "Element Preceded By", "#length ~ input", [ "idTest" ] ); + t( "Element Preceded By", "#siblingfirst ~ em", [ "siblingnext", "siblingthird" ] ); + t( "Element Preceded By (multiple)", "#siblingTest em ~ em ~ em ~ span", [ "siblingspan" ] ); + t( "Element Preceded By, Containing", "#liveHandlerOrder ~ div em:contains('1')", [ "siblingfirst" ] ); + + t( "Multiple combinators selects all levels", "#siblingTest em *", [ "siblingchild", "siblinggrandchild", "siblinggreatgrandchild" ] ); + t( "Multiple combinators selects all levels", "#siblingTest > em *", [ "siblingchild", "siblinggrandchild", "siblinggreatgrandchild" ] ); + t( "Multiple sibling combinators doesn't miss general siblings", "#siblingTest > em:first-child + em ~ span", [ "siblingspan" ] ); t( "Combinators are not skipped when mixing general and specific", "#siblingTest > em:contains('x') + em ~ span", [] ); - assert.equal( jQuery("#listWithTabIndex").length, 1, "Parent div for next test is found via ID (#8310)" ); - assert.equal( jQuery("#listWithTabIndex li:eq(2) ~ li").length, 1, "Find by general sibling combinator (#8310)" ); - assert.equal( jQuery("#__sizzle__").length, 0, "Make sure the temporary id assigned by sizzle is cleared out (#8310)" ); - assert.equal( jQuery("#listWithTabIndex").length, 1, "Parent div for previous test is still found via ID (#8310)" ); + assert.equal( jQuery( "#listWithTabIndex" ).length, 1, "Parent div for next test is found via ID (#8310)" ); + assert.equal( jQuery( "#listWithTabIndex li:eq(2) ~ li" ).length, 1, "Find by general sibling combinator (#8310)" ); + assert.equal( jQuery( "#__sizzle__" ).length, 0, "Make sure the temporary id assigned by sizzle is cleared out (#8310)" ); + assert.equal( jQuery( "#listWithTabIndex" ).length, 1, "Parent div for previous test is still found via ID (#8310)" ); t( "Verify deep class selector", "div.blah > p > a", [] ); t( "No element deep selector", "div.foo > span > a", [] ); - nothiddendiv = document.getElementById("nothiddendiv"); + nothiddendiv = document.getElementById( "nothiddendiv" ); t( "Non-existent ancestors", ".fototab > .thumbnails > a", [] ); -}); +} ); -QUnit.test("attributes", function( assert ) { +QUnit.test( "attributes", function( assert ) { assert.expect( 54 ); var attrbad, div, withScript; - t( "Find elements with a tabindex attribute", "[tabindex]", ["listWithTabIndex", "foodWithNegativeTabIndex", "linkWithTabIndex", "linkWithNegativeTabIndex", "linkWithNoHrefWithTabIndex", "linkWithNoHrefWithNegativeTabIndex"] ); + t( "Find elements with a tabindex attribute", "[tabindex]", [ "listWithTabIndex", "foodWithNegativeTabIndex", "linkWithTabIndex", "linkWithNegativeTabIndex", "linkWithNoHrefWithTabIndex", "linkWithNoHrefWithNegativeTabIndex" ] ); - t( "Attribute Exists", "#qunit-fixture a[title]", ["google"] ); - t( "Attribute Exists (case-insensitive)", "#qunit-fixture a[TITLE]", ["google"] ); - t( "Attribute Exists", "#qunit-fixture *[title]", ["google"] ); - t( "Attribute Exists", "#qunit-fixture [title]", ["google"] ); - t( "Attribute Exists", "#qunit-fixture a[ title ]", ["google"] ); + t( "Attribute Exists", "#qunit-fixture a[title]", [ "google" ] ); + t( "Attribute Exists (case-insensitive)", "#qunit-fixture a[TITLE]", [ "google" ] ); + t( "Attribute Exists", "#qunit-fixture *[title]", [ "google" ] ); + t( "Attribute Exists", "#qunit-fixture [title]", [ "google" ] ); + t( "Attribute Exists", "#qunit-fixture a[ title ]", [ "google" ] ); - t( "Boolean attribute exists", "#select2 option[selected]", ["option2d"]); - t( "Boolean attribute equals", "#select2 option[selected='selected']", ["option2d"]); + t( "Boolean attribute exists", "#select2 option[selected]", [ "option2d" ] ); + t( "Boolean attribute equals", "#select2 option[selected='selected']", [ "option2d" ] ); - t( "Attribute Equals", "#qunit-fixture a[rel='bookmark']", ["simon1"] ); - t( "Attribute Equals", "#qunit-fixture a[rel='bookmark']", ["simon1"] ); - t( "Attribute Equals", "#qunit-fixture a[rel=bookmark]", ["simon1"] ); - t( "Attribute Equals", "#qunit-fixture a[href='http://www.google.com/']", ["google"] ); - t( "Attribute Equals", "#qunit-fixture a[ rel = 'bookmark' ]", ["simon1"] ); - t( "Attribute Equals Number", "#qunit-fixture option[value=1]", ["option1b","option2b","option3b","option4b","option5c"] ); - t( "Attribute Equals Number", "#qunit-fixture li[tabIndex=-1]", ["foodWithNegativeTabIndex"] ); + t( "Attribute Equals", "#qunit-fixture a[rel='bookmark']", [ "simon1" ] ); + t( "Attribute Equals", "#qunit-fixture a[rel='bookmark']", [ "simon1" ] ); + t( "Attribute Equals", "#qunit-fixture a[rel=bookmark]", [ "simon1" ] ); + t( "Attribute Equals", "#qunit-fixture a[href='http://www.google.com/']", [ "google" ] ); + t( "Attribute Equals", "#qunit-fixture a[ rel = 'bookmark' ]", [ "simon1" ] ); + t( "Attribute Equals Number", "#qunit-fixture option[value=1]", [ "option1b","option2b","option3b","option4b","option5c" ] ); + t( "Attribute Equals Number", "#qunit-fixture li[tabIndex=-1]", [ "foodWithNegativeTabIndex" ] ); - document.getElementById("anchor2").href = "#2"; - t( "href Attribute", "p a[href^='#']", ["anchor2"] ); - t( "href Attribute", "p a[href*='#']", ["simon1", "anchor2"] ); + document.getElementById( "anchor2" ).href = "#2"; + t( "href Attribute", "p a[href^='#']", [ "anchor2" ] ); + t( "href Attribute", "p a[href*='#']", [ "simon1", "anchor2" ] ); - t( "for Attribute", "form label[for]", ["label-for"] ); - t( "for Attribute in form", "#form [for=action]", ["label-for"] ); + t( "for Attribute", "form label[for]", [ "label-for" ] ); + t( "for Attribute in form", "#form [for=action]", [ "label-for" ] ); - t( "Attribute containing []", "input[name^='foo[']", ["hidden2"] ); - t( "Attribute containing []", "input[name^='foo[bar]']", ["hidden2"] ); - t( "Attribute containing []", "input[name*='[bar]']", ["hidden2"] ); - t( "Attribute containing []", "input[name$='bar]']", ["hidden2"] ); - t( "Attribute containing []", "input[name$='[bar]']", ["hidden2"] ); - t( "Attribute containing []", "input[name$='foo[bar]']", ["hidden2"] ); - t( "Attribute containing []", "input[name*='foo[bar]']", ["hidden2"] ); + t( "Attribute containing []", "input[name^='foo[']", [ "hidden2" ] ); + t( "Attribute containing []", "input[name^='foo[bar]']", [ "hidden2" ] ); + t( "Attribute containing []", "input[name*='[bar]']", [ "hidden2" ] ); + t( "Attribute containing []", "input[name$='bar]']", [ "hidden2" ] ); + t( "Attribute containing []", "input[name$='[bar]']", [ "hidden2" ] ); + t( "Attribute containing []", "input[name$='foo[bar]']", [ "hidden2" ] ); + t( "Attribute containing []", "input[name*='foo[bar]']", [ "hidden2" ] ); - t( "Multiple Attribute Equals", "#form input[type='radio'], #form input[type='hidden']", ["radio1", "radio2", "hidden1"] ); - t( "Multiple Attribute Equals", "#form input[type='radio'], #form input[type=\"hidden\"]", ["radio1", "radio2", "hidden1"] ); - t( "Multiple Attribute Equals", "#form input[type='radio'], #form input[type=hidden]", ["radio1", "radio2", "hidden1"] ); + t( "Multiple Attribute Equals", "#form input[type='radio'], #form input[type='hidden']", [ "radio1", "radio2", "hidden1" ] ); + t( "Multiple Attribute Equals", "#form input[type='radio'], #form input[type=\"hidden\"]", [ "radio1", "radio2", "hidden1" ] ); + t( "Multiple Attribute Equals", "#form input[type='radio'], #form input[type=hidden]", [ "radio1", "radio2", "hidden1" ] ); - t( "Attribute selector using UTF8", "span[lang=中文]", ["台北"] ); + t( "Attribute selector using UTF8", "span[lang=中文]", [ "台北" ] ); - t( "Attribute Begins With", "a[href ^= 'http://www']", ["google","yahoo"] ); - t( "Attribute Ends With", "a[href $= 'org/']", ["mark"] ); - t( "Attribute Contains", "a[href *= 'google']", ["google","groups"] ); - t( "Attribute Is Not Equal", "#ap a[hreflang!='en']", ["google","groups","anchor1"] ); + t( "Attribute Begins With", "a[href ^= 'http://www']", [ "google","yahoo" ] ); + t( "Attribute Ends With", "a[href $= 'org/']", [ "mark" ] ); + t( "Attribute Contains", "a[href *= 'google']", [ "google","groups" ] ); + t( "Attribute Is Not Equal", "#ap a[hreflang!='en']", [ "google","groups","anchor1" ] ); - t( "Empty values", "#select1 option[value='']", ["option1a"] ); - t( "Empty values", "#select1 option[value!='']", ["option1b","option1c","option1d"] ); + t( "Empty values", "#select1 option[value='']", [ "option1a" ] ); + t( "Empty values", "#select1 option[value!='']", [ "option1b","option1c","option1d" ] ); - t( "Select options via :selected", "#select1 option:selected", ["option1a"] ); - t( "Select options via :selected", "#select2 option:selected", ["option2d"] ); - t( "Select options via :selected", "#select3 option:selected", ["option3b", "option3c"] ); - t( "Select options via :selected", "select[name='select2'] option:selected", ["option2d"] ); + t( "Select options via :selected", "#select1 option:selected", [ "option1a" ] ); + t( "Select options via :selected", "#select2 option:selected", [ "option2d" ] ); + t( "Select options via :selected", "#select3 option:selected", [ "option3b", "option3c" ] ); + t( "Select options via :selected", "select[name='select2'] option:selected", [ "option2d" ] ); - t( "Grouped Form Elements", "input[name='foo[bar]']", ["hidden2"] ); + t( "Grouped Form Elements", "input[name='foo[bar]']", [ "hidden2" ] ); // Make sure attribute value quoting works correctly. See jQuery #6093; #6428; #13894 // Use seeded results to bypass querySelectorAll optimizations @@ -213,63 +213,63 @@ QUnit.test("attributes", function( assert ) { "<input type='hidden' id='attrbad_backslash_quote' data-attr='\''/>" + "<input type='hidden' id='attrbad_backslash_backslash' data-attr='\\'/>" + "<input type='hidden' id='attrbad_unicode' data-attr='一'/>" - ).appendTo("#qunit-fixture").get(); + ).appendTo( "#qunit-fixture" ).get(); - t( "Underscores don't need escaping", "input[id=types_all]", ["types_all"] ); + t( "Underscores don't need escaping", "input[id=types_all]", [ "types_all" ] ); - t( "input[type=text]", "#form input[type=text]", ["text1", "text2", "hidden2", "name"] ); - t( "input[type=search]", "#form input[type=search]", ["search"] ); + t( "input[type=text]", "#form input[type=text]", [ "text1", "text2", "hidden2", "name" ] ); + t( "input[type=search]", "#form input[type=search]", [ "search" ] ); withScript = supportjQuery( "<div><span><script src=''/></span></div>" ); assert.ok( withScript.find( "#moretests script[src]" ).has( "script" ), "script[src] (jQuery #13777)" ); - div = document.getElementById("foo"); + div = document.getElementById( "foo" ); t( "Object.prototype property \"constructor\" (negative)", "[constructor]", [] ); t( "Gecko Object.prototype property \"watch\" (negative)", "[watch]", [] ); div.setAttribute( "constructor", "foo" ); div.setAttribute( "watch", "bar" ); - t( "Object.prototype property \"constructor\"", "[constructor='foo']", ["foo"] ); - t( "Gecko Object.prototype property \"watch\"", "[watch='bar']", ["foo"] ); + t( "Object.prototype property \"constructor\"", "[constructor='foo']", [ "foo" ] ); + t( "Gecko Object.prototype property \"watch\"", "[watch='bar']", [ "foo" ] ); - t( "Value attribute is retrieved correctly", "input[value=Test]", ["text1", "text2"] ); + t( "Value attribute is retrieved correctly", "input[value=Test]", [ "text1", "text2" ] ); // #12600 assert.ok( - jQuery("<select value='12600'><option value='option' selected='selected'></option><option value=''></option></select>") + jQuery( "<select value='12600'><option value='option' selected='selected'></option><option value=''></option></select>" ) .prop( "value", "option" ) - .is(":input[value='12600']"), + .is( ":input[value='12600']" ), ":input[value=foo] selects select by attribute" ); - assert.ok( jQuery("<input type='text' value='12600'/>").prop( "value", "option" ).is(":input[value='12600']"), + assert.ok( jQuery( "<input type='text' value='12600'/>" ).prop( "value", "option" ).is( ":input[value='12600']" ), ":input[value=foo] selects text input by attribute" ); // #11115 - assert.ok( jQuery("<input type='checkbox' checked='checked'/>").prop( "checked", false ).is("[checked]"), + assert.ok( jQuery( "<input type='checkbox' checked='checked'/>" ).prop( "checked", false ).is( "[checked]" ), "[checked] selects by attribute (positive)" ); - assert.ok( !jQuery("<input type='checkbox'/>").prop( "checked", true ).is("[checked]"), + assert.ok( !jQuery( "<input type='checkbox'/>" ).prop( "checked", true ).is( "[checked]" ), "[checked] selects by attribute (negative)" ); -}); +} ); -QUnit.test("disconnected nodes", function( assert ) { +QUnit.test( "disconnected nodes", function( assert ) { assert.expect( 1 ); - var $div = jQuery("<div/>"); - assert.equal( $div.is("div"), true, "Make sure .is('nodeName') works on disconnected nodes." ); -}); + var $div = jQuery( "<div/>" ); + assert.equal( $div.is( "div" ), true, "Make sure .is('nodeName') works on disconnected nodes." ); +} ); -QUnit.test("disconnected nodes - jQuery only", function( assert ) { +QUnit.test( "disconnected nodes - jQuery only", function( assert ) { assert.expect( 3 ); - var $opt = jQuery("<option></option>").attr("value", "whipit").appendTo("#qunit-fixture").detach(); + var $opt = jQuery( "<option></option>" ).attr( "value", "whipit" ).appendTo( "#qunit-fixture" ).detach(); assert.equal( $opt.val(), "whipit", "option value" ); - assert.equal( $opt.is(":selected"), false, "unselected option" ); - $opt.prop("selected", true); - assert.equal( $opt.is(":selected"), true, "selected option" ); -}); + assert.equal( $opt.is( ":selected" ), false, "unselected option" ); + $opt.prop( "selected", true ); + assert.equal( $opt.is( ":selected" ), true, "selected option" ); +} ); testIframe( "selector/html5_selector", @@ -286,7 +286,7 @@ testIframe( i = 0; for ( ; i < arguments.length; i++ ) { - r.push( document.getElementById( arguments[i] ) ); + r.push( document.getElementById( arguments[ i ] ) ); } return r; } @@ -299,15 +299,15 @@ testIframe( * @param {Array} c - Array of ids to construct what is expected */ function t( a, b, c ) { - var f = jQuery(b).get(), + var f = jQuery( b ).get(), s = "", i = 0; for ( ; i < f.length; i++ ) { - s += (s && ",") + "'" + f[i].id + "'"; + s += ( s && "," ) + "'" + f[ i ].id + "'"; } - assert.deepEqual(f, q.apply( q, c ), a + " (" + b + ")"); + assert.deepEqual( f, q.apply( q, c ), a + " (" + b + ")" ); } // ====== All known boolean attributes, including html5 booleans ====== @@ -318,79 +318,79 @@ testIframe( // noshade, nowrap, novalidate, open, pubdate, readonly, required, // reversed, scoped, seamless, selected, truespeed, visible (skipping visible attribute, which is on a barprop object) - t( "Attribute Exists", "[autobuffer]", ["video1"]); - t( "Attribute Exists", "[autofocus]", ["text1"]); - t( "Attribute Exists", "[autoplay]", ["video1"]); - t( "Attribute Exists", "[async]", ["script1"]); - t( "Attribute Exists", "[checked]", ["check1"]); - t( "Attribute Exists", "[compact]", ["dl"]); - t( "Attribute Exists", "[controls]", ["video1"]); - t( "Attribute Exists", "[declare]", ["object1"]); - t( "Attribute Exists", "[defer]", ["script1"]); - t( "Attribute Exists", "[disabled]", ["check1"]); - t( "Attribute Exists", "[formnovalidate]", ["form1"]); - t( "Attribute Exists", "[hidden]", ["div1"]); - t( "Attribute Exists", "[indeterminate]", []); - t( "Attribute Exists", "[ismap]", ["img1"]); - t( "Attribute Exists", "[itemscope]", ["div1"]); - t( "Attribute Exists", "[loop]", ["video1"]); - t( "Attribute Exists", "[multiple]", ["select1"]); - t( "Attribute Exists", "[muted]", ["audio1"]); - t( "Attribute Exists", "[nohref]", ["area1"]); - t( "Attribute Exists", "[noresize]", ["textarea1"]); - t( "Attribute Exists", "[noshade]", ["hr1"]); - t( "Attribute Exists", "[nowrap]", ["td1", "div1"]); - t( "Attribute Exists", "[novalidate]", ["form1"]); - t( "Attribute Exists", "[open]", ["details1"]); - t( "Attribute Exists", "[pubdate]", ["article1"]); - t( "Attribute Exists", "[readonly]", ["text1"]); - t( "Attribute Exists", "[required]", ["text1"]); - t( "Attribute Exists", "[reversed]", ["ol1"]); - t( "Attribute Exists", "[scoped]", ["style1"]); - t( "Attribute Exists", "[seamless]", ["iframe1"]); - t( "Attribute Exists", "[selected]", ["option1"]); - t( "Attribute Exists", "[truespeed]", ["marquee1"]); + t( "Attribute Exists", "[autobuffer]", [ "video1" ] ); + t( "Attribute Exists", "[autofocus]", [ "text1" ] ); + t( "Attribute Exists", "[autoplay]", [ "video1" ] ); + t( "Attribute Exists", "[async]", [ "script1" ] ); + t( "Attribute Exists", "[checked]", [ "check1" ] ); + t( "Attribute Exists", "[compact]", [ "dl" ] ); + t( "Attribute Exists", "[controls]", [ "video1" ] ); + t( "Attribute Exists", "[declare]", [ "object1" ] ); + t( "Attribute Exists", "[defer]", [ "script1" ] ); + t( "Attribute Exists", "[disabled]", [ "check1" ] ); + t( "Attribute Exists", "[formnovalidate]", [ "form1" ] ); + t( "Attribute Exists", "[hidden]", [ "div1" ] ); + t( "Attribute Exists", "[indeterminate]", [] ); + t( "Attribute Exists", "[ismap]", [ "img1" ] ); + t( "Attribute Exists", "[itemscope]", [ "div1" ] ); + t( "Attribute Exists", "[loop]", [ "video1" ] ); + t( "Attribute Exists", "[multiple]", [ "select1" ] ); + t( "Attribute Exists", "[muted]", [ "audio1" ] ); + t( "Attribute Exists", "[nohref]", [ "area1" ] ); + t( "Attribute Exists", "[noresize]", [ "textarea1" ] ); + t( "Attribute Exists", "[noshade]", [ "hr1" ] ); + t( "Attribute Exists", "[nowrap]", [ "td1", "div1" ] ); + t( "Attribute Exists", "[novalidate]", [ "form1" ] ); + t( "Attribute Exists", "[open]", [ "details1" ] ); + t( "Attribute Exists", "[pubdate]", [ "article1" ] ); + t( "Attribute Exists", "[readonly]", [ "text1" ] ); + t( "Attribute Exists", "[required]", [ "text1" ] ); + t( "Attribute Exists", "[reversed]", [ "ol1" ] ); + t( "Attribute Exists", "[scoped]", [ "style1" ] ); + t( "Attribute Exists", "[seamless]", [ "iframe1" ] ); + t( "Attribute Exists", "[selected]", [ "option1" ] ); + t( "Attribute Exists", "[truespeed]", [ "marquee1" ] ); // Enumerated attributes (these are not boolean content attributes) jQuery.expandedEach = jQuery.each; - jQuery.expandedEach([ "draggable", "contenteditable", "aria-disabled" ], function( i, val ) { - t( "Enumerated attribute", "[" + val + "]", ["div1"]); - }); - t( "Enumerated attribute", "[spellcheck]", ["span1"]); + jQuery.expandedEach( [ "draggable", "contenteditable", "aria-disabled" ], function( i, val ) { + t( "Enumerated attribute", "[" + val + "]", [ "div1" ] ); + } ); + t( "Enumerated attribute", "[spellcheck]", [ "span1" ] ); t( "tabindex selector does not retrieve all elements in IE6/7 (#8473)", "form, [tabindex]", [ "form1", "text1" ] ); - t( "Improperly named form elements do not interfere with form selections (#9570)", "form[name='formName']", ["form1"] ); + t( "Improperly named form elements do not interfere with form selections (#9570)", "form[name='formName']", [ "form1" ] ); } ); QUnit.test( "jQuery.contains", function( assert ) { assert.expect( 16 ); - var container = document.getElementById("nonnodes"), + var container = document.getElementById( "nonnodes" ), element = container.firstChild, text = element.nextSibling, nonContained = container.nextSibling, - detached = document.createElement("a"); + detached = document.createElement( "a" ); assert.ok( element && element.nodeType === 1, "preliminary: found element" ); assert.ok( text && text.nodeType === 3, "preliminary: found text" ); assert.ok( nonContained, "preliminary: found non-descendant" ); - assert.ok( jQuery.contains(container, element), "child" ); - assert.ok( jQuery.contains(container.parentNode, element), "grandchild" ); - assert.ok( jQuery.contains(container, text), "text child" ); - assert.ok( jQuery.contains(container.parentNode, text), "text grandchild" ); - assert.ok( !jQuery.contains(container, container), "self" ); - assert.ok( !jQuery.contains(element, container), "parent" ); - assert.ok( !jQuery.contains(container, nonContained), "non-descendant" ); - assert.ok( !jQuery.contains(container, document), "document" ); - assert.ok( !jQuery.contains(container, document.documentElement), "documentElement (negative)" ); - assert.ok( !jQuery.contains(container, null), "Passing null does not throw an error" ); - assert.ok( jQuery.contains(document, document.documentElement), "documentElement (positive)" ); - assert.ok( jQuery.contains(document, element), "document container (positive)" ); - assert.ok( !jQuery.contains(document, detached), "document container (negative)" ); -}); - -QUnit.test("jQuery.uniqueSort", function( assert ) { + assert.ok( jQuery.contains( container, element ), "child" ); + assert.ok( jQuery.contains( container.parentNode, element ), "grandchild" ); + assert.ok( jQuery.contains( container, text ), "text child" ); + assert.ok( jQuery.contains( container.parentNode, text ), "text grandchild" ); + assert.ok( !jQuery.contains( container, container ), "self" ); + assert.ok( !jQuery.contains( element, container ), "parent" ); + assert.ok( !jQuery.contains( container, nonContained ), "non-descendant" ); + assert.ok( !jQuery.contains( container, document ), "document" ); + assert.ok( !jQuery.contains( container, document.documentElement ), "documentElement (negative)" ); + assert.ok( !jQuery.contains( container, null ), "Passing null does not throw an error" ); + assert.ok( jQuery.contains( document, document.documentElement ), "documentElement (positive)" ); + assert.ok( jQuery.contains( document, element ), "document container (positive)" ); + assert.ok( !jQuery.contains( document, detached ), "document container (negative)" ); +} ); + +QUnit.test( "jQuery.uniqueSort", function( assert ) { assert.expect( 15 ); function Arrayish( arr ) { @@ -408,16 +408,16 @@ QUnit.test("jQuery.uniqueSort", function( assert ) { var i, tests, detached = [], body = document.body, - fixture = document.getElementById("qunit-fixture"), - detached1 = document.createElement("p"), - detached2 = document.createElement("ul"), - detachedChild = detached1.appendChild( document.createElement("a") ), - detachedGrandchild = detachedChild.appendChild( document.createElement("b") ); + fixture = document.getElementById( "qunit-fixture" ), + detached1 = document.createElement( "p" ), + detached2 = document.createElement( "ul" ), + detachedChild = detached1.appendChild( document.createElement( "a" ) ), + detachedGrandchild = detachedChild.appendChild( document.createElement( "b" ) ); for ( i = 0; i < 12; i++ ) { - detached.push( document.createElement("li") ); - detached[i].id = "detached" + i; - detached2.appendChild( document.createElement("li") ).id = "detachedChild" + i; + detached.push( document.createElement( "li" ) ); + detached[ i ].id = "detached" + i; + detached2.appendChild( document.createElement( "li" ) ).id = "detachedChild" + i; } tests = { @@ -443,16 +443,16 @@ QUnit.test("jQuery.uniqueSort", function( assert ) { }, "Detached children": { input: [ - detached2.childNodes[0], - detached2.childNodes[1], - detached2.childNodes[2], - detached2.childNodes[3] + detached2.childNodes[ 0 ], + detached2.childNodes[ 1 ], + detached2.childNodes[ 2 ], + detached2.childNodes[ 3 ] ], expected: [ - detached2.childNodes[0], - detached2.childNodes[1], - detached2.childNodes[2], - detached2.childNodes[3] + detached2.childNodes[ 0 ], + detached2.childNodes[ 1 ], + detached2.childNodes[ 2 ], + detached2.childNodes[ 3 ] ] }, "Attached/detached mixture": { @@ -465,23 +465,23 @@ QUnit.test("jQuery.uniqueSort", function( assert ) { jQuery.each( tests, function( label, test ) { var length = test.length || test.input.length; assert.deepEqual( jQuery.uniqueSort( test.input ).slice( 0, length ), test.expected, label + " (array)" ); - assert.deepEqual( jQuery.uniqueSort( new Arrayish(test.input) ).slice( 0, length ), test.expected, label + " (quasi-array)" ); - }); + assert.deepEqual( jQuery.uniqueSort( new Arrayish( test.input ) ).slice( 0, length ), test.expected, label + " (quasi-array)" ); + } ); assert.strictEqual( jQuery.unique, jQuery.uniqueSort, "jQuery.unique() is an alias for jQuery.uniqueSort()" ); -}); +} ); testIframe( "selector/sizzle_cache", "Sizzle cache collides with multiple Sizzles on a page", function( jQuery, window, document, assert ) { - var $cached = window["$cached"]; + var $cached = window[ "$cached" ]; - assert.expect(4); + assert.expect( 4 ); assert.notStrictEqual( jQuery, $cached, "Loaded two engines" ); - assert.deepEqual( $cached(".test a").get(), [ document.getElementById("collision") ], "Select collision anchor with first sizzle" ); - assert.equal( jQuery(".evil a").length, 0, "Select nothing with second sizzle" ); - assert.equal( jQuery(".evil a").length, 0, "Select nothing again with second sizzle" ); + assert.deepEqual( $cached( ".test a" ).get(), [ document.getElementById( "collision" ) ], "Select collision anchor with first sizzle" ); + assert.equal( jQuery( ".evil a" ).length, 0, "Select nothing with second sizzle" ); + assert.equal( jQuery( ".evil a" ).length, 0, "Select nothing again with second sizzle" ); } ); @@ -512,9 +512,9 @@ QUnit.asyncTest( "Iframe dispatch should not affect jQuery (#13936)", 1, functio loaded = true; form.submit(); } - }); + } ); iframeDoc.open(); iframeDoc.write( "<body><form id='navigate' action='?'></form></body>" ); iframeDoc.close(); -}); +} ); diff --git a/test/unit/serialize.js b/test/unit/serialize.js index a650f5456..047861530 100644 --- a/test/unit/serialize.js +++ b/test/unit/serialize.js @@ -1,43 +1,43 @@ -QUnit.module("serialize", { teardown: moduleTeardown }); +QUnit.module( "serialize", { teardown: moduleTeardown } ); -QUnit.test("jQuery.param()", function( assert ) { - assert.expect(22); +QUnit.test( "jQuery.param()", function( assert ) { + assert.expect( 22 ); var params, settings; assert.equal( !( jQuery.ajaxSettings && jQuery.ajaxSettings.traditional ), true, "traditional flag, falsy by default" ); - params = {"foo":"bar", "baz":42, "quux":"All your base are belong to us"}; - assert.equal( jQuery.param(params), "foo=bar&baz=42&quux=All+your+base+are+belong+to+us", "simple" ); + params = { "foo":"bar", "baz":42, "quux":"All your base are belong to us" }; + assert.equal( jQuery.param( params ), "foo=bar&baz=42&quux=All+your+base+are+belong+to+us", "simple" ); - params = {"string":"foo","null":null,"undefined":undefined}; - assert.equal( jQuery.param(params), "string=foo&null=&undefined=", "handle nulls and undefineds properly" ); + params = { "string":"foo","null":null,"undefined":undefined }; + assert.equal( jQuery.param( params ), "string=foo&null=&undefined=", "handle nulls and undefineds properly" ); - params = {"someName": [1, 2, 3], "regularThing": "blah" }; - assert.equal( jQuery.param(params), "someName%5B%5D=1&someName%5B%5D=2&someName%5B%5D=3®ularThing=blah", "with array" ); + params = { "someName": [ 1, 2, 3 ], "regularThing": "blah" }; + assert.equal( jQuery.param( params ), "someName%5B%5D=1&someName%5B%5D=2&someName%5B%5D=3®ularThing=blah", "with array" ); - params = {"foo": ["a", "b", "c"]}; - assert.equal( jQuery.param(params), "foo%5B%5D=a&foo%5B%5D=b&foo%5B%5D=c", "with array of strings" ); + params = { "foo": [ "a", "b", "c" ] }; + assert.equal( jQuery.param( params ), "foo%5B%5D=a&foo%5B%5D=b&foo%5B%5D=c", "with array of strings" ); - params = {"foo": ["baz", 42, "All your base are belong to us"] }; - assert.equal( jQuery.param(params), "foo%5B%5D=baz&foo%5B%5D=42&foo%5B%5D=All+your+base+are+belong+to+us", "more array" ); + params = { "foo": [ "baz", 42, "All your base are belong to us" ] }; + assert.equal( jQuery.param( params ), "foo%5B%5D=baz&foo%5B%5D=42&foo%5B%5D=All+your+base+are+belong+to+us", "more array" ); - params = {"foo": { "bar": "baz", "beep": 42, "quux": "All your base are belong to us" } }; - assert.equal( jQuery.param(params), "foo%5Bbar%5D=baz&foo%5Bbeep%5D=42&foo%5Bquux%5D=All+your+base+are+belong+to+us", "even more arrays" ); + params = { "foo": { "bar": "baz", "beep": 42, "quux": "All your base are belong to us" } }; + assert.equal( jQuery.param( params ), "foo%5Bbar%5D=baz&foo%5Bbeep%5D=42&foo%5Bquux%5D=All+your+base+are+belong+to+us", "even more arrays" ); - params = { a:[1,2], b:{ c:3, d:[4,5], e:{ x:[6], y:7, z:[8,9] }, f:true, g:false, h:undefined }, i:[10,11], j:true, k:false, l:[undefined,0], m:"cowboy hat?" }; - assert.equal( decodeURIComponent( jQuery.param(params) ), "a[]=1&a[]=2&b[c]=3&b[d][]=4&b[d][]=5&b[e][x][]=6&b[e][y]=7&b[e][z][]=8&b[e][z][]=9&b[f]=true&b[g]=false&b[h]=&i[]=10&i[]=11&j=true&k=false&l[]=&l[]=0&m=cowboy+hat?", "huge structure" ); + params = { a:[ 1,2 ], b:{ c:3, d:[ 4,5 ], e:{ x:[ 6 ], y:7, z:[ 8,9 ] }, f:true, g:false, h:undefined }, i:[ 10,11 ], j:true, k:false, l:[ undefined,0 ], m:"cowboy hat?" }; + assert.equal( decodeURIComponent( jQuery.param( params ) ), "a[]=1&a[]=2&b[c]=3&b[d][]=4&b[d][]=5&b[e][x][]=6&b[e][y]=7&b[e][z][]=8&b[e][z][]=9&b[f]=true&b[g]=false&b[h]=&i[]=10&i[]=11&j=true&k=false&l[]=&l[]=0&m=cowboy+hat?", "huge structure" ); params = { "a": [ 0, [ 1, 2 ], [ 3, [ 4, 5 ], [ 6 ] ], { "b": [ 7, [ 8, 9 ], [ { "c": 10, "d": 11 } ], [ [ 12 ] ], [ [ [ 13 ] ] ], { "e": { "f": { "g": [ 14, [ 15 ] ] } } }, 16 ] }, 17 ] }; - assert.equal( decodeURIComponent( jQuery.param(params) ), "a[]=0&a[1][]=1&a[1][]=2&a[2][]=3&a[2][1][]=4&a[2][1][]=5&a[2][2][]=6&a[3][b][]=7&a[3][b][1][]=8&a[3][b][1][]=9&a[3][b][2][0][c]=10&a[3][b][2][0][d]=11&a[3][b][3][0][]=12&a[3][b][4][0][0][]=13&a[3][b][5][e][f][g][]=14&a[3][b][5][e][f][g][1][]=15&a[3][b][]=16&a[]=17", "nested arrays" ); + assert.equal( decodeURIComponent( jQuery.param( params ) ), "a[]=0&a[1][]=1&a[1][]=2&a[2][]=3&a[2][1][]=4&a[2][1][]=5&a[2][2][]=6&a[3][b][]=7&a[3][b][1][]=8&a[3][b][1][]=9&a[3][b][2][0][c]=10&a[3][b][2][0][d]=11&a[3][b][3][0][]=12&a[3][b][4][0][0][]=13&a[3][b][5][e][f][g][]=14&a[3][b][5][e][f][g][1][]=15&a[3][b][]=16&a[]=17", "nested arrays" ); - params = { "a":[1,2], "b":{ "c":3, "d":[4,5], "e":{ "x":[6], "y":7, "z":[8,9] }, "f":true, "g":false, "h":undefined }, "i":[10,11], "j":true, "k":false, "l":[undefined,0], "m":"cowboy hat?" }; - assert.equal( jQuery.param(params,true), "a=1&a=2&b=%5Bobject+Object%5D&i=10&i=11&j=true&k=false&l=&l=0&m=cowboy+hat%3F", "huge structure, forced traditional" ); + params = { "a":[ 1,2 ], "b":{ "c":3, "d":[ 4,5 ], "e":{ "x":[ 6 ], "y":7, "z":[ 8,9 ] }, "f":true, "g":false, "h":undefined }, "i":[ 10,11 ], "j":true, "k":false, "l":[ undefined,0 ], "m":"cowboy hat?" }; + assert.equal( jQuery.param( params, true ), "a=1&a=2&b=%5Bobject+Object%5D&i=10&i=11&j=true&k=false&l=&l=0&m=cowboy+hat%3F", "huge structure, forced traditional" ); - assert.equal( decodeURIComponent( jQuery.param({ "a": [1,2,3], "b[]": [4,5,6], "c[d]": [7,8,9], "e": { "f": [10], "g": [11,12], "h": 13 } }) ), "a[]=1&a[]=2&a[]=3&b[]=4&b[]=5&b[]=6&c[d][]=7&c[d][]=8&c[d][]=9&e[f][]=10&e[g][]=11&e[g][]=12&e[h]=13", "Make sure params are not double-encoded." ); + assert.equal( decodeURIComponent( jQuery.param( { "a": [ 1,2,3 ], "b[]": [ 4,5,6 ], "c[d]": [ 7,8,9 ], "e": { "f": [ 10 ], "g": [ 11,12 ], "h": 13 } } ) ), "a[]=1&a[]=2&a[]=3&b[]=4&b[]=5&b[]=6&c[d][]=7&c[d][]=8&c[d][]=9&e[f][]=10&e[g][]=11&e[g][]=12&e[h]=13", "Make sure params are not double-encoded." ); // #7945 - assert.equal( jQuery.param({"jquery": "1.4.2"}), "jquery=1.4.2", "Check that object with a jQuery property get serialized correctly" ); + assert.equal( jQuery.param( { "jquery": "1.4.2" } ), "jquery=1.4.2", "Check that object with a jQuery property get serialized correctly" ); settings = { traditional: true }; @@ -47,58 +47,58 @@ QUnit.test("jQuery.param()", function( assert ) { jQuery.ajaxSettings = settings; } - params = {"foo":"bar", "baz":42, "quux":"All your base are belong to us"}; - assert.equal( jQuery.param(params), "foo=bar&baz=42&quux=All+your+base+are+belong+to+us", "simple" ); + params = { "foo":"bar", "baz":42, "quux":"All your base are belong to us" }; + assert.equal( jQuery.param( params ), "foo=bar&baz=42&quux=All+your+base+are+belong+to+us", "simple" ); - params = {"someName": [1, 2, 3], "regularThing": "blah" }; - assert.equal( jQuery.param(params), "someName=1&someName=2&someName=3®ularThing=blah", "with array" ); + params = { "someName": [ 1, 2, 3 ], "regularThing": "blah" }; + assert.equal( jQuery.param( params ), "someName=1&someName=2&someName=3®ularThing=blah", "with array" ); - params = {"foo": ["a", "b", "c"]}; - assert.equal( jQuery.param(params), "foo=a&foo=b&foo=c", "with array of strings" ); + params = { "foo": [ "a", "b", "c" ] }; + assert.equal( jQuery.param( params ), "foo=a&foo=b&foo=c", "with array of strings" ); - params = {"foo[]":["baz", 42, "All your base are belong to us"]}; - assert.equal( jQuery.param(params), "foo%5B%5D=baz&foo%5B%5D=42&foo%5B%5D=All+your+base+are+belong+to+us", "more array" ); + params = { "foo[]":[ "baz", 42, "All your base are belong to us" ] }; + assert.equal( jQuery.param( params ), "foo%5B%5D=baz&foo%5B%5D=42&foo%5B%5D=All+your+base+are+belong+to+us", "more array" ); - params = {"foo[bar]":"baz", "foo[beep]":42, "foo[quux]":"All your base are belong to us"}; - assert.equal( jQuery.param(params), "foo%5Bbar%5D=baz&foo%5Bbeep%5D=42&foo%5Bquux%5D=All+your+base+are+belong+to+us", "even more arrays" ); + params = { "foo[bar]":"baz", "foo[beep]":42, "foo[quux]":"All your base are belong to us" }; + assert.equal( jQuery.param( params ), "foo%5Bbar%5D=baz&foo%5Bbeep%5D=42&foo%5Bquux%5D=All+your+base+are+belong+to+us", "even more arrays" ); - params = { a:[1,2], b:{ c:3, d:[4,5], e:{ x:[6], y:7, z:[8,9] }, f:true, g:false, h:undefined }, i:[10,11], j:true, k:false, l:[undefined,0], m:"cowboy hat?" }; - assert.equal( jQuery.param(params), "a=1&a=2&b=%5Bobject+Object%5D&i=10&i=11&j=true&k=false&l=&l=0&m=cowboy+hat%3F", "huge structure" ); + params = { a:[ 1,2 ], b:{ c:3, d:[ 4,5 ], e:{ x:[ 6 ], y:7, z:[ 8,9 ] }, f:true, g:false, h:undefined }, i:[ 10,11 ], j:true, k:false, l:[ undefined,0 ], m:"cowboy hat?" }; + assert.equal( jQuery.param( params ), "a=1&a=2&b=%5Bobject+Object%5D&i=10&i=11&j=true&k=false&l=&l=0&m=cowboy+hat%3F", "huge structure" ); params = { "a": [ 0, [ 1, 2 ], [ 3, [ 4, 5 ], [ 6 ] ], { "b": [ 7, [ 8, 9 ], [ { "c": 10, d: 11 } ], [ [ 12 ] ], [ [ [ 13 ] ] ], { "e": { "f": { "g": [ 14, [ 15 ] ] } } }, 16 ] }, 17 ] }; - assert.equal( jQuery.param(params), "a=0&a=1%2C2&a=3%2C4%2C5%2C6&a=%5Bobject+Object%5D&a=17", "nested arrays (not possible when jQuery.param.traditional == true)" ); + assert.equal( jQuery.param( params ), "a=0&a=1%2C2&a=3%2C4%2C5%2C6&a=%5Bobject+Object%5D&a=17", "nested arrays (not possible when jQuery.param.traditional == true)" ); - params = { a:[1,2], b:{ c:3, d:[4,5], e:{ x:[6], y:7, z:[8,9] }, f:true, g:false, h:undefined }, i:[10,11], j:true, k:false, l:[undefined,0], m:"cowboy hat?" }; - assert.equal( decodeURIComponent( jQuery.param(params,false) ), "a[]=1&a[]=2&b[c]=3&b[d][]=4&b[d][]=5&b[e][x][]=6&b[e][y]=7&b[e][z][]=8&b[e][z][]=9&b[f]=true&b[g]=false&b[h]=&i[]=10&i[]=11&j=true&k=false&l[]=&l[]=0&m=cowboy+hat?", "huge structure, forced not traditional" ); + params = { a:[ 1,2 ], b:{ c:3, d:[ 4,5 ], e:{ x:[ 6 ], y:7, z:[ 8,9 ] }, f:true, g:false, h:undefined }, i:[ 10,11 ], j:true, k:false, l:[ undefined,0 ], m:"cowboy hat?" }; + assert.equal( decodeURIComponent( jQuery.param( params, false ) ), "a[]=1&a[]=2&b[c]=3&b[d][]=4&b[d][]=5&b[e][x][]=6&b[e][y]=7&b[e][z][]=8&b[e][z][]=9&b[f]=true&b[g]=false&b[h]=&i[]=10&i[]=11&j=true&k=false&l[]=&l[]=0&m=cowboy+hat?", "huge structure, forced not traditional" ); params = { "param1": null }; - assert.equal( jQuery.param(params,false), "param1=", "Make sure that null params aren't traversed." ); + assert.equal( jQuery.param( params, false ), "param1=", "Make sure that null params aren't traversed." ); - params = {"test": {"length": 3, "foo": "bar"} }; + params = { "test": { "length": 3, "foo": "bar" } }; assert.equal( jQuery.param( params, false ), "test%5Blength%5D=3&test%5Bfoo%5D=bar", "Sub-object with a length property" ); if ( jQuery.ajaxSettings === settings ) { delete jQuery.ajaxSettings; } else { - jQuery.ajaxSetup({ traditional: false }); + jQuery.ajaxSetup( { traditional: false } ); } -}); +} ); -QUnit.test("jQuery.param() Constructed prop values", function( assert ) { +QUnit.test( "jQuery.param() Constructed prop values", function( assert ) { assert.expect( 4 ); /** @constructor */ function Record() { - this["prop"] = "val"; + this[ "prop" ] = "val"; } var MyString = String, MyNumber = Number, - params = { "test": new MyString("foo") }; + params = { "test": new MyString( "foo" ) }; assert.equal( jQuery.param( params, false ), "test=foo", "Do not mistake new String() for a plain object" ); - params = { "test": new MyNumber(5) }; + params = { "test": new MyNumber( 5 ) }; assert.equal( jQuery.param( params, false ), "test=5", "Do not mistake new Number() for a plain object" ); params = { "test": new Date() }; @@ -106,41 +106,41 @@ QUnit.test("jQuery.param() Constructed prop values", function( assert ) { // should allow non-native constructed objects params = { "test": new Record() }; - assert.equal( jQuery.param( params, false ), jQuery.param({ "test": { "prop": "val" } }), "Allow non-native constructed objects" ); -}); + assert.equal( jQuery.param( params, false ), jQuery.param( { "test": { "prop": "val" } } ), "Allow non-native constructed objects" ); +} ); -QUnit.test("serialize()", function( assert ) { - assert.expect(6); +QUnit.test( "serialize()", function( assert ) { + assert.expect( 6 ); // Add html5 elements only for serialize because selector can't yet find them on non-html5 browsers - jQuery("#search").after( + jQuery( "#search" ).after( "<input type='email' id='html5email' name='email' value='dave@jquery.com' />" + "<input type='number' id='html5number' name='number' value='43' />" + "<input type='file' name='fileupload' />" ); - assert.equal( jQuery("#form").serialize(), + assert.equal( jQuery( "#form" ).serialize(), "action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&email=dave%40jquery.com&number=43&select1=&select2=3&select3=1&select3=2&select5=3", - "Check form serialization as query string"); + "Check form serialization as query string" ); - assert.equal( jQuery("input,select,textarea,button", "#form").serialize(), + assert.equal( jQuery( "input,select,textarea,button", "#form" ).serialize(), "action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&email=dave%40jquery.com&number=43&select1=&select2=3&select3=1&select3=2&select5=3", - "Check input serialization as query string"); + "Check input serialization as query string" ); - assert.equal( jQuery("#testForm").serialize(), + assert.equal( jQuery( "#testForm" ).serialize(), "T3=%3F%0D%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=", - "Check form serialization as query string"); + "Check form serialization as query string" ); - assert.equal( jQuery("input,select,textarea,button", "#testForm").serialize(), + assert.equal( jQuery( "input,select,textarea,button", "#testForm" ).serialize(), "T3=%3F%0D%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=", - "Check input serialization as query string"); + "Check input serialization as query string" ); - assert.equal( jQuery("#form, #testForm").serialize(), + assert.equal( jQuery( "#form, #testForm" ).serialize(), "action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&email=dave%40jquery.com&number=43&select1=&select2=3&select3=1&select3=2&select5=3&T3=%3F%0D%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=", - "Multiple form serialization as query string"); + "Multiple form serialization as query string" ); - assert.equal( jQuery("#form, #testForm :input").serialize(), + assert.equal( jQuery( "#form, #testForm :input" ).serialize(), "action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&email=dave%40jquery.com&number=43&select1=&select2=3&select3=1&select3=2&select5=3&T3=%3F%0D%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=", - "Mixed form/input serialization as query string"); - jQuery("#html5email, #html5number").remove(); -}); + "Mixed form/input serialization as query string" ); + jQuery( "#html5email, #html5number" ).remove(); +} ); diff --git a/test/unit/support.js b/test/unit/support.js index d1e3a4661..ec1ada480 100644 --- a/test/unit/support.js +++ b/test/unit/support.js @@ -1,4 +1,4 @@ -QUnit.module("support", { teardown: moduleTeardown }); +QUnit.module( "support", { teardown: moduleTeardown } ); var computedSupport = getComputedSupport( jQuery.support ); @@ -45,14 +45,14 @@ testIframeWithCallback( QUnit.stop(); - supportjQuery.get( "data/support/csp.log" ).done(function( data ) { + supportjQuery.get( "data/support/csp.log" ).done( function( data ) { assert.equal( data, "", "No log request should be sent" ); supportjQuery.get( "data/support/csp-clean.php" ).done( start ); - }); + } ); } ); -(function() { +( function() { var expected, userAgent = window.navigator.userAgent; @@ -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,16 +271,17 @@ 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 ], "jQuery.support['" + i + "']: " + computedSupport[ i ] + - ", expected['" + i + "']: " + expected[ i ]); + ", expected['" + i + "']: " + expected[ i ] ); } else { assert.ok( true, "no ajax; skipping jQuery.support[' " + i + " ']" ); } } - }); + } ); } -})(); +} )(); diff --git a/test/unit/traversing.js b/test/unit/traversing.js index 7b5a393d9..39558fa68 100644 --- a/test/unit/traversing.js +++ b/test/unit/traversing.js @@ -1,46 +1,46 @@ -QUnit.module("traversing", { teardown: moduleTeardown }); +QUnit.module( "traversing", { teardown: moduleTeardown } ); QUnit.test( "find(String)", function( assert ) { assert.expect( 1 ); - assert.equal( jQuery("#foo").find(".blogTest").text(), "Yahoo", "Basic selector" ); -}); + assert.equal( jQuery( "#foo" ).find( ".blogTest" ).text(), "Yahoo", "Basic selector" ); +} ); QUnit.test( "find(String) under non-elements", function( assert ) { assert.expect( 2 ); - var j = jQuery("#nonnodes").contents(); - assert.equal( j.find("div").length, 0, "Check node,textnode,comment to find zero divs" ); - assert.equal( j.find("div").addBack().length, 3, "Check node,textnode,comment to find zero divs, but preserves pushStack" ); -}); + var j = jQuery( "#nonnodes" ).contents(); + assert.equal( j.find( "div" ).length, 0, "Check node,textnode,comment to find zero divs" ); + assert.equal( j.find( "div" ).addBack().length, 3, "Check node,textnode,comment to find zero divs, but preserves pushStack" ); +} ); QUnit.test( "find(leading combinator)", function( assert ) { assert.expect( 4 ); - assert.deepEqual( jQuery("#qunit-fixture").find("> div").get(), q( "foo", "nothiddendiv", "moretests", "tabindex-tests", "liveHandlerOrder", "siblingTest", "fx-test-group" ), "find child elements" ); - assert.deepEqual( jQuery("#qunit-fixture").find("> #foo, > #moretests").get(), q( "foo", "moretests" ), "find child elements" ); - assert.deepEqual( jQuery("#qunit-fixture").find("> #foo > p").get(), q( "sndp", "en", "sap" ), "find child elements" ); + assert.deepEqual( jQuery( "#qunit-fixture" ).find( "> div" ).get(), q( "foo", "nothiddendiv", "moretests", "tabindex-tests", "liveHandlerOrder", "siblingTest", "fx-test-group" ), "find child elements" ); + assert.deepEqual( jQuery( "#qunit-fixture" ).find( "> #foo, > #moretests" ).get(), q( "foo", "moretests" ), "find child elements" ); + assert.deepEqual( jQuery( "#qunit-fixture" ).find( "> #foo > p" ).get(), q( "sndp", "en", "sap" ), "find child elements" ); - assert.deepEqual( jQuery("#siblingTest, #siblingfirst").find("+ *").get(), q( "siblingnext", "fx-test-group" ), "ensure document order" ); -}); + assert.deepEqual( jQuery( "#siblingTest, #siblingfirst" ).find( "+ *" ).get(), q( "siblingnext", "fx-test-group" ), "ensure document order" ); +} ); QUnit.test( "find(node|jQuery object)", function( assert ) { assert.expect( 13 ); - var $foo = jQuery("#foo"), - $blog = jQuery(".blogTest"), - $first = jQuery("#first"), + var $foo = jQuery( "#foo" ), + $blog = jQuery( ".blogTest" ), + $first = jQuery( "#first" ), $two = $blog.add( $first ), - $twoMore = jQuery("#ap").add( $blog ), + $twoMore = jQuery( "#ap" ).add( $blog ), $fooTwo = $foo.add( $blog ); assert.equal( $foo.find( $blog ).text(), "Yahoo", "Find with blog jQuery object" ); assert.equal( $foo.find( $blog[ 0 ] ).text(), "Yahoo", "Find with blog node" ); assert.equal( $foo.find( $first ).length, 0, "#first is not in #foo" ); - assert.equal( $foo.find( $first[ 0 ]).length, 0, "#first not in #foo (node)" ); + assert.equal( $foo.find( $first[ 0 ] ).length, 0, "#first not in #foo (node)" ); assert.deepEqual( $foo.find( $two ).get(), $blog.get(), "Find returns only nodes within #foo" ); assert.deepEqual( $foo.find( $twoMore ).get(), $blog.get(), "...regardless of order" ); - assert.ok( $fooTwo.find( $blog ).is(".blogTest"), "Blog is part of the collection, but also within foo" ); - assert.ok( $fooTwo.find( $blog[ 0 ] ).is(".blogTest"), "Blog is part of the collection, but also within foo(node)" ); + assert.ok( $fooTwo.find( $blog ).is( ".blogTest" ), "Blog is part of the collection, but also within foo" ); + assert.ok( $fooTwo.find( $blog[ 0 ] ).is( ".blogTest" ), "Blog is part of the collection, but also within foo(node)" ); assert.equal( $two.find( $foo ).length, 0, "Foo is not in two elements" ); assert.equal( $two.find( $foo[ 0 ] ).length, 0, "Foo is not in two elements(node)" ); @@ -48,47 +48,47 @@ QUnit.test( "find(node|jQuery object)", function( assert ) { assert.equal( $two.find( $first ).length, 0, "first is in the collection and not within two(node)" ); assert.equal( $two.find( $foo[ 0 ] ).addBack().length, 2, "find preserves the pushStack, see #12009" ); -}); - -QUnit.test("is(String|undefined)", function( assert ) { - assert.expect(23); - assert.ok( jQuery("#form").is("form"), "Check for element: A form must be a form" ); - assert.ok( !jQuery("#form").is("div"), "Check for element: A form is not a div" ); - assert.ok( jQuery("#mark").is(".blog"), "Check for class: Expected class 'blog'" ); - assert.ok( !jQuery("#mark").is(".link"), "Check for class: Did not expect class 'link'" ); - assert.ok( jQuery("#simon").is(".blog.link"), "Check for multiple classes: Expected classes 'blog' and 'link'" ); - assert.ok( !jQuery("#simon").is(".blogTest"), "Check for multiple classes: Expected classes 'blog' and 'link', but not 'blogTest'" ); - assert.ok( jQuery("#en").is("[lang=\"en\"]"), "Check for attribute: Expected attribute lang to be 'en'" ); - assert.ok( !jQuery("#en").is("[lang=\"de\"]"), "Check for attribute: Expected attribute lang to be 'en', not 'de'" ); - assert.ok( jQuery("#text1").is("[type=\"text\"]"), "Check for attribute: Expected attribute type to be 'text'" ); - assert.ok( !jQuery("#text1").is("[type=\"radio\"]"), "Check for attribute: Expected attribute type to be 'text', not 'radio'" ); - assert.ok( jQuery("#text2").is(":disabled"), "Check for pseudoclass: Expected to be disabled" ); - assert.ok( !jQuery("#text1").is(":disabled"), "Check for pseudoclass: Expected not disabled" ); - assert.ok( jQuery("#radio2").is(":checked"), "Check for pseudoclass: Expected to be checked" ); - assert.ok( !jQuery("#radio1").is(":checked"), "Check for pseudoclass: Expected not checked" ); - - assert.ok( !jQuery("#foo").is(0), "Expected false for an invalid expression - 0" ); - assert.ok( !jQuery("#foo").is(null), "Expected false for an invalid expression - null" ); - assert.ok( !jQuery("#foo").is(""), "Expected false for an invalid expression - \"\"" ); - assert.ok( !jQuery("#foo").is(undefined), "Expected false for an invalid expression - undefined" ); - assert.ok( !jQuery("#foo").is({ plain: "object" }), "Check passing invalid object" ); +} ); + +QUnit.test( "is(String|undefined)", function( assert ) { + assert.expect( 23 ); + assert.ok( jQuery( "#form" ).is( "form" ), "Check for element: A form must be a form" ); + assert.ok( !jQuery( "#form" ).is( "div" ), "Check for element: A form is not a div" ); + assert.ok( jQuery( "#mark" ).is( ".blog" ), "Check for class: Expected class 'blog'" ); + assert.ok( !jQuery( "#mark" ).is( ".link" ), "Check for class: Did not expect class 'link'" ); + assert.ok( jQuery( "#simon" ).is( ".blog.link" ), "Check for multiple classes: Expected classes 'blog' and 'link'" ); + assert.ok( !jQuery( "#simon" ).is( ".blogTest" ), "Check for multiple classes: Expected classes 'blog' and 'link', but not 'blogTest'" ); + assert.ok( jQuery( "#en" ).is( "[lang=\"en\"]" ), "Check for attribute: Expected attribute lang to be 'en'" ); + assert.ok( !jQuery( "#en" ).is( "[lang=\"de\"]" ), "Check for attribute: Expected attribute lang to be 'en', not 'de'" ); + assert.ok( jQuery( "#text1" ).is( "[type=\"text\"]" ), "Check for attribute: Expected attribute type to be 'text'" ); + assert.ok( !jQuery( "#text1" ).is( "[type=\"radio\"]" ), "Check for attribute: Expected attribute type to be 'text', not 'radio'" ); + assert.ok( jQuery( "#text2" ).is( ":disabled" ), "Check for pseudoclass: Expected to be disabled" ); + assert.ok( !jQuery( "#text1" ).is( ":disabled" ), "Check for pseudoclass: Expected not disabled" ); + assert.ok( jQuery( "#radio2" ).is( ":checked" ), "Check for pseudoclass: Expected to be checked" ); + assert.ok( !jQuery( "#radio1" ).is( ":checked" ), "Check for pseudoclass: Expected not checked" ); + + assert.ok( !jQuery( "#foo" ).is( 0 ), "Expected false for an invalid expression - 0" ); + assert.ok( !jQuery( "#foo" ).is( null ), "Expected false for an invalid expression - null" ); + assert.ok( !jQuery( "#foo" ).is( "" ), "Expected false for an invalid expression - \"\"" ); + assert.ok( !jQuery( "#foo" ).is( undefined ), "Expected false for an invalid expression - undefined" ); + assert.ok( !jQuery( "#foo" ).is( { plain: "object" } ), "Check passing invalid object" ); // test is() with comma-separated expressions - assert.ok( jQuery("#en").is("[lang=\"en\"],[lang=\"de\"]"), "Comma-separated; Check for lang attribute: Expect en or de" ); - assert.ok( jQuery("#en").is("[lang=\"de\"],[lang=\"en\"]"), "Comma-separated; Check for lang attribute: Expect en or de" ); - assert.ok( jQuery("#en").is("[lang=\"en\"] , [lang=\"de\"]"), "Comma-separated; Check for lang attribute: Expect en or de" ); - assert.ok( jQuery("#en").is("[lang=\"de\"] , [lang=\"en\"]"), "Comma-separated; Check for lang attribute: Expect en or de" ); -}); + assert.ok( jQuery( "#en" ).is( "[lang=\"en\"],[lang=\"de\"]" ), "Comma-separated; Check for lang attribute: Expect en or de" ); + assert.ok( jQuery( "#en" ).is( "[lang=\"de\"],[lang=\"en\"]" ), "Comma-separated; Check for lang attribute: Expect en or de" ); + assert.ok( jQuery( "#en" ).is( "[lang=\"en\"] , [lang=\"de\"]" ), "Comma-separated; Check for lang attribute: Expect en or de" ); + assert.ok( jQuery( "#en" ).is( "[lang=\"de\"] , [lang=\"en\"]" ), "Comma-separated; Check for lang attribute: Expect en or de" ); +} ); -QUnit.test("is() against non-elements (#10178)", function( assert ) { - assert.expect(14); +QUnit.test( "is() against non-elements (#10178)", function( assert ) { + assert.expect( 14 ); var label, i, test, collection = jQuery( document ), tests = [ "a", "*" ], nonelements = { - text: document.createTextNode(""), - comment: document.createComment(""), + text: document.createTextNode( "" ), + comment: document.createComment( "" ), document: document, window: window, array: [], @@ -103,47 +103,47 @@ QUnit.test("is() against non-elements (#10178)", function( assert ) { assert.ok( !collection.is( test ), label + " does not match \"" + test + "\"" ); } } -}); - -QUnit.test("is(jQuery)", function( assert ) { - assert.expect(19); - assert.ok( jQuery("#form").is( jQuery("form") ), "Check for element: A form is a form" ); - assert.ok( !jQuery("#form").is( jQuery("div") ), "Check for element: A form is not a div" ); - assert.ok( jQuery("#mark").is( jQuery(".blog") ), "Check for class: Expected class 'blog'" ); - assert.ok( !jQuery("#mark").is( jQuery(".link") ), "Check for class: Did not expect class 'link'" ); - assert.ok( jQuery("#simon").is( jQuery(".blog.link") ), "Check for multiple classes: Expected classes 'blog' and 'link'" ); - assert.ok( !jQuery("#simon").is( jQuery(".blogTest") ), "Check for multiple classes: Expected classes 'blog' and 'link', but not 'blogTest'" ); - assert.ok( jQuery("#en").is( jQuery("[lang=\"en\"]") ), "Check for attribute: Expected attribute lang to be 'en'" ); - assert.ok( !jQuery("#en").is( jQuery("[lang=\"de\"]") ), "Check for attribute: Expected attribute lang to be 'en', not 'de'" ); - assert.ok( jQuery("#text1").is( jQuery("[type=\"text\"]") ), "Check for attribute: Expected attribute type to be 'text'" ); - assert.ok( !jQuery("#text1").is( jQuery("[type=\"radio\"]") ), "Check for attribute: Expected attribute type to be 'text', not 'radio'" ); - assert.ok( !jQuery("#text1").is( jQuery("input:disabled") ), "Check for pseudoclass: Expected not disabled" ); - assert.ok( jQuery("#radio2").is( jQuery("input:checked") ), "Check for pseudoclass: Expected to be checked" ); - assert.ok( !jQuery("#radio1").is( jQuery("input:checked") ), "Check for pseudoclass: Expected not checked" ); +} ); + +QUnit.test( "is(jQuery)", function( assert ) { + assert.expect( 19 ); + assert.ok( jQuery( "#form" ).is( jQuery( "form" ) ), "Check for element: A form is a form" ); + assert.ok( !jQuery( "#form" ).is( jQuery( "div" ) ), "Check for element: A form is not a div" ); + assert.ok( jQuery( "#mark" ).is( jQuery( ".blog" ) ), "Check for class: Expected class 'blog'" ); + assert.ok( !jQuery( "#mark" ).is( jQuery( ".link" ) ), "Check for class: Did not expect class 'link'" ); + assert.ok( jQuery( "#simon" ).is( jQuery( ".blog.link" ) ), "Check for multiple classes: Expected classes 'blog' and 'link'" ); + assert.ok( !jQuery( "#simon" ).is( jQuery( ".blogTest" ) ), "Check for multiple classes: Expected classes 'blog' and 'link', but not 'blogTest'" ); + assert.ok( jQuery( "#en" ).is( jQuery( "[lang=\"en\"]" ) ), "Check for attribute: Expected attribute lang to be 'en'" ); + assert.ok( !jQuery( "#en" ).is( jQuery( "[lang=\"de\"]" ) ), "Check for attribute: Expected attribute lang to be 'en', not 'de'" ); + assert.ok( jQuery( "#text1" ).is( jQuery( "[type=\"text\"]" ) ), "Check for attribute: Expected attribute type to be 'text'" ); + assert.ok( !jQuery( "#text1" ).is( jQuery( "[type=\"radio\"]" ) ), "Check for attribute: Expected attribute type to be 'text', not 'radio'" ); + assert.ok( !jQuery( "#text1" ).is( jQuery( "input:disabled" ) ), "Check for pseudoclass: Expected not disabled" ); + assert.ok( jQuery( "#radio2" ).is( jQuery( "input:checked" ) ), "Check for pseudoclass: Expected to be checked" ); + assert.ok( !jQuery( "#radio1" ).is( jQuery( "input:checked" ) ), "Check for pseudoclass: Expected not checked" ); // Some raw elements - assert.ok( jQuery("#form").is( jQuery("#qunit-fixture form")[0] ), "Check for element: A form is a form" ); - assert.ok( !jQuery("#form").is( jQuery("div")[0] ), "Check for element: A form is not a div" ); - assert.ok( jQuery("#mark").is( jQuery(".blog")[0] ), "Check for class: Expected class 'blog'" ); - assert.ok( !jQuery("#mark").is( jQuery(".link")[0] ), "Check for class: Did not expect class 'link'" ); - assert.ok( jQuery("#simon").is( jQuery(".blog.link")[0] ), "Check for multiple classes: Expected classes 'blog' and 'link'" ); - assert.ok( !jQuery("#simon").is( jQuery(".blogTest")[0] ), "Check for multiple classes: Expected classes 'blog' and 'link', but not 'blogTest'" ); -}); + assert.ok( jQuery( "#form" ).is( jQuery( "#qunit-fixture form" )[ 0 ] ), "Check for element: A form is a form" ); + assert.ok( !jQuery( "#form" ).is( jQuery( "div" )[ 0 ] ), "Check for element: A form is not a div" ); + assert.ok( jQuery( "#mark" ).is( jQuery( ".blog" )[ 0 ] ), "Check for class: Expected class 'blog'" ); + assert.ok( !jQuery( "#mark" ).is( jQuery( ".link" )[ 0 ] ), "Check for class: Did not expect class 'link'" ); + assert.ok( jQuery( "#simon" ).is( jQuery( ".blog.link" )[ 0 ] ), "Check for multiple classes: Expected classes 'blog' and 'link'" ); + assert.ok( !jQuery( "#simon" ).is( jQuery( ".blogTest" )[ 0 ] ), "Check for multiple classes: Expected classes 'blog' and 'link', but not 'blogTest'" ); +} ); -QUnit.test("is() with :has() selectors", function( assert ) { - assert.expect(6); +QUnit.test( "is() with :has() selectors", function( assert ) { + assert.expect( 6 ); - assert.ok( jQuery("#foo").is(":has(p)"), "Check for child: Expected a child 'p' element" ); - assert.ok( !jQuery("#foo").is(":has(ul)"), "Check for child: Did not expect 'ul' element" ); - assert.ok( jQuery("#foo").is(":has(p):has(a):has(code)"), "Check for childs: Expected 'p', 'a' and 'code' child elements" ); - assert.ok( !jQuery("#foo").is(":has(p):has(a):has(code):has(ol)"), "Check for childs: Expected 'p', 'a' and 'code' child elements, but no 'ol'" ); + assert.ok( jQuery( "#foo" ).is( ":has(p)" ), "Check for child: Expected a child 'p' element" ); + assert.ok( !jQuery( "#foo" ).is( ":has(ul)" ), "Check for child: Did not expect 'ul' element" ); + assert.ok( jQuery( "#foo" ).is( ":has(p):has(a):has(code)" ), "Check for childs: Expected 'p', 'a' and 'code' child elements" ); + assert.ok( !jQuery( "#foo" ).is( ":has(p):has(a):has(code):has(ol)" ), "Check for childs: Expected 'p', 'a' and 'code' child elements, but no 'ol'" ); - assert.ok( jQuery("#foo").is( jQuery("div:has(p)") ), "Check for child: Expected a child 'p' element" ); - assert.ok( !jQuery("#foo").is( jQuery("div:has(ul)") ), "Check for child: Did not expect 'ul' element" ); -}); + assert.ok( jQuery( "#foo" ).is( jQuery( "div:has(p)" ) ), "Check for child: Expected a child 'p' element" ); + assert.ok( !jQuery( "#foo" ).is( jQuery( "div:has(ul)" ) ), "Check for child: Did not expect 'ul' element" ); +} ); -QUnit.test("is() with positional selectors", function( assert ) { - assert.expect(27); +QUnit.test( "is() with positional selectors", function( assert ) { + assert.expect( 27 ); var posp = jQuery( @@ -186,104 +186,103 @@ QUnit.test("is() with positional selectors", function( assert ) { isit( "#posp em", "#posp a em:last", true ); isit( "#posp em", "#posp a em:eq(2)", false ); - assert.ok( jQuery("#option1b").is("#select1 option:not(:first)"), "POS inside of :not() (#10970)" ); + assert.ok( jQuery( "#option1b" ).is( "#select1 option:not(:first)" ), "POS inside of :not() (#10970)" ); - assert.ok( jQuery( posp[0] ).is("p:last"), "context constructed from a single node (#13797)" ); - assert.ok( !jQuery( posp[0] ).find("#firsta").is("a:first"), "context derived from a single node (#13797)" ); -}); + assert.ok( jQuery( posp[ 0 ] ).is( "p:last" ), "context constructed from a single node (#13797)" ); + assert.ok( !jQuery( posp[ 0 ] ).find( "#firsta" ).is( "a:first" ), "context derived from a single node (#13797)" ); +} ); -QUnit.test("index()", function( assert ) { +QUnit.test( "index()", function( assert ) { assert.expect( 2 ); - assert.equal( jQuery("#text2").index(), 2, "Returns the index of a child amongst its siblings" ); + assert.equal( jQuery( "#text2" ).index(), 2, "Returns the index of a child amongst its siblings" ); - assert.equal( jQuery("<div/>").index(), -1, "Node without parent returns -1" ); -}); + assert.equal( jQuery( "<div/>" ).index(), -1, "Node without parent returns -1" ); +} ); -QUnit.test("index(Object|String|undefined)", function( assert ) { - assert.expect(16); +QUnit.test( "index(Object|String|undefined)", function( assert ) { + assert.expect( 16 ); - var elements = jQuery([window, document]), - inputElements = jQuery("#radio1,#radio2,#check1,#check2"); + var elements = jQuery( [ window, document ] ), + inputElements = jQuery( "#radio1,#radio2,#check1,#check2" ); // Passing a node - assert.equal( elements.index(window), 0, "Check for index of elements" ); - assert.equal( elements.index(document), 1, "Check for index of elements" ); - assert.equal( inputElements.index(document.getElementById("radio1")), 0, "Check for index of elements" ); - assert.equal( inputElements.index(document.getElementById("radio2")), 1, "Check for index of elements" ); - assert.equal( inputElements.index(document.getElementById("check1")), 2, "Check for index of elements" ); - assert.equal( inputElements.index(document.getElementById("check2")), 3, "Check for index of elements" ); - assert.equal( inputElements.index(window), -1, "Check for not found index" ); - assert.equal( inputElements.index(document), -1, "Check for not found index" ); + assert.equal( elements.index( window ), 0, "Check for index of elements" ); + assert.equal( elements.index( document ), 1, "Check for index of elements" ); + assert.equal( inputElements.index( document.getElementById( "radio1" ) ), 0, "Check for index of elements" ); + assert.equal( inputElements.index( document.getElementById( "radio2" ) ), 1, "Check for index of elements" ); + assert.equal( inputElements.index( document.getElementById( "check1" ) ), 2, "Check for index of elements" ); + assert.equal( inputElements.index( document.getElementById( "check2" ) ), 3, "Check for index of elements" ); + assert.equal( inputElements.index( window ), -1, "Check for not found index" ); + assert.equal( inputElements.index( document ), -1, "Check for not found index" ); // Passing a jQuery object // enabled since [5500] assert.equal( elements.index( elements ), 0, "Pass in a jQuery object" ); - assert.equal( elements.index( elements.eq(1) ), 1, "Pass in a jQuery object" ); - assert.equal( jQuery("#form input[type='radio']").index( jQuery("#radio2") ), 1, "Pass in a jQuery object" ); + assert.equal( elements.index( elements.eq( 1 ) ), 1, "Pass in a jQuery object" ); + assert.equal( jQuery( "#form input[type='radio']" ).index( jQuery( "#radio2" ) ), 1, "Pass in a jQuery object" ); // Passing a selector or nothing // enabled since [6330] - assert.equal( jQuery("#text2").index(), 2, "Check for index amongst siblings" ); - assert.equal( jQuery("#form").children().eq(4).index(), 4, "Check for index amongst siblings" ); - assert.equal( jQuery("#radio2").index("#form input[type='radio']") , 1, "Check for index within a selector" ); - assert.equal( jQuery("#form input[type='radio']").index( jQuery("#radio2") ), 1, "Check for index within a selector" ); - assert.equal( jQuery("#radio2").index("#form input[type='text']") , -1, "Check for index not found within a selector" ); -}); - -QUnit.test("filter(Selector|undefined)", function( assert ) { - assert.expect(9); - assert.deepEqual( jQuery("#form input").filter(":checked").get(), q("radio2", "check1"), "filter(String)" ); - assert.deepEqual( jQuery("p").filter("#ap, #sndp").get(), q("ap", "sndp"), "filter('String, String')" ); - assert.deepEqual( jQuery("p").filter("#ap,#sndp").get(), q("ap", "sndp"), "filter('String,String')" ); - - assert.deepEqual( jQuery("p").filter(null).get(), [], "filter(null) should return an empty jQuery object"); - assert.deepEqual( jQuery("p").filter(undefined).get(), [], "filter(undefined) should return an empty jQuery object"); - assert.deepEqual( jQuery("p").filter(0).get(), [], "filter(0) should return an empty jQuery object"); - assert.deepEqual( jQuery("p").filter("").get(), [], "filter('') should return an empty jQuery object"); + assert.equal( jQuery( "#text2" ).index(), 2, "Check for index amongst siblings" ); + assert.equal( jQuery( "#form" ).children().eq( 4 ).index(), 4, "Check for index amongst siblings" ); + assert.equal( jQuery( "#radio2" ).index( "#form input[type='radio']" ), 1, "Check for index within a selector" ); + assert.equal( jQuery( "#form input[type='radio']" ).index( jQuery( "#radio2" ) ), 1, "Check for index within a selector" ); + assert.equal( jQuery( "#radio2" ).index( "#form input[type='text']" ), -1, "Check for index not found within a selector" ); +} ); + +QUnit.test( "filter(Selector|undefined)", function( assert ) { + assert.expect( 9 ); + assert.deepEqual( jQuery( "#form input" ).filter( ":checked" ).get(), q( "radio2", "check1" ), "filter(String)" ); + assert.deepEqual( jQuery( "p" ).filter( "#ap, #sndp" ).get(), q( "ap", "sndp" ), "filter('String, String')" ); + assert.deepEqual( jQuery( "p" ).filter( "#ap,#sndp" ).get(), q( "ap", "sndp" ), "filter('String,String')" ); + + assert.deepEqual( jQuery( "p" ).filter( null ).get(), [], "filter(null) should return an empty jQuery object" ); + assert.deepEqual( jQuery( "p" ).filter( undefined ).get(), [], "filter(undefined) should return an empty jQuery object" ); + assert.deepEqual( jQuery( "p" ).filter( 0 ).get(), [], "filter(0) should return an empty jQuery object" ); + assert.deepEqual( jQuery( "p" ).filter( "" ).get(), [], "filter('') should return an empty jQuery object" ); // using contents will get comments regular, text, and comment nodes - var j = jQuery("#nonnodes").contents(); - assert.equal( j.filter("span").length, 1, "Check node,textnode,comment to filter the one span" ); - assert.equal( j.filter("[name]").length, 0, "Check node,textnode,comment to filter the one span" ); -}); + var j = jQuery( "#nonnodes" ).contents(); + assert.equal( j.filter( "span" ).length, 1, "Check node,textnode,comment to filter the one span" ); + assert.equal( j.filter( "[name]" ).length, 0, "Check node,textnode,comment to filter the one span" ); +} ); -QUnit.test("filter(Function)", function( assert ) { - assert.expect(2); - - assert.deepEqual( jQuery("#qunit-fixture p").filter(function() { - return !jQuery("a", this).length; - }).get(), q("sndp", "first"), "filter(Function)" ); +QUnit.test( "filter(Function)", function( assert ) { + assert.expect( 2 ); - assert.deepEqual( jQuery("#qunit-fixture p").filter(function(i, elem) { return !jQuery("a", elem).length; }).get(), q("sndp", "first"), "filter(Function) using arg" ); -}); + assert.deepEqual( jQuery( "#qunit-fixture p" ).filter( function() { + return !jQuery( "a", this ).length; + } ).get(), q( "sndp", "first" ), "filter(Function)" ); -QUnit.test("filter(Element)", function( assert ) { - assert.expect(1); + assert.deepEqual( jQuery( "#qunit-fixture p" ).filter( function( i, elem ) { return !jQuery( "a", elem ).length; } ).get(), q( "sndp", "first" ), "filter(Function) using arg" ); +} ); - var element = document.getElementById("text1"); - assert.deepEqual( jQuery("#form input").filter(element).get(), q("text1"), "filter(Element)" ); -}); +QUnit.test( "filter(Element)", function( assert ) { + assert.expect( 1 ); -QUnit.test("filter(Array)", function( assert ) { - assert.expect(1); + var element = document.getElementById( "text1" ); + assert.deepEqual( jQuery( "#form input" ).filter( element ).get(), q( "text1" ), "filter(Element)" ); +} ); - var elements = [ document.getElementById("text1") ]; - assert.deepEqual( jQuery("#form input").filter(elements).get(), q("text1"), "filter(Element)" ); -}); +QUnit.test( "filter(Array)", function( assert ) { + assert.expect( 1 ); -QUnit.test("filter(jQuery)", function( assert ) { - assert.expect(1); + var elements = [ document.getElementById( "text1" ) ]; + assert.deepEqual( jQuery( "#form input" ).filter( elements ).get(), q( "text1" ), "filter(Element)" ); +} ); - var elements = jQuery("#text1"); - assert.deepEqual( jQuery("#form input").filter(elements).get(), q("text1"), "filter(Element)" ); -}); +QUnit.test( "filter(jQuery)", function( assert ) { + assert.expect( 1 ); + var elements = jQuery( "#text1" ); + assert.deepEqual( jQuery( "#form input" ).filter( elements ).get(), q( "text1" ), "filter(Element)" ); +} ); -QUnit.test("filter() with positional selectors", function( assert ) { - assert.expect(19); +QUnit.test( "filter() with positional selectors", function( assert ) { + assert.expect( 19 ); - var filterit = function(sel, filter, length) { + var filterit = function( sel, filter, length ) { assert.equal( jQuery( sel ).filter( filter ).length, length, "jQuery( " + sel + " ).filter( " + filter + " )" ); }; @@ -298,7 +297,7 @@ QUnit.test("filter() with positional selectors", function( assert ) { "<em></em>" + "</p>" ).appendTo( "#qunit-fixture" ); - filterit( "#posp", "#posp:first", 1); + filterit( "#posp", "#posp:first", 1 ); filterit( "#posp", "#posp:eq(2)", 0 ); filterit( "#posp", "#posp a:first", 0 ); @@ -321,364 +320,364 @@ QUnit.test("filter() with positional selectors", function( assert ) { filterit( "#posp .seconda", "#posp a:gt(0)", 0 ); filterit( "#posp .seconda", "#posp a:lt(5)", 1 ); filterit( "#posp .seconda", "#posp a:lt(1)", 1 ); -}); +} ); -QUnit.test("closest()", function( assert ) { +QUnit.test( "closest()", function( assert ) { assert.expect( 13 ); var jq; - assert.deepEqual( jQuery("body").closest("body").get(), q("body"), "closest(body)" ); - assert.deepEqual( jQuery("body").closest("html").get(), q("html"), "closest(html)" ); - assert.deepEqual( jQuery("body").closest("div").get(), [], "closest(div)" ); - assert.deepEqual( jQuery("#qunit-fixture").closest("span,#html").get(), q("html"), "closest(span,#html)" ); + assert.deepEqual( jQuery( "body" ).closest( "body" ).get(), q( "body" ), "closest(body)" ); + assert.deepEqual( jQuery( "body" ).closest( "html" ).get(), q( "html" ), "closest(html)" ); + assert.deepEqual( jQuery( "body" ).closest( "div" ).get(), [], "closest(div)" ); + assert.deepEqual( jQuery( "#qunit-fixture" ).closest( "span,#html" ).get(), q( "html" ), "closest(span,#html)" ); // Test .closest() limited by the context - jq = jQuery("#nothiddendivchild"); - assert.deepEqual( jq.closest("html", document.body).get(), [], "Context limited." ); - assert.deepEqual( jq.closest("body", document.body).get(), [], "Context limited." ); - assert.deepEqual( jq.closest("#nothiddendiv", document.body).get(), q("nothiddendiv"), "Context not reached." ); + jq = jQuery( "#nothiddendivchild" ); + assert.deepEqual( jq.closest( "html", document.body ).get(), [], "Context limited." ); + assert.deepEqual( jq.closest( "body", document.body ).get(), [], "Context limited." ); + assert.deepEqual( jq.closest( "#nothiddendiv", document.body ).get(), q( "nothiddendiv" ), "Context not reached." ); //Test that .closest() returns unique'd set - assert.equal( jQuery("#qunit-fixture p").closest("#qunit-fixture").length, 1, "Closest should return a unique set" ); + assert.equal( jQuery( "#qunit-fixture p" ).closest( "#qunit-fixture" ).length, 1, "Closest should return a unique set" ); // Test on disconnected node - assert.equal( jQuery("<div><p></p></div>").find("p").closest("table").length, 0, "Make sure disconnected closest work." ); + assert.equal( jQuery( "<div><p></p></div>" ).find( "p" ).closest( "table" ).length, 0, "Make sure disconnected closest work." ); // Bug #7369 - assert.equal( jQuery("<div foo='bar'></div>").closest("[foo]").length, 1, "Disconnected nodes with attribute selector" ); - assert.equal( jQuery("<div>text</div>").closest("[lang]").length, 0, "Disconnected nodes with text and non-existent attribute selector" ); + assert.equal( jQuery( "<div foo='bar'></div>" ).closest( "[foo]" ).length, 1, "Disconnected nodes with attribute selector" ); + assert.equal( jQuery( "<div>text</div>" ).closest( "[lang]" ).length, 0, "Disconnected nodes with text and non-existent attribute selector" ); - assert.ok( !jQuery(document).closest("#foo").length, "Calling closest on a document fails silently" ); + assert.ok( !jQuery( document ).closest( "#foo" ).length, "Calling closest on a document fails silently" ); - jq = jQuery("<div>text</div>"); - assert.deepEqual( jq.contents().closest("*").get(), jq.get(), "Text node input (#13332)" ); -}); + jq = jQuery( "<div>text</div>" ); + assert.deepEqual( jq.contents().closest( "*" ).get(), jq.get(), "Text node input (#13332)" ); +} ); -QUnit.test("closest() with positional selectors", function( assert ) { +QUnit.test( "closest() with positional selectors", function( assert ) { assert.expect( 2 ); - assert.deepEqual( jQuery("#qunit-fixture").closest("div:first").get(), [], "closest(div:first)" ); - assert.deepEqual( jQuery("#qunit-fixture div").closest("body:first div:last").get(), q("fx-tests"), "closest(body:first div:last)" ); -}); - -QUnit.test("closest(jQuery)", function( assert ) { - assert.expect(8); - var $child = jQuery("#nothiddendivchild"), - $parent = jQuery("#nothiddendiv"), - $sibling = jQuery("#foo"), - $body = jQuery("body"); - assert.ok( $child.closest( $parent ).is("#nothiddendiv"), "closest( jQuery('#nothiddendiv') )" ); - assert.ok( $child.closest( $parent[0] ).is("#nothiddendiv"), "closest( jQuery('#nothiddendiv') ) :: node" ); - assert.ok( $child.closest( $child ).is("#nothiddendivchild"), "child is included" ); - assert.ok( $child.closest( $child[0] ).is("#nothiddendivchild"), "child is included :: node" ); - assert.equal( $child.closest( document.createElement("div") ).length, 0, "created element is not related" ); + assert.deepEqual( jQuery( "#qunit-fixture" ).closest( "div:first" ).get(), [], "closest(div:first)" ); + assert.deepEqual( jQuery( "#qunit-fixture div" ).closest( "body:first div:last" ).get(), q( "fx-tests" ), "closest(body:first div:last)" ); +} ); + +QUnit.test( "closest(jQuery)", function( assert ) { + assert.expect( 8 ); + var $child = jQuery( "#nothiddendivchild" ), + $parent = jQuery( "#nothiddendiv" ), + $sibling = jQuery( "#foo" ), + $body = jQuery( "body" ); + assert.ok( $child.closest( $parent ).is( "#nothiddendiv" ), "closest( jQuery('#nothiddendiv') )" ); + assert.ok( $child.closest( $parent[ 0 ] ).is( "#nothiddendiv" ), "closest( jQuery('#nothiddendiv') ) :: node" ); + assert.ok( $child.closest( $child ).is( "#nothiddendivchild" ), "child is included" ); + assert.ok( $child.closest( $child[ 0 ] ).is( "#nothiddendivchild" ), "child is included :: node" ); + assert.equal( $child.closest( document.createElement( "div" ) ).length, 0, "created element is not related" ); assert.equal( $child.closest( $sibling ).length, 0, "Sibling not a parent of child" ); - assert.equal( $child.closest( $sibling[0] ).length, 0, "Sibling not a parent of child :: node" ); - assert.ok( $child.closest( $body.add($parent) ).is("#nothiddendiv"), "Closest ancestor retrieved." ); -}); - -QUnit.test("not(Selector|undefined)", function( assert ) { - assert.expect(11); - assert.equal( jQuery("#qunit-fixture > p#ap > a").not("#google").length, 2, "not('selector')" ); - assert.deepEqual( jQuery("p").not(".result").get(), q("firstp", "ap", "sndp", "en", "sap", "first"), "not('.class')" ); - assert.deepEqual( jQuery("p").not("#ap, #sndp, .result").get(), q("firstp", "en", "sap", "first"), "not('selector, selector')" ); - - assert.deepEqual( jQuery("#ap *").not("code").get(), q("google", "groups", "anchor1", "mark"), "not('tag selector')" ); - assert.deepEqual( jQuery("#ap *").not("code, #mark").get(), q("google", "groups", "anchor1"), "not('tag, ID selector')" ); - assert.deepEqual( jQuery("#ap *").not("#mark, code").get(), q("google", "groups", "anchor1"), "not('ID, tag selector')"); - - var all = jQuery("p").get(); - assert.deepEqual( jQuery("p").not(null).get(), all, "not(null) should have no effect"); - assert.deepEqual( jQuery("p").not(undefined).get(), all, "not(undefined) should have no effect"); - assert.deepEqual( jQuery("p").not(0).get(), all, "not(0) should have no effect"); - assert.deepEqual( jQuery("p").not("").get(), all, "not('') should have no effect"); + assert.equal( $child.closest( $sibling[ 0 ] ).length, 0, "Sibling not a parent of child :: node" ); + assert.ok( $child.closest( $body.add( $parent ) ).is( "#nothiddendiv" ), "Closest ancestor retrieved." ); +} ); + +QUnit.test( "not(Selector|undefined)", function( assert ) { + assert.expect( 11 ); + assert.equal( jQuery( "#qunit-fixture > p#ap > a" ).not( "#google" ).length, 2, "not('selector')" ); + assert.deepEqual( jQuery( "p" ).not( ".result" ).get(), q( "firstp", "ap", "sndp", "en", "sap", "first" ), "not('.class')" ); + assert.deepEqual( jQuery( "p" ).not( "#ap, #sndp, .result" ).get(), q( "firstp", "en", "sap", "first" ), "not('selector, selector')" ); + + assert.deepEqual( jQuery( "#ap *" ).not( "code" ).get(), q( "google", "groups", "anchor1", "mark" ), "not('tag selector')" ); + assert.deepEqual( jQuery( "#ap *" ).not( "code, #mark" ).get(), q( "google", "groups", "anchor1" ), "not('tag, ID selector')" ); + assert.deepEqual( jQuery( "#ap *" ).not( "#mark, code" ).get(), q( "google", "groups", "anchor1" ), "not('ID, tag selector')" ); + + var all = jQuery( "p" ).get(); + assert.deepEqual( jQuery( "p" ).not( null ).get(), all, "not(null) should have no effect" ); + assert.deepEqual( jQuery( "p" ).not( undefined ).get(), all, "not(undefined) should have no effect" ); + assert.deepEqual( jQuery( "p" ).not( 0 ).get(), all, "not(0) should have no effect" ); + assert.deepEqual( jQuery( "p" ).not( "" ).get(), all, "not('') should have no effect" ); assert.deepEqual( - jQuery("#form option").not("option.emptyopt:contains('Nothing'),optgroup *,[value='1']").get(), - q("option1c", "option1d", "option2c", "option2d", "option3c", "option3d", "option3e", "option4d", "option4e", "option5a", "option5b"), + jQuery( "#form option" ).not( "option.emptyopt:contains('Nothing'),optgroup *,[value='1']" ).get(), + q( "option1c", "option1d", "option2c", "option2d", "option3c", "option3d", "option3e", "option4d", "option4e", "option5a", "option5b" ), "not('complex selector')" ); -}); +} ); -QUnit.test("not(Element)", function( assert ) { - assert.expect(1); +QUnit.test( "not(Element)", function( assert ) { + assert.expect( 1 ); - var selects = jQuery("#form select"); - assert.deepEqual( selects.not( selects[1] ).get(), q("select1", "select3", "select4", "select5"), "filter out DOM element"); -}); + var selects = jQuery( "#form select" ); + assert.deepEqual( selects.not( selects[ 1 ] ).get(), q( "select1", "select3", "select4", "select5" ), "filter out DOM element" ); +} ); -QUnit.test("not(Function)", function( assert ) { - assert.expect(1); +QUnit.test( "not(Function)", function( assert ) { + assert.expect( 1 ); - assert.deepEqual( jQuery("#qunit-fixture p").not(function() { return jQuery("a", this).length; }).get(), q("sndp", "first"), "not(Function)" ); -}); + assert.deepEqual( jQuery( "#qunit-fixture p" ).not( function() { return jQuery( "a", this ).length; } ).get(), q( "sndp", "first" ), "not(Function)" ); +} ); -QUnit.test("not(Array)", function( assert ) { - assert.expect(2); +QUnit.test( "not(Array)", function( assert ) { + assert.expect( 2 ); - assert.equal( jQuery("#qunit-fixture > p#ap > a").not(document.getElementById("google")).length, 2, "not(DOMElement)" ); - assert.equal( jQuery("p").not(document.getElementsByTagName("p")).length, 0, "not(Array-like DOM collection)" ); -}); + assert.equal( jQuery( "#qunit-fixture > p#ap > a" ).not( document.getElementById( "google" ) ).length, 2, "not(DOMElement)" ); + assert.equal( jQuery( "p" ).not( document.getElementsByTagName( "p" ) ).length, 0, "not(Array-like DOM collection)" ); +} ); -QUnit.test("not(jQuery)", function( assert ) { +QUnit.test( "not(jQuery)", function( assert ) { assert.expect( 1 ); - assert.deepEqual( jQuery("p").not(jQuery("#ap, #sndp, .result")).get(), q("firstp", "en", "sap", "first"), "not(jQuery)" ); -}); + assert.deepEqual( jQuery( "p" ).not( jQuery( "#ap, #sndp, .result" ) ).get(), q( "firstp", "en", "sap", "first" ), "not(jQuery)" ); +} ); -QUnit.test("has(Element)", function( assert ) { - assert.expect(3); +QUnit.test( "has(Element)", function( assert ) { + assert.expect( 3 ); var obj, detached, multipleParent; - obj = jQuery("#qunit-fixture").has(jQuery("#sndp")[0]); - assert.deepEqual( obj.get(), q("qunit-fixture"), "Keeps elements that have the element as a descendant" ); + obj = jQuery( "#qunit-fixture" ).has( jQuery( "#sndp" )[ 0 ] ); + assert.deepEqual( obj.get(), q( "qunit-fixture" ), "Keeps elements that have the element as a descendant" ); - detached = jQuery("<a><b><i/></b></a>"); - assert.deepEqual( detached.has( detached.find("i")[0] ).get(), detached.get(), "...Even when detached" ); + detached = jQuery( "<a><b><i/></b></a>" ); + assert.deepEqual( detached.has( detached.find( "i" )[ 0 ] ).get(), detached.get(), "...Even when detached" ); - multipleParent = jQuery("#qunit-fixture, #header").has(jQuery("#sndp")[0]); - assert.deepEqual( multipleParent.get(), q("qunit-fixture"), "Does not include elements that do not have the element as a descendant" ); -}); + multipleParent = jQuery( "#qunit-fixture, #header" ).has( jQuery( "#sndp" )[ 0 ] ); + assert.deepEqual( multipleParent.get(), q( "qunit-fixture" ), "Does not include elements that do not have the element as a descendant" ); +} ); -QUnit.test("has(Selector)", function( assert ) { +QUnit.test( "has(Selector)", function( assert ) { assert.expect( 5 ); var obj, detached, multipleParent, multipleHas; - obj = jQuery("#qunit-fixture").has("#sndp"); - assert.deepEqual( obj.get(), q("qunit-fixture"), "Keeps elements that have any element matching the selector as a descendant" ); + obj = jQuery( "#qunit-fixture" ).has( "#sndp" ); + assert.deepEqual( obj.get(), q( "qunit-fixture" ), "Keeps elements that have any element matching the selector as a descendant" ); - detached = jQuery("<a><b><i/></b></a>"); - assert.deepEqual( detached.has("i").get(), detached.get(), "...Even when detached" ); + detached = jQuery( "<a><b><i/></b></a>" ); + assert.deepEqual( detached.has( "i" ).get(), detached.get(), "...Even when detached" ); - multipleParent = jQuery("#qunit-fixture, #header").has("#sndp"); - assert.deepEqual( multipleParent.get(), q("qunit-fixture"), "Does not include elements that do not have the element as a descendant" ); + multipleParent = jQuery( "#qunit-fixture, #header" ).has( "#sndp" ); + assert.deepEqual( multipleParent.get(), q( "qunit-fixture" ), "Does not include elements that do not have the element as a descendant" ); - multipleParent = jQuery("#select1, #select2, #select3").has("#option1a, #option3a"); - assert.deepEqual( multipleParent.get(), q("select1", "select3"), "Multiple contexts are checks correctly" ); + multipleParent = jQuery( "#select1, #select2, #select3" ).has( "#option1a, #option3a" ); + assert.deepEqual( multipleParent.get(), q( "select1", "select3" ), "Multiple contexts are checks correctly" ); - multipleHas = jQuery("#qunit-fixture").has("#sndp, #first"); - assert.deepEqual( multipleHas.get(), q("qunit-fixture"), "Only adds elements once" ); -}); + multipleHas = jQuery( "#qunit-fixture" ).has( "#sndp, #first" ); + assert.deepEqual( multipleHas.get(), q( "qunit-fixture" ), "Only adds elements once" ); +} ); -QUnit.test("has(Arrayish)", function( assert ) { - assert.expect(4); +QUnit.test( "has(Arrayish)", function( assert ) { + assert.expect( 4 ); var simple, detached, multipleParent, multipleHas; - simple = jQuery("#qunit-fixture").has(jQuery("#sndp")); - assert.deepEqual( simple.get(), q("qunit-fixture"), "Keeps elements that have any element in the jQuery list as a descendant" ); - - detached = jQuery("<a><b><i/></b></a>"); - assert.deepEqual( detached.has( detached.find("i") ).get(), detached.get(), "...Even when detached" ); - - multipleParent = jQuery("#qunit-fixture, #header").has(jQuery("#sndp")); - assert.deepEqual( multipleParent.get(), q("qunit-fixture"), "Does not include elements that do not have an element in the jQuery list as a descendant" ); - - multipleHas = jQuery("#qunit-fixture").has(jQuery("#sndp, #first")); - assert.deepEqual( multipleHas.get(), q("qunit-fixture"), "Only adds elements once" ); -}); - -QUnit.test("addBack()", function( assert ) { - assert.expect(5); - assert.deepEqual( jQuery("#en").siblings().addBack().get(), q("sndp", "en", "sap"), "Check for siblings and self" ); - assert.deepEqual( jQuery("#foo").children().addBack().get(), q("foo", "sndp", "en", "sap"), "Check for children and self" ); - assert.deepEqual( jQuery("#sndp, #en").parent().addBack().get(), q("foo","sndp","en"), "Check for parent and self" ); - assert.deepEqual( jQuery("#groups").parents("p, div").addBack().get(), q("qunit-fixture", "ap", "groups"), "Check for parents and self" ); - assert.deepEqual( jQuery("#select1 > option").filter(":first-child").addBack(":last-child").get(), q("option1a", "option1d"), "Should contain the last elems plus the *filtered* prior set elements" ); -}); - -QUnit.test("siblings([String])", function( assert ) { - assert.expect(6); - assert.deepEqual( jQuery("#en").siblings().get(), q("sndp", "sap"), "Check for siblings" ); - assert.deepEqual( jQuery("#nonnodes").contents().eq(1).siblings().get(), q("nonnodesElement"), "Check for text node siblings" ); - assert.deepEqual( jQuery("#foo").siblings("form, b").get(), q("form", "floatTest", "lengthtest", "name-tests", "testForm"), "Check for multiple filters" ); - - var set = q("sndp", "en", "sap"); - assert.deepEqual( jQuery("#en, #sndp").siblings().get(), set, "Check for unique results from siblings" ); - assert.deepEqual( jQuery("#option5a").siblings("option[data-attr]").get(), q("option5c"), "Has attribute selector in siblings (#9261)" ); - assert.equal( jQuery("<a/>").siblings().length, 0, "Detached elements have no siblings (#11370)" ); -}); - -QUnit.test("siblings([String]) - jQuery only", function( assert ) { - assert.expect(2); - assert.deepEqual( jQuery("#sndp").siblings(":has(code)").get(), q("sap"), "Check for filtered siblings (has code child element)" ); - assert.deepEqual( jQuery("#sndp").siblings(":has(a)").get(), q("en", "sap"), "Check for filtered siblings (has anchor child element)" ); -}); - -QUnit.test("children([String])", function( assert ) { - assert.expect(2); - assert.deepEqual( jQuery("#foo").children().get(), q("sndp", "en", "sap"), "Check for children" ); - assert.deepEqual( jQuery("#foo").children("#en, #sap").get(), q("en", "sap"), "Check for multiple filters" ); -}); - -QUnit.test("children([String]) - jQuery only", function( assert ) { - assert.expect(1); - assert.deepEqual( jQuery("#foo").children(":has(code)").get(), q("sndp", "sap"), "Check for filtered children" ); -}); - -QUnit.test("parent([String])", function( assert ) { - assert.expect(6); + simple = jQuery( "#qunit-fixture" ).has( jQuery( "#sndp" ) ); + assert.deepEqual( simple.get(), q( "qunit-fixture" ), "Keeps elements that have any element in the jQuery list as a descendant" ); + + detached = jQuery( "<a><b><i/></b></a>" ); + assert.deepEqual( detached.has( detached.find( "i" ) ).get(), detached.get(), "...Even when detached" ); + + multipleParent = jQuery( "#qunit-fixture, #header" ).has( jQuery( "#sndp" ) ); + assert.deepEqual( multipleParent.get(), q( "qunit-fixture" ), "Does not include elements that do not have an element in the jQuery list as a descendant" ); + + multipleHas = jQuery( "#qunit-fixture" ).has( jQuery( "#sndp, #first" ) ); + assert.deepEqual( multipleHas.get(), q( "qunit-fixture" ), "Only adds elements once" ); +} ); + +QUnit.test( "addBack()", function( assert ) { + assert.expect( 5 ); + assert.deepEqual( jQuery( "#en" ).siblings().addBack().get(), q( "sndp", "en", "sap" ), "Check for siblings and self" ); + assert.deepEqual( jQuery( "#foo" ).children().addBack().get(), q( "foo", "sndp", "en", "sap" ), "Check for children and self" ); + assert.deepEqual( jQuery( "#sndp, #en" ).parent().addBack().get(), q( "foo", "sndp", "en" ), "Check for parent and self" ); + assert.deepEqual( jQuery( "#groups" ).parents( "p, div" ).addBack().get(), q( "qunit-fixture", "ap", "groups" ), "Check for parents and self" ); + assert.deepEqual( jQuery( "#select1 > option" ).filter( ":first-child" ).addBack( ":last-child" ).get(), q( "option1a", "option1d" ), "Should contain the last elems plus the *filtered* prior set elements" ); +} ); + +QUnit.test( "siblings([String])", function( assert ) { + assert.expect( 6 ); + assert.deepEqual( jQuery( "#en" ).siblings().get(), q( "sndp", "sap" ), "Check for siblings" ); + assert.deepEqual( jQuery( "#nonnodes" ).contents().eq( 1 ).siblings().get(), q( "nonnodesElement" ), "Check for text node siblings" ); + assert.deepEqual( jQuery( "#foo" ).siblings( "form, b" ).get(), q( "form", "floatTest", "lengthtest", "name-tests", "testForm" ), "Check for multiple filters" ); + + var set = q( "sndp", "en", "sap" ); + assert.deepEqual( jQuery( "#en, #sndp" ).siblings().get(), set, "Check for unique results from siblings" ); + assert.deepEqual( jQuery( "#option5a" ).siblings( "option[data-attr]" ).get(), q( "option5c" ), "Has attribute selector in siblings (#9261)" ); + assert.equal( jQuery( "<a/>" ).siblings().length, 0, "Detached elements have no siblings (#11370)" ); +} ); + +QUnit.test( "siblings([String]) - jQuery only", function( assert ) { + assert.expect( 2 ); + assert.deepEqual( jQuery( "#sndp" ).siblings( ":has(code)" ).get(), q( "sap" ), "Check for filtered siblings (has code child element)" ); + assert.deepEqual( jQuery( "#sndp" ).siblings( ":has(a)" ).get(), q( "en", "sap" ), "Check for filtered siblings (has anchor child element)" ); +} ); + +QUnit.test( "children([String])", function( assert ) { + assert.expect( 2 ); + assert.deepEqual( jQuery( "#foo" ).children().get(), q( "sndp", "en", "sap" ), "Check for children" ); + assert.deepEqual( jQuery( "#foo" ).children( "#en, #sap" ).get(), q( "en", "sap" ), "Check for multiple filters" ); +} ); + +QUnit.test( "children([String]) - jQuery only", function( assert ) { + assert.expect( 1 ); + assert.deepEqual( jQuery( "#foo" ).children( ":has(code)" ).get(), q( "sndp", "sap" ), "Check for filtered children" ); +} ); + +QUnit.test( "parent([String])", function( assert ) { + assert.expect( 6 ); var $el; - assert.equal( jQuery("#groups").parent()[0].id, "ap", "Simple parent check" ); - assert.equal( jQuery("#groups").parent("p")[0].id, "ap", "Filtered parent check" ); - assert.equal( jQuery("#groups").parent("div").length, 0, "Filtered parent check, no match" ); - assert.equal( jQuery("#groups").parent("div, p")[0].id, "ap", "Check for multiple filters" ); - assert.deepEqual( jQuery("#en, #sndp").parent().get(), q("foo"), "Check for unique results from parent" ); + assert.equal( jQuery( "#groups" ).parent()[ 0 ].id, "ap", "Simple parent check" ); + assert.equal( jQuery( "#groups" ).parent( "p" )[ 0 ].id, "ap", "Filtered parent check" ); + assert.equal( jQuery( "#groups" ).parent( "div" ).length, 0, "Filtered parent check, no match" ); + assert.equal( jQuery( "#groups" ).parent( "div, p" )[ 0 ].id, "ap", "Check for multiple filters" ); + assert.deepEqual( jQuery( "#en, #sndp" ).parent().get(), q( "foo" ), "Check for unique results from parent" ); - $el = jQuery("<div>text</div>"); + $el = jQuery( "<div>text</div>" ); assert.deepEqual( $el.contents().parent().get(), $el.get(), "Check for parent of text node (#13265)" ); -}); - -QUnit.test("parents([String])", function( assert ) { - assert.expect(6); - assert.equal( jQuery("#groups").parents()[0].id, "ap", "Simple parents check" ); - assert.deepEqual( jQuery("#nonnodes").contents().eq(1).parents().eq(0).get(), q("nonnodes"), "Text node parents check" ); - assert.equal( jQuery("#groups").parents("p")[0].id, "ap", "Filtered parents check" ); - assert.equal( jQuery("#groups").parents("div")[0].id, "qunit-fixture", "Filtered parents check2" ); - assert.deepEqual( jQuery("#groups").parents("p, div").get(), q("ap", "qunit-fixture"), "Check for multiple filters" ); - assert.deepEqual( jQuery("#en, #sndp").parents().get(), q("foo", "qunit-fixture", "dl", "body", "html"), "Check for unique results from parents" ); -}); - -QUnit.test("parentsUntil([String])", function( assert ) { - assert.expect(10); - - var parents = jQuery("#groups").parents(); - - assert.deepEqual( jQuery("#groups").parentsUntil().get(), parents.get(), "parentsUntil with no selector (nextAll)" ); - assert.deepEqual( jQuery("#groups").parentsUntil(".foo").get(), parents.get(), "parentsUntil with invalid selector (nextAll)" ); - assert.deepEqual( jQuery("#groups").parentsUntil("#html").get(), parents.slice(0, -1).get(), "Simple parentsUntil check" ); - assert.equal( jQuery("#groups").parentsUntil("#ap").length, 0, "Simple parentsUntil check" ); - assert.deepEqual( jQuery("#nonnodes").contents().eq(1).parentsUntil("#html").eq(0).get(), q("nonnodes"), "Text node parentsUntil check" ); - assert.deepEqual( jQuery("#groups").parentsUntil("#html, #body").get(), parents.slice( 0, 3 ).get(), "Less simple parentsUntil check" ); - assert.deepEqual( jQuery("#groups").parentsUntil("#html", "div").get(), jQuery("#qunit-fixture").get(), "Filtered parentsUntil check" ); - assert.deepEqual( jQuery("#groups").parentsUntil("#html", "p,div,dl").get(), parents.slice( 0, 3 ).get(), "Multiple-filtered parentsUntil check" ); - assert.equal( jQuery("#groups").parentsUntil("#html", "span").length, 0, "Filtered parentsUntil check, no match" ); - assert.deepEqual( jQuery("#groups, #ap").parentsUntil("#html", "p,div,dl").get(), parents.slice( 0, 3 ).get(), "Multi-source, multiple-filtered parentsUntil check" ); -}); - -QUnit.test("next([String])", function( assert ) { - assert.expect(6); - assert.equal( jQuery("#ap").next()[0].id, "foo", "Simple next check" ); - assert.equal( jQuery("<div>text<a id='element'></a></div>").contents().eq(0).next().attr("id"), "element", "Text node next check" ); - assert.equal( jQuery("#ap").next("div")[0].id, "foo", "Filtered next check" ); - assert.equal( jQuery("#ap").next("p").length, 0, "Filtered next check, no match" ); - assert.equal( jQuery("#ap").next("div, p")[0].id, "foo", "Multiple filters" ); - assert.equal( jQuery("body").next().length, 0, "Simple next check, no match" ); -}); - -QUnit.test("prev([String])", function( assert ) { - assert.expect(5); - assert.equal( jQuery("#foo").prev()[0].id, "ap", "Simple prev check" ); - assert.deepEqual( jQuery("#nonnodes").contents().eq(1).prev().get(), q("nonnodesElement"), "Text node prev check" ); - assert.equal( jQuery("#foo").prev("p")[0].id, "ap", "Filtered prev check" ); - assert.equal( jQuery("#foo").prev("div").length, 0, "Filtered prev check, no match" ); - assert.equal( jQuery("#foo").prev("p, div")[0].id, "ap", "Multiple filters" ); -}); - -QUnit.test("nextAll([String])", function( assert ) { - assert.expect(5); - - var elems = jQuery("#form").children(); - - assert.deepEqual( jQuery("#label-for").nextAll().get(), elems.slice(1).get(), "Simple nextAll check" ); - assert.equal( jQuery("<div>text<a id='element'></a></div>").contents().eq(0).nextAll().attr("id"), "element", "Text node nextAll check" ); - assert.deepEqual( jQuery("#label-for").nextAll("input").get(), elems.slice(1).filter("input").get(), "Filtered nextAll check" ); - assert.deepEqual( jQuery("#label-for").nextAll("input,select").get(), elems.slice(1).filter("input,select").get(), "Multiple-filtered nextAll check" ); - assert.deepEqual( jQuery("#label-for, #hidden1").nextAll("input,select").get(), elems.slice(1).filter("input,select").get(), "Multi-source, multiple-filtered nextAll check" ); -}); - -QUnit.test("prevAll([String])", function( assert ) { - assert.expect(5); - - var elems = jQuery( jQuery("#form").children().slice(0, 12).get().reverse() ); - - assert.deepEqual( jQuery("#area1").prevAll().get(), elems.get(), "Simple prevAll check" ); - assert.deepEqual( jQuery("#nonnodes").contents().eq(1).prevAll().get(), q("nonnodesElement"), "Text node prevAll check" ); - assert.deepEqual( jQuery("#area1").prevAll("input").get(), elems.filter("input").get(), "Filtered prevAll check" ); - assert.deepEqual( jQuery("#area1").prevAll("input,select").get(), elems.filter("input,select").get(), "Multiple-filtered prevAll check" ); - assert.deepEqual( jQuery("#area1, #hidden1").prevAll("input,select").get(), elems.filter("input,select").get(), "Multi-source, multiple-filtered prevAll check" ); -}); - -QUnit.test("nextUntil([String])", function( assert ) { - assert.expect(12); - - var elems = jQuery("#form").children().slice( 2, 12 ); - - assert.deepEqual( jQuery("#text1").nextUntil().get(), jQuery("#text1").nextAll().get(), "nextUntil with no selector (nextAll)" ); - assert.equal( jQuery("<div>text<a id='element'></a></div>").contents().eq(0).nextUntil().attr("id"), "element", "Text node nextUntil with no selector (nextAll)" ); - assert.deepEqual( jQuery("#text1").nextUntil(".foo").get(), jQuery("#text1").nextAll().get(), "nextUntil with invalid selector (nextAll)" ); - assert.deepEqual( jQuery("#text1").nextUntil("#area1").get(), elems.get(), "Simple nextUntil check" ); - assert.equal( jQuery("#text1").nextUntil("#text2").length, 0, "Simple nextUntil check" ); - assert.deepEqual( jQuery("#text1").nextUntil("#area1, #radio1").get(), jQuery("#text1").next().get(), "Less simple nextUntil check" ); - assert.deepEqual( jQuery("#text1").nextUntil("#area1", "input").get(), elems.not("button").get(), "Filtered nextUntil check" ); - assert.deepEqual( jQuery("#text1").nextUntil("#area1", "button").get(), elems.not("input").get(), "Filtered nextUntil check" ); - assert.deepEqual( jQuery("#text1").nextUntil("#area1", "button,input").get(), elems.get(), "Multiple-filtered nextUntil check" ); - assert.equal( jQuery("#text1").nextUntil("#area1", "div").length, 0, "Filtered nextUntil check, no match" ); - assert.deepEqual( jQuery("#text1, #hidden1").nextUntil("#area1", "button,input").get(), elems.get(), "Multi-source, multiple-filtered nextUntil check" ); - - assert.deepEqual( jQuery("#text1").nextUntil("[class=foo]").get(), jQuery("#text1").nextAll().get(), "Non-element nodes must be skipped, since they have no attributes" ); -}); - -QUnit.test("prevUntil([String])", function( assert ) { - assert.expect(11); - - var elems = jQuery("#area1").prevAll(); - - assert.deepEqual( jQuery("#area1").prevUntil().get(), elems.get(), "prevUntil with no selector (prevAll)" ); - assert.deepEqual( jQuery("#nonnodes").contents().eq(1).prevUntil().get(), q("nonnodesElement"), "Text node prevUntil with no selector (prevAll)" ); - assert.deepEqual( jQuery("#area1").prevUntil(".foo").get(), elems.get(), "prevUntil with invalid selector (prevAll)" ); - assert.deepEqual( jQuery("#area1").prevUntil("label").get(), elems.slice(0, -1).get(), "Simple prevUntil check" ); - assert.equal( jQuery("#area1").prevUntil("#button").length, 0, "Simple prevUntil check" ); - assert.deepEqual( jQuery("#area1").prevUntil("label, #search").get(), jQuery("#area1").prev().get(), "Less simple prevUntil check" ); - assert.deepEqual( jQuery("#area1").prevUntil("label", "input").get(), elems.slice(0, -1).not("button").get(), "Filtered prevUntil check" ); - assert.deepEqual( jQuery("#area1").prevUntil("label", "button").get(), elems.slice(0, -1).not("input").get(), "Filtered prevUntil check" ); - assert.deepEqual( jQuery("#area1").prevUntil("label", "button,input").get(), elems.slice(0, -1).get(), "Multiple-filtered prevUntil check" ); - assert.equal( jQuery("#area1").prevUntil("label", "div").length, 0, "Filtered prevUntil check, no match" ); - assert.deepEqual( jQuery("#area1, #hidden1").prevUntil("label", "button,input").get(), elems.slice(0, -1).get(), "Multi-source, multiple-filtered prevUntil check" ); -}); - -QUnit.test("contents()", function( assert ) { - assert.expect(12); +} ); + +QUnit.test( "parents([String])", function( assert ) { + assert.expect( 6 ); + assert.equal( jQuery( "#groups" ).parents()[ 0 ].id, "ap", "Simple parents check" ); + assert.deepEqual( jQuery( "#nonnodes" ).contents().eq( 1 ).parents().eq( 0 ).get(), q( "nonnodes" ), "Text node parents check" ); + assert.equal( jQuery( "#groups" ).parents( "p" )[ 0 ].id, "ap", "Filtered parents check" ); + assert.equal( jQuery( "#groups" ).parents( "div" )[ 0 ].id, "qunit-fixture", "Filtered parents check2" ); + assert.deepEqual( jQuery( "#groups" ).parents( "p, div" ).get(), q( "ap", "qunit-fixture" ), "Check for multiple filters" ); + assert.deepEqual( jQuery( "#en, #sndp" ).parents().get(), q( "foo", "qunit-fixture", "dl", "body", "html" ), "Check for unique results from parents" ); +} ); + +QUnit.test( "parentsUntil([String])", function( assert ) { + assert.expect( 10 ); + + var parents = jQuery( "#groups" ).parents(); + + assert.deepEqual( jQuery( "#groups" ).parentsUntil().get(), parents.get(), "parentsUntil with no selector (nextAll)" ); + assert.deepEqual( jQuery( "#groups" ).parentsUntil( ".foo" ).get(), parents.get(), "parentsUntil with invalid selector (nextAll)" ); + assert.deepEqual( jQuery( "#groups" ).parentsUntil( "#html" ).get(), parents.slice( 0, -1 ).get(), "Simple parentsUntil check" ); + assert.equal( jQuery( "#groups" ).parentsUntil( "#ap" ).length, 0, "Simple parentsUntil check" ); + assert.deepEqual( jQuery( "#nonnodes" ).contents().eq( 1 ).parentsUntil( "#html" ).eq( 0 ).get(), q( "nonnodes" ), "Text node parentsUntil check" ); + assert.deepEqual( jQuery( "#groups" ).parentsUntil( "#html, #body" ).get(), parents.slice( 0, 3 ).get(), "Less simple parentsUntil check" ); + assert.deepEqual( jQuery( "#groups" ).parentsUntil( "#html", "div" ).get(), jQuery( "#qunit-fixture" ).get(), "Filtered parentsUntil check" ); + assert.deepEqual( jQuery( "#groups" ).parentsUntil( "#html", "p,div,dl" ).get(), parents.slice( 0, 3 ).get(), "Multiple-filtered parentsUntil check" ); + assert.equal( jQuery( "#groups" ).parentsUntil( "#html", "span" ).length, 0, "Filtered parentsUntil check, no match" ); + assert.deepEqual( jQuery( "#groups, #ap" ).parentsUntil( "#html", "p,div,dl" ).get(), parents.slice( 0, 3 ).get(), "Multi-source, multiple-filtered parentsUntil check" ); +} ); + +QUnit.test( "next([String])", function( assert ) { + assert.expect( 6 ); + assert.equal( jQuery( "#ap" ).next()[ 0 ].id, "foo", "Simple next check" ); + assert.equal( jQuery( "<div>text<a id='element'></a></div>" ).contents().eq( 0 ).next().attr( "id" ), "element", "Text node next check" ); + assert.equal( jQuery( "#ap" ).next( "div" )[ 0 ].id, "foo", "Filtered next check" ); + assert.equal( jQuery( "#ap" ).next( "p" ).length, 0, "Filtered next check, no match" ); + assert.equal( jQuery( "#ap" ).next( "div, p" )[ 0 ].id, "foo", "Multiple filters" ); + assert.equal( jQuery( "body" ).next().length, 0, "Simple next check, no match" ); +} ); + +QUnit.test( "prev([String])", function( assert ) { + assert.expect( 5 ); + assert.equal( jQuery( "#foo" ).prev()[ 0 ].id, "ap", "Simple prev check" ); + assert.deepEqual( jQuery( "#nonnodes" ).contents().eq( 1 ).prev().get(), q( "nonnodesElement" ), "Text node prev check" ); + assert.equal( jQuery( "#foo" ).prev( "p" )[ 0 ].id, "ap", "Filtered prev check" ); + assert.equal( jQuery( "#foo" ).prev( "div" ).length, 0, "Filtered prev check, no match" ); + assert.equal( jQuery( "#foo" ).prev( "p, div" )[ 0 ].id, "ap", "Multiple filters" ); +} ); + +QUnit.test( "nextAll([String])", function( assert ) { + assert.expect( 5 ); + + var elems = jQuery( "#form" ).children(); + + assert.deepEqual( jQuery( "#label-for" ).nextAll().get(), elems.slice( 1 ).get(), "Simple nextAll check" ); + assert.equal( jQuery( "<div>text<a id='element'></a></div>" ).contents().eq( 0 ).nextAll().attr( "id" ), "element", "Text node nextAll check" ); + assert.deepEqual( jQuery( "#label-for" ).nextAll( "input" ).get(), elems.slice( 1 ).filter( "input" ).get(), "Filtered nextAll check" ); + assert.deepEqual( jQuery( "#label-for" ).nextAll( "input,select" ).get(), elems.slice( 1 ).filter( "input,select" ).get(), "Multiple-filtered nextAll check" ); + assert.deepEqual( jQuery( "#label-for, #hidden1" ).nextAll( "input,select" ).get(), elems.slice( 1 ).filter( "input,select" ).get(), "Multi-source, multiple-filtered nextAll check" ); +} ); + +QUnit.test( "prevAll([String])", function( assert ) { + assert.expect( 5 ); + + var elems = jQuery( jQuery( "#form" ).children().slice( 0, 12 ).get().reverse() ); + + assert.deepEqual( jQuery( "#area1" ).prevAll().get(), elems.get(), "Simple prevAll check" ); + assert.deepEqual( jQuery( "#nonnodes" ).contents().eq( 1 ).prevAll().get(), q( "nonnodesElement" ), "Text node prevAll check" ); + assert.deepEqual( jQuery( "#area1" ).prevAll( "input" ).get(), elems.filter( "input" ).get(), "Filtered prevAll check" ); + assert.deepEqual( jQuery( "#area1" ).prevAll( "input,select" ).get(), elems.filter( "input,select" ).get(), "Multiple-filtered prevAll check" ); + assert.deepEqual( jQuery( "#area1, #hidden1" ).prevAll( "input,select" ).get(), elems.filter( "input,select" ).get(), "Multi-source, multiple-filtered prevAll check" ); +} ); + +QUnit.test( "nextUntil([String])", function( assert ) { + assert.expect( 12 ); + + var elems = jQuery( "#form" ).children().slice( 2, 12 ); + + assert.deepEqual( jQuery( "#text1" ).nextUntil().get(), jQuery( "#text1" ).nextAll().get(), "nextUntil with no selector (nextAll)" ); + assert.equal( jQuery( "<div>text<a id='element'></a></div>" ).contents().eq( 0 ).nextUntil().attr( "id" ), "element", "Text node nextUntil with no selector (nextAll)" ); + assert.deepEqual( jQuery( "#text1" ).nextUntil( ".foo" ).get(), jQuery( "#text1" ).nextAll().get(), "nextUntil with invalid selector (nextAll)" ); + assert.deepEqual( jQuery( "#text1" ).nextUntil( "#area1" ).get(), elems.get(), "Simple nextUntil check" ); + assert.equal( jQuery( "#text1" ).nextUntil( "#text2" ).length, 0, "Simple nextUntil check" ); + assert.deepEqual( jQuery( "#text1" ).nextUntil( "#area1, #radio1" ).get(), jQuery( "#text1" ).next().get(), "Less simple nextUntil check" ); + assert.deepEqual( jQuery( "#text1" ).nextUntil( "#area1", "input" ).get(), elems.not( "button" ).get(), "Filtered nextUntil check" ); + assert.deepEqual( jQuery( "#text1" ).nextUntil( "#area1", "button" ).get(), elems.not( "input" ).get(), "Filtered nextUntil check" ); + assert.deepEqual( jQuery( "#text1" ).nextUntil( "#area1", "button,input" ).get(), elems.get(), "Multiple-filtered nextUntil check" ); + assert.equal( jQuery( "#text1" ).nextUntil( "#area1", "div" ).length, 0, "Filtered nextUntil check, no match" ); + assert.deepEqual( jQuery( "#text1, #hidden1" ).nextUntil( "#area1", "button,input" ).get(), elems.get(), "Multi-source, multiple-filtered nextUntil check" ); + + assert.deepEqual( jQuery( "#text1" ).nextUntil( "[class=foo]" ).get(), jQuery( "#text1" ).nextAll().get(), "Non-element nodes must be skipped, since they have no attributes" ); +} ); + +QUnit.test( "prevUntil([String])", function( assert ) { + assert.expect( 11 ); + + var elems = jQuery( "#area1" ).prevAll(); + + assert.deepEqual( jQuery( "#area1" ).prevUntil().get(), elems.get(), "prevUntil with no selector (prevAll)" ); + assert.deepEqual( jQuery( "#nonnodes" ).contents().eq( 1 ).prevUntil().get(), q( "nonnodesElement" ), "Text node prevUntil with no selector (prevAll)" ); + assert.deepEqual( jQuery( "#area1" ).prevUntil( ".foo" ).get(), elems.get(), "prevUntil with invalid selector (prevAll)" ); + assert.deepEqual( jQuery( "#area1" ).prevUntil( "label" ).get(), elems.slice( 0, -1 ).get(), "Simple prevUntil check" ); + assert.equal( jQuery( "#area1" ).prevUntil( "#button" ).length, 0, "Simple prevUntil check" ); + assert.deepEqual( jQuery( "#area1" ).prevUntil( "label, #search" ).get(), jQuery( "#area1" ).prev().get(), "Less simple prevUntil check" ); + assert.deepEqual( jQuery( "#area1" ).prevUntil( "label", "input" ).get(), elems.slice( 0, -1 ).not( "button" ).get(), "Filtered prevUntil check" ); + assert.deepEqual( jQuery( "#area1" ).prevUntil( "label", "button" ).get(), elems.slice( 0, -1 ).not( "input" ).get(), "Filtered prevUntil check" ); + assert.deepEqual( jQuery( "#area1" ).prevUntil( "label", "button,input" ).get(), elems.slice( 0, -1 ).get(), "Multiple-filtered prevUntil check" ); + assert.equal( jQuery( "#area1" ).prevUntil( "label", "div" ).length, 0, "Filtered prevUntil check, no match" ); + assert.deepEqual( jQuery( "#area1, #hidden1" ).prevUntil( "label", "button,input" ).get(), elems.slice( 0, -1 ).get(), "Multi-source, multiple-filtered prevUntil check" ); +} ); + +QUnit.test( "contents()", function( assert ) { + assert.expect( 12 ); var ibody, c; - assert.equal( jQuery("#ap").contents().length, 9, "Check element contents" ); - assert.ok( jQuery("#iframe").contents()[0], "Check existence of IFrame document" ); - ibody = jQuery("#loadediframe").contents()[0].body; + assert.equal( jQuery( "#ap" ).contents().length, 9, "Check element contents" ); + assert.ok( jQuery( "#iframe" ).contents()[ 0 ], "Check existence of IFrame document" ); + ibody = jQuery( "#loadediframe" ).contents()[ 0 ].body; assert.ok( ibody, "Check existence of IFrame body" ); - assert.equal( jQuery("span", ibody).text(), "span text", "Find span in IFrame and check its text" ); + assert.equal( jQuery( "span", ibody ).text(), "span text", "Find span in IFrame and check its text" ); - jQuery(ibody).append("<div>init text</div>"); - assert.equal( jQuery("div", ibody).length, 2, "Check the original div and the new div are in IFrame" ); + jQuery( ibody ).append( "<div>init text</div>" ); + assert.equal( jQuery( "div", ibody ).length, 2, "Check the original div and the new div are in IFrame" ); - assert.equal( jQuery("div", ibody).last().text(), "init text", "Add text to div in IFrame" ); + assert.equal( jQuery( "div", ibody ).last().text(), "init text", "Add text to div in IFrame" ); - jQuery("div", ibody).last().text("div text"); - assert.equal( jQuery("div", ibody).last().text(), "div text", "Add text to div in IFrame" ); + jQuery( "div", ibody ).last().text( "div text" ); + assert.equal( jQuery( "div", ibody ).last().text(), "div text", "Add text to div in IFrame" ); - jQuery("div", ibody).last().remove(); - assert.equal( jQuery("div", ibody).length, 1, "Delete the div and check only one div left in IFrame" ); + jQuery( "div", ibody ).last().remove(); + assert.equal( jQuery( "div", ibody ).length, 1, "Delete the div and check only one div left in IFrame" ); - assert.equal( jQuery("div", ibody).text(), "span text", "Make sure the correct div is still left after deletion in IFrame" ); + assert.equal( jQuery( "div", ibody ).text(), "span text", "Make sure the correct div is still left after deletion in IFrame" ); - jQuery("<table/>", ibody).append("<tr><td>cell</td></tr>").appendTo(ibody); - jQuery("table", ibody).remove(); - assert.equal( jQuery("div", ibody).length, 1, "Check for JS error on add and delete of a table in IFrame" ); + jQuery( "<table/>", ibody ).append( "<tr><td>cell</td></tr>" ).appendTo( ibody ); + jQuery( "table", ibody ).remove(); + assert.equal( jQuery( "div", ibody ).length, 1, "Check for JS error on add and delete of a table in IFrame" ); // using contents will get comments regular, text, and comment nodes - c = jQuery("#nonnodes").contents().contents(); + c = jQuery( "#nonnodes" ).contents().contents(); assert.equal( c.length, 1, "Check node,textnode,comment contents is just one" ); - assert.equal( c[0].nodeValue, "hi", "Check node,textnode,comment contents is just the one from span" ); -}); + assert.equal( c[ 0 ].nodeValue, "hi", "Check node,textnode,comment contents is just the one from span" ); +} ); -QUnit.test("sort direction", function( assert ) { +QUnit.test( "sort direction", function( assert ) { assert.expect( 12 ); - var elems = jQuery("#ap, #select1 > *, #moretests > form"), + var elems = jQuery( "#ap, #select1 > *, #moretests > form" ), methodDirections = { parent: false, parents: true, @@ -698,99 +697,98 @@ QUnit.test("sort direction", function( assert ) { var actual = elems[ method ]().get(), forward = jQuery.uniqueSort( [].concat( actual ) ); assert.deepEqual( actual, reversed ? forward.reverse() : forward, "Correct sort direction for " + method ); - }); -}); + } ); +} ); -QUnit.test("add(String selector)", function( assert ) { +QUnit.test( "add(String selector)", function( assert ) { assert.expect( 2 ); var divs; assert.deepEqual( - jQuery("#sndp").add("#en").add("#sap").toArray(), - q("sndp", "en", "sap"), + jQuery( "#sndp" ).add( "#en" ).add( "#sap" ).toArray(), + q( "sndp", "en", "sap" ), "Check elements from document" ); - divs = jQuery("<div/>").add("#sndp"); - assert.ok( divs[0].parentNode, "Sort with the disconnected node last (started with disconnected first)." ); -}); + divs = jQuery( "<div/>" ).add( "#sndp" ); + assert.ok( divs[ 0 ].parentNode, "Sort with the disconnected node last (started with disconnected first)." ); +} ); -QUnit.test("add(String selector, String context)", function( assert ) { +QUnit.test( "add(String selector, String context)", function( assert ) { assert.expect( 1 ); assert.deepEqual( - jQuery([]).add("div", "#nothiddendiv").toArray(), - q("nothiddendivchild"), + jQuery( [] ).add( "div", "#nothiddendiv" ).toArray(), + q( "nothiddendivchild" ), "Check elements from document" ); -}); +} ); -QUnit.test("add(String html)", function( assert ) { +QUnit.test( "add(String html)", function( assert ) { assert.expect( 3 ); var x, - divs = jQuery("#sndp").add("<div/>"); + divs = jQuery( "#sndp" ).add( "<div/>" ); - assert.ok( !divs[1].parentNode, "Sort with the disconnected node last." ); + 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" ); +} ); - 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" ); -}); - -QUnit.test("add(jQuery)", function( assert ) { +QUnit.test( "add(jQuery)", function( assert ) { assert.expect( 4 ); var x, - tmp = jQuery("<div/>"); + tmp = jQuery( "<div/>" ); - x = jQuery([]) + x = jQuery( [] ) .add( - jQuery("<p id='x1'>xxx</p>").appendTo(tmp) + jQuery( "<p id='x1'>xxx</p>" ).appendTo( tmp ) ) .add( - jQuery("<p id='x2'>xxx</p>").appendTo(tmp) + jQuery( "<p id='x2'>xxx</p>" ).appendTo( tmp ) ); - assert.equal( x[0].id, "x1", "Check element1 in detached parent" ); - assert.equal( x[1].id, "x2", "Check element2 in detached parent" ); + assert.equal( x[ 0 ].id, "x1", "Check element1 in detached parent" ); + assert.equal( x[ 1 ].id, "x2", "Check element2 in detached parent" ); - x = jQuery([]) + x = jQuery( [] ) .add( - jQuery("<p id='x1'>xxx</p>") + jQuery( "<p id='x1'>xxx</p>" ) ) .add( - jQuery("<p id='x2'>xxx</p>") + jQuery( "<p id='x2'>xxx</p>" ) ); - assert.equal( x[0].id, "x1", "Check detached element1" ); - assert.equal( x[1].id, "x2", "Check detached element2" ); -}); + assert.equal( x[ 0 ].id, "x1", "Check detached element1" ); + assert.equal( x[ 1 ].id, "x2", "Check detached element2" ); +} ); -QUnit.test("add(Element)", function( assert ) { +QUnit.test( "add(Element)", function( assert ) { assert.expect( 2 ); var x, - tmp = jQuery("<div/>"); + tmp = jQuery( "<div/>" ); - x = jQuery([]).add(jQuery("<p id='x1'>xxx</p>").appendTo(tmp)[0]).add(jQuery("<p id='x2'>xxx</p>").appendTo(tmp)[0]); - assert.equal( x[0].id, "x1", "Check on-the-fly element1" ); - assert.equal( x[1].id, "x2", "Check on-the-fly element2" ); -}); + x = jQuery( [] ).add( jQuery( "<p id='x1'>xxx</p>" ).appendTo( tmp )[ 0 ] ).add( jQuery( "<p id='x2'>xxx</p>" ).appendTo( tmp )[ 0 ] ); + assert.equal( x[ 0 ].id, "x1", "Check on-the-fly element1" ); + assert.equal( x[ 1 ].id, "x2", "Check on-the-fly element2" ); +} ); -QUnit.test("add(Array elements)", function( assert ) { +QUnit.test( "add(Array elements)", function( assert ) { assert.expect( 1 ); assert.deepEqual( - jQuery("#sndp").add( jQuery("#en")[0] ).add( jQuery("#sap") ).toArray(), - q("sndp", "en", "sap"), + jQuery( "#sndp" ).add( jQuery( "#en" )[ 0 ] ).add( jQuery( "#sap" ) ).toArray(), + q( "sndp", "en", "sap" ), "Check elements from document" ); -}); +} ); -QUnit.test("add(Window)", function( assert ) { +QUnit.test( "add(Window)", function( assert ) { assert.expect( 1 ); var frame1 = document.createElement( "iframe" ), @@ -802,25 +800,25 @@ QUnit.test("add(Window)", function( assert ) { // Window is tricky because it is a lot like an array, even Array#slice will // turn it into a multi-item array. - assert.equal( jQuery([]).add( window ).length, 1, "Add a window" ); + assert.equal( jQuery( [] ).add( window ).length, 1, "Add a window" ); document.body.removeChild( frame1 ); document.body.removeChild( frame2 ); -}); +} ); -QUnit.test("add(NodeList|undefined|HTMLFormElement|HTMLSelectElement)", function( assert ) { +QUnit.test( "add(NodeList|undefined|HTMLFormElement|HTMLSelectElement)", function( assert ) { assert.expect( 4 ); var ps, notDefined; - ps = document.getElementsByTagName("p"); + ps = document.getElementsByTagName( "p" ); - assert.equal( jQuery([]).add(ps).length, ps.length, "Add a NodeList" ); + assert.equal( jQuery( [] ).add( ps ).length, ps.length, "Add a NodeList" ); - assert.equal( jQuery([]).add(notDefined).length, 0, "Adding undefined adds nothing" ); + assert.equal( jQuery( [] ).add( notDefined ).length, 0, "Adding undefined adds nothing" ); - assert.equal( jQuery([]).add( document.getElementById("form") ).length, 1, "Add a form" ); - assert.equal( jQuery([]).add( document.getElementById("select1") ).length, 1, "Add a select" ); + assert.equal( jQuery( [] ).add( document.getElementById( "form" ) ).length, 1, "Add a form" ); + assert.equal( jQuery( [] ).add( document.getElementById( "select1" ) ).length, 1, "Add a select" ); // We no longer support .add(form.elements), unfortunately. // There is no way, in browsers, to reliably determine the difference @@ -831,53 +829,53 @@ QUnit.test("add(NodeList|undefined|HTMLFormElement|HTMLSelectElement)", function // For the time being, we're discontinuing support for jQuery(form.elements) since it's ambiguous in IE // use jQuery([]).add(form.elements) instead. //equal( jQuery([]).add(jQuery("#form")[0].elements).length, jQuery(jQuery("#form")[0].elements).length, "Array in constructor must equals array in add()" ); -}); +} ); -QUnit.test("add(String, Context)", function( assert ) { - assert.expect(6); +QUnit.test( "add(String, Context)", function( assert ) { + assert.expect( 6 ); assert.deepEqual( jQuery( "#firstp" ).add( "#ap" ).get(), q( "firstp", "ap" ), "Add selector to selector " ); - assert.deepEqual( jQuery( document.getElementById("firstp") ).add( "#ap" ).get(), q( "firstp", "ap" ), "Add gEBId to selector" ); - assert.deepEqual( jQuery( document.getElementById("firstp") ).add( document.getElementById("ap") ).get(), q( "firstp", "ap" ), "Add gEBId to gEBId" ); + assert.deepEqual( jQuery( document.getElementById( "firstp" ) ).add( "#ap" ).get(), q( "firstp", "ap" ), "Add gEBId to selector" ); + assert.deepEqual( jQuery( document.getElementById( "firstp" ) ).add( document.getElementById( "ap" ) ).get(), q( "firstp", "ap" ), "Add gEBId to gEBId" ); - var ctx = document.getElementById("firstp"); + var ctx = document.getElementById( "firstp" ); assert.deepEqual( jQuery( "#firstp" ).add( "#ap", ctx ).get(), q( "firstp" ), "Add selector to selector " ); - assert.deepEqual( jQuery( document.getElementById("firstp") ).add( "#ap", ctx ).get(), q( "firstp" ), "Add gEBId to selector, not in context" ); - assert.deepEqual( jQuery( document.getElementById("firstp") ).add( "#ap", document.getElementsByTagName("body")[0] ).get(), q( "firstp", "ap" ), "Add gEBId to selector, in context" ); -}); + assert.deepEqual( jQuery( document.getElementById( "firstp" ) ).add( "#ap", ctx ).get(), q( "firstp" ), "Add gEBId to selector, not in context" ); + assert.deepEqual( jQuery( document.getElementById( "firstp" ) ).add( "#ap", document.getElementsByTagName( "body" )[ 0 ] ).get(), q( "firstp", "ap" ), "Add gEBId to selector, in context" ); +} ); -QUnit.test("eq('-1') #10616", function( assert ) { - assert.expect(3); +QUnit.test( "eq('-1') #10616", function( assert ) { + assert.expect( 3 ); var $divs = jQuery( "div" ); assert.equal( $divs.eq( -1 ).length, 1, "The number -1 returns a selection that has length 1" ); assert.equal( $divs.eq( "-1" ).length, 1, "The string '-1' returns a selection that has length 1" ); assert.deepEqual( $divs.eq( "-1" ), $divs.eq( -1 ), "String and number -1 match" ); -}); +} ); -QUnit.test("index(no arg) #10977", function( assert ) { - assert.expect(2); +QUnit.test( "index(no arg) #10977", function( assert ) { + assert.expect( 2 ); var $list, fragment, div; - $list = jQuery("<ul id='indextest'><li class='zero'>THIS ONE</li><li class='one'>a</li><li class='two'>b</li><li class='three'>c</li></ul>"); - jQuery("#qunit-fixture").append( $list ); - strictEqual ( jQuery( "#indextest li.zero" ).first().index() , 0, "No Argument Index Check" ); + $list = jQuery( "<ul id='indextest'><li class='zero'>THIS ONE</li><li class='one'>a</li><li class='two'>b</li><li class='three'>c</li></ul>" ); + jQuery( "#qunit-fixture" ).append( $list ); + strictEqual ( jQuery( "#indextest li.zero" ).first().index(), 0, "No Argument Index Check" ); $list.remove(); fragment = document.createDocumentFragment(); - div = fragment.appendChild( document.createElement("div") ); + div = fragment.appendChild( document.createElement( "div" ) ); assert.equal( jQuery( div ).index(), 0, "If jQuery#index called on element whose parent is fragment, it still should work correctly" ); -}); +} ); -QUnit.test("traversing non-elements with attribute filters (#12523)", function( assert ) { - assert.expect(5); +QUnit.test( "traversing non-elements with attribute filters (#12523)", function( assert ) { + assert.expect( 5 ); - var nonnodes = jQuery("#nonnodes").contents(); + var nonnodes = jQuery( "#nonnodes" ).contents(); - assert.equal( nonnodes.filter("[id]").length, 1, ".filter" ); - assert.equal( nonnodes.find("[id]").length, 0, ".find" ); - assert.strictEqual( nonnodes.is("[id]"), true, ".is" ); - assert.deepEqual( nonnodes.closest("[id='nonnodes']").get(), q("nonnodes"), ".closest" ); - assert.deepEqual( nonnodes.parents("[id='nonnodes']").get(), q("nonnodes"), ".parents" ); -}); + assert.equal( nonnodes.filter( "[id]" ).length, 1, ".filter" ); + assert.equal( nonnodes.find( "[id]" ).length, 0, ".find" ); + assert.strictEqual( nonnodes.is( "[id]" ), true, ".is" ); + assert.deepEqual( nonnodes.closest( "[id='nonnodes']" ).get(), q( "nonnodes" ), ".closest" ); + assert.deepEqual( nonnodes.parents( "[id='nonnodes']" ).get(), q( "nonnodes" ), ".parents" ); +} ); diff --git a/test/unit/wrap.js b/test/unit/wrap.js index cefbcfc18..80abd9e87 100644 --- a/test/unit/wrap.js +++ b/test/unit/wrap.js @@ -1,4 +1,4 @@ -(function() { +( function() { if ( !jQuery.fn.wrap ) { // no wrap module return; @@ -6,7 +6,7 @@ if ( !jQuery.fn.wrap ) { // no wrap module QUnit.module( "wrap", { teardown: moduleTeardown -}); +} ); // See test/unit/manipulation.js for explanation about these 2 functions function manipulationBareObj( value ) { @@ -19,36 +19,54 @@ function manipulationFunctionReturningObj( value ) { }; } -function testWrap( val , assert ) { +function testWrap( val, assert ) { assert.expect( 19 ); var defaultText, result, j, i, cacheLength; 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'" ); - - 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" ); - - jQuery("#check1").on( "click", function() { + 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'" + ); + + 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" + ); + + jQuery( "#check1" ).on( "click", function() { var checkbox = this; - 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" ); - }).prop( "checked", false )[ 0 ].click(); + 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" + ); + } ).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" ); + 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" + ); // Try wrapping a disconnected node cacheLength = 0; @@ -56,79 +74,109 @@ function testWrap( val , assert ) { cacheLength++; } - 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" ); + 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" + ); 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." ); + 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." + ); // 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." ); + 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." + ); // Wrap an element with a jQuery set - j = jQuery("<span/>").wrap( jQuery("<div></div>") ); - assert.equal( j[ 0 ].parentNode.nodeName.toLowerCase(), "div", "Wrapping works." ); + j = jQuery( "<span/>" ).wrap( jQuery( "<div></div>" ) ); + 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." ); + result = jQuery( "<div></div>" ).on( "click", function() { + assert.ok( + true, "Event triggered." + ); // Remove handlers on detached elements result.off(); - jQuery(this).off(); - }); + jQuery( this ).off(); + } ); - j = jQuery("<span/>").wrap( result ); - assert.equal( j[ 0 ].parentNode.nodeName.toLowerCase(), "div", "Wrapping works." ); + j = jQuery( "<span/>" ).wrap( result ); + assert.equal( + j[ 0 ].parentNode.nodeName.toLowerCase(), "div", "Wrapping works." + ); - j.parent().trigger("click"); + j.parent().trigger( "click" ); } QUnit.test( "wrap(String|Element)", function( assert ) { testWrap( manipulationBareObj, assert ); -}); +} ); QUnit.test( "wrap(Function)", function( assert ) { testWrap( manipulationFunctionReturningObj, assert ); -}); +} ); QUnit.test( "wrap(Function) with index (#10177)", function( assert ) { var expectedIndex = 0, - targets = jQuery("#qunit-fixture p"); + targets = jQuery( "#qunit-fixture p" ); assert.expect( targets.length ); - targets.wrap(function(i) { - assert.equal( i, expectedIndex, "Check if the provided index (" + i + ") is as expected (" + expectedIndex + ")" ); + targets.wrap( function( i ) { + assert.equal( + i, expectedIndex, + "Check if the provided index (" + i + ") is as expected (" + expectedIndex + ")" + ); expectedIndex++; return "<div id='wrap_index_'" + i + "'></div>"; - }); -}); + } ); +} ); QUnit.test( "wrap(String) consecutive elements (#10177)", function( assert ) { - var targets = jQuery("#qunit-fixture p"); + var targets = jQuery( "#qunit-fixture p" ); assert.expect( targets.length * 2 ); - targets.wrap("<div class='wrapper'></div>"); + targets.wrap( "<div class='wrapper'></div>" ); - targets.each(function() { - var $this = jQuery(this); + 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" + ); + } ); +} ); QUnit.test( "wrapAll(String)", function( assert ) { @@ -136,65 +184,97 @@ QUnit.test( "wrapAll(String)", function( assert ) { var prev, p, result; - prev = jQuery("#firstp")[ 0 ].previousSibling; - 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" ); - -}); + prev = jQuery( "#firstp" )[ 0 ].previousSibling; + 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" + ); + +} ); QUnit.test( "wrapAll(Function)", function( assert ) { assert.expect( 5 ); var prev = jQuery( "#firstp" )[ 0 ].previousSibling, p = jQuery( "#firstp,#first" )[ 0 ].parentNode, - result = jQuery( "#firstp,#first" ).wrapAll(function() { + result = jQuery( "#firstp,#first" ).wrapAll( function() { 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 ) { assert.expect( 3 ); var i = 0; - jQuery( "non-existent" ).wrapAll(function() { + jQuery( "non-existent" ).wrapAll( function() { i++; return ""; - }); - - 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.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" + ); + } ); +} ); QUnit.test( "wrapAll(Element)", function( assert ) { assert.expect( 3 ); var prev, p; - prev = jQuery("#firstp")[ 0 ].previousSibling; - 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" ); -}); + prev = jQuery( "#firstp" )[ 0 ].previousSibling; + 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" + ); +} ); QUnit.test( "wrapInner(String)", function( assert ) { @@ -202,37 +282,59 @@ QUnit.test( "wrapInner(String)", function( assert ) { var num; - 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" ); - - 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" ); -}); + 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" + ); + + 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" + ); +} ); QUnit.test( "wrapInner(Element)", function( assert ) { assert.expect( 5 ); var num, - div = jQuery("<div/>"); - - 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" ); + div = jQuery( "<div/>" ); + + 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" + ); 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 ) { @@ -241,19 +343,31 @@ QUnit.test( "wrapInner(Function) returns String", function( assert ) { var num, val = manipulationFunctionReturningObj; - 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" ); - - 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" ); -}); + 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" + ); + + 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" + ); +} ); QUnit.test( "wrapInner(Function) returns Element", function( assert ) { @@ -261,71 +375,127 @@ QUnit.test( "wrapInner(Function) returns Element", function( assert ) { var num, val = manipulationFunctionReturningObj, - div = jQuery("<div/>"); - - 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" ); - - 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." ); -}); + div = jQuery( "<div/>" ); + + 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" + ); + + 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." + ); +} ); 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>"); - - 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.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("#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("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" ); - - jQuery("body > span.unwrap").remove(); -}); + 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.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( "#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( "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" + ); + + jQuery( "body > span.unwrap" ).remove(); +} ); 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" ); - - jQuery("body > span.unwrap").remove(); -}); + 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(); +} ); QUnit.test( "jQuery(<tag>) & wrap[Inner/All]() handle unknown elems (#10667)", function( assert ) { @@ -334,24 +504,33 @@ QUnit.test( "jQuery(<tag>) & wrap[Inner/All]() handle unknown elems (#10667)", f var $wraptarget = jQuery( "<div id='wrap-target'>Target</div>" ).appendTo( "#qunit-fixture" ), $section = jQuery( "<section>" ).appendTo( "#qunit-fixture" ); - $wraptarget.wrapAll("<aside style='background-color:green'></aside>"); + $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 ) { assert.expect( 2 ); - var script = document.createElement("script"); - script.text = script.textContent = "ok( !document.eval10470, 'script evaluated once' ); document.eval10470 = true;"; + var script = document.createElement( "script" ); + 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" ); + 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" + ); jQuery( script ).remove(); -}); +} ); -})(); +} )(); |