Skip to content

Instantly share code, notes, and snippets.

@lynsei
Created November 15, 2021 02:40
Show Gist options
  • Save lynsei/95f01d6ddf9097d2986b68304a5d22e2 to your computer and use it in GitHub Desktop.
Save lynsei/95f01d6ddf9097d2986b68304a5d22e2 to your computer and use it in GitHub Desktop.
This is a UMS Plugin beingn created for jQuery, following the UMD spec here: https://github.com/umdjs/umd
// Uses CommonJS, AMD or browser globals to create a jQuery plugin.
(function (factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['jquery'], factory);
} else if (typeof module === 'object' && module.exports) {
// Node/CommonJS
module.exports = function( root, jQuery ) {
if ( jQuery === undefined ) {
// require('jQuery') returns a factory that requires window to
// build a jQuery instance, we normalize how we use modules
// that require this pattern but the window provided is a noop
// if it's defined (how jquery works)
if ( typeof window !== 'undefined' ) {
jQuery = require('jquery');
}
else {
jQuery = require('jquery')(root);
}
}
factory(jQuery);
return jQuery;
};
} else {
// Browser globals
factory(jQuery);
}
}(function ($) {
$.fn.jqueryPlugin = function () { return true; };
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment