Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add UMD wrapper #209

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Add UMD wrapper #209

wants to merge 1 commit into from

Conversation

flintinatux
Copy link

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

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

@olmokramer
Copy link

👍 This would be awesome!

@@ -9,7 +9,20 @@
*
*/

;(function( $ ){
!function(factory) {
Copy link
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

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