-
Notifications
You must be signed in to change notification settings - Fork 114
AMD support #4
Comments
@timmywil That's a great idea! |
Hey @timmywil, maybe you can help me with something... I'm a designer first and a developer second, so it's hard for me to judge the best way to tackle this from a developer perspective... especially since I've never used RequireJS before! hideShowPassword works with either jQuery or Zepto. This is easy enough in the current version of the plugin, as I can just pass This post suggests doing something like this: define(('__proto__' in {} ? ['zepto'] : ['jquery']), function($) {
return $;
}); This makes sense to me if your library overtly recommends the use of both Zepto and jQuery, but my goal in writing the plugin that way was flexibility... I would guess most users will be favoring jQuery, so it seems a pretty big assumption to say "when I apologize if this is a newb question, but how would you recommend supporting both frameworks? |
No problem! I'd recommend something like this: (function (factory, global) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
// To use Zepto, map Zepto to the the name 'jquery' in your paths config
define(['jquery'], factory);
} else {
// Browser globals
factory(global.jQuery || global.Zepto);
}
}(function ($) {
// hideShowPassword code here
}, this)); AMD folks who use Zepto are used to mapping zepto already because Zepto doesn't register as an AMD module (much to the objection of Zepto's users and the front-end community). I would simply document that using zepto instead is a matter of path config: require.config({
paths: {
jquery: 'path/to/zepto'
}
}); This will map Zepto to the name 'jquery' and the define call will pull in Zepto for the |
@timmywil Perfect. Thanks so much for the detailed explanation... knowledge is awesome. :) |
@timmywil Okay, I think I have this working... but just in case, I pushed to an amd-support branch. If you get a moment, would you mind taking a look or giving it a whirl before I unleash it on an unsuspecting populace? |
👍 I just tested and it works great! Thanks! |
@timmywil Sweet! Branch merged, release tagged, and bob's your uncle. Thanks again for your help. |
It would be great if this plugin didn't assume a jQuery global. This could be done with the UMD syntax for jQuery plugins.
The text was updated successfully, but these errors were encountered: