Skip to content
This repository was archived by the owner on Apr 20, 2018. It is now read-only.

Commit f4b444f

Browse files
Austin PivarnikAustin Pivarnik
authored andcommitted
Add isNodeList function, to check if element is a NodeList or StaticNodeList
1 parent 55404d3 commit f4b444f

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

src/core/linq/observable/fromevent.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
/**
2+
* Returns true if `el` is a NodeList or StaticNodeList (IE8 querySelectorAll returns a StaticNodeList)
3+
* @param {object} el
4+
* @returns {boolean}
5+
*/
6+
function isNodeList(el) {
7+
if (window.StaticNodeList) {
8+
// IE8 Specific
9+
// instanceof is slower than Object#toString, but Object#toString will not work as intended in IE8
10+
return (el instanceof window.StaticNodeList || el instanceof NodeList);
11+
} else {
12+
return (Object.prototype.toString.call(el) == '[object NodeList]')
13+
}
14+
}
115
function fixEvent(event) {
216
var stopPropagation = function () {
317
this.cancelBubble = true;
@@ -80,7 +94,7 @@
8094
var disposables = new CompositeDisposable();
8195

8296
// Asume NodeList
83-
if (Object.prototype.toString.call(el) === '[object NodeList]') {
97+
if (isNodeList(el)) {
8498
for (var i = 0, len = el.length; i < len; i++) {
8599
disposables.add(createEventListener(el.item(i), eventName, handler));
86100
}

0 commit comments

Comments
 (0)