/***** BEGIN LICENSE BLOCK ***** {{{ Version: MPL 1.1/GPL 2.0/LGPL 2.1 The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.mozilla.org/MPL/ Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. Copyright (c) 2006-2009 by Martin Stubenschrott Alternatively, the contents of this file may be used under the terms of either the GNU General Public License Version 2 or later (the "GPL"), or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), in which case the provisions of the GPL or the LGPL are applicable instead of those above. If you wish to allow use of your version of this file only under the terms of either the GPL or the LGPL, and not to allow others to use your version of this file under the terms of the MPL, indicate your decision by deleting the provisions above and replace them with the notice and other provisions required by the GPL or the LGPL. If you do not delete the provisions above, a recipient may use your version of this file under the terms of any one of the MPL, the GPL or the LGPL. }}} ***** END LICENSE BLOCK *****/ /** @scope modules */ /** * @instance hints */ function Hints() //{{{ { //////////////////////////////////////////////////////////////////////////////// ////////////////////// PRIVATE SECTION ///////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////{{{ const ELEM = 0, TEXT = 1, SPAN = 2, IMGSPAN = 3; var myModes = config.browserModes; var hintMode; var submode = ""; // used for extended mode, can be "o", "t", "y", etc. var hintString = ""; // the typed string part of the hint is in this string var hintNumber = 0; // only the numerical part of the hint var usedTabKey = false; // when we used to select an element var prevInput = ""; // record previous user input type, "text" || "number" var extendedhintCount; // for the count argument of Mode#action (extended hint only) // hints[] = [elem, text, span, imgspan, elem.style.backgroundColor, elem.style.color] var pageHints = []; var validHints = []; // store the indices of the "hints" array with valid elements var activeTimeout = null; // needed for hinttimeout > 0 var canUpdate = false; // keep track of the documents which we generated the hints for // docs = { doc: document, start: start_index in hints[], end: end_index in hints[] } var docs = []; const Mode = new Struct("prompt", "action", "tags"); Mode.defaultValue("tags", function () function () options.hinttags); function extended() options.extendedhinttags; function images() "//img | //xhtml:img"; const hintModes = { ";": Mode("Focus hint", function (elem) buffer.focusElement(elem), extended), "?": Mode("Show information for hint", function (elem) buffer.showElementInfo(elem), extended), s: Mode("Save hint", function (elem) buffer.saveLink(elem, true)), 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"), 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)), b: Mode("Follow hint in a background tab", function (elem) buffer.followLink(elem, liberator.NEW_BACKGROUND_TAB)), w: Mode("Follow hint in a new window", function (elem) buffer.followLink(elem, liberator.NEW_WINDOW), extended), F: Mode("Open multiple hints in tabs", followAndReshow), O: Mode("Generate an ':open URL' using hint", function (elem, loc) commandline.open(":", "open " + loc, modes.EX)), T: Mode("Generate a ':tabopen URL' using hint", function (elem, loc) commandline.open(":", "tabopen " + loc, modes.EX)), W: Mode("Generate a ':winopen URL' using hint", function (elem, loc) commandline.open(":", "winopen " + loc, modes.EX)), v: Mode("View hint source", function (elem, loc) buffer.viewSource(loc, false), extended), V: Mode("View hint source in external editor", function (elem, loc) buffer.viewSource(loc, true), extended), y: Mode("Yank hint location", function (elem, loc) util.copyToClipboard(loc, true)), Y: Mode("Yank hint description", function (elem) util.copyToClipboard(elem.textContent || "", true), extended), c: Mode("Open context menu", function (elem) buffer.openContextMenu(elem), extended), i: Mode("Show image", function (elem) liberator.open(elem.src), images), I: Mode("Show image in a new tab", function (elem) liberator.open(elem.src, liberator.NEW_TAB), images) }; /** * Follows the specified hint and then reshows all hints. Used to open * multiple hints in succession. * * @param {Node} elem The selected hint. */ function followAndReshow(elem) { buffer.followLink(elem, liberator.NEW_BACKGROUND_TAB); // TODO: Maybe we find a *simple* way to keep the hints displayed rather than // showing them again, or is this short flash actually needed as a "usability // feature"? --mst hints.show("F"); } /** * Reset hints, so that they can be cleanly used again. */ function reset() { statusline.updateInputBuffer(""); hintString = ""; hintNumber = 0; usedTabKey = false; prevInput = ""; pageHints = []; validHints = []; canUpdate = false; docs = []; hints.escNumbers = false; if (activeTimeout) clearTimeout(activeTimeout); activeTimeout = null; } /** * Display the current status to the user. */ function updateStatusline() { statusline.updateInputBuffer((hints.escNumbers ? mappings.getMapLeader() : "") + (hintNumber || "")); } /** * Get a hint for "input", "textarea" and "select". * * Tries to use