about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorElias Norberg <xyzzy@kudzu.se>2012-01-16 22:13:07 +0100
committerMarco Peereboom <marco@conformal.com>2012-01-16 20:37:30 -0600
commit45582bbe49cf5fa2bb8d70af3c3eae7da6b0a0b1 (patch)
treeddde24632181ca2b5abef6ce66d2d442a92f6758
parentd227dacd365706164c17d1306084d9d742b82424 (diff)
downloadxombrero-45582bbe49cf5fa2bb8d70af3c3eae7da6b0a0b1.tar.gz
Fix for FS#205 - use same number for hints with same url
-rw-r--r--hinting.js26
1 files changed, 22 insertions, 4 deletions
diff --git a/hinting.js b/hinting.js
index 135c4dd..f3ca601 100644
--- a/hinting.js
+++ b/hinting.js
@@ -110,19 +110,37 @@ function Hints() {
                 var leftpos = Math.max((rect.left + scrollX), scrollX);
                 var toppos = Math.max((rect.top + scrollY), scrollY);
 
+                /* check if we already created a hint for this URL */
+                var hintNumber = hintCount;
+                if (elem.nodeName.toLowerCase() == "a") {
+                        for (var j = 0; j < hints.length; j++) {
+                                var h = hints[j];
+                                if (h.elem.nodeName.toLowerCase() != "a")
+                                        continue;
+                                if (h.elem.href.toLowerCase() == elem.href.toLowerCase()){
+                                        hintNumber = h.number - 1;
+                                        break;
+                                }
+                        }
+                }
+
                 /* making this block DOM compliant */
                 var hint = hintSpan.cloneNode(false);
-                hint.setAttribute("id", "vimprobablehint" + hintCount);
+                hint.setAttribute("id", "vimprobablehint" + hintNumber);
                 hint.style.left = leftpos + "px";
                 hint.style.top =  toppos + "px";
-                text = doc.createTextNode(hintCount + 1);
+                text = doc.createTextNode(hintNumber + 1);
                 hint.appendChild(text);
 
                 hintContainer.appendChild(hint);
-                hintCount++;
+                if (hintNumber == hintCount)
+                        hintCount++;
+                else
+                        hintNumber = -2; /* do not follow dupes */
+
                 hints.push({
                     elem:       elem,
-                    number:     hintCount,
+                    number:     hintNumber+1,
                     span:       hint,
                     background: elem.style.background,
                     foreground: elem.style.color}