Browse Source

refactor _matches() out of _closest()

The _closest() method already defined a way to do what _matches() was
trying to accomplish.  This pulls the functionality out of _closest() so
that it can be reused outside of _closest() but refactors _closest() to
use this new _matches() method.
pull/607/head
Dan LaMotte 9 years ago
parent
commit
4facaff715
  1. 35
      Sortable.js

35
Sortable.js

@ -979,17 +979,11 @@
function _closest(/**HTMLElement*/el, /**String*/selector, /**HTMLElement*/ctx) {
if (el) {
ctx = ctx || document;
selector = selector.split('.');
var tag = selector.shift().toUpperCase(),
re = new RegExp('\\s(' + selector.join('|') + ')(?=\\s)', 'g');
do {
if (
(tag === '>*' && el.parentNode === ctx) || (
(tag === '' || el.nodeName.toUpperCase() == tag) &&
(!selector.length || ((' ' + el.className + ' ').match(re) || []).length == selector.length)
)
(selector === '>*' && el.parentNode === ctx)
|| _matches(el, selector)
) {
return el;
}
@ -1186,20 +1180,19 @@
}
function _matches(/**HTMLElement*/el, /**String*/selector) {
var matches,
i = 0;
if (el.matches) {
return el.matches(selector);
} else if (el.matchesSelector) {
return el.matchesSelector(selector);
} else {
matches = (el.document || el.ownerDocument).querySelectorAll(selector);
while (matches[i] && matches[i] !== el) {
i++;
}
return matches[i] ? true : false;
if (el) {
selector = selector.split('.');
var tag = selector.shift().toUpperCase(),
re = new RegExp('\\s(' + selector.join('|') + ')(?=\\s)', 'g');
return (
(tag === '' || el.nodeName.toUpperCase() == tag) &&
(!selector.length || ((' ' + el.className + ' ').match(re) || []).length == selector.length)
);
}
return false;
}
function _throttle(callback, ms) {

Loading…
Cancel
Save