Skip to content

Commit 4990ac9

Browse files
MikhailRootmarcandre
authored andcommitted
Turned featherlight.js into UMD module (#377)
Now we can use it in ES6 code like `import 'featherlight';` and it will not say there's no jQuery if you use webpack.
1 parent 3690049 commit 4990ac9

File tree

2 files changed

+56
-6
lines changed

2 files changed

+56
-6
lines changed

src/featherlight.gallery.js

+28-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,36 @@
11
/**
22
* Featherlight Gallery – an extension for the ultra slim jQuery lightbox
3-
* Version 1.7.13 - http://noelboss.github.io/featherlight/
3+
* Version 1.7.13-UMD - http://noelboss.github.io/featherlight/
44
*
55
* Copyright 2018, Noël Raoul Bossart (http://www.noelboss.com)
66
* MIT Licensed.
77
**/
8-
(function($) {
8+
(function (factory) {
9+
if (typeof define === 'function' && define.amd) {
10+
// AMD. Register as an anonymous module.
11+
define(['jquery'], factory);
12+
} else if (typeof module === 'object' && module.exports) {
13+
// Node/CommonJS
14+
module.exports = function (root, jQuery) {
15+
if (jQuery === undefined) {
16+
// require('jQuery') returns a factory that requires window to
17+
// build a jQuery instance, we normalize how we use modules
18+
// that require this pattern but the window provided is a noop
19+
// if it's defined (how jquery works)
20+
if (typeof window !== 'undefined') {
21+
jQuery = require('jquery');
22+
} else {
23+
jQuery = require('jquery')(root);
24+
}
25+
}
26+
factory(jQuery);
27+
return jQuery;
28+
};
29+
} else {
30+
// Browser globals
31+
factory(jQuery);
32+
}
33+
})(function($) {
934
"use strict";
1035

1136
var warn = function(m) {
@@ -167,4 +192,4 @@
167192
/* bind featherlight on ready if config autoBind is set */
168193
$(document).ready(function(){ FeatherlightGallery._onReady(); });
169194

170-
}(jQuery));
195+
});

src/featherlight.js

+28-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,36 @@
11
/**
22
* Featherlight - ultra slim jQuery lightbox
3-
* Version 1.7.13 - http://noelboss.github.io/featherlight/
3+
* Version 1.7.13-UMD - http://noelboss.github.io/featherlight/
44
*
55
* Copyright 2018, Noël Raoul Bossart (http://www.noelboss.com)
66
* MIT Licensed.
77
**/
8-
(function($) {
8+
(function (factory) {
9+
if (typeof define === 'function' && define.amd) {
10+
// AMD. Register as an anonymous module.
11+
define(['jquery'], factory);
12+
} else if (typeof module === 'object' && module.exports) {
13+
// Node/CommonJS
14+
module.exports = function (root, jQuery) {
15+
if (jQuery === undefined) {
16+
// require('jQuery') returns a factory that requires window to
17+
// build a jQuery instance, we normalize how we use modules
18+
// that require this pattern but the window provided is a noop
19+
// if it's defined (how jquery works)
20+
if (typeof window !== 'undefined') {
21+
jQuery = require('jquery');
22+
} else {
23+
jQuery = require('jquery')(root);
24+
}
25+
}
26+
factory(jQuery);
27+
return jQuery;
28+
};
29+
} else {
30+
// Browser globals
31+
factory(jQuery);
32+
}
33+
})(function($) {
934
"use strict";
1035

1136
if('undefined' === typeof $) {
@@ -640,4 +665,4 @@
640665

641666
/* bind featherlight on ready if config autoBind is set */
642667
$(document).ready(function(){ Featherlight._onReady(); });
643-
}(jQuery));
668+
});

0 commit comments

Comments
 (0)