FitVids.js icon indicating copy to clipboard operation
FitVids.js copied to clipboard

Add UMD wrapper

Open flintinatux opened this issue 9 years ago • 3 comments

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:

flintinatux avatar Mar 06 '15 20:03 flintinatux

I would very much like this—thanks @flintinatux for doing this! +1

chrisforrette avatar Mar 11 '15 21:03 chrisforrette

:+1: This would be awesome!

olmokramer avatar Apr 29 '15 16:04 olmokramer

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.

kevinsmith avatar Nov 30 '16 23:11 kevinsmith