Skip to content

Commit 9eac5a6

Browse files
committed
Merge pull request marcj#70 from netiul/hotfix-detaching-when-collection-typed
detach correctly when element is collection typed
2 parents 9dfa6d2 + 99ab7da commit 9eac5a6

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/ResizeSensor.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,16 @@
125125
addEvent(expand, 'scroll', onScroll);
126126
addEvent(shrink, 'scroll', onScroll);
127127
}
128-
128+
129129
var elementType = Object.prototype.toString.call(element);
130-
if ('[object Array]' === elementType
130+
var isCollectionTyped = ('[object Array]' === elementType
131131
|| ('[object NodeList]' === elementType)
132132
|| ('[object HTMLCollection]' === elementType)
133133
|| ('undefined' !== typeof jQuery && element instanceof jQuery) //jquery
134134
|| ('undefined' !== typeof Elements && element instanceof Elements) //mootools
135-
) {
135+
);
136+
137+
if (isCollectionTyped) {
136138
var i = 0, j = element.length;
137139
for (; i < j; i++) {
138140
attachResizeEvent(element[i], callback);
@@ -142,7 +144,14 @@
142144
}
143145

144146
this.detach = function() {
145-
ResizeSensor.detach(element);
147+
if (isCollectionTyped) {
148+
var i = 0, j = element.length;
149+
for (; i < j; i++) {
150+
ResizeSensor.detach(element[i]);
151+
}
152+
} else {
153+
ResizeSensor.detach(element);
154+
}
146155
};
147156
};
148157

0 commit comments

Comments
 (0)