mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-20 08:27:59 +01:00
Add util.makeXPath for constructing XPath expressions.
--HG-- extra : transplant_source : G%A7_%1B%9B%7BN%9C%FF%14%A9g%BA%04%99%B3%8B%23%ED%F2
This commit is contained in:
@@ -336,24 +336,16 @@ function Buffer() //{{{
|
|||||||
buffer.focusElement(buffer.lastInputField);
|
buffer.focusElement(buffer.lastInputField);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
let elements = [];
|
let xpath = util.makeXPath(["input[not(@type) or @type='text' or @type='password' or @type='file']",
|
||||||
let matches = buffer.evaluateXPath(
|
"textarea[not(@disabled) and not(@readonly)]"]);
|
||||||
"//input[not(@type) or @type='text' or @type='password' or @type='file'] | //textarea[not(@disabled) and not(@readonly)] |" +
|
|
||||||
"//xhtml:input[not(@type) or @type='text' or @type='password' or @type='file'] | //xhtml:textarea[not(@disabled) and not(@readonly)]"
|
|
||||||
);
|
|
||||||
|
|
||||||
for (let match in matches)
|
let elements = [m for (m in buffer.evaluateXPath(xpath))].filter(function (match) {
|
||||||
{
|
|
||||||
let computedStyle = util.computedStyle(match);
|
let computedStyle = util.computedStyle(match);
|
||||||
if (computedStyle.visibility != "hidden" && computedStyle.display != "none")
|
return computedStyle.visibility != "hidden" && computedStyle.display != "none";
|
||||||
elements.push(match);
|
});
|
||||||
}
|
|
||||||
|
|
||||||
if (elements.length > 0)
|
if (elements.length > 0)
|
||||||
{
|
buffer.focusElement(elements[util.Math.constrain(count, 1, elements.length) - 1]);
|
||||||
count = util.Math.constrain(count, 1, elements.length);
|
|
||||||
buffer.focusElement(elements[count - 1]);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
liberator.beep();
|
liberator.beep();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,14 +63,14 @@ function Hints() //{{{
|
|||||||
const Mode = new Struct("prompt", "action", "tags");
|
const Mode = new Struct("prompt", "action", "tags");
|
||||||
Mode.defaultValue("tags", function () function () options.hinttags);
|
Mode.defaultValue("tags", function () function () options.hinttags);
|
||||||
function extended() options.extendedhinttags;
|
function extended() options.extendedhinttags;
|
||||||
function images() "//img | //xhtml:img";
|
function images() util.makeXPath(["img"]);
|
||||||
|
|
||||||
const hintModes = {
|
const hintModes = {
|
||||||
";": Mode("Focus hint", function (elem) buffer.focusElement(elem), extended),
|
";": Mode("Focus hint", function (elem) buffer.focusElement(elem), extended),
|
||||||
"?": Mode("Show information for hint", function (elem) buffer.showElementInfo(elem), extended),
|
"?": Mode("Show information for hint", function (elem) buffer.showElementInfo(elem), extended),
|
||||||
s: Mode("Save hint", function (elem) buffer.saveLink(elem, true)),
|
s: Mode("Save hint", function (elem) buffer.saveLink(elem, true)),
|
||||||
a: Mode("Save hint with prompt", function (elem) buffer.saveLink(elem, false)),
|
a: Mode("Save hint with prompt", function (elem) buffer.saveLink(elem, false)),
|
||||||
f: Mode("Focus frame", function (elem) elem.ownerDocument.defaultView.focus(), function () "//body | //xhtml:body"),
|
f: Mode("Focus frame", function (elem) elem.ownerDocument.defaultView.focus(), function () util.makeXPath(["body"])),
|
||||||
o: Mode("Follow hint", function (elem) buffer.followLink(elem, liberator.CURRENT_TAB)),
|
o: Mode("Follow hint", function (elem) buffer.followLink(elem, liberator.CURRENT_TAB)),
|
||||||
t: Mode("Follow hint in a new tab", function (elem) buffer.followLink(elem, liberator.NEW_TAB)),
|
t: Mode("Follow hint in a new tab", function (elem) buffer.followLink(elem, liberator.NEW_TAB)),
|
||||||
b: Mode("Follow hint in a background tab", function (elem) buffer.followLink(elem, liberator.NEW_BACKGROUND_TAB)),
|
b: Mode("Follow hint in a background tab", function (elem) buffer.followLink(elem, liberator.NEW_BACKGROUND_TAB)),
|
||||||
@@ -786,10 +786,8 @@ function Hints() //{{{
|
|||||||
/////////////////////////////////////////////////////////////////////////////{{{
|
/////////////////////////////////////////////////////////////////////////////{{{
|
||||||
|
|
||||||
const DEFAULT_HINTTAGS =
|
const DEFAULT_HINTTAGS =
|
||||||
util.Array(["input[not(@type='hidden')]", "a", "area", "iframe", "textarea", "button", "select"])
|
util.makeXPath(["input[not(@type='hidden')]", "a", "area", "iframe", "textarea", "button", "select"])
|
||||||
.map(function (spec) [spec, "xhtml:" + spec]).flatten()
|
+ " | //*[@onclick or @onmouseover or @onmousedown or @onmouseup or @oncommand or @role='link']";
|
||||||
.concat("*[@onclick or @onmouseover or @onmousedown or @onmouseup or @oncommand or @role='link']")
|
|
||||||
.map(function (node) "//" + node).join(" | ");
|
|
||||||
|
|
||||||
function checkXPath(val)
|
function checkXPath(val)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -178,6 +178,20 @@ const util = { //{{{
|
|||||||
return dest;
|
return dest;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an XPath union expression constructed from the specified node
|
||||||
|
* tests. An expression is built with node tests for both the null and
|
||||||
|
* XHTML namespaces. See {@link Buffer#evaluateXPath}.
|
||||||
|
*
|
||||||
|
* @param nodes {Array(string)}
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
makeXPath: function makeXPath(nodes)
|
||||||
|
{
|
||||||
|
return util.Array(nodes).map(function (node) [node, "xhtml:" + node]).flatten()
|
||||||
|
.map(function (node) "//" + node).join(" | ");
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Memoize the lookup of a property in an object.
|
* Memoize the lookup of a property in an object.
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user