mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-23 01:37:58 +01:00
Take a crack at killing security warnings. Fail miserably. Keep the new code because it's a bit nicer.
--HG-- branch : xslt
This commit is contained in:
@@ -365,6 +365,48 @@ const util = { //{{{
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Evaluates an XPath expression in the current or provided
|
||||
* document. It provides the xhtml, xhtml2 and liberator XML
|
||||
* namespaces. The result may be used as an iterator.
|
||||
*
|
||||
* @param {string} expression The XPath expression to evaluate.
|
||||
* @param {Document} doc The document to evaluate the expression in.
|
||||
* @default The current document.
|
||||
* @param {Node} elem The context element.
|
||||
* @default <b>doc</b>
|
||||
* @param {boolean} asIterator Whether to return the results as an
|
||||
* XPath iterator.
|
||||
*/
|
||||
evaluateXPath: function (expression, doc, elem, asIterator)
|
||||
{
|
||||
if (!doc)
|
||||
doc = window.content.document;
|
||||
if (!elem)
|
||||
elem = doc;
|
||||
if (util.isArray(expression))
|
||||
expression = util.makeXPath(expression);
|
||||
|
||||
let result = doc.evaluate(expression, elem,
|
||||
function lookupNamespaceURI(prefix)
|
||||
{
|
||||
return {
|
||||
xhtml: "http://www.w3.org/1999/xhtml",
|
||||
xhtml2: "http://www.w3.org/2002/06/xhtml2",
|
||||
liberator: NS.uri
|
||||
}[prefix] || null;
|
||||
},
|
||||
asIterator ? XPathResult.ORDERED_NODE_ITERATOR_TYPE : XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
|
||||
null
|
||||
);
|
||||
|
||||
result.__iterator__ = asIterator
|
||||
? function () { let elem; while ((elem = this.iterateNext())) yield elem; }
|
||||
: function () { for (let i = 0; i < this.snapshotLength; i++) yield this.snapshotItem(i); };
|
||||
|
||||
return result;
|
||||
},
|
||||
|
||||
/**
|
||||
* The identity function.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user