// Copyright (c) 2006-2008 by Martin Stubenschrott <stubenschrott@vimperator.org>
// Copyright (c) 2007-2011 by Doug Kearns <dougkearns@gmail.com>
-// Copyright (c) 2008-2013 Kris Maglione <maglione.k@gmail.com>
+// Copyright (c) 2008-2014 Kris Maglione <maglione.k@gmail.com>
//
// This work is licensed for reuse under an MIT license. Details are
// given in the LICENSE.txt file included with this file.
var HintSession = Class("HintSession", CommandMode, {
get extendedMode() modes.HINTS,
- init: function init(mode, opts = {}) {
+ init: function init(mode, opts={}) {
init.supercall(this);
if (!opts.window)
this.activeTimeout = null; // needed for hinttimeout > 0
this.continue = Boolean(opts.continue);
this.docs = [];
- this.hintKeys = DOM.Event.parse(options["hintkeys"]).map(DOM.Event.closure.stringify);
+ this.hintKeys = DOM.Event.parse(options["hintkeys"]).map(DOM.Event.bound.stringify);
this.hintNumber = 0;
this.hintString = opts.filter || "";
this.pageHints = [];
this.open();
this.top = opts.window || content;
- this.top.addEventListener("resize", this.closure._onResize, true);
- this.top.addEventListener("dactyl-commandupdate", this.closure._onResize, false, true);
+ this.top.addEventListener("resize", this.bound._onResize, true);
+ this.top.addEventListener("dactyl-commandupdate", this.bound._onResize, false, true);
this.generate();
if (hints.hintSession == this)
hints.hintSession = null;
if (this.top) {
- this.top.removeEventListener("resize", this.closure._onResize, true);
- this.top.removeEventListener("dactyl-commandupdate", this.closure._onResize, true);
+ this.top.removeEventListener("resize", this.bound._onResize, true);
+ this.top.removeEventListener("dactyl-commandupdate", this.bound._onResize, true);
}
this.removeHints(0);
return false;
let computedStyle = doc.defaultView.getComputedStyle(elem, null);
+ if (!computedStyle)
+ return false;
if (computedStyle.visibility != "visible" || computedStyle.display == "none")
return false;
return true;
__proto__: this.Hint
});
- for (let hint in values(_hints)) {
+ for (let hint of _hints) {
let { elem, rect } = hint;
if (elem.hasAttributeNS(NS, "hint"))
updateValidNumbers: function updateValidNumbers(always) {
let string = this.getHintString(this.hintNumber);
for (let hint in values(this.validHints))
- hint.valid = always || hint.span.getAttribute("number").indexOf(string) == 0;
+ hint.valid = always || hint.span.getAttribute("number").startsWith(string);
},
tab: function tab(previous) {
let appContent = document.getElementById("appcontent");
if (appContent)
- events.listen(appContent, "scroll", this.resizeTimer.closure.tell, false);
+ events.listen(appContent, "scroll", this.resizeTimer.bound.tell, false);
const Mode = Hints.Mode;
Mode.prototype.__defineGetter__("matcher", function ()
options.get("extendedhinttags").getKey(this.name, options.get("hinttags").matcher));
+ function cleanLoc(loc) {
+ try {
+ let uri = util.newURI(loc);
+ if (uri.scheme == "mailto" && !~uri.path.indexOf("?"))
+ return uri.path;
+ }
+ catch (e) {}
+ return loc;
+ }
+
this.modes = {};
- this.addMode(";", "Focus hint", buffer.closure.focusElement);
+ this.addMode(";", "Focus hint", buffer.bound.focusElement);
this.addMode("?", "Show information for hint", elem => buffer.showElementInfo(elem));
// TODO: allow for ! override to overwrite existing paths -- where? --djk
this.addMode("s", "Save hint", elem => buffer.saveLink(elem, false));
this.addMode("f", "Focus frame", elem => dactyl.focus(elem.ownerDocument.defaultView));
- this.addMode("F", "Focus frame or pseudo-frame", buffer.closure.focusElement, isScrollable);
+ this.addMode("F", "Focus frame or pseudo-frame", buffer.bound.focusElement, isScrollable);
this.addMode("o", "Follow hint", elem => buffer.followLink(elem, dactyl.CURRENT_TAB));
this.addMode("t", "Follow hint in a new tab", elem => buffer.followLink(elem, dactyl.NEW_TAB));
this.addMode("b", "Follow hint in a background tab", elem => buffer.followLink(elem, dactyl.NEW_BACKGROUND_TAB));
this.addMode("S", "Add a search keyword", elem => bookmarks.addSearchKeyword(elem));
this.addMode("v", "View hint source", (elem, loc) => buffer.viewSource(loc, false));
this.addMode("V", "View hint source in external editor", (elem, loc) => buffer.viewSource(loc, true));
- this.addMode("y", "Yank hint location", (elem, loc) => editor.setRegister(null, loc, true));
+ this.addMode("y", "Yank hint location", (elem, loc) => editor.setRegister(null, cleanLoc(loc), true));
this.addMode("Y", "Yank hint description", elem => editor.setRegister(null, elem.textContent || "", true));
this.addMode("A", "Yank hint anchor url", function (elem) {
let uri = elem.ownerDocument.documentURIObject.clone();
let indexOf = String.indexOf;
if (options.get("hintmatching").has("transliterated"))
- indexOf = Hints.closure.indexOf;
+ indexOf = Hints.bound.indexOf;
switch (options["hintmatching"][0]) {
case "contains" : return containsMatcher(hintString);
return null;
}, //}}}
- open: function open(mode, opts = {}) {
+ open: function open(mode, opts={}) {
this._extendedhintCount = opts.count;
mappings.pushCommand();
- commandline.input(["Normal", mode], null, {
+ commandline.input(["Normal", mode], {
autocomplete: false,
completer: function (context) {
context.compare = () => 0;
context.completions = [[k, v.prompt] for ([k, v] in Iterator(hints.modes))];
},
- onCancel: mappings.closure.popCommand,
+ onCancel: mappings.bound.popCommand,
onSubmit: function (arg) {
if (arg)
hints.show(arg, opts);
mappings.popCommand();
},
onChange: function (arg) {
- if (Object.keys(hints.modes).some(m => m != arg && m.indexOf(arg) == 0))
+ if (Object.keys(hints.modes).some(m => m != arg && m.startsWith(arg)))
return;
this.accepted = true;
},
{
keepQuotes: true,
+
getKey: function (val, default_)
- let (res = array.nth(this.value, re => let (match = re.exec(val)) match && match[0] == val, 0))
- res ? res.matcher : default_,
+ let (res = this.value.find(re => let (match = re.exec(val)) match && match[0] == val))
+ res ? res.matcher
+ : default_,
+
parse: function parse(val) {
let vals = parse.supercall(this, val);
for (let value in values(vals))
value.matcher = DOM.compileMatcher(Option.splitList(value.result));
return vals;
},
+
testValues: function testValues(vals, validator) vals.every(re => Option.splitList(re).every(validator)),
+
validator: DOM.validateMatcher
});
options.add(["hinttags", "ht"],
"XPath or CSS selector strings of hintable elements for Hints mode",
// Make sure to update the docs when you change this.
- "stringlist", ":-moz-any-link,area,button,iframe,input:not([type=hidden]),label[for],select,textarea," +
+ "stringlist", ":-moz-any-link,area,button,iframe,input:not([type=hidden]):not([disabled])," +
+ "label[for],select,textarea," +
"[onclick],[onmouseover],[onmousedown],[onmouseup],[oncommand]," +
"[tabindex],[role=link],[role=button],[contenteditable=true]",
{
"asdfg;lkjh": "Home Row"
},
validator: function (value) {
- let values = DOM.Event.parse(value).map(DOM.Event.closure.stringify);
+ let values = DOM.Event.parse(value).map(DOM.Event.bound.stringify);
return Option.validIf(array.uniq(values).length === values.length && values.length > 1,
_("option.hintkeys.duplicate"));
}