Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions source/tappable.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

var abs = Math.abs,
noop = function(){},
dEl = d.documentElement,
matchesSelectorFn = dEl.matchesSelector || dEl.mozMatchesSelector || dEl.webkitMatchesSelector || dEl.oMatchesSelector || dEl.msMatchesSelector,
defaults = {
noScroll: false,
activeClass: 'tappable-active',
Expand Down Expand Up @@ -70,21 +72,29 @@
}
el.className = el.className.replace(new RegExp('(^|\\s)' + className + '(?:\\s|$)'), '$1');
},
matchesSelector = function(node, selector){
var root = d.documentElement,
matches = root.matchesSelector || root.mozMatchesSelector || root.webkitMatchesSelector || root.oMatchesSelector || root.msMatchesSelector;
return matches.call(node, selector);
matchesSelector = function (node, selector) {
return matchesSelectorFn.call(node, selector);
},
closest = function(node, selector){
var matches = false;
do {
matches = matchesSelector(node, selector);
} while (!matches && (node = node.parentNode) && node.ownerDocument);
return matches ? node : false;
if (typeof selector === 'string') {
var matches = false;
do {
matches = matchesSelector(node, selector);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure this works without .call() ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really :D just tested it without selectors :/

} while (!matches && (node = node.parentNode) && node.ownerDocument);
return matches ? node : false;
} else {
if (node === selector || selector.contains(node)) {
return selector;
}
return false;
}
};

w.tappable = function(selector, opts){
if (typeof opts == 'function') opts = { onTap: opts };
if (typeof selector === 'undefined') {
return;
}
if (typeof opts === 'function') opts = { onTap: opts };
var options = {};
for (var key in defaults) options[key] = opts[key] || defaults[key];

Expand Down