Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

You can remove this function #4

Open
Spuds opened this issue Mar 27, 2022 · 3 comments
Open

You can remove this function #4

Spuds opened this issue Mar 27, 2022 · 3 comments

Comments

@Spuds
Copy link

Spuds commented Mar 27, 2022

if ((typeof Node != 'undefined') && !document.selectNodes) {
Node.prototype.selectNodes = function(xpath, resolver) {
var contextNode = this.ownerDocument || this,
result = [],
i = 0,
node,
nodes = contextNode.evaluate(xpath, contextNode, resolver || null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
while (node = nodes.snapshotItem(i++)) {
result.push(node);
}
return result;
};
Node.prototype.selectSingleNode = function(xpath, resolver) {
return document.evaluate(xpath, this.ownerDocument || this, resolver || null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
};
}

Two things I noted while working on a 2.0 version. The first defined function I could not find any usage.

The second function, selectSingleNode is only used twice and does not appear to be doing what was expected.

For example it is called as node.selectSingleNode('ancestor::pre')) where node is a node inside of a specific post. However node is used as a backup in document.evaluate(xpath, this.ownerDocument || this, resolver || null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
this will resolve as document.evaluate(xpath, this.ownerDocument, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; where this.ownerDocument is likely the entire document and not the real area of interest.

You could reverse the logic as this || this.ownerDocument but I chose to drop the entire wrapper and just make the native call in the two places used.

@Frenzie
Copy link
Owner

Frenzie commented Jun 25, 2022

@Spuds So shall I archive this repo? It probably doesn't serve much purpose anymore.

@Spuds
Copy link
Author

Spuds commented Jun 25, 2022

May want to leave it around until 2.0 gets done ... its still a nice 1.1 addon

@Frenzie
Copy link
Owner

Frenzie commented Jun 25, 2022

By archive I didn't mean delete of course, but sure, I'll leave it open for now. ^_^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants