/[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

Annotation of /trunk2/out/js/highlight.js

Parent Directory Parent Directory | Revision Log Revision Log


Revision 393 - (hide annotations)
Wed Jul 21 21:41:18 2004 UTC (19 years, 9 months ago) by dpavlin
File MIME type: application/javascript
File size: 2321 byte(s)
import original Google Highlighter by Cal Henderson from 
http://www.iamcal.com/publish/articles/hacks/google_highlighter/

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

  ViewVC Help
Powered by ViewVC 1.1.26