aboutsummaryrefslogtreecommitdiffstats
path: root/lib/utils.js
diff options
context:
space:
mode:
authorJez Ng2012-01-09 00:02:25 +0800
committerJez Ng2012-01-09 00:18:12 +0800
commit6ae84b98b094384e9a5e4eeaa2f041ea1140633f (patch)
tree5358daee36109256f7cf6124c139b4b58cfe1d25 /lib/utils.js
parente2f3b54ba488d5fac6f4f3d2d75b46dada19660a (diff)
downloadvimium-6ae84b98b094384e9a5e4eeaa2f041ea1140633f.tar.bz2
Make focusInput detect textareas as well, and refactor the XPath code.
Together with e2f3b54, this closes issue #276.
Diffstat (limited to 'lib/utils.js')
-rw-r--r--lib/utils.js19
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/utils.js b/lib/utils.js
index 0c992ad4..ef961833 100644
--- a/lib/utils.js
+++ b/lib/utils.js
@@ -11,4 +11,23 @@ var utils = {
var func = obj[components.pop()];
return func.apply(obj, argArray);
},
+
+ /*
+ * Takes an array of XPath selectors, adds the necessary namespaces (currently only XHTML), and applies them
+ * to the document root. The namespaceResolver in evaluateXPath should be kept in sync with the namespaces
+ * here.
+ */
+ makeXPath: function(elementArray) {
+ var xpath = [];
+ for (var i in elementArray)
+ xpath.push("//" + elementArray[i], "//xhtml:" + elementArray[i]);
+ return xpath.join(" | ");
+ },
+
+ evaluateXPath: function(xpath, resultType) {
+ function namespaceResolver(namespace) {
+ return namespace == "xhtml" ? "http://www.w3.org/1999/xhtml" : null;
+ }
+ return document.evaluate(xpath, document.documentElement, namespaceResolver, resultType, null);
+ },
};