Skip to content

Commit

Permalink
Turned featherlight.js into UMD module (#377)
Browse files Browse the repository at this point in the history
Now we can use it in ES6 code like `import 'featherlight';` and it will not say there's no jQuery if you use webpack.
  • Loading branch information
MikhailRoot authored and marcandre committed Aug 21, 2019
1 parent 3690049 commit 4990ac9
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 6 deletions.
31 changes: 28 additions & 3 deletions src/featherlight.gallery.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,36 @@
/**
* Featherlight Gallery – an extension for the ultra slim jQuery lightbox
* Version 1.7.13 - http://noelboss.github.io/featherlight/
* Version 1.7.13-UMD - http://noelboss.github.io/featherlight/
*
* Copyright 2018, Noël Raoul Bossart (http://www.noelboss.com)
* MIT Licensed.
**/
(function($) {
(function (factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['jquery'], factory);
} else if (typeof module === 'object' && module.exports) {
// Node/CommonJS
module.exports = function (root, jQuery) {
if (jQuery === undefined) {
// require('jQuery') returns a factory that requires window to
// build a jQuery instance, we normalize how we use modules
// that require this pattern but the window provided is a noop
// if it's defined (how jquery works)
if (typeof window !== 'undefined') {
jQuery = require('jquery');
} else {
jQuery = require('jquery')(root);
}
}
factory(jQuery);
return jQuery;
};
} else {
// Browser globals
factory(jQuery);
}
})(function($) {
"use strict";

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

}(jQuery));
});
31 changes: 28 additions & 3 deletions src/featherlight.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,36 @@
/**
* Featherlight - ultra slim jQuery lightbox
* Version 1.7.13 - http://noelboss.github.io/featherlight/
* Version 1.7.13-UMD - http://noelboss.github.io/featherlight/
*
* Copyright 2018, Noël Raoul Bossart (http://www.noelboss.com)
* MIT Licensed.
**/
(function($) {
(function (factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['jquery'], factory);
} else if (typeof module === 'object' && module.exports) {
// Node/CommonJS
module.exports = function (root, jQuery) {
if (jQuery === undefined) {
// require('jQuery') returns a factory that requires window to
// build a jQuery instance, we normalize how we use modules
// that require this pattern but the window provided is a noop
// if it's defined (how jquery works)
if (typeof window !== 'undefined') {
jQuery = require('jquery');
} else {
jQuery = require('jquery')(root);
}
}
factory(jQuery);
return jQuery;
};
} else {
// Browser globals
factory(jQuery);
}
})(function($) {
"use strict";

if('undefined' === typeof $) {
Expand Down Expand Up @@ -640,4 +665,4 @@

/* bind featherlight on ready if config autoBind is set */
$(document).ready(function(){ Featherlight._onReady(); });
}(jQuery));
});

0 comments on commit 4990ac9

Please sign in to comment.