/[webpac]/trunk2/out/js/highlight.js
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk2/out/js/highlight.js

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 396 by dpavlin, Thu Jul 22 19:00:27 2004 UTC revision 397 by dpavlin, Thu Jul 22 19:07:16 2004 UTC
# Line 1  Line 1 
1  //  //
2  // google.js  // google.js
3  // Google Highlighter  // Google Highlighter
4  //  //
5  // Copyright(C)2001 - 2003  // Copyright(C)2001 - 2003
6  // Cal Henderson <cal@iamcal.com>  // Cal Henderson <cal@iamcal.com>
7  //  //
8  // Thanks to Ian Beveridge for bugfixes  // Thanks to Ian Beveridge for bugfixes
9  //  //
10  // This code may be freely redistributed,  // This code may be freely redistributed,
11  // providing this message remains intact.  // providing this message remains intact.
12  //  //
13    
14  var google_text_color = '#000000';  var google_text_color = '#000000';
15    
16  var google_link_colors = new Array('#ffff66','#a0ffff','#99ff99','#ff9999','#ff66ff');  var google_link_colors = new Array('#ffff66','#a0ffff','#99ff99','#ff9999','#ff66ff');
17    
18  function init_google(){  function init_google(){
19          var pattern = /query=/i;          var pattern = /query=/i;
20          var url_args;          var url_args;
21    
22          //alert("referer: "+document.referrer+" location.search: "+location.search.substring(1));          if (pattern.exec(document.referrer) != null) {
23                    var url_parts = document.referrer.split('?');
24          if (pattern.exec(document.referrer) != null) {                  if (url_parts[1]) url_args = url_parts[1];
25                  var url_parts = document.referrer.split('?');          } else if (pattern.exec(location.search.substring(1)) != null) {
26                  if (url_parts[1]) url_args = url_parts[1];                  url_args = location.search.substring(1);
27          } else if (pattern.exec(location.search.substring(1)) != null) {          }
28                  url_args = location.search.substring(1);                  
29                  alert(url_args);          if (url_args){
30          }                  var url_args = url_args.split('&');
31                                    for(var i=0; i<url_args.length; i++){
32          if (url_args){                          var keyval = url_args[i].split('=');
33                  var url_args = url_args.split('&');                          if (keyval[0] == 'query'){
34                  for(var i=0; i<url_args.length; i++){                                  go_google(decode_url(keyval[1]));
35                          var keyval = url_args[i].split('=');                                  return;
36                          if (keyval[0] == 'query'){                          }
37                                  go_google(decode_url(keyval[1]));                  }
38                                  return;          }
39                          }  }
40                  }  
41          }  function decode_url(url){
42  }          return l2_unescape(url.replace(/\+/g,' '));
43    }
44  function decode_url(url){  
45          return l2_unescape(url.replace(/\+/g,' '));  function go_google(terms){
46  }          terms = terms.replace(/\"/g,"");
47            var terms_split = terms.split(' ');
48  function go_google(terms){          var c = 0;
49          terms = terms.replace(/\"/g,"");          for(var i=0; i<terms_split.length; i++){
50          var terms_split = terms.split(' ');                  highlight_goolge(terms_split[i], document.body,google_link_colors[c]);
51          var c = 0;                  c = (c == google_link_colors.length-1)?0:c+1;
52          for(var i=0; i<terms_split.length; i++){          }
53                  highlight_goolge(terms_split[i], document.body,google_link_colors[c]);  }
54                  c = (c == google_link_colors.length-1)?0:c+1;  
55          }  function highlight_goolge(term, container, color){
56  }          var term_low = term.toLowerCase();
57    
58  function highlight_goolge(term, container, color){          for(var i=0; i<container.childNodes.length; i++){
59          var term_low = term.toLowerCase();                  var node = container.childNodes[i];
60    
61          for(var i=0; i<container.childNodes.length; i++){                  if (node.nodeType == 3){
62                  var node = container.childNodes[i];                          var data = node.data;
63                            var data_low = data.toLowerCase();
64                  if (node.nodeType == 3){                          if (data_low.indexOf(term_low) != -1){
65                          var data = node.data;                                  //term found!
66                          var data_low = data.toLowerCase();                                  var new_node = document.createElement('SPAN');
67                          if (data_low.indexOf(term_low) != -1){                                  node.parentNode.replaceChild(new_node,node);
68                                  //term found!                                  var result;
69                                  var new_node = document.createElement('SPAN');                                  while((result = data_low.indexOf(term_low)) != -1){
70                                  node.parentNode.replaceChild(new_node,node);                                          new_node.appendChild(document.createTextNode(data.substr(0,result)));
71                                  var result;                                          new_node.appendChild(create_node_google(document.createTextNode(data.substr(result,term.length)),color));
72                                  while((result = data_low.indexOf(term_low)) != -1){                                          data = data.substr(result + term.length);
73                                          new_node.appendChild(document.createTextNode(data.substr(0,result)));                                          data_low = data_low.substr(result + term.length);
74                                          new_node.appendChild(create_node_google(document.createTextNode(data.substr(result,term.length)),color));                                  }
75                                          data = data.substr(result + term.length);                                  new_node.appendChild(document.createTextNode(data));
76                                          data_low = data_low.substr(result + term.length);                          }
77                                  }                  }else{
78                                  new_node.appendChild(document.createTextNode(data));                          //recurse
79                          }                          highlight_goolge(term, node, color);
80                  }else{                  }
81                          //recurse          }
82                          highlight_goolge(term, node, color);  }
83                  }  
84          }  function create_node_google(child, color){
85  }          var node = document.createElement('SPAN');
86            node.style.backgroundColor = color;
87  function create_node_google(child, color){          node.style.color = google_text_color;
88          var node = document.createElement('SPAN');          node.appendChild(child);
89          node.style.backgroundColor = color;          return node;
90          node.style.color = google_text_color;  }
91          node.appendChild(child);  
         return node;  
 }  

Legend:
Removed from v.396  
changed lines
  Added in v.397

  ViewVC Help
Powered by ViewVC 1.1.26