X Tutup
Skip to content

Commit a128355

Browse files
isaacsrwaldron
authored andcommitted
Support node-like module loaders. Closes jquerygh-1103
1 parent 0f977e6 commit a128355

File tree

2 files changed

+25
-17
lines changed

2 files changed

+25
-17
lines changed

src/exports.js

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
1-
// Expose jQuery to the global object
2-
window.jQuery = window.$ = jQuery;
1+
if ( typeof module === "object" && typeof module.exports === "object" ) {
2+
// Expose jQuery as module.exports in loaders that implement the Node
3+
// module pattern (including browserify). Do not create the global, since
4+
// the user will be storing it themselves locally, and globals are frowned
5+
// upon in the Node module world.
6+
module.exports = jQuery;
7+
} else {
8+
// Otherwise expose jQuery to the global object as usual
9+
window.jQuery = window.$ = jQuery;
310

4-
// Expose jQuery as an AMD module, but only for AMD loaders that
5-
// understand the issues with loading multiple versions of jQuery
6-
// in a page that all might call define(). The loader will indicate
7-
// they have special allowances for multiple jQuery versions by
8-
// specifying define.amd.jQuery = true. Register as a named module,
9-
// since jQuery can be concatenated with other files that may use define,
10-
// but not use a proper concatenation script that understands anonymous
11-
// AMD modules. A named AMD is safest and most robust way to register.
12-
// Lowercase jquery is used because AMD module names are derived from
13-
// file names, and jQuery is normally delivered in a lowercase file name.
14-
// Do this after creating the global so that if an AMD module wants to call
15-
// noConflict to hide this version of jQuery, it will work.
16-
if ( typeof define === "function" && define.amd && define.amd.jQuery ) {
17-
define( "jquery", [], function () { return jQuery; } );
11+
// Expose jQuery as an AMD module, but only for AMD loaders that
12+
// understand the issues with loading multiple versions of jQuery
13+
// in a page that all might call define(). The loader will indicate
14+
// they have special allowances for multiple jQuery versions by
15+
// specifying define.amd.jQuery = true. Register as a named module,
16+
// since jQuery can be concatenated with other files that may use define,
17+
// but not use a proper concatenation script that understands anonymous
18+
// AMD modules. A named AMD is safest and most robust way to register.
19+
// Lowercase jquery is used because AMD module names are derived from
20+
// file names, and jQuery is normally delivered in a lowercase file name.
21+
// Do this after creating the global so that if an AMD module wants to call
22+
// noConflict to hide this version of jQuery, it will work.
23+
if ( typeof define === "function" && define.amd && define.amd.jQuery ) {
24+
define( "jquery", [], function () { return jQuery; } );
25+
}
1826
}

src/outro.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11

2-
})( window );
2+
})( this );

0 commit comments

Comments
 (0)
X Tutup