Skip to content

Commit d6daad6

Browse files
committed
ResizeSensor now following Universal Module Definition for compatibility with CommonJS and a fallback as a browser globals
1 parent dd7e4cb commit d6daad6

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/ResizeSensor.js

Lines changed: 14 additions & 4 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 module === 'object' && module.exports) {
11+
module.exports = factory();
12+
} else {
13+
root.ResizeSensor = factory();
14+
}
15+
}(this, function(){
816

917
/**
1018
* Class for dimension change detection.
@@ -14,7 +22,7 @@
1422
*
1523
* @constructor
1624
*/
17-
this.ResizeSensor = function(element, callback) {
25+
function ResizeSensor(element, callback) {
1826
/**
1927
*
2028
* @constructor
@@ -155,12 +163,14 @@
155163
};
156164
};
157165

158-
this.ResizeSensor.detach = function(element) {
166+
ResizeSensor.detach = function(element) {
159167
if (element.resizeSensor) {
160168
element.removeChild(element.resizeSensor);
161169
delete element.resizeSensor;
162170
delete element.resizedAttached;
163171
}
164172
};
165173

166-
})();
174+
return ResizeSensor;
175+
176+
}));

0 commit comments

Comments
 (0)