diff --git a/src/ElementQueries.js b/src/ElementQueries.js index c98329a..b71d6c9 100755 --- a/src/ElementQueries.js +++ b/src/ElementQueries.js @@ -4,13 +4,15 @@ * https://github.com/marcj/css-element-queries/blob/master/LICENSE. */ ; -(function() { - - var ResizeSensor = window.ResizeSensor; - - if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') { - ResizeSensor = require('./ResizeSensor'); +(function (root, factory) { + if (typeof define === "function" && define.amd) { + define(['./ResizeSensor.js'], factory); + } else if (typeof exports === "object") { + module.exports = factory(require('./ResizeSensor.js')); + } else { + root.ElementQueries = factory(root.ResizeSensor); } +}(this, function (ResizeSensor) { /** * @@ -507,4 +509,7 @@ window.ElementQueries = ElementQueries; ElementQueries.listen(); } -})(); + + return ElementQueries; + +})); diff --git a/src/ResizeSensor.js b/src/ResizeSensor.js index 1349bbd..648a713 100755 --- a/src/ResizeSensor.js +++ b/src/ResizeSensor.js @@ -4,7 +4,15 @@ * https://github.com/marcj/css-element-queries/blob/master/LICENSE. */ ; -(function() { +(function (root, factory) { + if (typeof define === "function" && define.amd) { + define(factory); + } else if (typeof exports === "object") { + module.exports = factory(); + } else { + root.ResizeSensor = factory(); + } +}(this, function () { // Only used for the dirty checking, so the event callback count is limted to max 1 call per fps per sensor. // In combination with the event based resize sensor this saves cpu time, because the sensor is too fast and @@ -205,12 +213,6 @@ }); }; - // make available to common module loader - if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') { - module.exports = ResizeSensor; - } - else { - window.ResizeSensor = ResizeSensor; - } + return ResizeSensor; -})(); \ No newline at end of file +}));