Skip to content

Commit 9da2161

Browse files
osvaldoMstanlemon
authored andcommitted
Add amd and commonjs support (#75)
1 parent 68cb84d commit 9da2161

File tree

3 files changed

+1270
-8
lines changed

3 files changed

+1270
-8
lines changed

jquery.jgrowl.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,30 @@
154154
* - Removed dependency on metadata plugin in favor of .data()
155155
* - Namespaced all events
156156
*/
157-
(function($) {
157+
158+
// Support for UMD style
159+
// Based on UMDjs (https://github.com/umdjs/umd/blob/master/templates/jqueryPlugin.js)
160+
(function (factory) {
161+
if (typeof define === 'function' && define.amd) {
162+
define(['jquery'], factory);
163+
} else if (typeof module === 'object' && module.exports) {
164+
module.exports = function( root, jQuery ) {
165+
if ( jQuery === undefined ) {
166+
if ( typeof window !== 'undefined' ) {
167+
jQuery = require('jquery');
168+
}
169+
else {
170+
jQuery = require('jquery')(root);
171+
}
172+
}
173+
factory(jQuery);
174+
return jQuery;
175+
};
176+
} else {
177+
factory(jQuery);
178+
}
179+
}(function ($) {
180+
158181
/** jGrowl Wrapper - Establish a base jGrowl Container for compatibility with older releases. **/
159182
$.jGrowl = function( m , o ) {
160183
// To maintain compatibility with older version that only supported one instance we'll create the base container.
@@ -396,4 +419,4 @@
396419
/** Reference the Defaults Object for compatibility with older versions of jGrowl **/
397420
$.jGrowl.defaults = $.fn.jGrowl.prototype.defaults;
398421

399-
})(jQuery);
422+
}));

0 commit comments

Comments
 (0)