From 8bc60bab5dd9747e7ae06c3fdb0c60782d346ff0 Mon Sep 17 00:00:00 2001 From: jrburke Date: Mon, 14 Nov 2011 12:13:25 -0500 Subject: [PATCH] Landing pull request 586. Create exports.js for exporting jQuery to window and AMD. Fixes #10687. More Details: - https://github.com/jquery/jquery/pull/586 - http://bugs.jquery.com/ticket/10687 --- Makefile | 3 ++- src/core.js | 14 -------------- src/exports.js | 22 ++++++++++++++++++++++ src/outro.js | 3 +-- test/index.html | 2 ++ test/unit/core.js | 8 +------- test/unit/exports.js | 7 +++++++ 7 files changed, 35 insertions(+), 24 deletions(-) create mode 100644 src/exports.js create mode 100644 test/unit/exports.js diff --git a/Makefile b/Makefile index 2bc41a070..b33fc2ab8 100644 --- a/Makefile +++ b/Makefile @@ -27,7 +27,8 @@ BASE_FILES = ${SRC_DIR}/core.js\ ${SRC_DIR}/ajax/xhr.js\ ${SRC_DIR}/effects.js\ ${SRC_DIR}/offset.js\ - ${SRC_DIR}/dimensions.js + ${SRC_DIR}/dimensions.js\ + ${SRC_DIR}/exports.js MODULES = ${SRC_DIR}/intro.js\ ${BASE_FILES}\ diff --git a/src/core.js b/src/core.js index bc728ee90..e56394bf6 100644 --- a/src/core.js +++ b/src/core.js @@ -934,20 +934,6 @@ function doScrollCheck() { 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; })(); diff --git a/src/exports.js b/src/exports.js new file mode 100644 index 000000000..7d8964f01 --- /dev/null +++ b/src/exports.js @@ -0,0 +1,22 @@ +(function( jQuery ) { + +// Expose jQuery to the global object +window.jQuery = window.$ = jQuery; + +// 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. +// Do this after creating the global so that if an AMD module wants to call +// noConflict to hide this version of jQuery, it will work. +if ( typeof define === "function" && define.amd && define.amd.jQuery ) { + define( "jquery", [], function () { return jQuery; } ); +} + +})( jQuery ); diff --git a/src/outro.js b/src/outro.js index 64ef28ed3..ac484391c 100644 --- a/src/outro.js +++ b/src/outro.js @@ -1,3 +1,2 @@ -// Expose jQuery to the global object -window.jQuery = window.$ = jQuery; + })( window ); diff --git a/test/index.html b/test/index.html index e6cbc013f..0d518f1ac 100644 --- a/test/index.html +++ b/test/index.html @@ -28,6 +28,7 @@ + @@ -51,6 +52,7 @@ +