Skip to content

Add UMD wrapper - #209

Open
flintinatux wants to merge 1 commit into
davatron5000:masterfrom
articulate:umd
Open

Add UMD wrapper#209
flintinatux wants to merge 1 commit into
davatron5000:masterfrom
articulate:umd

Conversation

@flintinatux

Copy link
Copy Markdown

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! 😄

@chrisforrette

Copy link
Copy Markdown

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

@olmokramer

Copy link
Copy Markdown

👍 This would be awesome!

Comment thread jquery.fitvids.js

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please keep the style of the IIFE. The semicolon actually makes sense: #192.

@kevinsmith

Copy link
Copy Markdown

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants