]> git.donarmstrong.com Git - dactyl.git/blobdiff - common/content/hints.js
Import r6923 from upstream hg supporting Firefox up to 22.0a1
[dactyl.git] / common / content / hints.js
index 96fe44acbbbfa5399fa2a7aed63596d6fa999051..a9154e88fcea43a9b57b84d53df8df9d25ea7f9f 100644 (file)
@@ -1,10 +1,10 @@
 // Copyright (c) 2006-2008 by Martin Stubenschrott <stubenschrott@vimperator.org>
 // Copyright (c) 2007-2011 by Doug Kearns <dougkearns@gmail.com>
-// Copyright (c) 2008-2011 by Kris Maglione <maglione.k@gmail.com>
+// Copyright (c) 2008-2012 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.
-/* use strict */
+"use strict";
 
 /** @scope modules */
 /** @instance hints */
@@ -312,11 +312,11 @@ var HintSession = Class("HintSession", CommandMode, {
 
         let body = doc.body || doc.querySelector("body");
         if (body) {
-            let fragment = DOM(<div highlight="hints"/>, doc).appendTo(body);
+            let fragment = DOM(["div", { highlight: "hints" }], doc).appendTo(body);
             fragment.style.height; // Force application of binding.
             let container = doc.getAnonymousElementByAttribute(fragment[0], "anonid", "hints") || fragment[0];
 
-            let baseNode = DOM(<span highlight="Hint" style="display: none;"/>, doc)[0];
+            let baseNode = DOM(["span", { highlight: "Hint", style: "display: none;" }], doc)[0];
 
             let mode = this.hintMode;
             let res = mode.matcher(doc);
@@ -490,6 +490,10 @@ var HintSession = Class("HintSession", CommandMode, {
 
         let n = 5;
         (function next() {
+            if (Cu.isDeadWrapper && Cu.isDeadWrapper(elem))
+                // Hint document has been unloaded.
+                return;
+
             let hinted = n || this.validHints.some(function (h) h.elem === elem);
             if (!hinted)
                 hints.setClass(elem, null);
@@ -569,7 +573,9 @@ var HintSession = Class("HintSession", CommandMode, {
     /**
      * Display the hints in pageHints that are still valid.
      */
+    showCount: 0,
     show: function _show() {
+        let count = ++this.showCount;
         let hintnum = 1;
         let validHint = hints.hintMatcher(this.hintString.toLowerCase());
         let activeHint = this.hintNumber || 1;
@@ -581,6 +587,9 @@ var HintSession = Class("HintSession", CommandMode, {
 
         inner:
             for (let i in (util.interruptibleRange(start, end + 1, 500))) {
+                if (this.showCount != count)
+                    return;
+
                 let hint = this.pageHints[i];
 
                 hint.valid = validHint(hint.text);
@@ -593,7 +602,7 @@ var HintSession = Class("HintSession", CommandMode, {
                         if (!rect)
                             continue;
 
-                        hint.imgSpan = DOM(<span highlight="Hint" dactyl:hl="HintImage" xmlns:dactyl={NS}/>, doc).css({
+                        hint.imgSpan = DOM(["span", { highlight: "Hint", "dactyl:hl": "HintImage" }], doc).css({
                             display: "none",
                             left: (rect.left + offsetX) + "px",
                             top: (rect.top + offsetY) + "px",
@@ -746,6 +755,7 @@ var Hints = Module("hints", {
         this.modes = {};
         this.addMode(";", "Focus hint",                           buffer.closure.focusElement);
         this.addMode("?", "Show information for hint",            function (elem) buffer.showElementInfo(elem));
+        // TODO: allow for ! override to overwrite existing paths -- where? --djk
         this.addMode("s", "Save hint",                            function (elem) buffer.saveLink(elem, false));
         this.addMode("f", "Focus frame",                          function (elem) dactyl.focus(elem.ownerDocument.defaultView));
         this.addMode("F", "Focus frame or pseudo-frame",          buffer.closure.focusElement, isScrollable);
@@ -856,7 +866,8 @@ var Hints = Module("hints", {
                 }
                 else if (option == "label") {
                     if (elem.id) {
-                        let label = elem.ownerDocument.dactylLabels[elem.id];
+                        let label = (elem.ownerDocument.dactylLabels || {})[elem.id];
+                        // Urgh.
                         if (label)
                             return [label.textContent.toLowerCase(), true];
                     }
@@ -1301,7 +1312,7 @@ var Hints = Module("hints", {
         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]),select,textarea," +
+            "stringlist", ":-moz-any-link,area,button,iframe,input:not([type=hidden]),label[for],select,textarea," +
                           "[onclick],[onmouseover],[onmousedown],[onmouseup],[oncommand]," +
                           "[tabindex],[role=link],[role=button],[contenteditable=true]",
             {