Commit bba3d610 authored by jrburke's avatar jrburke Committed by timmywil

Landing pull request 331. Add support for registering jQuery as an AMD module. Fixes #7102.

More Details:
 - https://github.com/jquery/jquery/pull/331
 - http://bugs.jquery.com/ticket/7102
parents 2831cfd0 0b1c2e64
...@@ -935,6 +935,20 @@ function doScrollCheck() { ...@@ -935,6 +935,20 @@ function doScrollCheck() {
jQuery.ready(); jQuery.ready();
} }
// Expose jQuery as an AMD module, but only for AMD loaders that
// understand the issues with loading multiple versions of jQuery
// in a page that all might call define(). The loader will indicate
// they have special allowances for multiple jQuery versions by
// specifying define.amd.jQuery = true. Register as a named module,
// since jQuery can be concatenated with other files that may use define,
// but not use a proper concatenation script that understands anonymous
// AMD modules. A named AMD is safest and most robust way to register.
// Lowercase jquery is used because AMD module names are derived from
// file names, and jQuery is normally delivered in a lowercase file name.
if ( typeof define === "function" && define.amd && define.amd.jQuery ) {
define( "jquery", [], function () { return jQuery; } );
}
return jQuery; return jQuery;
})(); })();
var jQuery = this.jQuery || "jQuery", // For testing .noConflict() var jQuery = this.jQuery || "jQuery", // For testing .noConflict()
$ = this.$ || "$", $ = this.$ || "$",
originaljQuery = jQuery, originaljQuery = jQuery,
original$ = $; original$ = $,
amdDefined;
/**
* Set up a mock AMD define function for testing AMD registration.
*/
function define(name, dependencies, callback) {
amdDefined = callback();
}
define.amd = {
jQuery: true
};
/** /**
* Returns an array of elements with the given IDs, eg. * Returns an array of elements with the given IDs, eg.
......
...@@ -225,6 +225,12 @@ test("browser", function() { ...@@ -225,6 +225,12 @@ test("browser", function() {
}); });
} }
test("amdModule", function() {
expect(1);
equals( jQuery, amdDefined, "Make sure defined module matches jQuery" );
});
test("noConflict", function() { test("noConflict", function() {
expect(7); expect(7);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment