AMD-ify jQuery sourcegit s! Woo! Fixes #14113, #14163.

Conflicts:
	Gruntfile.js
	README.md
	src/ajax.js
	src/ajax/xhr.js
	src/attributes.js
	src/core.js
	src/css.js
	src/data.js
	src/effects.js
	src/event.js
	src/manipulation.js
	src/offset.js
	src/selector-native.js
	src/traversing.js
	test/unit/core.js
	test/unit/data.js
This commit is contained in:
Timmy Willison
2013-08-15 14:15:49 -04:00
parent 144837afdf
commit 217cbb7109
73 changed files with 27840 additions and 1659 deletions

View File

@@ -1,6 +1,6 @@
/*jshint multistr:true, quotmark:false */
var amdDefined, fireNative,
var fireNative,
originaljQuery = this.jQuery || "jQuery",
original$ = this.$ || "$",
// see RFC 2606
@@ -13,15 +13,6 @@ this.isLocal = window.location.protocol === "file:";
this.jQuery = originaljQuery;
this.$ = original$;
/**
* Set up a mock AMD define function for testing AMD registration.
*/
function define( name, dependencies, callback ) {
amdDefined = callback();
}
define.amd = {};
/**
* Returns an array of elements with the given IDs
* @example q("main", "foo", "bar")

View File

@@ -242,11 +242,11 @@ this.Globals = (function() {
}
}
};
QUnit.config.urlConfig.push( {
QUnit.config.urlConfig.push({
id: "jqdata",
label: "Always check jQuery.data",
tooltip: "Trigger QUnit.expectJqData detection for all tests instead of just the ones that call it"
} );
});
/**
* Ensures that tests have cleaned up properly after themselves. Should be passed as the

View File

@@ -14,63 +14,33 @@
<script src="data/testinit.js"></script>
<script src="../bower_components/qunit/qunit/qunit.js"></script>
<script>
(function() {
var src = "../dist/jquery.min.js";
// Config parameter to use minified jQuery
QUnit.config.urlConfig.push({
id: "dev",
label: "Load unminified",
tooltip: "Load the development (unminified) jQuery file"
});
if ( QUnit.urlParams.dev ) {
src = "../dist/jquery.js";
}
// Config parameter to force basic code paths
QUnit.config.urlConfig.push({
id: "basic",
label: "Bypass optimizations",
tooltip: "Force use of the most basic code by disabling native querySelectorAll; contains; compareDocumentPosition"
});
if ( QUnit.urlParams.basic ) {
document.querySelectorAll = null;
document.documentElement.contains = null;
document.documentElement.compareDocumentPosition = null;
}
// Load jQuery
document.write( "<script id='jquery-js' src='" + src + "'><\x2Fscript>" );
})();
</script>
<script src="data/testrunner.js"></script>
<script src="unit/core.js"></script>
<script src="unit/callbacks.js"></script>
<script src="unit/deferred.js"></script>
<script src="unit/support.js"></script>
<script src="unit/data.js"></script>
<script src="unit/queue.js"></script>
<script src="unit/attributes.js"></script>
<script src="unit/event.js"></script>
<script src="unit/selector.js"></script>
<script src="unit/traversing.js"></script>
<script src="unit/manipulation.js"></script>
<script src="unit/wrap.js"></script>
<script src="unit/css.js"></script>
<script src="unit/serialize.js"></script>
<script src="unit/ajax.js"></script>
<script src="unit/effects.js"></script>
<script src="unit/offset.js"></script>
<script src="unit/dimensions.js"></script>
<script src="unit/deprecated.js"></script>
<script src="unit/exports.js"></script>
<!-- Subproject tests must be last because they replace our test fixture -->
<script>
testSubproject( "Sizzle", "../bower_components/sizzle/test/", /^unit\/.*\.js$/ );
</script>
<script src="../bower_components/requirejs/require.js"></script>
<script>loadTests = [
"data/testrunner.js",
"unit/core.js",
"unit/callbacks.js",
"unit/deferred.js",
"unit/support.js",
"unit/data.js",
"unit/queue.js",
"unit/attributes.js",
"unit/event.js",
"unit/selector.js",
"unit/traversing.js",
"unit/manipulation.js",
"unit/wrap.js",
"unit/css.js",
"unit/serialize.js",
"unit/ajax.js",
"unit/effects.js",
"unit/offset.js",
"unit/dimensions.js"
];</script>
<!-- A script that includes jQuery min, dev, or AMD -->
<!-- Adds "basic" URL option, even to iframes -->
<!-- iframes will not load AMD as loading needs to be synchronous for some tests -->
<!-- Also loads the tests above synchronously with min or dev and async with AMD -->
<script src="jquery.js"></script>
<script>
// html5shiv, enabling HTML5 elements to be used with jQuery

82
test/jquery.js vendored
View File

@@ -1,5 +1,77 @@
// Use the right jQuery source in iframe tests
document.write( "<script id='jquery-js' src='" +
parent.document.getElementById("jquery-js").src.replace( /^(?![^\/?#]+:)/,
parent.location.pathname.replace( /[^\/]$/, "$0/" ) ) +
"'><\x2Fscript>" );
// Use the right jQuery source on the test page (and iframes)
(function() {
/* global loadTests: true, testSubproject: false */
/* jshint eqeqeq: false */
var i, len,
// Parent is the current window if not an iframe, which is fine
src = /^(.*)test\//.exec( parent.location.pathname )[1],
QUnit = QUnit || parent.QUnit,
require = require || parent.require;
// Config parameter to force basic code paths
QUnit.config.urlConfig.push({
id: "basic",
label: "Bypass optimizations",
tooltip: "Force use of the most basic code by disabling native querySelectorAll; contains; compareDocumentPosition"
});
if ( QUnit.urlParams.basic ) {
document.querySelectorAll = null;
document.documentElement.contains = null;
document.documentElement.compareDocumentPosition = null;
}
// iFrames won't load AMD (the iframe tests synchronously expect jQuery to be there)
QUnit.config.urlConfig.push({
id: "amd",
label: "Load with AMD",
tooltip: "Load the AMD jQuery file (and its dependencies)"
});
if ( QUnit.urlParams.amd && parent == window ) {
require.config({ baseUrl: src });
src = "src/jquery";
// Include tests if specified
if ( typeof loadTests !== "undefined" ) {
QUnit.config.autostart = false;
require( [ src ], function() {
// Ensure load order (to preserve test numbers)
(function loadDep() {
var dep = loadTests.shift();
if ( dep ) {
require( [ dep ], loadDep );
} else {
// Subproject tests must be last because they replace our test fixture
testSubproject( "Sizzle", "../bower_components/sizzle/test/", /^unit\/.*\.js$/ );
QUnit.start();
}
})();
});
} else {
require( [ src ] );
}
return;
}
// Config parameter to use minified jQuery
QUnit.config.urlConfig.push({
id: "dev",
label: "Load unminified",
tooltip: "Load the development (unminified) jQuery file"
});
if ( QUnit.urlParams.dev ) {
src += "dist/jquery.js";
} else {
src += "dist/jquery.min.js";
}
// Load jQuery
document.write( "<script id='jquery-js' src='" + src + "'><\x2Fscript>" );
// Load tests synchronously if available
if ( typeof loadTests !== "undefined" ) {
for ( i = 0, len = loadTests.length; i < len; i++ ) {
document.write( "<script src='" + loadTests.shift() + "'><\x2Fscript>" );
}
}
})();

