1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-02-13 09:25:44 +01:00

Better DOM#is(). Yay.

This commit is contained in:
Kris Maglione
2011-10-16 15:06:37 -04:00
parent 0c3bccb5c6
commit 3ef14e8c3c
2 changed files with 2 additions and 19 deletions

View File

@@ -98,24 +98,7 @@ var DOM = Class("DOM", {
}]
]),
matcher: function matcher(sel) {
let res;
if (/^([a-z0-9_-]+)$/i.exec(sel))
res = function (elem) elem.localName == val;
else if (/^#([a-z0-9:_-]+)$/i.exec(sel))
res = function (elem) elem.id == val;
else if (/^\.([a-z0-9:_-]+)$/i.exec(sel))
res = function (elem) elem.classList.contains(val);
else if (/^\[([a-z0-9:_-]+)\]$/i.exec(sel))
res = function (elem) elem.hasAttribute(val);
else
res = function (elem) ~Array.indexOf(elem.parentNode.querySelectorAll(sel),
elem);
let val = RegExp.$1;
return res;
},
matcher: function matcher(sel) function (elem) elem.mozMatchesSelector && elem.mozMatchesSelector(sel),
each: function each(fn, self) {
let obj = self || this.Empty();