Support for :host, ::content and similar selectors in element.matches()

This commit is contained in:
Nazar Mokrynskyi
2015-01-24 08:49:04 +01:00
parent 9f91fd5d9d
commit 215806a2a7

View File

@@ -60,6 +60,30 @@
oldValue: oldValue
});
}
function shimMatchesSelector (selector) {
selector = selector
// Transform `:host(selector)` to `selector`
.replace(
/:host\(([^\s]+)\)/g,
'$1'
)
// Transform `selector:host` to `selector`
.replace(
/([^\s]):host/g,
'$1'
)
// Transform `:host` to `*`
.replace(
':host',
'*'
);
// From ShadowCSS, will be replaced by space
selector = selector.replace(
/\^|\/shadow\/|\/shadow-deep\/|::shadow|\/deep\/|::content/g,
' '
);
return selector;
}
var classListTable = new WeakMap();
@@ -99,6 +123,7 @@
},
matches: function(selector) {
selector = shimMatchesSelector(selector);
return originalMatches.call(unsafeUnwrap(this), selector);
},