From 2be1637db2ea3dedab9e8e6e3d3c0d61a249a704 Mon Sep 17 00:00:00 2001 From: Mark Polyakov Date: Tue, 8 Jan 2019 06:04:58 -0800 Subject: [PATCH] Expose API via CommonJS instead of a global variable, when supported (#38) * Expose API via CommonJS instead of a global variable, when supported * use double quotes :( * bump verison number, this is a breaking change --- multirange.js | 17 +++++++++++------ package.json | 2 +- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/multirange.js b/multirange.js index de90c2b..2ba4a01 100644 --- a/multirange.js +++ b/multirange.js @@ -5,7 +5,7 @@ var supportsMultiple = self.HTMLInputElement && "valueLow" in HTMLInputElement.p var descriptor = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, "value"); -self.multirange = function(input) { +var multirange = function(input) { if (supportsMultiple || input.classList.contains("multirange")) { return; } @@ -76,11 +76,16 @@ multirange.init = function() { [].slice.call(document.querySelectorAll("input[type=range][multiple]:not(.multirange)")).forEach(multirange); } -if (document.readyState == "loading") { - document.addEventListener("DOMContentLoaded", multirange.init); -} -else { - multirange.init(); +if (typeof module === "undefined") { + self.multirange = multirange; + if (document.readyState == "loading") { + document.addEventListener("DOMContentLoaded", multirange.init); + } + else { + multirange.init(); + } +} else { + module.exports = multirange; } })(); diff --git a/package.json b/package.json index fba2dfd..6e89351 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "multirange", - "version": "1.0.0", + "version": "2.0.0", "description": "A tiny polyfill for HTML5 multi-handle sliders", "main": "multirange.js", "scripts": {