hintClassFocus: "__hint_container",
eBg: bg,
eBgf: bgf,
- eFg: fg,
+ eFg: fg
};
var hCont;
/* due to the different XPath result type, we will need two counter variables */
var rect, elem, text, node, show_text;
- for (var i = 0; i < res.snapshotLength; i++) {
+ for (i = 0; i < res.snapshotLength; i++) {
if (hintCount >= config.maxHints) {
break;
}
for (var i = 0, nframes = frames.length; i < nframes; ++i) {
elem = frames[i];
rect = elem.getBoundingClientRect();
- if (!elem.contentWindow || !rect || rect.left > maxX || rect.right < minX || rect.top > maxY || rect.bottom < minY)
+ if (!elem.contentWindow || !rect || rect.left > maxX || rect.right < minX || rect.top > maxY || rect.bottom < minY) {
continue;
+ }
_helper(elem.contentWindow, offsetX + rect.left, offsetY + rect.top);
}
}
{
var index = _getHintIdByNumber(curFocusNum);
- if (typeof(hints[index + 1]) != "undefined") {
+ if (typeof(hints[index + 1]) !== "undefined") {
_focus(hints[index + 1].number);
} else {
_focus(hints[0].number);
this.focusPrev = function()
{
var index = _getHintIdByNumber(curFocusNum);
- if (index != 0 && typeof(hints[index - 1].number) != "undefined") {
+ if (index !== 0 && typeof(hints[index - 1].number) !== "undefined") {
_focus(hints[index - 1].number);
} else {
_focus(hints[hints.length - 1].number);
/* filters hints matching given number */
this.update = function(n)
{
- if (n == 0) {
+ if (n === 0) {
return this.create();
}
/* remove none matching hints */
var remove = [];
- for (var i = 0; i < hints.length; ++i) {
+ var i;
+ for (i = 0; i < hints.length; ++i) {
var hint = hints[i];
- if (0 != hint.number.toString().indexOf(n.toString())) {
+ if (0 !== hint.number.toString().indexOf(n.toString())) {
remove.push(hint.number);
}
}
- for (var i = 0; i < remove.length; ++i) {
+ for (i = 0; i < remove.length; ++i) {
_removeHint(remove[i]);
}
if (hints.length === 1) {
return this.fire(hints[0].number);
- } else {
- return _focus(n);
}
+ return _focus(n);
};
/* remove all hints and set previous style to them */
this.clear = function()
{
- if (hints.length == 0) {
+ if (hints.length === 0) {
return;
}
for (var i = 0; i < hints.length; ++i) {
var hint = hints[i];
- if (typeof(hint.elem) != "undefined") {
+ if (typeof(hint.elem) !== "undefined") {
hint.elem.style.background = hint.background;
hint.elem.style.color = hint.foreground;
hint.span.parentNode.removeChild(hint.span);
/* fires the modeevent on hint with given number */
this.fire = function(n)
{
- var doc, result;
- if (!n) {
- var n = curFocusNum;
- }
+ n = n ? n : curFocusNum;
+ var result;
var hint = _getHintByNumber(n);
if (typeof(hint.elem) == "undefined") {
return "DONE:";
}
- var el = hint.elem;
+ var el = hint.elem;
var tag = el.nodeName.toLowerCase();
this.clear();
- if (tag == "iframe" || tag == "frame" || tag == "textarea" || tag == "input" && (el.type == "text" || el.type == "password" || el.type == "checkbox" || el.type == "radio") || tag == "select") {
+ if (tag === "iframe" || tag === "frame" || tag === "textarea" || tag === "input" && (el.type === "text" || el.type === "password" || el.type === "checkbox" || el.type === "radio") || tag === "select") {
el.focus();
- if (tag == "input" || tag == "textarea") {
- return "INSERT:"
+ if (tag === "input" || tag === "textarea") {
+ return "INSERT:";
}
return "DONE:";
}
result = "DONE:";
switch (mode) {
- case "f": _open(el); break;
- case "F": _openNewWindow(el); break;
- case "i": _open(el); break;
- case "I": _openNewWindow(el); break;
- default: result = "DATA:" + _getElemtSource(el);
+ case "f":
+ _open(el);
+ break;
+ case "F":
+ _openNewWindow(el);
+ break;
+ case "i":
+ _open(el);
+ break;
+ case "I":
+ _openNewWindow(el);
+ break;
+ default:
+ result = "DATA:" + _getElemtSource(el);
+ break;
}
return result;
curFocusNum = n;
/* mark new hint as focused */
- var hint = _getHintByNumber(curFocusNum);
+ hint = _getHintByNumber(curFocusNum);
if (hint !== null) {
hint.elem.className = hint.elem.className.replace(config.hintClass, config.hintClassFocus);
hint.elem.style.background = config.eBgf;
/* retrieves text content fro given element */
function _getTextFromElement(el)
{
+ var text;
if (el instanceof HTMLInputElement || el instanceof HTMLTextAreaElement) {
text = el.value;
} else if (el instanceof HTMLSelectElement) {
} else {
text = el.textContent;
}
- return text.toLowerCase();;
+ return text.toLowerCase();
}
/* retrieves the hint for given hint number */
/* retrieves the id of hint with given number */
function _getHintIdByNumber(n)
{
+ var hint;
for (var i = 0; i < hints.length; ++i) {
- var hint = hints[i];
+ hint = hints[i];
if (hint.number === n) {
return i;
}
function _mouseEvent(elem, name)
{
- doc = elem.ownerDocument;
- view = elem.contentWindow;
+ var doc = elem.ownerDocument;
+ var view = elem.contentWindow;
var evObj = doc.createEvent("MouseEvents");
evObj.initMouseEvent(name, true, true, view, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
function _getXpathXpression(text)
{
var expr;
- if (typeof(text) == "undefined") {
+ if (typeof(text) === "undefined") {
text = "";
}
switch (mode) {
case "f":
case "F":
- if (text == "") {
+ if (text === "") {
expr = "//*[@onclick or @onmouseover or @onmousedown or @onmouseup or @oncommand or @class='lk' or @role='link' or @href] | //input[not(@type='hidden')] | //a[href] | //area | //textarea | //button | //select";
} else {
expr = "//*[(@onclick or @onmouseover or @onmousedown or @onmouseup or @oncommand or @class='lk' or @role='link' or @href) and contains(., '" + text + "')] | //input[not(@type='hidden') and contains(., '" + text + "')] | //a[@href and contains(., '" + text + "')] | //area[contains(., '" + text + "')] | //textarea[contains(., '" + text + "')] | //button[contains(@value, '" + text + "')] | //select[contains(., '" + text + "')]";
break;
case "i":
case "I":
- if (text == "") {
+ if (text === "") {
expr = "//img[@src]";
} else {
expr = "//img[@src and contains(., '" + text + "')]";
}
break;
default:
- if (text == "") {
+ if (text === "") {
expr = "//*[@role='link' or @href] | //a[href] | //area | //img[not(ancestor::a)]";
} else {
expr = "//*[(@role='link' or @href) and contains(., '" + text + "')] | //a[@href and contains(., '" + text + "')] | //area[contains(., '" + text + "')] | //img[not(ancestor::a) and contains(., '" + text + "')]";
}
return expr;
}
-}
+};
#include "command.h"
#include "hint.js.h"
-/* TODO use this in hinting script */
-#define MAX_HINTS 200
-#define HINT_CONTAINER_ID "__hint_container"
-#define HINT_CLASS "__hint"
+#define HINT_VAR "VpHint"
static void hints_run_script(char* js);
static void hints_fire(void);
{
hints_observe_input(FALSE);
if (GET_CLEAN_MODE() == VP_MODE_HINTING) {
- char* js = g_strdup("hints.clear();");
+ char* js = g_strdup_printf("%s.clear();", HINT_VAR);
char* value = NULL;
char* error = NULL;
vp.hints.num = 0;
js = g_strdup_printf(
- "hints = new VimpHints('%s', '%s', '%s', '%s');",
+ "var %s = new VimpHints('%s', '%s', '%s', '%s');",
+ HINT_VAR,
style->hint_bg,
style->hint_bg_focus,
style->hint_fg,
type = (HINTS_TARGET_BLANK & mode) ? 'F' : 'f';
}
- js = g_strdup_printf("hints.create('%s', '%c');", input ? input : "", type);
+ js = g_strdup_printf("%s.create('%s', '%c');", HINT_VAR, input ? input : "", type);
hints_run_script(js);
g_free(js);
}
void hints_update(const gulong num)
{
- char* js = g_strdup_printf("hints.update(%lu);", num);
+ char* js = g_strdup_printf("%s.update(%lu);", HINT_VAR, num);
hints_run_script(js);
g_free(js);
}
void hints_focus_next(const gboolean back)
{
- char* js = g_strdup(back ? "hints.focusPrev()" : "hints.focusNext();");
+ char* js = g_strdup_printf(back ? "%s.focusPrev()" : "%s.focusNext();", HINT_VAR);
hints_run_script(js);
g_free(js);
}
static void hints_fire(void)
{
hints_observe_input(FALSE);
- char* js = g_strdup("hints.fire();");
+ char* js = g_strdup_printf("%s.fire();", HINT_VAR);
hints_run_script(js);
g_free(js);
}