Skip to content

Commit 3c687f5

Browse files
author
Murad Rogozhnikov
committed
matchesSelector optimize
1 parent e7941c6 commit 3c687f5

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

lib/draggable.js

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,21 @@ function canDragX(draggable) {
2323
draggable.props.axis === 'x';
2424
}
2525

26-
function isFunction(fn) {
27-
return typeof fn === 'function';
28-
}
29-
3026
function matchesSelector(el, selector) {
31-
if (isFunction(el.matches)) {
32-
return el.matches(selector);
33-
} else if (isFunction(el.webkitMatchesSelector)) {
34-
return el.webkitMatchesSelector(selector);
35-
} else if (isFunction(el.mozMatchesSelector)) {
36-
return el.mozMatchesSelector(selector);
37-
} else if (isFunction(el.msMatchesSelector)) {
38-
return el.msMatchesSelector(selector);
39-
} else if (isFunction(el.oMatchesSelector)) {
40-
return el.oMatchesSelector(selector);
41-
}
27+
var matcheMethods = [
28+
'matches',
29+
'webkitMatchesSelector',
30+
'mozMatchesSelector',
31+
'msMatchesSelector',
32+
'oMatchesSelector'
33+
],
34+
length = matcheMethods.length;
35+
36+
for (var i = 0; i < length; i++) {
37+
if (typeof el[matcheMethods[i]] === 'function') {
38+
return el[matcheMethods[i]](selector);
39+
}
40+
}
4241
}
4342

4443
function addEvent(el, event, handler) {

0 commit comments

Comments
 (0)