From 9fac2e40bb000c2dad522f3245e17c7542ec405d Mon Sep 17 00:00:00 2001 From: Stanescu Eduard-Dan Date: Tue, 27 Aug 2024 15:35:15 +0300 Subject: [PATCH] UMD compatibility added --- jsStack.js | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/jsStack.js b/jsStack.js index 9b8cd25..1260a47 100644 --- a/jsStack.js +++ b/jsStack.js @@ -4,7 +4,19 @@ * License: Apache 2 * Author: https://elmah.io */ -(function() { + +(function (root, factory) { + if (typeof define === 'function' && define.amd) { + // AMD + define([], factory); + } else if (typeof module === 'object' && module.exports) { + // Node, CommonJS-like + module.exports = factory(); + } else { + // Browser globals (root is window) + root.jsStack = factory(); + } +}(typeof self !== 'undefined' ? self : this, function () { 'use strict'; function jsStack(element, options) { @@ -101,8 +113,11 @@ } // Expose the plugin globally - window.jsStack = function(selector, options) { + function jsStackLibrary(selector, options) { var elements = document.querySelectorAll(selector); initJsStack(Array.from(elements), options); - }; -})(); \ No newline at end of file + } + + return jsStackLibrary; + +})); \ No newline at end of file