Skip to content

Commit

Permalink
Add support for an array of event types
Browse files Browse the repository at this point in the history
  • Loading branch information
bfred-it committed Dec 21, 2016
1 parent d8ab407 commit 0f8f572
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
function getElementsList(elements) {
if (typeof elements === 'string') {
elements = document.querySelectorAll(elements);
}
if (!elements) {
return [];
}
// if elements is actually just one element or window or document
if (typeof elements === 'string') {
elements = document.querySelectorAll(elements);
}
// if `elements` supports events directly (one element, document, window)
if (typeof elements.addEventListener === 'function') {
return [elements];
}
return elements;
}

function run(action, elements, types, listener, useCapture) {
types = types.split(' ').filter();
if (typeof types === 'string') {
types = types.split(' ').filter();
}
elements = getElementsList(elements);
var i, l, m, n;
for (i = 0, l = elements.length; i < l; i++) {
Expand Down

0 comments on commit 0f8f572

Please sign in to comment.