content-buffer.js: order
[conkeror.git] / modules / dom.js
blob51ef9eec20a81e232a260a72f014e3de73caf99f
1 /**
2  * (C) Copyright 2009-2010,2012 John J. Foerch
3  *
4  * Use, modification, and distribution are subject to the terms specified in the
5  * COPYING file.
6 **/
8 /**
9  * xpath_lookup_namespace is a namespace resolver that may be passed to
10  * document.evaluate.
11  */
12 function xpath_lookup_namespace (prefix) {
13     return {
14         xhtml: XHTML_NS,
15         m: MATHML_NS,
16         xul: XUL_NS,
17         svg: SVG_NS
18     }[prefix] || null;
21 /**
22  * xpath_find_node takes a document and a string xpath expression,
23  * performs a FIRST_ORDERED_NODE_TYPE lookup with the expression, and
24  * returns the single node in the result set, if any.
25  */
26 function xpath_find_node (doc, xpath) {
27     var r = doc.evaluate(xpath, doc, xpath_lookup_namespace,
28                          Ci.nsIDOMXPathResult.FIRST_ORDERED_NODE_TYPE,
29                          null);
30     return r.singleNodeValue;
33 /**
34  * xpath_find_any takes a document and a string xpath expression, performs
35  * an ANY_TYPE lookup with the expression, and returns an XPathResult
36  * object that gives the result set.
37  */
38 function xpath_find_any (doc, xpath) {
39     return doc.evaluate(xpath, doc, xpath_lookup_namespace,
40                         Ci.nsIDOMXPathResult.ANY_TYPE, null);
43 provide("dom");