diff --git a/.jscsrc b/.jscsrc index 14f349133..c460130a4 100644 --- a/.jscsrc +++ b/.jscsrc @@ -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 = /(.*?)<[^"]+"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(""); + console.log( "" ); } cur = cat; - console.log( "

" + cat.charAt(0).toUpperCase() + cat.slice(1) + "

" ); - console.log("
" ); } - }); -}).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 " + commit.substr( 0, 10 ) + ""; } - 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("
").append( jQuery.parseHTML( responseText ) ).find( selector ) : + jQuery( "
" ).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(""); + jQuery( "#qunit-fixture" ).append( "" ); - 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("
").load( "data/404.html", function() { + jQuery( "
" ).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("
").load( url("data/name.html"), function( responseText ) { + } ); + jQuery( "
" ).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("
").load( url("data/params_html.php"), { + jQuery( "
" ).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("
").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( "
" ).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("
").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( "
" ).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("").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( "" ).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("").attr({ + jQuery( "" ).attr( { "id": "tAnchor5", "href": "#5" - }).appendTo("#qunit-fixture"); - assert.equal( jQuery("#tAnchor5").attr("href"), "#5", "Check for non-absolute href (an anchor)" ); - jQuery("").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( "" ).appendTo( "#qunit-fixture" ); + assert.equal( jQuery( "#tAnchor5" ).prop( "href" ), jQuery( "#tAnchor6" ).prop( "href" ), "Check for absolute href prop on an anchor" ); - jQuery("").appendTo("#qunit-fixture"); - assert.equal( jQuery("#tAnchor5").prop("href"), jQuery("#scriptSrc").prop("src"), "Check for absolute src prop on a script" ); + jQuery( "" ).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("").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( "" ).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("
").appendTo("#qunit-fixture").css({ + styleElem = jQuery( "
" ).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("").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( "" ).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("
").appendTo("#qunit-fixture"); - assert.equal( $form.attr("class"), "something", "Retrieve the class attribute on a form." ); + $form = jQuery( "
" ).appendTo( "#qunit-fixture" ); + assert.equal( $form.attr( "class" ), "something", "Retrieve the class attribute on a form." ); - $a = jQuery("
Click").appendTo("#qunit-fixture"); - assert.equal( $a.attr("onclick"), "something()", "Retrieve ^on attribute without anonymous function wrapper." ); + $a = jQuery( "Click" ).appendTo( "#qunit-fixture" ); + assert.equal( $a.attr( "onclick" ), "something()", "Retrieve ^on attribute without anonymous function wrapper." ); - assert.ok( jQuery("
").attr("doesntexist") === undefined, "Make sure undefined is returned when no attribute is found." ); - assert.ok( jQuery("
").attr("title") === undefined, "Make sure undefined is returned when no attribute is found." ); - assert.equal( jQuery("
").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("
").attr("value"), undefined, "An unset value on a div returns undefined." ); - assert.strictEqual( jQuery("").attr("value"), undefined, "An unset value on a select returns undefined." ); + assert.ok( jQuery( "
" ).attr( "doesntexist" ) === undefined, "Make sure undefined is returned when no attribute is found." ); + assert.ok( jQuery( "
" ).attr( "title" ) === undefined, "Make sure undefined is returned when no attribute is found." ); + assert.equal( jQuery( "
" ).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( "
" ).attr( "value" ), undefined, "An unset value on a div returns undefined." ); + assert.strictEqual( jQuery( "" ).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 = jQuery( "" ); - 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.attr("id"); + div = jQuery( "
" ); + 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.attr("value"); + input = jQuery( "" ); + 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( "", { 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("").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("