mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-22 07:57:58 +01:00
Change lots of local vars in hints.js to camel case.
HACKING is that way -> --HG-- extra : rebase_source : f531065897da913844d46f084a3b2ee890f215d1
This commit is contained in:
@@ -12,7 +12,7 @@ function Hints() //{{{
|
|||||||
////////////////////// PRIVATE SECTION /////////////////////////////////////////
|
////////////////////// PRIVATE SECTION /////////////////////////////////////////
|
||||||
/////////////////////////////////////////////////////////////////////////////{{{
|
/////////////////////////////////////////////////////////////////////////////{{{
|
||||||
|
|
||||||
const ELEM = 0, TEXT = 1, SPAN = 2, IMGSPAN = 3;
|
const ELEM = 0, TEXT = 1, SPAN = 2, IMG_SPAN = 3;
|
||||||
|
|
||||||
var myModes = config.browserModes;
|
var myModes = config.browserModes;
|
||||||
|
|
||||||
@@ -24,7 +24,7 @@ function Hints() //{{{
|
|||||||
var prevInput = ""; // record previous user input type, "text" || "number"
|
var prevInput = ""; // record previous user input type, "text" || "number"
|
||||||
var extendedhintCount; // for the count argument of Mode#action (extended hint only)
|
var extendedhintCount; // for the count argument of Mode#action (extended hint only)
|
||||||
|
|
||||||
// hints[] = [elem, text, span, imgspan, elem.style.backgroundColor, elem.style.color]
|
// hints[] = [elem, text, span, imgSpan, elem.style.backgroundColor, elem.style.color]
|
||||||
var pageHints = [];
|
var pageHints = [];
|
||||||
var validHints = []; // store the indices of the "hints" array with valid elements
|
var validHints = []; // store the indices of the "hints" array with valid elements
|
||||||
|
|
||||||
@@ -115,12 +115,12 @@ function Hints() //{{{
|
|||||||
* neighbouring element might look like a label. Only called by generate().
|
* neighbouring element might look like a label. Only called by generate().
|
||||||
*
|
*
|
||||||
* If it finds a hint it returns it, if the hint is not the caption of the
|
* If it finds a hint it returns it, if the hint is not the caption of the
|
||||||
* element it will return showtext=true.
|
* element it will return showText=true.
|
||||||
*
|
*
|
||||||
* @param {Object} elem The element used to generate hint text.
|
* @param {Object} elem The element used to generate hint text.
|
||||||
* @param {Document} doc The containing document.
|
* @param {Document} doc The containing document.
|
||||||
*
|
*
|
||||||
* @returns [text, showtext]
|
* @returns [text, showText]
|
||||||
*/
|
*/
|
||||||
function getInputHint(elem, doc)
|
function getInputHint(elem, doc)
|
||||||
{
|
{
|
||||||
@@ -128,7 +128,7 @@ function Hints() //{{{
|
|||||||
// <input type="radio|checkbox"> Use the value if it is not numeric or label or name
|
// <input type="radio|checkbox"> Use the value if it is not numeric or label or name
|
||||||
// <input type="password"> Never use the value, use label or name
|
// <input type="password"> Never use the value, use label or name
|
||||||
// <input type="text|file"> <textarea> Use value if set or label or name
|
// <input type="text|file"> <textarea> Use value if set or label or name
|
||||||
// <input type="image"> Use the alt text if present (showtext) or label or name
|
// <input type="image"> Use the alt text if present (showText) or label or name
|
||||||
// <input type="hidden"> Never gets here
|
// <input type="hidden"> Never gets here
|
||||||
// <select> Use the text of the selected item or label or name
|
// <select> Use the text of the selected item or label or name
|
||||||
|
|
||||||
@@ -183,69 +183,69 @@ function Hints() //{{{
|
|||||||
* Only called by generate().
|
* Only called by generate().
|
||||||
*
|
*
|
||||||
* @param {Object} elem The <area> element.
|
* @param {Object} elem The <area> element.
|
||||||
* @param {number} leftpos The left offset of the image.
|
* @param {number} leftPos The left offset of the image.
|
||||||
* @param {number} toppos The top offset of the image.
|
* @param {number} topPos The top offset of the image.
|
||||||
* @returns [leftpos, toppos] The updated offsets.
|
* @returns [leftPos, topPos] The updated offsets.
|
||||||
*/
|
*/
|
||||||
function getAreaOffset(elem, leftpos, toppos)
|
function getAreaOffset(elem, leftPos, topPos)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Need to add the offset to the area element.
|
// Need to add the offset to the area element.
|
||||||
// Always try to find the top-left point, as per liberator default.
|
// Always try to find the top-left point, as per liberator default.
|
||||||
let shape = elem.getAttribute("shape").toLowerCase();
|
let shape = elem.getAttribute("shape").toLowerCase();
|
||||||
let coordstr = elem.getAttribute("coords");
|
let coordStr = elem.getAttribute("coords");
|
||||||
// Technically it should be only commas, but hey
|
// Technically it should be only commas, but hey
|
||||||
coordstr = coordstr.replace(/\s+[;,]\s+/g, ",").replace(/\s+/g, ",");
|
coordStr = coordStr.replace(/\s+[;,]\s+/g, ",").replace(/\s+/g, ",");
|
||||||
let coords = coordstr.split(",").map(Number);
|
let coords = coordStr.split(",").map(Number);
|
||||||
|
|
||||||
if ((shape == "rect" || shape == "rectangle") && coords.length == 4)
|
if ((shape == "rect" || shape == "rectangle") && coords.length == 4)
|
||||||
{
|
{
|
||||||
leftpos += coords[0];
|
leftPos += coords[0];
|
||||||
toppos += coords[1];
|
topPos += coords[1];
|
||||||
}
|
}
|
||||||
else if (shape == "circle" && coords.length == 3)
|
else if (shape == "circle" && coords.length == 3)
|
||||||
{
|
{
|
||||||
leftpos += coords[0] - coords[2] / Math.sqrt(2);
|
leftPos += coords[0] - coords[2] / Math.sqrt(2);
|
||||||
toppos += coords[1] - coords[2] / Math.sqrt(2);
|
topPos += coords[1] - coords[2] / Math.sqrt(2);
|
||||||
}
|
}
|
||||||
else if ((shape == "poly" || shape == "polygon") && coords.length % 2 == 0)
|
else if ((shape == "poly" || shape == "polygon") && coords.length % 2 == 0)
|
||||||
{
|
{
|
||||||
let leftbound = Infinity;
|
let leftBound = Infinity;
|
||||||
let topbound = Infinity;
|
let topBound = Infinity;
|
||||||
|
|
||||||
// First find the top-left corner of the bounding rectangle (offset from image topleft can be noticably suboptimal)
|
// First find the top-left corner of the bounding rectangle (offset from image topleft can be noticably suboptimal)
|
||||||
for (let i = 0; i < coords.length; i += 2)
|
for (let i = 0; i < coords.length; i += 2)
|
||||||
{
|
{
|
||||||
leftbound = Math.min(coords[i], leftbound);
|
leftBound = Math.min(coords[i], leftBound);
|
||||||
topbound = Math.min(coords[i + 1], topbound);
|
topBound = Math.min(coords[i + 1], topBound);
|
||||||
}
|
}
|
||||||
|
|
||||||
let curtop = null;
|
let curTop = null;
|
||||||
let curleft = null;
|
let curLeft = null;
|
||||||
let curdist = Infinity;
|
let curDist = Infinity;
|
||||||
|
|
||||||
// Then find the closest vertex. (we could generalise to nearest point on an edge, but I doubt there is a need)
|
// Then find the closest vertex. (we could generalise to nearest point on an edge, but I doubt there is a need)
|
||||||
for (let i = 0; i < coords.length; i += 2)
|
for (let i = 0; i < coords.length; i += 2)
|
||||||
{
|
{
|
||||||
let leftoffset = coords[i] - leftbound;
|
let leftOffset = coords[i] - leftBound;
|
||||||
let topoffset = coords[i + 1] - topbound;
|
let topOffset = coords[i + 1] - topBound;
|
||||||
let dist = Math.sqrt(leftoffset * leftoffset + topoffset * topoffset);
|
let dist = Math.sqrt(leftOffset * leftOffset + topOffset * topOffset);
|
||||||
if (dist < curdist)
|
if (dist < curDist)
|
||||||
{
|
{
|
||||||
curdist = dist;
|
curDist = dist;
|
||||||
curleft = coords[i];
|
curLeft = coords[i];
|
||||||
curtop = coords[i + 1];
|
curTop = coords[i + 1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we found a satisfactory offset, let's use it.
|
// If we found a satisfactory offset, let's use it.
|
||||||
if (curdist < Infinity)
|
if (curDist < Infinity)
|
||||||
return [leftpos + curleft, toppos + curtop];
|
return [leftPos + curLeft, topPos + curTop];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (e) {} // badly formed document, or shape == "default" in which case we don't move the hint
|
catch (e) {} // badly formed document, or shape == "default" in which case we don't move the hint
|
||||||
return [leftpos, toppos];
|
return [leftPos, topPos];
|
||||||
}
|
}
|
||||||
|
|
||||||
// the containing block offsets with respect to the viewport
|
// the containing block offsets with respect to the viewport
|
||||||
@@ -283,14 +283,14 @@ function Hints() //{{{
|
|||||||
|
|
||||||
let baseNodeAbsolute = util.xmlToDom(<span highlight="Hint"/>, doc);
|
let baseNodeAbsolute = util.xmlToDom(<span highlight="Hint"/>, doc);
|
||||||
|
|
||||||
let elem, text, span, rect, showtext;
|
let elem, text, span, rect, showText;
|
||||||
let res = buffer.evaluateXPath(hintMode.tags(), doc, null, true);
|
let res = buffer.evaluateXPath(hintMode.tags(), doc, null, true);
|
||||||
|
|
||||||
let fragment = util.xmlToDom(<div highlight="hints"/>, doc);
|
let fragment = util.xmlToDom(<div highlight="hints"/>, doc);
|
||||||
let start = pageHints.length;
|
let start = pageHints.length;
|
||||||
for (let elem in res)
|
for (let elem in res)
|
||||||
{
|
{
|
||||||
showtext = false;
|
showText = false;
|
||||||
|
|
||||||
// TODO: for iframes, this calculation is wrong
|
// TODO: for iframes, this calculation is wrong
|
||||||
rect = elem.getBoundingClientRect();
|
rect = elem.getBoundingClientRect();
|
||||||
@@ -306,23 +306,23 @@ function Hints() //{{{
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (elem instanceof HTMLInputElement || elem instanceof HTMLSelectElement || elem instanceof HTMLTextAreaElement)
|
if (elem instanceof HTMLInputElement || elem instanceof HTMLSelectElement || elem instanceof HTMLTextAreaElement)
|
||||||
[text, showtext] = getInputHint(elem, doc);
|
[text, showText] = getInputHint(elem, doc);
|
||||||
else
|
else
|
||||||
text = elem.textContent.toLowerCase();
|
text = elem.textContent.toLowerCase();
|
||||||
|
|
||||||
span = baseNodeAbsolute.cloneNode(true);
|
span = baseNodeAbsolute.cloneNode(true);
|
||||||
|
|
||||||
let leftpos = Math.max((rect.left + offsetX), offsetX);
|
let leftPos = Math.max((rect.left + offsetX), offsetX);
|
||||||
let toppos = Math.max((rect.top + offsetY), offsetY);
|
let topPos = Math.max((rect.top + offsetY), offsetY);
|
||||||
|
|
||||||
if (elem instanceof HTMLAreaElement)
|
if (elem instanceof HTMLAreaElement)
|
||||||
[leftpos, toppos] = getAreaOffset(elem, leftpos, toppos);
|
[leftPos, topPos] = getAreaOffset(elem, leftPos, topPos);
|
||||||
|
|
||||||
span.style.left = leftpos + "px";
|
span.style.left = leftPos + "px";
|
||||||
span.style.top = toppos + "px";
|
span.style.top = topPos + "px";
|
||||||
fragment.appendChild(span);
|
fragment.appendChild(span);
|
||||||
|
|
||||||
pageHints.push([elem, text, span, null, elem.style.backgroundColor, elem.style.color, showtext]);
|
pageHints.push([elem, text, span, null, elem.style.backgroundColor, elem.style.color, showText]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (doc.body)
|
if (doc.body)
|
||||||
@@ -377,7 +377,7 @@ function Hints() //{{{
|
|||||||
function showHints()
|
function showHints()
|
||||||
{
|
{
|
||||||
|
|
||||||
let elem, text, rect, span, imgspan, _a, _b, showtext;
|
let elem, text, rect, span, imgSpan, _a, _b, showText;
|
||||||
let hintnum = 1;
|
let hintnum = 1;
|
||||||
let validHint = hintMatcher(hintString.toLowerCase());
|
let validHint = hintMatcher(hintString.toLowerCase());
|
||||||
let activeHint = hintNumber || 1;
|
let activeHint = hintNumber || 1;
|
||||||
@@ -391,12 +391,12 @@ function Hints() //{{{
|
|||||||
for (let i in (util.interruptibleRange(start, end + 1, 500)))
|
for (let i in (util.interruptibleRange(start, end + 1, 500)))
|
||||||
{
|
{
|
||||||
let hint = pageHints[i];
|
let hint = pageHints[i];
|
||||||
[elem, text, span, imgspan, _a, _b, showtext] = hint;
|
[elem, text, span, imgSpan, _a, _b, showText] = hint;
|
||||||
|
|
||||||
let valid = validHint(text);
|
let valid = validHint(text);
|
||||||
span.style.display = (valid ? "" : "none");
|
span.style.display = (valid ? "" : "none");
|
||||||
if (imgspan)
|
if (imgSpan)
|
||||||
imgspan.style.display = (valid ? "" : "none");
|
imgSpan.style.display = (valid ? "" : "none");
|
||||||
|
|
||||||
if (!valid)
|
if (!valid)
|
||||||
{
|
{
|
||||||
@@ -406,27 +406,27 @@ function Hints() //{{{
|
|||||||
|
|
||||||
if (text == "" && elem.firstChild && elem.firstChild instanceof HTMLImageElement)
|
if (text == "" && elem.firstChild && elem.firstChild instanceof HTMLImageElement)
|
||||||
{
|
{
|
||||||
if (!imgspan)
|
if (!imgSpan)
|
||||||
{
|
{
|
||||||
rect = elem.firstChild.getBoundingClientRect();
|
rect = elem.firstChild.getBoundingClientRect();
|
||||||
if (!rect)
|
if (!rect)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
imgspan = util.xmlToDom(<span highlight="Hint"/>, doc);
|
imgSpan = util.xmlToDom(<span highlight="Hint"/>, doc);
|
||||||
imgspan.setAttributeNS(NS.uri, "class", "HintImage");
|
imgSpan.setAttributeNS(NS.uri, "class", "HintImage");
|
||||||
imgspan.style.left = (rect.left + offsetX) + "px";
|
imgSpan.style.left = (rect.left + offsetX) + "px";
|
||||||
imgspan.style.top = (rect.top + offsetY) + "px";
|
imgSpan.style.top = (rect.top + offsetY) + "px";
|
||||||
imgspan.style.width = (rect.right - rect.left) + "px";
|
imgSpan.style.width = (rect.right - rect.left) + "px";
|
||||||
imgspan.style.height = (rect.bottom - rect.top) + "px";
|
imgSpan.style.height = (rect.bottom - rect.top) + "px";
|
||||||
hint[IMGSPAN] = imgspan;
|
hint[IMG_SPAN] = imgSpan;
|
||||||
span.parentNode.appendChild(imgspan);
|
span.parentNode.appendChild(imgSpan);
|
||||||
}
|
}
|
||||||
setClass(imgspan, activeHint == hintnum);
|
setClass(imgSpan, activeHint == hintnum);
|
||||||
}
|
}
|
||||||
|
|
||||||
span.setAttribute("number", showtext ? hintnum + ": " + text.substr(0, 50) : hintnum);
|
span.setAttribute("number", showText ? hintnum + ": " + text.substr(0, 50) : hintnum);
|
||||||
if (imgspan)
|
if (imgSpan)
|
||||||
imgspan.setAttribute("number", hintnum);
|
imgSpan.setAttribute("number", hintnum);
|
||||||
else
|
else
|
||||||
setClass(elem, activeHint == hintnum);
|
setClass(elem, activeHint == hintnum);
|
||||||
validHints.push(elem);
|
validHints.push(elem);
|
||||||
|
|||||||
Reference in New Issue
Block a user