diff --git a/.gitignore b/.gitignore index cd801eea..6d9469cd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ dist +coverage CDN .project .settings diff --git a/.mailmap b/.mailmap new file mode 100644 index 00000000..f91b62ad --- /dev/null +++ b/.mailmap @@ -0,0 +1,2 @@ +Igor Kalashnikov +Michał Gołębiowski diff --git a/.npmignore b/.npmignore index 8ec9e4ed..72b668b6 100644 --- a/.npmignore +++ b/.npmignore @@ -1,4 +1,5 @@ CDN +coverage .project .settings *~ diff --git a/.npmrc b/.npmrc new file mode 100644 index 00000000..cffe8cde --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +save-exact=true diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..0c206768 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,4 @@ +language: node_js +sudo: false +node_js: +- "5" \ No newline at end of file diff --git a/AUTHORS.txt b/AUTHORS.txt index 478380d5..20e6421b 100644 --- a/AUTHORS.txt +++ b/AUTHORS.txt @@ -2,6 +2,15 @@ Authors ordered by first contribution. Dave Methvin Richard Gibson +Corey Frang Igor Kalashnikov Max Riveiro - +Jörn Zaefferer +Timo Tijhof +Scott González +Michał Gołębiowski +Arthur Verschaeve +Will Binns-Smith +Eric Lee Carraway +Matthew Brundage +Oleg Gaidarenko diff --git a/Gruntfile.js b/Gruntfile.js index c4544707..07398bd6 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -35,7 +35,7 @@ module.exports = function(grunt) { ], tests: { "jquery-1": [ - "dev+1.x-git", + "dev+1.12.4", "dev+1.11.3", "dev+1.10.2", "dev+1.9.1", @@ -44,8 +44,8 @@ module.exports = function(grunt) { "dev+1.6.4" ], "jquery-2": [ - "dev+2.x-git", - "min+2.x-git.min", + "dev+2.2.4", + "min+2.2.4.min", "dev+2.1.4", "dev+2.0.3" ] diff --git a/README.md b/README.md index ea1a7ef6..c5472e54 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,17 @@ # jquery-migrate: Migrate older jQuery code to jQuery 1.9+ This plugin can be used to detect and restore APIs or features that have been deprecated in jQuery and removed as of version 1.9. -See the [warnings page](https://github.com/jquery/jquery-migrate/blob/master/warnings.md) for more information regarding messages the plugin generates. -For more information about the changes made in jQuery 1.9, see the [upgrade guide](http://jquery.com/upgrade-guide/1.9/) and [blog post](http://blog.jquery.com/2013/01/15/jquery-1-9-final-jquery-2-0-beta-migrate-final-released/). +See the [warnings page](https://github.com/jquery/jquery-migrate/blob/1.x-stable/warnings.md) for more information regarding messages the plugin generates. +For more information about the changes made in jQuery 1.9, see the [upgrade guide](https://jquery.com/upgrade-guide/1.9/) and [blog post](https://blog.jquery.com/2013/01/15/jquery-1-9-final-jquery-2-0-beta-migrate-final-released/). In your web page, load this plugin *after* the script for jQuery: ```html - - + + ``` -The plugin can be included with versions of jQuery as old as 1.6.4 to identify potential upgrade issues via its JQMIGRATE console warnings. -However, the plugin is only required for version 1.9.0 or higher to restore deprecated and removed functionality. +Note that jQuery 3.0 has a [separate version](https://github.com/jquery/jquery-migrate/) of jQuery Migrate. The two versions cannot be used simultaneously on a page, so you should fix any upgrade issues identified by Migrate 1.x before attempting an upgrade. ## Download @@ -20,28 +19,28 @@ However, the plugin is only required for version 1.9.0 or higher to restore depr To make it easier for jQuery developers to find and remove deprecated functionality, the development version of the plugin displays warnings on the browser's console. In browsers that don't support the console interface such as IE7, no messages are generated unless you include a debugging library such as [Firebug Lite](https://getfirebug.com/firebuglite) before including the jQuery Migrate plugin. Developers can also inspect the `jQuery.migrateWarnings` array to see what error messages have been generated. -All warnings generated by this plugin start with the string "JQMIGRATE". A list of the warnings you may see are in [warnings.md](https://github.com/jquery/jquery-migrate/blob/master/warnings.md). +All warnings generated by this plugin start with the string "JQMIGRATE". A list of the warnings you may see are in [warnings.md](https://github.com/jquery/jquery-migrate/blob/1.x-stable/warnings.md). ### Development version This version provides console warning messages when deprecated and/or removed APIs are used. Use this version during development and debugging, and whenever you are reporting bugs to the jQuery team. **Latest released development version:** This file is hosted on jQuery's CDN, and can be hotlinked if desired. -[http://code.jquery.com/jquery-migrate-1.3.0.js](http://code.jquery.com/jquery-migrate-1.3.0.js) +[https://code.jquery.com/jquery-migrate-1.4.1.js](https://code.jquery.com/jquery-migrate-1.4.1.js) **Current work-in-progress build:** Although this file represents the most recent updates to the plugin, it may not have been thoroughly tested. -[http://code.jquery.com/jquery-migrate-git.js](http://code.jquery.com/jquery-migrate-git.js) +[https://code.jquery.com/jquery-migrate-git.js](https://code.jquery.com/jquery-migrate-git.js) ### Production version The minified production file is compressed and does not generate console warnings. Do not use this file for development or debugging, it will make your life miserable. **Latest released production version:** -[http://code.jquery.com/jquery-migrate-1.3.0.min.js](http://code.jquery.com/jquery-migrate-1.3.0.min.js) +[https://code.jquery.com/jquery-migrate-1.4.1.min.js](https://code.jquery.com/jquery-migrate-1.4.1.min.js) This file is hosted on jQuery's CDN, and can be hotlinked if desired. **Current work-in-progress build:** Although this file represents the most recent updates to the plugin, it may not have been thoroughly tested. We do not recommend using this file on production sites since it may be unstable; use the released production version above. -[http://code.jquery.com/jquery-migrate-git.min.js](http://code.jquery.com/jquery-migrate-git.min.js) +[https://code.jquery.com/jquery-migrate-git.min.js](https://code.jquery.com/jquery-migrate-git.min.js) ## Migrate Plugin API @@ -59,11 +58,11 @@ This plugin adds some properties to the `jQuery` object that can be used to prog ## Reporting problems -Bugs that only occur when the jQuery Migrate plugin is used should be reported in the [jQuery Migrate Issue Tracker](https://github.com/jquery/jquery-migrate/issues) and *must* be accompanied by an executable test case that demonstrates the bug. The easiest way to do this is via an online test tool such as [jsFiddle.net](http://jsFiddle.net/) or [jsbin.com](http://jsbin.com). You can use [this jsFiddle template](http://jsfiddle.net/4ZwWv/) or [this jsbin template](http://jsbin.com/emuwuy/4/show) as a starting point; they already contain links to the work-in-progress versions of both jQuery and the jQuery Migrate plugin. Add your code there and post a link to it with your bug report. +Bugs that only occur when the jQuery Migrate plugin is used should be reported in the [jQuery Migrate Issue Tracker](https://github.com/jquery/jquery-migrate/issues) and *must* be accompanied by an executable test case that demonstrates the bug. The easiest way to do this is via an online test tool such as [jsFiddle.net](https://jsfiddle.net/) or [jsbin.com](https://jsbin.com). You can use [this jsFiddle template](https://jsfiddle.net/4ZwWv/) or [this jsbin template](https://jsbin.com/emuwuy/4/show) as a starting point; they already contain links to the work-in-progress versions of both jQuery and the jQuery Migrate plugin. Add your code there and post a link to it with your bug report. -Bugs in jQuery itself should be reported on the [jQuery Core bug tracker](http://bugs.jquery.com/) and again should be accompanied by a test case from [jsFiddle.net](http://jsFiddle.net/) or [jsbin.com](http://jsbin.com) so that we can reproduce the issue. +Bugs in jQuery itself should be reported on the [jQuery Core bug tracker](https://bugs.jquery.com/) and again should be accompanied by a test case from [jsFiddle.net](https://jsFiddle.net/) or [jsbin.com](https://jsbin.com) so that we can reproduce the issue. -For other questions about the plugin that aren't bugs, ask on the [jQuery Forum](http://forum.jquery.com). +For other questions about the plugin that aren't bugs, ask on the [jQuery Forum](https://forum.jquery.com). How to run the tests: ==================================================== diff --git a/build/release.js b/build/release.js index 567b6871..94a7214e 100644 --- a/build/release.js +++ b/build/release.js @@ -18,14 +18,13 @@ var releaseVersion, isBeta, pkg, - scpURL = "jqadmin@code.origin.jquery.com:/var/www/html/code.jquery.com/", - cdnURL = "http://code.origin.jquery.com/", repoURL = "git@github.com:jquery/jquery-migrate.git", - branch = "master", + branch = "1.x-stable", // Windows needs the .cmd version but will find the non-.cmd - // On Windows, ensure the HOME environment variable is set + // On Windows, also ensure the HOME environment variable is set gruntCmd = process.platform === "win32" ? "grunt.cmd" : "grunt", + npmCmd = process.platform == "win32" ? "npm.cmd" : "npm", readmeFile = "README.md", packageFile = "package.json", @@ -41,15 +40,16 @@ var releaseVersion, steps( initialize, checkGitStatus, - gruntBuild, + function( next ) { gruntBuild( "default", next ); }, updateVersions, tagReleaseVersion, - gruntBuild, + function( next ) { gruntBuild( "buildnounit", next ); }, makeReleaseCopies, - // uploadToCDN, + publishToNPM, setNextVersion, pushToRemote, + remindAboutCDN, exit ); @@ -87,7 +87,10 @@ function initialize( next ) { isBeta = !!xbeta; if ( !releaseVersion ) { - die( "Usage: release [ -d ] releaseVersion" ); + log( "Usage: release [ -d -r ] releaseVersion" ); + log( " -d Dry-run; no commands are executed at all" ); + log( " -r Skip-remote; nothing is pushed externally" ); + die( "Invalid args" ); } if ( !version.length ) { die( "'" + releaseVersion + "' is not a valid semver!" ); @@ -134,7 +137,7 @@ function checkGitStatus( next ) { } function tagReleaseVersion( next ) { - git( [ "commit", "-a", "-m", "Tagging the " + releaseVersion + " release." ], function(){ + git( [ "commit", "-a", "--no-verify", "-m", "Tagging the " + releaseVersion + " release." ], function(){ git( [ "tag", releaseVersion ], next); }); } @@ -146,8 +149,8 @@ function updateVersions( next ) { next(); } -function gruntBuild( next ) { - exec( gruntCmd, [], function( error, stdout ) { +function gruntBuild( target, next ) { + exec( gruntCmd, [ target || "default" ], function( error, stdout ) { if ( error ) { die( error + stderr ); } @@ -172,40 +175,28 @@ function publishToNPM( next ) { // Don't update "latest" if this is a beta if ( isBeta ) { - exec( "npm", [ "publish", "--tag", releaseVersion ], next, skipRemote ); + exec( npmCmd, [ "publish", "--tag", releaseVersion ], next, skipRemote ); } else { - exec( "npm", [ "publish" ], next, skipRemote ); + exec( npmCmd, [ "publish" ], next, skipRemote ); } } function setNextVersion( next ) { updateSourceVersion( nextVersion ); - updatePackageVersion( nextVersion, "master" ); - git( [ "commit", "-a", "-m", "Updating the source version to " + nextVersion ], next ); -} - -function uploadToCDN( next ) { - var cmds = []; - - Object.keys( finalFiles ).forEach(function( name ) { - cmds.push( - function( nxt ){ - exec( "scp", [ name, scpURL ], nxt, skipRemote ); - }, - function( nxt ){ - exec( "curl", [ cdnURL + name + "?reload" ], nxt, skipRemote ); - } - ); - }); - cmds.push( next ); - - steps.apply( this, cmds ); + updatePackageVersion( nextVersion, branch ); + git( [ "commit", "-a", "--no-verify", "-m", "Updating the source version to " + nextVersion ], next ); } function pushToRemote( next ) { git( [ "push", "--tags", repoURL, branch ], next, skipRemote ); } +function remindAboutCDN( next ) { + console.log( chalk.red( "TODO: Update CDN with jquery-migrate." + releaseVersion + " files (min and regular)" ) ); + console.log( chalk.red( " clone codeorigin.jquery.org, git add files, commit, push" ) ); + next(); +} + //============================== function steps() { @@ -223,7 +214,7 @@ function updatePackageVersion( ver, blobVer ) { blobVer = blobVer || ver; pkg.version = ver; pkg.author.url = setBlobVersion( pkg.author.url, blobVer ); - pkg.licenses[0].url = setBlobVersion( pkg.licenses[0].url, blobVer ); + writeJsonSync( packageFile, pkg ); } @@ -254,7 +245,7 @@ function updateReadmeVersion( ver ) { } function setBlobVersion( s, v ) { - return s.replace( /\/blob\/(?:(\d+\.\d+[^\/]+)|master)/, "/blob/" + v ); + return s.replace( /\/blob\/[^\/]+/, "/blob/" + v ); } function writeJsonSync( fname, json ) { diff --git a/package.json b/package.json index fcfea9dd..b8e7d692 100644 --- a/package.json +++ b/package.json @@ -1,43 +1,70 @@ { - "name": "jquery-migrate", - "title": "jQuery Migrate", - "description": "Migrate older jQuery code to jQuery 1.9+", - "main": "dist/jquery-migrate.js", - "version": "1.3.1-pre", - "homepage": "https://github.com/jquery/jquery-migrate", - "author": { - "name": "jQuery Foundation and other contributors", - "url": "https://github.com/jquery/jquery-migrate/blob/master/AUTHORS.txt" - }, - "repository": { - "type": "git", - "url": "git://github.com/jquery/jquery-migrate.git" - }, - "bugs": { - "url": "http://bugs.jquery.com/" - }, - "licenses": [ - { - "type": "MIT", - "url": "https://github.com/jquery/jquery-migrate/blob/master/LICENSE.txt" - } - ], - "devDependencies": { - "chalk": "1.1.1", - "grunt": "~0.4.5", - "grunt-contrib-concat": "0.5.1", - "grunt-contrib-jshint": "0.11.0", - "grunt-contrib-qunit": "0.5.2", - "grunt-contrib-uglify": "0.8.0", - "grunt-contrib-watch": "0.6.1", - "grunt-git-authors": "3.0.0", - "grunt-npmcopy": "0.1.0", - "jquery": "^2.1.3", - "qunitjs": "1.17.1", - "testswarm": "~1.1.0" - }, - "scripts": { - "prepublish": "grunt" - }, - "keywords": [] + "name": "jquery-migrate", + "title": "jQuery Migrate", + "description": "Migrate older jQuery code to jQuery 1.9+", + "main": "dist/jquery-migrate.js", + "version": "1.4.2-pre", + "homepage": "https://github.com/jquery/jquery-migrate", + "author": { + "name": "jQuery Foundation and other contributors", + "url": "https://github.com/jquery/jquery-migrate/blob/1.x-stable/AUTHORS.txt" + }, + "repository": { + "type": "git", + "url": "git://github.com/jquery/jquery-migrate.git" + }, + "bugs": { + "url": "http://bugs.jquery.com/" + }, + "license": "MIT", + "scripts": { + "test": "grunt" + }, + "dependencies": { + "jquery": ">=1.7.0 <3.0.0" + }, + "devDependencies": { + "chalk": "1.1.3", + "commitplease": "2.3.1", + "grunt": "0.4.5", + "grunt-cli": "0.1.13", + "grunt-contrib-concat": "1.0.1", + "grunt-contrib-jshint": "1.0.0", + "grunt-contrib-qunit": "1.2.0", + "grunt-contrib-uglify": "1.0.1", + "grunt-contrib-watch": "1.0.0", + "grunt-git-authors": "3.2.0", + "grunt-npmcopy": "0.1.0", + "jquery": "^2.1.3", + "phantomjs-polyfill": "0.0.2", + "qunitjs": "1.23.1", + "testswarm": "~1.1.0" + }, + "keywords": [], + "commitplease": { + "components": [ + "Docs", + "Tests", + "Build", + "Release", + "Core", + "Ajax", + "Attributes", + "Callbacks", + "CSS", + "Data", + "Deferred", + "Deprecated", + "Dimensions", + "Effects", + "Event", + "Manipulation", + "Offset", + "Queue", + "Selector", + "Serialize", + "Traversing", + "Wrap" + ] + } } diff --git a/src/core.js b/src/core.js index be976ed0..f24cf80a 100644 --- a/src/core.js +++ b/src/core.js @@ -1,8 +1,11 @@ var matched, browser, oldInit = jQuery.fn.init, + oldFind = jQuery.find, oldParseJSON = jQuery.parseJSON, rspaceAngle = /^\s*)([^>]*)$/; @@ -10,38 +13,37 @@ var matched, browser, jQuery.fn.init = function( selector, context, rootjQuery ) { var match, ret; - if ( selector && typeof selector === "string" && !jQuery.isPlainObject( context ) && - (match = rquickExpr.exec( jQuery.trim( selector ) )) && match[ 0 ] ) { - // This is an HTML string according to the "old" rules; is it still? - if ( !rspaceAngle.test( selector ) ) { - migrateWarn("$(html) HTML strings must start with '<' character"); + if ( selector && typeof selector === "string" ) { + if ( !jQuery.isPlainObject( context ) && + (match = rquickExpr.exec( jQuery.trim( selector ) )) && match[ 0 ] ) { + + // This is an HTML string according to the "old" rules; is it still? + if ( !rspaceAngle.test( selector ) ) { + migrateWarn("$(html) HTML strings must start with '<' character"); + } + if ( match[ 3 ] ) { + migrateWarn("$(html) HTML text after last tag is ignored"); + } + + // Consistently reject any HTML-like string starting with a hash (gh-9521) + // Note that this may break jQuery 1.6.x code that otherwise would work. + if ( match[ 0 ].charAt( 0 ) === "#" ) { + migrateWarn("HTML string cannot start with a '#' character"); + jQuery.error("JQMIGRATE: Invalid selector string (XSS)"); + } + + // Now process using loose rules; let pre-1.8 play too + // Is this a jQuery context? parseHTML expects a DOM element (#178) + if ( context && context.context && context.context.nodeType ) { + context = context.context; + } + + if ( jQuery.parseHTML ) { + return oldInit.call( this, + jQuery.parseHTML( match[ 2 ], context && context.ownerDocument || + context || document, true ), context, rootjQuery ); + } } - if ( match[ 3 ] ) { - migrateWarn("$(html) HTML text after last tag is ignored"); - } - - // Consistently reject any HTML-like string starting with a hash (#9521) - // Note that this may break jQuery 1.6.x code that otherwise would work. - if ( match[ 0 ].charAt( 0 ) === "#" ) { - migrateWarn("HTML string cannot start with a '#' character"); - jQuery.error("JQMIGRATE: Invalid selector string (XSS)"); - } - // Now process using loose rules; let pre-1.8 play too - if ( context && context.context ) { - // jQuery object as context; parseHTML expects a DOM object - context = context.context; - } - if ( jQuery.parseHTML ) { - return oldInit.call( this, - jQuery.parseHTML( match[ 2 ], context && context.ownerDocument || - context || document, true ), context, rootjQuery ); - } - } - - // jQuery( "#" ) is a bogus ID selector, but it returned an empty set before jQuery 3.0 - if ( selector === "#" ) { - migrateWarn( "jQuery( '#' ) is not a valid selector" ); - selector = []; } ret = oldInit.apply( this, arguments ); @@ -63,6 +65,47 @@ jQuery.fn.init = function( selector, context, rootjQuery ) { }; jQuery.fn.init.prototype = jQuery.fn; +jQuery.find = function( selector ) { + var args = Array.prototype.slice.call( arguments ); + + // Support: PhantomJS 1.x + // String#match fails to match when used with a //g RegExp, only on some strings + if ( typeof selector === "string" && rattrHashTest.test( selector ) ) { + + // The nonstandard and undocumented unquoted-hash was removed in jQuery 1.12.0 + // First see if qS thinks it's a valid selector, if so avoid a false positive + try { + document.querySelector( selector ); + } catch ( err1 ) { + + // Didn't *look* valid to qSA, warn and try quoting what we think is the value + selector = selector.replace( rattrHashGlob, function( _, attr, op, value ) { + return "[" + attr + op + "\"" + value + "\"]"; + } ); + + // If the regexp *may* have created an invalid selector, don't update it + // Note that there may be false alarms if selector uses jQuery extensions + try { + document.querySelector( selector ); + migrateWarn( "Attribute selector with '#' must be quoted: " + args[ 0 ] ); + args[ 0 ] = selector; + } catch ( err2 ) { + migrateWarn( "Attribute selector with '#' was not fixed: " + args[ 0 ] ); + } + } + } + + return oldFind.apply( this, args ); +}; + +// Copy properties attached to original jQuery.find method (e.g. .attr, .isXML) +var findProp; +for ( findProp in oldFind ) { + if ( Object.prototype.hasOwnProperty.call( oldFind, findProp ) ) { + jQuery.find[ findProp ] = oldFind[ findProp ]; + } +} + // Let $.parseJSON(falsy_value) return null jQuery.parseJSON = function( json ) { if ( !json ) { diff --git a/src/event.js b/src/event.js index bdf21fb9..892fa63c 100644 --- a/src/event.js +++ b/src/event.js @@ -43,16 +43,17 @@ jQuery.each( [ "load", "unload", "error" ], function( _, name ) { jQuery.fn[ name ] = function() { var args = Array.prototype.slice.call( arguments, 0 ); - migrateWarn( "jQuery.fn." + name + "() is deprecated" ); // If this is an ajax load() the first arg should be the string URL; // technically this could also be the "Anything" arg of the event .load() // which just goes to show why this dumb signature has been deprecated! // jQuery custom builds that exclude the Ajax module justifiably die here. - if ( name === "load" && typeof arguments[ 0 ] === "string" ) { - return oldLoad.apply( this, arguments ); + if ( name === "load" && typeof args[ 0 ] === "string" ) { + return oldLoad.apply( this, args ); } + migrateWarn( "jQuery.fn." + name + "() is deprecated" ); + args.splice( 0, 0, name ); if ( arguments.length ) { return this.bind.apply( this, args ); @@ -152,5 +153,9 @@ jQuery.each( ajaxEvents.split("|"), ); jQuery.event.special.ready = { - setup: function() { migrateWarn( "'ready' event is deprecated" ); } + setup: function() { + if ( this === document ) { + migrateWarn( "'ready' event is deprecated" ); + } + } }; diff --git a/src/intro.js b/src/intro.js index c3e8b3ce..7f59890d 100644 --- a/src/intro.js +++ b/src/intro.js @@ -1,3 +1,15 @@ -(function( jQuery, window, undefined ) { +;(function( factory ) { + /* jshint browserify:true */ + if ( typeof define === "function" && define.amd ) { + // AMD. Register as an anonymous module. + define( [ "jquery" ], window, factory ); + } else if ( typeof module === "object" && module.exports ) { + // Node/CommonJS + module.exports = factory( require( "jquery" ), window ); + } else { + // Browser globals + factory( jQuery, window ); + } +}(function( jQuery, window ) { // See http://bugs.jquery.com/ticket/13335 // "use strict"; diff --git a/src/migrate.js b/src/migrate.js index d2739e5c..ed867607 100644 --- a/src/migrate.js +++ b/src/migrate.js @@ -8,8 +8,10 @@ jQuery.migrateWarnings = []; // jQuery.migrateMute = false; // Show a message on the console so devs know we're active -if ( !jQuery.migrateMute && window.console && window.console.log ) { - window.console.log("JQMIGRATE: Logging is active"); +if ( window.console && window.console.log ) { + window.console.log( "JQMIGRATE: Migrate is installed" + + ( jQuery.migrateMute ? "" : " with logging active" ) + + ", version " + jQuery.migrateVersion ); } // Set to false to disable traces that appear with warnings diff --git a/src/outro.js b/src/outro.js index ff660771..d792ffb5 100644 --- a/src/outro.js +++ b/src/outro.js @@ -1,2 +1,2 @@ - -})( jQuery, window ); +return jQuery; +})); diff --git a/src/traversing.js b/src/traversing.js index dfc01a16..ed57ddae 100644 --- a/src/traversing.js +++ b/src/traversing.js @@ -1,5 +1,5 @@ var oldSelf = jQuery.fn.andSelf || jQuery.fn.addBack, - oldFind = jQuery.fn.find; + oldFnFind = jQuery.fn.find; jQuery.fn.andSelf = function() { migrateWarn("jQuery.fn.andSelf() replaced by jQuery.fn.addBack()"); @@ -7,7 +7,7 @@ jQuery.fn.andSelf = function() { }; jQuery.fn.find = function( selector ) { - var ret = oldFind.apply( this, arguments ); + var ret = oldFnFind.apply( this, arguments ); ret.context = this.context; ret.selector = this.selector ? this.selector + " " + selector : selector; return ret; diff --git a/src/version.js b/src/version.js index 20ac07a6..6e95d055 100644 --- a/src/version.js +++ b/src/version.js @@ -1,2 +1,2 @@ -jQuery.migrateVersion = "1.3.1-pre"; +jQuery.migrateVersion = "1.4.2-pre"; diff --git a/test/core.js b/test/core.js index 59b9fa3e..776c9c17 100644 --- a/test/core.js +++ b/test/core.js @@ -53,15 +53,122 @@ test( "jQuery(html) loose rules", function() { } }); -test( "jQuery( '#' )", function() { - expect( 2 ); +// Selector quoting doesn't work in IE<8 +if ( document.querySelector ) { - expectWarning( "Selector, through the jQuery constructor, nothing but hash", function() { - var set = jQuery( "#" ); - equal( set.length, 0, "empty set" ); +QUnit.test( "Attribute selectors with unquoted hashes", function( assert ) { + expect( 33 ); + + var markup = jQuery( + "
" + + "
" + + "test" + + "" + + "

" + + "anchor2" + + "" + + "anchor" + + "

" + + "
" ).appendTo( "#qunit-fixture" ), + + // No warning, no need to fix + okays = [ + "a[href='#some-anchor']", + "[data-id=\"#junk\"]", + "div[data-selector='a[href=#main]']", + "input[value~= '[strange*=#stuff]']" + ], + + // Fixable, and gives warning + fixables = [ + "a[href=#]", + ".space a[href=#]", + "a[href=#some-anchor]", + "link[rel*=#stuff]", + "p[class *= #junk]", + "a[href=space#junk]" + ], + + // False positives that still work + positives = [ + "div[data-selector='a[href=#main]']:first", + "input[value= '[strange*=#stuff]']:eq(0)" + ], + + // Failures due to quotes and jQuery extensions combined + failures = [ + "p[class ^= #junk]:first", + "a[href=space#junk]:eq(1)" + ]; + + expectNoWarning( "Perfectly cromulent selectors are unchanged", function() { + jQuery.each( okays, function( _, okay ) { + assert.equal( jQuery( okay, markup ).length, 1, okay ); + assert.equal( markup.find( okay ).length, 1, okay ); + } ); + } ); + + expectWarning( "Values with unquoted hashes are quoted", fixables.length, function() { + jQuery.each( fixables, function( _, fixable ) { + assert.equal( jQuery( fixable, markup ).length, 1, fixable ); + assert.equal( markup.find( fixable ).length, 1, fixable ); + } ); + } ); + + expectWarning( "False positives", positives.length, function() { + jQuery.each( positives, function( _, positive ) { + assert.equal( jQuery( positive, markup ).length, 1, positive ); + assert.equal( markup.find( positive ).length, 1, positive ); + } ); + } ); + + expectWarning( "Unfixable cases", failures.length, function() { + jQuery.each( failures, function( _, failure ) { + try { + jQuery( failure, markup ); + assert.ok( true, "jQuery() may die, it didn't" ); + } catch ( err1 ) { + assert.ok( true, "jQuery() may die, it did" ); + } + try { + markup.find( failure ); + assert.ok( true, ".find() may die, it didn't" ); + } catch ( err2 ) { + assert.ok( true, ".find() may die, it did" ); + } + } ); + } ); + + // Ensure we don't process jQuery( x ) when x is a function + expectNoWarning( "ready function with attribute selector", function() { + try { + jQuery( function() { + if ( jQuery.thisIsNeverDefined ) { + jQuery( "a[href=#junk]" ); + } + } ); + } catch( e ) {} }); }); +} + +QUnit.test( "document.context defined (#178)", function( assert ) { + assert.expect( 1 ); + + var span = jQuery( "hi" ).appendTo( "#qunit-fixture" ); + try { + document.context = "!!hosed!!"; + span.wrap( "

" ); + assert.ok( true, "document.context did not kill jQuery" ); + } catch ( err ) { + assert.ok( false, "died while wrapping" ); + } + + // Can't delete this property because of oldIE + document.context = null; +} ); + test( "selector state", function() { expect( 18 ); diff --git a/test/event.js b/test/event.js index 851e90b6..bca9fb32 100644 --- a/test/event.js +++ b/test/event.js @@ -734,7 +734,7 @@ test( "error() event method", function() { }); test( "load() and unload() event methods", function() { - expect( 4 ); + expect( 5 ); expectWarning( "jQuery.fn.load()", function() { jQuery( "" ) @@ -757,6 +757,16 @@ test( "load() and unload() event methods", function() { .unload() .remove(); }); + + expectNoWarning( "ajax load", function() { + stop(); + jQuery( "
" ) + .appendTo( "#qunit-fixture" ) + .load( "not-found.file", function() { + jQuery( "#load138" ).remove(); + start(); + }); + }); }); test( "hover pseudo-event", function() { @@ -792,12 +802,22 @@ test( "hover pseudo-event", function() { }); test( "ready event", function() { - expect( 2 ); + expect( 4 ); expectWarning( "Setting a ready event", 1, function() { jQuery( document ).bind( "ready", function() { ok( true, "ready event was triggered" ); - }).trigger( "ready" ); + }) + .trigger( "ready" ) + .unbind( "ready" ); + }); + + expectNoWarning( "Custom ready event not on document", 1, function() { + jQuery( "#foo" ).bind( "ready", function( e ) { + ok( true, "custom ready event was triggered" ); + }) + .trigger( "ready" ) + .unbind( "ready" ); }); }); diff --git a/test/index.html b/test/index.html index e521d32c..5766056b 100644 --- a/test/index.html +++ b/test/index.html @@ -16,14 +16,14 @@ TestManager.init({ "jquery": { urlTag: "jquery", - choices: "dev,min,git,2.1.3,2.0.3,1.11.2,1.10.2,1.9.1,1.8.3,1.7.2,1.6.4" + choices: "dev,min,2.2.4,2.1.4,2.0.3,1.12.4,1.11.3,1.10.2,1.9.1,1.8.3,1.7.2,1.6.4" }, "jquery-migrate": { urlTag: "plugin", - choices: "dev,min,git,1.0.0,1.1.0,1.2.1" + choices: "dev,min,1.4.1,1.4.0,1.3.0,1.2.1,1.1.1,1.0.0" } }); - TestManager.loadProject( "jquery", "2.x-git" ); + TestManager.loadProject( "jquery", "2.2.4" ); // Close this script tag so file will load