Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80684 views
1
var nwmatcher = require("nwmatcher/src/nwmatcher-noqsa");
2
3
function addNwmatcher(document) {
4
if (!document._nwmatcher) {
5
document._nwmatcher = nwmatcher({ document: document });
6
document._nwmatcher.configure({ UNIQUE_ID: false });
7
}
8
return document._nwmatcher;
9
}
10
11
exports.applyQuerySelectorPrototype = function(dom) {
12
dom.Document.prototype.querySelector = function(selector) {
13
return addNwmatcher(this).first(selector, this);
14
};
15
16
dom.Document.prototype.querySelectorAll = function(selector) {
17
return new dom.NodeList(addNwmatcher(this).select(selector, this));
18
};
19
20
dom.DocumentFragment.prototype.querySelector = function(selector) {
21
return addNwmatcher(this.ownerDocument).first(selector, this);
22
};
23
24
dom.DocumentFragment.prototype.querySelectorAll = function(selector) {
25
return new dom.NodeList(addNwmatcher(this.ownerDocument).select(selector, this));
26
};
27
28
dom.Element.prototype.querySelector = function(selector) {
29
return addNwmatcher(this.ownerDocument).first(selector, this);
30
};
31
32
dom.Element.prototype.querySelectorAll = function(selector) {
33
return new dom.NodeList(addNwmatcher(this.ownerDocument).select(selector, this));
34
};
35
36
dom.Element.prototype.matchesSelector = function(selector) {
37
return addNwmatcher(this.ownerDocument).match(this, selector);
38
};
39
};
40
41