Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Create exports.js for exporting jQuery to window and AMD. #586

Closed
wants to merge 2 commits into from

3 participants

@jrburke

This is in reference to ticket 10687. It is an updated pull request that supersedes #584. This ticket is based on feedback from @timmywil who asked for a new file that could be included in the tests so that the amdDefine test could be preserved.

The output of this file is the same as in #584 which was tested with the curl and requirejs AMD loaders. I also tested the built file from this branch with requirejs just for good measure.

@mikesherov
Collaborator

Should exports.js be wrapped in (function(jQuery){}(jQuery); like the other modules?

@timmywil
Collaborator

In this case it's not a big deal, but it wouldn't hurt.

@jrburke

Since exports.js does not declare any local variables that should be hidden from the other jQuery pieces or from the global scope, then I can see a case for not adding the wrapper, to keep the size of jQuery in check.

However, if you want it in there, just post back a confirmation and I will add it.

@timmywil
Collaborator

The makefile should remove all closures from each individual module and leave only the intro/outro in the built file.

@jrburke

Wow, I completely misread the Makefile, I scanned right over the dots in the regexp. I updated the patch to include the wrapper.

@timmywil
Collaborator

Landed in commit 8bc60ba.

@timmywil timmywil closed this
@mescoda mescoda referenced this pull request from a commit in mescoda/jquery
@jrburke jrburke Landing pull request 586. Create exports.js for exporting jQuery to w…
…indow and AMD. Fixes #10687.

More Details:
 - jquery#586
 - http://bugs.jquery.com/ticket/10687
9351c9e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
3  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}\
View
14 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;
})();
View
22 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 );
View
3  src/outro.js
@@ -1,3 +1,2 @@
-// Expose jQuery to the global object
-window.jQuery = window.$ = jQuery;
+
})( window );
View
2  test/index.html
@@ -28,6 +28,7 @@
<script src="../src/effects.js"></script>
<script src="../src/offset.js"></script>
<script src="../src/dimensions.js"></script>
+ <script src="../src/exports.js"></script>
<script src="data/versioncheck.js"></script>
@@ -51,6 +52,7 @@
<script src="unit/effects.js"></script>
<script src="unit/offset.js"></script>
<script src="unit/dimensions.js"></script>
+ <script src="unit/exports.js"></script>
<script>
// html5shiv, enabling HTML5 elements to be used with jQuery
View
8 test/unit/core.js
@@ -225,12 +225,6 @@ test("browser", function() {
});
}
-test("amdModule", function() {
- expect(1);
-
- equal( jQuery, amdDefined, "Make sure defined module matches jQuery" );
-});
-
test("noConflict", function() {
expect(7);
@@ -534,7 +528,7 @@ test("isXMLDoc - HTML", function() {
test("XSS via location.hash", function() {
expect(1);
-
+
stop();
jQuery._check9521 = function(x){
ok( x, "script called from #id-like selector with inline handler" );
View
7 test/unit/exports.js
@@ -0,0 +1,7 @@
+module("exports", { teardown: moduleTeardown });
+
+test("amdModule", function() {
+ expect(1);
+
+ equal( jQuery, amdDefined, "Make sure defined module matches jQuery" );
+});
Something went wrong with that request. Please try again.