Skip to content

Commit 6c125e7

Browse files
josephschmittmarcj
authored andcommitted
Use UMD module definition for increase compatibility. (marcj#108)
Also makes importing of ResizeSensor work out of the box with jspm.
1 parent 788b1b2 commit 6c125e7

File tree

2 files changed

+23
-16
lines changed

2 files changed

+23
-16
lines changed

src/ElementQueries.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
* https://github.com/marcj/css-element-queries/blob/master/LICENSE.
55
*/
66
;
7-
(function() {
8-
9-
var ResizeSensor = window.ResizeSensor;
10-
11-
if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
12-
ResizeSensor = require('./ResizeSensor');
7+
(function (root, factory) {
8+
if (typeof define === "function" && define.amd) {
9+
define(['./ResizeSensor.js'], factory);
10+
} else if (typeof exports === "object") {
11+
module.exports = factory(require('./ResizeSensor.js'));
12+
} else {
13+
root.ElementQueries = factory(root.ResizeSensor);
1314
}
15+
}(this, function (ResizeSensor) {
1416

1517
/**
1618
*
@@ -507,4 +509,7 @@
507509
window.ElementQueries = ElementQueries;
508510
ElementQueries.listen();
509511
}
510-
})();
512+
513+
return ElementQueries;
514+
515+
}));

src/ResizeSensor.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@
44
* https://github.com/marcj/css-element-queries/blob/master/LICENSE.
55
*/
66
;
7-
(function() {
7+
(function (root, factory) {
8+
if (typeof define === "function" && define.amd) {
9+
define(factory);
10+
} else if (typeof exports === "object") {
11+
module.exports = factory();
12+
} else {
13+
root.ResizeSensor = factory();
14+
}
15+
}(this, function () {
816

917
// Only used for the dirty checking, so the event callback count is limted to max 1 call per fps per sensor.
1018
// In combination with the event based resize sensor this saves cpu time, because the sensor is too fast and
@@ -205,12 +213,6 @@
205213
});
206214
};
207215

208-
// make available to common module loader
209-
if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
210-
module.exports = ResizeSensor;
211-
}
212-
else {
213-
window.ResizeSensor = ResizeSensor;
214-
}
216+
return ResizeSensor;
215217

216-
})();
218+
}));

0 commit comments

Comments
 (0)