FitVids.js
FitVids.js copied to clipboard
Add UMD wrapper
Our team has gotten excellent mileage out of this little library, but have recently switched to browserify as a build tool. This little PR adds a UMD wrapper around the FitVids factory, such that it can be consumed in three different ways, all of which still allow your choice between jQuery or Zepto.
For node
or CommonJS environments (such as browserify), it exports the factory itself, so that the choice of DOM library can be wired up manually:
var $ = require('jquery'); // or require('zepto');
require('fitvids')($);
For AMD environments (like require.js), you can just require
FitVids and then go about your business, since it will wrap itself around whichever DOM library you shimmed in as 'jquery'
:
requirejs.config({
paths: {
fitvids: 'path/to/fitvids.js',
jquery: 'path/to/jquery/or/zepto.js'
}
});
require(['jquery', 'fitvids'], function ($) {
// your code here
});
For those who like to live in the global namespace, that's cool too. The UMD wrapper will recognize that and look for window.jQuery
or window.Zepto
as before.
I ran the test.html
file, and everything performs as it originally did. This PR should also get you very close to publishing on npm (short of actually running npm publish .
). That would be super dreamy! :smile:
I would very much like this—thanks @flintinatux for doing this! +1
:+1: This would be awesome!
Just curious, is there not interest in adding this backwards compatible feature? It looks like there's a fork for this on npm already. It'd be great to have the official library up there.