Edgewall Software
Modify

Opened 20 years ago

Closed 20 years ago

#490 closed defect (fixed)

Highlighting search results doesnt work with konqueror

Reported by: vittorio Owned by: Christopher Lenz
Priority: low Milestone:
Component: search system Version: 0.7
Severity: normal Keywords:
Cc: Branch:
Release Notes:
API Changes:
Internal Changes:

Description

searchHighlight() doesnt get executed with konqueror (tried with 3.2.2). it gets executed if i move

<script src="<?cs var:$htdocs_location ?>trac.js" type="text/javascript"></script>

from <head> to <body>

but searchHighlight() crashes then because it recurses endless. it doesnt if i comment

node.parentNode.insertBefore(span, newNode);

Attachments (0)

Change History (6)

comment:1 by anonymous, 20 years ago

Owner: changed from Jonas Borgström to Christopher Lenz
Status: newassigned
Version: devel0.7

comment:2 by Christopher Lenz, 20 years ago

I currently have no access to Konqueror. Can you please try the following patch and see whether that helps?

Index: htdocs/trac.js
===================================================================
--- htdocs/trac.js	(revision 680)
+++ htdocs/trac.js	(working copy)
@@ -54,13 +54,15 @@
         var newNode = node.splitText(pos);
         newNode.nodeValue = newNode.nodeValue.substr(word.length);
         node.parentNode.insertBefore(span, newNode);
+        return true;
       }
     } else if (!node.nodeName.match(/button|select|textarea/i)) {
       // Recurse into child nodes
       for (var i = 0; i < node.childNodes.length; i++) {
-        highlightWord(node.childNodes[i], word, searchwordindex);
+        if (highlightWord(node.childNodes[i], word, searchwordindex)) i++;
       }
     }
+    return false;
   }
 
   var words = getSearchWords(document.URL);

comment:3 by Christopher Lenz, 20 years ago

Resolution: fixed
Status: assignedclosed

Fixed in [682].

comment:4 by Christopher Lenz, 20 years ago

Resolution: fixed
Status: closedreopened

As posted by vittori on TracIrc:

theres still an issue with konq when i click on a searchresult, i get "Type Error: Null value" on if (pos >= 0 && !node.parentNode.className.match(/^searchword\d/)) {

comment:5 by Christopher Lenz, 20 years ago

Vittorio, can you please try this:

Index: htdocs/trac.js
===================================================================
--- htdocs/trac.js	(revision 682)
+++ htdocs/trac.js	(working copy)
@@ -41,12 +41,13 @@
     return [];
   }
 
+  var classNameRE = /\bsearchword\d\b/;
   function highlightWord(node, word, searchwordindex) {
     // If this node is a text node and contains the search word, highlight it by
     // surrounding it with a span element
     if (node.nodeType == 3) { // Node.TEXT_NODE
       var pos = node.nodeValue.toLowerCase().indexOf(word.toLowerCase());
-      if (pos >= 0 && !node.parentNode.className.match(/^searchword\d/)) {
+      if (pos >= 0 && !classNameRE.test(node.parentNode.className)) {
         var span = document.createElement("span");
         span.className = "searchword" + (searchwordindex % 5);
         span.appendChild(document.createTextNode(

comment:6 by Christopher Lenz, 20 years ago

Resolution: fixed
Status: reopenedclosed

Fixed in [684].

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Christopher Lenz.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Christopher Lenz to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.