Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for registering jQuery as an AMD module. Only does so if the #331

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/core.js
Expand Up @@ -930,6 +930,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; } );
}

// Expose jQuery to the global object // Expose jQuery to the global object
return jQuery; return jQuery;


Expand Down
14 changes: 13 additions & 1 deletion test/data/testinit.js
@@ -1,7 +1,19 @@
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.
Expand Down
8 changes: 7 additions & 1 deletion test/unit/core.js
Expand Up @@ -214,6 +214,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);


Expand Down Expand Up @@ -850,7 +856,7 @@ test("jQuery.each(Object,Function)", function() {
f[i] = "baz"; f[i] = "baz";
}); });
equals( "baz", f.foo, "Loop over a function" ); equals( "baz", f.foo, "Loop over a function" );

var stylesheet_count = 0; var stylesheet_count = 0;
jQuery.each(document.styleSheets, function(i){ jQuery.each(document.styleSheets, function(i){
stylesheet_count++; stylesheet_count++;
Expand Down