diff options
author | isaacs <i@izs.me> | 2013-02-20 21:30:42 -0500 |
---|---|---|
committer | Rick Waldron <waldron.rick@gmail.com> | 2013-02-20 21:31:06 -0500 |
commit | a128355b25dc31a1312e4e190b9e3caec5f0b95b (patch) | |
tree | ac7e360a43da461a201dbaf9966c8ceafe7489ad | |
parent | 0f977e6d03724551ddff51e9ae2b6b9ac61cf649 (diff) | |
download | jquery-a128355b25dc31a1312e4e190b9e3caec5f0b95b.tar.gz jquery-a128355b25dc31a1312e4e190b9e3caec5f0b95b.zip |
Support node-like module loaders. Closes gh-1103
-rw-r--r-- | src/exports.js | 40 | ||||
-rw-r--r-- | src/outro.js | 2 |
2 files changed, 25 insertions, 17 deletions
diff --git a/src/exports.js b/src/exports.js index 88def50ba..c535b7eef 100644 --- a/src/exports.js +++ b/src/exports.js @@ -1,18 +1,26 @@ -// Expose jQuery to the global object -window.jQuery = window.$ = jQuery; +if ( typeof module === "object" && typeof module.exports === "object" ) { + // Expose jQuery as module.exports in loaders that implement the Node + // module pattern (including browserify). Do not create the global, since + // the user will be storing it themselves locally, and globals are frowned + // upon in the Node module world. + module.exports = jQuery; +} else { + // Otherwise expose jQuery to the global object as usual + 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; } ); + // 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; } ); + } } diff --git a/src/outro.js b/src/outro.js index ac484391c..70233feb1 100644 --- a/src/outro.js +++ b/src/outro.js @@ -1,2 +1,2 @@ -})( window ); +})( this ); |