Skip to content

Commit 76a0b2a

Browse files
author
Kevin Morris
committed
Updates AMD definition and adds CommonJS
1 parent 365d97e commit 76a0b2a

File tree

1 file changed

+25
-15
lines changed

1 file changed

+25
-15
lines changed

src/jquery.form.js

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,32 @@
1010
*/
1111
/*global ActiveXObject */
1212

13-
// AMD support
1413
(function (factory) {
15-
"use strict";
16-
if (typeof define === 'function' && define.amd) {
17-
// using AMD; register as anon module
18-
define(['jquery'], factory);
19-
} if (typeof module !== 'undefined') {
20-
factory(require('jquery'));
21-
} else {
22-
// no AMD; invoke directly
23-
factory( (typeof(jQuery) != 'undefined') ? jQuery : window.Zepto );
24-
}
25-
}
26-
27-
(function($) {
14+
if (typeof define === 'function' && define.amd) {
15+
// AMD. Register as an anonymous module.
16+
define(['jquery'], factory);
17+
} else if (typeof module === 'object' && module.exports) {
18+
// Node/CommonJS
19+
module.exports = function( root, jQuery ) {
20+
if ( jQuery === undefined ) {
21+
// require('jQuery') returns a factory that requires window to build a jQuery instance, we normalize how we use modules
22+
// that require this pattern but the window provided is a noop if it's defined (how jquery works)
23+
if ( typeof window !== 'undefined' ) {
24+
jQuery = require('jquery');
25+
}
26+
else {
27+
jQuery = require('jquery')(root);
28+
}
29+
}
30+
factory(jQuery);
31+
return jQuery;
32+
};
33+
} else {
34+
// Browser globals
35+
factory(jQuery);
36+
}
37+
38+
}(function ($) {
2839
"use strict";
2940

3041
/*
@@ -1359,5 +1370,4 @@ function log() {
13591370
window.opera.postError(msg);
13601371
}
13611372
}
1362-
13631373
}));

0 commit comments

Comments
 (0)