View File

@@ -17,13 +17,6 @@ test("Basic requirements", function() {
ok( $, "$" );
});
testIframeWithCallback( "Conditional compilation compatibility (#13274)", "core/cc_on.html", function( cc_on, errors, $ ) {
expect( 3 );
ok( true, "JScript conditional compilation " + ( cc_on ? "supported" : "not supported" ) );
deepEqual( errors, [], "No errors" );
ok( $(), "jQuery executes" );
});
test("jQuery()", function() {
var elem, i,
@@ -1358,3 +1351,10 @@ test("jQuery.camelCase()", function() {
equal( jQuery.camelCase( key ), val, "Converts: " + key + " => " + val );
});
});
testIframeWithCallback( "Conditional compilation compatibility (#13274)", "core/cc_on.html", function( cc_on, errors, $ ) {
expect( 3 );
ok( true, "JScript conditional compilation " + ( cc_on ? "supported" : "not supported" ) );
deepEqual( errors, [], "No errors" );
ok( $(), "jQuery executes" );
});

View File

@@ -6,7 +6,7 @@ test("expando", function(){
equal(jQuery.expando !== undefined, true, "jQuery is exposing the expando");
});
function dataTests (elem) {
function dataTests( elem ) {
var dataObj, internalDataObj;
equal( jQuery.data(elem, "foo"), undefined, "No data exists initially" );
@@ -73,30 +73,30 @@ function dataTests (elem) {
test("jQuery.data(div)", 25, function() {
var div = document.createElement("div");
dataTests(div);
dataTests( div );
// We stored one key in the private data
// assert that nothing else was put in there, and that that
// one stayed there.
QUnit.expectJqData(div, "foo");
QUnit.expectJqData( div, "foo" );
});
test("jQuery.data({})", 25, function() {
dataTests({});
dataTests( {} );
});
test("jQuery.data(window)", 25, function() {
// remove bound handlers from window object to stop potential false positives caused by fix for #5280 in
// transports/xhr.js
jQuery(window).off("unload");
jQuery( window ).off( "unload" );
dataTests(window);
dataTests( window );
});
test("jQuery.data(document)", 25, function() {
dataTests(document);
dataTests( document );
QUnit.expectJqData(document, "foo");
QUnit.expectJqData( document, "foo" );
});
test("Expando cleanup", 4, function() {

View File

@@ -12,13 +12,18 @@ test( "zoom of doom (#13089)", function() {
if ( jQuery.css ) {
testIframeWithCallback( "body background is not lost if set prior to loading jQuery (#9239)", "support/bodyBackground.html", function( color, support ) {
expect( 2 );
var okValue = {
"#000000": true,
"rgb(0, 0, 0)": true
};
var okValue = {
"#000000": true,
"rgb(0, 0, 0)": true
};
ok( okValue[ color ], "color was not reset (" + color + ")" );
deepEqual( jQuery.extend( {}, support ), jQuery.support, "Same support properties" );
stop();
// Run doc ready tests as well
jQuery(function() {
deepEqual( jQuery.extend( {}, support ), jQuery.support, "Same support properties" );
start();
});
});
}