From 62bd4ce4bb00b8aff83aba03ddbf54591831bc5d Mon Sep 17 00:00:00 2001 From: Basix Date: Tue, 16 Feb 2021 13:42:03 +0900 Subject: [PATCH] Apply UMD pattern --- jquery.fontselect.js | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/jquery.fontselect.js b/jquery.fontselect.js index f77b6c1..d98f710 100644 --- a/jquery.fontselect.js +++ b/jquery.fontselect.js @@ -6,7 +6,33 @@ * @version 0.1 */ -(function($){ +(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.fontselect = function(options) { @@ -407,4 +433,4 @@ }); }; -})(jQuery); +}));